Search in sources :

Example 1 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method removeInitiators.

@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    long startTime = System.currentTimeMillis();
    log.info("{} removeInitiator START...", storage.getSerialNumber());
    try {
        log.info("removeInitiator: Export mask id: {}", exportMaskURI);
        if (volumeURIList != null) {
            log.info("removeInitiator: volumes : {}", Joiner.on(',').join(volumeURIList));
        }
        log.info("removeInitiator: initiators : {}", Joiner.on(',').join(initiators));
        log.info("removeInitiator: targets : {}", Joiner.on(',').join(targets));
        if (null == initiators || initiators.isEmpty()) {
            log.info("No initiators found to remove {}", exportMaskURI);
            taskCompleter.ready(dbClient);
            return;
        }
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        // Get the context from the task completer, in case this is a rollback.
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumeURIList, dbClient);
        ctx.setInitiators(initiators);
        // Allow exceptions to be thrown when not rolling back
        ctx.setAllowExceptions(!isRollback);
        AbstractHDSValidator removeInitiatorFromMaskValidator = (AbstractHDSValidator) validator.removeInitiators(ctx);
        removeInitiatorFromMaskValidator.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> hsdObjectIDSet = deviceDataMap.keySet();
            for (String hsdObjectID : hsdObjectIDSet) {
                HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectID);
                if (null == hsd) {
                    log.warn("Not able to remove initiators as HSD {} couldn't find on array.", hsdObjectID);
                    continue;
                }
                List<String> fcInitiators = getFCInitiatorsExistOnHSD(hsd, initiators);
                List<String> iSCSIInitiators = getISCSIInitiatorsExistOnHSD(hsd, initiators);
                boolean isLastFCInitiator = (fcInitiators.size() == 1 && null != hsd.getWwnList() && hsd.getWwnList().size() == fcInitiators.size());
                boolean isLastISCSIInitiator = (iSCSIInitiators.size() == 1 && null != hsd.getIscsiList() && hsd.getIscsiList().size() == iSCSIInitiators.size());
                // If Initiator is last one, remove the HSD
                if (isLastFCInitiator || isLastISCSIInitiator) {
                    exportMgr.deleteHostStorageDomain(systemObjectID, hsd.getObjectID(), storage.getModel());
                    exportMask.getDeviceDataMap().remove(hsd.getObjectID());
                } else {
                    if (null != fcInitiators && !fcInitiators.isEmpty()) {
                        // remove FC initiators from HSD.
                        exportMgr.deleteWWNsFromHostStorageDomain(systemObjectID, hsd.getObjectID(), fcInitiators, storage.getModel());
                    }
                    if (null != iSCSIInitiators && !iSCSIInitiators.isEmpty()) {
                        // remove ISCSInames from HSD.
                        exportMgr.deleteISCSIsFromHostStorageDomain(systemObjectID, hsd.getObjectID(), iSCSIInitiators, storage.getModel());
                    }
                }
            }
            dbClient.updateObject(exportMask);
            // update the task status after processing all HSD's.
            taskCompleter.ready(dbClient);
        } else {
            log.info("No Host groups found on exportMask {}", exportMaskURI);
            // No HSD's found in exportMask.
            taskCompleter.ready(dbClient);
        }
    } catch (Exception e) {
        log.error(String.format("removeInitiator failed - maskURI: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName(), e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        long totalTime = System.currentTimeMillis() - startTime;
        log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
    }
    log.info("{} removeInitiator 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) 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 2 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiators, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} addInitiator START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    List<HostStorageDomain> hsdsToCreate = null;
    List<HostStorageDomain> hsdsWithInitiators = null;
    try {
        log.info("addInitiator: Export mask id: {}", exportMaskURI);
        if (volumeURIs != null) {
            log.info("addInitiator: volumes : {}", Joiner.on(',').join(volumeURIs));
        }
        log.info("addInitiator: initiators : {}", Joiner.on(',').join(initiators));
        log.info("addInitiator: targets : {}", Joiner.on(",").join(targetURIList));
        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);
        List<StoragePort> ports = dbClient.queryObject(StoragePort.class, targetURIList, true);
        if (checkIfMixedTargetPortTypeSelected(ports)) {
            log.error("Unsupported Host as it has both FC & iSCSI Initiators");
            throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
        }
        // @TODO register new initiators by adding them to host on HiCommand DM.
        // Currently, HiCommand is not supporting this. Need to see how we can handle.
        String hostName = getHostNameForInitiators(initiators);
        String hostMode = null, hostModeOption = null;
        Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiators);
        if (hostModeInfo != null) {
            hostMode = hostModeInfo.first;
            hostModeOption = hostModeInfo.second;
        }
        if (targetURIList != null && !targetURIList.isEmpty()) {
            Set<URI> newTargetPorts = new HashSet<>(targetURIList);
            Set<URI> existingTargetPortsInMask = new HashSet<>();
            if (exportMask.getStoragePorts() != null) {
                existingTargetPortsInMask = new HashSet<>(targetURIList);
                Collection<URI> targetPorts = Collections2.transform(exportMask.getStoragePorts(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
                existingTargetPortsInMask.retainAll(targetPorts);
            }
            newTargetPorts.removeAll(existingTargetPortsInMask);
            log.info("list of new storage target ports {}", newTargetPorts);
            log.info("list of existing storage target ports available in export masks {}", existingTargetPortsInMask);
            // Case 1 is handled here for the new initiators & new target ports.
            if (!newTargetPorts.isEmpty()) {
                // If the HLU's are already configured on this target port, then an exception is thrown.
                // User should make sure that all volumes should have same HLU across all target HSD's.
                VolumeURIHLU[] volumeURIHLUs = getVolumeURIHLUFromExportMask(exportMask);
                if (0 < volumeURIHLUs.length) {
                    List<URI> portList = new ArrayList<>(newTargetPorts);
                    hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, portList, 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 to add new initiators. Aborting operation...");
                        throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
                    }
                    // Step 2: Add initiators to all HSD's.
                    Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, newTargetPorts);
                    List<StoragePort> stPortList = new ArrayList<>();
                    while (storagePortIterator.hasNext()) {
                        StoragePort stPort = storagePortIterator.next();
                        if (stPort != null && !stPort.getInactive()) {
                            stPortList.add(stPort);
                        }
                    }
                    hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, 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);
                    }
                } else {
                    log.info("There are no volumes on this exportmask: {} to add to new initiator", exportMaskURI);
                }
            }
            // existing HSD to access the volumes already exported in the exportmask.
            if (!existingTargetPortsInMask.isEmpty()) {
                // Step 1: Collect all HSDs from export mask
                StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
                if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
                    List<HostStorageDomain> hsdResponseList = new ArrayList<>();
                    Set<String> hsdObjectIdSet = deviceDataMap.keySet();
                    for (String hsdObjectId : hsdObjectIdSet) {
                        HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
                        if (null == hsd) {
                            throw HDSException.exceptions.notAbleToFindHostStorageDomain(hsdObjectId);
                        }
                        hsdResponseList.add(hsd);
                    }
                    // Step 2: Add initiators to all HSD's.
                    Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, existingTargetPortsInMask, true);
                    List<StoragePort> stPortList = new ArrayList<>();
                    while (storagePortIterator.hasNext()) {
                        StoragePort stPort = storagePortIterator.next();
                        if (stPort != null) {
                            stPortList.add(stPort);
                        }
                    }
                    hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
                } else {
                    log.info("There are no hsd information in exportMask to add initiators");
                }
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception ex) {
        try {
            log.info("Exception occurred while adding new initiators: {}", 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("addInitiator failed - maskURI: %s", exportMaskURI.toString()), ex);
        } catch (Exception ex1) {
            log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
        } finally {
            ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_INITIATOR.getName(), ex.getMessage());
            taskCompleter.error(dbClient, serviceError);
        }
    }
    log.info("{} addInitiator END...", storage.getSerialNumber());
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) 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) StoragePort(com.emc.storageos.db.client.model.StoragePort) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 3 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method removeVolumes.

