예제 #1
0
//terminate specified hosts of a cluster
// Request
// URL:
// 	PUT /v1/cluster/<CLUSTER_ID>/hosts
// Header:
// 	X-Auth-Token
// Except Body:
//{
//    "host_ids":["568e23655d5c3d173019f1ba","568e2be45d5c3d173019f1bb","568e2bfd5d5c3d173019f1bc","568e2c335d5c3d173019f1bd"]
//}
//
// Response:
//{
//  "success": true
//}
//
func (p *Resource) HostsDeleteHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("HostsDeleteHandler is called!")

	x_auth_token := req.HeaderParameter("X-Auth-Token")
	code, err := services.TokenValidation(x_auth_token)
	if err != nil {
		logrus.Errorln("token validation error is %v", err)
		response.WriteStatusError(code, err, resp)
		return
	}

	clusterId := req.PathParameter(ParamID)
	body := TerminateHostsRequestBody{}
	err = json.NewDecoder(req.Request.Body).Decode(&body)

	errorCode, err := services.GetClusterService().TerminateHosts(clusterId, body.HostIds, x_auth_token)
	if err != nil {
		logrus.Errorln("terminate hosts error is %v", err)
		response.WriteStatusError(errorCode, err, resp)
		return
	}

	// Write success response
	response.WriteSuccess(resp)
	return
}
예제 #2
0
// UserDeleteHandler parses the http request and delete a user.
// Usage :
//		DELETE /v1/user/{ParamID}
// Params :
//		ParamID : storage identifier of user
// If successful,response code will be set to 201.
func (p *Resource) UserDeleteHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("UserDeleteHandler is called!")
	token := req.HeaderParameter("X-Auth-Token")
	id := req.PathParameter(ParamID)
	if len(id) <= 0 {
		logrus.Warnln("user id should not be null for delete operation")
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, errors.New("user id should not be null for delete operation"), resp)
		return
	}

	errorCode, err := services.GetUserService().UserDelete(token, id)
	if err != nil {
		response.WriteStatusError(errorCode, err, resp)
		return
	}

	response.WriteSuccess(resp)
}
예제 #3
0
// TokenValidateHandler parses the http request and return valid user token.
// Usage :
//		GET /v1/token
// If successful,response code will be set to 201.
func (p *Resource) TokenValidateHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("TokenValidateHandler is called!")

	var tokenId = req.QueryParameter("token")
	if len(tokenId) <= 0 {
		logrus.Errorln("invalie parameter! tokenId can not be null for token validation")
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, errors.New("invalie parameter! tokenId can not be null for token validation"), resp)
		return
	}

	errorCode, err := services.GetTokenService().TokenValidate(tokenId)
	if err != nil {
		response.WriteStatusError(errorCode, err, resp)
		return
	}
	response.WriteSuccess(resp)

}
예제 #4
0
func (p *Resource) UserClusterDeleteHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infoln("UserClusterDeleteHandler is called!")
	x_auth_token := req.HeaderParameter("X-Auth-Token")
	code, err := services.TokenValidation(x_auth_token)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	userId := req.QueryParameter("user_id")

	code, err = services.GetClusterService().DeleteByUserId(userId, x_auth_token)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}
	// Write success response
	response.WriteSuccess(resp)
	return
}
예제 #5
0
//Send cluster owner an email of endpoint
func (p *Resource) EmailSendHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infoln("EmailSendHandler is called!")
	x_auth_token := req.HeaderParameter("X-Auth-Token")
	code, err := services.TokenValidation(x_auth_token)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	clusterId := req.PathParameter(ParamID)

	errorCode, err := services.GetEmailService().SendClusterDeployedEmail(clusterId, x_auth_token)
	if err != nil {
		response.WriteStatusError(errorCode, err, resp)
		return
	}
	// Write success response
	response.WriteSuccess(resp)
	return
}
예제 #6
0
func (p *Resource) UserValidateHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infof("UserValidateHandler is called!")
	token := req.HeaderParameter("X-Auth-Token")
	username := req.QueryParameter("username")
	if len(username) == 0 {
		logrus.Warnln("username should not be null")
		response.WriteStatusError(services.COMMON_ERROR_INVALIDATE, errors.New("username should not be null"), resp)
		return
	}
	logrus.Infof("username is %v", username)
	logrus.Infof("start to test username")

	errorCode, _, err := services.GetUserService().Validate(username, token)
	if err != nil {
		response.WriteStatusError(errorCode, err, resp)
		return
	}

	response.WriteSuccess(resp)

}
예제 #7
0
//check username and clustername
func (p *Resource) ClusterNameCheckHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infoln("ClusterNameCheckHandler is called!")
	x_auth_token := req.HeaderParameter("X-Auth-Token")
	code, err := services.TokenValidation(x_auth_token)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	userId := req.QueryParameter("userid")
	clusterName := req.QueryParameter("clustername")

	errorCode, err := services.GetClusterService().CheckClusterName(userId, clusterName, x_auth_token)

	if err != nil {
		response.WriteStatusError(errorCode, err, resp)
		return
	}
	// Write success response
	response.WriteSuccess(resp)
	return
}
예제 #8
0
func (p *Resource) ClustersDeleteHandler(req *restful.Request, resp *restful.Response) {
	logrus.Infoln("UserClusterDeleteHandler is called!")
	x_auth_token := req.HeaderParameter("X-Auth-Token")
	code, err := services.TokenValidation(x_auth_token)
	if err != nil {
		response.WriteStatusError(code, err, resp)
		return
	}

	body := DeleteClustersRequestBody{}
	err = json.NewDecoder(req.Request.Body).Decode(&body)

	errorCode, err := services.GetClusterService().DeleteClusters(body.ClusterIds, x_auth_token)
	if err != nil {
		logrus.Errorln("delete clusters error , [%v]", err)
		response.WriteStatusError(errorCode, err, resp)
		return
	}

	// Write success response
	response.WriteSuccess(resp)
	return
}