Exemple #1
0
func (cmd *CreateRoute) CreateRoute(hostName string, domain cf.Domain, space cf.Space) (route cf.Route, apiResponse net.ApiResponse) {
	routeToCreate := cf.Route{Host: hostName, Domain: domain}

	cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
		terminal.EntityNameColor(routeToCreate.URL()),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	route, apiResponse = cmd.routeRepo.CreateInSpace(routeToCreate, domain, space)
	if apiResponse.IsNotSuccessful() {
		var findApiResponse net.ApiResponse
		route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain.Name)

		if findApiResponse.IsNotSuccessful() ||
			route.Space.Guid != space.Guid ||
			route.Domain.Guid != domain.Guid ||
			route.Host != hostName {
			return
		}

		apiResponse = net.NewSuccessfulApiResponse()
		cmd.ui.Ok()
		cmd.ui.Warn("Route %s already exists", route.URL())
		return
	}

	cmd.ui.Ok()
	return
}
Exemple #2
0
func (repo CloudControllerApplicationRepository) FindByName(name string) (app cf.Application, apiErr *net.ApiError) {
	path := fmt.Sprintf("%s/v2/spaces/%s/apps?q=name%s&inline-relations-depth=1", repo.config.Target, repo.config.Space.Guid, "%3A"+name)
	request, apiErr := repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
	if apiErr != nil {
		return
	}

	findResponse := new(ApplicationsApiResponse)
	apiErr = repo.gateway.PerformRequestForJSONResponse(request, findResponse)
	if apiErr != nil {
		return
	}

	if len(findResponse.Resources) == 0 {
		apiErr = net.NewApiErrorWithMessage(fmt.Sprintf("Application %s not found", name))
		return
	}

	res := findResponse.Resources[0]
	path = fmt.Sprintf("%s/v2/apps/%s/summary", repo.config.Target, res.Metadata.Guid)
	request, apiErr = repo.gateway.NewRequest("GET", path, repo.config.AccessToken, nil)
	if apiErr != nil {
		return
	}

	summaryResponse := new(ApplicationSummary)
	apiErr = repo.gateway.PerformRequestForJSONResponse(request, summaryResponse)
	if apiErr != nil {
		return
	}

	urls := []string{}
	// This is a little wonky but we made a concious effort
	// to keep the domain very separate from the API repsonses
	// to maintain flexibility.
	domainRoute := cf.Route{}
	for _, route := range summaryResponse.Routes {
		domainRoute.Domain = cf.Domain{Name: route.Domain.Name}
		domainRoute.Host = route.Host
		urls = append(urls, domainRoute.URL())
	}

	app = cf.Application{
		Name:             summaryResponse.Name,
		Guid:             summaryResponse.Guid,
		Instances:        summaryResponse.Instances,
		RunningInstances: summaryResponse.RunningInstances,
		Memory:           summaryResponse.Memory,
		EnvironmentVars:  res.Entity.EnvironmentJson,
		Urls:             urls,
		State:            strings.ToLower(summaryResponse.State),
	}

	return
}
Exemple #3
0
func (repo CloudControllerApplicationRepository) FindByName(name string) (app cf.Application, err error) {
	path := fmt.Sprintf("%s/v2/spaces/%s/apps?q=name%s&inline-relations-depth=1", repo.config.Target, repo.config.Space.Guid, "%3A"+name)
	request, err := NewRequest("GET", path, repo.config.AccessToken, nil)
	if err != nil {
		return
	}

	findResponse := new(ApplicationsApiResponse)
	_, err = repo.apiClient.PerformRequestAndParseResponse(request, findResponse)
	if err != nil {
		return
	}

	if len(findResponse.Resources) == 0 {
		err = errors.New(fmt.Sprintf("Application %s not found", name))
		return
	}

	res := findResponse.Resources[0]
	path = fmt.Sprintf("%s/v2/apps/%s/summary", repo.config.Target, res.Metadata.Guid)
	request, err = NewRequest("GET", path, repo.config.AccessToken, nil)
	if err != nil {
		return
	}

	summaryResponse := new(ApplicationSummary)
	_, err = repo.apiClient.PerformRequestAndParseResponse(request, summaryResponse)
	if err != nil {
		return
	}

	urls := []string{}
	// This is a little wonky but we made a concious effort
	// to keep the domain very separate from the API repsonses
	// to maintain flexibility.
	domainRoute := cf.Route{}
	for _, route := range summaryResponse.Routes {
		domainRoute.Domain = cf.Domain{Name: route.Domain.Name}
		domainRoute.Host = route.Host
		urls = append(urls, domainRoute.URL())
	}

	app = cf.Application{
		Name:      summaryResponse.Name,
		Guid:      summaryResponse.Guid,
		Instances: summaryResponse.Instances,
		Memory:    summaryResponse.Memory,
		Urls:      urls,
	}

	return
}
Exemple #4
0
func (cmd Push) createRoute(hostName string, domain cf.Domain) (route cf.Route) {
	newRoute := cf.Route{Host: hostName, Domain: domain}

	cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(newRoute.URL()))

	route, apiResponse := cmd.routeRepo.Create(newRoute, domain)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	return
}