Esempio n. 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,
			RootFS:                 desiredLRP.RootFS,
			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.RoutesFromRoutingInfo(desiredLRP.Routes),
			LogGuid:                desiredLRP.LogGuid,
			LogSource:              desiredLRP.LogSource,
			Annotation:             desiredLRP.Annotation,
			Monitor:                parseMonitor(desiredLRP.Monitor),
		}
	}

	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
}
Esempio n. 2
0
			Context("and when route overrides are not empty", func() {
				BeforeEach(func() {
					createAppParams.AppEnvironmentParams.RouteOverrides = app_runner.RouteOverrides{
						{HostnamePrefix: "wiggle/this", Port: 2000},
						{HostnamePrefix: "wiggle.com/this", Port: 2000},
						{HostnamePrefix: "swang", Port: 2000},
						{HostnamePrefix: "shuffle", Port: 4000},
					}
				})

				It("uses the tcp routes", func() {
					err := appRunner.CreateApp(createAppParams)
					Expect(err).NotTo(HaveOccurred())

					Expect(fakeReceptorClient.CreateDesiredLRPCallCount()).To(Equal(1))
					routes := route_helpers.RoutesFromRoutingInfo(fakeReceptorClient.CreateDesiredLRPArgsForCall(0).Routes)
					Expect(routes.TcpRoutes).To(ContainExactly(route_helpers.TcpRoutes{
						{ExternalPort: 60000, Port: 2000},
						{ExternalPort: 60010, Port: 2000},
						{ExternalPort: 60020, Port: 3000},
					}))
					Expect(routes.AppRoutes).To(ContainExactly(route_helpers.AppRoutes{
						{Hostnames: []string{"wiggle.myDiegoInstall.com/this", "wiggle.com/this", "swang.myDiegoInstall.com"}, Port: 2000},
						{Hostnames: []string{"shuffle.myDiegoInstall.com"}, Port: 4000},
					}))
				})
			})

			Context("and when route overrides are empty", func() {
				It("uses the tcp routes", func() {
					err := appRunner.CreateApp(createAppParams)
					tcpRoutesPayload, err := routingInfo[route_helpers.TcpRouter].MarshalJSON()
					Expect(err).NotTo(HaveOccurred())
					Expect(tcpRoutesPayload).To(MatchJSON("[]"))
				})
			})
		})

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

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

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

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

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

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