Example #1
0
func getAllocatedInfo(repo *redis.RemoteRepository) (Allocated, error) {
	allocated := Allocated{}

	allocatedInstances, err := repo.AllInstances()
	if err != nil {
		return allocated, err
	}

	for _, instance := range allocatedInstances {
		bindingIDs, err := repo.BindingsForInstance(instance.ID)
		if err != nil {
			return allocated, err
		}

		c := Cluster{
			ID:    instance.ID,
			Hosts: []string{instance.Host},
		}

		for _, id := range bindingIDs {
			c.Bindings = append(c.Bindings, Binding{ID: id})
		}

		allocated.Clusters = append(allocated.Clusters, c)
	}

	allocated.Count = len(allocatedInstances)

	return allocated, nil
}
Example #2
0
func getPoolInfo(repo *redis.RemoteRepository) Pool {
	pool := Pool{}

	availableNodes := []string{}
	for _, instance := range repo.AvailableInstances() {
		availableNodes = append(availableNodes, instance.Host)
	}

	pool.Count = len(availableNodes)

	for _, node := range availableNodes {
		cluster := []string{node}
		pool.Clusters = append(pool.Clusters, cluster)
	}

	return pool
}
	"github.com/pivotal-cf/brokerapi"
	"github.com/pivotal-cf/cf-redis-broker/brokerconfig"
	"github.com/pivotal-cf/cf-redis-broker/redis"
	"github.com/pivotal-cf/cf-redis-broker/redis/fakes"
	"github.com/pivotal-golang/lager/lagertest"

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

var _ = Describe("RemoteRepository", func() {
	var (
		repo            *redis.RemoteRepository
		statefilePath   string
		tmpDir          string
		config          brokerconfig.Config
		fakeAgentClient *fakes.FakeAgentClient
		logger          *lagertest.TestLogger
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("remote-repo")
		config = brokerconfig.Config{}
		config.RedisConfiguration.Dedicated.Nodes = []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"}
		config.RedisConfiguration.Dedicated.Port = 6379
		config.AgentPort = "1234"

		var err error
		tmpDir, err = ioutil.TempDir("", "cf-redis-broker")
		Expect(err).ToNot(HaveOccurred())