Beispiel #1
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)
}
Beispiel #2
0
func maskContainerInfo(cId string) {
	var resData map[string]interface{}
	fasthttp.JsonReqAndResHandler(PATH_CONTAINER+"/soft/"+cId, nil, &resData, "DELETE")
	if int(resData["status"].(float64)) != http.StatusOK {
		log.Println("[CHAOSWHISPER] mask container info fail... CID: " + cId)
	}
}
Beispiel #3
0
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)
}
Beispiel #4
0
func delIp(cId string) {
	var resData map[string]interface{}
	uri := fmt.Sprintf(PATH_IPHOLDER, cId)
	fasthttp.JsonReqAndResHandler(uri, nil, &resData, "DELETE")
	if int(resData["status"].(float64)) != http.StatusOK {
		log.Println("[CHAOSWHISPER] delete ip fail... CID: " + cId)
	}
}
Beispiel #5
0
func updateState(cId string, cState int) {
	log.Printf("[REGISTRATOR]now begin to update state, cid: %s, cstate: %s %n", cId, cState)
	var resData map[string]interface{}
	uri := fmt.Sprintf(PATH_CONTAINER_STATE, cId, cState)
	fasthttp.JsonReqAndResHandler(uri, make(map[string]interface{}), &resData, "POST")
	if int(resData["status"].(float64)) != http.StatusOK {
		log.Println("[CHAOSWHISPER] request cloud server fail... CID: " + cId)
	}
}
Beispiel #6
0
func createOrUpdateAppsService(request entity.DeployAppsBatchRequest) (interface{}, int) {
	finalRequest := make([]marathon.MarathonAppsRequest, len(request.Batch))
	for i, v := range request.Batch {
		deployInfo := webUtils.BuildAppsRequest(v)
		finalRequest[i] = *deployInfo
	}
	var response map[string]interface{}
	code := fasthttp.JsonReqAndResHandler(common.Path.MarathonAppsUrl, finalRequest, &response, "PUT")
	return response, code
}
Beispiel #7
0
func getIp(cId string) string {
	var resData map[string]interface{}
	uri := fmt.Sprintf(PATH_IPHOLDER, cId)
	fasthttp.JsonReqAndResHandler(uri, nil, &resData, "GET")
	if int(resData["status"].(float64)) == http.StatusOK {
		return resData["data"].(string)
	} else {
		// ALARM. TODO
		return "127.0.0.1"
	}
}
Beispiel #8
0
func storeContainerInfo(cId string) {
	var resData map[string]interface{}
	var request mongo.Container
	request.BizId = cId
	docker, _ := dockerClient.InspectContainer(cId)
	request.BizName = docker.Name
	request.State = mongo.CONTAINER_STATE_STARTED
	fasthttp.JsonReqAndResHandler(PATH_CONTAINER, request, &resData, "POST")
	if int(resData["status"].(float64)) != http.StatusOK {
		log.Println("[CHAOSWHISPER] store container info fail... CID: " + cId)
	}
}
Beispiel #9
0
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)
}
Beispiel #10
0
func (f *FastDocker) GetImageAndTagByFreshness(repository string, version string, tagStyle string, previous int, needHttpPrefix bool) (string, string, string) {
	if version != "" {
		return sweepHttpPrefix(Path.DockerRegistryUrl+"/"+repository+":"+version, needHttpPrefix)
	}
	uri := fmt.Sprintf(Path.DockerRegistrySearchUrl, repository)
	var res docker.DockerRegistryTagsResponse
	fasthttp.JsonReqAndResHandler(uri, nil, &res, "GET")
	if tagStyle == "" {
		tagStyle = IMAGES_TAG_STYLE_SIMPLE
	}

	if len(res.Tags) == 1 {
		return sweepHttpPrefix(Path.DockerRegistryUrl+"/"+repository+":"+res.Tags[0], needHttpPrefix)
	}

	tagArray := make([]int, len(res.Tags))
	for i, v := range res.Tags {
		tagArray[i], _ = strconv.Atoi(v)
	}

	sort.Ints(tagArray)
	fullImage := Path.DockerRegistryUrl + "/" + repository + ":" + strconv.Itoa(tagArray[len(tagArray)-1-previous])
	return sweepHttpPrefix(fullImage, needHttpPrefix)
}
Beispiel #11
0
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)
}