Search in sources :

Example 1 with ColumnField

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

the class AggregationIndexTimeUUIDMigration method removeTimeUUIDIndexedFields.

private void removeTimeUUIDIndexedFields(Class<? extends DataObject> clazz) throws Exception {
    DataObjectType doType = TypeMap.getDoType(clazz);
    Collection<ColumnField> fields = doType.getColumnFields();
    Map<String, ColumnField> uuidFields = new HashMap<>();
    for (ColumnField field : fields) {
        DbIndex index = field.getIndex();
        if (index != null && index instanceof AggregateDbIndex) {
            uuidFields.put(field.getName(), field);
        }
    }
    // true: ignore exception while accessing db
    getInternalDbClient().resetFields(clazz, uuidFields, true);
}
Also used : HashMap(java.util.HashMap) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) AggregateDbIndex(com.emc.storageos.db.client.impl.AggregateDbIndex) DbIndex(com.emc.storageos.db.client.impl.DbIndex) AggregateDbIndex(com.emc.storageos.db.client.impl.AggregateDbIndex)

Example 2 with ColumnField

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

the class DbIndexTest method isEqual.

public static boolean isEqual(DataObject obj, Object[] ops) {
    DataObject shouldBe = createInitial(obj.getClass(), obj.getId(), ops);
    // Get DataObjectType
    DataObjectType doType = TypeMap.getDoType(obj.getClass());
    for (ColumnField field : doType.getColumnFields()) {
        if (!shouldBe.isChanged(field.getName())) {
            continue;
        }
        Method readMethod = field.getPropertyDescriptor().getReadMethod();
        try {
            Object shouldBeVal = readMethod.invoke(shouldBe);
            Object realVal = readMethod.invoke(obj);
            if (!equalsObject(realVal, shouldBeVal)) {
                return false;
            }
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
Also used : ColumnField(com.emc.storageos.db.client.impl.ColumnField) JsonObject(com.google.gson.JsonObject) Method(java.lang.reflect.Method) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ColumnField

use of com.emc.storageos.db.client.impl.ColumnField 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 4 with ColumnField

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

the class StaleRelationURICleanupMigration method doRelationURICleanup.

protected boolean doRelationURICleanup(DataObjectType doType, DataObject dataObject, String relationField) {
    boolean isChanged = false;
    try {
        ColumnField columnField = doType.getColumnField(relationField);
        Object fieldValue = columnField.getFieldValue(columnField, dataObject);
        List<String> relationURIList = getURIListFromDataObject(fieldValue);
        List<String> validRelationURIList = queryValidRelationURIList((DbClientImpl) getDbClient(), relationField, relationURIList);
        // get invalid URI list
        List<String> invalidURIs = ListUtils.subtract(relationURIList, validRelationURIList);
        if (!invalidURIs.isEmpty()) {
            totalStaleURICount += invalidURIs.size();
            log.info("Stale/invalid URI found for class: {}, key: {}, field: {}", doType.getDataObjectClass().getSimpleName(), dataObject.getId(), relationField);
            log.info(StringUtils.join(invalidURIs, ","));
            isChanged = true;
            saveNewURIListToObject(dataObject, columnField, fieldValue, invalidURIs);
        }
    } catch (Exception e) {
        log.error("Failed to run migration handler for class{}, {}", doType.getDataObjectClass().getSimpleName(), relationField, e);
    }
    return isChanged;
}
Also used : ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObject(com.emc.storageos.db.client.model.DataObject) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ColumnField

use of com.emc.storageos.db.client.impl.ColumnField 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)

Aggregations

ColumnField (com.emc.storageos.db.client.impl.ColumnField)13 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 ArrayList (java.util.ArrayList)3 DbIndex (com.emc.storageos.db.client.impl.DbIndex)2 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)2 DataObject (com.emc.storageos.db.client.model.DataObject)2 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)2 JsonObject (com.google.gson.JsonObject)2 Rows (com.netflix.astyanax.model.Rows)2 HashMap (java.util.HashMap)2 com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ContainmentConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl)1