Exemplo n.º 1
0
func (m Encryptor) performEncryption(logger lager.Logger) error {
	response, err := m.storeClient.Get(etcddb.V1SchemaRoot, false, true)
	if err != nil {
		err = etcddb.ErrorFromEtcdError(logger, err)

		// Continue if the root node does not exist
		if err != models.ErrResourceNotFound {
			return err
		}
	}

	if response != nil {
		rootNode := response.Node
		return m.rewriteNode(logger, rootNode)
	}

	return nil
}
Exemplo n.º 2
0
func (m *SplitDesiredLRP) Up(logger lager.Logger) error {
	_, err := m.storeClient.Delete(etcd.DesiredLRPSchedulingInfoSchemaRoot, true)
	if err != nil {
		logger.Error("failed-to-delete-dir", err, lager.Data{"key": etcd.DesiredLRPSchedulingInfoSchemaRoot})
	}

	_, err = m.storeClient.Delete(etcd.DesiredLRPRunInfoSchemaRoot, true)
	if err != nil {
		logger.Error("failed-to-delete-dir", err, lager.Data{"key": etcd.DesiredLRPRunInfoSchemaRoot})
	}

	response, err := m.storeClient.Get(deprecations.DesiredLRPSchemaRoot, false, true)
	if err != nil {
		err = etcd.ErrorFromEtcdError(logger, err)
		if err != models.ErrResourceNotFound {
			return err
		}
	}

	if response != nil {
		desiredLRPRootNode := response.Node
		for _, node := range desiredLRPRootNode.Nodes {
			var desiredLRP models.DesiredLRP
			err := m.serializer.Unmarshal(logger, []byte(node.Value), &desiredLRP)
			if err != nil {
				logger.Error("failed-unmarshaling-desired-lrp", err, lager.Data{"process_guid": desiredLRP.ProcessGuid})
				continue
			}

			m.WriteRunInfo(logger, desiredLRP)
			m.WriteSchedulingInfo(logger, desiredLRP)

		}

		_, err = m.storeClient.Delete(deprecations.DesiredLRPSchemaRoot, true)
		if err != nil {
			logger.Error("failed-to-delete-dir", err, lager.Data{"key": deprecations.DesiredLRPSchemaRoot})
		}
	}

	return nil
}
Exemplo n.º 3
0
		Context("when the RunInfo exists, and the SchedulingInfo does not exist", func() {
			BeforeEach(func() {
				err := etcdDB.DesireLRP(logger, lrp)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Delete(etcd.DesiredLRPSchedulingInfoSchemaPath(lrp.ProcessGuid), true)
				Expect(err).NotTo(HaveOccurred())
			})

			It("deletes the RunInfo", func() {
				err := etcdDB.RemoveDesiredLRP(logger, lrp.ProcessGuid)
				Expect(err).ToNot(HaveOccurred())
				_, err = etcdDB.DesiredLRPByProcessGuid(logger, lrp.ProcessGuid)
				Expect(err).To(Equal(models.ErrResourceNotFound))
				_, err = storeClient.Get(etcd.DesiredLRPRunInfoSchemaPath(lrp.ProcessGuid), false, false)
				Expect(etcd.ErrorFromEtcdError(logger, err)).To(Equal(models.ErrResourceNotFound))
			})
		})

		Context("when removing the SchedulingInfo fails", func() {
			BeforeEach(func() {
				fakeStoreClient.DeleteReturns(nil, errors.New("kabooom!"))

				err := etcdDBWithFakeStore.DesireLRP(logger, lrp)
				Expect(err).NotTo(HaveOccurred())
			})

			It("does not remove the RunInfo", func() {
				err := etcdDBWithFakeStore.RemoveDesiredLRP(logger, lrp.ProcessGuid)
				Expect(err).To(HaveOccurred())
func (b Base64ProtobufEncode) Up(logger lager.Logger) error {
	// Desired LRPs
	response, err := b.storeClient.Get(deprecations.DesiredLRPSchemaRoot, false, true)
	if err != nil {
		err = etcd.ErrorFromEtcdError(logger, err)

		// Continue if the root node does not exist
		if err != models.ErrResourceNotFound {
			return err
		}
	}

	if response != nil {
		desiredLRPRootNode := response.Node
		for _, node := range desiredLRPRootNode.Nodes {
			var desiredLRP models.DesiredLRP
			err := b.reWriteNode(logger, node, &desiredLRP)
			if err != nil {
				return err
			}
		}
	}

	// Actual LRPs
	response, err = b.storeClient.Get(etcd.ActualLRPSchemaRoot, false, true)
	if err != nil {
		err = etcd.ErrorFromEtcdError(logger, err)

		// Continue if the root node does not exist
		if err != models.ErrResourceNotFound {
			return err
		}
	}

	if response != nil {
		actualLRPRootNode := response.Node
		for _, processNode := range actualLRPRootNode.Nodes {
			for _, groupNode := range processNode.Nodes {
				for _, actualLRPNode := range groupNode.Nodes {
					var actualLRP models.ActualLRP
					err := b.reWriteNode(logger, actualLRPNode, &actualLRP)
					if err != nil {
						return err
					}
				}
			}
		}
	}

	// Tasks
	response, err = b.storeClient.Get(etcd.TaskSchemaRoot, false, true)
	if err != nil {
		err = etcd.ErrorFromEtcdError(logger, err)

		// Continue if the root node does not exist
		if err != models.ErrResourceNotFound {
			return err
		}
	}

	if response != nil {
		taskRootNode := response.Node
		for _, node := range taskRootNode.Nodes {
			var task models.Task
			err := b.reWriteNode(logger, node, &task)
			if err != nil {
				return err
			}
		}
	}

	return nil
}