Search in sources :

Example 1 with CinderDeleteVolumeJob

use of com.emc.storageos.volumecontroller.impl.cinder.job.CinderDeleteVolumeJob in project coprhd-controller by CoprHD.

the class CinderStorageDevice method doDeleteVolumes.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteVolumes
     * (com.emc.storageos.db.client.model.StorageSystem,
     * java.lang.String,
     * java.util.List,
     * com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        List<String> volumeNativeIdsToDelete = new ArrayList<String>(volumes.size());
        List<String> volumeLabels = new ArrayList<String>(volumes.size());
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume Start - Array:%s", storageSystem.getSerialNumber()));
        log.info(logMsgBuilder.toString());
        MultiVolumeTaskCompleter multiVolumeTaskCompleter = (MultiVolumeTaskCompleter) taskCompleter;
        CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
        log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
        CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
        for (Volume volume : volumes) {
            logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
            try {
                // Check if the volume is present on the back-end device
                cinderApi.showVolume(volume.getNativeId());
            } catch (CinderException ce) {
                // This means, the volume is not present on the back-end device
                log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
                volume.setInactive(true);
                dbClient.persistObject(volume);
                VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
                deleteTaskCompleter.ready(dbClient);
                continue;
            }
            volumeNativeIdsToDelete.add(volume.getNativeId());
            volumeLabels.add(volume.getLabel());
            // cleanup if there are any snapshots created for a volume
            cleanupAnyBackupSnapshots(volume, cinderApi);
        }
        // Now - trigger the delete
        if (!multiVolumeTaskCompleter.isVolumeTaskCompletersEmpty()) {
            cinderApi.deleteVolumes(volumeNativeIdsToDelete.toArray(new String[] {}));
            ControllerServiceImpl.enqueueJob(new QueueJob(new CinderDeleteVolumeJob(volumeNativeIdsToDelete.get(0), volumeLabels.get(0), volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, 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 (Exception e) {
        log.error("Problem in doDeleteVolume: ", e);
        ServiceError error = DeviceControllerErrors.cinder.operationFailed("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());
}
Also used : CinderException(com.emc.storageos.cinder.errorhandling.CinderException) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) CinderDeleteVolumeJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderDeleteVolumeJob) ArrayList(java.util.ArrayList) CinderApi(com.emc.storageos.cinder.api.CinderApi) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) CinderException(com.emc.storageos.cinder.errorhandling.CinderException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) Volume(com.emc.storageos.db.client.model.Volume) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Aggregations

CinderEndPointInfo (com.emc.storageos.cinder.CinderEndPointInfo)1 CinderApi (com.emc.storageos.cinder.api.CinderApi)1 CinderException (com.emc.storageos.cinder.errorhandling.CinderException)1 Volume (com.emc.storageos.db.client.model.Volume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 MultiVolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter)1 VolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter)1 CinderDeleteVolumeJob (com.emc.storageos.volumecontroller.impl.cinder.job.CinderDeleteVolumeJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 ArrayList (java.util.ArrayList)1