use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class PersistingChangesTest method getIndexRecordCount.
private int getIndexRecordCount(String fieldName) throws ConnectionException {
Keyspace keyspace = ((DbClientTest.DbClientImplUnitTester) dbClient).getLocalContext().getKeyspace();
DataObjectType doType = TypeMap.getDoType(Volume.class);
ColumnField field = doType.getColumnField(fieldName);
ColumnFamilyQuery<String, IndexColumnName> query = keyspace.prepareQuery(field.getIndexCF());
OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().execute();
int count = 0;
for (Row<String, IndexColumnName> row : result.getResult()) {
_log.debug("{}, RowKey={}, Columns Size={}", ++count, row.getKey(), row.getColumns().size());
for (Column<IndexColumnName> column : row.getColumns()) {
_log.debug("\t, Column Name={}, String Value={}.", column.getName(), column.getStringValue());
}
}
return count;
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class RowMutationTest method testTimeUUID.
@Test
public void testTimeUUID() throws Exception {
Volume volume = new Volume();
URI id1 = URIUtil.createId(Volume.class);
URI pool1 = URIUtil.createId(StoragePool.class);
volume.setId(id1);
volume.setLabel("volume1");
volume.setPool(pool1);
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
volume.setAssociatedSourceVolume(URI.create("test"));
volume.setVolumeGroupIds(new StringSet(Sets.newHashSet("v1", "v2")));
getDbClient().updateObject(volume);
DataObjectType doType = TypeMap.getDoType(Volume.class);
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(volume.getId().toString()).execute();
List<Long> columnTimeUUIDStamps = new ArrayList<Long>();
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getTimeUUID() != null) {
columnTimeUUIDStamps.add(TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID()));
}
}
Collections.sort(columnTimeUUIDStamps);
for (int i = 1; i < columnTimeUUIDStamps.size(); i++) {
Assert.assertEquals(1, columnTimeUUIDStamps.get(i) - columnTimeUUIDStamps.get(i - 1));
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class RebuildIndexDuplicatedCFNameMigrationTest method testHandleDataObjectClass.
@Test
public void testHandleDataObjectClass() throws Exception {
DataObjectType doType = TypeMap.getDoType(FileShare.class);
for (int i = 0; i < 5; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
getDbClient().updateObject(testData);
}
// create data object whose index are neede to be rebuild
resetRowMutatorTimeStampOffSet(0);
FileShare[] testDataArray = new FileShare[10];
for (int i = 0; i < 10; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
testDataArray[i] = testData;
getDbClient().updateObject(testData);
}
resetRowMutatorTimeStampOffSet(1);
target = new RebuildIndexDuplicatedCFNameMigration();
target.setDbClient(getDbClient());
target.process();
assertEquals(testDataArray.length, target.getTotalProcessedIndexCount());
for (FileShare testData : testDataArray) {
FileShare targetData = (FileShare) getDbClient().queryObject(testData.getId());
assertEquals(testData.getPath(), targetData.getPath());
assertEquals(testData.getMountPath(), targetData.getMountPath());
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(testData.getId().toString()).execute();
long pathTime = 0;
long mountPathTime = 0;
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getOne().equals("path")) {
pathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
} else if (column.getName().getOne().equals("mountPath")) {
mountPathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
}
}
assertEquals(1, Math.abs(pathTime - mountPathTime));
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DbClientTest method testConfigOverride.
@Test
public void testConfigOverride() {
final int newTtl = 1234;
TypeMap.DataObjectFieldConfiguration doConfig = new TypeMap.DataObjectFieldConfiguration();
doConfig.setDoClass(FileShare.class);
doConfig.setFieldName("status");
doConfig.setTtl(newTtl);
TypeMap.loadDataObjectConfiguration(Arrays.asList(doConfig));
DataObjectType fsType = TypeMap.getDoType(FileShare.class);
Assert.assertEquals(fsType.getColumnField("status").getTtl().intValue(), newTtl);
TypeMap.TimeSeriesConfiguration tsConfig = new TypeMap.TimeSeriesConfiguration();
tsConfig.setTsClass(EventTimeSeries.class);
tsConfig.setTtl(newTtl);
TypeMap.loadTimeSeriesConfiguration(Arrays.asList(tsConfig));
TimeSeriesType tsType = TypeMap.getTimeSeriesType(EventTimeSeries.class);
Assert.assertEquals(tsType.getTtl().intValue(), newTtl);
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DataObjectScanner method addToTypeMap.
private void addToTypeMap(Class clazz, Map<String, ColumnFamily> useCfMap) {
DependencyInterceptor dependencyInterceptor = new DependencyInterceptor(this.modelClasses);
Map<String, List<String>> indexCfTypeMap = new HashMap<String, List<String>>();
DataObjectType doType = TypeMap.getDoType(clazz);
useCfMap.put(doType.getCF().getName(), doType.getCF());
boolean include = (clazz.getAnnotation(ExcludeFromGarbageCollection.class) == null);
Iterator<ColumnField> it = doType.getColumnFields().iterator();
while (it.hasNext()) {
ColumnField field = it.next();
if (field.getIndex() == null) {
continue;
}
useCfMap.put(field.getIndexCF().getName(), field.getIndexCF());
// for dependency processing
if (field.getIndexRefType() != null) {
_log.info(" index: " + field.getIndex().getClass().getSimpleName() + " class: " + clazz.getSimpleName() + " field: " + field.getName() + " indexCF: " + field.getIndexCF().getName() + " reference: " + field.getIndexRefType());
if (isDuplicateIndexCf(field, indexCfTypeMap)) {
_log.error("Class: {} has muliple indexed columns of the same type configured to use the same index column family: {}", clazz.getName(), field.getIndexCF().getName());
throw new IllegalStateException("Class: " + clazz.getName() + " has muliple indexed columns of the same type configured to use the same index column family: " + field.getIndexCF().getName());
}
// check first before adding the dependency
if (!isDependencyValidated(field.getIndexRefType(), clazz)) {
_log.error("Class: {} is a global object but it has illegal reference to a non-global dependency: {}", clazz.getName(), field.getIndexRefType());
throw new IllegalStateException("Class: " + clazz.getName() + " is a global object but it has illegal reference to a non-global dependency: " + field.getIndexRefType());
}
if (dependencyInterceptor.isConcretModelClass(field.getIndexRefType())) {
_dependencyTracker.addDependency(field.getIndexRefType(), clazz, field);
} else {
_log.info("reference type is abstract class, need special process");
dependencyInterceptor.handleDependency(_dependencyTracker, clazz, field);
}
}
}
if (include) {
_dependencyTracker.includeClass(clazz);
} else {
_dependencyTracker.excludeClass(clazz);
}
}
Aggregations