func launchExternalHTTPReps() map[string]rep.SimClient {
	repNodeBinary, err := gexec.Build("github.com/cloudfoundry-incubator/auction/simulation/repnode")
	Expect(err).NotTo(HaveOccurred())

	cells := map[string]rep.SimClient{}

	client := &http.Client{
		Timeout: timeout,
	}
	for i := 0; i < numCells; i++ {
		repGuid := cellGuid(i)
		httpAddr := fmt.Sprintf("127.0.0.1:%d", 30000+i)

		serverCmd := exec.Command(
			repNodeBinary,
			"-repGuid", repGuid,
			"-httpAddr", httpAddr,
			"-memoryMB", fmt.Sprintf("%d", repResources.MemoryMB),
			"-diskMB", fmt.Sprintf("%d", repResources.DiskMB),
			"-containers", fmt.Sprintf("%d", repResources.Containers),
			"-stack", linuxStack,
			"-zone", zone(i),
		)

		sess, err := gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
		sessionsToTerminate = append(sessionsToTerminate, sess)
		Eventually(sess).Should(gbytes.Say("listening"))

		cells[cellGuid(i)] = rep.NewClient(client, "http://"+httpAddr).(rep.SimClient)
	}

	return cells
}
Exemplo n.º 2
0
func RepState(out io.Writer) (err error) {
	client := rep.NewClient(&http.Client{
		Timeout: 5 * time.Second,
	}, "http://localhost:1800")

	t := time.Now()
	state, err := client.State()
	dt := time.Since(t)

	if err != nil {
		say.Println(0, "Cell State [%s] - Error:%s", dt, say.Red(err.Error()))
		return err
	}

	name := say.Green("Cell State")
	if state.Evacuating {
		name = say.Red("Cell State - EVAC -")
	}

	rootFSes := []string{}
	for key := range state.RootFSProviders {
		if key != "preloaded" {
			rootFSes = append(rootFSes, say.Yellow(key))
		}
	}

	for key := range state.RootFSProviders["preloaded"].(rep.FixedSetRootFSProvider).FixedSet {
		rootFSes = append(rootFSes, say.Green("preloaded:%s", key))
	}

	say.Println(0, "%s [%s] - Zone:%s | %s Tasks, %s LRPs | C:%d/%d M:%d/%d D:%d/%d | %s",
		name,
		dt,
		say.Cyan(state.Zone),
		say.Cyan("%d", len(state.Tasks)),
		say.Cyan("%d", len(state.LRPs)),
		state.AvailableResources.Containers,
		state.TotalResources.Containers,
		state.AvailableResources.MemoryMB,
		state.TotalResources.MemoryMB,
		state.AvailableResources.DiskMB,
		state.TotalResources.DiskMB,
		strings.Join(rootFSes, ", "),
	)

	return nil
}
Exemplo n.º 3
0
					Expect(cells[cellID]).To(Equal(cellPresence))

					Expect(runner.Session).NotTo(Exit())
				})
			})
		})

		Context("acting as an auction representative", func() {
			var client rep.Client

			JustBeforeEach(func() {
				Eventually(fetchCells(logger, serviceClient)).Should(HaveLen(1))
				cells, err := serviceClient.Cells(logger)
				Expect(err).NotTo(HaveOccurred())

				client = rep.NewClient(http.DefaultClient, cf_http.NewCustomTimeoutClient(100*time.Millisecond), cells[cellID].RepAddress)
			})

			Context("Capacity with a container", func() {
				BeforeEach(func() {
					fakeGarden.RouteToHandler("GET", "/containers",
						ghttp.RespondWithJSONEncoded(http.StatusOK, map[string][]string{"handles": []string{"handle-guid"}}),
					)
					fakeGarden.RouteToHandler("GET", "/containers/bulk_info",
						ghttp.RespondWithJSONEncoded(http.StatusOK,
							map[string]garden.ContainerInfoEntry{
								"handle-guid": garden.ContainerInfoEntry{Info: garden.ContainerInfo{
									Properties: map[string]string{
										gardenstore.ContainerStateProperty:    string(executor.StateRunning),
										gardenstore.ContainerMemoryMBProperty: "512", gardenstore.ContainerDiskMBProperty: "1024"},
								}},
Exemplo n.º 4
0
	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/cloudfoundry-incubator/cf_http"
	"github.com/cloudfoundry-incubator/rep"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Client", func() {
	var fakeServer *ghttp.Server
	var client rep.Client

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		client = rep.NewClient(cf_http.NewClient(), fakeServer.URL())
	})

	AfterEach(func() {
		fakeServer.Close()
	})

	Describe("StopLRPInstance", func() {
		const cellAddr = "cell.example.com"
		var stopErr error
		var actualLRP = models.ActualLRP{
			ActualLRPKey:         models.NewActualLRPKey("some-process-guid", 2, "test-domain"),
			ActualLRPInstanceKey: models.NewActualLRPInstanceKey("some-instance-guid", "some-cell-id"),
		}

		JustBeforeEach(func() {
Exemplo n.º 5
0
	cf_http.Initialize(cfHttpTimeout)
})

var _ = BeforeEach(func() {
	logger := lagertest.NewTestLogger("test")

	auctionRep = &repfakes.FakeClient{}
	fakeLRPStopper = &fake_lrp_stopper.FakeLRPStopper{}
	fakeExecutorClient = &executorfakes.FakeClient{}
	fakeEvacuatable = &fake_evacuation_context.FakeEvacuatable{}

	handler, err := rata.NewRouter(rep.Routes, handlers.New(auctionRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger))
	Expect(err).NotTo(HaveOccurred())
	server = httptest.NewServer(handler)

	client = rep.NewClient(&http.Client{}, server.URL)

	serverThatErrors = ghttp.NewServer()
	erroringHandler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
		serverThatErrors.CloseClientConnections()
	})
	//5 erroringHandlers should be more than enough: none of the individual tests should make more than 5 requests to this server
	serverThatErrors.AppendHandlers(erroringHandler, erroringHandler, erroringHandler, erroringHandler, erroringHandler)

	clientForServerThatErrors = rep.NewClient(&http.Client{}, serverThatErrors.URL())
})

var _ = AfterEach(func() {
	server.Close()
	serverThatErrors.Close()
})
Exemplo n.º 6
0
					Expect(cells[0]).To(Equal(cellPresence))

					Expect(runner.Session).NotTo(Exit())
				})
			})
		})

		Context("acting as an auction representative", func() {
			var client rep.Client

			JustBeforeEach(func() {
				Eventually(locketClient.Cells).Should(HaveLen(1))
				cells, err := locketClient.Cells()
				Expect(err).NotTo(HaveOccurred())

				client = rep.NewClient(http.DefaultClient, cells[0].RepAddress)
			})

			Context("Capacity with a container", func() {
				BeforeEach(func() {
					fakeGarden.RouteToHandler("GET", "/containers",
						ghttp.RespondWithJSONEncoded(http.StatusOK, map[string][]string{"handles": []string{"handle-guid"}}),
					)
					fakeGarden.RouteToHandler("GET", "/containers/bulk_info",
						ghttp.RespondWithJSONEncoded(http.StatusOK,
							map[string]garden.ContainerInfoEntry{
								"handle-guid": garden.ContainerInfoEntry{Info: garden.ContainerInfo{
									Properties: map[string]string{
										gardenstore.ContainerStateProperty:    string(executor.StateRunning),
										gardenstore.ContainerMemoryMBProperty: "512", gardenstore.ContainerDiskMBProperty: "1024"},
								}},