示例#1
0
func mergeDesiredActualLRPs(desiredLRPs []receptor.DesiredLRPResponse, actualLRPs []receptor.ActualLRPResponse) map[string]*AppInfo {
	appMap := make(map[string]*AppInfo)

	for _, desiredLRP := range desiredLRPs {
		appMap[desiredLRP.ProcessGuid] = &AppInfo{
			ProcessGuid:            desiredLRP.ProcessGuid,
			DesiredInstances:       desiredLRP.Instances,
			ActualRunningInstances: 0,
			EnvironmentVariables:   buildEnvVars(desiredLRP),
			StartTimeout:           desiredLRP.StartTimeout,
			DiskMB:                 desiredLRP.DiskMB,
			MemoryMB:               desiredLRP.MemoryMB,
			CPUWeight:              desiredLRP.CPUWeight,
			Ports:                  desiredLRP.Ports,
			Routes:                 route_helpers.AppRoutesFromRoutingInfo(desiredLRP.Routes),
			LogGuid:                desiredLRP.LogGuid,
			LogSource:              desiredLRP.LogSource,
			Annotation:             desiredLRP.Annotation,
		}
	}

	for _, actualLRP := range actualLRPs {

		appInfo, ok := appMap[actualLRP.ProcessGuid]
		if !ok {
			appInfo = &AppInfo{ProcessGuid: actualLRP.ProcessGuid, DesiredInstances: 0}
			appMap[actualLRP.ProcessGuid] = appInfo
		}

		if actualLRP.State == receptor.ActualLRPStateRunning {
			appInfo.ActualRunningInstances++
		}

		instancePorts := make([]PortMapping, 0)
		for _, respPorts := range actualLRP.Ports {
			instancePorts = append(instancePorts, PortMapping{HostPort: respPorts.HostPort, ContainerPort: respPorts.ContainerPort})
		}
		instanceInfo := InstanceInfo{
			InstanceGuid:   actualLRP.InstanceGuid,
			CellID:         actualLRP.CellID,
			Index:          actualLRP.Index,
			Ip:             actualLRP.Address,
			Ports:          instancePorts,
			State:          string(actualLRP.State),
			Since:          actualLRP.Since,
			PlacementError: actualLRP.PlacementError,
			CrashCount:     actualLRP.CrashCount,
			HasMetrics:     false,
		}

		appMap[actualLRP.ProcessGuid].ActualInstances = append(appMap[actualLRP.ProcessGuid].ActualInstances, instanceInfo)
	}

	for _, appInfo := range appMap {
		sort.Sort(instanceInfoSortableByIndex(appInfo.ActualInstances))
	}

	return appMap
}
示例#2
0
			expectedRouteOverrides := app_runner.RouteOverrides{
				{HostnamePrefix: "foo.com", Port: 8080},
				{HostnamePrefix: "bar.com", Port: 9090},
			}

			err := appRunner.UpdateAppRoutes("americano-app", expectedRouteOverrides)
			Expect(err).NotTo(HaveOccurred())

			Expect(fakeReceptorClient.UpdateDesiredLRPCallCount()).To(Equal(1))
			processGuid, updateRequest := fakeReceptorClient.UpdateDesiredLRPArgsForCall(0)
			Expect(processGuid).To(Equal("americano-app"))
			expectedRoutes := route_helpers.AppRoutes{
				{Hostnames: []string{"foo.com.myDiegoInstall.com"}, Port: 8080},
				{Hostnames: []string{"bar.com.myDiegoInstall.com"}, Port: 9090},
			}
			Expect(route_helpers.AppRoutesFromRoutingInfo(updateRequest.Routes)).To(ContainExactly(expectedRoutes))
		})

		Context("when an empty routes is passed", func() {
			It("deregisters the routes", func() {
				desiredLRPs := []receptor.DesiredLRPResponse{receptor.DesiredLRPResponse{ProcessGuid: "americano-app"}}
				fakeReceptorClient.DesiredLRPsReturns(desiredLRPs, nil)

				err := appRunner.UpdateAppRoutes("americano-app", app_runner.RouteOverrides{})
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeReceptorClient.UpdateDesiredLRPCallCount()).To(Equal(1))
				processGuid, updateRequest := fakeReceptorClient.UpdateDesiredLRPArgsForCall(0)
				Expect(processGuid).To(Equal("americano-app"))
				Expect(updateRequest.Routes).To(Equal(route_helpers.AppRoutes{}.RoutingInfo()))
			})
示例#3
0
			It("uses the overriden routes instead of the defaults", func() {
				createAppParams = app_runner.CreateAppParams{
					AppEnvironmentParams: app_runner.AppEnvironmentParams{
						RouteOverrides: app_runner.RouteOverrides{
							app_runner.RouteOverride{HostnamePrefix: "wiggle", Port: 2000},
							app_runner.RouteOverride{HostnamePrefix: "swang", Port: 2000},
							app_runner.RouteOverride{HostnamePrefix: "shuffle", Port: 4000},
						},
					},
				}

				err := appRunner.CreateApp(createAppParams)
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeReceptorClient.CreateDesiredLRPCallCount()).To(Equal(1))
				appRoutes := route_helpers.AppRoutesFromRoutingInfo(fakeReceptorClient.CreateDesiredLRPArgsForCall(0).Routes)
				Expect(appRoutes).To(ContainExactly(
					route_helpers.AppRoutes{
						route_helpers.AppRoute{
							Hostnames: []string{"wiggle.myDiegoInstall.com", "swang.myDiegoInstall.com"},
							Port:      2000,
						},
						route_helpers.AppRoute{
							Hostnames: []string{"shuffle.myDiegoInstall.com"},
							Port:      4000,
						},
					}))
			})
		})

		Context("when NoRoutes is true", func() {
					Expect(err).NotTo(HaveOccurred())

					Expect(payload).To(MatchJSON(`[]`))
				})
			})
		})
	})

	Describe("AppRoutesFromRoutingInfo", func() {
		var routingInfo receptor.RoutingInfo

		Context("when the method returns a value", func() {
			var routesResult route_helpers.AppRoutes

			JustBeforeEach(func() {
				routesResult = route_helpers.AppRoutesFromRoutingInfo(routingInfo)
			})

			Context("when lattice app routes are present in the routing info", func() {
				BeforeEach(func() {
					routingInfo = appRoutes.RoutingInfo()
				})

				It("returns the routes", func() {
					Expect(appRoutes).To(Equal(routesResult))
				})
			})

			Context("when the result should be nil", func() {
				itReturnsNilRoutes := func() {
					It("returns nil routes", func() {