Beispiel #1
0
func (repo CloudControllerAppInstancesRepository) GetInstances(appGuid string) (instances []cf.AppInstanceFields, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/apps/%s/instances", repo.config.Target, appGuid)
	request, apiResponse := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
	if apiResponse.IsNotSuccessful() {
		return
	}

	instancesResponse := InstancesApiResponse{}

	_, apiResponse = repo.gateway.PerformRequestForJSONResponse(request, &instancesResponse)
	if apiResponse.IsNotSuccessful() {
		return
	}

	instances = make([]cf.AppInstanceFields, len(instancesResponse), len(instancesResponse))
	for k, v := range instancesResponse {
		index, err := strconv.Atoi(k)
		if err != nil {
			continue
		}

		instances[index] = cf.AppInstanceFields{
			State: cf.InstanceState(strings.ToLower(v.State)),
			Since: time.Unix(int64(v.Since), 0),
		}
	}

	return repo.updateInstancesWithStats(appGuid, instances)
}
Beispiel #2
0
func (repo CloudControllerApplicationRepository) GetInstances(app cf.Application) (instances []cf.ApplicationInstance, apiErr *net.ApiError) {
	path := fmt.Sprintf("%s/v2/apps/%s/instances", repo.config.Target, app.Guid)
	request, apiErr := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
	if apiErr != nil {
		return
	}

	apiResponse := InstancesApiResponse{}

	apiErr = repo.gateway.PerformRequestForJSONResponse(request, &apiResponse)
	if apiErr != nil {
		return
	}

	instances = make([]cf.ApplicationInstance, len(apiResponse), len(apiResponse))
	for k, v := range apiResponse {
		index, err := strconv.Atoi(k)
		if err != nil {
			continue
		}

		instances[index] = cf.ApplicationInstance{
			State: cf.InstanceState(strings.ToLower(v.State)),
			Since: time.Unix(int64(v.Since), 0),
		}
	}
	return
}
Beispiel #3
0
func (repo CloudControllerApplicationRepository) GetInstances(app cf.Application) (instances []cf.ApplicationInstance, errorCode int, err error) {
	path := fmt.Sprintf("%s/v2/apps/%s/instances", repo.config.Target, app.Guid)
	request, err := NewRequest("GET", path, repo.config.AccessToken, nil)
	if err != nil {
		return
	}

	apiResponse := InstancesApiResponse{}

	errorCode, err = repo.apiClient.PerformRequestAndParseResponse(request, &apiResponse)
	if err != nil {
		return
	}

	instances = make([]cf.ApplicationInstance, len(apiResponse), len(apiResponse))
	for k, v := range apiResponse {
		index, err := strconv.Atoi(k)
		if err != nil {
			continue
		}
		instances[index] = cf.ApplicationInstance{State: cf.InstanceState(strings.ToLower(v.State))}
	}
	return
}