Search in sources :

Example 11 with DataObjectType

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

the class DbCli method printFieldsByCf.

/**
 * Print the fields' info of column family.
 *
 * @Param cfName
 */
public void printFieldsByCf(String cfName) {
    // fill in type from cfName
    final Class clazz = getClassFromCFName(cfName);
    if (clazz == null) {
        return;
    }
    if (DataObject.class.isAssignableFrom(clazz)) {
        DataObjectType doType = TypeMap.getDoType(clazz);
        System.out.println(String.format("Column Family: %s", doType.getCF().getName()));
        Collection<ColumnField> cfs = doType.getColumnFields();
        Iterator it = cfs.iterator();
        while (it.hasNext()) {
            ColumnField field = (ColumnField) it.next();
            System.out.println(String.format("\tfield=%-30s\ttype=%s", field.getName(), field.getPropertyDescriptor().getPropertyType().toString().substring(6)));
        }
    }
}
Also used : ColumnField(com.emc.storageos.db.client.impl.ColumnField) Iterator(java.util.Iterator) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Example 12 with DataObjectType

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

the class DBClient method checkDB.

/**
 * This db consistency check is for a specific CF,
 * It could also detect the 2 paths same as {@link DBClient#checkDB()}
 *
 * @param cfName
 */
public void checkDB(String cfName) {
    final Class clazz = getClassFromCFName(cfName);
    if (clazz == null) {
        return;
    }
    DataObjectType dataCf = TypeMap.getDoType(clazz);
    DbConsistencyCheckerHelper helper = new DbConsistencyCheckerHelper(_dbClient);
    int corruptedCount = 0;
    try {
        logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_ID_START);
        int illegalCount = helper.checkDataObject(dataCf, true);
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_ID_END_SPECIFIED, dataCf.getCF().getName(), illegalCount));
        corruptedCount += illegalCount;
        logMsg(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_START);
        CheckResult checkResult = new CheckResult();
        helper.checkCFIndices(dataCf, true, checkResult);
        logMsg(checkResult.toString());
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_OBJECT_INDICES_END_SPECIFIED, dataCf.getCF().getName(), checkResult.getTotal()));
        corruptedCount += checkResult.getTotal();
        logMsg(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_START);
        Collection<DbConsistencyCheckerHelper.IndexAndCf> idxCfs = helper.getIndicesOfCF(dataCf).values();
        checkResult = new CheckResult();
        for (DbConsistencyCheckerHelper.IndexAndCf indexAndCf : idxCfs) {
            helper.checkIndexingCF(indexAndCf, true, checkResult);
        }
        logMsg(checkResult.toString());
        logMsg(String.format(DbConsistencyCheckerHelper.MSG_INDEX_OBJECTS_END_SPECIFIED, idxCfs.size(), dataCf.getCF().getName(), checkResult.getTotal()));
        corruptedCount += checkResult.getTotal();
        String msg = generateSummaryForDBChecker(corruptedCount != 0);
        System.out.println(msg);
        log.info(msg);
    } catch (ConnectionException e) {
        log.error("Database connection exception happens, fail to connect: ", e);
        System.err.println("The checker has been stopped by database connection exception. " + "Please see the log for more information.");
    } finally {
        DbCheckerFileWriter.close();
    }
}
Also used : CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 13 with DataObjectType

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

the class MailHandler method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    this.dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = new ArrayList<>();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    if (userPrefsIds.isEmpty()) {
        return null;
    }
    final List<UserPreferences> userPrefs = new ArrayList<>();
    Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    }
    if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) ArrayList(java.util.ArrayList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 14 with DataObjectType

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

the class SchedulerConfig method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    this.dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = new ArrayList<>();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    if (userPrefsIds.isEmpty()) {
        return null;
    }
    final List<UserPreferences> userPrefs = new ArrayList<>();
    Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    }
    if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) ArrayList(java.util.ArrayList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 15 with DataObjectType

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

the class PersistingChangesTest method testCleanupSoftReference.

@Test
public void testCleanupSoftReference() throws ConnectionException {
    Volume volume = new Volume();
    URI id = URIUtil.createId(Volume.class);
    URI pool = URIUtil.createId(StoragePool.class);
    volume.setId(id);
    volume.setLabel("origin");
    volume.setPool(pool);
    volume.setNativeGuid("native_guid");
    volume.setNativeId("native_id");
    volume.setCompositionType("compositionType");
    volume.setInactive(false);
    volume.setAllocatedCapacity(1000L);
    volume.setProvisionedCapacity(2000L);
    dbClient.updateObject(volume);
    // Search the label index directly
    String labelFieldName = "label";
    int labelCount = getIndexRecordCount(labelFieldName);
    // By default, label index contains one record for VirtualDataCenter
    Assert.assertEquals(2, labelCount);
    List<URI> volumes = dbClient.queryByType(Volume.class, true);
    int size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
        Assert.assertEquals("origin", entry.getLabel());
    }
    Assert.assertEquals(1, size);
    _log.info("\nStart to update with new label");
    // Mock warning when listToCleanRef is null in indexCleaner
    this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester() {

        @Override
        public synchronized void start() {
            super.start();
            _indexCleaner = new IndexCleaner() {

                @Override
                public void cleanIndex(RowMutator mutator, DataObjectType doType, SoftReference<IndexCleanupList> listToCleanRef) {
                    listToCleanRef.clear();
                    super.cleanIndex(mutator, doType, listToCleanRef);
                }
            };
        }
    });
    volume = dbClient.queryObject(Volume.class, id);
    volume.setLabel("new");
    dbClient.updateObject(volume);
    // Search the label index directly
    labelCount = getIndexRecordCount(labelFieldName);
    // We mocked indexCleaner, so that old label index couldn't be removed, still in DB
    Assert.assertEquals(3, labelCount);
    volumes = dbClient.queryByType(Volume.class, true);
    size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
        Assert.assertEquals("new", entry.getLabel());
    }
    Assert.assertEquals(1, size);
    // Remove the object
    _log.info("\nStart to remove volume");
    this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester());
    volume = dbClient.queryObject(Volume.class, id);
    dbClient.removeObject(volume);
    // Search the label index directly
    labelCount = getIndexRecordCount(labelFieldName);
    // All the label index related to volume should be removed.
    Assert.assertEquals(1, labelCount);
    volumes = dbClient.queryByType(Volume.class, true);
    size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
    }
    Assert.assertEquals(0, size);
}
Also used : IndexCleanupList(com.emc.storageos.db.client.impl.IndexCleanupList) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) IndexCleaner(com.emc.storageos.db.client.impl.IndexCleaner) URI(java.net.URI) RowMutator(com.emc.storageos.db.client.impl.RowMutator) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) com.emc.storageos.db.client.constraint(com.emc.storageos.db.client.constraint) Test(org.junit.Test) DbClientTest(com.emc.storageos.db.server.DbClientTest)

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