Exemplo n.º 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
	}
}
Exemplo n.º 2
0
func putGlusterfsVolume(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")
	volume := request.PathParameter("volume")

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

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

}
Exemplo n.º 3
0
func getAllGlusterfsVolume(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")

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

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

	response.WriteJson(glusterfsVolumeSlice, "[]GlusterfsVolume")
}
Exemplo n.º 4
0
func (hostControl *HostControl) GetGlusterfsHostStatus() (map[string]interface{}, error) {
	glusterfsClusterSlice, err := glusterfs.GetStorage().LoadAllGlusterfsCluster()
	if err != nil {
		log.Error(err)
		return nil, err
	}

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

	allGlusterfsClusterJsonMap := make(map[string]interface{})
	for _, glusterfsCluster := range glusterfsClusterSlice {
		glusterfsClusterJsonMap := make(map[string]interface{})
		for _, host := range glusterfsCluster.HostSlice {
			if glusterfsJsonMap[host] == nil {
				glusterfsClusterJsonMap[host] = make(map[string]interface{})
				glusterfsClusterJsonMap[host].(map[string]interface{})["active"] = false
			} else {
				glusterfsClusterJsonMap[host] = glusterfsJsonMap[host]
			}
		}
		allGlusterfsClusterJsonMap[glusterfsCluster.Name] = glusterfsClusterJsonMap
	}

	return allGlusterfsClusterJsonMap, nil
}
Exemplo n.º 5
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
	}
}
Exemplo n.º 6
0
func postGlusterfsVolume(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")

	glusterfsVolumeCreateParameter := &glusterfs.GlusterfsVolumeCreateParameter{}
	err := request.ReadEntity(&glusterfsVolumeCreateParameter)
	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
	}

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

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

	err = glusterfsCluster.StartVolume(glusterfsVolumeCreateParameter.VolumeName)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Start glusterfs volume failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["cluster"] = cluster
		jsonMap["glusterfsVolumeCreateParameter"] = glusterfsVolumeCreateParameter
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemplo n.º 7
0
func getAllGlusterfsCluster(request *restful.Request, response *restful.Response) {
	glusterfsClusterSlice, err := glusterfs.GetStorage().LoadAllGlusterfsCluster()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all glusterfs cluster failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(glusterfsClusterSlice, "[]GlusterfsCluster")
}
Exemplo n.º 8
0
func deleteGlusterfsCluster(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")

	err := glusterfs.GetStorage().DeleteGlusterfsCluster(cluster)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Delete glusterfs cluster failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["cluster"] = cluster
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Exemplo n.º 9
0
func deleteGlusterfsVolume(request *restful.Request, response *restful.Response) {
	cluster := request.PathParameter("cluster")
	volume := request.PathParameter("volume")

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

	glusterfsVolume, err := glusterfsCluster.GetVolume(volume)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get glusterfs volume failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["cluster"] = cluster
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	err = glusterfsCluster.StopVolume(volume)

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

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

	// Delete data on disk in asynchronized way since it may take hours
	go func() {
		glusterfsCluster.CleanDataOnDisk(glusterfsVolume)
	}()
}