use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class DbClientImpl method removeObject.
public void removeObject(Class<? extends DataObject> clazz, DataObject... object) {
tracer.newTracer("write");
List<DataObject> allObjects = Arrays.asList(object);
Keyspace ks = getKeyspace(clazz);
DataObjectType doType = null;
RemovedColumnsList removedList = new RemovedColumnsList();
for (DataObject dataObject : allObjects) {
_log.debug("Try to remove data object {}", dataObject.getId());
checkGeoVersionForMutation(dataObject);
doType = TypeMap.getDoType(dataObject.getClass());
// delete all the index columns for this object first
if (doType == null) {
throw new IllegalArgumentException();
}
Row<String, CompositeColumnName> row = queryRowWithAllColumns(ks, dataObject.getId(), doType.getCF());
if (row != null) {
Iterator<Column<CompositeColumnName>> it = row.getColumns().iterator();
String key = row.getKey();
while (it.hasNext()) {
Column<CompositeColumnName> column = it.next();
removedList.add(key, column);
}
}
}
if (!removedList.isEmpty()) {
boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
_indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
}
}
use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class InternalDbClientImpl method countTimeSeries.
public int countTimeSeries(String cfName, Calendar startTime, Calendar endTime) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/HH");
String startTimeStr = dateFormat.format(startTime.getTime());
String endTimeStr = dateFormat.format(endTime.getTime());
int recordCount = 0;
try {
Keyspace keyspace = getLocalKeyspace();
ColumnFamily<String, String> cf = new ColumnFamily<String, String>(cfName, StringSerializer.get(), StringSerializer.get());
List<String> keys = genTimeSeriesKeys(startTime, endTime);
for (String key : keys) {
recordCount += keyspace.prepareQuery(cf).getKey(key).getCount().execute().getResult();
}
System.out.println(String.format("Column Family %s's record count between %s and %s is: %s", cfName, startTimeStr, endTimeStr, recordCount));
return recordCount;
} catch (ConnectionException e) {
System.err.println(String.format("Exception=%s", e));
throw DatabaseException.retryables.connectionFailed(e);
}
}
use of com.netflix.astyanax.Keyspace in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method clearStorage.
@Override
public void clearStorage() throws BackendException {
try {
Cluster cluster = clusterContext.getClient();
Keyspace ks = cluster.getKeyspace(keySpaceName);
// everything up, so first invocation would always fail as Keyspace doesn't yet exist.
if (ks == null)
return;
if (this.storageConfig.get(GraphDatabaseConfiguration.DROP_ON_CLEAR)) {
ks.dropKeyspace();
} else {
final KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keySpaceName);
if (keyspaceDefinition == null) {
return;
}
for (final ColumnFamilyDefinition cf : keyspaceDefinition.getColumnFamilyList()) {
ks.truncateColumnFamily(new ColumnFamily<>(cf.getName(), null, null));
}
}
} catch (ConnectionException e) {
throw new PermanentBackendException(e);
}
}
use of com.netflix.astyanax.Keyspace in project zuul by Netflix.
the class StartServer method initCassandra.
void initCassandra() throws Exception {
if (cassandraEnabled.get()) {
LOG.info("Getting AstyanaxContext");
Keyspace keyspace = CassandraHelper.getInstance().getZuulCassKeyspace();
LOG.info("Initializing Cassandra ZuulFilterDAO");
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(keyspace);
LOG.info("Starting ZuulFilter Poller");
ZuulFilterPoller.start(dao);
}
}
use of com.netflix.astyanax.Keyspace in project zuul by Netflix.
the class CassandraHelper method getZuulCassKeyspace.
/**
* @return the Keyspace for the Zuul Cassandra cluster which stores filters
* @throws Exception
*/
public Keyspace getZuulCassKeyspace() throws Exception {
if (zuulCassKeyspace != null)
return zuulCassKeyspace;
try {
setAstynaxConfiguration(ConfigurationManager.getConfigInstance());
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder().forKeyspace(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_KEYSPACE, "zuul_scripts").get()).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)).withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("cass_connection_pool").setPort(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()).setMaxConnsPerHost(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_MAXCONNECTIONSPERHOST, 1).get()).setSeeds(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_HOST, "").get() + ":" + DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
zuulCassKeyspace = context.getClient();
return zuulCassKeyspace;
} catch (Exception e) {
LOG.error("Exception occurred when initializing Cassandra keyspace: " + e);
throw e;
}
}
Aggregations