Exemple #1
0
func deleteReplicationControllerNotifier(request *restful.Request, response *restful.Response) {
	namespace := request.PathParameter("namespace")
	kind := request.PathParameter("kind")
	name := request.PathParameter("name")

	replicationControllerNotifier := &notification.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)
}
Exemple #2
0
func getAllSMSNexmo(request *restful.Request, response *restful.Response) {
	smsNexmoSlice, err := notification.GetStorage().LoadAllSMSNexmo()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all sms nexmo failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(smsNexmoSlice, "[]SMSNexmo")
}
Exemple #3
0
func getAllEmailServerSMTP(request *restful.Request, response *restful.Response) {
	emailServerSMTPSlice, err := notification.GetStorage().LoadAllEmailServerSMTP()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all smtp email server failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(emailServerSMTPSlice, "[]EmailServerSMTP")
}
Exemple #4
0
func postSMSNexmo(request *restful.Request, response *restful.Response) {
	smsNexmo := &notification.SMSNexmo{}
	err := request.ReadEntity(&smsNexmo)
	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
	}

	existingSMSNexmo, _ := notification.GetStorage().LoadSMSNexmo(smsNexmo.Name)
	if existingSMSNexmo != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The sms nexmo to create already exists"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = smsNexmo.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(409, string(errorMessageByteSlice))
		return
	}

	err = notification.GetStorage().SaveSMSNexmo(smsNexmo)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save sms nexmo failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["smsNexmo"] = smsNexmo
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemple #5
0
func postEmailServerSMTP(request *restful.Request, response *restful.Response) {
	emailServerSMTP := &notification.EmailServerSMTP{}
	err := request.ReadEntity(&emailServerSMTP)
	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
	}

	existingEmailServerSMTP, _ := notification.GetStorage().LoadEmailServerSMTP(emailServerSMTP.Name)
	if existingEmailServerSMTP != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The smtp email server to create already exists"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = emailServerSMTP.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(409, string(errorMessageByteSlice))
		return
	}

	err = notification.GetStorage().SaveEmailServerSMTP(emailServerSMTP)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save smtp email server failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["emailServerSMTP"] = emailServerSMTP
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemple #6
0
func deleteSMSNexmo(request *restful.Request, response *restful.Response) {
	name := request.PathParameter("name")

	err := notification.GetStorage().DeleteSMSNexmo(name)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Delete sms nexmo failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
func init() {
	// Load from database
	replicationControllerNotifierSerializableSlice, err := notification.GetStorage().LoadAllReplicationControllerNotifierSerializable()
	if err != nil {
		log.Error(err)
	} else {
		for _, replicationControllerNotifierSerializable := range replicationControllerNotifierSerializableSlice {
			replicationControllerNotifier, err := notification.ConvertFromSerializable(replicationControllerNotifierSerializable)
			if err != nil {
				log.Error(err)
			} else {
				AddReplicationControllerNotifier(&replicationControllerNotifier)
			}
		}
	}
}
Exemple #8
0
func getEmailServerSMTP(request *restful.Request, response *restful.Response) {
	name := request.PathParameter("name")

	emailServerSMTP, err := notification.GetStorage().LoadEmailServerSMTP(name)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get smtp email server failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(emailServerSMTP, "EmailServerSMTP")
}
Exemple #9
0
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)
}