Search in sources :

Example 21 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSExportOperations method refreshExportMask.

@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
    try {
        HDSApiClient client = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportManager = client.getHDSApiExportManager();
        String systemObjectID = HDSUtils.getSystemObjectID(storage);
        if (null != mask.getDeviceDataMap() && !mask.getDeviceDataMap().isEmpty()) {
            Set<String> hsdList = mask.getDeviceDataMap().keySet();
            StringBuilder builder = new StringBuilder();
            Set<String> discoveredInitiators = new HashSet<String>();
            String maskName = null;
            Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
            for (String hsdObjectIdFromDb : hsdList) {
                HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
                if (null == hsd) {
                    // If the HSD is removed using non-ViPR, update ViPR DB.
                    mask.getDeviceDataMap().remove(hsdObjectIdFromDb);
                    continue;
                }
                maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
                // Get volumes and initiators for the masking instance
                discoveredVolumes.putAll(HDSUtils.getVolumesFromHSD(hsd, storage));
                discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
            }
            Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
            Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
            builder.append(String.format("%nXM object: %s I{%s} V:{%s}%n", maskName, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
            builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", maskName, Joiner.on(',').join(discoveredInitiators), Joiner.on(',').join(discoveredVolumes.keySet())));
            List<Initiator> initiatorList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(discoveredInitiators)) {
                for (String port : discoveredInitiators) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
                    if (existingInitiator != null && !existingInitiator.getInactive()) {
                        initiatorList.add(existingInitiator);
                    }
                }
            }
            mask.addInitiators(initiatorList);
            dbClient.updateObject(mask);
            List<String> initiatorsToAddToExisting = new ArrayList<String>();
            List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
            /**
             * For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
             * add them to user added and initiators list, otherwise add to existing list.
             */
            for (String port : discoveredInitiators) {
                String normalizedPort = Initiator.normalizePort(port);
                if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
                    // Don't add additional initiator to initiators list if it belongs to different host/cluster
                    if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                        log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
                        initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                    } else {
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            /**
             * Get the existing initiators from the mask and remove the non-discovered ports because
             * they are not discovered and are stale.
             *
             * If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
             * initiators has to get added to user Added and initiators list, and removed from existing list.
             */
            List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
            if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
                for (String existingInitiatorStr : mask.getExistingInitiators()) {
                    if (!discoveredInitiators.contains(existingInitiatorStr)) {
                        initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                    } else {
                        Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), dbClient);
                        if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                            log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
                            initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                            initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                        }
                    }
                }
            }
            /**
             * Get all the initiators from the mask and remove all the ViPR discovered ports.
             * The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
             * but has to be moved to existing list.
             */
            List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
            if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
                initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
                for (String port : discoveredInitiators) {
                    String normalizedPort = Initiator.normalizePort(port);
                    Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
                    if (initiatorDiscoveredInViPR != null) {
                        initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
                    } else if (!mask.hasExistingInitiator(normalizedPort)) {
                        log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
            boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.isEmpty();
            // Check the volumes and update the lists as necessary
            Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
            boolean addVolumes = !volumesToAdd.isEmpty();
            boolean removeVolumes = false;
            List<String> volumesToRemove = new ArrayList<String>();
            // if the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
            for (String wwn : discoveredVolumes.keySet()) {
                if (mask.hasExistingVolume(wwn)) {
                    URIQueryResultList volumeList = new URIQueryResultList();
                    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
                    if (volumeList.iterator().hasNext()) {
                        URI volumeURI = volumeList.iterator().next();
                        if (mask.hasUserCreatedVolume(volumeURI)) {
                            builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
                            volumesToRemove.add(wwn);
                        }
                    }
                }
            }
            if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
                volumesToRemove.addAll(mask.getExistingVolumes().keySet());
                volumesToRemove.removeAll(discoveredVolumes.keySet());
                removeVolumes = !volumesToRemove.isEmpty();
            }
            // Update user added volume's HLU information in ExportMask and ExportGroup
            ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, dbClient);
            builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
            builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
            builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
            // Any changes indicated, then update the mask and persist it
            if (addInitiators || removeInitiators || addVolumes || removeVolumes) {
                builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
                if (!initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty()) {
                    mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
                    mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
                }
                List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorsToAddToUserAddedAndInitiatorList, dbClient);
                mask.addToUserCreatedInitiators(userAddedInitiators);
                builder.append(String.format("XM refresh: %s user added initiators; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(userAddedInitiators), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
                mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
                mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
                mask.removeFromExistingVolumes(volumesToRemove);
                mask.addToExistingVolumesIfAbsent(volumesToAdd);
                ExportMaskUtils.sanitizeExportMaskContainers(dbClient, mask);
                builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
                dbClient.updateObject(mask);
            } else {
                builder.append("XM refresh: There are no changes to the mask\n");
            }
            _networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
            log.info(builder.toString());
        }
    } catch (Exception e) {
        log.error("Error when attempting to query HostStorageDomain information", e);
        throw HDSException.exceptions.refreshExistingMaskFailure(mask.getLabel());
    }
    return mask;
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Initiator(com.emc.storageos.db.client.model.Initiator) HashSet(java.util.HashSet)

