Search in sources :

Example 16 with DataObjectType

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;
}
Also used : IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) Keyspace(com.netflix.astyanax.Keyspace) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) com.emc.storageos.db.client.constraint(com.emc.storageos.db.client.constraint) DbClientTest(com.emc.storageos.db.server.DbClientTest) Rows(com.netflix.astyanax.model.Rows)

Example 17 with DataObjectType

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));
    }
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) ArrayList(java.util.ArrayList) URI(java.net.URI) Volume(com.emc.storageos.db.client.model.Volume) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) StringSet(com.emc.storageos.db.client.model.StringSet) ColumnList(com.netflix.astyanax.model.ColumnList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Test(org.junit.Test)

Example 18 with DataObjectType

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));
    }
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) ColumnList(com.netflix.astyanax.model.ColumnList) RebuildIndexDuplicatedCFNameMigration(com.emc.storageos.db.client.upgrade.callbacks.RebuildIndexDuplicatedCFNameMigration) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) FileShare(com.emc.storageos.db.client.model.FileShare) Test(org.junit.Test)

Example 19 with DataObjectType

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);
}
Also used : TimeSeriesType(com.emc.storageos.db.client.impl.TimeSeriesType) TypeMap(com.emc.storageos.db.client.impl.TypeMap) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Test(org.junit.Test)

Example 20 with DataObjectType

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);
    }
}
Also used : HashMap(java.util.HashMap) ColumnField(com.emc.storageos.db.client.impl.ColumnField) ArrayList(java.util.ArrayList) List(java.util.List) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Aggregations

DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)28 ColumnField (com.emc.storageos.db.client.impl.ColumnField)10 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)8 URI (java.net.URI)8 ArrayList (java.util.ArrayList)7 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)5 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)4 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)4 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 Test (org.junit.Test)4 Constraint (com.emc.storageos.db.client.constraint.Constraint)3 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)3 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)3 Rows (com.netflix.astyanax.model.Rows)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2