func (c *ResetController) Get() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") clusterName := c.GetString("clusterName") glusterfsVolume := c.GetString("glusterfsVolume") url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/glusterfs/clusters/" + clusterName + "/volumes/" + glusterfsVolume jsonMap := make(map[string]interface{}) tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, jsonMap, tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Glusterfs volume " + glusterfsVolume + " is reset") } // Redirect to list c.Ctx.Redirect(302, "/gui/filesystem/glusterfs/volume/list?clusterName="+clusterName) guimessage.RedirectMessage(c) }
func (c *ConfigureController) Get() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") name := c.GetString("name") url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/slbs/daemons/" + name + "/configure" tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, make(map[string]interface{}), tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("SLB daemon " + name + " is configured") } // Redirect to list c.Ctx.Redirect(302, "/gui/system/slb/daemon/list") guimessage.RedirectMessage(c) }
func UpdateReplicationControllerSize(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, size int) (returnedError error) { defer func() { if err := recover(); err != nil { log.Error("UpdateReplicationControllerSize Error: %s", err) log.Error(logger.GetStackTrace(4096, false)) returnedError = err.(error) } }() headerMap := make(map[string]string) headerMap["Authorization"] = kubeApiServerToken url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/" result, err := restclient.RequestGet(url, headerMap, true) jsonMap, _ := result.(map[string]interface{}) if err != nil { log.Error("Get replication controller information failure where size: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", size, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error()) return err } else { jsonMap["spec"].(map[string]interface{})["replicas"] = float64(size) _, err := restclient.RequestPut(url, jsonMap, headerMap, true) if err != nil { return err } else { return nil } } }
// Used for failed slb host to reconfigure func SendCommandToSLBDaemon(targetEndPoint string) error { slbDaemonSlice, err := GetStorage().LoadAllSLBDaemon() if err != nil { log.Error(err) return nil } command, err := CreateCommand() if err != nil { log.Error(err) return nil } for _, slbDaemon := range slbDaemonSlice { for _, endPoint := range slbDaemon.EndPointSlice { if endPoint == targetEndPoint { command.NodeHostSlice = slbDaemon.NodeHostSlice url := endPoint + "/api/v1/slb" _, err := restclient.RequestPut(url, command, nil, false) if err != nil { log.Error(err) return errors.New("Fail to configure " + endPoint + "with error " + err.Error() + "\n") } else { return nil } } } } return errors.New("Can't find endpoint " + targetEndPoint) }
func (c *ResizeController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) name := c.GetString("name") size, _ := c.GetInt("size") url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploys/resize/" + namespace + "/" + name + "?size=" + strconv.Itoa(size) tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, make(map[string]interface{}), tokenHeaderMap, false) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Application " + name + " is resized") } c.Ctx.Redirect(302, "/gui/deploy/deploy/list") guimessage.RedirectMessage(c) }
func (c *SizeController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) name := c.GetString("name") size := c.GetString("size") keySlice := make([]string, 0) inputMap := c.Input() if inputMap != nil { for key, _ := range inputMap { keySlice = append(keySlice, key) } } environmentSlice := make([]interface{}, 0) for _, key := range keySlice { value := c.GetString(key) if len(value) > 0 { environmentMap := make(map[string]string) environmentMap["name"] = key environmentMap["value"] = value environmentSlice = append(environmentSlice, environmentMap) } } url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deployclusterapplications/size/" + namespace + "/" + name + "?size=" + size tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, environmentSlice, tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Cluster application " + name + " is resized") } c.Ctx.Redirect(302, "/gui/deploy/deployclusterapplication/list") guimessage.RedirectMessage(c) }
func ResizeReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, delta int, maximumSize int, minimumSize int) (resized bool, size int, returnedError error) { defer func() { if err := recover(); err != nil { log.Error("ResizeReplicationController Error: %s", err) log.Error(logger.GetStackTrace(4096, false)) resized = false size = -1 returnedError = err.(error) } }() headerMap := make(map[string]string) headerMap["Authorization"] = kubeApiServerToken url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/" result, err := restclient.RequestGet(url, headerMap, true) jsonMap, _ := result.(map[string]interface{}) if err != nil { log.Error("Get replication controller information failure where delta: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", delta, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error()) return false, -1, err } else { replicas, _ := jsonparse.ConvertToInt64(jsonMap["spec"].(map[string]interface{})["replicas"]) currentSize := int(replicas) newSize := currentSize + delta if newSize < minimumSize { newSize = minimumSize } if newSize > maximumSize { newSize = maximumSize } if newSize == currentSize { return false, currentSize, nil } jsonMap["spec"].(map[string]interface{})["replicas"] = float64(newSize) result, err := restclient.RequestPut(url, jsonMap, headerMap, true) resultJsonMap, _ := result.(map[string]interface{}) if err != nil { return false, currentSize, err } else { replicas, _ := jsonparse.ConvertToInt64(resultJsonMap["spec"].(map[string]interface{})["replicas"]) return true, int(replicas), nil } } }
// @Title resize // @Description resize the cluster application // @Param body body []Environment true "Array of environment" // @Param name path string true "The name of cluster application deployment" // @Param size query string true "The size to change" // @Success 200 {string} {} // @Failure 404 error reason // @router /size/:name [put] func (c *SizeController) Put() { inputBody := c.Ctx.Input.CopyBody(limit.InputPostBodyMaximum) environmentSlice := make([]Environment, 0) err := json.Unmarshal(inputBody, &environmentSlice) if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } name := c.GetString(":name") size := c.GetString("size") cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deployclusterapplications/size/" + namespace + "/" + name + "?size=" + size tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err = restclient.RequestPut(url, environmentSlice, tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } else { c.Data["json"] = make(map[string]interface{}) c.ServeJSON() } }
func (slbDaemon *SLBDaemon) SendCommand(command *slb.Command) error { command.NodeHostSlice = slbDaemon.NodeHostSlice buffer := bytes.Buffer{} for _, endPoint := range slbDaemon.EndPointSlice { url := endPoint + "/api/v1/slb" _, err := restclient.RequestPut(url, command, nil, false) if err != nil { log.Error(err) buffer.WriteString("Fail to configure " + endPoint + " with error " + err.Error() + "\n") } } if buffer.Len() > 0 { return errors.New(buffer.String()) } else { return nil } }
func (c *SizeController) Post() { guimessage := guimessagedisplay.GetGUIMessage(c) cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) name := c.GetString("name") size, _ := c.GetInt("size") url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/replicationcontrollers/size/" + namespace + "/" + name putBodyJsonMap := make(map[string]interface{}) putBodyJsonMap["Size"] = size tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, putBodyJsonMap, tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err)) } else { guimessage.AddSuccess("Replication Controller " + name + " is resized") } c.Ctx.Redirect(302, "/gui/inventory/replicationcontroller/list") guimessage.RedirectMessage(c) }
func UpdateReplicationControllerWithJson(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, bodyJsonMap map[string]interface{}) (returnedError error) { defer func() { if err := recover(); err != nil { log.Error("UpdateReplicationControllerWithJson Error: %s", err) log.Error(logger.GetStackTrace(4096, false)) returnedError = err.(error) } }() headerMap := make(map[string]string) headerMap["Authorization"] = kubeApiServerToken url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName result, err := restclient.RequestGet(url, headerMap, true) if err != nil { log.Error(err) return err } jsonMap, _ := result.(map[string]interface{}) metadataJsonMap, _ := jsonMap["metadata"].(map[string]interface{}) resourceVersion, _ := metadataJsonMap["resourceVersion"].(string) // Update requires the resoruce version bodyJsonMap["metadata"].(map[string]interface{})["resourceVersion"] = resourceVersion url = kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName _, err = restclient.RequestPut(url, bodyJsonMap, headerMap, true) if err != nil { log.Error(err) return err } else { return nil } }
func UpdateServiceWithJson(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, serviceName string, bodyJsonMap map[string]interface{}) (returnedError error) { defer func() { if err := recover(); err != nil { log.Error("CreateServiceWithJson Error: %s", err) log.Error(logger.GetStackTrace(4096, false)) returnedError = err.(error) } }() headerMap := make(map[string]string) headerMap["Authorization"] = kubeApiServerToken url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/services/" + serviceName result, err := restclient.RequestGet(url, headerMap, true) jsonMap, _ := result.(map[string]interface{}) metadataJsonMap, _ := jsonMap["metadata"].(map[string]interface{}) resourceVersion, _ := metadataJsonMap["resourceVersion"].(string) specJsonMap, _ := jsonMap["spec"].(map[string]interface{}) clusterIP, _ := specJsonMap["clusterIP"].(string) // Update requires the resoruce version and cluster ip bodyJsonMap["metadata"].(map[string]interface{})["resourceVersion"] = resourceVersion bodyJsonMap["spec"].(map[string]interface{})["clusterIP"] = clusterIP url = kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/services/" + serviceName _, err = restclient.RequestPut(url, bodyJsonMap, headerMap, true) if err != nil { log.Error(err) return err } else { return nil } }
// @Title resize // @Description resize replication controller // @Param name path string true "The name of replication controller" // @Param size query string true "the new size" // @Success 200 {string} {} // @Failure 404 error reason // @router /resize/:name [put] func (c *SizeController) Put() { name := c.GetString(":name") size, _ := c.GetInt("size") cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol") cloudoneHost := beego.AppConfig.String("cloudoneHost") cloudonePort := beego.AppConfig.String("cloudonePort") namespace, _ := c.GetSession("namespace").(string) url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/replicationcontrollers/size/" + namespace + "/" + name putBodyJsonMap := make(map[string]interface{}) putBodyJsonMap["Size"] = size tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string) _, err := restclient.RequestPut(url, putBodyJsonMap, tokenHeaderMap, true) if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) { return } if err != nil { // Error c.Data["json"] = make(map[string]interface{}) c.Data["json"].(map[string]interface{})["error"] = err.Error() c.Ctx.Output.Status = 404 c.ServeJSON() return } else { c.Data["json"] = make(map[string]interface{}) c.ServeJSON() } }