diff --git a/README.md b/README.md index b4ff182..1261800 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,12 @@ scale it can call the outscaler to persist the right action curl -v -d '{"direction": true}' \ http://localhost:8000/handle/infra_scale/docker ``` +Or if you prefer + +```sh +curl -v -X POST http://localhost:8000/handle/infra_scale/docker/up +``` + ## Autodetect The autodetect mode starts when you don't specify any configuration file. diff --git a/api/handle.go b/api/handle.go index 915df2c..b9a65ad 100644 --- a/api/handle.go +++ b/api/handle.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/http/httputil" "github.com/Sirupsen/logrus" "github.com/gianarb/orbiter/autoscaler" @@ -21,6 +22,11 @@ type scaleRequest struct { func Handle(scalers autoscaler.Autoscalers) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { var err error + requestDump, err := httputil.DumpRequest(r, true) + if err != nil { + fmt.Println(err) + } + fmt.Println(string(requestDump)) w.Header().Set("Content-Type", "application/json") decoder := json.NewDecoder(r.Body) var scaleRequest scaleRequest @@ -35,6 +41,16 @@ func Handle(scalers autoscaler.Autoscalers) func(w http.ResponseWriter, r *http. w.WriteHeader(406) return } + + directionByRoute, ok := vars["direction"] + if ok { + if directionByRoute == "up" { + scaleRequest.Direction = DIRECTION_UP + } else { + scaleRequest.Direction = DIRECTION_DOWN + } + } + serviceName, ok := vars["service_name"] if !ok { logrus.WithFields(logrus.Fields{ diff --git a/api/router.go b/api/router.go index 9d0f6a3..722238a 100644 --- a/api/router.go +++ b/api/router.go @@ -9,6 +9,7 @@ import ( func GetRouter(core core.Core, eventChannel chan *logrus.Entry) *mux.Router { r := mux.NewRouter() r.HandleFunc("/handle/{autoscaler_name}/{service_name}", Handle(core.Autoscalers)).Methods("POST") + r.HandleFunc("/handle/{autoscaler_name}/{service_name}/{direction}", Handle(core.Autoscalers)).Methods("POST") r.HandleFunc("/autoscaler", AutoscalerList(core.Autoscalers)).Methods("GET") r.HandleFunc("/health", Health()).Methods("GET") r.HandleFunc("/events", Events(eventChannel)).Methods("GET")