Search in sources :

Example 1 with DataObjectType

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

use of com.emc.storageos.db.client.impl.DataObjectType 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;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) ArrayList(java.util.ArrayList) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Keyspace(com.netflix.astyanax.Keyspace) Row(com.netflix.astyanax.model.Row) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Rows(com.netflix.astyanax.model.Rows)

Example 3 with DataObjectType

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

the class DbClientTest method checkAggregatedQuery.

private void checkAggregatedQuery(Iterator<AggregationQueryResultList.AggregatedEntry> it, Class<? extends DataObject> clazz, String field, Map<URI, ? extends DataObject> validatedObj) {
    int count = 0;
    while (it.hasNext()) {
        AggregationQueryResultList.AggregatedEntry entry = it.next();
        _logger.info("         " + entry.getId() + ";  capacity = " + entry.getValue().toString());
        DataObject obj = validatedObj.get(entry.getId());
        DataObjectType doType = TypeMap.getDoType(clazz);
        Object value = ColumnField.getFieldValue(doType.getColumnField(field), obj);
        Assert.assertEquals(value, entry.getValue());
        count++;
    }
    Assert.assertEquals(count, validatedObj.size());
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) DataObject(com.emc.storageos.db.client.model.DataObject) 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)

Example 4 with DataObjectType

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

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

the class DbIndexTest method testInactive.

@Test
public void testInactive() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    // We're going to need synchronize between threads calling into DbClient
    this._dbClient.threadStepLock = new ThreadLocal<DbClientTest.StepLock>();
    URI vol1Uri = URIUtil.createId(Volume.class);
    URI varr1Uri = URIUtil.createId(VirtualArray.class);
    IndexTestData[] tests = new IndexTestData[] { new IndexTestData("Test inactive with other index", Volume.class, // Initial state
    new Object[] { "personality=", "abc" }, new Object[][] { new Object[] { "inactive=", true }, new Object[] { "personality=", "ghi" } }, new IndexVerifier() {

        @Override
        public void verify(Class<? extends DataObject> clazz, URI id, DbClient client) {
            Volume vol = (Volume) client.queryObject(clazz, id);
            String per = vol.getPersonality();
            DataObjectType doType = TypeMap.getDoType(clazz);
            AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField("personality"), per);
            URIQueryResultList list = new URIQueryResultList();
            client.queryByConstraint(constraint, list);
            for (URI elem : list) {
                assertTrue("The index of .personality should be removed", !elem.equals(id));
            }
        }
    }) };
    for (int i = 0; i < tests.length; i++) {
        testRaceCondition(tests[i]);
    }
}
Also used : AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Test(org.junit.Test)

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