Search in sources :

Example 11 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOExportOperations method runLunMapDeletionOrRemoveInitiatorAlgorithm.

/**
 * It deletes the LunMap if the IG contains no other initiators than the requested ones.
 * Else it removes the requested initiators from the IG
 */
private void runLunMapDeletionOrRemoveInitiatorAlgorithm(StorageSystem storage, ExportMask exportMask, List<URI> volumes, List<Initiator> initiators, TaskCompleter taskCompleter) throws DeviceControllerException {
    // find LunMap associated with Volume
    // Then find initiatorGroup associated with this lun map
    XtremIOClient client = null;
    // Default_IG;
    try {
        String hostName = null;
        String clusterName = null;
        client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        boolean initiatorsOfRP = ExportUtils.checkIfInitiatorsForRP(initiators);
        for (Initiator initiator : initiators) {
            if (null != initiator.getHostName()) {
                // initiators already grouped by Host
                hostName = initiator.getHostName();
                clusterName = initiator.getClusterName();
                break;
            }
        }
        ArrayListMultimap<String, Initiator> groupInitiatorsByIG = XtremIOProvUtils.mapInitiatorToInitiatorGroup(storage.getSerialNumber(), initiators, null, xioClusterName, client);
        ArrayListMultimap<String, Initiator> knownInitiatorsToIGMap = ArrayListMultimap.create();
        // DU validations for removing volumes from IG.
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setInitiators(initiators);
        ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId()));
        XtremIOExportMaskInitiatorsValidator initiatorsValidator = (XtremIOExportMaskInitiatorsValidator) validator.removeVolumes(ctx);
        initiatorsValidator.setInitiatorToIGMap(groupInitiatorsByIG);
        initiatorsValidator.setKnownInitiatorToIGMap(knownInitiatorsToIGMap);
        initiatorsValidator.validate();
        Set<String> igNames = groupInitiatorsByIG.keySet();
        List<String> failedVolumes = new ArrayList<String>();
        List<String> failedIGs = new ArrayList<String>();
        for (URI volumeUri : volumes) {
            BlockObject blockObj = BlockObject.fetch(dbClient, volumeUri);
            _log.info("Block Obj {} , wwn {}", blockObj.getId(), blockObj.getWWN());
            XtremIOVolume xtremIOVolume = null;
            if (URIUtil.isType(volumeUri, Volume.class)) {
                xtremIOVolume = XtremIOProvUtils.isVolumeAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
            } else {
                if (URIUtil.isType(volumeUri, BlockSnapshot.class) && BlockObject.checkForRP(dbClient, volumeUri)) {
                    // If the BlockObject is a BlockSnapshot of type RP (bookmark), there will be no exported
                    // snapshot. In this case, a target volume will have been exported and the deviceLabel of
                    // the BlockSnapshot reflects the name of that target.
                    _log.info(String.format("Dealing with a RecoverPoint bookmark lun mapping.  Checking to see if volume %s is available on array.", blockObj.getDeviceLabel()));
                    xtremIOVolume = XtremIOProvUtils.isVolumeAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
                } else {
                    xtremIOVolume = XtremIOProvUtils.isSnapAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
                }
            }
            if (null != xtremIOVolume) {
                // I need lun map id and igName
                // if iGName is available in the above group:
                _log.info("Volume Details {}", xtremIOVolume.toString());
                _log.info("Volume lunMap details {}", xtremIOVolume.getLunMaps().toString());
                // Lun Maps to delete
                Set<String> lunMaps = new HashSet<String>();
                boolean removeInitiator = false;
                String volId = xtremIOVolume.getVolInfo().get(2);
                if (xtremIOVolume.getLunMaps().isEmpty()) {
                    // handle scenarios where volumes gets unexported already
                    _log.info("Volume  {} doesn't have any existing export available on Array, unexported already.", xtremIOVolume.toString());
                    exportMask.removeFromUserCreatedVolumes(blockObj);
                    exportMask.removeVolume(blockObj.getId());
                    continue;
                }
                for (List<Object> lunMapEntries : xtremIOVolume.getLunMaps()) {
                    @SuppressWarnings("unchecked") List<Object> igDetails = (List<Object>) lunMapEntries.get(0);
                    String igName = (String) igDetails.get(1);
                    // IG details is actually transforming to a double by default, even though
                    // its modeled as List<String>
                    // hence this logic
                    Double IgIdDouble = (Double) igDetails.get(2);
                    String igId = String.valueOf(IgIdDouble.intValue());
                    _log.info("IG Name: {} Id: {} found in Lun Map", igName, igId);
                    if (!igNames.contains(igName)) {
                        _log.info("Volume is associated with IG {} which is not in the removal list requested, ignoring..", igName);
                        continue;
                    }
                    /**
                     * i) If Cluster export:
                     * If there are additional initiators other than the requested ones (Single IG with all cluster
                     * initiators)
                     * - - - remove initiator from IG,
                     * - - - Note: If initiators are of RP (CTRL-13622), always delete LunMap.
                     * - ii) Host export:
                     * - - -- delete LunMap
                     */
                    boolean igHasOtherHostInitiatorsOfSameCluster = knownInitiatorsToIGMap.get(igName).size() > groupInitiatorsByIG.get(igName).size();
                    if (!initiatorsOfRP && clusterName != null && igHasOtherHostInitiatorsOfSameCluster) {
                        removeInitiator = true;
                    }
                    if (!removeInitiator) {
                        // delete LunMap
                        @SuppressWarnings("unchecked") List<Object> tgtGroupDetails = (List<Object>) lunMapEntries.get(1);
                        Double tgIdDouble = (Double) tgtGroupDetails.get(2);
                        String tgtid = String.valueOf(tgIdDouble.intValue());
                        String lunMapId = volId.concat(XtremIOConstants.UNDERSCORE).concat(igId).concat(XtremIOConstants.UNDERSCORE).concat(tgtid);
                        _log.info("LunMap Id {} Found associated with Volume {}", lunMapId, blockObj.getDeviceLabel());
                        lunMaps.add(lunMapId);
                    }
                }
                // there will be only one lun map always
                for (String lunMap : lunMaps) {
                    try {
                        client.deleteLunMap(lunMap, xioClusterName);
                    } catch (Exception e) {
                        failedVolumes.add(volumeUri.toString().concat(XtremIOConstants.DASH).concat(e.getMessage()));
                        _log.warn("Deletion of Lun Map {} failed}", lunMap, e);
                    }
                }
                // remove initiator from IG
                if (removeInitiator) {
                    _log.info("Removing requested intiators from IG instead of deleting LunMap" + " as the IG contains other Host's initiators belonging to same Cluster.");
                    ctx = new ExportMaskValidationContext();
                    ctx.setStorage(storage);
                    ctx.setExportMask(exportMask);
                    ctx.setBlockObjects(volumes, dbClient);
                    ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId()));
                    // DU validation when removing initiators
                    XtremIOExportMaskVolumesValidator volumeValidator = (XtremIOExportMaskVolumesValidator) validator.removeInitiators(ctx);
                    volumeValidator.setIgNames(groupInitiatorsByIG.keySet());
                    volumeValidator.validate();
                    List<Initiator> initiatorsToBeRemoved = new ArrayList<Initiator>();
                    // Get the context from the task completer, in case this is a rollback.
                    ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
                    if (context != null && context.getOperations() != null) {
                        ListIterator li = context.getOperations().listIterator(context.getOperations().size());
                        while (li.hasPrevious()) {
                            _log.info("Handling deleteExportMask as a result of rollback");
                            ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                            if (operation != null && XtremIOExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP.equals(operation.getOperation())) {
                                initiatorsToBeRemoved = (List<Initiator>) operation.getArgs().get(0);
                                _log.info("Removing initiators {} as part of rollback", Joiner.on(',').join(initiatorsToBeRemoved));
                            }
                        }
                    } else {
                        initiatorsToBeRemoved = initiators;
                    }
                    // Deleting the initiator automatically removes the initiator from lun map
                    for (Initiator initiator : initiatorsToBeRemoved) {
                        try {
                            // check if Initiator has already been deleted during previous volume processing
                            String initiatorName = initiator.getMappedInitiatorName(storage.getSerialNumber());
                            XtremIOInitiator initiatorObj = client.getInitiator(initiatorName, xioClusterName);
                            if (null != initiatorObj) {
                                client.deleteInitiator(initiatorName, xioClusterName);
                            } else {
                                _log.info("Initiator {} already deleted", initiatorName);
                            }
                        } catch (Exception e) {
                            failedIGs.add(initiator.getLabel().concat(XtremIOConstants.DASH).concat(e.getMessage()));
                            _log.warn("Removal of Initiator {} from IG failed", initiator.getLabel(), e);
                        }
                    }
                }
            } else {
                exportMask.removeFromUserCreatedVolumes(blockObj);
                exportMask.removeVolume(blockObj.getId());
            }
        }
        dbClient.updateObject(exportMask);
        if (!failedVolumes.isEmpty()) {
            String errMsg = "Export Operations failed for these volumes: ".concat(Joiner.on(", ").join(failedVolumes));
            ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
            taskCompleter.error(dbClient, serviceError);
            return;
        }
        if (!failedIGs.isEmpty()) {
            String errMsg = "Export Operations failed deleting these initiators: ".concat(Joiner.on(", ").join(failedIGs));
            ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
            taskCompleter.error(dbClient, serviceError);
            return;
        }
        // Clean IGs if empty
        deleteInitiatorGroup(groupInitiatorsByIG, client, xioClusterName);
        // delete IG Folder as well if IGs are empty
        deleteInitiatorGroupFolder(client, xioClusterName, clusterName, hostName, storage);
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error(String.format("Export Operations failed - maskName: %s", exportMask.getId().toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : XtremIOExportMaskInitiatorsValidator(com.emc.storageos.volumecontroller.impl.validators.xtremio.XtremIOExportMaskInitiatorsValidator) ArrayList(java.util.ArrayList) URI(java.net.URI) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOExportMaskVolumesValidator(com.emc.storageos.volumecontroller.impl.validators.xtremio.XtremIOExportMaskVolumesValidator) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ListIterator(java.util.ListIterator) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 12 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method resyncSingleVolumeSnapshot.

@Override
public void resyncSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    Volume sourceVol = null;
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        sourceVol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        client.refreshSnapshotFromVolume(clusterName, sourceVol.getDeviceLabel(), snapshotObj.getDeviceLabel());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot resync failed", e);
        ServiceError serviceError = null;
        if (e instanceof XtremIOApiException) {
            XtremIOApiException xioException = (XtremIOApiException) e;
            // check for specific error key for snapshot size mismatch with source volume.
            if (null != xioException.getMessage() && xioException.getMessage().contains(XtremIOConstants.SNAP_SIZE_MISMATCH_ERROR_KEY)) {
                String restoreFailureMsg = String.format("snapshot size mismatch with the source volume size %s. Use expand snapshot feature to increase the snapshot size.", sourceVol.getProvisionedCapacity());
                serviceError = DeviceControllerErrors.xtremio.resyncSnapshotFailureSourceSizeMismatch(restoreFailureMsg);
            }
        } else {
            serviceError = DeviceControllerException.errors.jobFailed(e);
        }
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 13 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method restoreSingleVolumeSnapshot.

@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    Volume sourceVol = null;
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        sourceVol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        client.restoreVolumeFromSnapshot(clusterName, sourceVol.getDeviceLabel(), snapshotObj.getDeviceLabel());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot restore failed", e);
        ServiceError serviceError = null;
        if (e instanceof XtremIOApiException) {
            XtremIOApiException xioException = (XtremIOApiException) e;
            // check for specific error key for snapshot size mismatch with source volume.
            if (null != xioException.getMessage() && xioException.getMessage().contains(XtremIOConstants.SNAP_SIZE_MISMATCH_ERROR_KEY)) {
                String restoreFailureMsg = String.format("snapshot size mismatch with the source volume size %s. Use expand snapshot feature to increase the snapshot size.", sourceVol.getProvisionedCapacity());
                serviceError = DeviceControllerErrors.xtremio.restoreSnapshotFailureSourceSizeMismatch(restoreFailureMsg);
            }
        } else {
            serviceError = DeviceControllerException.errors.jobFailed(e);
        }
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 14 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method createSingleVolumeSnapshot.

@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockSnapshot snap = dbClient.queryObject(BlockSnapshot.class, snapshot);
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        String generatedLabel = nameGenerator.generate("", snap.getLabel(), "", '_', XtremIOConstants.XTREMIO_MAX_VOL_LENGTH);
        snap.setLabel(generatedLabel);
        XtremIOVolume createdSnap;
        if (client.isVersion2()) {
            createdSnap = createV2Snapshot(client, storage, xioClusterName, snap, generatedLabel, readOnly, taskCompleter);
        } else {
            createdSnap = createV1Snapshot(client, storage, snap, generatedLabel, readOnly, taskCompleter);
        }
        if (createdSnap != null) {
            processSnapshot(createdSnap, snap, storage);
        }
        dbClient.updateObject(snap);
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot creation failed", e);
        snap.setInactive(true);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 15 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method deleteGroupSnapshots.

@Override
public void deleteGroupSnapshots(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        String rgName = snapshotObj.getReplicationGroupInstance();
        if (NullColumnValueGetter.isNotNullValue(rgName) && null != XtremIOProvUtils.isSnapsetAvailableInArray(client, rgName, clusterName)) {
            client.deleteSnapshotSet(rgName, clusterName);
        }
        // Set inactive=true for all snapshots in the snap
        List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, dbClient);
        for (BlockSnapshot snap : snapshots) {
            snap.setIsSyncActive(false);
            snap.setInactive(true);
            dbClient.updateObject(snap);
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot deletion failed", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

XtremIOClient (com.emc.storageos.xtremio.restapi.XtremIOClient)38 XtremIOApiException (com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)20 XtremIOVolume (com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume)15 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)13 URI (java.net.URI)13 ArrayList (java.util.ArrayList)12 Initiator (com.emc.storageos.db.client.model.Initiator)11 XtremIOInitiator (com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator)11 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)9 BlockObject (com.emc.storageos.db.client.model.BlockObject)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)8 Volume (com.emc.storageos.db.client.model.Volume)7 XtremIOConsistencyGroup (com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 ExportMask (com.emc.storageos.db.client.model.ExportMask)5 ExportOperationContext (com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext)5 List (java.util.List)5