コード例 #1
0
ファイル: service_client.go プロジェクト: cfibmers/bbs
func (db *serviceClient) Cells(logger lager.Logger) (models.CellSet, error) {
	kvPairs, _, err := db.consulClient.KV().List(CellSchemaRoot(), nil)
	if err != nil {
		bbsErr := models.ConvertError(convertConsulError(err))
		if bbsErr.Type != models.Error_ResourceNotFound {
			return nil, bbsErr
		}
	}

	if kvPairs == nil {
		err = consuladapter.NewPrefixNotFoundError(CellSchemaRoot())
		bbsErr := models.ConvertError(convertConsulError(err))
		if bbsErr.Type != models.Error_ResourceNotFound {
			return nil, bbsErr
		}
	}

	cellPresences := models.NewCellSet()
	for _, kvPair := range kvPairs {
		if kvPair.Session == "" {
			continue
		}

		cell := kvPair.Value
		presence := new(models.CellPresence)
		err := models.FromJSON(cell, presence)
		if err != nil {
			logger.Error("failed-to-unmarshal-cells-json", err)
			continue
		}
		cellPresences.Add(presence)
	}

	return cellPresences, nil
}
コード例 #2
0
ファイル: cell_handlers_test.go プロジェクト: cfibmers/bbs
			{
				CellId:     "cell-2",
				RepAddress: "2.2.2.2",
				Zone:       "z2",
				Capacity: &models.CellCapacity{
					MemoryMb:   2000,
					DiskMb:     2000,
					Containers: 20,
				},
				RootfsProviders: []*models.Provider{
					&models.Provider{"preloaded", []string{"provider-1"}},
				},
				PlacementTags: []string{"test3", "test4"},
			},
		}
		cellSet = models.NewCellSet()
		cellSet.Add(cells[0])
		cellSet.Add(cells[1])
	})

	Describe("Cells", func() {
		JustBeforeEach(func() {
			handler.Cells(logger, responseRecorder, newTestRequest(""))
		})

		Context("when reading cells succeeds", func() {
			BeforeEach(func() {
				fakeServiceClient.CellsReturns(cellSet, nil)
			})

			It("returns a list of cells", func() {
コード例 #3
0
						MetricName: NsyncBulkerFetching,
					})
				}
			}()

			// start convergence
			go func() {
				defer GinkgoRecover()
				logger.Info("start-lrp-convergence-loop")
				defer logger.Info("finish-lrp-convergence-loop")
				wg.Add(1)
				defer wg.Done()
				for i := 0; i < numTrials; i++ {
					sleepDuration := getSleepDuration(i, bulkCycle)
					time.Sleep(sleepDuration)
					cellSet := models.NewCellSet()
					for i := 0; i < numReps; i++ {
						cellID := fmt.Sprintf("cell-%d", i)
						presence := models.NewCellPresence(cellID, "earth", "http://planet-earth", "north", models.CellCapacity{}, nil, nil, nil, nil)
						cellSet.Add(&presence)
					}

					b.Time("BBS' internal gathering of LRPs", func() {
						activeDB.ConvergeLRPs(logger, cellSet)
					}, reporter.ReporterInfo{
						MetricName: ConvergenceGathering,
					})
				}
			}()

			// start route-emitter