Example #1
0
func (store *GardenStore) transitionToComplete(logger lager.Logger, gardenContainer garden.Container, result executor.ContainerRunResult) error {
	resultJson, err := json.Marshal(result)
	if err != nil {
		return err
	}

	err = gardenContainer.SetProperty(ContainerResultProperty, string(resultJson))
	if err != nil {
		return err
	}

	err = gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateCompleted))
	if err != nil {
		return err
	}

	executorContainer, err := store.exchanger.Info(logger, gardenContainer)
	if err != nil {
		return err
	}

	store.eventEmitter.Emit(executor.NewContainerCompleteEvent(executorContainer))

	return nil
}
Example #2
0
func (a *AllocationStore) Fail(logger lager.Logger, guid string, reason string) (executor.Container, error) {
	a.lock.Lock()
	defer a.lock.Unlock()

	container, err := a.lookup(guid)
	if err != nil {
		logger.Error("failed-completing-container", err)
		return executor.Container{}, err
	}

	if container.State == executor.StateCompleted {
		logger.Error(
			"failed-completing-container",
			executor.ErrInvalidTransition,
			lager.Data{
				"current_state":  container.State,
				"expected_state": executor.StateInitializing,
			},
		)
		return executor.Container{}, executor.ErrInvalidTransition
	}

	logger.Debug("marking-container-completed-with-failure-reason", lager.Data{
		"guid":           guid,
		"failure_reason": reason,
	})

	container.State = executor.StateCompleted
	container.RunResult = executor.ContainerRunResult{
		Failed:        true,
		FailureReason: reason,
	}
	a.allocated[guid] = container

	a.eventEmitter.Emit(executor.NewContainerCompleteEvent(container))

	return container, nil
}
Example #3
0
					BeforeEach(func() {
						container = executor.Container{
							Guid: "some-instance-guid",

							State: executor.StateCompleted,

							Tags: executor.Tags{
								rep.ProcessGuidTag:  "some-process-guid",
								rep.DomainTag:       "some-domain",
								rep.ProcessIndexTag: "1",
							},
						}
					})

					JustBeforeEach(func() {
						receivedEvents <- executor.NewContainerCompleteEvent(container)
					})

					Context("when the lifecycle is LRP", func() {
						BeforeEach(func() {
							container.Tags[rep.LifecycleTag] = rep.LRPLifecycle
						})

						It("yields an operation for that container", func() {
							var operation operationq.Operation
							Eventually(stream).Should(Receive(&operation))
							Expect(operation.Key()).To(Equal(container.Guid))
						})
					})

					Context("when the lifecycle is Task", func() {
			})

			It("it is marked as COMPLETED with failure reason", func() {
				emitCallCount := fakeEventEmitter.EmitCallCount()
				allocation, err := allocationStore.Fail(logger, req.Guid, "failure-reason")
				Expect(err).NotTo(HaveOccurred())

				Expect(allocation.Guid).To(Equal(req.Guid))
				Expect(allocation.State).To(Equal(executor.StateCompleted))
				Expect(allocation.RunResult).To(Equal(executor.ContainerRunResult{
					Failed:        true,
					FailureReason: "failure-reason",
				}))

				Expect(fakeEventEmitter.EmitCallCount()).To(Equal(emitCallCount + 1))
				Expect(fakeEventEmitter.EmitArgsForCall(emitCallCount)).To(Equal(executor.NewContainerCompleteEvent(allocation)))
			})

			It("remains in the allocation store as reserved", func() {
				c, err := allocationStore.Lookup(req.Guid)
				Expect(err).NotTo(HaveOccurred())
				Expect(c.State).To(Equal(executor.StateReserved))
			})

			Context("when the container is already in the completed state", func() {
				BeforeEach(func() {
					runReq := executor.NewRunRequest(req.Guid, &executor.RunInfo{}, executor.Tags{})
					err := allocationStore.Initialize(logger, &runReq)
					Expect(err).NotTo(HaveOccurred())

					_, err = allocationStore.Fail(logger, req.Guid, "force-completed")