Example 22 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSExportOperations method updateStorageGroupPolicyAndLimits.

@Override
public void updateStorageGroupPolicyAndLimits(StorageSystem storage, ExportMask exportMask, List<URI> volumeURIs, VirtualPool newVirtualPool, boolean rollback, TaskCompleter taskCompleter) throws Exception {
    String message = rollback ? ("updateAutoTieringPolicy" + "(rollback)") : ("updateAutoTieringPolicy");
    log.info("{} {} START...", storage.getSerialNumber(), message);
    log.info("{} : volumeURIs: {}", message, volumeURIs);
    try {
        String newPolicyName = ControllerUtils.getFastPolicyNameFromVirtualPool(dbClient, storage, newVirtualPool);
        log.info("{} : AutoTieringPolicy: {}", message, newPolicyName);
        List<Volume> volumes = dbClient.queryObject(Volume.class, volumeURIs);
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        String systemObjectID = HDSUtils.getSystemObjectID(storage);
        for (Volume volume : volumes) {
            String luObjectId = HDSUtils.getLogicalUnitObjectId(volume.getNativeId(), storage);
            LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(systemObjectID, luObjectId);
            if (null != logicalUnit && null != logicalUnit.getLdevList() && !logicalUnit.getLdevList().isEmpty()) {
                Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
                if (ldevItr.hasNext()) {
                    LDEV ldev = ldevItr.next();
                    hdsApiClient.getLogicalUnitInfo(systemObjectID, luObjectId);
                    String tieringPolicyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), dbClient);
                    String policId = HitachiTieringPolicy.getPolicy(tieringPolicyName.replaceAll(HDSConstants.SLASH_OPERATOR, HDSConstants.UNDERSCORE_OPERATOR)).getKey();
                    String asyncMessageId = hdsApiClient.modifyThinVolumeTieringPolicy(systemObjectID, luObjectId, ldev.getObjectID(), policId, storage.getModel());
                    if (null != asyncMessageId) {
                        HDSJob modifyHDSJob = new HDSModifyVolumeJob(asyncMessageId, volume.getStorageController(), taskCompleter, HDSModifyVolumeJob.VOLUME_VPOOL_CHANGE_JOB);
                        ControllerServiceImpl.enqueueJob(new QueueJob(modifyHDSJob));
                    } else {
                        throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the modify volume call");
                    }
                }
            }
        }
    } catch (Exception e) {
        String errMsg = String.format("An error occurred while updating Auto-tiering policy for Volumes %s", volumeURIs);
        log.error(errMsg, e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(e.getMessage(), e);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} {} updateAutoTieringPolicy END...", storage.getSerialNumber(), message);
}
Also used : HDSModifyVolumeJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSModifyVolumeJob) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HDSJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob) Volume(com.emc.storageos.db.client.model.Volume) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) LDEV(com.emc.storageos.hds.model.LDEV) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException)

Example 23 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSExportOperations method createExportMask.

