Exemple #1
0
func (t *ETCDHelper) CreateDesiredLRPsInDomains(domainCounts map[string]int) map[string][]*models.DesiredLRP {
	createdDesiredLRPs := map[string][]*models.DesiredLRP{}

	for domain, count := range domainCounts {
		createdDesiredLRPs[domain] = []*models.DesiredLRP{}

		for i := 0; i < count; i++ {
			guid := fmt.Sprintf("guid-%d-for-%s", i, domain)
			desiredLRP := model_helpers.NewValidDesiredLRP(guid)
			desiredLRP.Domain = domain
			schedulingInfo, runInfo := desiredLRP.Explode()

			schedulingInfoValue, err := t.serializer.Marshal(t.logger, t.format, &schedulingInfo)
			Expect(err).NotTo(HaveOccurred())

			t.client.Set(etcddb.DesiredLRPSchedulingInfoSchemaPath(guid), schedulingInfoValue, 0)
			Expect(err).NotTo(HaveOccurred())

			runInfoValue, err := t.serializer.Marshal(t.logger, t.format, &runInfo)
			Expect(err).NotTo(HaveOccurred())

			t.client.Set(etcddb.DesiredLRPRunInfoSchemaPath(guid), runInfoValue, 0)
			Expect(err).NotTo(HaveOccurred())

			createdDesiredLRPs[domain] = append(createdDesiredLRPs[domain], desiredLRP)
		}
	}

	return createdDesiredLRPs
}
					expectedSchedulingInfos = append(expectedSchedulingInfos, &schedulingInfo)
				}
				Expect(schedulingInfos).To(ConsistOf(expectedSchedulingInfos))
			})
		})
	})

	Describe("DesireLRP", func() {
		var (
			desiredLRP *models.DesiredLRP

			desireErr error
		)

		JustBeforeEach(func() {
			desiredLRP = model_helpers.NewValidDesiredLRP("super-lrp")
			desireErr = client.DesireLRP(desiredLRP)
		})

		It("creates the desired LRP in the system", func() {
			Expect(desireErr).NotTo(HaveOccurred())
			persistedDesiredLRP, err := client.DesiredLRPByProcessGuid("super-lrp")
			Expect(err).NotTo(HaveOccurred())
			Expect(persistedDesiredLRP.DesiredLRPKey()).To(Equal(desiredLRP.DesiredLRPKey()))
			Expect(persistedDesiredLRP.DesiredLRPResource()).To(Equal(desiredLRP.DesiredLRPResource()))
			Expect(persistedDesiredLRP.Annotation).To(Equal(desiredLRP.Annotation))
			Expect(persistedDesiredLRP.Instances).To(Equal(desiredLRP.Instances))
			Expect(persistedDesiredLRP.DesiredLRPRunInfo()).To(Equal(desiredLRP.DesiredLRPRunInfo()))
		})
	})
