Search in sources :

Example 71 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeExportOperations method removeInitiators.

@Override
public void removeInitiators(StorageSystem storage, URI exportMask, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} removeInitiators START...", storage.getSerialNumber());
    ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMask);
    if (mask == null || mask.getInactive()) {
        _logger.error(String.format("The exportMask %s is invalid.", exportMask));
        throw DeviceControllerException.exceptions.invalidObjectNull();
    }
    boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
    if (isRollback) {
        List<Initiator> addedInitiators = 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) {
            _logger.info("Handling removeInitiators as a result of rollback");
            ListIterator li = context.getOperations().listIterator(context.getOperations().size());
            while (li.hasPrevious()) {
                ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                if (operation != null && VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST.equals(operation.getOperation())) {
                    addedInitiators = (List<Initiator>) operation.getArgs().get(0);
                    _logger.info("Removing initiators {} as part of rollback", Joiner.on(',').join(addedInitiators));
                }
            }
        }
        // Update the initiators in the task completer such that we update the export mask/group correctly
        for (Initiator initiator : initiators) {
            if (addedInitiators == null || !addedInitiators.contains(initiator)) {
                ((ExportMaskRemoveInitiatorCompleter) taskCompleter).removeInitiator(initiator.getId());
            }
        }
        initiators = addedInitiators;
        if (initiators == null || initiators.isEmpty()) {
            _logger.info("There was no context found for add initiator. So there is nothing to rollback.");
            taskCompleter.ready(_dbClient);
            return;
        }
    }
    StringSet initiatorsInMask = mask.getInitiators();
    List<Initiator> initiatorToBeRemoved = new ArrayList<>();
    for (Initiator initiator : initiators) {
        if (initiatorsInMask.contains(initiator.getId().toString())) {
            initiatorToBeRemoved.add(initiator);
        }
    }
    try {
        VNXeApiClient apiClient = getVnxeClient(storage);
        List<Initiator> allInitiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        String vnxeHostId = getHostIdFromInitiators(allInitiators, apiClient);
        if (vnxeHostId != null) {
            List<VNXeHostInitiator> vnxeInitiators = apiClient.getInitiatorsByHostId(vnxeHostId);
            // initiators is a subset of allInitiators
            Map<Initiator, VNXeHostInitiator> vnxeInitiatorsToBeRemoved = prepareInitiators(initiatorToBeRemoved);
            Set<String> initiatorIds = new HashSet<String>();
            for (VNXeHostInitiator vnxeInit : vnxeInitiators) {
                initiatorIds.add(vnxeInit.getInitiatorId());
            }
            Set<String> initiatorsToBeRemoved = new HashSet<String>();
            for (VNXeHostInitiator vnxeInit : vnxeInitiatorsToBeRemoved.values()) {
                String initiatorId = vnxeInit.getId();
                if (initiatorIds.remove(initiatorId)) {
                    initiatorsToBeRemoved.add(initiatorId);
                }
            }
            ExportMaskValidationContext ctx = new ExportMaskValidationContext();
            ctx.setStorage(storage);
            ctx.setExportMask(mask);
            ctx.setBlockObjects(volumeURIList, _dbClient);
            // Allow exceptions to be thrown when not rolling back
            ctx.setAllowExceptions(!isRollback);
            AbstractVNXeValidator removeInitiatorsValidator = (AbstractVNXeValidator) validator.removeInitiators(ctx);
            removeInitiatorsValidator.setHostId(vnxeHostId);
            removeInitiatorsValidator.validate();
            // 3. shared initiators, but all export masks have same set of initiators
            if (!isRollback) {
                boolean hasSharedInitiator = false;
                for (Initiator initiator : initiatorToBeRemoved) {
                    if (ExportUtils.isInitiatorSharedByMasks(_dbClient, mask, initiator.getId())) {
                        hasSharedInitiator = true;
                        break;
                    }
                }
                if (hasSharedInitiator) {
                    validateAllMasks(_dbClient, mask, apiClient, vnxeHostId);
                }
            }
        }
        List<String> initiatorIdList = new ArrayList<>();
        for (Initiator initiator : initiatorToBeRemoved) {
            _logger.info("Processing initiator {}", initiator.getLabel());
            if (vnxeHostId != null) {
                String initiatorId = initiator.getInitiatorPort();
                if (Protocol.FC.name().equals(initiator.getProtocol())) {
                    initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
                }
                initiatorIdList.add(initiatorId);
            }
            mask.removeFromExistingInitiators(initiator);
            mask.removeFromUserCreatedInitiators(initiator);
        }
        if (!initiatorIdList.isEmpty()) {
            apiClient.deleteInitiators(initiatorIdList);
        }
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Problem in removeInitiators: ", e);
        ServiceError serviceError = DeviceControllerErrors.vnxe.jobFailed("removeInitiator", e.getMessage());
        taskCompleter.error(_dbClient, serviceError);
    }
    _logger.info("{} removeInitiators END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportMaskRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveInitiatorCompleter) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) AbstractVNXeValidator(com.emc.storageos.volumecontroller.impl.validators.vnxe.AbstractVNXeValidator) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) StringSet(com.emc.storageos.db.client.model.StringSet) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) HashSet(java.util.HashSet)

Example 72 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeExportOperations method deleteExportMask.

@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} deleteExportMask START...", storage.getSerialNumber());
    boolean removeLastInitiator = false;
    List<URI> volumesToBeUnmapped = new ArrayList<URI>();
    try {
        _logger.info("Export mask id: {}", exportMaskUri);
        if (volumeURIList != null) {
            _logger.info("deleteExportMask: volumes:  {}", Joiner.on(',').join(volumeURIList));
        }
        if (targetURIList != null) {
            _logger.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        }
        if (initiatorList != null) {
            if (!initiatorList.isEmpty()) {
                removeLastInitiator = true;
                _logger.info("deleteExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
            }
        }
        // Get the context from the task completer, in case this is a rollback.
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        if (isRollback) {
            List<URI> addedVolumes = new ArrayList<URI>();
            ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
            if (context != null && context.getOperations() != null) {
                _logger.info("Handling deleteExportMask as a result of rollback");
                ListIterator li = context.getOperations().listIterator(context.getOperations().size());
                while (li.hasPrevious()) {
                    ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                    if (operation != null && VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT.equals(operation.getOperation())) {
                        addedVolumes = (List<URI>) operation.getArgs().get(0);
                        _logger.info("Removing volumes {} as part of rollback", Joiner.on(',').join(addedVolumes));
                    }
                }
            }
            volumesToBeUnmapped = addedVolumes;
            if (volumesToBeUnmapped == null || volumesToBeUnmapped.isEmpty()) {
                _logger.info("There was no context found for add volumes. So there is nothing to rollback.");
                taskCompleter.ready(_dbClient);
                return;
            }
        } else {
            volumesToBeUnmapped = volumeURIList;
        }
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
        if (exportMask == null || exportMask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
        }
        if (initiatorList.isEmpty()) {
            initiatorList = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        }
        VNXeApiClient apiClient = getVnxeClient(storage);
        String hostId = getHostIdFromInitiators(initiatorList, apiClient);
        Set<String> allExportedVolumes = new HashSet<>();
        if (hostId != null) {
            ExportMaskValidationContext ctx = new ExportMaskValidationContext();
            ctx.setStorage(storage);
            ctx.setExportMask(exportMask);
            ctx.setBlockObjects(volumeURIList, _dbClient);
            ctx.setInitiators(initiatorList);
            // Allow exceptions to be thrown when not rolling back
            ctx.setAllowExceptions(!isRollback);
            AbstractVNXeValidator deleteMaskValidator = (AbstractVNXeValidator) validator.exportMaskDelete(ctx);
            deleteMaskValidator.setHostId(hostId);
            deleteMaskValidator.validate();
            if (removeLastInitiator) {
                ctx = new ExportMaskValidationContext();
                ctx.setStorage(storage);
                ctx.setExportMask(exportMask);
                ctx.setBlockObjects(volumeURIList, _dbClient);
                ctx.setAllowExceptions(!isRollback);
                AbstractVNXeValidator removeInitiatorsValidator = (AbstractVNXeValidator) validator.removeInitiators(ctx);
                removeInitiatorsValidator.setHostId(hostId);
                removeInitiatorsValidator.validate();
                boolean hasSharedInitiator = false;
                for (String strUri : exportMask.getInitiators()) {
                    if (ExportUtils.isInitiatorSharedByMasks(_dbClient, exportMask, URI.create(strUri))) {
                        hasSharedInitiator = true;
                        _logger.info("Initiators are used by multiple export masks");
                        break;
                    }
                }
                if (hasSharedInitiator) {
                    // if any initiator is shared, all initiators have to be shared, and each mask should have same set of initiators
                    // Otherwise, removing initiator will not be allowed, user can delete individual export mask
                    Collection<ExportMask> masksWithSharedInitiators = validateAllMasks(_dbClient, exportMask, apiClient, hostId);
                    _logger.info("Masks use the same initiators {}", Joiner.on(", ").join(Collections2.transform(masksWithSharedInitiators, CommonTransformerFunctions.fctnDataObjectToForDisplay())));
                    // need to unexport all volumes of all export masks
                    // except shared export co-exists with exclusive export, don't touch exclusive export
                    // in case of multiple shared exports (e.g., with different projects), all exported LUNs will be unmapped, regardless exclusive export
                    String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
                    if (ExportGroupType.Cluster.name().equals(exportType)) {
                        Iterator<ExportMask> maskIter = masksWithSharedInitiators.iterator();
                        while (maskIter.hasNext()) {
                            ExportMask mask = maskIter.next();
                            if (!ExportGroupType.Cluster.name().equals(ExportMaskUtils.getExportType(_dbClient, mask))) {
                                _logger.info("Ignore exclusive export {}", mask.getMaskName());
                                maskIter.remove();
                            }
                        }
                    }
                    volumesToBeUnmapped.addAll(getExportedVolumes(_dbClient, storage.getId(), masksWithSharedInitiators));
                }
            }
            allExportedVolumes = ExportUtils.getAllLUNsForHost(_dbClient, exportMask);
        }
        String opId = taskCompleter.getOpId();
        Set<String> processedCGs = new HashSet<String>();
        for (URI volUri : volumesToBeUnmapped) {
            if (hostId != null) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
                String nativeId = blockObject.getNativeId();
                String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
                if (cgName != null && !processedCGs.contains(cgName)) {
                    processedCGs.add(cgName);
                    VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
                }
                if (URIUtil.isType(volUri, Volume.class)) {
                    apiClient.unexportLun(hostId, nativeId);
                } else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
                    if (BlockObject.checkForRP(_dbClient, volUri)) {
                        _logger.info(String.format("BlockObject %s is a RecoverPoint bookmark. Un-exporting associated lun %s instead of snap.", volUri, nativeId));
                        apiClient.unexportLun(hostId, nativeId);
                    } else {
                        apiClient.unexportSnap(hostId, nativeId);
                        setSnapWWN(apiClient, blockObject, nativeId);
                    }
                }
            }
            // update the exportMask object
            exportMask.removeVolume(volUri);
        }
        // check if there are LUNs on array
        // initiator will not be able to removed if there are LUNs belongs to other masks (if initiator is shared), or unknown to ViPR
        Set<String> lunIds = new HashSet<>();
        if (hostId != null) {
            lunIds = apiClient.getHostLUNIds(hostId);
            _logger.info("Mapped resources {}", Joiner.on(", ").join(lunIds));
        }
        boolean hasLUN = lunIds.isEmpty() ? false : true;
        lunIds.removeAll(allExportedVolumes);
        boolean hasUnknownLUN = lunIds.isEmpty() ? false : true;
        _logger.info("Export mask deletion - hasLUN {}, hasUnknownLUN {}", hasLUN, hasUnknownLUN);
        for (Initiator initiator : initiatorList) {
            _logger.info("Processing initiator {}", initiator.getLabel());
            if (hostId != null && (!hasLUN || (!hasUnknownLUN && !ExportUtils.isInitiatorSharedByMasks(_dbClient, exportMask, initiator.getId())))) {
                String initiatorId = initiator.getInitiatorPort();
                if (Protocol.FC.name().equals(initiator.getProtocol())) {
                    initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
                }
                try {
                    if (hasLUN) {
                        // move and delete initiator
                        apiClient.deleteInitiators(new ArrayList<String>(Arrays.asList(initiatorId)));
                    } else {
                        apiClient.deleteInitiator(initiatorId);
                    }
                } catch (VNXeException e) {
                    _logger.warn("Error on deleting initiator: {}", e.getMessage());
                }
            }
            exportMask.removeFromExistingInitiators(initiator);
            exportMask.removeFromUserCreatedInitiators(initiator);
        }
        _dbClient.updateObject(exportMask);
        if (hostId != null) {
            List<VNXeHostInitiator> vnxeInitiators = apiClient.getInitiatorsByHostId(hostId);
            if (vnxeInitiators.isEmpty()) {
                Set<String> vnxeLUNIds = apiClient.getHostLUNIds(hostId);
                if ((vnxeLUNIds.isEmpty())) {
                    try {
                        apiClient.deleteHost(hostId);
                    } catch (VNXeException e) {
                        _logger.warn("Error on deleting host: {}", e.getMessage());
                    }
                }
            }
        }
        List<ExportGroup> exportGroups = ExportMaskUtils.getExportGroups(_dbClient, exportMask);
        if (exportGroups != null) {
            // Remove the mask references in the export group
            for (ExportGroup exportGroup : exportGroups) {
                // Remove this mask from the export group
                exportGroup.removeExportMask(exportMask.getId().toString());
            }
            // Update all of the export groups in the DB
            _dbClient.updateObject(exportGroups);
        }
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Unexpected error: deleteExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("deleteExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _logger.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ListIterator(java.util.ListIterator) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) AbstractVNXeValidator(com.emc.storageos.volumecontroller.impl.validators.vnxe.AbstractVNXeValidator) VNXeException(com.emc.storageos.vnxe.VNXeException)

Example 73 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeExportOperations method createExportMask.

@Override
public void createExportMask(StorageSystem storage, URI exportMask, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} createExportMask START...", storage.getSerialNumber());
    VNXeApiClient apiClient = getVnxeClient(storage);
    List<URI> mappedVolumes = new ArrayList<URI>();
    ExportMask mask = null;
    try {
        _logger.info("createExportMask: Export mask id: {}", exportMask);
        _logger.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        _logger.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        _logger.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        ExportOperationContext context = new VNXeExportOperationContext();
        taskCompleter.updateWorkflowStepContext(context);
        mask = _dbClient.queryObject(ExportMask.class, exportMask);
        if (mask == null || mask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMask);
        }
        Set<String> processedCGs = new HashSet<String>();
        Collection<VNXeHostInitiator> initiators = prepareInitiators(initiatorList).values();
        VNXeBase host = apiClient.prepareHostsForExport(initiators);
        validateInitiators(_dbClient, initiatorList, apiClient, host.getId());
        String opId = taskCompleter.getOpId();
        for (VolumeURIHLU volURIHLU : volumeURIHLUs) {
            URI volUri = volURIHLU.getVolumeURI();
            String hlu = volURIHLU.getHLU();
            _logger.info(String.format("hlu %s", hlu));
            BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
            String nativeId = blockObject.getNativeId();
            VNXeExportResult result = null;
            Integer newhlu = -1;
            if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
                newhlu = Integer.valueOf(hlu);
            }
            String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
            if (cgName != null && !processedCGs.contains(cgName)) {
                processedCGs.add(cgName);
                VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
            }
            if (URIUtil.isType(volUri, Volume.class)) {
                result = apiClient.exportLun(host, nativeId, newhlu);
                mask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
            } else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
                if (BlockObject.checkForRP(_dbClient, volUri)) {
                    _logger.info(String.format("BlockObject %s is a RecoverPoint bookmark.  Exporting associated lun %s instead of snap.", volUri, nativeId));
                    result = apiClient.exportLun(host, nativeId, newhlu);
                } else {
                    result = apiClient.exportSnap(host, nativeId, newhlu);
                    setSnapWWN(apiClient, blockObject, nativeId);
                }
                mask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
            }
        }
        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
        mask.setNativeId(host.getId());
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Unexpected error: createExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _logger.info("{} createExportMask END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 74 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeExportOperations method refreshExportMask.

@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
    _logger.info("Refreshing export mask {}", mask.getMaskName());
    try {
        VNXeApiClient apiClient = getVnxeClient(storage);
        List<Initiator> initiatorList = ExportUtils.getExportMaskInitiators(mask, _dbClient);
        String vnxeHostId = getHostIdFromInitiators(initiatorList, apiClient);
        if (vnxeHostId != null) {
            VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
            if (vnxeHost != null) {
                Map<String, Integer> discoveredVolumes = apiClient.getHostLUNWWNs(vnxeHostId);
                // Clear the existing volumes to update with the latest info
                if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
                    mask.getExistingVolumes().clear();
                }
                // COP-27296 fix
                if (null == mask.getUserAddedVolumes()) {
                    mask.setUserAddedVolumes(new StringMap());
                }
                Set<String> existingVolumes = Sets.difference(discoveredVolumes.keySet(), mask.getUserAddedVolumes().keySet());
                _logger.info(String.format("VNXe discovered volumes: {%s}%n", Joiner.on(',').join(discoveredVolumes.keySet())));
                _logger.info(String.format("%nVNXe existing volumes : {%s}%n", Joiner.on(',').join(existingVolumes)));
                for (String lunId : existingVolumes) {
                    mask.addToExistingVolumesIfAbsent(lunId, discoveredVolumes.get(lunId).toString());
                }
                // Update user added volume's HLU information in ExportMask and ExportGroup
                ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, _dbClient);
                _dbClient.updateObject(mask);
            }
        }
    } catch (Exception e) {
        _logger.warn("Error on refreshing export mask {}", mask.getMaskName());
    }
    return mask;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 75 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeExpandVolumeJob method updateStatus.

