func deleteReplicationControllerNotifier(request *restful.Request, response *restful.Response) { namespace := request.PathParameter("namespace") kind := request.PathParameter("kind") name := request.PathParameter("name") replicationControllerNotifier := ¬ification.ReplicationControllerNotifier{} replicationControllerNotifier.Namespace = namespace replicationControllerNotifier.Kind = kind replicationControllerNotifier.Name = name replicationControllerNotifier.Check = false err := notification.GetStorage().DeleteReplicationControllerNotifierSerializable(namespace, kind, name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Delete replication controller notifier 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.AddReplicationControllerNotifier(replicationControllerNotifier) }
func putReplicationControllerNotifier(request *restful.Request, response *restful.Response) { replicationControllerNotifierSerializable := new(notification.ReplicationControllerNotifierSerializable) err := request.ReadEntity(&replicationControllerNotifierSerializable) 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 } replicationControllerNotifierSerializable.KubeApiServerEndPoint = kubeApiServerEndPoint replicationControllerNotifierSerializable.KubeApiServerToken = kubeApiServerToken switch replicationControllerNotifierSerializable.Kind { case "application": _, err := deploy.GetStorage().LoadDeployInformation(replicationControllerNotifierSerializable.Namespace, replicationControllerNotifierSerializable.Name) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Check whether the application exists or not failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } case "selector": nameSlice, err := monitor.GetReplicationControllerNameFromSelector(replicationControllerNotifierSerializable.KubeApiServerEndPoint, replicationControllerNotifierSerializable.KubeApiServerToken, replicationControllerNotifierSerializable.Namespace, replicationControllerNotifierSerializable.Name) if err != nil { for _, name := range nameSlice { exist, err := monitor.ExistReplicationController(replicationControllerNotifierSerializable.KubeApiServerEndPoint, replicationControllerNotifierSerializable.KubeApiServerToken, replicationControllerNotifierSerializable.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["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable 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 notify doesn't exist" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(404, string(errorMessageByteSlice)) return } } } case "replicationController": exist, err := monitor.ExistReplicationController(replicationControllerNotifierSerializable.KubeApiServerEndPoint, replicationControllerNotifierSerializable.KubeApiServerToken, replicationControllerNotifierSerializable.Namespace, replicationControllerNotifierSerializable.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["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable 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 notify doesn't exist" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } default: jsonMap := make(map[string]interface{}) jsonMap["Error"] = "No such kind" jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable jsonMap["kind"] = replicationControllerNotifierSerializable.Kind errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } replicationControllerNotifier, err := notification.ConvertFromSerializable(*replicationControllerNotifierSerializable) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Convert replication controller notifier failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(400, string(errorMessageByteSlice)) return } err = notification.GetStorage().SaveReplicationControllerNotifierSerializable(replicationControllerNotifierSerializable) if err != nil { jsonMap := make(map[string]interface{}) jsonMap["Error"] = "Save replication controller notifier failure" jsonMap["ErrorMessage"] = err.Error() jsonMap["replicationControllerNotifierSerializable"] = replicationControllerNotifierSerializable errorMessageByteSlice, _ := json.Marshal(jsonMap) log.Error(jsonMap) response.WriteErrorString(422, string(errorMessageByteSlice)) return } execute.AddReplicationControllerNotifier(&replicationControllerNotifier) }