private void retrySetKeyspace(String ksName, Cassandra.Client client) throws BackendException { final long end = System.currentTimeMillis() + (60L * 1000L); while (System.currentTimeMillis() <= end) { try { client.set_keyspace(ksName); return; } catch (Exception e) { log.warn("Exception when changing to keyspace {} after creating it", ksName, e); try { Thread.sleep(1000L); } catch (InterruptedException ie) { throw new PermanentBackendException("Unexpected interrupt (shutting down?)", ie); } } } throw new PermanentBackendException("Could change to keyspace " + ksName + " after creating it"); }
client.set_keyspace(keySpaceName); ksDef = client.describe_keyspace(keySpaceName); } catch (NotFoundException e) { if (conn != null && conn.getClient() != null) { try { conn.getClient().set_keyspace(SYSTEM_KS); } catch (InvalidRequestException e) { log.warn("Failed to reset keyspace", e);
client.set_keyspace(keyspaceName); // Don't remove client.set_keyspace(SYSTEM_KS); log.debug("Found existing keyspace {}", keyspaceName); } catch (InvalidRequestException e) { .setStrategy_options(strategyOptions); client.set_keyspace(SYSTEM_KS); try { client.system_add_keyspace(ksdef);
client.set_keyspace(keyspace);
getClient().set_keyspace(keyspaceName); getClient().execute_cql3_query(ByteBuffer.wrap(cqlQuery.getBytes("UTF-8")), Compression.NONE, ConsistencyLevel.ONE);
client.set_keyspace(keyspace); for (String column : columns)
getClient().set_keyspace(keyspaceName); getClient().execute_cql3_query(ByteBuffer.wrap(cqlQuery.getBytes("UTF-8")), Compression.NONE, ConsistencyLevel.ONE);
client.set_keyspace(keyspace); for (String column : columns)
CassandraCli.createKeySpace("UUIDCassandra"); Cassandra.Client client = CassandraCli.getClient(); client.set_keyspace("UUIDCassandra"); CfDef cf_def = new CfDef(); cf_def.keyspace = "UUIDCassandra";
/** * Sets the up. * * @throws Exception * the exception */ @Before public void setUp() throws Exception { CassandraCli.cassandraSetUp(); CassandraCli.createKeySpace("KunderaExamples"); Cassandra.Client client = CassandraCli.getClient(); client.set_keyspace("KunderaExamples"); CfDef cf_def = new CfDef(); cf_def.keyspace = "KunderaExamples"; cf_def.name = "users"; cf_def.setKey_validation_class("UTF8Type"); ColumnDef columnDef2 = new ColumnDef(ByteBuffer.wrap("full_name".getBytes()), "UTF8Type"); columnDef2.index_type = IndexType.KEYS; cf_def.addToColumn_metadata(columnDef2); ColumnDef columnDef3 = new ColumnDef(ByteBuffer.wrap("birth_date".getBytes()), "Int32Type"); columnDef3.index_type = IndexType.KEYS; cf_def.addToColumn_metadata(columnDef3); ColumnDef columnDef4 = new ColumnDef(ByteBuffer.wrap("state".getBytes()), "UTF8Type"); columnDef4.index_type = IndexType.KEYS; cf_def.addToColumn_metadata(columnDef4); client.system_add_column_family(cf_def); }
/** * Drop keyspace or c fs. * * @throws InvalidRequestException * the invalid request exception * @throws SchemaDisagreementException * the schema disagreement exception * @throws TException * the t exception * @throws Exception * the exception */ private void dropKeyspaceOrCFs() throws InvalidRequestException, SchemaDisagreementException, TException, Exception { if (createdKeyspaces.contains(databaseName))// drop if created during // create-drop call. { cassandra_client.system_drop_keyspace(databaseName); } else { cassandra_client.set_keyspace(databaseName); for (TableInfo tableInfo : tableInfos) { dropColumnFamily(tableInfo); } } }
public static boolean columnFamilyExist(String columnfamilyName, String keyspaceName) { try { client.set_keyspace(keyspaceName); client.system_add_column_family(new CfDef(keyspaceName, columnfamilyName)); } catch (InvalidRequestException irex) { StringBuilder builder = new StringBuilder("^Cannot add already existing (?:column family|table) .*$"); if (irex.getWhy() != null && irex.getWhy().matches(builder.toString())) { return true; } return false; } catch (SchemaDisagreementException e) { return false; } catch (TException e) { return false; } return true; }
public static boolean columnFamilyExist(String columnfamilyName, String keyspaceName) { try { client.set_keyspace(keyspaceName); client.system_add_column_family(new CfDef(keyspaceName, columnfamilyName)); } catch (InvalidRequestException irex) { StringBuilder builder = new StringBuilder("Cannot add already existing column family "); if (irex.getWhy() != null && irex.getWhy().contains(builder.toString())) { return true; } return false; } catch (SchemaDisagreementException e) { return false; } catch (TException e) { return false; } return true; }
/** * On create keyspace. * * @return the ks def * @throws Exception * the exception */ private KsDef onCreateKeyspace() throws Exception { try { createdKeyspaces.add(databaseName); createKeyspace(); } catch (InvalidRequestException irex) { // Ignore and add a log.debug // keyspace already exists. // remove from list if already created. createdKeyspaces.remove(databaseName); } cassandra_client.set_keyspace(databaseName); return cassandra_client.describe_keyspace(databaseName); }
/** * {@inheritDoc} */ public Cassandra.Client getCassandra(String keyspaceNameArg) { getCassandra(); if ( keyspaceNameArg != null && !StringUtils.equals(keyspaceName, keyspaceNameArg)) { if ( log.isDebugEnabled() ) log.debug("keyspace reseting from {} to {}", keyspaceName, keyspaceNameArg); try { cassandraClient.set_keyspace(keyspaceNameArg); } catch (InvalidRequestException ire) { throw new HInvalidRequestException(ire); } catch (TException e) { throw exceptionsTranslator.translate(e); } keyspaceName = keyspaceNameArg; } return cassandraClient; }
private static Cassandra.Client getRawClientWithKeyspace(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws Exception { Client ret = getRawClient(addr, config); try { ret.set_keyspace(config.getKeyspaceOrThrow()); log.debug("Created new client for {}/{}{}{}", SafeArg.of("address", CassandraLogHelper.host(addr)), UnsafeArg.of("keyspace", config.getKeyspaceOrThrow()), SafeArg.of("usingSsl", config.usingSsl() ? " over SSL" : ""), UnsafeArg.of("usernameConfig", config.credentials().isPresent() ? " as user " + config.credentials().get().username() : "")); return ret; } catch (Exception e) { ret.getOutputProtocol().getTransport().close(); throw e; } }
private void createSchema() throws InvalidRequestException, TException, SchemaDisagreementException { Client client = CassandraCli.getClient(); CassandraCli.createKeySpace(keyspace); client.set_keyspace(keyspace); CfDef cfDef = new CfDef(); cfDef.keyspace = keyspace; cfDef.name = "counters"; cfDef.default_validation_class = "CounterColumnType"; cfDef.key_validation_class = "UTF8Type"; ColumnDef columnDef = new ColumnDef(ByteBuffer.wrap("counter".getBytes()), "CounterColumnType"); columnDef.index_type = IndexType.KEYS; cfDef.addToColumn_metadata(columnDef); cfDef.comparator_type = "UTF8Type"; client.system_add_column_family(cfDef); }
private void createSchema() throws InvalidRequestException, TException, SchemaDisagreementException { Client client = CassandraCli.getClient(); CassandraCli.createKeySpace(keyspace); client.set_keyspace(keyspace); CfDef cfDef = new CfDef(); cfDef.keyspace = keyspace; cfDef.name = "SuperCounters"; cfDef.column_type = "Super"; cfDef.default_validation_class = "CounterColumnType"; cfDef.comparator_type = "UTF8Type"; cfDef.subcomparator_type = "UTF8Type"; client.system_add_column_family(cfDef); }
@Override public void set_keyspace(String keyspace) throws InvalidRequestException, TException { client.set_keyspace(keyspace); }
@Override public CTConnection makeObject(String key) throws Exception { CTConnection conn = makeRawConnection(); Cassandra.Client client = conn.getClient(); client.set_keyspace(key); return conn; }