use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class FieldValueTimeUUIDPair method handleDataObjectClass.
public void handleDataObjectClass(Class<? extends DataObject> clazz) throws Exception {
log.info("proccess model class {}", clazz);
InternalDbClient dbClient = (InternalDbClient) getDbClient();
DataObjectType doType = TypeMap.getDoType(clazz);
Keyspace keyspace = dbClient.getLocalContext().getKeyspace();
ColumnFamilyQuery<String, CompositeColumnName> query = keyspace.prepareQuery(doType.getCF());
OperationResult<Rows<String, CompositeColumnName>> result = query.getAllRows().setRowLimit(100).execute();
int totalCount = 0;
List<Row<String, CompositeColumnName>> rows = new ArrayList<Row<String, CompositeColumnName>>();
for (Row<String, CompositeColumnName> objRow : result.getResult()) {
boolean inactiveObject = false;
totalCount++;
for (Column<CompositeColumnName> column : objRow.getColumns()) {
if (DataObject.INACTIVE_FIELD_NAME.equals(column.getName().getOne()) && column.getBooleanValue()) {
inactiveObject = true;
break;
}
}
if (inactiveObject) {
continue;
}
rows.add(objRow);
if (rows.size() > REBUILD_INDEX_BATCH_SIZE) {
try {
executor.submit(new RebuildIndexTask(doType, rows, keyspace));
rows = new ArrayList<Row<String, CompositeColumnName>>();
} catch (Exception e) {
log.warn("Failed to submit rebuild index task, this may be caused by thread pool is full, try in next round", e);
}
}
}
executor.submit(new RebuildIndexTask(doType, rows, keyspace));
log.info("Total data object count is {} for model {}", totalCount, clazz.getName());
return;
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method setupTest.
@Before
public void setupTest() {
volumeCF = new ColumnFamily<String, CompositeColumnName>("Volume", StringSerializer.get(), CompositeColumnNameSerializer.get());
indexCF = new ColumnFamily<String, IndexColumnName>("LabelPrefixIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
noExistCF = new ColumnFamily<String, CompositeColumnName>("no_exits_CF", StringSerializer.get(), CompositeColumnNameSerializer.get());
rowMutator = new RowMutator(((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace(), false);
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method insertRecordAndIndexColumnWithError.
@Test
public void insertRecordAndIndexColumnWithError() throws ConnectionException {
String rowKey = URIUtil.createId(Volume.class).toString();
String volumeLabel = "volume label";
// insert data object
ColumnListMutation<CompositeColumnName> columnList = rowMutator.getRecordColumnList(volumeCF, rowKey);
columnList.putColumn(new CompositeColumnName("allocatedCapacity"), 20);
columnList.putColumn(new CompositeColumnName("label"), volumeLabel);
// insert related index
rowMutator.getIndexColumnList(indexCF, "vo").putColumn(new IndexColumnName("Volume", volumeLabel, volumeLabel, rowKey, rowMutator.getTimeUUID()), "");
// insert error column
ColumnListMutation<CompositeColumnName> no_columnList = rowMutator.getRecordColumnList(noExistCF, rowKey);
no_columnList.putColumn(new CompositeColumnName("test"), 20);
try {
rowMutator.execute();
Assert.fail();
} catch (Exception e) {
// expected exception
}
// no volume should be created
Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
Assert.assertNull(volume);
// no index should be created
CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", "vo", volumeLabel, volumeLabel, rowKey);
CqlStatementResult result = statement.withCql(cql).execute().getResult();
Rows<String, IndexColumnName> rows = result.getRows(indexCF);
Assert.assertEquals(rows.size(), 0);
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testCheckIndexingCF_SkipRecordWithNoInactiveColumn.
@Test
public void testCheckIndexingCF_SkipRecordWithNoInactiveColumn() throws Exception {
ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("path1");
testData.setMountPath("mountPath1");
getDbClient().createObject(testData);
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
keyspace.prepareQuery(cf).withCql(String.format("delete from \"FileShare\" where key='%s' and column1='inactive'", testData.getId().toString())).execute();
CheckResult checkResult = new CheckResult();
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(0, checkResult.getTotal());
testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("path1");
testData.setMountPath("mountPath1");
getDbClient().createObject(testData);
testData = (FileShare) getDbClient().queryObject(testData.getId());
testData.setInactive(true);
getDbClient().updateObject(testData);
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(0, checkResult.getTotal());
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testTimeSeriesAlternateId.
@Test
public void testTimeSeriesAlternateId() throws Exception {
DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
Order order = new Order();
order.setId(URIUtil.createId(Order.class));
order.setLabel("order2");
order.setTenant("tenant");
order.setIndexed(true);
getDbClient().createObject(order);
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
ColumnFamily<String, TimeSeriesIndexColumnName> indexCF = new ColumnFamily<String, TimeSeriesIndexColumnName>("AllOrdersByTimeStamp", StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
IndexAndCf indexAndCf = new IndexAndCf(TimeSeriesDbIndex.class, indexCF, keyspace);
CheckResult checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(0, checkResult.getTotal());
keyspace.prepareQuery(cf).withCql(String.format("delete from \"Order\" where key='%s'", order.getId())).execute();
checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(1, checkResult.getTotal());
keyspace.prepareQuery(indexCF).withCql(mockHelper.getCleanIndexCQL()).execute();
checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(0, checkResult.getTotal());
}
Aggregations