/**
 * Creates a ExportMask with the given initiators & volumes.
 *
 * Below are the steps to follow to create an Export Mask on Hitachi array.
 * Step 1: Register host with initiators.
 * Step 2: Based on the targetport type, create a Host Storage Domain.
 * Step 3: Add WWN/ISCSI names to the Host Storage Domain.
 * Step 4: Add Luns to the HostStorageDomain created in step 2.
 */
@Override
public void createExportMask(StorageSystem storage, URI exportMaskId, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} createExportMask START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    ExportMask exportMask = null;
    List<HostStorageDomain> hsdsWithInitiators = null;
    List<HostStorageDomain> hsdsToCreate = null;
    try {
        log.info("createExportMask: Export mask id :{}", exportMaskId);
        log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        systemObjectID = HDSUtils.getSystemObjectID(storage);
        exportMask = dbClient.queryObject(ExportMask.class, exportMaskId);
        // Check whether host is already registered or not. If host is not
        // registered, add the host.
        registerHostsWithInitiators(initiatorList, hdsApiClient);
        List<StoragePort> storagePorts = dbClient.queryObject(StoragePort.class, targetURIList, true);
        if (checkIfMixedTargetPortTypeSelected(storagePorts)) {
            log.error("Unsupported Host as it has both FC & iSCSI Initiators");
            throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
        }
        if (null != targetURIList && !targetURIList.isEmpty()) {
            String hostName = getHostNameForInitiators(initiatorList);
            String hostMode = null, hostModeOption = null;
            Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiatorList);
            if (hostModeInfo != null) {
                hostMode = hostModeInfo.first;
                hostModeOption = hostModeInfo.second;
            }
            hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, targetURIList, hostName, exportMask, hostModeInfo, systemObjectID);
            // Step 1: Create all HSD's using batch operation.
            List<HostStorageDomain> hsdResponseList = hdsApiClient.getHDSBatchApiExportManager().addHostStorageDomains(systemObjectID, hsdsToCreate, storage.getModel());
            if (null == hsdResponseList || hsdResponseList.isEmpty()) {
                log.error("Batch HSD creation failed. Aborting operation...");
                throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
            }
            // Step 2: Add initiators to all HSD's.
            hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, storagePorts, initiatorList, storage.getModel());
            // Step 3: Add volumes to all HSD's.
            List<Path> allHSDPaths = executeBatchHSDAddVolumesCommand(hdsApiClient, systemObjectID, hsdsWithInitiators, volumeURIHLUs, storage.getModel());
            if (null != allHSDPaths && !allHSDPaths.isEmpty()) {
                updateExportMaskDetailInDB(hsdsWithInitiators, allHSDPaths, exportMask, storage, volumeURIHLUs);
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception ex) {
        // initiators/volumes.
        try {
            log.info("Exception occurred while processing exportmask due to: {}", ex.getMessage());
            if (null != hsdsWithInitiators && !hsdsWithInitiators.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, hsdsWithInitiators, storage.getModel());
            } else {
                if (null != hsdsToCreate && !hsdsToCreate.isEmpty()) {
                    List<HostStorageDomain> allHSDs = hdsApiClient.getHDSApiExportManager().getHostStorageDomains(systemObjectID);
                    List<HostStorageDomain> partialHSDListToRemove = getPartialHSDListToDelete(allHSDs, hsdsToCreate);
                    hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, partialHSDListToRemove, storage.getModel());
                }
            }
            log.error(String.format("createExportMask failed - maskName: %s", exportMaskId.toString()), ex);
        } catch (Exception ex1) {
            log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
        } finally {
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(ex);
            taskCompleter.error(dbClient, serviceError);
        }
    }
    log.info("{} createExportMask END...", storage.getSerialNumber());
}
Also used : Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) StoragePort(com.emc.storageos.db.client.model.StoragePort) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 24 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSExportOperations method deleteExportMask.

