Esempio n. 1
0
func (b *LinuxBackend) BulkInfo(handles []string) (map[string]garden.ContainerInfoEntry, error) {
	containers := b.containerRepo.Query(withHandles(handles), nil)

	infos := make(map[string]garden.ContainerInfoEntry)
	for _, container := range containers {
		info, err := container.Info()
		if err != nil {
			infos[container.Handle()] = garden.ContainerInfoEntry{
				Err: garden.NewError(err.Error()),
			}
		} else {
			infos[container.Handle()] = garden.ContainerInfoEntry{
				Info: info,
			}
		}
	}

	return infos, nil
}
Esempio n. 2
0
func (b *LinuxBackend) BulkMetrics(handles []string) (map[string]garden.ContainerMetricsEntry, error) {
	containers := b.containerRepo.Query(withHandles(handles), nil)

	metrics := make(map[string]garden.ContainerMetricsEntry)
	for _, container := range containers {
		metric, err := container.Metrics()
		if err != nil {
			metrics[container.Handle()] = garden.ContainerMetricsEntry{
				Err: garden.NewError(err.Error()),
			}
		} else {
			metrics[container.Handle()] = garden.ContainerMetricsEntry{
				Metrics: metric,
			}
		}
	}

	return metrics, nil
}
Esempio n. 3
0
					),
				)
			})

			It("returns the error", func() {
				_, err := connection.BulkInfo(handles)
				Ω(err).Should(HaveOccurred())
			})
		})

		Context("when a container is in error state", func() {
			It("returns the error for the container", func() {

				expectedBulkInfo := map[string]garden.ContainerInfoEntry{
					"error": garden.ContainerInfoEntry{
						Err: garden.NewError("Oopps"),
					},
					"success": garden.ContainerInfoEntry{
						Info: garden.ContainerInfo{
							State: "container2state",
						},
					},
				}

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/containers/bulk_info", queryParams),
						ghttp.RespondWith(200, marshalProto(expectedBulkInfo))))

				bulkInfo, err := connection.BulkInfo(handles)
				Ω(err).ShouldNot(HaveOccurred())
			BeforeEach(func() {
				container2.InfoReturns(garden.ContainerInfo{}, errors.New("Oh no!"))
			})

			It("returns the err for the failed container", func() {
				bulkInfo, err := linuxBackend.BulkInfo(handles)
				Expect(err).ToNot(HaveOccurred())

				Expect(bulkInfo).To(Equal(map[string]garden.ContainerInfoEntry{
					container1.Handle(): garden.ContainerInfoEntry{
						Info: garden.ContainerInfo{
							HostIP: "hostip for handle1",
						},
					},
					container2.Handle(): garden.ContainerInfoEntry{
						Err: garden.NewError("Oh no!"),
					},
				}))
			})
		})
	})

	Describe("BulkMetrics", func() {
		newContainer := func(n uint64) *fakes.FakeContainer {
			fakeContainer := &fakes.FakeContainer{}
			fakeContainer.HandleReturns(fmt.Sprintf("handle%d", n))
			fakeContainer.MetricsReturns(
				garden.Metrics{
					DiskStat: garden.ContainerDiskStat{
						TotalInodesUsed: n,
					},