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

	slbDaemon := slb.SLBDaemon{}
	err := request.ReadEntity(&slbDaemon)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Read body failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	if name != slbDaemon.Name {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Path parameter name is different from name in the body"
		jsonMap["path"] = name
		jsonMap["body"] = slbDaemon.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	oldSLBDaemon, _ := slb.GetStorage().LoadSLBDaemon(slbDaemon.Name)
	if oldSLBDaemon == nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The slbDaemon to update doesn't exist"
		jsonMap["name"] = slbDaemon.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	err = slb.GetStorage().SaveSLBDaemon(&slbDaemon)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["slbDaemon"] = slbDaemon
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemple #2
0
func getAllSLBDaemon(request *restful.Request, response *restful.Response) {
	slbDaemonClusterSlice, err := slb.GetStorage().LoadAllSLBDaemon()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(slbDaemonClusterSlice, "[]SLBDaemon")
}
Exemple #3
0
func postSLBDaemon(request *restful.Request, response *restful.Response) {
	slbDaemon := slb.SLBDaemon{}
	err := request.ReadEntity(&slbDaemon)
	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
	}

	oldSLBDaemon, _ := slb.GetStorage().LoadSLBDaemon(slbDaemon.Name)
	if oldSLBDaemon != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The slbDaemon to create already exists"
		jsonMap["name"] = slbDaemon.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(409, string(errorMessageByteSlice))
		return
	}

	err = slb.GetStorage().SaveSLBDaemon(&slbDaemon)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["slbDaemon"] = slbDaemon
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemple #4
0
func deleteSLBDaemon(request *restful.Request, response *restful.Response) {
	name := request.PathParameter("name")

	err := slb.GetStorage().DeleteSLBDaemon(name)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Delete slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["name"] = name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemple #5
0
func (hostControl *HostControl) GetSLBHostStatus() (map[string]interface{}, error) {
	slbDaemonSlice, err := slb.GetStorage().LoadAllSLBDaemon()
	if err != nil {
		log.Error(err)
		return nil, err
	}

	slbDaemonJsonMap := make(map[string]interface{})
	for key, value := range hostControl.dataJsonMap {
		hostJsonMap, ok := value.(map[string]interface{})
		if ok {
			if hostControl.isHostType(hostJsonMap, HostTypeSLB) {
				hostJsonMap["active"] = true
				slbDaemonJsonMap[key] = hostJsonMap
			}
		}
	}

	allSLBDaemonSetJsonMap := make(map[string]interface{})
	for _, slbDaemon := range slbDaemonSlice {
		slbDaemonSetJsonMap := make(map[string]interface{})
		for _, endPoint := range slbDaemon.EndPointSlice {
			host, err := parseHostFromEndpoint(endPoint, slbDaemon)
			if err != nil {
				log.Error(err)
				return nil, err
			}

			if slbDaemonJsonMap[host] == nil {
				slbDaemonSetJsonMap[host] = make(map[string]interface{})
				slbDaemonSetJsonMap[host].(map[string]interface{})["active"] = false
			} else {
				slbDaemonSetJsonMap[host] = slbDaemonJsonMap[host]
			}
		}
		allSLBDaemonSetJsonMap[slbDaemon.Name] = slbDaemonSetJsonMap
	}

	return allSLBDaemonSetJsonMap, nil
}
Exemple #6
0
func putSLBDaemonConfigure(request *restful.Request, response *restful.Response) {
	name := request.PathParameter("name")

	slbDaemon, _ := slb.GetStorage().LoadSLBDaemon(name)
	if slbDaemon == nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The slbDaemon to configre doesn't exist"
		jsonMap["name"] = name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	command, err := slb.CreateCommand()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Create command for slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["slbDaemon"] = slbDaemon
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	err = slbDaemon.SendCommand(command)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Send command to slbDaemon failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["slbDaemon"] = slbDaemon
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}