Example #1
0
func TestCBClustering(t *testing.T) {
	if !couchbase_running(couchbase_location) {
		t.Skip("Couchbase not running - skipping test")
	}
	ds, err := mock.NewDatastore("mock:")
	as, err := accounting_stub.NewAccountingStore("stub:")
	cs, err := NewConfigstore("http://" + couchbase_location + ":8091")
	if err != nil {
		t.Fatalf("Error creating configstore: ", err)
	}
	version := clustering.NewVersion("0.7.0")

	fmt.Printf("Created config store %v\n\n", cs)

	cfm := cs.ConfigurationManager()

	cluster1, _ := NewCluster("cluster1", version, cs, ds, as)

	fmt.Printf("Creating cluster %v\n\n", cluster1)

	cluster1, err = cfm.AddCluster(cluster1)

	if err != nil {
		t.Fatalf("Error adding cluster: ", err)
	}

	_, no_such_cluster := cs.ClusterByName("no_such_cluster")
	if no_such_cluster == nil {
		t.Fatalf("Expected error retrieving configuration of non-existent cluster")
	}
	if no_such_cluster.Code() != 2040 && no_such_cluster.TranslationKey() != "admin.clustering.get_cluster_error" {
		t.Fatalf("Expected error code %d", 2010)
	}
	// There should be a cluster called "default" in the Couchbase installation:
	cluster1check, errCheck := cs.ClusterByName("default")
	if errCheck != nil {
		t.Fatalf("Unexpected Error retrieving cluster by name: ", errCheck)
	}

	fmt.Printf("Retrieved cluster: %v\n\n", cluster1check)

	cm := cs.ConfigurationManager()

	// Get all clusters. There should be at least one ("default")
	clusters, errCheck := cm.GetClusters()
	clusters_json, json_err := json.Marshal(clusters)
	if err != nil {
		t.Fatalf("Unexpected Error marshalling GetClusters: ", json_err)
	}

	fmt.Printf("Retrieved clusters: %s\n", string(clusters_json))
	if errCheck != nil {
		t.Fatalf("Unexpected Error retrieving all cluster configs: ", errCheck)
	}
	iterateClusters(clusters, t)
}
Example #2
0
func NewClusterConfig(uri string,
	clusterName string,
	version string,
	datastore datastore.Datastore,
	acctstore accounting.AccountingStore,
	cfgstore clustering.ConfigurationStore) (clustering.Cluster, errors.Error) {

	if strings.HasPrefix(uri, "zookeeper:") {
		v := clustering.NewVersion(version)
		return clustering_zk.NewCluster(clusterName, v, cfgstore, datastore, acctstore)
	}
	return nil, errors.NewAdminInvalidURL("ConfigurationStore", uri)
}
Example #3
0
func NewQueryNodeConfig(uri string,
	version string,
	httpAddr string,
	opts clustering.ClOptions,
	datastore datastore.Datastore,
	acctstore accounting.AccountingStore,
	cfgstore clustering.ConfigurationStore) (clustering.QueryNode, errors.Error) {

	if strings.HasPrefix(uri, "zookeeper:") {
		v := clustering.NewVersion(version)
		s := clustering.NewStandalone(v, cfgstore, datastore, acctstore)
		return clustering_zk.NewQueryNode(httpAddr, s, &opts)
	}
	return nil, errors.NewAdminInvalidURL("ConfigurationStore", uri)
}
Example #4
0
func (z *zkCluster) Version() clustering.Version {
	if z.version == nil {
		z.version = clustering.NewVersion(z.VersionString)
	}
	return z.version
}
Example #5
0
func (c *cbCluster) Version() clustering.Version {
	if c.version == nil {
		c.version = clustering.NewVersion(c.VersionString)
	}
	return c.version
}
Example #6
0
func TestZKClustering(t *testing.T) {
	cs, err := NewConfigstore("localhost:2181")
	ds, err := mock.NewDatastore("mock:")
	as, err := accounting_stub.NewAccountingStore("stub:")
	version := clustering.NewVersion("0.7.0")
	version2 := clustering.NewVersion("0.7.9")
	stdCfg := clustering.NewStandalone(version, cs, ds, as)
	stdCfg2 := clustering.NewStandalone(version2, cs, ds, as)
	stdOpts := clustering.NewOptions(ds.URL(), cs.URL(), as.URL(), "default", false, false, true,
		runtime.NumCPU()<<16, runtime.NumCPU()<<6, 0, 0, ":8093", ":8094", "", false, "cluster1", "", "")

	if !zookeeper_running() {
		t.Skip("Zookeeper not running - skipping test")
	}

	if err != nil {
		t.Fatalf("Error creating configstore: ", err)
	}
	fmt.Printf("Created config store %v\n\n", cs)

	cfm := cs.ConfigurationManager()

	cluster1, _ := NewCluster("cluster1", version, cs, ds, as)

	fmt.Printf("Creating cluster %v\n\n", cluster1)

	cluster1, err = cfm.AddCluster(cluster1)

	if err != nil {
		t.Fatalf("Error adding cluster: ", err)
	}

	cluster1check, errCheck := cs.ClusterByName("cluster1")
	if errCheck != nil {
		t.Fatalf("Unexpected Error retrieving cluster by name: ", errCheck)
	}

	fmt.Printf("Retrieved cluster: %v\n\n", cluster1check)

	qn, err_qn := cluster1check.QueryNodeByName("qryNode")
	if err_qn == nil {
		t.Fatalf("Expected error getting query node: ", qn)
	}
	if qn != nil {
		t.Fatalf("Unexpected query node! ", qn)
	}

	clusterMgr := cluster1check.ClusterManager()

	queryNode, _ := NewQueryNode(":8093", stdCfg, stdOpts)
	queryNode, err_qn = clusterMgr.AddQueryNode(queryNode)
	if err_qn != nil {
		t.Fatalf("Unexpected error adding query node: ", err_qn)
	}
	fmt.Printf("Added query node %v to cluster %v\n\n", queryNode, cluster1)

	queryNode, _ = NewQueryNode(":8094", stdCfg, stdOpts)
	queryNode, err_qn = clusterMgr.AddQueryNode(queryNode)
	if err_qn != nil {
		t.Fatalf("Unexpected error adding query node: ", err_qn)
	}
	fmt.Printf("Added query node %v to cluster %v\n\n", queryNode, cluster1)

	queryNode, _ = NewQueryNode(":8095", stdCfg, stdOpts)
	queryNode, err_qn = clusterMgr.AddQueryNode(queryNode)
	if err_qn != nil {
		t.Fatalf("Unexpected error adding query node: ", err_qn)
	}
	fmt.Printf("Added query node %v to cluster %v\n\n", queryNode, cluster1)

	queryNode, _ = NewQueryNode(":8095", stdCfg2, stdOpts)
	queryNode, err_qn = clusterMgr.AddQueryNode(queryNode)
	if err_qn == nil {
		t.Fatalf("Expected error adding query node: version incompatibility")
	}
	fmt.Printf("Version incompatibility adding query node 4: %v\n\n", err_qn)

	qryNodes, errT := clusterMgr.GetQueryNodes()
	if errT != nil {
		t.Fatalf("Unexpected error getting query nodes: ", errT)
	}
	for i, qNode := range qryNodes {
		fmt.Printf("Query Node %d: configuration = %v\n\n", i, qNode)
	}

	clusters, errC := cfm.GetClusters()
	if errC != nil {
		t.Fatalf("Unexpected error getting clusters: ", errC)
	}
	for c, cluster := range clusters {
		fmt.Printf("Cluster %d: configuration = %v\n\n", c, cluster)
	}

	for _, qNode := range qryNodes {
		qNode, errT = clusterMgr.RemoveQueryNodeByName(qNode.Name())
		if errT != nil {
			t.Fatalf("Unexpected error removing query node: ", errT)
		}
	}
	r, err := cfm.RemoveClusterByName(cluster1check.Name())
	if err != nil {
		t.Fatalf("Unexpected error removing cluster: ", err)
	}
	if r {
		fmt.Printf("Successfully removed cluster \n\n", cluster1)
	}

}