예제 #1
0
func getAllTasks(store storeadapter.StoreAdapter, state models.TaskState) ([]*models.Task, error) {
	node, err := store.ListRecursively(TaskSchemaRoot)
	if err == storeadapter.ErrorKeyNotFound {
		return []*models.Task{}, nil
	}

	if err != nil {
		return []*models.Task{}, err
	}

	tasks := []*models.Task{}
	for _, node := range node.ChildNodes {
		task, err := models.NewTaskFromJSON(node.Value)
		if err != nil {
			steno.NewLogger("bbs").Errorf("cannot parse task JSON for key %s: %s", node.Key, err.Error())
		} else if task.State == state {
			tasks = append(tasks, &task)
		}
	}

	return tasks, nil
}
	AfterEach(func() {
		storeAdapter.Disconnect()
	})

	Describe("Saving stop messages", func() {
		BeforeEach(func() {
			err := store.SavePendingStopMessages(
				message1,
				message2,
			)
			Ω(err).ShouldNot(HaveOccurred())
		})

		It("stores the passed in stop messages", func() {
			node, err := storeAdapter.ListRecursively("/hm/v1/stop")
			Ω(err).ShouldNot(HaveOccurred())
			Ω(node.ChildNodes).Should(HaveLen(2))
			Ω(node.ChildNodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/hm/v1/stop/" + message1.StoreKey(),
				Value: message1.ToJSON(),
				TTL:   0,
			}))
			Ω(node.ChildNodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/hm/v1/stop/" + message2.StoreKey(),
				Value: message2.ToJSON(),
				TTL:   0,
			}))
		})
	})
예제 #3
0
					close(done)
				})
			})

			PIt("adds a TTL to the associated app", func(done Done) {
				app2Service2 := domain.AppService{AppId: app2Service1.AppId, Url: "syslog://new.example.com:12345"}

				incomingChan <- domain.AppServices{
					AppId: app2Service1.AppId,
					Urls:  []string{app2Service1.Url, app2Service2.Url},
				}

				assertInStore(app2Service1, app2Service2)

				node, err := adapter.ListRecursively("/loggregator/services/app-2")
				Expect(err).NotTo(HaveOccurred())
				Expect(node.TTL).NotTo(BeZero())

				close(done)
			})
		})

		Context("when a service or app should be removed", func() {
			Context("when an existing app loses one of its services", func() {
				It("removes that service from the store", func(done Done) {
					incomingChan <- domain.AppServices{
						AppId: app1Service1.AppId,
						Urls:  []string{app1Service1.Url},
					}