Search in sources :

Example 1 with HDSCleanupMetaVolumeMembersJob

use of com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSCleanupMetaVolumeMembersJob in project coprhd-controller by CoprHD.

the class HDSStorageDevice method doCleanupMetaMembers.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCleanupMetaMembers(com.emc.storageos.db.client.model.StorageSystem,
     * com.emc.storageos.db.client.model.Volume,
     * com.emc.storageos.volumecontroller.impl.block.taskcompleter.CleanupMetaVolumeMembersCompleter)
     */
@Override
public void doCleanupMetaMembers(StorageSystem storageSystem, Volume volume, CleanupMetaVolumeMembersCompleter cleanupCompleter) throws DeviceControllerException {
    // Remove meta member volumes from storage device
    try {
        log.info(String.format("doCleanupMetaMembers  Start - Array: %s, Volume: %s", storageSystem.getSerialNumber(), volume.getLabel()));
        // Load meta volume members from WF data
        String sourceStepId = cleanupCompleter.getSourceStepId();
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getUsername(), storageSystem.getSmisPassword());
        List<String> metaMembers = (ArrayList<String>) WorkflowService.getInstance().loadStepData(sourceStepId);
        if (metaMembers != null && !metaMembers.isEmpty()) {
            log.info(String.format("doCleanupMetaMembers: Members stored for meta volume: %n %s", metaMembers));
            // Check if volumes still exist in array and if it is not composite member (already
            // added to the meta volume)
            Set<String> volumeIds = new HashSet<String>();
            for (String logicalUnitObjectId : metaMembers) {
                LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(HDSUtils.getSystemObjectID(storageSystem), logicalUnitObjectId);
                if (logicalUnit != null) {
                    log.debug("doCleanupMetaMembers: Volume: " + logicalUnitObjectId + ", Usage of volume: " + logicalUnit.getComposite());
                    if (logicalUnit.getComposite() != HDSConstants.COMPOSITE_ELEMENT_MEMBER) {
                        volumeIds.add(logicalUnitObjectId);
                    }
                }
            }
            if (volumeIds.isEmpty()) {
                log.info("doCleanupMetaMembers: No meta members to cleanup in array.");
                cleanupCompleter.ready(dbClient);
            } else {
                log.info(String.format("doCleanupMetaMembers: Members to cleanup in array: %n   %s", volumeIds));
                // Prepare parameters and call method to delete meta members from array
                HDSCleanupMetaVolumeMembersJob hdsJobCompleter = null;
                // When "cleanup" is separate workflow step, call async (for example rollback
                // step in volume expand)
                // Otherwise, call synchronously (for example when cleanup is part of meta
                // volume create rollback)
                String asyncMessageId = hdsApiClient.deleteThickLogicalUnits(HDSUtils.getSystemObjectID(storageSystem), volumeIds, storageSystem.getModel());
                if (asyncMessageId == null) {
                    throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
                }
                if (cleanupCompleter.isWFStep()) {
                    if (asyncMessageId != null) {
                        ControllerServiceImpl.enqueueJob(new QueueJob(new HDSCleanupMetaVolumeMembersJob(asyncMessageId, storageSystem.getId(), volume.getId(), cleanupCompleter)));
                    }
                } else {
                    // invoke synchronously
                    hdsJobCompleter = new HDSCleanupMetaVolumeMembersJob(asyncMessageId, storageSystem.getId(), volume.getId(), cleanupCompleter);
                    ((HDSMetaVolumeOperations) metaVolumeOperations).invokeMethodSynchronously(hdsApiFactory, asyncMessageId, hdsJobCompleter);
                }
            }
        } else {
            log.info("doCleanupMetaMembers: No meta members stored for meta volume. Nothing to cleanup in array.");
            cleanupCompleter.ready(dbClient);
        }
    } catch (Exception e) {
        log.error("Problem in doCleanupMetaMembers: ", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("doCleanupMetaMembers", e.getMessage());
        cleanupCompleter.error(dbClient, error);
    }
    log.info(String.format("doCleanupMetaMembers End - Array: %s,  Volume: %s", storageSystem.getSerialNumber(), volume.getLabel()));
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HDSCleanupMetaVolumeMembersJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSCleanupMetaVolumeMembersJob) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) ArrayList(java.util.ArrayList) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) HashSet(java.util.HashSet)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 HDSException (com.emc.storageos.hds.HDSException)1 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)1 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 HDSCleanupMetaVolumeMembersJob (com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSCleanupMetaVolumeMembersJob)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1