コード例 #1
0
func NewEventFromBBS(bbsEvent models.Event) (receptor.Event, error) {
	switch bbsEvent := bbsEvent.(type) {
	case *models.ActualLRPCreatedEvent:
		actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve()
		return receptor.NewActualLRPCreatedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil
	case *models.ActualLRPChangedEvent:
		before, evacuating := bbsEvent.Before.Resolve()
		after, evacuating := bbsEvent.After.Resolve()
		return receptor.NewActualLRPChangedEvent(
			serialization.ActualLRPProtoToResponse(before, evacuating),
			serialization.ActualLRPProtoToResponse(after, evacuating),
		), nil
	case *models.ActualLRPRemovedEvent:
		actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve()
		return receptor.NewActualLRPRemovedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil
	case *models.DesiredLRPCreatedEvent:
		return receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil
	case *models.DesiredLRPChangedEvent:
		return receptor.NewDesiredLRPChangedEvent(
			serialization.DesiredLRPProtoToResponse(bbsEvent.Before),
			serialization.DesiredLRPProtoToResponse(bbsEvent.After),
		), nil
	case *models.DesiredLRPRemovedEvent:
		return receptor.NewDesiredLRPRemovedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil
	}
	return nil, fmt.Errorf("unknown event type: %#v", bbsEvent)
}
コード例 #2
0
ファイル: watcher.go プロジェクト: thomasdarimont/lattice
func (w *watcher) watchActual(logger lager.Logger) (chan<- bool, <-chan error) {
	return w.bbs.WatchForActualLRPChanges(logger,
		func(created models.ActualLRP, evacuating bool) {
			logger.Debug("handling-actual-create")
			w.hub.Emit(receptor.NewActualLRPCreatedEvent(serialization.ActualLRPToResponse(created, evacuating)))
		},
		func(changed models.ActualLRPChange, evacuating bool) {
			logger.Debug("handling-actual-change")
			w.hub.Emit(receptor.NewActualLRPChangedEvent(
				serialization.ActualLRPToResponse(changed.Before, evacuating),
				serialization.ActualLRPToResponse(changed.After, evacuating),
			))
		},
		func(deleted models.ActualLRP, evacuating bool) {
			logger.Debug("handling-actual-delete")
			w.hub.Emit(receptor.NewActualLRPRemovedEvent(serialization.ActualLRPToResponse(deleted, evacuating)))
		})
}
コード例 #3
0
				It("returns the event", func() {
					event, err := eventSource.Next()
					Expect(err).NotTo(HaveOccurred())

					actualLRPCreatedEvent, ok := event.(receptor.ActualLRPCreatedEvent)
					Expect(ok).To(BeTrue())
					Expect(actualLRPCreatedEvent).To(Equal(expectedEvent))
				})
			})

			Context("when receiving a ActualLRPChangedEvent", func() {
				var expectedEvent receptor.ActualLRPChangedEvent

				BeforeEach(func() {
					expectedEvent = receptor.NewActualLRPChangedEvent(
						actualLRPResponse,
						actualLRPResponse,
					)
					payload, err := json.Marshal(expectedEvent)
					Expect(err).NotTo(HaveOccurred())

					fakeRawEventSource.NextReturns(
						sse.Event{
							ID:   "sup",
							Name: string(expectedEvent.EventType()),
							Data: payload,
						},
						nil,
					)
				})

				It("returns the event", func() {