use of com.emc.storageos.db.client.constraint.AlternateIdConstraint 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();
}
use of com.emc.storageos.db.client.constraint.AlternateIdConstraint in project coprhd-controller by CoprHD.
the class VPlexDeviceController method deleteMigrationSources.
/**
* This step is executed after a virtual volume is successfully migrated to
* delete the old source volumes. We create a sub workflow to perform this
* task. We do this in a sub workflow because we don't want any of the steps
* required to delete the sources to initiate rollback in the main workflow
* if it fails.
*
* We also update the class of service, if required, for the virtual
* volume when the migration is the result of a CoS change. When this
* step is executed we know that the migrations have been committed and
* the new CoS now applies to the virtual volume.
*
* @param vplexURI
* The URI of the VPlex storage system.
* @param virtualVolumeURI
* The URI of the virtual volume.
* @param newVpoolURI
* The CoS to be assigned to the virtual volume
* upon successful commit of the migration or null when not
* specified.
* @param newVarrayURI
* The varray to be assigned to the virtual volume
* upon successful commit of the migration or null when not
* specified.
* @param migrationSources
* The migration sources to delete.
* @param stepId
* The workflow step id.
* @throws WorkflowException
*/
public void deleteMigrationSources(URI vplexURI, URI virtualVolumeURI, URI newVpoolURI, URI newVarrayURI, List<URI> migrationSources, String stepId) throws WorkflowException {
try {
WorkflowStepCompleter.stepExecuting(stepId);
// First update the virtual volume CoS, if necessary.
Volume volume = _dbClient.queryObject(Volume.class, virtualVolumeURI);
// or create a new exportGroup
if (newVarrayURI != null && volume.isVolumeExported(_dbClient)) {
URIQueryResultList exportGroupURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getBlockObjectExportGroupConstraint(virtualVolumeURI), exportGroupURIs);
Iterator<URI> iterator = exportGroupURIs.iterator();
while (iterator.hasNext()) {
URI egUri = iterator.next();
ExportGroup eg = _dbClient.queryObject(ExportGroup.class, egUri);
if (eg != null) {
StringMap volumesMap = eg.getVolumes();
String lun = volumesMap.get(virtualVolumeURI.toString());
if (lun == null || lun.isEmpty()) {
lun = ExportGroup.LUN_UNASSIGNED_DECIMAL_STR;
}
List<URI> initiators = StringSetUtil.stringSetToUriList(eg.getInitiators());
ExportGroup newEg = null;
if (initiators != null && !initiators.isEmpty()) {
URI initiatorUri = initiators.get(0);
AlternateIdConstraint constraint = AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorUri.toString());
URIQueryResultList egUris = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, egUris);
Iterator<URI> egIt = egUris.iterator();
while (egIt.hasNext()) {
ExportGroup theEg = _dbClient.queryObject(ExportGroup.class, egIt.next());
if (theEg.getVirtualArray().equals(newVarrayURI)) {
List<URI> theEgInits = StringSetUtil.stringSetToUriList(theEg.getInitiators());
if (theEgInits.containsAll(initiators) && theEgInits.size() == initiators.size()) {
_log.info(String.format("Found existing exportGroup %s", theEg.getId().toString()));
newEg = theEg;
break;
}
}
}
}
if (newEg != null) {
// add the volume to the export group
newEg.addVolume(virtualVolumeURI, Integer.valueOf(lun));
_dbClient.updateObject(newEg);
} else {
// create a new export group
_log.info("Creating new ExportGroup");
createExportGroup(eg, volume, Integer.valueOf(lun));
}
eg.removeVolume(virtualVolumeURI);
_dbClient.updateObject(eg);
}
}
}
if (!migrationSources.isEmpty()) {
final String workflowKey = "deleteOriginalSources";
if (!WorkflowService.getInstance().hasWorkflowBeenCreated(stepId, workflowKey)) {
// Now create and execute the sub workflow to delete the
// migration source volumes if we have any. If the volume
// migrated was ingested VPLEX volume we will not have
// the sources.
String subTaskId = stepId;
Workflow subWorkflow = _workflowService.getNewWorkflow(this, DELETE_MIGRATION_SOURCES_WF_NAME, true, subTaskId);
WorkflowTaskCompleter completer = new WorkflowTaskCompleter(subWorkflow.getWorkflowURI(), subTaskId);
// Creates steps to remove the migration source volumes from all
// export groups containing them and delete them.
boolean unexportStepsAdded = vplexAddUnexportVolumeWfSteps(subWorkflow, null, migrationSources, null);
// Only need to wait for unexport if there was a step for it added
// to the workflow.
String waitFor = null;
if (unexportStepsAdded) {
waitFor = UNEXPORT_STEP;
// If the migration sources are unexported, Add a step to
// forget these backend volumes.
addStepToForgetVolumes(subWorkflow, vplexURI, migrationSources, waitFor);
}
// Add steps to delete the volumes.
Iterator<URI> migrationSourcesIter = migrationSources.iterator();
while (migrationSourcesIter.hasNext()) {
URI migrationSourceURI = migrationSourcesIter.next();
_log.info("Migration source URI is {}", migrationSourceURI);
Volume migrationSource = _dbClient.queryObject(Volume.class, migrationSourceURI);
URI sourceSystemURI = migrationSource.getStorageController();
_log.info("Source storage system URI is {}", sourceSystemURI);
StorageSystem sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceSystemURI);
String subWFStepId = subWorkflow.createStepId();
Workflow.Method deleteVolumesMethod = new Workflow.Method(DELETE_VOLUMES_METHOD_NAME, sourceSystemURI, Arrays.asList(migrationSourceURI));
_log.info("Creating workflow step to delete source");
subWorkflow.createStep(MIGRATION_VOLUME_DELETE_STEP, String.format("Delete volume from storage system: %s", sourceSystemURI), waitFor, sourceSystemURI, sourceSystem.getSystemType(), BlockDeviceController.class, deleteVolumesMethod, null, subWFStepId);
_log.info("Created workflow step to delete source");
}
// Execute this sub workflow.
subWorkflow.executePlan(completer, "Deleted migration sources");
// Mark this workflow as created/executed so we don't do it again on retry/resume
WorkflowService.getInstance().markWorkflowBeenCreated(stepId, workflowKey);
}
} else {
// No sources to delete. Must have migrated an ingested volume.
WorkflowStepCompleter.stepSucceded(stepId);
_log.info("Updated workflow step to success");
}
} catch (Exception ex) {
// Log the error.
_log.error("Error deleting migration sources", ex);
// Always return success. This is a cleanup step after a
// successfully committed migration. We don't want rollback,
// so we return success.
WorkflowStepCompleter.stepSucceded(stepId);
}
}
use of com.emc.storageos.db.client.constraint.AlternateIdConstraint in project coprhd-controller by CoprHD.
the class SchemaUtil method queryLocalVdc.
private VirtualDataCenter queryLocalVdc(DbClient dbClient) {
// all vdc info stored in local db
try {
_log.debug("my vdcid: " + _vdcShortId);
URIQueryResultList list = new URIQueryResultList();
AlternateIdConstraint constraints = AlternateIdConstraint.Factory.getVirtualDataCenterByShortIdConstraint(_vdcShortId);
dbClient.queryByConstraint(constraints, list);
if (list.iterator().hasNext()) {
URI vdcId = list.iterator().next();
VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcId);
return vdc;
} else {
_log.info("vdc resource query returned no results");
return null;
}
} catch (DatabaseException ex) {
_log.error("failed querying for vdc resource", ex);
// Throw an DatabaseException and retry
throw ex;
} catch (Exception ex) {
_log.error("unexpected error during querying for vdc info", ex);
// throw IllegalStateExcpetion and stop
throw new IllegalStateException("vdc resource query failed");
}
}
use of com.emc.storageos.db.client.constraint.AlternateIdConstraint 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()));
}
}
use of com.emc.storageos.db.client.constraint.AlternateIdConstraint in project coprhd-controller by CoprHD.
the class DbIndexTest method testAlternativeIdSetIndex.
@Test
public void testAlternativeIdSetIndex() {
URI id = URIUtil.createId(AuthnProvider.class);
String key0 = "abcd1234";
String key1 = "efgh5678";
AlternateIdConstraint constraint0 = AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(key0);
AlternateIdConstraint constraint1 = AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(key1);
{
AuthnProvider obj = new AuthnProvider();
obj.setId(id);
obj.setDomains(new StringSet());
obj.getDomains().add(key0);
_dbClient.createObject(obj);
}
verifyContain(constraint0, id, 1);
verifyContain(constraint1, null, 0);
{
AuthnProvider obj = _dbClient.queryObject(AuthnProvider.class, id);
obj.getDomains().add(key1);
_dbClient.persistObject(obj);
}
verifyContain(constraint0, id, 1);
verifyContain(constraint1, id, 1);
{
AuthnProvider obj = _dbClient.queryObject(AuthnProvider.class, id);
obj.getDomains().remove(key0);
_dbClient.persistObject(obj);
}
verifyContain(constraint1, id, 1);
verifyContain(constraint0, null, 0);
}
Aggregations