Search in sources :

Example 1 with AlternateIdConstraint

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

the class VolumeIngestionUtil method verifyExportGroupExists.

/**
 * Get the export group associated with initiator URIs
 *
 * Note: Once it finds an export group associated with any initiator, it returns that export group. This may not
 * be what the caller wants.
 *
 * @param requestContext current unManagedVolume Ingestion context.
 * @param exportGroupGeneratedName the generated name for the ExportGroup label
 * @param project project
 * @param knownInitiatorUris initiators list
 * @param vArray virtual array
 * @param dbClient dbclient
 * @return export group
 */
public static ExportGroup verifyExportGroupExists(IngestionRequestContext requestContext, String exportGroupGeneratedName, URI project, StringSet knownInitiatorUris, URI vArray, DbClient dbClient) {
    ExportGroup exportGroup = null;
    for (String initiatorIdStr : knownInitiatorUris) {
        AlternateIdConstraint constraint = AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorIdStr);
        URIQueryResultList egUris = new URIQueryResultList();
        dbClient.queryByConstraint(constraint, egUris);
        List<ExportGroup> queryExportGroups = dbClient.queryObject(ExportGroup.class, egUris);
        for (ExportGroup eg : queryExportGroups) {
            if (!eg.getGeneratedName().equals(exportGroupGeneratedName)) {
                continue;
            }
            if (!eg.getProject().getURI().equals(project)) {
                continue;
            }
            if (!eg.getVirtualArray().equals(vArray)) {
                continue;
            }
            if (queryExportGroups.size() > 1) {
                _logger.info("More than one export group contains the initiator(s) requested.  Choosing : " + eg.getId().toString());
            }
            exportGroup = eg;
            break;
        }
    }
    if (exportGroup != null) {
        DataObject alreadyLoadedExportGroup = requestContext.findInUpdatedObjects(exportGroup.getId());
        if (alreadyLoadedExportGroup != null && (alreadyLoadedExportGroup instanceof ExportGroup)) {
            _logger.info("Found an already loaded export group");
            exportGroup = (ExportGroup) alreadyLoadedExportGroup;
        }
    }
    return exportGroup;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) DataObject(com.emc.storageos.db.client.model.DataObject) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 2 with AlternateIdConstraint

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

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

the class DbIndexTest method testAlternativeIdMapIndex.

@Test
public void testAlternativeIdMapIndex() {
    URI id = URIUtil.createId(Network.class);
    String key0 = "abcd1234";
    String key1 = "efgh5678";
    AlternateIdConstraint constraint0 = AlternateIdConstraint.Factory.getEndpointNetworkConstraint(key0);
    AlternateIdConstraint constraint1 = AlternateIdConstraint.Factory.getEndpointNetworkConstraint(key1);
    {
        Network obj = new Network();
        obj.setId(id);
        obj.setEndpointsMap(new StringMap());
        obj.getEndpointsMap().put(key0, "test1");
        _dbClient.createObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, null, 0);
    {
        Network obj = _dbClient.queryObject(Network.class, id);
        obj.getEndpointsMap().put(key1, "test2");
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, id, 1);
    {
        Network obj = _dbClient.queryObject(Network.class, id);
        obj.getEndpointsMap().remove(key0);
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint1, id, 1);
    verifyContain(constraint0, null, 0);
}
Also used : URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) Test(org.junit.Test)

Example 4 with AlternateIdConstraint

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

the class ScaleIOPoolAndStorageSystemMigration method getStoragePoolsForStorageSystem.

/**
 * Query StoragePools associated to the StorageSystem
 *
 * @param storageSystem [in] - StorageSystem object
 * @return List of StoragePools associated with the StorageSystem
 */
private List<StoragePool> getStoragePoolsForStorageSystem(StorageSystem storageSystem) {
    URIQueryResultList storagePoolURIs = new URIQueryResultList();
    AlternateIdConstraint storagePoolByStorageDevice = AlternateIdConstraint.Factory.getConstraint(StoragePool.class, "storageDevice", storageSystem.getId().toString());
    dbClient.queryByConstraint(storagePoolByStorageDevice, storagePoolURIs);
    List<StoragePool> storagePools = new ArrayList<>();
    Iterator<URI> storagePoolIter = storagePoolURIs.iterator();
    while (storagePoolIter.hasNext()) {
        URI storagePoolURI = storagePoolIter.next();
        StoragePool storagePool = dbClient.queryObject(StoragePool.class, storagePoolURI);
        if (storagePool != null && !storagePool.getInactive()) {
            storagePools.add(storagePool);
        }
    }
    return storagePools;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 5 with AlternateIdConstraint

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

Aggregations

AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)17 URI (java.net.URI)11 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)6 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)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 TypeMap (com.emc.storageos.db.client.impl.TypeMap)1 DataObject (com.emc.storageos.db.client.model.DataObject)1