func deleteReplicationControllerAutoScaler(request *restful.Request, response *restful.Response) { namespace := request.PathParameter("namespace") kind := request.PathParameter("kind") name := request.PathParameter("name") replicationControllerAutoScaler := &autoscaler.ReplicationControllerAutoScaler{} replicationControllerAutoScaler.Namespace = namespace replicationControllerAutoScaler.Kind = kind replicationControllerAutoScaler.Name = name replicationControllerAutoScaler.Check = false err := autoscaler.GetStorage().DeleteReplicationControllerAutoScaler(replicationControllerAutoScaler.Namespace, replicationControllerAutoScaler.Kind, replicationControllerAutoScaler.Name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Delete replication controller autoscaler failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["namespace"] = namespace jsonMap["kind"] = kind jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } execute.AddReplicationControllerAutoScaler(replicationControllerAutoScaler) }
func init() { // Load from database replicationControllerAutoScalerSlice, err := autoscaler.GetStorage().LoadAllReplicationControllerAutoScaler() if err != nil { log.Error(err) } else { for _, replicationControllerAutoScaler := range replicationControllerAutoScalerSlice { AddReplicationControllerAutoScaler(&replicationControllerAutoScaler) } } }
func putReplicationControllerAutoScaler(request *restful.Request, response *restful.Response) { replicationControllerAutoScaler := new(autoscaler.ReplicationControllerAutoScaler) err := request.ReadEntity(&replicationControllerAutoScaler) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Read body failure" jsonMap["ErrorMessage"] = err.Error() errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } kubeApiServerEndPoint, kubeApiServerToken, err := configuration.GetAvailablekubeApiServerEndPoint() if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Get kube apiserver endpoint and token failure" jsonMap["ErrorMessage"] = err.Error() errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } replicationControllerAutoScaler.KubeApiServerEndPoint = kubeApiServerEndPoint replicationControllerAutoScaler.KubeApiServerToken = kubeApiServerToken switch replicationControllerAutoScaler.Kind { case "application": _, err := deploy.GetStorage().LoadDeployInformation(replicationControllerAutoScaler.Namespace, replicationControllerAutoScaler.Name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Check whether the application exists or not failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } case "selector": nameSlice, err := monitor.GetReplicationControllerNameFromSelector(replicationControllerAutoScaler.KubeApiServerEndPoint, replicationControllerAutoScaler.KubeApiServerToken, replicationControllerAutoScaler.Namespace, replicationControllerAutoScaler.Name) if err != nil { for _, name := range nameSlice { exist, err := monitor.ExistReplicationController(replicationControllerAutoScaler.KubeApiServerEndPoint, replicationControllerAutoScaler.KubeApiServerToken, replicationControllerAutoScaler.Namespace, name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Check whether the replication controller exists or not failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } if exist == false { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "The replication controller to auto scale doesn't exist" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } } } case "replicationController": exist, err := monitor.ExistReplicationController(replicationControllerAutoScaler.KubeApiServerEndPoint, replicationControllerAutoScaler.KubeApiServerToken, replicationControllerAutoScaler.Namespace, replicationControllerAutoScaler.Name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Check whether the replication controller exists or not failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } if exist == false { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "The replication controller to auto scale doesn't exist" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } default: jsonMap := make(map[string]interface{}) jsonMap["Error"] = "No such kind" jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler jsonMap["kind"] = replicationControllerAutoScaler.Kind errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } err = autoscaler.GetStorage().SaveReplicationControllerAutoScaler(replicationControllerAutoScaler) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Save replication controller autoscaler failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerAutoScaler"] = replicationControllerAutoScaler errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } execute.AddReplicationControllerAutoScaler(replicationControllerAutoScaler) }