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;
}
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]);
}
}
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);
}
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;
}
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();
}
Aggregations