@Override
public void removeVolumes(StorageSystem storage, URI exportMaskURI, List<URI> volumes, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} removeVolumes START...", storage.getSerialNumber());
    try {
        log.info("removeVolumes: Export mask id: {}", exportMaskURI);
        log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumes));
        if (initiatorList != null) {
            log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
        }
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        String systemObjectID = HDSUtils.getSystemObjectID(storage);
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        if (CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
            log.info("HSD's are not found in the exportMask {} device DataMap.", exportMask.getId());
            taskCompleter.ready(dbClient);
        }
        // Get the context from the task completer, in case this is a rollback.
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumes, dbClient);
        ctx.setInitiators(initiatorList);
        // Allow exceptions to be thrown when not rolling back
        ctx.setAllowExceptions(!isRollback);
        AbstractHDSValidator removeVolumeFromMaskValidator = (AbstractHDSValidator) validator.removeVolumes(ctx);
        removeVolumeFromMaskValidator.validate();
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        Set<String> hsdList = deviceDataMap.keySet();
        List<Path> pathObjectIdList = new ArrayList<Path>();
        if (null == hsdList || hsdList.isEmpty()) {
            throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
        }
        if (null != exportMask && !exportMask.getInactive()) {
            for (String hsdObjectId : hsdList) {
                HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
                if (null == hsd) {
                    log.warn("Couldn't find the HSD {} to remove volume from ExportMask", hsdObjectId);
                    continue;
                }
                if (null != hsd.getPathList() && !hsd.getPathList().isEmpty()) {
                    pathObjectIdList.addAll(getPathObjectIdsFromHsd(hsd, volumes));
                }
            }
            if (!pathObjectIdList.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteLUNPathsFromStorageSystem(systemObjectID, pathObjectIdList, storage.getModel());
            } else {
                log.info("No volumes found on system: {}", systemObjectID);
            }
        }
        // Update the status after deleting the volume from all HSD's.
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error(String.format("removeVolume failed - maskURI: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(e.getMessage(), e);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} removeVolumes 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) 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 4 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method findExportMasks.

@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) throws DeviceControllerException {
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    log.info("finding export masks for storage {}", storage.getId());
    String systemObjectID = HDSUtils.getSystemObjectID(storage);
    Map<URI, Set<HostStorageDomain>> matchedHostHSDsMap = new HashMap<URI, Set<HostStorageDomain>>();
    Map<URI, Set<URI>> hostToInitiatorMap = new HashMap<URI, Set<URI>>();
    Map<URI, Set<String>> matchedHostInitiators = new HashMap<URI, Set<String>>();
    try {
        HDSApiClient client = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportManager = client.getHDSApiExportManager();
        List<HostStorageDomain> hsdList = exportManager.getHostStorageDomains(systemObjectID);
        for (HostStorageDomain hsd : hsdList) {
            List<String> initiatorsExistsOnHSD = getInitiatorsExistsOnHSD(hsd.getWwnList(), hsd.getIscsiList());
            // Find out if the port is in this masking container
            for (String initiatorName : initiatorNames) {
                String normalizedName = initiatorName.replace(HDSConstants.COLON, HDSConstants.DOT_OPERATOR);
                if (initiatorsExistsOnHSD.contains(normalizedName)) {
                    log.info("Found a matching HSD for {}", initiatorName);
                    Initiator initiator = fetchInitiatorByName(initiatorName);
                    Set<HostStorageDomain> matchedHSDs = matchedHostHSDsMap.get(initiator.getHost());
                    if (matchedHSDs == null) {
                        matchedHSDs = new HashSet<HostStorageDomain>();
                        matchedHostHSDsMap.put(initiator.getHost(), matchedHSDs);
                    }
                    matchedHSDs.add(hsd);
                    Set<String> matchedInitiators = matchedHostInitiators.get(initiator.getHost());
                    if (null == matchedInitiators) {
                        matchedInitiators = new HashSet<String>();
                        matchedHostInitiators.put(initiator.getHost(), matchedInitiators);
                    }
                    matchedInitiators.add(initiatorName);
                }
            }
        }
        hsdList.clear();
        log.info("matchedHSDs: {}", matchedHostHSDsMap);
        log.info("initiatorURIToNameMap: {}", matchedHostInitiators);
        processInitiators(initiatorNames, hostToInitiatorMap);
        List<URI> activeMaskIdsInDb = dbClient.queryByType(ExportMask.class, true);
        List<ExportMask> activeMasks = dbClient.queryObject(ExportMask.class, activeMaskIdsInDb);
        if (null != matchedHostHSDsMap && !matchedHostHSDsMap.isEmpty()) {
            // Iterate through each host
            for (URI hostURI : hostToInitiatorMap.keySet()) {
                Set<URI> hostInitiators = hostToInitiatorMap.get(hostURI);
                boolean isNewExportMask = false;
                // Create single ExportMask for each host-varray combination
                List<ExportMask> exportMaskWithHostInitiators = fetchExportMasksFromDB(activeMasks, hostInitiators, storage);
                Set<HostStorageDomain> hsds = matchedHostHSDsMap.get(hostURI);
                if (!CollectionUtils.isEmpty(hsds)) {
                    for (HostStorageDomain hsd : hsds) {
                        String storagePortOFHDSURI = getStoragePortURIs(Arrays.asList(hsd.getPortID()), storage).get(0);
                        ExportMask maskForHSD = null;
                        for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
                            if (exportMaskhavingInitiators.getStoragePorts().contains(storagePortOFHDSURI)) {
                                maskForHSD = exportMaskhavingInitiators;
                                break;
                            }
                        }
                        if (null == maskForHSD) {
                            // first get the varrays associated with the storage port of the HSD and then check if
                            // any of the export masks have storage ports, which have virtual arrays overlapping with the virtual
                            // arrays of the HSD storage port
                            // NOTE: If the storageport is assigned to multiple varrays, then maintaining one
                            // export mask per varray is not possible. Proper seggregation has to be done.
                            StringSet varraysAssociatedWithHSDStoragePort = getTaggedVarrays(storagePortOFHDSURI);
                            if (!varraysAssociatedWithHSDStoragePort.isEmpty()) {
                                boolean bMaskFound = false;
                                for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
                                    for (String storagePortUriIter : exportMaskhavingInitiators.getStoragePorts()) {
                                        // get the storage port entity
                                        StringSet varraysOfStoragePort = getTaggedVarrays(storagePortUriIter);
                                        if (StringSetUtil.hasIntersection(varraysOfStoragePort, varraysAssociatedWithHSDStoragePort)) {
                                            maskForHSD = exportMaskhavingInitiators;
                                            // Ingest the foreign HSD into a matching export mask with same host and varray combination
                                            bMaskFound = true;
                                            break;
                                        }
                                    }
                                    if (bMaskFound) {
                                        break;
                                    }
                                }
                            } else {
                                // Since this HSD port is not tagged to any varray, we will not ingest it
                                continue;
                            }
                            if (null == maskForHSD) {
                                // No matching export mask found for the same host and varray combination. Creating a new export mask.
                                isNewExportMask = true;
                                maskForHSD = new ExportMask();
                                maskForHSD.setId(URIUtil.createId(ExportMask.class));
                                maskForHSD.setStorageDevice(storage.getId());
                                maskForHSD.setCreatedBySystem(false);
                            }
                        }
                        Set<HostStorageDomain> hsdSet = new HashSet<>();
                        hsdSet.add(hsd);
                        updateHSDInfoInExportMask(maskForHSD, hostInitiators, hsdSet, storage, matchingMasks);
                        if (isNewExportMask) {
                            dbClient.createObject(maskForHSD);
                            exportMaskWithHostInitiators.add(maskForHSD);
                        } else {
                            ExportMaskUtils.sanitizeExportMaskContainers(dbClient, maskForHSD);
                            dbClient.updateObject(maskForHSD);
                        }
                        updateMatchingMasksForHost(matchedHostInitiators.get(hostURI), maskForHSD, matchingMasks);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Error when attempting to query LUN masking information", e);
        throw HDSException.exceptions.queryExistingMasksFailure(e.getMessage());
    }
    log.info("Found matching masks: {}", matchingMasks);
    return matchingMasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) HashSet(java.util.HashSet) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException)

Example 5 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method updateHSDInfoInExportMask.

/**
 * Updates the HSD information in the ExportMask.
 *
 * @param exportMask
 * @param hostInitiators
 * @param matchedHSDs
 */
private void updateHSDInfoInExportMask(ExportMask exportMask, Set<URI> hostInitiators, Set<HostStorageDomain> matchedHSDs, StorageSystem storage, Map<String, Set<URI>> matchingMasks) {
    StringBuilder builder = new StringBuilder();
    if (null != matchedHSDs && !matchedHSDs.isEmpty()) {
        StringSetMap deviceDataMapEntries = new StringSetMap();
        for (HostStorageDomain matchedHSD : matchedHSDs) {
            List<String> initiatorsExistsOnHSD = getInitiatorsExistsOnHSD(matchedHSD.getWwnList(), matchedHSD.getIscsiList());
            // volume Map['volume Id'] = lun
            Map<String, Integer> volumesExistsOnHSD = getExportedVolumes(matchedHSD.getPathList(), storage);
            log.info("Current list of Volumes exists on this HSD: {}", volumesExistsOnHSD);
            builder.append(String.format("XM:%s I:{%s} V:{%s}%n", matchedHSD.getObjectID(), Joiner.on(',').join(initiatorsExistsOnHSD), Joiner.on(',').join(volumesExistsOnHSD.keySet())));
            // Update deviceDataMap in ExportMask with HSD information.
            updateDeviceDataMapInExportMask(exportMask, matchedHSD, storage, deviceDataMapEntries);
            List<String> storagePorts = Arrays.asList(matchedHSD.getPortID());
            List<String> storagePortURIs = getStoragePortURIs(storagePorts, storage);
            if (null != exportMask.getStoragePorts() && !exportMask.getStoragePorts().isEmpty()) {
                // Add the storage ports if they already exist on
                // exportmask.
                exportMask.getStoragePorts().addAll(storagePortURIs);
            } else {
                exportMask.setStoragePorts(storagePortURIs);
            }
            String maskName = (null == matchedHSD.getName()) ? matchedHSD.getNickname() : matchedHSD.getName();
            exportMask.setMaskName(maskName);
            exportMask.addToExistingVolumesIfAbsent(volumesExistsOnHSD);
            exportMask.addToExistingInitiatorsIfAbsent(initiatorsExistsOnHSD);
            List<Initiator> initiatorList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(initiatorsExistsOnHSD)) {
                for (String port : initiatorsExistsOnHSD) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
                    if (existingInitiator != null && !existingInitiator.getInactive()) {
                        initiatorList.add(existingInitiator);
                    }
                }
            }
            exportMask.addInitiators(initiatorList);
            String strExistingInitiators = "";
            String strExistingVolumes = "";
            if (exportMask.getExistingInitiators() != null) {
                strExistingInitiators = Joiner.on(',').join(exportMask.getExistingInitiators());
            }
            if (exportMask.getExistingVolumes() != null) {
                strExistingVolumes = Joiner.on(',').join(exportMask.getExistingVolumes().keySet());
            }
            builder.append(String.format("XM is matching. " + "EI: { %s }, EV: { %s }\n", strExistingInitiators, strExistingVolumes));
        }
        exportMask.addDeviceDataMap(deviceDataMapEntries);
    }
    log.info(builder.toString());
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList)

Aggregations

HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)35 URI (java.net.URI)18 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)11 StorageArray (com.emc.storageos.hds.model.StorageArray)11 ClientResponse (com.sun.jersey.api.client.ClientResponse)11 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 JavaResult (org.milyn.payload.JavaResult)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 HDSException (com.emc.storageos.hds.HDSException)9 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)8 Path (com.emc.storageos.hds.model.Path)7 HashSet (java.util.HashSet)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 StoragePort (com.emc.storageos.db.client.model.StoragePort)5 Add (com.emc.storageos.hds.model.Add)5