Add the ability to send post without content

This commit is contained in:
Gianluca Arbezzano 2017-03-28 12:38:47 +01:00
parent b6f6cb3784
commit d231b613ea
3 changed files with 23 additions and 0 deletions

View File

@ -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.

View File

@ -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{

View File

@ -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")