use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RecoverPointVolumeIngestionContext method commit.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext#commit()
*/
@Override
public void commit() {
_logger.info("persisting RecoverPoint backend for volume " + getUnmanagedVolume().forDisplay());
// commit the basic IngestionRequestContext collections
for (BlockObject bo : getObjectsIngestedByExportProcessing()) {
_logger.info("Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
_dbClient.createObject(bo);
}
for (BlockObject bo : getBlockObjectsToBeCreatedMap().values()) {
_logger.info("Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
_dbClient.createObject(bo);
}
for (Set<DataObject> createdObjects : getDataObjectsToBeCreatedMap().values()) {
if (createdObjects != null && !createdObjects.isEmpty()) {
for (DataObject dob : createdObjects) {
_logger.info("Creating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
_dbClient.createObject(dob);
}
}
}
for (Set<DataObject> updatedObjects : getDataObjectsToBeUpdatedMap().values()) {
if (updatedObjects != null && !updatedObjects.isEmpty()) {
for (DataObject dob : updatedObjects) {
if (dob.getInactive()) {
_logger.info("Deleting DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
} else {
_logger.info("Updating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
}
_dbClient.updateObject(dob);
}
}
}
for (UnManagedVolume umv : getUnManagedVolumesToBeDeleted()) {
_logger.info("Deleting UnManagedVolume {} (hash {})", umv.forDisplay(), umv.hashCode());
_dbClient.updateObject(umv);
}
// now commit the RecoverPoint specific data
if (_managedSourceVolumesToUpdate != null) {
_logger.info("Updating RP Source Volumes: " + _managedSourceVolumesToUpdate);
_dbClient.updateObject(_managedSourceVolumesToUpdate);
}
if (_unmanagedSourceVolumesToUpdate != null) {
_logger.info("Updating RP Source UnManagedVolumes: " + _unmanagedSourceVolumesToUpdate);
_dbClient.updateObject(_unmanagedSourceVolumesToUpdate);
}
if (_unmanagedTargetVolumesToUpdate != null) {
_logger.info("Updating RP Target UnManagedVolumes: " + _unmanagedTargetVolumesToUpdate);
_dbClient.updateObject(_unmanagedTargetVolumesToUpdate);
}
// commit the ProtectionSet, if created, and remove the UnManagedProtectionSet
ProtectionSet managedProtectionSet = getManagedProtectionSet();
if (null != managedProtectionSet) {
if (getManagedBlockObject() != null) {
managedProtectionSet.getVolumes().add(_managedBlockObject.getId().toString());
}
_logger.info("Creating ProtectionSet {} (hash {})", managedProtectionSet.forDisplay(), managedProtectionSet.hashCode());
_dbClient.createObject(managedProtectionSet);
// the protection set was created, so delete the unmanaged one
_logger.info("Deleting UnManagedProtectionSet {} (hash {})", _unManagedProtectionSet.forDisplay(), _unManagedProtectionSet.hashCode());
_dbClient.removeObject(_unManagedProtectionSet);
}
// commit the BlockConsistencyGroup, if created
if (null != getManagedBlockConsistencyGroup()) {
_logger.info("Creating BlockConsistencyGroup {} (hash {})", _managedBlockConsistencyGroup.forDisplay(), _managedBlockConsistencyGroup.hashCode());
_dbClient.createObject(_managedBlockConsistencyGroup);
}
for (Entry<ExportGroup, Boolean> entry : getRpExportGroupMap().entrySet()) {
ExportGroup exportGroup = entry.getKey();
boolean exportGroupIsCreated = entry.getValue();
if (exportGroupIsCreated) {
_logger.info("Creating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
_dbClient.createObject(exportGroup);
} else {
_logger.info("Updating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
_dbClient.updateObject(exportGroup);
}
}
super.commit();
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method isRPProtectingVplexVolumes.
/**
* Checks whether RP is protecting any VPLEX volumes or not.
*
* 1. Get the ProtectionSet from the context for the given unmanagedvolume.
* 2. Check every volume in the protectionset.
* 3. If the volume belongs to a VPLEX or not.
* 4. If it belongs to VPLEX break the loop and return true.
*
* @param umv - unmanaged volume to ingest
* @param requestContext - current unmanaged volume context.
* @param dbClient - dbclient reference.
*/
public static boolean isRPProtectingVplexVolumes(UnManagedVolume umv, IngestionRequestContext requestContext, DbClient dbClient) {
VolumeIngestionContext context = requestContext.getVolumeContext(umv.getNativeGuid());
boolean isRPProtectingVplexVolumes = false;
// We expect RP Context to validate Vplex volumes protected by RP or not.
if (context instanceof RecoverPointVolumeIngestionContext) {
RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) context;
ProtectionSet pset = rpContext.getManagedProtectionSet();
if (pset == null) {
return isRPProtectingVplexVolumes;
}
// Iterate thru protection set volumes.
for (String volumeIdStr : pset.getVolumes()) {
for (Set<DataObject> dataObjList : rpContext.getDataObjectsToBeUpdatedMap().values()) {
for (DataObject dataObj : dataObjList) {
if (URIUtil.identical(dataObj.getId(), URI.create(volumeIdStr))) {
Volume volume = (Volume) dataObj;
if (volume.isVPlexVolume(dbClient)) {
isRPProtectingVplexVolumes = true;
break;
}
}
}
}
}
} else if (context instanceof BlockVolumeIngestionContext) {
// In this case, the last volume ingested was a replica, so we need to fish out RP information slightly differently.
Set<DataObject> updatedObjects = requestContext.getDataObjectsToBeUpdatedMap().get(umv.getNativeGuid());
if (updatedObjects != null && !updatedObjects.isEmpty()) {
for (DataObject dataObj : updatedObjects) {
if (dataObj instanceof Volume) {
Volume volume = (Volume) dataObj;
if (volume.isVPlexVolume(dbClient)) {
isRPProtectingVplexVolumes = true;
break;
}
}
}
}
} else {
_logger.error("Context found of type: {} invalid", context.getClass().toString());
}
return isRPProtectingVplexVolumes;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class TaskLockingCompleter method lockCG.
/**
* Lock the entire CG based on this volume.
*
* @param dbClient db client
* @param locker locker service
* @return true if lock was acquired
*/
public boolean lockCG(DbClient dbClient, ControllerLockingService locker) {
// Figure out the lock ID (rpSystemInstallationID:CGName)
URI volumeId = getId();
// If this is a snapshot object completer, get the volume id from the snapshot.
if (URIUtil.isType(getId(), BlockSnapshot.class)) {
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, getId());
volumeId = snapshot.getParent().getURI();
} else if (URIUtil.isType(getId(), BlockConsistencyGroup.class)) {
List<Volume> cgVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Volume.class, getVolumesByConsistencyGroup(getId()));
if (cgVolumes != null && !cgVolumes.isEmpty()) {
// Get the first volume in the CG
volumeId = cgVolumes.get(0).getId();
}
}
// Figure out the lock ID (rpSystemInstallationID:CGName)
Volume volume = dbClient.queryObject(Volume.class, volumeId);
if (volume != null && locker != null) {
if (volume.getProtectionController() != null && volume.getProtectionSet() != null) {
ProtectionSystem rpSystem = dbClient.queryObject(ProtectionSystem.class, volume.getProtectionController());
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
if (rpSystem != null && protectionSet != null && rpSystem.getInstallationId() != null && protectionSet.getLabel() != null) {
// Unlock the CG based on this volume
String lockName = rpSystem.getInstallationId() + LOCK_SEPARATOR + protectionSet.getLabel();
if (locker.acquirePersistentLock(lockName, _opId, 5)) {
_logger.info("Acquired lock: " + lockName);
lockedName = lockName;
return true;
} else {
_logger.info("Failed to acquire lock: " + lockName);
}
}
} else if (volume.getProtectionSet() == null) {
_logger.info("Lock not required, no CG in use");
lockedName = null;
return true;
}
}
return false;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPCommunicationInterface method discoverProtectionSet.
/**
* Discover a single protection set.
*
* @param protectionSystem protection system
* @param protectionSetId protection set
* @throws RecoverPointException
*/
private void discoverProtectionSet(ProtectionSystem protectionSystem, URI protectionSetId) throws RecoverPointException {
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet == null || protectionSet.getInactive()) {
return;
}
List<String> staleVolumes = new ArrayList<String>();
StringSet protectionVolumes = protectionSet.getVolumes();
RecoverPointVolumeProtectionInfo protectionVolume = null;
RecoverPointClient rp = RPHelper.getRecoverPointClient(protectionSystem);
boolean changed = false;
_log.info("ProtectionSet discover in the RPDeviceController called for protection set: " + protectionSet.getLabel());
for (String volume : protectionVolumes) {
Volume protectionVolumeWWN = _dbClient.queryObject(Volume.class, URI.create(volume));
if (protectionVolumeWWN == null || protectionVolumeWWN.getInactive()) {
staleVolumes.add(volume);
continue;
}
try {
protectionVolume = rp.getProtectionInfoForVolume(RPHelper.getRPWWn(protectionVolumeWWN.getId(), _dbClient));
} catch (RecoverPointException re) {
StringBuffer errMsgBuilder = new StringBuffer();
String msg = "Discovery of protection set failed. Protection system: " + protectionSystem.getId() + ", ";
errMsgBuilder.append(msg);
errMsgBuilder.append(re.getMessage());
_log.warn(errMsgBuilder.toString());
}
if (protectionVolume == null) {
continue;
}
// If the volume is a source volume, let's check to see if the personality changed.
if ((!changed) && (((protectionVolume.getRpVolumeCurrentProtectionStatus() == RecoverPointVolumeProtectionInfo.volumeProtectionStatus.PROTECTED_SOURCE) && (protectionVolumeWWN.getPersonality().equalsIgnoreCase(Volume.PersonalityTypes.TARGET.toString())))) || ((protectionVolume.getRpVolumeCurrentProtectionStatus() == RecoverPointVolumeProtectionInfo.volumeProtectionStatus.PROTECTED_TARGET) && (protectionVolumeWWN.getPersonality().equalsIgnoreCase(Volume.PersonalityTypes.SOURCE.toString())))) {
_log.info("Changing personality of volume {} due to RP condition on consistency group", protectionVolumeWWN.getLabel());
updatePostFailoverPersonalities(protectionVolumeWWN);
changed = true;
}
if (protectionVolume.getRpVolumeCurrentProtectionStatus() == RecoverPointVolumeProtectionInfo.volumeProtectionStatus.PROTECTED_SOURCE) {
switch(rp.getCGState(protectionVolume)) {
case DELETED:
protectionSet.setProtectionStatus(ProtectionStatus.DELETED.toString());
break;
case STOPPED:
protectionSet.setProtectionStatus(ProtectionStatus.DISABLED.toString());
break;
case PAUSED:
protectionSet.setProtectionStatus(ProtectionStatus.PAUSED.toString());
break;
case MIXED:
protectionSet.setProtectionStatus(ProtectionStatus.MIXED.toString());
break;
case READY:
protectionSet.setProtectionStatus(ProtectionStatus.ENABLED.toString());
break;
}
_dbClient.updateObject(protectionSet);
break;
}
}
// remove stale entries from protection set
if (!staleVolumes.isEmpty()) {
_log.info(String.format("ProtectionSet %s references at least one volume id that no longer exist in the database. Removing all stale volume references: %s", protectionSet.getLabel(), String.join(",", staleVolumes)));
protectionSet.getVolumes().removeAll(staleVolumes);
_dbClient.updateObject(protectionSet);
}
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class BlockMapper method map.
public static BlockConsistencyGroupRestRep map(BlockConsistencyGroup from, Set<URI> volumes, DbClient dbClient) {
if (from == null) {
return null;
}
BlockConsistencyGroupRestRep to = new BlockConsistencyGroupRestRep();
mapDataObjectFields(from, to);
to.setVirtualArray(toRelatedResource(ResourceTypeEnum.VARRAY, from.getVirtualArray()));
to.setProject(toRelatedResource(ResourceTypeEnum.PROJECT, from.getProject().getURI()));
if (!NullColumnValueGetter.isNullURI(from.getStorageController())) {
to.setStorageController(toRelatedResource(ResourceTypeEnum.STORAGE_SYSTEM, from.getStorageController()));
}
to.setArrayConsistency(from.getArrayConsistency());
// Default snapshot session support to false
to.setSupportsSnapshotSessions(Boolean.FALSE);
if (dbClient != null && from.getSystemConsistencyGroups() != null) {
for (String systemId : from.getSystemConsistencyGroups().keySet()) {
StorageSystem system = dbClient.queryObject(StorageSystem.class, URI.create(systemId));
if (system != null && system.checkIfVmax3()) {
to.setSupportsSnapshotSessions(Boolean.TRUE);
}
}
}
try {
if (from.getSystemConsistencyGroups() != null) {
to.setSystemConsistencyGroups(new StringSetMapAdapter().marshal(from.getSystemConsistencyGroups()));
if (!to.getSupportsSnapshotSessions()) {
// we can flag this as true.
if (dbClient != null && to.getSystemConsistencyGroups() != null) {
for (StringSetMapAdapter.Entry entry : to.getSystemConsistencyGroups()) {
String storageSystemId = entry.getKey();
if (storageSystemId != null) {
StorageSystem system = dbClient.queryObject(StorageSystem.class, URI.create(storageSystemId));
if (system != null && system.checkIfVmax3()) {
to.setSupportsSnapshotSessions(Boolean.TRUE);
break;
}
}
}
}
}
}
} catch (Exception e) {
// internally ignored
logger.debug(e.getMessage(), e);
}
if (from.getTypes() != null) {
to.setTypes(from.getTypes());
}
if (dbClient != null) {
List<RelatedResourceRep> volumesResourceRep = new ArrayList<RelatedResourceRep>();
final URIQueryResultList cgVolumesResults = new URIQueryResultList();
dbClient.queryByConstraint(getVolumesByConsistencyGroup(from.getId()), cgVolumesResults);
Iterator<Volume> volumeIterator = dbClient.queryIterativeObjects(Volume.class, cgVolumesResults);
boolean first = true;
while (volumeIterator.hasNext()) {
// Get the first RP or SRDF volume. From this we are able to obtain the
// link status and protection set (RP) information for all volumes in the
// CG.
Volume volume = volumeIterator.next();
if (first) {
if (from.getTypes().contains(BlockConsistencyGroup.Types.RP.toString()) && !NullColumnValueGetter.isNullNamedURI(volume.getProtectionSet())) {
// Get the protection set from the first volume and set the appropriate fields
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
to.setRpConsistenyGroupId(protectionSet.getProtectionId());
to.setLinkStatus(protectionSet.getProtectionStatus());
to.setRpProtectionSystem(protectionSet.getProtectionSystem());
} else if (from.getTypes().contains(BlockConsistencyGroup.Types.SRDF.toString())) {
// Operations cannot be performed individually on volumes within an SRDF CG, hence
// we can take any one of the volume's link status and update the CG link status.
to.setLinkStatus(volume.getLinkStatus());
}
}
// Only display CG volumes that are non-RP or RP source volumes. Exclude RP+VPlex backing volumes.
if ((!volume.checkForRp() && !RPHelper.isAssociatedToAnyRpVplexTypes(volume, dbClient)) || (volume.checkForRp() && PersonalityTypes.SOURCE.name().equals(volume.getPersonality()))) {
volumesResourceRep.add(toRelatedResource(ResourceTypeEnum.VOLUME, volume.getId()));
}
first = false;
}
to.setVolumes(volumesResourceRep);
}
return to;
}
Aggregations