/** * Method looks in the cache for the cluster by name. If none exists, a new * ThriftCluster instance is created and added to the map of known clusters * * @param clusterName * The cluster name. This is an identifying string for the cluster, * e.g. "production" or "test" etc. Clusters will be created on * demand per each unique clusterName key. * @param cassandraHostConfigurator * @param credentials */ public static Cluster createCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String, String> credentials) { synchronized (clusters) { Cluster cluster = clusters.get(clusterName); if ( cluster == null ) { cluster = new ThriftCluster(clusterName, cassandraHostConfigurator, credentials); clusters.put(clusterName, cluster); cluster.onStartup(); } return cluster; } }
private Keyspace keyspace(final String host, final String clusterName, final String keyspaceName, final String consistency) { if (clusterName == null) { throw new IllegalArgumentException("cluster name can't be null"); } if (keyspaceName == null) { throw new IllegalArgumentException("keyspace name can't be null"); } if (host == null) { throw new IllegalArgumentException("host can't be null"); } final ConfigurableConsistencyLevel consistencyLevelPolicy = new ConfigurableConsistencyLevel(); if (consistency == null) { consistencyLevelPolicy.setDefaultReadConsistencyLevel(HConsistencyLevel.QUORUM); } else { consistencyLevelPolicy.setDefaultReadConsistencyLevel(HConsistencyLevel.valueOf(consistency.toUpperCase())); } final ThriftCluster cluster = new ThriftCluster(clusterName, new CassandraHostConfigurator(host)); return HFactory.createKeyspace(keyspaceName, cluster, consistencyLevelPolicy); }
@Before public void setupCase() throws TTransportException, TException, IllegalArgumentException, NotFoundException, UnknownHostException, Exception { cassandraHostConfigurator = getCHCForTest(); cassandraCluster = new ThriftCluster(clusterName, cassandraHostConfigurator); }
@Before public void setupCase() throws TTransportException, TException, IllegalArgumentException, NotFoundException, UnknownHostException, Exception { cassandraHostConfigurator = getCHCForTest(); cassandraCluster = new ThriftCluster(clusterName, cassandraHostConfigurator); }
@Test public void testDescribeKeyspaces() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1Credentials); List<KeyspaceDefinition> keyspaces = cassandraCluster.describeKeyspaces(); assertEquals(2,keyspaces.size()); }
@Test public void testDescribeKeyspace() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1Credentials); KeyspaceDefinition keyspaceDetail = cassandraCluster.describeKeyspace("Keyspace1"); assertNotNull(keyspaceDetail); assertEquals(22, keyspaceDetail.getCfDefs().size()); }
@Test public void testAddDropKeyspace() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1Credentials); ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("DynKeyspace", "DynCf"); cassandraCluster.addKeyspace( new ThriftKsDef("DynKeyspace", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef))); String ksid2 = cassandraCluster.dropKeyspace("DynKeyspace"); assertNotNull(ksid2); }
@Test public void testDescribeKeyspacesBadAuth() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1CredentialsBad); try { cassandraCluster.describeKeyspaces(); fail("Should have gotten a wrapped AuthenticationException"); } catch (HectorException he) { assertTrue(he.getCause() instanceof AuthenticationException); } }
@Test public void testAddDropColumnFamily() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1Credentials); ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("Keyspace1", "DynCf"); cassandraCluster.addColumnFamily(cfDef); String cfid2 = cassandraCluster.dropColumnFamily("Keyspace1", "DynCf"); assertNotNull(cfid2); }
@Before public void setUp() throws Exception { super.setupClient(); KEYSPACE_DEV = new ThriftKsDef(new KsDef(KEYSPACE, "org.apache.cassandra.locator.SimpleStrategy", Arrays.asList(new CfDef[] { BLOB_CF_DEF }))); ((ThriftKsDef)KEYSPACE_DEV).setReplicationFactor(1); cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator); keyspace = HFactory.createKeyspace(KEYSPACE, cassandraCluster); try { cassandraCluster.dropKeyspace(KEYSPACE); } catch (Exception e) { } cassandraCluster.addKeyspace(KEYSPACE_DEV); }
/** * Method looks in the cache for the cluster by name. If none exists, a new * ThriftCluster instance is created and added to the map of known clusters * * @param clusterName * The cluster name. This is an identifying string for the cluster, * e.g. "production" or "test" etc. Clusters will be created on * demand per each unique clusterName key. * @param cassandraHostConfigurator * @param credentials */ public static Cluster createCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String, String> credentials) { synchronized (clusters) { Cluster cluster = clusters.get(clusterName); if ( cluster == null ) { cluster = new ThriftCluster(clusterName, cassandraHostConfigurator, credentials); clusters.put(clusterName, cluster); cluster.onStartup(); } return cluster; } }
/** * Method looks in the cache for the cluster by name. If none exists, a new * ThriftCluster instance is created and added to the map of known clusters * * @param clusterName * The cluster name. This is an identifying string for the cluster, * e.g. "production" or "test" etc. Clusters will be created on * demand per each unique clusterName key. * @param cassandraHostConfigurator * @param credentials */ public static Cluster createCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String, String> credentials) { synchronized (clusters) { Cluster cluster = clusters.get(clusterName); if ( cluster == null ) { cluster = new ThriftCluster(clusterName, cassandraHostConfigurator, credentials); clusters.put(clusterName, cluster); cluster.onStartup(); } return cluster; } }