Search in sources :

Example 6 with HDSApiExportManager

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

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

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

Example 9 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)

Example 10 with HDSApiExportManager

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

the class HDSExportMaskValidator method validate.

@Override
public boolean validate() throws Exception {
    log.info("Initiating 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> discoveredInitiators = new HashSet<>();
                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());
                discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
                log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
                log.info("Initiators {} discovered from array for the HSD {}", discoveredInitiators, maskName);
                Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
                Set<String> additionalInitiatorsOnArray = Sets.difference(discoveredInitiators, initiatorsInExportMask);
                if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
                }
                if (!CollectionUtils.isEmpty(additionalInitiatorsOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "initiators", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalInitiatorsOnArray));
                }
            }
            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