예제 #1
0
파일: ipholder.go 프로젝트: zufangzi/chaos
func DeleteIpForContainer(pathParams map[string]string, data []byte) interface{} {
	cId := pathParams["cId"]
	container := mongo.GetContainerInfoById(cId)
	if container.ContainerIp == "" {
		return webUtils.ProcessResponse(http.StatusNotFound, "")
	}
	// 将ip重新push到队列里面去
	ok := redis.Lpush(IP_QUEUE, container.ContainerIp)
	if !ok {
		log.Fatalln("[CHAOS]push to queue error!")
	}
	return webUtils.ProcessResponse(http.StatusOK, "")
}
예제 #2
0
파일: apps.go 프로젝트: zufangzi/chaos
func CreateAppsHandler(pathParams map[string]string, data []byte) interface{} {
	var request entity.DeployAppsRequest
	webUtils.ParseOuterRequest(data, &request)
	deployInfo := webUtils.BuildAppsRequest(request)
	var resData map[string]interface{}
	resCode := fasthttp.JsonReqAndResHandler(common.Path.MarathonAppsUrl, deployInfo, &resData, "POST")
	return webUtils.ProcessResponse(resCode, resData)
}
예제 #3
0
파일: ipholder.go 프로젝트: zufangzi/chaos
func CreateIpForContainer(pathParams map[string]string, data []byte) interface{} {
	cId := pathParams["cId"]
	// 查一下库里面是不是已经有了。有了的话直接返回。
	container := mongo.GetContainerInfoById(cId)
	if container.ContainerIp != "" {
		return webUtils.ProcessResponseFully(http.StatusOK, container.ContainerIp, false)
	}
	// 如果库里没有,那么就从redis的队列里面拿一个,然后存到mongo里,最后返回
	ip := redis.Rpop(IP_QUEUE)
	if ip != "" {
		return saveAndReturnIp(container, ip)
	}
	// 如果库里没有,而且redis队列也空了,那么就触发一次队列更新。如果队列没有,那么返回异常code。由请求方自行处理。
	if !triggerRedisQueueUpdated() {
		return webUtils.ProcessResponse(http.StatusNotFound, "")
	}
	// 如果有,那么就开始处理。可能存在高并发的场景,刷完之后又被其他请求先抢了。这里就不加锁了,由客户端来判断,如果内容
	ip = redis.Rpop(IP_QUEUE)
	if ip == "" {
		return webUtils.ProcessResponse(http.StatusNotFound, "")
	}
	// 保存ip并返回
	return saveAndReturnIp(container, ip)
}
예제 #4
0
파일: apps.go 프로젝트: zufangzi/chaos
// 逻辑为:放入仓库的时候,即每个模块携带时间戳,每次前端构建时候传入比如zookeeper
// 则后端则从私库里捞出zookeeper所有模块,并按时间倒叙取出最新的zk模块镜像进行部署
// 则,在回滚时候,捞出倒数第二新的模块进行重新部署。部署时候更新labels即可。
func RollbackAppsHandler(pathParams map[string]string, data []byte) interface{} {
	var request entity.RollbackAppsBatchRequest
	webUtils.ParseOuterRequest(data, &request)

	requestBatch := make([]entity.DeployAppsRequest, len(request.Batch))
	for i, v := range request.Batch {
		// TODO 通过ID把Image信息拿到,暂时认为ID和Image是等价的
		_, image, tag := common.DockerClient.GetPreviousImageAndTag(v.Id, v.Version, "")
		var request entity.DeployAppsRequest
		request.Id = v.Id
		request.Image = image
		request.Version = tag
		requestBatch[i] = request
	}
	appsBatchRequest := entity.DeployAppsBatchRequest{}
	appsBatchRequest.Batch = requestBatch
	resData, code := createOrUpdateAppsService(appsBatchRequest)
	return webUtils.ProcessResponse(code, resData)
}
예제 #5
0
파일: groups.go 프로젝트: zufangzi/chaos
func DeployGroupsHandler(pathParams map[string]string, data []byte) interface{} {
	var request entity.DeployGroupsRequest
	webUtils.ParseOuterRequest(data, &request)

	var groupsRequest marathon.MarathonGroupsRequest
	groupsRequest.Id = request.Id
	perGroups := make([]marathon.MarathonGroupsInfo, len(request.Groups))
	for i, v := range request.Groups {
		var group marathon.MarathonGroupsInfo
		group.Id = v.Id
		perApps := make([]marathon.MarathonAppsRequest, len(v.Apps))
		for j, app := range v.Apps {
			perApps[j] = *webUtils.BuildAppsRequest(app)
		}
		group.Apps = perApps
		perGroups[i] = group
	}
	groupsRequest.Groups = perGroups
	var resData map[string]interface{}
	resCode := fasthttp.JsonReqAndResHandler(common.Path.MarathonGroupsUrl, groupsRequest, &resData, "POST")
	return webUtils.ProcessResponse(resCode, resData)
}
예제 #6
0
파일: apps.go 프로젝트: zufangzi/chaos
func DeleteAppsHandler(pathParams map[string]string, data []byte) interface{} {
	appId := pathParams["appId"]
	var resData map[string]interface{}
	resCode := fasthttp.JsonReqAndResHandler(common.Path.MarathonAppsUrl+"/"+appId, nil, &resData, "DELETE")
	return webUtils.ProcessResponse(resCode, resData)
}
예제 #7
0
파일: apps.go 프로젝트: zufangzi/chaos
func CreateOrUpdateAppsHandler(pathParams map[string]string, data []byte) interface{} {
	var request entity.DeployAppsBatchRequest
	webUtils.ParseOuterRequest(data, &request)
	resData, resCode := createOrUpdateAppsService(request)
	return webUtils.ProcessResponse(resCode, resData)
}