コード例 #1
0
ファイル: garden_store.go プロジェクト: snowsnail/executor
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
}
コード例 #2
0
ファイル: garden_store.go プロジェクト: snowsnail/executor
func (store *GardenStore) transitionToRunning(logger lager.Logger, gardenContainer garden.Container) error {
	err := gardenContainer.SetProperty(ContainerStateProperty, string(executor.StateRunning))
	if err != nil {
		return err
	}

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

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

	return nil
}
コード例 #3
0
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/api/containers/containerhandle/properties/key"),
					func() http.HandlerFunc {
						return func(w http.ResponseWriter, req *http.Request) {
							body, err := ioutil.ReadAll(req.Body)
							Expect(err).NotTo(HaveOccurred())
							Expect(string(body)).Should(Equal(payloadText))
						}
					}(),
					ghttp.RespondWith(200, "a body that doesn't matter"),
				),
			)
		})

		It("makes a call out to an external service", func() {
			err := container.SetProperty("key", payloadText)
			Expect(err).NotTo(HaveOccurred())
			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})
	})

	Describe("RemoveProperty", func() {
		BeforeEach(func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("DELETE", "/api/containers/containerhandle/properties/key"),
					ghttp.RespondWith(204, ""),
				),
			)
		})
コード例 #4
0
ファイル: container_test.go プロジェクト: digideskio/guardian
	Describe("Properties", func() {
		BeforeEach(func() {
			propertyManager = new(fakes.FakePropertyManager)
			container = gardener.NewContainer(nil, "some-handle", nil, nil, propertyManager)
		})

		It("delegates to the property manager for Properties", func() {
			container.Properties()
			Expect(propertyManager.AllCallCount()).To(Equal(1))
			handle := propertyManager.AllArgsForCall(0)
			Expect(handle).To(Equal("some-handle"))
		})

		It("delegates to the property manager for SetProperty", func() {
			container.SetProperty("name", "value")
			Expect(propertyManager.SetCallCount()).To(Equal(1))
			handle, prop, val := propertyManager.SetArgsForCall(0)
			Expect(handle).To(Equal("some-handle"))
			Expect(prop).To(Equal("name"))
			Expect(val).To(Equal("value"))
		})

		It("delegates to the property manager for Property", func() {
			container.Property("name")
			Expect(propertyManager.GetCallCount()).To(Equal(1))
			handle, name := propertyManager.GetArgsForCall(0)
			Expect(handle).To(Equal("some-handle"))
			Expect(name).To(Equal("name"))
		})
コード例 #5
0
		Describe("info for one container", func() {
			It("includes the properties", func() {
				info, err := container.Info()
				Expect(err).ToNot(HaveOccurred())

				Expect(info.Properties["foo"]).To(Equal("bar"))
				Expect(info.Properties["a"]).To(Equal("b"))

				Expect(info.Properties).To(HaveLen(2))
			})
		})

		Describe("getting container properties without getting info", func() {
			It("can list properties", func() {
				err := container.SetProperty("bar", "baz")

				value, err := container.Properties()
				Expect(err).ToNot(HaveOccurred())
				Expect(value).To(HaveKeyWithValue("foo", "bar"))
				Expect(value).To(HaveKeyWithValue("bar", "baz"))
			})
		})

		Describe("updating container properties", func() {
			It("can CRUD", func() {
				value, err := container.Property("foo")
				Expect(err).ToNot(HaveOccurred())
				Expect(value).To(Equal("bar"))

				err = container.SetProperty("foo", "baz")
コード例 #6
0
		})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	It("can get properties", func() {
		properties, err := container.Properties()
		Expect(err).NotTo(HaveOccurred())
		Expect(properties).To(HaveKeyWithValue("somename", "somevalue"))
	})

	It("can set a single property", func() {
		err := container.SetProperty("someothername", "someothervalue")
		Expect(err).NotTo(HaveOccurred())

		properties, err := container.Properties()
		Expect(err).NotTo(HaveOccurred())
		Expect(properties).To(HaveKeyWithValue("somename", "somevalue"))
		Expect(properties).To(HaveKeyWithValue("someothername", "someothervalue"))
	})

	It("can get a single property", func() {
		err := container.SetProperty("bing", "bong")
		Expect(err).NotTo(HaveOccurred())

		value, err := container.Property("bing")
		Expect(err).NotTo(HaveOccurred())
		Expect(value).To(Equal("bong"))
コード例 #7
0
					It("returns an error", func() {
						value, err := container.GetProperty("some-property")
						Ω(err).Should(HaveOccurred())
						Ω(value).Should(BeZero())
					})
				})
			})

			Describe("setting", func() {
				Context("when setting the property succeeds", func() {
					BeforeEach(func() {
						fakeContainer.SetPropertyReturns(nil)
					})

					It("sets the property on the container", func() {
						err := container.SetProperty("some-property", "some-value")
						Ω(err).ShouldNot(HaveOccurred())

						Ω(fakeContainer.SetPropertyCallCount()).Should(Equal(1))

						name, value := fakeContainer.SetPropertyArgsForCall(0)
						Ω(name).Should(Equal("some-property"))
						Ω(value).Should(Equal("some-value"))
					})

					itResetsGraceTimeWhenHandling(func() {
						err := container.SetProperty("some-property", "some-value")
						Ω(err).ShouldNot(HaveOccurred())
					})

					itFailsWhenTheContainerIsNotFound(func() error {
コード例 #8
0
			Consistently(client).ShouldNot(gbytes.Say("banana"))
		})
	})

	Context("when working with properties", func() {
		BeforeEach(func() {
			containerSpec = garden.ContainerSpec{
				Properties: garden.Properties{
					"super": "banana",
				},
			}
		})

		It("should not log the properties when we are getting them", func() {
			_, err := container.Properties()
			Expect(err).ToNot(HaveOccurred())

			Consistently(client).ShouldNot(gbytes.Say("super"))
			Consistently(client).ShouldNot(gbytes.Say("banana"))
		})

		It("should not log the properties when we are setting them", func() {
			err := container.SetProperty("super", "banana")
			Expect(err).ToNot(HaveOccurred())

			Consistently(client).ShouldNot(gbytes.Say("super"))
			Consistently(client).ShouldNot(gbytes.Say("banana"))
		})
	})
})