コード例 #1
0
func (p *Resource) CreateClusterHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("CreateClusterHandler is called!")

	// Stub an repairpolicy to be populated from the body
	request := entity.Request{}

	// Populate the user data
	err := json.NewDecoder(req.Request.Body).Decode(&request)

	logrus.Infof("Request is %v", request)
	logrus.Infof("ProviderInfo is %v", request.ProviderInfo)
	logrus.Infof("AwsEC2Info is %v", request.ProviderInfo.AwsEC2Info)

	if err != nil {
		logrus.Errorf("convert body to request failed, error is %v", err)
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, err, resp)
		return
	}

	servers, code, err := services.GetDeployService().CreateCluster(request)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	res := response.Response{Success: true, Data: servers}
	resp.WriteEntity(res)
	return
}
コード例 #2
0
func (p *Resource) DeleteClusterHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("DeleteClusterHandler is called!")

	// Stub an repairpolicy to be populated from the body
	request := entity.DeleteRequest{}

	// Populate the user data
	err := json.NewDecoder(req.Request.Body).Decode(&request)

	logrus.Infof("Username is %v", request.UserName)
	logrus.Infof("Cluster is %v", request.ClusterName)
	logrus.Infof("Servers is %v", request.Servers)

	if err != nil {
		logrus.Errorf("convert body to DeleteClusterRequest failed, error is %v", err)
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, err, resp)
		return
	}

	code, err := services.GetDeployService().DeleteCluster(request.UserName, request.ClusterName, request.Servers)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	res := response.Response{Success: true}
	resp.WriteEntity(res)
	return
}
コード例 #3
0
func (p *Resource) AddNodesHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("AddNodesHandler is called!")

	// Stub an repairpolicy to be populated from the body
	request := entity.AddNodeRequest{}

	// Populate the user data
	err := json.NewDecoder(req.Request.Body).Decode(&request)

	logrus.Infof("Username is %v", request.UserName)
	logrus.Infof("Cluster is %v", request.ClusterName)
	logrus.Infof("CreateNumber is %v", request.CreateNumber)

	if err != nil {
		logrus.Errorf("convert body to AddNodesRequest failed, error is %v", err)
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, err, resp)
		return
	}

	servers, code, err := services.GetDeployService().CreateNode(request)

	var res response.Response
	if err != nil {
		errObj := response.Error{Code: code, ErrorMsg: fmt.Sprintf("%v", err)}
		res = response.Response{Success: true, Error: &errObj, Data: servers}
	} else {
		res = response.Response{Success: true, Data: servers}
	}

	resp.WriteEntity(res)
	return
}