Beispiel #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
}
Beispiel #2
0
func (t *ETCDHelper) SetRawDesiredLRPRunInfo(model *models.DesiredLRPRunInfo) {
	value, err := t.serializer.Marshal(t.logger, t.format, model)
	Expect(err).NotTo(HaveOccurred())

	key := etcddb.DesiredLRPRunInfoSchemaPath(model.ProcessGuid)
	_, err = t.client.Set(key, value, 0)

	Expect(err).NotTo(HaveOccurred())
}
func (m *SplitDesiredLRP) WriteRunInfo(logger lager.Logger, desiredLRP models.DesiredLRP) {
	environmentVariables := make([]models.EnvironmentVariable, len(desiredLRP.EnvironmentVariables))
	for i := range desiredLRP.EnvironmentVariables {
		environmentVariables[i] = *desiredLRP.EnvironmentVariables[i]
	}

	egressRules := make([]models.SecurityGroupRule, len(desiredLRP.EgressRules))
	for i := range desiredLRP.EgressRules {
		egressRules[i] = *desiredLRP.EgressRules[i]
	}

	runInfo := models.DesiredLRPRunInfo{
		DesiredLRPKey:        desiredLRP.DesiredLRPKey(),
		EnvironmentVariables: environmentVariables,
		Setup:                desiredLRP.Setup,
		Action:               desiredLRP.Action,
		Monitor:              desiredLRP.Monitor,
		StartTimeoutMs:       desiredLRP.StartTimeoutMs,
		Privileged:           desiredLRP.Privileged,
		CpuWeight:            desiredLRP.CpuWeight,
		Ports:                desiredLRP.Ports,
		EgressRules:          egressRules,
		LogSource:            desiredLRP.LogSource,
		MetricsGuid:          desiredLRP.MetricsGuid,
	}

	runInfoPayload, marshalErr := m.serializer.Marshal(logger, format.ENCRYPTED_PROTO, &runInfo)
	if marshalErr != nil {
		logger.Error("failed-marshaling-run-info", marshalErr, lager.Data{"process_guid": runInfo.ProcessGuid})
	}

	_, setErr := m.storeClient.Set(etcd.DesiredLRPRunInfoSchemaPath(runInfo.ProcessGuid), runInfoPayload, etcd.NO_TTL)
	if setErr != nil {
		logger.Error("failed-set-of-run-info", marshalErr, lager.Data{"process_guid": runInfo.ProcessGuid})
	}
}
Beispiel #4
0
func (t *ETCDHelper) DeleteDesiredLRP(guid string) {
	_, err := t.client.Delete(etcd.DesiredLRPSchedulingInfoSchemaPath(guid), false)
	Expect(err).NotTo(HaveOccurred())
	_, err = t.client.Delete(etcd.DesiredLRPRunInfoSchemaPath(guid), false)
	Expect(err).NotTo(HaveOccurred())
}
Beispiel #5
0
						if count == 0 {
							count++
							return nil, nil
						} else {
							return nil, errors.New("Failed Scheduling desired lrp ingo")
						}
					}
				})

				It("attempts to delete the run info", func() {
					err := etcdDBWithFakeStore.DesireLRP(logger, lrp)
					Expect(err).To(HaveOccurred())

					Expect(fakeStoreClient.DeleteCallCount()).To(Equal(1))
					schemaPath, _ := fakeStoreClient.DeleteArgsForCall(0)
					Expect(schemaPath).To(Equal(etcd.DesiredLRPRunInfoSchemaPath(lrp.ProcessGuid)))
				})
			})
		})

		Context("when the desired LRP already exists", func() {
			var newLRP *models.DesiredLRP

			BeforeEach(func() {
				err := etcdDB.DesireLRP(logger, lrp)
				Expect(err).NotTo(HaveOccurred())

				newLRP = lrp
				newLRP.Instances = 3
			})
Beispiel #6
0
func (t *ETCDHelper) CreateMalformedDesiredLRP(guid string) {
	t.createMalformedValueForKey(etcddb.DesiredLRPSchedulingInfoSchemaPath(guid))
	t.createMalformedValueForKey(etcddb.DesiredLRPRunInfoSchemaPath(guid))
}
			})

			JustBeforeEach(func() {
				schedulingInfo, runInfo := desiredLRP.CreateComponents(fakeClock.Now())
				runInfo.DeprecatedStartTimeoutS = 15

				_, err := json.Marshal(desiredLRP.Routes)
				Expect(err).NotTo(HaveOccurred())

				schedInfoData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &schedulingInfo)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcddb.DesiredLRPSchedulingInfoSchemaPath(processGuid), schedInfoData, 0)
				Expect(err).NotTo(HaveOccurred())
				runInfoData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &runInfo)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcddb.DesiredLRPRunInfoSchemaPath(processGuid), runInfoData, 0)
				Expect(err).NotTo(HaveOccurred())

				encoder := format.NewEncoder(cryptor)
				encryptedVolumePlacement, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, schedulingInfo.VolumePlacement)
				Expect(err).NotTo(HaveOccurred())
				_, err = encoder.Decode(encryptedVolumePlacement)
				Expect(err).NotTo(HaveOccurred())

				migration.SetStoreClient(storeClient)
				migration.SetCryptor(cryptor)
				migration.SetClock(fakeClock)
				migrationErr = migration.Up(logger)
			})

			It("changes desiredLRP startTimeout to milliseconds", func() {
		})

		Context("when there are already 'migrated' data in the database", func() {
			var existingSplit *models.DesiredLRP
			BeforeEach(func() {
				existingSplit = newValidDesiredLRP("existing-split")
				schedulingInfo, runInfo := existingSplit.CreateComponents(time.Unix(42, 42))

				schedulingInfoPayload, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &schedulingInfo)
				Expect(err).NotTo(HaveOccurred())
				runInfoPayload, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &runInfo)
				Expect(err).NotTo(HaveOccurred())

				_, err = storeClient.Set(etcd.DesiredLRPSchedulingInfoSchemaPath("existing-split"), schedulingInfoPayload, 0)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcd.DesiredLRPRunInfoSchemaPath("existing-split"), runInfoPayload, 0)
				Expect(err).NotTo(HaveOccurred())
			})

			It("deletes the existing lrp that was already split afterwards", func() {
				Expect(migrationErr).NotTo(HaveOccurred())

				_, err := storeClient.Get(etcd.DesiredLRPSchedulingInfoSchemaPath("existing-split"), false, true)
				Expect(err).To(HaveOccurred())

				_, err = storeClient.Get(etcd.DesiredLRPRunInfoSchemaPath("existing-split"), false, true)
				Expect(err).To(HaveOccurred())
			})
		})
	})