Search in sources :

Example 1 with AlternateIdConstraintImpl

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

Example 2 with AlternateIdConstraintImpl

use of com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl 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 3 with AlternateIdConstraintImpl

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

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

the class DbIndexTest method verifyAltIdDbIndex.

private void verifyAltIdDbIndex(DataObject obj, ColumnField field, Object val, boolean indexByKey, DbClient client) {
    switch(field.getType()) {
        case Primitive:
            {
                AlternateIdConstraint constraint = new AlternateIdConstraintImpl(field, (String) val);
                verifyContain(constraint, obj.getId(), -1, client);
            }
            break;
        case TrackingMap:
            for (Map.Entry entry : ((AbstractChangeTrackingMap<?>) val).entrySet()) {
                Object altId = indexByKey ? entry.getKey() : entry.getValue();
                AlternateIdConstraint constraint = new AlternateIdConstraintImpl(field, (String) altId);
                verifyContain(constraint, obj.getId(), -1, client);
            }
            break;
        case TrackingSet:
            for (String key : (AbstractChangeTrackingSet<String>) val) {
                AlternateIdConstraint constraint = new AlternateIdConstraintImpl(field, key);
                verifyContain(constraint, obj.getId(), -1, client);
            }
            break;
        case Id:
        case NamedURI:
        case NestedObject:
        case TrackingSetMap:
        default:
            throw new IllegalArgumentException(String.format("Field type %s is not supported by AltIdDbIndex", field.getType().toString()));
    }
}
Also used : AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) TypeMap(com.emc.storageos.db.client.impl.TypeMap) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 5 with AlternateIdConstraintImpl

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

the class DbDowntimeTracker 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) 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)

Aggregations

AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)7 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)7 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)5 URI (java.net.URI)5 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 ArrayList (java.util.ArrayList)2 DbClient (com.emc.storageos.db.client.DbClient)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)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 TypeMap (com.emc.storageos.db.client.impl.TypeMap)1 JsonObject (com.google.gson.JsonObject)1 Map (java.util.Map)1 Test (org.junit.Test)1