func getDeployClusterApplication(request *restful.Request, response *restful.Response) { namespace := request.PathParameter("namespace") clusterApplication := request.PathParameter("clusterapplication") deployClusterApplication, err := deploy.GetDeployClusterApplication(namespace, clusterApplication) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Get cluster application deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["namespace"] = namespace jsonMap["clusterApplication"] = clusterApplication errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } response.WriteJson(deployClusterApplication, "DeployClusterApplication") }
func postLaunchClusterApplication(request *restful.Request, response *restful.Response) { namespace := request.PathParameter("namespace") name := request.PathParameter("clusterapplication") 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() jsonMap["namespace"] = namespace jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } clusterLaunch := ClusterLaunch{} err = request.ReadEntity(&clusterLaunch) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Read body failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["namespace"] = namespace jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } oldDeployClusterApplication, _ := deploy.GetDeployClusterApplication(namespace, name) if oldDeployClusterApplication != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "The cluster application already exists" jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["namespace"] = namespace jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(409, string(errorMessageByteSlice)) return } err = application.LaunchClusterApplication(kubeApiServerEndPoint, kubeApiServerToken, namespace, name, clusterLaunch.EnvironmentSlice, clusterLaunch.Size, clusterLaunch.ReplicationControllerExtraJsonMap) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Launch cluster application deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["namespace"] = namespace jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = deploy.InitializeDeployClusterApplication(kubeApiServerEndPoint, kubeApiServerToken, namespace, name, clusterLaunch.EnvironmentSlice, clusterLaunch.Size, clusterLaunch.ReplicationControllerExtraJsonMap) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Create cluster application deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["namespace"] = namespace jsonMap["name"] = name errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } }