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.CreateComponents(t.clock.Now()) 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 }
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}) } }
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 })
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()) }
}) 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() {
func (t *ETCDHelper) CreateMalformedDesiredLRP(guid string) { t.createMalformedValueForKey(etcddb.DesiredLRPSchedulingInfoSchemaPath(guid)) t.createMalformedValueForKey(etcddb.DesiredLRPRunInfoSchemaPath(guid)) }