Search in sources :

Example 6 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class DbIndexTest method verify.

@Override
public void verify(Class<? extends DataObject> clazz, URI id, DbClient client) {
    // Get meta data about the object, field and index we're going to test
    DataObjectType doType = TypeMap.getDoType(clazz);
    ColumnField field = doType.getColumnField(fieldName);
    if (field == null) {
        throw new NullPointerException(String.format("Cannot find field %s from class %s", fieldName, clazz.getSimpleName()));
    }
    DbIndex index = field.getIndex();
    // Load object first
    DataObject obj = (DataObject) client.queryObject(clazz, id);
    // Get current value of indexed field
    Object val = null;
    try {
        val = field.getPropertyDescriptor().getReadMethod().invoke(obj);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Cannot get field value");
    }
    boolean indexByKey = field.getPropertyDescriptor().getReadMethod().getAnnotation(IndexByKey.class) != null;
    // See which type the index is, and call corresponding verification functions
    if (index instanceof AltIdDbIndex) {
        verifyAltIdDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof RelationDbIndex) {
        verifyRelationDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof NamedRelationDbIndex) {
        verifyNamedRelationDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof PrefixDbIndex) {
        verifyPrefixDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof DecommissionedDbIndex) {
        verifyDecommissionedDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof PermissionsDbIndex) {
        verifyPermissionsDbIndex(obj, field, val, indexByKey, client);
    } else if (index instanceof ScopedLabelDbIndex) {
        verifyScopedLabelDbIndex(obj, field, val, indexByKey, client);
    } else {
        System.out.printf("Unsupported index type %s%n", index.getClass().getSimpleName());
    }
}
Also used : AltIdDbIndex(com.emc.storageos.db.client.impl.AltIdDbIndex) PrefixDbIndex(com.emc.storageos.db.client.impl.PrefixDbIndex) DecommissionedDbIndex(com.emc.storageos.db.client.impl.DecommissionedDbIndex) ColumnField(com.emc.storageos.db.client.impl.ColumnField) ScopedLabelDbIndex(com.emc.storageos.db.client.impl.ScopedLabelDbIndex) NamedRelationDbIndex(com.emc.storageos.db.client.impl.NamedRelationDbIndex) AltIdDbIndex(com.emc.storageos.db.client.impl.AltIdDbIndex) RelationDbIndex(com.emc.storageos.db.client.impl.RelationDbIndex) PrefixDbIndex(com.emc.storageos.db.client.impl.PrefixDbIndex) DbIndex(com.emc.storageos.db.client.impl.DbIndex) DecommissionedDbIndex(com.emc.storageos.db.client.impl.DecommissionedDbIndex) PermissionsDbIndex(com.emc.storageos.db.client.impl.PermissionsDbIndex) InvocationTargetException(java.lang.reflect.InvocationTargetException) ScopedLabelDbIndex(com.emc.storageos.db.client.impl.ScopedLabelDbIndex) JsonObject(com.google.gson.JsonObject) PermissionsDbIndex(com.emc.storageos.db.client.impl.PermissionsDbIndex) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedRelationDbIndex(com.emc.storageos.db.client.impl.NamedRelationDbIndex) NamedRelationDbIndex(com.emc.storageos.db.client.impl.NamedRelationDbIndex) RelationDbIndex(com.emc.storageos.db.client.impl.RelationDbIndex)

Example 7 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class StaleIndexCleanerMigration method getAllIndexCFs.

private Map<String, IndexAndCf> getAllIndexCFs() {
    Map<String, IndexAndCf> allIdxCfs = new TreeMap<>();
    for (DataObjectType objType : TypeMap.getAllDoTypes()) {
        if (KeyspaceUtil.isLocal(objType.getDataObjectClass())) {
            Map<String, IndexAndCf> idxCfs = checkHelper.getIndicesOfCF(objType);
            allIdxCfs.putAll(idxCfs);
        }
    }
    return allIdxCfs;
}
Also used : IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) TreeMap(java.util.TreeMap) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Example 8 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class StaleRelationURICleanupMigration method process.

