use of com.emc.storageos.volumecontroller.impl.smis.job.SmisDeleteVolumeJob in project coprhd-controller by CoprHD.
the class SmisStorageDevice method doDeleteVolumes.
@Override
public void doDeleteVolumes(final StorageSystem storageSystem, final String opId, final List<Volume> volumes, final TaskCompleter taskCompleter) throws DeviceControllerException {
try {
List<String> volumeNativeIds = new ArrayList<String>();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume Start - Array:%s", storageSystem.getSerialNumber()));
MultiVolumeTaskCompleter multiVolumeTaskCompleter = (MultiVolumeTaskCompleter) taskCompleter;
Set<CIMInstance> parkingSLOStorageGroups = new HashSet<>();
Set<Volume> cloneVolumes = new HashSet<Volume>();
_helper.callRefreshSystem(storageSystem, null, false);
Iterator<Volume> volumeItr = volumes.iterator();
Set<String> nativeIdsForParkingSG = new HashSet<String>();
// Flag to indicate whether or not we need to use the EMCForce flag on this operation.
// We currently use this flag when dealing with RP Volumes as they are tagged for RP and the
// operation on these volumes would fail otherwise.
boolean forceFlag = false;
while (volumeItr.hasNext()) {
Volume volume = volumeItr.next();
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
// check if the volume is on array, if not, no operation on array side
CIMInstance volumeInstance = _helper.checkExists(storageSystem, _cimPath.getBlockObjectPath(storageSystem, volume), false, false);
if (volumeInstance == null) {
// related volume state (if any) has been deleted. skip processing, if already
// deleted from array.
_log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
volume.setInactive(true);
_dbClient.updateObject(volume);
// remove the volume from the processing list
volumeItr.remove();
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
deleteTaskCompleter.ready(_dbClient);
continue;
}
nativeIdsForParkingSG.add(volume.getNativeId());
if (!forceFlag) {
forceFlag = ExportUtils.useEMCForceFlag(_dbClient, volume.getId());
}
}
if (storageSystem.checkIfVmax3()) {
parkingSLOStorageGroups = _helper.removeVolumeFromParkingSLOStorageGroup(storageSystem, nativeIdsForParkingSG.toArray(new String[] {}), forceFlag);
_log.info("Done invoking remove volumes from parking SLO storage group");
// delete operation.
if (!parkingSLOStorageGroups.isEmpty()) {
_helper.deleteParkingSLOStorageGroupsIfEmpty(storageSystem, parkingSLOStorageGroups);
}
}
for (Volume volume : volumes) {
if (volume.getConsistencyGroup() != null || NullColumnValueGetter.isNotNullValue(volume.getReplicationGroupInstance())) {
_log.info(String.format("Volume [%s](%s) is a part of CG (%s), extra cleanup operations may be needed.", volume.getLabel(), volume.getId(), volume.getConsistencyGroup()));
// Clean up any group backup snapshots (VNX only), if there are none this step will be skipped.
if (storageSystem.deviceIsType(Type.vnxblock)) {
cleanupAnyGroupBackupSnapshots(storageSystem, volume);
}
// Remove the volume from the backend CG, if it's not actually in a backend CG this step will be skipped.
removeVolumeFromConsistencyGroup(storageSystem, volume);
// Clean up any volume backup snapshots, if there are none this step will be skipped.
cleanupAnyBackupSnapshots(storageSystem, volume);
} else {
// for VMAX3, clean up unlinked snapshot session, which is possible for ingested volume
if (storageSystem.deviceIsType(Type.vnxblock) || storageSystem.checkIfVmax3()) {
cleanupAnyBackupSnapshots(storageSystem, volume);
}
}
if (storageSystem.deviceIsType(Type.vmax)) {
// VMAX2 & VMAX3 - remove volume from Storage Groups if volume is not in any MaskingView
// COP-16705, COP-21770 - Ingested non-exported Volume may be associated with SG outside of ViPR.
_helper.removeVolumeFromStorageGroupsIfVolumeIsNotInAnyMV(storageSystem, volume);
}
_helper.doApplyRecoverPointTag(storageSystem, volume, false);
// Compare the volume labels of the to-be-deleted and existing volumes
/**
* This will fail in the case when the user just changes the label of the
* volume...until we subscribe to indications from the provider, we will live with
* that.
*/
String volToDeleteLabel = volume.getDeviceLabel();
CIMInstance volumeInstance = _helper.checkExists(storageSystem, _cimPath.getBlockObjectPath(storageSystem, volume), false, false);
String volInstanceLabel = CIMPropertyFactory.getPropertyValue(volumeInstance, SmisConstants.CP_ELEMENT_NAME);
if (volToDeleteLabel != null && volInstanceLabel != null && !volToDeleteLabel.equals(volInstanceLabel)) {
// related volume state (if any) has been deleted. skip processing, if already
// deleted from array.
_log.info("VolToDeleteLabel {} : volInstancelabel {}", volToDeleteLabel, volInstanceLabel);
_log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
volume.setInactive(true);
// clear the associated consistency group from the volume
volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
_dbClient.updateObject(volume);
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
deleteTaskCompleter.ready(_dbClient);
continue;
}
// dangling meta members as a result of expansion failure (and rollback failure).
if (!storageSystem.checkIfVmax3()) {
boolean cleanupSuccess = cleanupDanglingMetaMembers(storageSystem, volume);
if (!cleanupSuccess) {
// cannot delete volume
String errorMessage = String.format("Failed to delete meta volume: %s , nativeId: %s .\n" + "Could not cleanup dangling meta members.", volume.getId(), volume.getNativeId());
ServiceError error = DeviceControllerErrors.smis.methodFailed("doDeleteVolume", errorMessage);
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
deleteTaskCompleter.error(_dbClient, error);
_log.error(String.format(errorMessage));
continue;
}
}
if (!NullColumnValueGetter.isNullURI(volume.getAssociatedSourceVolume())) {
cloneVolumes.add(volume);
}
volumeNativeIds.add(volume.getNativeId());
}
_log.info(logMsgBuilder.toString());
// execute SMI-S Call , only if any Volumes left for deletion.
if (!multiVolumeTaskCompleter.isVolumeTaskCompletersEmpty()) {
if (!cloneVolumes.isEmpty()) {
processClonesBeforeDeletion(storageSystem, cloneVolumes);
}
CIMObjectPath configSvcPath = _cimPath.getConfigSvcPath(storageSystem);
CIMArgument[] inArgs = _helper.getDeleteVolumesInputArguments(storageSystem, volumeNativeIds.toArray(new String[0]));
CIMArgument[] outArgs = new CIMArgument[5];
String returnElementsMethod;
if (storageSystem.getUsingSmis80()) {
returnElementsMethod = SmisConstants.RETURN_ELEMENTS_TO_STORAGE_POOL;
} else {
returnElementsMethod = SmisConstants.EMC_RETURN_TO_STORAGE_POOL;
}
_helper.invokeMethod(storageSystem, configSvcPath, returnElementsMethod, inArgs, outArgs);
CIMObjectPath job = _cimPath.getCimObjectPathFromOutputArgs(outArgs, SmisConstants.JOB);
if (job != null) {
ControllerServiceImpl.enqueueJob(new QueueJob(new SmisDeleteVolumeJob(job, storageSystem.getId(), taskCompleter)));
}
} else {
// If we are here, there are no volumes to delete, we have
// invoked ready() for the VolumeDeleteCompleter, and told
// the multiVolumeTaskCompleter to skip these completers.
// In this case, the multiVolumeTaskCompleter complete()
// method will not be invoked and the result is that the
// workflow that initiated this delete request will never
// be updated. So, here we just call complete() on the
// multiVolumeTaskCompleter to ensure the workflow status is
// updated.
multiVolumeTaskCompleter.ready(_dbClient);
}
} catch (WBEMException e) {
_log.error("Problem making SMI-S call: ", e);
ServiceError error = DeviceControllerErrors.smis.unableToCallStorageProvider(e.getMessage());
taskCompleter.error(_dbClient, error);
} catch (Exception e) {
_log.error("Problem in doDeleteVolume: ", e);
// Check to see if an Asynchronous job will now handle the task status.
if (!taskCompleter.isAsynchronous()) {
ServiceError error = DeviceControllerErrors.smis.methodFailed("doDeleteVolume", e.getMessage());
taskCompleter.error(_dbClient, error);
}
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume End - Array: %s", storageSystem.getSerialNumber()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
}
_log.info(logMsgBuilder.toString());
}
Aggregations