Move handle* methods to their respective locations

Fix names
This commit is contained in:
Clayton Coleman
2014-07-29 18:54:20 -04:00
parent fe7f611d88
commit e64a393e1a
3 changed files with 96 additions and 94 deletions

View File

@@ -17,8 +17,11 @@ limitations under the License.
package apiserver
import (
"net/http"
"path"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
@@ -27,6 +30,47 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
func (s *APIServer) operationPrefix() string {
return path.Join(s.prefix, "operations")
}
func (s *APIServer) handleOperation(w http.ResponseWriter, req *http.Request) {
opPrefix := s.operationPrefix()
if !strings.HasPrefix(req.URL.Path, opPrefix) {
notFound(w, req)
return
}
trimmed := strings.TrimLeft(req.URL.Path[len(opPrefix):], "/")
parts := strings.Split(trimmed, "/")
if len(parts) > 1 {
notFound(w, req)
return
}
if req.Method != "GET" {
notFound(w, req)
return
}
if len(parts) == 0 {
// List outstanding operations.
list := s.ops.List()
writeJSON(http.StatusOK, list, w)
return
}
op := s.ops.Get(parts[0])
if op == nil {
notFound(w, req)
return
}
obj, complete := op.StatusOrResult()
if complete {
writeJSON(http.StatusOK, obj, w)
} else {
writeJSON(http.StatusAccepted, obj, w)
}
}
// Operation represents an ongoing action which the server is performing.
type Operation struct {
ID string