@Override
public void process() throws MigrationCallbackException {
    initRelationFields();
    DbClientImpl dbClient = (DbClientImpl) getDbClient();
    for (Entry<Class<? extends DataObject>, List<String>> entry : relationFields.entrySet()) {
        DataObjectType doType = TypeMap.getDoType(entry.getKey());
        // for each class, query out all objects iteratively
        List<URI> uriList = dbClient.queryByType(entry.getKey(), true);
        Iterator<DataObject> resultIterator = (Iterator<DataObject>) dbClient.queryIterativeObjects(entry.getKey(), uriList, true);
        while (resultIterator.hasNext()) {
            DataObject dataObject = resultIterator.next();
            boolean isChanged = false;
            for (String relationField : entry.getValue()) {
                isChanged |= doRelationURICleanup(doType, dataObject, relationField);
            }
            if (isChanged) {
                totalModifiedObject++;
                dbClient.updateObject(dataObject);
            }
        }
    }
    log.info("Totally found {} stale/invalid URI keys", totalStaleURICount);
    log.info("Totally {} data objects have been modifed to remove stale/invalid URI", totalModifiedObject);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ColumnList(com.netflix.astyanax.model.ColumnList) List(java.util.List) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) URI(java.net.URI)

Example 9 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class UserToOrdersMigration method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Adding new index records for class: {} field: {} annotation: {} name={}", new Object[] { Order.class, Order.SUBMITTED_BY_USER_ID, ClassNameTimeSeries.class.getName(), name });
    DataObjectType doType = TypeMap.getDoType(Order.class);
    ColumnField field = doType.getColumnField(Order.SUBMITTED_BY_USER_ID);
    newIndexCF = field.getIndexCF();
    ColumnFamily<String, IndexColumnName> userToOrders = new ColumnFamily<>(SOURCE_INDEX_CF_NAME, StringSerializer.get(), IndexColumnNameSerializer.get());
    DbClientImpl client = (DbClientImpl) dbClient;
    ks = client.getKeyspace(Order.class);
    MutationBatch mutationBatch = ks.prepareMutationBatch();
    long m = 0;
    try {
        OperationResult<Rows<String, IndexColumnName>> result = ks.prepareQuery(userToOrders).getAllRows().setRowLimit(1000).withColumnRange(new RangeBuilder().setLimit(0).build()).execute();
        ColumnList<IndexColumnName> cols;
        for (Row<String, IndexColumnName> row : result.getResult()) {
            RowQuery<String, IndexColumnName> rowQuery = ks.prepareQuery(userToOrders).getKey(row.getKey()).autoPaginate(true).withColumnRange(new RangeBuilder().setLimit(5).build());
            while (!(cols = rowQuery.execute().getResult()).isEmpty()) {
                m++;
                for (Column<IndexColumnName> col : cols) {
                    String indexKey = row.getKey();
                    String orderId = col.getName().getTwo();
                    ClassNameTimeSeriesIndexColumnName newCol = new ClassNameTimeSeriesIndexColumnName(col.getName().getOne(), orderId, col.getName().getTimeUUID());
                    mutationBatch.withRow(newIndexCF, indexKey).putEmptyColumn(newCol, null);
                    if (m % 10000 == 0) {
                        mutationBatch.execute();
                    }
                }
            }
        }
        mutationBatch.execute();
    } catch (Exception e) {
        log.error("Migration to {} failed e=", newIndexCF.getName(), e);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ColumnField(com.emc.storageos.db.client.impl.ColumnField) RangeBuilder(com.netflix.astyanax.util.RangeBuilder) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) MutationBatch(com.netflix.astyanax.MutationBatch) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Rows(com.netflix.astyanax.model.Rows)

Example 10 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class DataObjectUtils method getPropertyValue.

/**
 * This function returns the property value for an object of {@link DataObject} subtype.
 *
 * @param clzz the object class that should be a subtype of {@link DataObject}
 * @param dataObject the instance of clzz
 * @param property the string name of the property
 * @return the value of the property
 */
public static <T extends DataObject> Object getPropertyValue(Class<T> clzz, DataObject dataObject, String property) {
    try {
        DataObjectType doType = TypeMap.getDoType(clzz);
        ColumnField field = doType.getColumnField(property);
        return field.getPropertyDescriptor().getReadMethod().invoke(dataObject);
    } catch (Exception ex) {
        throw DatabaseException.fatals.failedToReadPropertyValue(clzz, property, ex);
    }
}
Also used : ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

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