use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method disableImageForSnapshots.
/**
* Disable image access for RP snapshots.
*
* @param protectionDevice
* protection system
* @param snapshotList
* list of snapshots to enable
* @param setSnapshotSyncActive
* true if the isSyncActive field on BlockSnapshot should be true, false otherwise.
* @param opId
* @throws ControllerException
*/
private void disableImageForSnapshots(URI protectionDevice, List<URI> snapshotList, boolean setSnapshotSyncActive, String opId) throws ControllerException {
BlockSnapshotDeactivateCompleter completer = null;
try {
_log.info("Deactivating a bookmark on the RP CG(s)");
completer = new BlockSnapshotDeactivateCompleter(snapshotList, setSnapshotSyncActive, opId);
ProtectionSystem system = null;
try {
system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
} catch (DatabaseException e) {
throw DeviceControllerExceptions.recoverpoint.databaseExceptionDeactivateSnapshot(protectionDevice);
}
if (system == null) {
throw DeviceControllerExceptions.recoverpoint.databaseExceptionDeactivateSnapshot(protectionDevice);
}
// Keep a mapping of the emNames(bookmark names) to target copy volume WWNs
Map<String, Set<String>> emNamesToVolumeWWNs = new HashMap<String, Set<String>>();
// Keep a mapping of the emNames(bookmark names) to BlockSnapshot objects
Map<String, Set<URI>> emNamesToSnapshots = new HashMap<String, Set<URI>>();
for (URI snapshotID : snapshotList) {
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
// Determine if we can actually disable image access to the copy associated with the snapshot first
if (!doDisableImageCopies(snapshot)) {
// Skip this snapshot because we cannot disable image access. Likely due to the snapshot
// being exported to multiple hosts.
_log.warn(String.format("Cannot disable image access for snapshot %s so it will be skipped. Likely due to the snapshot being exported to multiple hosts", snapshot.getId()));
continue;
}
String emName = snapshot.getEmName();
if (NullColumnValueGetter.isNotNullValue(emName)) {
if (!emNamesToVolumeWWNs.containsKey(emName)) {
emNamesToVolumeWWNs.put(emName, new HashSet<String>());
}
if (!emNamesToSnapshots.containsKey(emName)) {
emNamesToSnapshots.put(emName, new HashSet<URI>());
}
emNamesToSnapshots.get(emName).add(snapshotID);
} else {
throw DeviceControllerExceptions.recoverpoint.failedToDeactivateSnapshotEmNameMissing(snapshotID);
}
// Get the volume associated with this snapshot
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
// Fetch the VPLEX volume that is created with this volume as the back-end volume.
if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
volume = Volume.fetchVplexVolume(_dbClient, volume);
}
String wwn = null;
// If the personality is SOURCE, then the enable image access request is part of export operation.
if (volume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) {
wwn = RPHelper.getRPWWn(volume.getId(), _dbClient);
} else {
// Now determine the target volume that corresponds to the site of the snapshot
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
Volume targetVolume = ProtectionSet.getTargetVolumeFromSourceAndInternalSiteName(_dbClient, protectionSet, volume, snapshot.getEmInternalSiteName());
wwn = RPHelper.getRPWWn(targetVolume.getId(), _dbClient);
}
// Add the volume WWN
emNamesToVolumeWWNs.get(emName).add(wwn);
}
// Now disable image access on the bookmark copies
RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
// correponding to each emName.
for (Map.Entry<String, Set<String>> emNameEntry : emNamesToVolumeWWNs.entrySet()) {
MultiCopyDisableImageRequestParams request = new MultiCopyDisableImageRequestParams();
request.setVolumeWWNSet(emNameEntry.getValue());
request.setEmName(emNameEntry.getKey());
MultiCopyDisableImageResponse response = rp.disableImageCopies(request);
if (response == null) {
throw DeviceControllerExceptions.recoverpoint.failedDisableAccessOnRP();
}
// Let the completer know about the deactivated snapshots (ones who's associated copies
// had image access disabled). This will be used to update the BlockSnapshot fields accordingly.
// This is done because not all snapshots used when creating the completer will be deactivated.
// We need to maintain a collection of snapshots so that those exported to multiple hosts to not
// get deactivated.
completer.addDeactivatedSnapshots(emNamesToSnapshots.get(emNameEntry.getKey()));
}
completer.ready(_dbClient);
} catch (InternalException e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, e);
}
} catch (URISyntaxException e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, DeviceControllerException.errors.invalidURI(e));
}
} catch (Exception e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
}
}
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method enableImageForSnapshots.
/**
* Enable image access for RP snapshots.
*
* @param protectionDevice
* protection system
* @param storageDevice
* storage device of the backing (parent) volume
* @param snapshotList
* list of snapshots to enable
* @param opId
* task ID
* @return true if operation was successful
* @throws ControllerException
* @throws URISyntaxException
*/
private boolean enableImageForSnapshots(URI protectionDevice, URI storageDevice, List<URI> snapshotList, String opId) throws ControllerException, URISyntaxException {
TaskCompleter completer = null;
try {
_log.info("Activating a bookmark on the RP CG(s)");
completer = new BlockSnapshotActivateCompleter(snapshotList, opId);
ProtectionSystem system = null;
try {
system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
} catch (DatabaseException e) {
throw DeviceControllerExceptions.recoverpoint.databaseExceptionActivateSnapshot(protectionDevice);
}
// Verify non-null storage device returned from the database client.
if (system == null) {
throw DeviceControllerExceptions.recoverpoint.databaseExceptionActivateSnapshot(protectionDevice);
}
// is still creating the snapshot
if (snapshotList != null && !snapshotList.isEmpty()) {
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotList.get(0));
Volume parent = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
final List<Volume> vplexVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, getVolumesByAssociatedId(parent.getId().toString()));
if (vplexVolumes != null && !vplexVolumes.isEmpty()) {
parent = vplexVolumes.get(0);
}
String lockName = ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, parent.getConsistencyGroup(), system.getId());
if (null != lockName) {
List<String> locks = new ArrayList<String>();
locks.add(lockName);
acquireWorkflowLockOrThrow(_workflowService.getWorkflowFromStepId(opId), locks);
}
}
// Keep a mapping of the emNames(bookmark names) to target copy volume WWNs
Map<String, Set<String>> emNamesToVolumeWWNs = new HashMap<String, Set<String>>();
// Keep a mapping of the emNames(bookmark names) to BlockSnapshot objects
Map<String, Set<URI>> emNamesToSnapshots = new HashMap<String, Set<URI>>();
for (URI snapshotID : snapshotList) {
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
String emName = snapshot.getEmName();
if (NullColumnValueGetter.isNotNullValue(emName)) {
if (!emNamesToVolumeWWNs.containsKey(emName)) {
emNamesToVolumeWWNs.put(emName, new HashSet<String>());
}
if (!emNamesToSnapshots.containsKey(emName)) {
emNamesToSnapshots.put(emName, new HashSet<URI>());
}
emNamesToSnapshots.get(emName).add(snapshotID);
} else {
throw DeviceControllerExceptions.recoverpoint.failedToActivateSnapshotEmNameMissing(snapshotID);
}
// Get the volume associated with this snapshot
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
// Fetch the VPLEX volume that is created with this volume as the back-end volume.
if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
volume = Volume.fetchVplexVolume(_dbClient, volume);
}
String wwn = null;
// If the personality is SOURCE, then the enable image access request is part of export operation.
if (volume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) {
wwn = RPHelper.getRPWWn(volume.getId(), _dbClient);
} else {
// Now determine the target volume that corresponds to the site of the snapshot
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
Volume targetVolume = ProtectionSet.getTargetVolumeFromSourceAndInternalSiteName(_dbClient, protectionSet, volume, snapshot.getEmInternalSiteName());
wwn = RPHelper.getRPWWn(targetVolume.getId(), _dbClient);
}
// Add the volume WWN
emNamesToVolumeWWNs.get(emName).add(wwn);
}
// Now enable image access to that bookmark
RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
// correponding to each emName.
for (Map.Entry<String, Set<String>> emNameEntry : emNamesToVolumeWWNs.entrySet()) {
MultiCopyEnableImageRequestParams request = new MultiCopyEnableImageRequestParams();
request.setVolumeWWNSet(emNameEntry.getValue());
request.setBookmark(emNameEntry.getKey());
MultiCopyEnableImageResponse response = rp.enableImageCopies(request);
if (response == null) {
throw DeviceControllerExceptions.recoverpoint.failedEnableAccessOnRP();
}
}
completer.ready(_dbClient);
return true;
} catch (InternalException e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, e);
}
throw e;
} catch (URISyntaxException e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, DeviceControllerException.errors.invalidURI(e));
}
throw e;
} catch (Exception e) {
_log.error("Operation failed with Exception: ", e);
if (completer != null) {
completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
}
throw e;
}
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method constructSnapshotObjectFromBookmark.
/**
* Amend the BlockSnapshot object based on the results of the Bookmark creation operation
*
* @param result
* result from the snapshot creation command
* @param system
* protection system
* @param snapshotList
* snapshot list generated
* @param name
* emName
* @param opId
* operation ID for task completer
* @throws InternalException
* @throws FunctionalAPIInternalError_Exception
* @throws FunctionalAPIActionFailedException_Exception
*/
private void constructSnapshotObjectFromBookmark(CreateBookmarkResponse response, ProtectionSystem system, List<URI> snapshotList, String name, String opId) throws InternalException {
ProtectionSet protectionSet = null;
RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
// Update each snapshot object with the respective information.
for (URI snapshotID : snapshotList) {
// Get the snapshot and the associated volume
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
// Fetch the VPLEX volume that is created with this volume as the back-end volume.
if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
volume = Volume.fetchVplexVolume(_dbClient, volume);
}
if (protectionSet == null || !protectionSet.getId().equals(volume.getProtectionSet().getURI())) {
protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
}
// Gather the bookmark date, which is different than the snapshot date
Date bookmarkDate = new Date();
if (response.getVolumeWWNBookmarkDateMap() != null) {
bookmarkDate = response.getVolumeWWNBookmarkDateMap().get(RPHelper.getRPWWn(volume.getId(), _dbClient));
} else {
_log.warn("Bookmark date was not filled-in. Will use current date/time.");
}
snapshot.setEmName(name);
snapshot.setInactive(false);
snapshot.setEmBookmarkTime("" + bookmarkDate.getTime());
snapshot.setCreationTime(Calendar.getInstance());
snapshot.setTechnologyType(TechnologyType.RP.toString());
Volume targetVolume = RPHelper.getRPTargetVolumeFromSource(_dbClient, volume, snapshot.getVirtualArray());
// This section will identify and store the COPY ID associated with the bookmarks created.
// It is critical to store this information so we can later determine which bookmarks have
// been deleted from the RPA.
//
// May be able to remove this if the protection set object is more detailed (for instance, if
// we store the copy id with the volume)
RecoverPointVolumeProtectionInfo protectionInfo = rp.getProtectionInfoForVolume(RPHelper.getRPWWn(targetVolume.getId(), _dbClient));
for (RPConsistencyGroup rpcg : response.getCgBookmarkMap().keySet()) {
if (rpcg.getCGUID().getId() == protectionInfo.getRpVolumeGroupID()) {
for (RPBookmark bookmark : response.getCgBookmarkMap().get(rpcg)) {
if (bookmark.getBookmarkName() != null && bookmark.getBookmarkName().equalsIgnoreCase(name) && bookmark.getCGGroupCopyUID().getGlobalCopyUID().getCopyUID() == protectionInfo.getRpVolumeGroupCopyID()) {
snapshot.setEmCGGroupCopyId(protectionInfo.getRpVolumeGroupCopyID());
break;
}
}
}
}
if (targetVolume.getId().equals(volume.getId())) {
_log.error("The source and the target volumes are the same");
throw DeviceControllerExceptions.recoverpoint.cannotActivateSnapshotNoTargetVolume();
}
snapshot.setDeviceLabel(targetVolume.getDeviceLabel());
snapshot.setStorageController(targetVolume.getStorageController());
snapshot.setSystemType(targetVolume.getSystemType());
snapshot.setVirtualArray(targetVolume.getVirtualArray());
snapshot.setNativeId(targetVolume.getNativeId());
snapshot.setAlternateName(targetVolume.getAlternateName());
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(system, snapshot));
snapshot.setIsSyncActive(false);
// Setting the WWN of the bookmark to the WWN of the volume, no functional reason for now.
snapshot.setWWN(RPHelper.getRPWWn(targetVolume.getId(), _dbClient));
snapshot.setProtectionController(system.getId());
snapshot.setProtectionSet(volume.getProtectionSet().getURI());
_log.info(String.format("Updated bookmark %1$s associated with block volume %2$s on site %3$s.", name, volume.getDeviceLabel(), snapshot.getEmInternalSiteName()));
_dbClient.updateObject(snapshot);
List<URI> taskSnapshotURIList = new ArrayList<URI>();
taskSnapshotURIList.add(snapshot.getId());
TaskCompleter completer = new BlockSnapshotCreateCompleter(taskSnapshotURIList, opId);
completer.ready(_dbClient);
}
// Get information about the bookmarks created so we can get to them later.
_log.info("Bookmark(s) created for snapshot operation");
return;
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method updatePostSwapPersonalities.
/**
* After a swap, we need to swap personalities of source and target volumes
*
* @param id
* volume we failed over to
* @throws InternalException
*/
private Volume updatePostSwapPersonalities(Volume volume) throws InternalException {
_log.info("Changing personality of source and targets");
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
List<URI> volumeIDs = new ArrayList<URI>();
for (String volumeString : protectionSet.getVolumes()) {
URI volumeURI;
try {
volumeURI = new URI(volumeString);
volumeIDs.add(volumeURI);
} catch (URISyntaxException e) {
_log.error("URI syntax incorrect: ", e);
}
}
//
for (URI protectionVolumeID : volumeIDs) {
Volume protectionVolume = _dbClient.queryObject(Volume.class, protectionVolumeID);
if (protectionVolume == null || protectionVolume.getInactive()) {
continue;
}
if ((protectionVolume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) && (protectionVolume.getRpCopyName().equals(volume.getRpCopyName()))) {
// This is a TARGET we failed over to. We need to build up all of its targets
for (URI potentialTargetVolumeID : volumeIDs) {
Volume potentialTargetVolume = _dbClient.queryObject(Volume.class, potentialTargetVolumeID);
if (potentialTargetVolume == null || potentialTargetVolume.getInactive()) {
continue;
}
if (!potentialTargetVolume.checkPersonality(Volume.PersonalityTypes.METADATA.toString()) && NullColumnValueGetter.isNotNullValue(potentialTargetVolume.getRSetName()) && potentialTargetVolume.getRSetName().equals(protectionVolume.getRSetName()) && !potentialTargetVolumeID.equals(protectionVolume.getId())) {
if (protectionVolume.getRpTargets() == null) {
protectionVolume.setRpTargets(new StringSet());
}
protectionVolume.getRpTargets().add(String.valueOf(potentialTargetVolume.getId()));
}
}
_log.info("Change personality of failover target " + RPHelper.getRPWWn(protectionVolume.getId(), _dbClient) + " to source");
protectionVolume.setPersonality(Volume.PersonalityTypes.SOURCE.toString());
protectionVolume.setAccessState(Volume.VolumeAccessState.READWRITE.name());
protectionVolume.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
_dbClient.updateObject(protectionVolume);
} else if (protectionVolume.checkPersonality(Volume.PersonalityTypes.SOURCE.toString())) {
_log.info("Change personality of source volume " + RPHelper.getRPWWn(protectionVolume.getId(), _dbClient) + " to target");
protectionVolume.setPersonality(Volume.PersonalityTypes.TARGET.toString());
protectionVolume.setAccessState(Volume.VolumeAccessState.NOT_READY.name());
protectionVolume.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
protectionVolume.setRpTargets(new StringSet());
_dbClient.updateObject(protectionVolume);
} else if (!protectionVolume.checkPersonality(Volume.PersonalityTypes.METADATA.toString())) {
_log.info("Target " + RPHelper.getRPWWn(protectionVolume.getId(), _dbClient) + " is a target that remains a target");
// TODO: Handle failover to CRR. Need to remove the CDP volumes (including journals)
}
}
return _dbClient.queryObject(Volume.class, volume.getId());
}
use of com.emc.storageos.db.client.model.ProtectionSet in project coprhd-controller by CoprHD.
the class RPDeviceController method updatePostFailoverCancel.
/**
* After a failover of a failover (without swap), we need to set specific flags
*
* @param id
* volume we failed over to
* @throws InternalException
*/
private void updatePostFailoverCancel(Volume volume) throws InternalException {
_log.info("Setting respective flags after failover of failover");
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
List<URI> volumeIDs = new ArrayList<URI>();
for (String volumeString : protectionSet.getVolumes()) {
URI volumeURI;
try {
volumeURI = new URI(volumeString);
volumeIDs.add(volumeURI);
} catch (URISyntaxException e) {
_log.error("URI syntax incorrect: ", e);
}
}
for (URI protectionVolumeID : volumeIDs) {
Volume protectionVolume = _dbClient.queryObject(Volume.class, protectionVolumeID);
if (protectionVolume == null || protectionVolume.getInactive()) {
continue;
}
if ((protectionVolume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) && (protectionVolume.getRpCopyName().equals(volume.getRpCopyName()))) {
_log.info("Change flags of failover target " + RPHelper.getRPWWn(protectionVolume.getId(), _dbClient));
protectionVolume.setAccessState(Volume.VolumeAccessState.NOT_READY.name());
protectionVolume.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
_dbClient.updateObject(protectionVolume);
} else if (protectionVolume.checkPersonality(Volume.PersonalityTypes.SOURCE.toString())) {
_log.info("Change flags of failover source " + RPHelper.getRPWWn(protectionVolume.getId(), _dbClient));
protectionVolume.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
_dbClient.updateObject(protectionVolume);
}
}
}
Aggregations