/**
 * Called to update the job status when the volume expand job completes.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        URI volumeId = getTaskCompleter().getId();
        Volume volumeObj = dbClient.queryObject(Volume.class, volumeId);
        // If terminal state update storage pool capacity
        if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
            VNXeJob.updateStoragePoolCapacity(dbClient, vnxeApiClient, volumeObj.getPool(), Arrays.asList(volumeObj.getId().toString()));
        }
        if (_status == JobStatus.SUCCESS && volumeObj != null) {
            updateVolume(volumeObj, dbClient, logMsgBuilder, vnxeApiClient);
        } else if (_status == JobStatus.FAILED && volumeObj != null) {
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to expand volume: %s", opId, volumeId.toString()));
        } else {
            logMsgBuilder.append(String.format("The volume: %s is not found anymore", volumeId));
        }
        _logger.info(logMsgBuilder.toString());
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeExpandVolumeJob", e);
        setErrorStatus("Encountered an internal error during expand volume job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) Volume(com.emc.storageos.db.client.model.Volume) URI(java.net.URI)

Aggregations

VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)123 VNXeException (com.emc.storageos.vnxe.VNXeException)79 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)66 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)55 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)48 ControllerException (com.emc.storageos.volumecontroller.ControllerException)44 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)40 URI (java.net.URI)37 ArrayList (java.util.ArrayList)34 FileShare (com.emc.storageos.db.client.model.FileShare)33 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)33 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)30 Snapshot (com.emc.storageos.db.client.model.Snapshot)27 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)24 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)23 DbClient (com.emc.storageos.db.client.DbClient)21 Volume (com.emc.storageos.db.client.model.Volume)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 FileExport (com.emc.storageos.db.client.model.FileExport)14 HashMap (java.util.HashMap)14