Пример #1
0
func (cmd *CreateRoute) CreateRoute(hostName string, path string, domain models.DomainFields, space models.SpaceFields) (models.Route, error) {
	cmd.ui.Say(T("Creating route {{.URL}} for org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
		map[string]interface{}{
			"URL":       terminal.EntityNameColor(domain.UrlForHostAndPath(hostName, path)),
			"OrgName":   terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
			"SpaceName": terminal.EntityNameColor(space.Name),
			"Username":  terminal.EntityNameColor(cmd.config.Username())}))

	route, err := cmd.routeRepo.CreateInSpace(hostName, path, domain.Guid, space.Guid)
	if err != nil {
		var findErr error
		route, findErr = cmd.routeRepo.Find(hostName, domain, path)
		if findErr != nil {
			return models.Route{}, err
		}

		if route.Space.Guid != space.Guid || route.Domain.Guid != domain.Guid {
			return models.Route{}, err
		}

		cmd.ui.Ok()
		cmd.ui.Warn(T("Route {{.URL}} already exists",
			map[string]interface{}{"URL": route.URL()}))

		return route, nil
	}

	cmd.ui.Ok()

	return route, nil
}
Пример #2
0
func (routeActor routeActor) FindOrCreateRoute(hostname string, domain models.DomainFields, path string, useRandomPort bool) (models.Route, error) {
	var port int
	route, err := routeActor.routeRepo.Find(hostname, domain, path, port)

	switch err.(type) {
	case nil:
		routeActor.ui.Say(
			T("Using route {{.RouteURL}}",
				map[string]interface{}{
					"RouteURL": terminal.EntityNameColor(route.URL()),
				}),
		)
	case *errors.ModelNotFoundError:
		if useRandomPort {
			route, err = routeActor.CreateRandomTCPRoute(domain)
		} else {
			routeActor.ui.Say(
				T("Creating route {{.Hostname}}...",
					map[string]interface{}{
						"Hostname": terminal.EntityNameColor(domain.URLForHostAndPath(hostname, path, port)),
					}),
			)

			route, err = routeActor.routeRepo.Create(hostname, domain, path, useRandomPort)
		}

		routeActor.ui.Ok()
		routeActor.ui.Say("")
	}

	return route, err
}
Пример #3
0
func (cmd *CreateRoute) CreateRoute(hostName string, domain models.DomainFields, space models.SpaceFields) (route models.Route, apiErr error) {
	cmd.ui.Say(T("Creating route {{.Hostname}} for org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
		map[string]interface{}{
			"Hostname":  terminal.EntityNameColor(domain.UrlForHost(hostName)),
			"OrgName":   terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
			"SpaceName": terminal.EntityNameColor(space.Name),
			"Username":  terminal.EntityNameColor(cmd.config.Username())}))

	route, apiErr = cmd.routeRepo.CreateInSpace(hostName, domain.Guid, space.Guid)
	if apiErr != nil {
		var findApiResponse error
		route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain)

		if findApiResponse != nil ||
			route.Space.Guid != space.Guid ||
			route.Domain.Guid != domain.Guid {
			return
		}

		apiErr = nil
		cmd.ui.Ok()
		cmd.ui.Warn(T("Route {{.URL}} already exists",
			map[string]interface{}{"URL": route.URL()}))
		return
	}

	cmd.ui.Ok()
	return
}
Пример #4
0
func (cmd *CreateRoute) CreateRoute(hostName string, domain models.DomainFields, space models.SpaceFields) (route models.Route, apiErr error) {
	cmd.ui.Say("Creating route %s for org %s / space %s as %s...",
		terminal.EntityNameColor(domain.UrlForHost(hostName)),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	route, apiErr = cmd.routeRepo.CreateInSpace(hostName, domain.Guid, space.Guid)
	if apiErr != nil {
		var findApiResponse error
		route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain)

		if findApiResponse != nil ||
			route.Space.Guid != space.Guid ||
			route.Domain.Guid != domain.Guid {
			return
		}

		apiErr = nil
		cmd.ui.Ok()
		cmd.ui.Warn("Route %s already exists", route.URL())
		return
	}

	cmd.ui.Ok()
	return
}
Пример #5
0
func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"

	domain := models.DomainFields{}
	domain.Name = "example.com"

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.Stack = &models.Stack{
		Name: "fake_stack",
		Guid: "123-123-123",
	}
	application.Routes = []models.RouteSummary{route, secondRoute}
	application.PackageUpdatedAt = &packgeUpdatedAt

	return application
}
Пример #6
0
func makeAppWithOptions(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"
	application.Command = "run main.go"
	application.BuildpackUrl = "go-buildpack"

	domain := models.DomainFields{}
	domain.Name = "example.com"

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}
	packgeUpdatedAt, _ := time.Parse("2006-01-02T15:04:05Z07:00", "2012-10-24T19:54:00Z")

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.HealthCheckTimeout = 100
	application.Routes = []models.RouteSummary{route, secondRoute}
	application.PackageUpdatedAt = &packgeUpdatedAt

	envMap := make(map[string]interface{})
	envMap["foo"] = "bar"
	application.EnvironmentVars = envMap

	application.Services = append(application.Services, models.ServicePlanSummary{
		Guid: "",
		Name: "server1",
	})

	return application
}
Пример #7
0
func fakeDomainRepo() *testapi.FakeDomainRepository {
	domain := models.DomainFields{}
	domain.Name = "foo.com"
	domain.Guid = "foo-guid"
	domain.Shared = true

	return &testapi.FakeDomainRepository{
		FindByNameInOrgDomain: domain,
	}
}
func (resource RouteSummary) ToModel() (route models.RouteSummary) {
	domain := models.DomainFields{}
	domain.Guid = resource.Domain.Guid
	domain.Name = resource.Domain.Name
	domain.Shared = resource.Domain.OwningOrganizationGuid != ""

	route.Guid = resource.Guid
	route.Host = resource.Host
	route.Domain = domain
	return
}
Пример #9
0
func (resource RouteSummary) ToModel() (route models.RouteSummary) {
	domain := models.DomainFields{}
	domain.GUID = resource.Domain.GUID
	domain.Name = resource.Domain.Name
	domain.Shared = resource.Domain.OwningOrganizationGUID != ""

	route.GUID = resource.GUID
	route.Host = resource.Host
	route.Path = resource.Path
	route.Port = resource.Port
	route.Domain = domain
	return
}
Пример #10
0
func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"

	domain := models.DomainFields{}
	domain.Name = "example.com"

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.Routes = []models.RouteSummary{route, secondRoute}

	return application
}
Пример #11
0
func (routeActor RouteActor) FindOrCreateRoute(hostname string, domain models.DomainFields) (route models.Route) {
	route, apiErr := routeActor.routeRepo.FindByHostAndDomain(hostname, domain)

	switch apiErr.(type) {
	case nil:
		routeActor.ui.Say("Using route %s", terminal.EntityNameColor(route.URL()))
	case *errors.ModelNotFoundError:
		routeActor.ui.Say("Creating route %s...", terminal.EntityNameColor(domain.UrlForHost(hostname)))

		route, apiErr = routeActor.routeRepo.Create(hostname, domain)
		if apiErr != nil {
			routeActor.ui.Failed(apiErr.Error())
		}

		routeActor.ui.Ok()
		routeActor.ui.Say("")
	default:
		routeActor.ui.Failed(apiErr.Error())
	}

	return
}
Пример #12
0
func (routeActor routeActor) FindOrCreateRoute(hostname string, domain models.DomainFields, path string, port int, useRandomPort bool) (models.Route, error) {
	var route models.Route
	var err error
	//if tcp route use random port should skip route lookup
	if useRandomPort && domain.RouterGroupType == tcp {
		err = new(errors.ModelNotFoundError)
	} else {
		route, err = routeActor.routeRepo.Find(hostname, domain, path, port)
	}

	switch err.(type) {
	case nil:
		routeActor.ui.Say(
			T("Using route {{.RouteURL}}",
				map[string]interface{}{
					"RouteURL": terminal.EntityNameColor(route.URL()),
				}),
		)
	case *errors.ModelNotFoundError:
		if useRandomPort && domain.RouterGroupType == tcp {
			route, err = routeActor.CreateRandomTCPRoute(domain)
		} else {
			routeActor.ui.Say(
				T("Creating route {{.Hostname}}...",
					map[string]interface{}{
						"Hostname": terminal.EntityNameColor(domain.URLForHostAndPath(hostname, path, port)),
					}),
			)

			route, err = routeActor.routeRepo.Create(hostname, domain, path, port, false)
		}

		routeActor.ui.Ok()
		routeActor.ui.Say("")
	}

	return route, err
}
Пример #13
0
			runCommand("some-space")
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Context("when logged in and an org is targeted", func() {
		BeforeEach(func() {
			org := models.OrganizationFields{}
			org.Name = "my-org"

			app := models.ApplicationFields{}
			app.Name = "app1"
			app.Guid = "app1-guid"
			apps := []models.ApplicationFields{app}

			domain := models.DomainFields{}
			domain.Name = "domain1"
			domain.Guid = "domain1-guid"
			domains := []models.DomainFields{domain}

			serviceInstance := models.ServiceInstanceFields{}
			serviceInstance.Name = "service1"
			serviceInstance.Guid = "service1-guid"
			services := []models.ServiceInstanceFields{serviceInstance}

			securityGroup1 := models.SecurityGroupFields{Name: "Nacho Security"}
			securityGroup2 := models.SecurityGroupFields{Name: "Nacho Prime"}
			securityGroups := []models.SecurityGroupFields{securityGroup1, securityGroup2}

			space := models.Space{}
			space.Name = "whose-space-is-it-anyway"
Пример #14
0
			Expect(routes[1].Guid).To(Equal("route-2-guid"))
			Expect(handler).To(HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())
		})

		It("finds a route by host and domain", func() {
			ts, handler = testnet.NewServer([]testnet.TestRequest{
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/routes?q=host%3Amy-cool-app%3Bdomain_guid%3Amy-domain-guid",
					Response: findRouteByHostResponse,
				}),
			})
			configRepo.SetApiEndpoint(ts.URL)

			domain := models.DomainFields{}
			domain.Guid = "my-domain-guid"

			route, apiErr := repo.FindByHostAndDomain("my-cool-app", domain)

			Expect(apiErr).NotTo(HaveOccurred())
			Expect(handler).To(HaveAllRequestsCalled())
			Expect(route.Host).To(Equal("my-cool-app"))
			Expect(route.Guid).To(Equal("my-route-guid"))
			Expect(route.Domain.Guid).To(Equal(domain.Guid))
		})

		It("returns 'not found' response when there is no route w/ the given domain and host", func() {
			ts, handler = testnet.NewServer([]testnet.TestRequest{
				testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
Пример #15
0
		appRepo = &testApplication.FakeApplicationRepository{}

		displayApp = &appCmdFakes.FakeAppDisplayer{}

		//save original command dependency and restore later
		OriginalAppCommand = command_registry.Commands.FindCommand("app")

		defaultInstanceErrorCodes = []string{"", ""}

		defaultAppForStart = models.Application{}
		defaultAppForStart.Name = "my-app"
		defaultAppForStart.Guid = "my-app-guid"
		defaultAppForStart.InstanceCount = 2
		defaultAppForStart.PackageState = "STAGED"

		domain := models.DomainFields{}
		domain.Name = "example.com"

		route := models.RouteSummary{}
		route.Host = "my-app"
		route.Domain = domain

		defaultAppForStart.Routes = []models.RouteSummary{route}

		instance1 := models.AppInstanceFields{}
		instance1.State = models.InstanceStarting

		instance2 := models.AppInstanceFields{}
		instance2.State = models.InstanceStarting

		instance3 := models.AppInstanceFields{}
Пример #16
0
func (routeActor RouteActor) FindOrCreateRoute(hostname string, domain models.DomainFields, path string) (route models.Route) {
	var port int
	route, apiErr := routeActor.routeRepo.Find(hostname, domain, path, port)

	switch apiErr.(type) {
	case nil:
		routeActor.ui.Say(T("Using route {{.RouteURL}}", map[string]interface{}{"RouteURL": terminal.EntityNameColor(route.URL())}))
	case *errors.ModelNotFoundError:
		routeActor.ui.Say(T("Creating route {{.Hostname}}...", map[string]interface{}{"Hostname": terminal.EntityNameColor(domain.UrlForHostAndPath(hostname, path))}))

		route, apiErr = routeActor.routeRepo.Create(hostname, domain, path)
		if apiErr != nil {
			routeActor.ui.Failed(apiErr.Error())
		}

		routeActor.ui.Ok()
		routeActor.ui.Say("")
	default:
		routeActor.ui.Failed(apiErr.Error())
	}

	return
}
Пример #17
0
		args := []string{"my-org"}
		ui := callShowOrg(args, requirementsFactory)
		Expect(ui.FailedWithUsage).To(BeFalse())

		args = []string{}
		ui = callShowOrg(args, requirementsFactory)
		Expect(ui.FailedWithUsage).To(BeTrue())
	})
	It("TestRunWhenOrganizationExists", func() {

		developmentSpaceFields := models.SpaceFields{}
		developmentSpaceFields.Name = "development"
		stagingSpaceFields := models.SpaceFields{}
		stagingSpaceFields.Name = "staging"
		domainFields := models.DomainFields{}
		domainFields.Name = "cfapps.io"
		cfAppDomainFields := models.DomainFields{}
		cfAppDomainFields.Name = "cf-app.com"
		org := models.Organization{}
		org.Name = "my-org"
		org.Guid = "my-org-guid"
		org.QuotaDefinition = models.NewQuotaFields("cantina-quota", 512, 2, 5, true)
		org.Spaces = []models.SpaceFields{developmentSpaceFields, stagingSpaceFields}
		org.Domains = []models.DomainFields{domainFields, cfAppDomainFields}

		requirementsFactory := &testreq.FakeReqFactory{Organization: org, LoginSuccess: true}

		args := []string{"my-org"}
		ui := callShowOrg(args, requirementsFactory)
Пример #18
0
		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Creating route"},
			[]string{"OK"},
			[]string{"host.example.com", "already exists"},
		))

		Expect(routeRepo.CreateInSpaceHost).To(Equal("host"))
		Expect(routeRepo.CreateInSpaceDomainGuid).To(Equal("domain-guid"))
		Expect(routeRepo.CreateInSpaceSpaceGuid).To(Equal("my-space-guid"))
	})

	It("TestRouteCreator", func() {
		space := models.SpaceFields{}
		space.Guid = "my-space-guid"
		space.Name = "my-space"
		domain := models.DomainFields{}
		domain.Guid = "domain-guid"
		domain.Name = "example.com"

		createdRoute := models.Route{}
		createdRoute.Host = "my-host"
		createdRoute.Guid = "my-route-guid"
		routeRepo := &testapi.FakeRouteRepository{
			CreateInSpaceCreatedRoute: createdRoute,
		}

		ui := new(testterm.FakeUI)
		configRepo := testconfig.NewRepositoryWithAccessToken(configuration.TokenInfo{Username: "******"})
		orgFields := models.OrganizationFields{}
		orgFields.Name = "my-org"
		configRepo.SetOrganizationFields(orgFields)
Пример #19
0
				v.Set("inline-relations-depth", "1")
				v.Set("q", "host:my-cool-app;domain_guid:my-domain-guid;path:/somepath")

				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/v2/routes", v.Encode()),
						ghttp.VerifyHeader(http.Header{
							"accept": []string{"application/json"},
						}),
						ghttp.RespondWith(http.StatusCreated, findResponseBodyForHostAndDomainAndPath),
					),
				)
			})

			It("returns the route", func() {
				domain := models.DomainFields{}
				domain.GUID = "my-domain-guid"

				route, apiErr := repo.Find("my-cool-app", domain, "somepath", 0)

				Expect(apiErr).NotTo(HaveOccurred())
				Expect(route.Host).To(Equal("my-cool-app"))
				Expect(route.GUID).To(Equal("my-route-guid"))
				Expect(route.Path).To(Equal("/somepath"))
				Expect(route.Port).To(Equal(0))
				Expect(route.Domain.GUID).To(Equal(domain.GUID))
			})
		})

		Context("when the path is empty", func() {
			BeforeEach(func() {
Пример #20
0
			runCommand("too", "much")
			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Incorrect Usage", "Requires an argument"},
			))
		})
	})

	Context("when logged in, and provided the name of an org", func() {
		BeforeEach(func() {
			developmentSpaceFields := models.SpaceFields{}
			developmentSpaceFields.Name = "development"
			developmentSpaceFields.Guid = "dev-space-guid-1"
			stagingSpaceFields := models.SpaceFields{}
			stagingSpaceFields.Name = "staging"
			stagingSpaceFields.Guid = "staging-space-guid-1"
			domainFields := models.DomainFields{}
			domainFields.Name = "cfapps.io"
			domainFields.Guid = "1111"
			domainFields.OwningOrganizationGuid = "my-org-guid"
			domainFields.Shared = true
			cfAppDomainFields := models.DomainFields{}
			cfAppDomainFields.Name = "cf-app.com"
			cfAppDomainFields.Guid = "2222"
			cfAppDomainFields.OwningOrganizationGuid = "my-org-guid"
			cfAppDomainFields.Shared = false

			org := models.Organization{}
			org.Name = "my-org"
			org.Guid = "my-org-guid"
			org.QuotaDefinition = models.NewQuotaFields("cantina-quota", 512, 256, 2, 5, true)
			org.Spaces = []models.SpaceFields{developmentSpaceFields, stagingSpaceFields}