func (h *DesiredLRPHandler) Create(w http.ResponseWriter, r *http.Request) { log := h.logger.Session("create") desireLRPRequest := receptor.DesiredLRPCreateRequest{} err := json.NewDecoder(r.Body).Decode(&desireLRPRequest) if err != nil { log.Error("invalid-json", err) writeBadRequestResponse(w, receptor.InvalidJSON, err) return } desiredLRP := serialization.DesiredLRPFromRequest(desireLRPRequest) err = h.legacyBBS.DesireLRP(log, desiredLRP) if err != nil { if _, ok := err.(oldmodels.ValidationError); ok { log.Error("lrp-request-invalid", err) writeBadRequestResponse(w, receptor.InvalidLRP, err) return } if err == bbserrors.ErrStoreResourceExists { writeDesiredLRPAlreadyExistsResponse(w, desiredLRP.ProcessGuid) return } log.Error("desire-lrp-failed", err) writeUnknownErrorResponse(w, err) return } w.WriteHeader(http.StatusCreated) }
User: "******", Path: "the-path", }, StartTimeout: 4, Privileged: true, LogGuid: "log-guid-0", LogSource: "log-source-name-0", MetricsGuid: "metrics-guid-0", EgressRules: []models.SecurityGroupRule{ securityRule, }, Routes: routingInfo, } }) JustBeforeEach(func() { desiredLRP = serialization.DesiredLRPFromRequest(request) }) It("translates the request into a DesiredLRP model, preserving attributes", func() { Expect(desiredLRP.ProcessGuid).To(Equal("the-process-guid")) Expect(desiredLRP.Domain).To(Equal("the-domain")) Expect(desiredLRP.RootFS).To(Equal("the-rootfs")) Expect(desiredLRP.Annotation).To(Equal("foo")) Expect(desiredLRP.StartTimeout).To(Equal(uint(4))) Expect(desiredLRP.Ports).To(HaveLen(2)) Expect(desiredLRP.Ports[0]).To(Equal(uint16(2345))) Expect(desiredLRP.Ports[1]).To(Equal(uint16(6789))) Expect(desiredLRP.Privileged).To(BeTrue()) Expect(desiredLRP.EgressRules).To(HaveLen(1)) Expect(desiredLRP.EgressRules[0].Protocol).To(Equal(securityRule.Protocol)) Expect(desiredLRP.EgressRules[0].PortRange).To(Equal(securityRule.PortRange))