Exemple #3
0
				for i := 0; i < count/concurrency; i++ {
					f()
				}
				done <- true
			}()
		}
		for c := 0; c < concurrency; c++ {
			<-done
		}
	}

	desireLRP := func() {
		var err error
		guid, err := uuid.NewV4()
		Expect(err).NotTo(HaveOccurred())
		desiredLRP := model_helpers.NewValidDesiredLRP(guid.String())
		desiredLRP.Instances = 8
		err = client.DesireLRP(desiredLRP)
		Expect(err).NotTo(HaveOccurred())
		readLRP, err := client.DesiredLRPByProcessGuid(guid.String())
		Expect(err).NotTo(HaveOccurred())
		Expect(readLRP).ToNot(BeNil())
	}

	runMeasurements := func() {
		Measure("ping time", func(b Benchmarker) {
			b.Time("first-request", func() {
				Expect(client.Ping()).To(BeTrue())
			})
			b.Time("second-request", func() {
				Expect(client.Ping()).To(BeTrue())
		It("errors when passed malformed input", func() {
			_, err := rep.UnmarshalStackPathMap([]byte(`{"foo": ["bar"]}`))
			Expect(err).To(MatchError(ContainSubstring("unmarshal")))
		})
	})

	Describe("NewRunRequestFromDesiredLRP", func() {
		var (
			containerGuid string
			desiredLRP    *models.DesiredLRP
			actualLRP     *models.ActualLRP
		)

		BeforeEach(func() {
			containerGuid = "the-container-guid"
			desiredLRP = model_helpers.NewValidDesiredLRP("the-process-guid")
			actualLRP = model_helpers.NewValidActualLRP("the-process-guid", 9)
			desiredLRP.RootFs = "preloaded://foobar"
		})

		It("returns a valid run request", func() {
			runReq, err := rep.NewRunRequestFromDesiredLRP(containerGuid, desiredLRP, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey)
			Expect(err).NotTo(HaveOccurred())
			Expect(runReq.Tags).To(Equal(executor.Tags{}))
			Expect(runReq.RunInfo).To(Equal(executor.RunInfo{
				CPUWeight: uint(desiredLRP.CpuWeight),
				DiskScope: executor.ExclusiveDiskLimit,
				Ports:     rep.ConvertPortMappings(desiredLRP.Ports),
				LogConfig: executor.LogConfig{
					Guid:       desiredLRP.LogGuid,
					Index:      int(actualLRP.Index),
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1441411196))
		})
	})

	Describe("Up", func() {
		var (
			expectedDesiredLRP                             *models.DesiredLRP
			expectedActualLRP, expectedEvacuatingActualLRP *models.ActualLRP
			expectedTask                                   *models.Task
			migrationErr                                   error
		)

		BeforeEach(func() {
			// DesiredLRP
			expectedDesiredLRP = model_helpers.NewValidDesiredLRP("process-guid")
			jsonValue, err := json.Marshal(expectedDesiredLRP)
			Expect(err).NotTo(HaveOccurred())
			_, err = storeClient.Set(deprecations.DesiredLRPSchemaPath(expectedDesiredLRP), jsonValue, 0)
			Expect(err).NotTo(HaveOccurred())

			// ActualLRP
			expectedActualLRP = model_helpers.NewValidActualLRP("process-guid", 1)
			jsonValue, err = json.Marshal(expectedActualLRP)
			Expect(err).NotTo(HaveOccurred())
			_, err = storeClient.Set(etcd.ActualLRPSchemaPath(expectedActualLRP.ProcessGuid, 1), jsonValue, 0)
			Expect(err).NotTo(HaveOccurred())

			// Evacuating ActualLRP
			expectedEvacuatingActualLRP = model_helpers.NewValidActualLRP("process-guid", 4)
			jsonValue, err = json.Marshal(expectedEvacuatingActualLRP)
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(Equal(models.ErrUnknownError))
			})
		})
	})

	Describe("DesireDesiredLRP", func() {
		var (
			desiredLRP *models.DesiredLRP

			requestBody interface{}
		)

		BeforeEach(func() {
			desiredLRP = model_helpers.NewValidDesiredLRP("some-guid")
			requestBody = &models.DesireLRPRequest{
				DesiredLrp: desiredLRP,
			}
		})

		JustBeforeEach(func() {
			request := newTestRequest(requestBody)
			handler.DesireDesiredLRP(responseRecorder, request)
		})

		Context("when creating desired lrp in DB succeeds", func() {
			BeforeEach(func() {
				fakeDesiredLRPDB.DesireLRPReturns(nil)
			})
Exemple #7
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Evacuation API", func() {
	BeforeEach(func() {
		bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
		bbsProcess = ginkgomon.Invoke(bbsRunner)
	})

	var actual *models.ActualLRP

	BeforeEach(func() {
		actual = model_helpers.NewValidActualLRP("some-process-guid", 1)
		actual.State = models.ActualLRPStateRunning
		desiredLRP := model_helpers.NewValidDesiredLRP(actual.ProcessGuid)
		desiredLRP.Instances = 2
		err := client.DesireLRP(logger, desiredLRP)
		Expect(err).NotTo(HaveOccurred())
		err = client.ClaimActualLRP(logger, actual.ProcessGuid, 1, &actual.ActualLRPInstanceKey)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("RemoveEvacuatingActualLRP", func() {
		It("removes the evacuating actual_lrp", func() {
			_, err := client.EvacuateClaimedActualLRP(logger, &actual.ActualLRPKey, &actual.ActualLRPInstanceKey)
			Expect(err).NotTo(HaveOccurred())

			err = client.RemoveEvacuatingActualLRP(logger, &actual.ActualLRPKey, &actual.ActualLRPInstanceKey)
			Expect(err).NotTo(HaveOccurred())
Exemple #8
0
				etcdRunner.Start()
			})

			It("errors", func() {
				_, err := etcdDB.DesiredLRPs(logger, filter)
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("DesiredLRPByProcessGuid", func() {
		Context("when there is a desired lrp", func() {
			var desiredLRP *models.DesiredLRP

			BeforeEach(func() {
				desiredLRP = model_helpers.NewValidDesiredLRP("process-guid")
				etcdHelper.SetRawDesiredLRP(desiredLRP)
			})

			It("returns the desired lrp", func() {
				lrp, err := etcdDB.DesiredLRPByProcessGuid(logger, "process-guid")
				Expect(err).NotTo(HaveOccurred())
				Expect(lrp).To(Equal(desiredLRP))
			})
		})

		Context("when there is no LRP", func() {
			It("returns a ResourceNotFound", func() {
				_, err := etcdDB.DesiredLRPByProcessGuid(logger, "nota-guid")
				Expect(err).To(Equal(models.ErrResourceNotFound))
			})
Exemple #9
0
func (t *ETCDHelper) CreateValidDesiredLRP(guid string) {
	t.SetRawDesiredLRP(model_helpers.NewValidDesiredLRP(guid))
}
					Expect(migrationErr).NotTo(HaveOccurred())
					_, err := db.TaskByGuid(logger, task.TaskGuid)
					Expect(err).NotTo(HaveOccurred())
				})
			})
		})

		Describe("DesiredLRP Migration", func() {
			var (
				processGuid string
				desiredLRP  *models.DesiredLRP
			)

			BeforeEach(func() {
				processGuid = "process-guid-1"
				desiredLRP = model_helpers.NewValidDesiredLRP(processGuid)
				desiredLRP.DeprecatedStartTimeoutS = 15
				desiredLRP.Action = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
					DeprecatedTimeoutNs: 4 * int64(time.Second),
				})

				desiredLRP.Setup = models.WrapAction(&models.TimeoutAction{Action: models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
					DeprecatedTimeoutNs: 7 * int64(time.Second),
				})
				desiredLRP.Monitor = models.WrapAction(models.EmitProgressFor(
					&models.TimeoutAction{
						Action:              models.WrapAction(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"})))),
						DeprecatedTimeoutNs: 10 * int64(time.Second),
					},
					"start-message",
					"success-message",
Exemple #11
0
				Expect(response.Error).To(Equal(models.ErrResourceNotFound))
			})
		})
	})

	Describe("EvacuateClaimedActualLRP", func() {
		var (
			request     *http.Request
			requestBody *models.EvacuateClaimedActualLRPRequest
			actual      *models.ActualLRP
			afterActual *models.ActualLRP
			desiredLRP  *models.DesiredLRP
		)

		BeforeEach(func() {
			desiredLRP = model_helpers.NewValidDesiredLRP("the-guid")
			fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil)

			actual = model_helpers.NewValidActualLRP("process-guid", 1)
			requestBody = &models.EvacuateClaimedActualLRPRequest{
				ActualLrpKey:         &actual.ActualLRPKey,
				ActualLrpInstanceKey: &actual.ActualLRPInstanceKey,
			}
			afterActual = model_helpers.NewValidActualLRP("process-guid", 1)
			afterActual.State = models.ActualLRPStateUnclaimed
			fakeActualLRPDB.ActualLRPGroupByProcessGuidAndIndexReturns(&models.ActualLRPGroup{Evacuating: actual}, nil)
			fakeActualLRPDB.UnclaimActualLRPReturns(&models.ActualLRPGroup{Instance: actual}, &models.ActualLRPGroup{Instance: afterActual}, nil)

			request = newTestRequest(requestBody)
		})
Exemple #12
0
		BeforeEach(func() {
			bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
			bbsProcess = ginkgomon.Invoke(bbsRunner)

			cellPresence := models.NewCellPresence(
				"some-cell",
				"cell.example.com",
				"the-zone",
				models.NewCellCapacity(128, 1024, 6),
				[]string{},
				[]string{},
			)
			consulHelper.RegisterCell(&cellPresence)
			processGuid = "some-process-guid"
			err := client.DesireLRP(logger, model_helpers.NewValidDesiredLRP(processGuid))
			Expect(err).NotTo(HaveOccurred())
			err = client.RemoveActualLRP(logger, processGuid, 0, nil)
			Expect(err).NotTo(HaveOccurred())
		})

		It("converges the lrps", func() {
			err := client.ConvergeLRPs(logger)
			Expect(err).NotTo(HaveOccurred())

			groups, err := client.ActualLRPGroupsByProcessGuid(logger, processGuid)
			Expect(err).NotTo(HaveOccurred())
			Expect(groups).To(HaveLen(1))
		})
	})
})
Exemple #13
0
		BeforeEach(func() {
			server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				handler.Subscribe_r0(w, r)
				close(eventStreamDone)
			}))
		})

		Describe("Subscribe to Desired Events", func() {
			ItStreamsEventsFromHub(&desiredHub)

			It("migrates desired lrps down to v0", func() {
				response, err := http.Get(server.URL)
				Expect(err).NotTo(HaveOccurred())
				reader := sse.NewReadCloser(response.Body)

				desiredLRP := model_helpers.NewValidDesiredLRP("guid")
				event := models.NewDesiredLRPCreatedEvent(desiredLRP)

				migratedLRP := desiredLRP.VersionDownTo(format.V0)
				Expect(migratedLRP).NotTo(Equal(desiredLRP))
				migratedEvent := models.NewDesiredLRPCreatedEvent(migratedLRP)

				expectedEvent, err := events.NewEventFromModelEvent(0, migratedEvent)
				Expect(err).NotTo(HaveOccurred())

				desiredHub.Emit(event)

				Expect(reader.Next()).To(Equal(expectedEvent))
			})
		})
Exemple #14
0
func (t *ETCDHelper) CreateOrphanedRunInfo(guid string, createdAt time.Time) {
	lrp := model_helpers.NewValidDesiredLRP(guid)
	_, runInfo := lrp.CreateComponents(createdAt)

	t.SetRawDesiredLRPRunInfo(&runInfo)
}
Exemple #15
0
func (t *ETCDHelper) CreateOrphanedSchedulingInfo(guid string, createdAt time.Time) {
	lrp := model_helpers.NewValidDesiredLRP(guid)
	schedulingInfo, _ := lrp.CreateComponents(createdAt)

	t.SetRawDesiredLRPSchedulingInfo(&schedulingInfo)
}