Ejemplo n.º 1
0
func (h *DesiredLRPHandler) Get(w http.ResponseWriter, r *http.Request) {
	processGuid := r.FormValue(":process_guid")
	logger := h.logger.Session("get", lager.Data{
		"ProcessGuid": processGuid,
	})

	if processGuid == "" {
		err := errors.New("process_guid missing from request")
		logger.Error("missing-process-guid", err)
		writeBadRequestResponse(w, receptor.InvalidRequest, err)
		return
	}

	desiredLRP, err := h.bbs.DesiredLRPByProcessGuid(logger, processGuid)
	if err == bbserrors.ErrStoreResourceNotFound {
		writeDesiredLRPNotFoundResponse(w, processGuid)
		return
	}

	if err != nil {
		logger.Error("unknown-error", err)
		writeUnknownErrorResponse(w, err)
		return
	}

	writeJSONResponse(w, http.StatusOK, serialization.DesiredLRPToResponse(desiredLRP))
}
Ejemplo n.º 2
0
func (w *watcher) watchDesired(logger lager.Logger) (chan<- bool, <-chan error) {
	return w.bbs.WatchForDesiredLRPChanges(logger,
		func(created models.DesiredLRP) {
			logger.Debug("handling-desired-create")
			w.hub.Emit(receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPToResponse(created)))
		},
		func(changed models.DesiredLRPChange) {
			logger.Debug("handling-desired-change")
			w.hub.Emit(receptor.NewDesiredLRPChangedEvent(
				serialization.DesiredLRPToResponse(changed.Before),
				serialization.DesiredLRPToResponse(changed.After),
			))
		},
		func(deleted models.DesiredLRP) {
			logger.Debug("handling-desired-delete")
			w.hub.Emit(receptor.NewDesiredLRPRemovedEvent(serialization.DesiredLRPToResponse(deleted)))
		})
}
Ejemplo n.º 3
0
func writeDesiredLRPResponse(w http.ResponseWriter, logger lager.Logger, desiredLRPs []models.DesiredLRP, err error) {
	if err != nil {
		logger.Error("failed-to-fetch-desired-lrps", err)
		writeUnknownErrorResponse(w, err)
		return
	}

	responses := make([]receptor.DesiredLRPResponse, 0, len(desiredLRPs))
	for _, desiredLRP := range desiredLRPs {
		responses = append(responses, serialization.DesiredLRPToResponse(desiredLRP))
	}

	writeJSONResponse(w, http.StatusOK, responses)
}
Ejemplo n.º 4
0
			lrpRequest = newValidDesiredLRPCreateRequest()
			err := client.CreateDesiredLRP(lrpRequest)
			Expect(err).NotTo(HaveOccurred())

			desiredLRP, err = bbs.DesiredLRPByProcessGuid(logger, lrpRequest.ProcessGuid)
			Expect(err).NotTo(HaveOccurred())

			lrpResponse, getErr = client.GetDesiredLRP(lrpRequest.ProcessGuid)
		})

		It("responds without an error", func() {
			Expect(getErr).NotTo(HaveOccurred())
		})

		It("fetches the desired lrp with the matching process guid", func() {
			expectedLRPResponse := serialization.DesiredLRPToResponse(desiredLRP)
			Expect(lrpResponse).To(Equal(expectedLRPResponse))
		})
	})

	Describe("PUT /v1/desired_lrps/:process_guid", func() {
		var updateErr error

		instances := 6
		annotation := "update-annotation"
		rawMessage := json.RawMessage([]byte(`[{"port":8080,"hostnames":["updated-route"]}]`))

		routingInfo := receptor.RoutingInfo{
			"cf-router": &rawMessage,
		}
Ejemplo n.º 5
0
		It("receives events", func() {
			By("creating a DesiredLRP")
			err := legacyBBS.DesireLRP(logger, desiredLRP)
			Expect(err).NotTo(HaveOccurred())

			desiredLRP, err := legacyBBS.DesiredLRPByProcessGuid(logger, desiredLRP.ProcessGuid)
			Expect(err).NotTo(HaveOccurred())

			var event receptor.Event
			Eventually(events).Should(Receive(&event))

			desiredLRPCreatedEvent, ok := event.(receptor.DesiredLRPCreatedEvent)
			Expect(ok).To(BeTrue())

			Expect(desiredLRPCreatedEvent.DesiredLRPResponse).To(Equal(serialization.DesiredLRPToResponse(desiredLRP)))

			By("updating an existing DesiredLRP")
			routeMessage := json.RawMessage([]byte(`[{"port":8080,"hostnames":["new-route"]}]`))
			newRoutes := map[string]*json.RawMessage{
				"cf-router": &routeMessage,
			}
			err = legacyBBS.UpdateDesiredLRP(logger, desiredLRP.ProcessGuid, oldmodels.DesiredLRPUpdate{Routes: newRoutes})
			Expect(err).NotTo(HaveOccurred())

			Eventually(events).Should(Receive(&event))

			desiredLRPChangedEvent, ok := event.(receptor.DesiredLRPChangedEvent)
			Expect(ok).To(BeTrue())
			Expect(desiredLRPChangedEvent.After.Routes).To(Equal(receptor.RoutingInfo(newRoutes)))
Ejemplo n.º 6
0
					{Name: "ENV_VAR_NAME", Value: "value"},
				},
				Action:       &models.RunAction{Path: "/bin/true"},
				StartTimeout: 4,
				DiskMB:       126,
				MemoryMB:     1234,
				CPUWeight:    192,
				Privileged:   true,
				Ports: []uint16{
					456,
				},
				Routes:      routingInfo,
				LogGuid:     "log-guid-0",
				LogSource:   "log-source-name-0",
				MetricsGuid: "metrics-guid-0",
				Annotation:  "annotation-0",
				EgressRules: []models.SecurityGroupRule{
					securityRule,
				},
				ModificationTag: receptor.ModificationTag{
					Epoch: "some-epoch",
					Index: 50,
				},
			}

			actualResponse := serialization.DesiredLRPToResponse(desiredLRP)
			Expect(actualResponse).To(Equal(expectedResponse))
		})
	})
})
Ejemplo n.º 7
0
	BeforeEach(func() {
		fakeRawEventSource = new(fake_receptor.FakeRawEventSource)
		eventSource = receptor.NewEventSource(fakeRawEventSource)
	})

	Describe("Next", func() {
		Describe("Desired LRP events", func() {
			var desiredLRPResponse receptor.DesiredLRPResponse

			BeforeEach(func() {
				desiredLRPResponse = serialization.DesiredLRPToResponse(
					models.DesiredLRP{
						ProcessGuid: "some-guid",
						Domain:      "some-domain",
						RootFS:      "some-rootfs",
						Action: &models.RunAction{
							Path: "true",
						},
					},
				)
			})

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

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

					fakeRawEventSource.NextReturns(
Ejemplo n.º 8
0
					ProcessGuid: expectedProcessGuid,
				}
			})

			Context("when a create arrives", func() {
				BeforeEach(func() {
					desiredCreateCB(desiredLRP)
				})

				It("emits a DesiredLRPCreatedEvent to the hub", func() {
					Expect(hub.EmitCallCount()).To(Equal(1))
					event := hub.EmitArgsForCall(0)

					desiredLRPCreatedEvent, ok := event.(receptor.DesiredLRPCreatedEvent)
					Expect(ok).To(BeTrue())
					Expect(desiredLRPCreatedEvent.DesiredLRPResponse).To(Equal(serialization.DesiredLRPToResponse(desiredLRP)))
				})
			})

			Context("when a change arrives", func() {
				BeforeEach(func() {
					desiredChangeCB(models.DesiredLRPChange{Before: desiredLRP, After: desiredLRP})
				})

				It("emits a DesiredLRPChangedEvent to the hub", func() {
					Expect(hub.EmitCallCount()).To(Equal(1))
					event := hub.EmitArgsForCall(0)

					desiredLRPChangedEvent, ok := event.(receptor.DesiredLRPChangedEvent)
					Expect(ok).To(BeTrue())
					Expect(desiredLRPChangedEvent.Before).To(Equal(serialization.DesiredLRPToResponse(desiredLRP)))