@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} deleteExportMask START...", storage.getSerialNumber());
    List<HostStorageDomain> hsdToDeleteList = new ArrayList<HostStorageDomain>();
    try {
        log.info("deleteExportMask: Export mask id: {}", exportMaskURI);
        if (volumeURIList != null) {
            log.info("deleteExportMask: volumes:  {}", Joiner.on(',').join(volumeURIList));
        }
        if (targetURIList != null) {
            log.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        }
        if (initiatorList != null) {
            log.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());
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        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);
        AbstractHDSValidator deleteMaskValidator = (AbstractHDSValidator) validator.exportMaskDelete(ctx);
        deleteMaskValidator.validate();
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        String systemObjectId = HDSUtils.getSystemObjectID(storage);
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
            Set<String> hsdObjectIdList = deviceDataMap.keySet();
            for (String hsdObjectIdFromDb : hsdObjectIdList) {
                HostStorageDomain hsdObj = exportMgr.getHostStorageDomain(systemObjectId, hsdObjectIdFromDb);
                if (null != hsdObj) {
                    hsdToDeleteList.add(hsdObj);
                }
            }
            if (!hsdToDeleteList.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectId, hsdToDeleteList, storage.getModel());
            }
            // By this time, we have removed all HSD's created in this mask.
            taskCompleter.ready(dbClient);
        } else {
            String message = String.format("ExportMask %s does not have a configured HSD's, " + "indicating that this export may not have been created " + "successfully. Marking the delete operation ready.", exportMaskURI.toString());
            log.info(message);
            taskCompleter.ready(dbClient);
            return;
        }
    } catch (Exception e) {
        log.error("Unexpected error: deleteExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("deleteExportMask", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
    log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) AbstractHDSValidator(com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain)

Example 25 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSExportOperations method addVolumes.

@Override
public void addVolumes(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} addVolumes START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    try {
        log.info("addVolumes: Export mask id: {}", exportMaskURI);
        log.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        if (initiatorList != null) {
            log.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
        }
        hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        systemObjectID = HDSUtils.getSystemObjectID(storage);
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        Set<String> hsdList = deviceDataMap.keySet();
        if (null == hsdList || hsdList.isEmpty()) {
            throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
        }
        if (null != exportMask && !exportMask.getInactive() && !hsdList.isEmpty()) {
            List<Path> pathList = new ArrayList<Path>();
            for (String hsdObjectID : hsdList) {
                // Query the provider to see whether the HSD exists or not.
                HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectID);
                if (null != hsd) {
                    Map<String, String> volumeLunMap = getVolumeLunMap(systemObjectID, hsd.getObjectID(), volumeURIHLUs, exportMgr);
                    for (Map.Entry<String, String> entry : volumeLunMap.entrySet()) {
                        if (!checkIfVolumeAlreadyExistsOnHSD(entry.getKey(), hsd)) {
                            Path path = new Path(hsd.getPortID(), hsd.getDomainID(), null, entry.getValue(), entry.getKey());
                            pathList.add(path);
                        }
                    }
                }
            }
            if (!pathList.isEmpty()) {
                List<Path> pathResponseList = hdsApiClient.getHDSBatchApiExportManager().addLUNPathsToHSDs(systemObjectID, pathList, storage.getModel());
                if (null != pathResponseList && !pathResponseList.isEmpty()) {
                    // update volume-lun relationship to exportmask.
                    updateVolumeHLUInfo(volumeURIHLUs, pathResponseList, exportMask);
                    dbClient.updateObject(exportMask);
                } else {
                    log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), new Exception("Not able to parse the response of addLUN from server"));
                    ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_VOLUME.getName(), "Not able to parse the response of addLUN from server");
                    taskCompleter.error(dbClient, serviceError);
                    return;
                }
            } else {
                log.info("All the volumes are already part of the HSDs.");
            }
            taskCompleter.ready(dbClient);
        }
    } catch (Exception e) {
        log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} addVolumes END...", storage.getSerialNumber());
}
Also used : Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap)

Aggregations

HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)45 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)26 HDSException (com.emc.storageos.hds.HDSException)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)21 Volume (com.emc.storageos.db.client.model.Volume)14 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)13 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)12 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)12 ArrayList (java.util.ArrayList)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 HashSet (java.util.HashSet)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)10 URI (java.net.URI)10 HDSJob (com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob)9 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 StoragePool (com.emc.storageos.db.client.model.StoragePool)6 HDSApiProtectionManager (com.emc.storageos.hds.api.HDSApiProtectionManager)6