Search in sources :

Example 1 with HDSApiExportManager

use of com.emc.storageos.hds.api.HDSApiExportManager 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 HDSApiExportManager

use of com.emc.storageos.hds.api.HDSApiExportManager 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 HDSApiExportManager

use of com.emc.storageos.hds.api.HDSApiExportManager 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 HDSApiExportManager

use of com.emc.storageos.hds.api.HDSApiExportManager 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 HDSApiExportManager

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

the class HDSExportMaskInitiatorsValidator method validate.

@Override
public boolean validate() throws Exception {
    log.info("Initiating initiators validation of HDS ExportMask: {}", id);
    try {
        ExportMask exportMask = getExportMask();
        StorageSystem system = getStorage();
        if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
            Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
            HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
            HDSApiExportManager exportManager = client.getHDSApiExportManager();
            String maskName = null;
            String systemObjectID = HDSUtils.getSystemObjectID(system);
            Set<String> volumesInExportMask = new HashSet<>();
            Set<String> initiatorsInExportMask = new HashSet<>();
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
                volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
            }
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
                initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
            }
            log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
            log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
            for (String hsdObjectIdFromDb : hsdList) {
                Set<String> discoveredVolumes = new HashSet<>();
                HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
                if (null == hsd) {
                    continue;
                }
                maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
                // Get volumes and initiators from storage system
                discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
                log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
                Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
                if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
                }
            }
            checkForErrors();
        }
    } catch (Exception ex) {
        log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
        if (getValidatorConfig().isValidationEnabled()) {
            throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
        }
    }
    return true;
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) ExportMask(com.emc.storageos.db.client.model.ExportMask) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Aggregations

HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)13 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)12 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 ExportMask (com.emc.storageos.db.client.model.ExportMask)9 HDSException (com.emc.storageos.hds.HDSException)7 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 Path (com.emc.storageos.hds.model.Path)4 HashMap (java.util.HashMap)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Initiator (com.emc.storageos.db.client.model.Initiator)3 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)3 ExportMaskValidationContext (com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext)3 AbstractHDSValidator (com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator)3 URI (java.net.URI)3 StringSet (com.emc.storageos.db.client.model.StringSet)2 List (java.util.List)2