Esempio n. 1
0
func MaskContainerInfo(pathParams map[string]string, data []byte) interface{} {
	request := make(map[string]int)
	cId := pathParams["cId"]
	request["state"] = model.CONTAINER_STATE_DELETE
	mongo.UpdateContainerByIdUsingMap(cId, request)
	return webUtils.ProcessResponseFully(http.StatusOK, nil, true)
}
Esempio n. 2
0
func GetInfoAppsHandler(pathParams map[string]string, data []byte) interface{} {
	var marathonApps marathon.MarathonAppsGlobalInfoResponse
	fasthttp.JsonReqAndResHandler(common.Path.MarathonAppsUrl, nil, &marathonApps, "GET")
	appsCnt := len(marathonApps.Apps)

	// should not code like this: appsGlobalInfos := [appsCnt]entity.AppsGlobalInfo{}
	appsGlobalInfos := make([]entity.AppsGlobalInfoResponse, appsCnt)

	for i, v := range marathonApps.Apps {
		var perApp entity.AppsGlobalInfoResponse
		if strings.LastIndex(v.Id, "/") == -1 {
			perApp.Id = v.Id
		} else {
			perApp.Id = v.Id[strings.LastIndex(v.Id, "/")+1:]
		}
		perApp.Cpus = strconv.FormatFloat(v.Cpus, 'f', 1, 64)
		perApp.CurrentInstances = strconv.Itoa(v.TasksRunning)
		if strings.LastIndex(v.Id, "/") <= 0 { // exclude like /zk or zk
			perApp.Group = "No Groups"
		} else {
			perApp.Group = v.Id[0:strings.LastIndex(v.Id, "/")]
		}
		perApp.Instances = strconv.Itoa(v.Instances)
		perApp.Mem = strconv.FormatFloat(v.Mem, 'f', 1, 64)
		perApp.Healthy = strconv.FormatFloat(100*float64(v.TasksRunning)/float64(v.Instances), 'f', 1, 64)
		perApp.FormatStatus(v.TasksStaged)
		appsGlobalInfos[i] = perApp
	}
	return webUtils.ProcessResponseFully(http.StatusOK, appsGlobalInfos, false)
}
Esempio n. 3
0
func UpdateStateContainerInfo(pathParams map[string]string, data []byte) interface{} {
	request := make(map[string]int)
	cId := pathParams["cId"]
	cState := pathParams["cState"]
	request["state"], _ = strconv.Atoi(cState)
	mongo.UpdateContainerByIdUsingMap(cId, request)
	return webUtils.ProcessResponseFully(http.StatusOK, nil, true)
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
func CreateContainerInfo(pathParams map[string]string, data []byte) interface{} {
	var request model.Container
	webUtils.ParseOuterRequest(data, &request)
	mongo.InsertContainer(request)
	return webUtils.ProcessResponseFully(http.StatusOK, nil, true)
}
Esempio n. 6
0
func saveAndReturnIp(container model.Container, ip string) interface{} {
	container.ContainerIp = ip
	mongo.UpdateContainerById(container.BizId, container)
	return webUtils.ProcessResponseFully(http.StatusOK, ip, false)
}