Beispiel #1
0
func putGlusterfsCluster(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")

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

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

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

	glusterfsCluster = glusterfs.CreateGlusterfsCluster(
		glusterfsClusterInput.Name,
		glusterfsClusterInput.HostSlice,
		glusterfsClusterInput.Path,
		glusterfsClusterInput.SSHDialTimeoutInMilliSecond,
		glusterfsClusterInput.SSHSessionTimeoutInMilliSecond,
		glusterfsClusterInput.SSHPort,
		glusterfsClusterInput.SSHUser,
		glusterfsClusterInput.SSHPassword)

	err = glusterfs.GetStorage().SaveGlusterfsCluster(glusterfsCluster)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save glusterfs cluster failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["glusterfsCluster"] = glusterfsCluster
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Beispiel #2
0
func postGlusterfsCluster(request *restful.Request, response *restful.Response) {
	glusterfsClusterInput := GlusterfsClusterInput{}
	err := request.ReadEntity(&glusterfsClusterInput)
	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
	}

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

	glusterfsCluster = glusterfs.CreateGlusterfsCluster(
		glusterfsClusterInput.Name,
		glusterfsClusterInput.HostSlice,
		glusterfsClusterInput.Path,
		glusterfsClusterInput.SSHDialTimeoutInMilliSecond,
		glusterfsClusterInput.SSHSessionTimeoutInMilliSecond,
		glusterfsClusterInput.SSHPort,
		glusterfsClusterInput.SSHUser,
		glusterfsClusterInput.SSHPassword)

	err = glusterfs.GetStorage().SaveGlusterfsCluster(glusterfsCluster)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save glusterfs cluster failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["glusterfsCluster"] = glusterfsCluster
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}