예제 #1
0
func (watcher *Watcher) handleDesiredUpdate(logger lager.Logger, before, after *models.DesiredLRPSchedulingInfo) {
	logger = logger.Session("handling-desired-update", lager.Data{
		"before": desiredLRPData(before),
		"after":  desiredLRPData(after),
	})
	logger.Info("starting")
	defer logger.Info("complete")

	afterKeysSet := watcher.setRoutesForDesired(logger, after)

	beforeRoutingKeys := routing_table.RoutingKeysFromSchedulingInfo(before)
	afterRoutes, _ := cfroutes.CFRoutesFromRoutingInfo(after.Routes)

	afterContainerPorts := set{}
	for _, route := range afterRoutes {
		afterContainerPorts.add(route.Port)
	}

	for _, key := range beforeRoutingKeys {
		if !afterKeysSet.contains(key) || !afterContainerPorts.contains(key.ContainerPort) {
			messagesToEmit := watcher.table.RemoveRoutes(key, &after.ModificationTag)
			watcher.emitMessages(logger, messagesToEmit)
		}
	}
}
func RoutingKeysFromSchedulingInfo(schedulingInfo *models.DesiredLRPSchedulingInfo) []RoutingKey {
	keys := []RoutingKey{}

	routes, err := cfroutes.CFRoutesFromRoutingInfo(schedulingInfo.Routes)
	if err == nil && len(routes) > 0 {
		for _, cfRoute := range routes {
			keys = append(keys, RoutingKey{ProcessGuid: schedulingInfo.ProcessGuid, ContainerPort: cfRoute.Port})
		}
	}
	return keys
}
func RoutesByRoutingKeyFromSchedulingInfos(schedulingInfos []*models.DesiredLRPSchedulingInfo) RoutesByRoutingKey {
	routesByRoutingKey := RoutesByRoutingKey{}
	for _, desired := range schedulingInfos {
		routes, err := cfroutes.CFRoutesFromRoutingInfo(desired.Routes)
		if err == nil && len(routes) > 0 {
			for _, cfRoute := range routes {
				key := RoutingKey{ProcessGuid: desired.ProcessGuid, ContainerPort: cfRoute.Port}
				routesByRoutingKey[key] = Routes{
					Hostnames:       cfRoute.Hostnames,
					LogGuid:         desired.LogGuid,
					RouteServiceUrl: cfRoute.RouteServiceUrl,
				}
			}
		}
	}

	return routesByRoutingKey
}
예제 #4
0
func (watcher *Watcher) setRoutesForDesired(logger lager.Logger, schedulingInfo *models.DesiredLRPSchedulingInfo) set {
	routingKeys := routing_table.RoutingKeysFromSchedulingInfo(schedulingInfo)
	routes, _ := cfroutes.CFRoutesFromRoutingInfo(schedulingInfo.Routes)
	routingKeySet := set{}

	for _, key := range routingKeys {
		routingKeySet.add(key)
		for _, route := range routes {
			if key.ContainerPort == route.Port {
				messagesToEmit := watcher.table.SetRoutes(key, routing_table.Routes{
					Hostnames:       route.Hostnames,
					LogGuid:         schedulingInfo.LogGuid,
					RouteServiceUrl: route.RouteServiceUrl,
				})
				watcher.emitMessages(logger, messagesToEmit)
			}
		}
	}

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

	Describe("CFRoutesFromRoutingInfo", func() {
		var (
			routesResult    cfroutes.CFRoutes
			conversionError error

			routingInfo models.Routes
		)

		JustBeforeEach(func() {
			routesResult, conversionError = cfroutes.CFRoutesFromRoutingInfo(routingInfo)
		})

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

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

			Context("when the CF routes are nil", func() {
				BeforeEach(func() {
					routingInfo = models.Routes{cfroutes.CF_ROUTER: nil}
				})