use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelper method getIndicesOfCF.
public Map<String, IndexAndCf> getIndicesOfCF(DataObjectType objType) {
Map<String, IndexAndCf> idxCfs = new TreeMap<>();
Keyspace keyspace = dbClient.getKeyspace(objType.getDataObjectClass());
for (ColumnField field : objType.getColumnFields()) {
DbIndex index = field.getIndex();
if (index == null) {
continue;
}
IndexAndCf indexAndCf = new IndexAndCf(index.getClass(), field.getIndexCF(), keyspace);
String key = indexAndCf.generateKey();
IndexAndCf idxAndCf = idxCfs.get(key);
if (idxAndCf == null) {
idxAndCf = new IndexAndCf(index.getClass(), field.getIndexCF(), keyspace);
idxCfs.put(key, idxAndCf);
}
}
return idxCfs;
}
use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class DbClientImpl method scanRowsByType.
private <T extends DataObject> Iterable<Row<String, CompositeColumnName>> scanRowsByType(Class<T> clazz, Boolean inactiveValue, URI startId, int count) {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
try {
ColumnFamily<String, CompositeColumnName> cf = doType.getCF();
Keyspace ks = getKeyspace(clazz);
ColumnFamilyQuery<String, CompositeColumnName> query = ks.prepareQuery(cf);
// Column filter, get only last .inactive column, or get any column
ByteBufferRange columnRange = inactiveValue == null ? CompositeColumnNameSerializer.get().buildRange().limit(1).build() : CompositeColumnNameSerializer.get().buildRange().greaterThanEquals(DataObject.INACTIVE_FIELD_NAME).lessThanEquals(DataObject.INACTIVE_FIELD_NAME).reverse().limit(1).build();
Execution<Rows<String, CompositeColumnName>> exec;
if (count == Integer.MAX_VALUE) {
exec = query.getAllRows().withColumnRange(columnRange);
} else {
Partitioner partitioner = ks.getPartitioner();
String strKey = startId != null ? startId.toString() : null;
String startToken = strKey != null ? partitioner.getTokenForKey(cf.getKeySerializer().toByteBuffer(strKey)) : partitioner.getMinToken();
exec = query.getRowRange(strKey, null, startToken, partitioner.getMaxToken(), count).withColumnRange(columnRange);
}
return exec.execute().getResult();
} catch (ConnectionException e) {
throw DatabaseException.retryables.connectionFailed(e);
}
}
use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class DbClientImpl method aggregateObjectField.
@Override
public <T extends DataObject> void aggregateObjectField(Class<T> clazz, Iterator<URI> ids, DbAggregatorItf aggregator) {
tracer.newTracer("read");
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
boolean buildRange = false;
String[] fields = aggregator.getAggregatedFields();
CompositeColumnName[] columns = new CompositeColumnName[fields.length];
for (int ii = 0; ii < fields.length; ii++) {
ColumnField columnField = doType.getColumnField(fields[ii]);
if (columnField == null) {
throw new IllegalArgumentException();
}
if (fields.length > 1) {
// ***** multiple columns aggregation can be done only for non-indexed columns. ******
if (columnField.getIndex() != null || columnField.getType() != ColumnField.ColumnType.Primitive) {
throw DatabaseException.fatals.queryFailed(new Exception("... "));
}
} else if (columnField.getIndex() != null) {
buildRange = true;
}
columns[ii] = new CompositeColumnName(columnField.getName());
}
List<String> idList = new ArrayList<String>();
while (ids.hasNext()) {
idList.clear();
for (int ii = 0; ii < DEFAULT_BATCH_SIZE && ids.hasNext(); ii++) {
idList.add(ids.next().toString());
}
Keyspace ks = getKeyspace(clazz);
aggregateObjectFieldBatch(aggregator, ks, idList, doType, buildRange, columns);
}
}
use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.
the class InternalDbClient method getGeoStrategyOptions.
public Map<String, String> getGeoStrategyOptions() throws ConnectionException {
Keyspace ks = getGeoKeyspace();
KeyspaceDefinition ksDef = ks.describeKeyspace();
return ksDef.getStrategyOptions();
}
Aggregations