func deleteDeployBlueGreen(request *restful.Request, response *restful.Response) { imageInformation := request.PathParameter("imageinformation") 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 } err = deploy.GetStorage().DeleteDeployBlueGreen(imageInformation) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Delete blue green deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["imageInformation"] = imageInformation errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = deploy.CleanAllServiceUnderBlueGreenDeployment(kubeApiServerEndPoint, kubeApiServerToken, imageInformation) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Delete all services under blue green deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["imageInformation"] = imageInformation errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = slb.SendCommandToAllSLBDaemon() if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Configure SLB failure" jsonMap["ErrorMessage"] = err.Error() errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } }
func putDeployBlueGreen(request *restful.Request, response *restful.Response) { 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 } deployBlueGreen := new(deploy.DeployBlueGreen) err = request.ReadEntity(&deployBlueGreen) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Read body failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } err = deploy.UpdateDeployBlueGreen(kubeApiServerEndPoint, kubeApiServerToken, deployBlueGreen) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Update blue green deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["deployBlueGreen"] = deployBlueGreen errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = slb.SendCommandToAllSLBDaemon() if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Configure SLB failure" jsonMap["ErrorMessage"] = err.Error() errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } }
func postDeployCreate(request *restful.Request, response *restful.Response) { namespace := request.PathParameter("namespace") 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 errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } deployCreateInput := new(DeployCreateInput) err = request.ReadEntity(&deployCreateInput) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Read body failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint jsonMap["namespace"] = namespace errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } deploymentInformation, _ := deploy.GetStorage().LoadDeployInformation(namespace, deployCreateInput.ImageInformationName) if deploymentInformation != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Duplicate deployment error" jsonMap["ErrorMessage"] = "Already exists" jsonMap["kubeApiServerToken"] = kubeApiServerToken jsonMap["namespace"] = namespace jsonMap["deployCreateInput"] = deployCreateInput errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = deploy.DeployCreate( kubeApiServerEndPoint, kubeApiServerToken, namespace, deployCreateInput.ImageInformationName, deployCreateInput.Version, deployCreateInput.Description, deployCreateInput.ReplicaAmount, deployCreateInput.PortSlice, deployCreateInput.EnvironmentSlice, deployCreateInput.ResourceMap, deployCreateInput.ExtraJsonMap, deployCreateInput.AutoUpdateForNewBuild, ) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Create deployment failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["kubeApiServerToken"] = kubeApiServerToken jsonMap["namespace"] = namespace jsonMap["deployCreateInput"] = deployCreateInput errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } err = slb.SendCommandToAllSLBDaemon() if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Configure SLB failure" jsonMap["ErrorMessage"] = err.Error() errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } }