public void checkKeyspaces() { List<KeyspaceDefinition> ksDefs = null; try { ksDefs = cluster.describeKeyspaces(); } catch (Exception e) { log.error("Unable to describe keyspaces", e); } if (ksDefs != null) { for (KeyspaceDefinition ksDef : ksDefs) { log.info(ksDef.getName().toString()); } } }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getRpc_endpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
@Before public void setup() { cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); connectionManager = Mockito.mock(HConnectionManager.class); cluster = Mockito.mock(ThriftCluster.class); Mockito.when(cluster.getConfigurator()).thenReturn(cassandraHostConfigurator); final KeyspaceDefinition kdef = Mockito.mock(KeyspaceDefinition.class); Mockito.when(kdef.getName()).thenReturn("TestKeyspace"); Mockito.when(cluster.describeKeyspaces()).thenReturn(new LinkedList<KeyspaceDefinition>() {{ add(kdef); }}); }
public ThriftKsDef(KeyspaceDefinition keyspaceDefinition) { name = keyspaceDefinition.getName(); strategyClass = keyspaceDefinition.getStrategyClass(); strategyOptions = keyspaceDefinition.getStrategyOptions(); setReplicationFactor(keyspaceDefinition.getReplicationFactor()); cfDefs = keyspaceDefinition.getCfDefs(); }
private void checkCreateLockSchema() { KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspace.getKeyspaceName()); if (keyspaceDef == null) { ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspace.getKeyspaceName(), ThriftKsDef.DEF_STRATEGY_CLASS, lockManagerConfigurator.getReplicationFactor(), Arrays.asList(cfDef)); log.info("Creating Keyspace and Column Family for LockManager with name (KSPS/CF): (" + newKeyspace.getName() + " / " + cfDef.getName()); cluster.addKeyspace(newKeyspace, true); } else { log.info("Keyspace for LockManager already exists. Skipping creation."); // The Keyspace exists but we don't know anything about the CF yet. if (!doesLockCFExist(keyspaceDef)) { // create it ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); log.info("Creating Column Family for LockManager with name: " + cfDef.getName()); cluster.addColumnFamily(cfDef, true); } else { log.info("Column Family for LockManager already exists. Skipping creation."); } } }
private void dropKeyspaces() { List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); /* drop all keyspace except internal cassandra keyspace */ for (KeyspaceDefinition keyspaceDefinition : keyspaces) { String keyspaceName = keyspaceDefinition.getName(); if (!keyspaceName.startsWith(INTERNAL_CASSANDRA_KEYSPACE)) { cluster.dropKeyspace(keyspaceName, true); } } List<KeyspaceDefinition> keyspaces2 = cluster.describeKeyspaces(); }
private void dropKeyspaces() { List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); /* drop all keyspace except internal cassandra keyspace */ for (KeyspaceDefinition keyspaceDefinition : keyspaces) { String keyspaceName = keyspaceDefinition.getName(); if (!keyspaceName.startsWith(INTERNAL_CASSANDRA_KEYSPACE)) { cluster.dropKeyspace(keyspaceName, true); } } List<KeyspaceDefinition> keyspaces2 = cluster.describeKeyspaces(); }
@Override public boolean isAlive() { boolean alive = true; List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); List<String> names = new ArrayList<String>(); for (KeyspaceDefinition k : keyspaces) { names.add(k.getName()); } alive &= names.contains(CMBProperties.getInstance().getCQSKeyspace()); alive &= names.contains(CMBProperties.getInstance().getCNSKeyspace()); alive &= names.contains(CMBProperties.getInstance().getCMBKeyspace()); return alive; }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getRpc_endpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getEndpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getRpcPort(); log.debug("Cleaning cassandra keyspaces on " + host + ":" + port); Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator(host + ":" + port)); /* get all keyspace */ List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); /* drop all keyspace except internal cassandra keyspace */ for (KeyspaceDefinition keyspaceDefinition : keyspaces) { String keyspaceName = keyspaceDefinition.getName(); if (!INTERNAL_CASSANDRA_KEYSPACE.equals(keyspaceName)) { cluster.dropKeyspace(keyspaceName); } } }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getRpcPort(); log.debug("Cleaning cassandra keyspaces on " + host + ":" + port); Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator(host + ":" + port)); /* get all keyspace */ List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); /* drop all keyspace except internal cassandra keyspace */ for (KeyspaceDefinition keyspaceDefinition : keyspaces) { String keyspaceName = keyspaceDefinition.getName(); if (!INTERNAL_CASSANDRA_KEYSPACE.equals(keyspaceName)) { cluster.dropKeyspace(keyspaceName); } } }
public ThriftKsDef(KeyspaceDefinition keyspaceDefinition) { name = keyspaceDefinition.getName(); strategyClass = keyspaceDefinition.getStrategyClass(); strategyOptions = keyspaceDefinition.getStrategyOptions(); setReplicationFactor(keyspaceDefinition.getReplicationFactor()); cfDefs = keyspaceDefinition.getCfDefs(); }
public ThriftKsDef(KeyspaceDefinition keyspaceDefinition) { name = keyspaceDefinition.getName(); strategyClass = keyspaceDefinition.getStrategyClass(); strategyOptions = keyspaceDefinition.getStrategyOptions(); setReplicationFactor(keyspaceDefinition.getReplicationFactor()); cfDefs = keyspaceDefinition.getCfDefs(); }
/** * Private helper to initialize the schema */ protected void initializeSchema() throws Exception { if (keyspaceDefinitions.size() == 0) throw new IllegalStateException("no keyspace definitions founds, maybe add some entities to the factory"); for (KeyspaceDefinition keyspaceDefinition : ThriftKsDef.fromThriftList(new ArrayList<KsDef>(keyspaceDefinitions.values()))) { KeyspaceDefinition existingKeyspace = cluster.describeKeyspace(keyspaceDefinition.getName()); if (existingKeyspace == null) { cluster.addKeyspace(keyspaceDefinition, true); } else { for (ColumnFamilyDefinition columnFamilyDefinition : keyspaceDefinition.getCfDefs()) { if (keyspaceContainsColumnFamily(columnFamilyDefinition, existingKeyspace)) { log.debug(String.format("found column family %s, updating schema", columnFamilyDefinition.getName())); ColumnFamilyDefinition existingColumnFamilyDefinition = getColumnFamilyFromKeyspace(columnFamilyDefinition.getName(), existingKeyspace); existingColumnFamilyDefinition.getColumnMetadata().clear(); for (ColumnDefinition columnDefinition : columnFamilyDefinition.getColumnMetadata()) { existingColumnFamilyDefinition.addColumnDefinition(columnDefinition); } cluster.updateColumnFamily(existingColumnFamilyDefinition, true); } else { log.debug(String.format("not found column family %s, adding to schema", columnFamilyDefinition.getName())); cluster.addColumnFamily(columnFamilyDefinition, true); } } } } }
private void checkCreateLockSchema() { KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspace.getKeyspaceName()); if (keyspaceDef == null) { ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspace.getKeyspaceName(), ThriftKsDef.DEF_STRATEGY_CLASS, lockManagerConfigurator.getReplicationFactor(), Arrays.asList(cfDef)); log.info("Creating Keyspace and Column Family for LockManager with name (KSPS/CF): (" + newKeyspace.getName() + " / " + cfDef.getName()); cluster.addKeyspace(newKeyspace, true); } else { log.info("Keyspace for LockManager already exists. Skipping creation."); // The Keyspace exists but we don't know anything about the CF yet. if (!doesLockCFExist(keyspaceDef)) { // create it ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); log.info("Creating Column Family for LockManager with name: " + cfDef.getName()); cluster.addColumnFamily(cfDef, true); } else { log.info("Column Family for LockManager already exists. Skipping creation."); } } }