Search in sources :

Example 91 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class CreateNFSExportAndMountService method execute.

@Override
public void execute() throws Exception {
    // set fs quotas
    int tempSoftLimit = (softLimit != null) ? softLimit.intValue() : 0;
    int tempAdvisoryLimit = (advisoryLimit != null) ? advisoryLimit.intValue() : 0;
    int tempGracePeriod = (gracePeriod != null) ? gracePeriod.intValue() : 0;
    // convert mount object to export
    List<FileExportRule> exportList = new ArrayList<FileExportRule>();
    for (Mount mount : mountList) {
        FileExportRule export = new FileExportRule();
        List<String> exportHosts = new ArrayList<String>();
        exportHosts.add(BlockStorageUtils.getHost(mount.getHost()).getHostName());
        export.setExportHosts(exportHosts);
        export.setPermission(mount.getPermission());
        export.setSecurity(mount.getSecurity());
        export.setDomain(mount.getDomain());
        export.setRootUserMapping(mount.getRootUserMapping());
        exportList.add(export);
    }
    // create filesystem
    URI fileSystemId = FileStorageUtils.createFileSystemWithoutRollBack(project, virtualArray, virtualPool, exportName, sizeInGb, tempAdvisoryLimit, tempSoftLimit, tempGracePeriod);
    // create nfs export
    if (exportList != null) {
        String rootUserMapping = exportList.get(0).getRootUserMapping().trim();
        String domain = exportList.get(0).getDomain();
        if (StringUtils.isNotBlank(domain)) {
            rootUserMapping = domain.trim() + "\\" + rootUserMapping.trim();
        }
        FileStorageUtils.createFileSystemExportWithoutRollBack(fileSystemId, comment, exportList.get(0).getSecurity(), exportList.get(0).getPermission(), rootUserMapping, exportList.get(0).getExportHosts(), null, false);
        if (!exportList.isEmpty()) {
            FileStorageUtils.updateFileSystemExport(fileSystemId, null, exportList.toArray(new FileExportRule[exportList.size()]), false);
        }
    }
    // mount the exports
    for (Mount mount : mountList) {
        Host host = BlockStorageUtils.getHost(mount.getHost());
        mountNFSExportHelper.mountExport(fileSystemId, mount.getHost(), null, mount.getMountPath(), mount.getSecurity(), host.getHostName(), mount.getFsType());
        ExecutionUtils.addAffectedResource(mount.getHost().toString());
    }
}
Also used : FileExportRule(com.emc.sa.service.vipr.file.FileStorageUtils.FileExportRule) ArrayList(java.util.ArrayList) Mount(com.emc.sa.service.vipr.file.FileStorageUtils.Mount) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 92 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class BlockProvider method getBlockVolumes.

@Asset("unassignedBlockVolume")
@AssetDependencies({ "host", "project", "blockStorageType" })
public List<AssetOption> getBlockVolumes(AssetOptionsContext ctx, URI hostOrClusterId, final URI projectId, String blockStorageType) {
    ViPRCoreClient client = api(ctx);
    Set<URI> exportedBlockResources = BlockProvider.getExportedVolumes(client, projectId, hostOrClusterId, null);
    UnexportedBlockResourceFilter<VolumeRestRep> unexportedFilter = new UnexportedBlockResourceFilter<VolumeRestRep>(exportedBlockResources);
    SourceTargetVolumesFilter sourceTargetVolumesFilter = new SourceTargetVolumesFilter();
    BlockVolumeBootVolumeFilter bootVolumeFilter = new BlockVolumeBootVolumeFilter();
    List<VolumeRestRep> volumes = client.blockVolumes().findByProject(projectId, unexportedFilter.and(sourceTargetVolumesFilter).and(bootVolumeFilter.not()));
    // get varray IDs for host/cluster
    List<VirtualArrayRestRep> varrays = new ArrayList<>();
    if (EXCLUSIVE_STORAGE_OPTION.key.equals(blockStorageType) && URIUtil.isType(hostOrClusterId, Host.class)) {
        varrays = client.varrays().findByConnectedHost(hostOrClusterId);
    } else if (SHARED_STORAGE_OPTION.key.equals(blockStorageType) && URIUtil.isType(hostOrClusterId, Cluster.class)) {
        varrays = client.varrays().findByConnectedCluster(hostOrClusterId);
    }
    List<URI> varrayIds = new ArrayList<>();
    for (VirtualArrayRestRep varray : varrays) {
        varrayIds.add(varray.getId());
    }
    // remove volumes not in hosts/cluster's varray
    Iterator<VolumeRestRep> itr = volumes.iterator();
    while (itr.hasNext()) {
        if (!varrayIds.contains(itr.next().getVirtualArray().getId())) {
            itr.remove();
        }
    }
    return createVolumeOptions(client, volumes);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) SourceTargetVolumesFilter(com.emc.vipr.client.core.filters.SourceTargetVolumesFilter) URI(java.net.URI) BlockVolumeBootVolumeFilter(com.emc.vipr.client.core.filters.BlockVolumeBootVolumeFilter) VirtualArrayRestRep(com.emc.storageos.model.varray.VirtualArrayRestRep) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 93 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method discoverUnmanagedExportMasks.

/**
 * Create unmanaged export masks per host
 *
 * @param systemId
 * @param hostVolumesMap
 *            host-- exportedvolume list
 * @param apiClient
 * @param dbClient
 * @param partitionManager
 * @throws Exception
 */
private void discoverUnmanagedExportMasks(URI systemId, Map<String, List<UnManagedVolume>> hostVolumesMap, VNXeApiClient apiClient, DbClient dbClient, PartitionManager partitionManager) throws Exception {
    unManagedExportMasksToCreate = new ArrayList<UnManagedExportMask>();
    unManagedExportMasksToUpdate = new ArrayList<UnManagedExportMask>();
    List<UnManagedVolume> unManagedExportVolumesToUpdate = new ArrayList<UnManagedVolume>();
    // In Unity, the volumes are exposed through all the storage ports.
    // Get all the storage ports to be added as known ports in the unmanaged export mask
    // If the host ports are FC, then add all FC storage ports to the mask
    // else add all IP ports
    StringSet knownFCStoragePortUris = new StringSet();
    StringSet knownIPStoragePortUris = new StringSet();
    List<StoragePort> matchedFCPorts = new ArrayList<StoragePort>();
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(systemId), storagePortURIs);
    Iterator<URI> portsItr = storagePortURIs.iterator();
    while (portsItr.hasNext()) {
        URI storagePortURI = portsItr.next();
        StoragePort port = dbClient.queryObject(StoragePort.class, storagePortURI);
        if (TransportType.FC.toString().equals(port.getTransportType())) {
            knownFCStoragePortUris.add(storagePortURI.toString());
            matchedFCPorts.add(port);
        } else if (TransportType.IP.toString().equals(port.getTransportType())) {
            knownIPStoragePortUris.add(storagePortURI.toString());
        }
    }
    for (Map.Entry<String, List<UnManagedVolume>> entry : hostVolumesMap.entrySet()) {
        String hostId = entry.getKey();
        List<UnManagedVolume> volumes = entry.getValue();
        StringSet knownInitSet = new StringSet();
        StringSet knownNetworkIdSet = new StringSet();
        StringSet knownVolumeSet = new StringSet();
        List<Initiator> matchedFCInitiators = new ArrayList<Initiator>();
        VNXeHost host = apiClient.getHostById(hostId);
        List<VNXeBase> fcInits = host.getFcHostInitiators();
        List<VNXeBase> iScsiInits = host.getIscsiHostInitiators();
        boolean isVplexHost = false;
        boolean isRPHost = false;
        Set<URI> hostURIs = new HashSet<>();
        if (fcInits != null && !fcInits.isEmpty()) {
            for (VNXeBase init : fcInits) {
                VNXeHostInitiator initiator = apiClient.getHostInitiator(init.getId());
                String portwwn = initiator.getPortWWN();
                if (portwwn == null || portwwn.isEmpty()) {
                    continue;
                }
                Initiator knownInitiator = NetworkUtil.getInitiator(portwwn, dbClient);
                if (knownInitiator != null) {
                    knownInitSet.add(knownInitiator.getId().toString());
                    knownNetworkIdSet.add(portwwn);
                    matchedFCInitiators.add(knownInitiator);
                    URI hostURI = knownInitiator.getHost();
                    if (!NullColumnValueGetter.isNullURI(hostURI) && URIUtil.isType(hostURI, Host.class)) {
                        hostURIs.add(hostURI);
                    }
                } else {
                    knownInitiator = new Initiator();
                    knownInitiator.setInitiatorPort(portwwn);
                }
                if (!isVplexHost && VPlexControllerUtils.isVplexInitiator(knownInitiator, dbClient)) {
                    isVplexHost = true;
                }
            }
        }
        if (!matchedFCInitiators.isEmpty() && ExportUtils.checkIfInitiatorsForRP(matchedFCInitiators)) {
            log.info("host {} contains RP initiators, " + "so this mask contains RP protected volumes", host.getName());
            isRPHost = true;
        }
        if (iScsiInits != null && !iScsiInits.isEmpty()) {
            for (VNXeBase init : iScsiInits) {
                VNXeHostInitiator initiator = apiClient.getHostInitiator(init.getId());
                String portwwn = initiator.getInitiatorId();
                if (portwwn == null || portwwn.isEmpty()) {
                    continue;
                }
                Initiator knownInitiator = NetworkUtil.getInitiator(portwwn, dbClient);
                if (knownInitiator != null) {
                    knownInitSet.add(knownInitiator.getId().toString());
                    knownNetworkIdSet.add(portwwn);
                    URI hostURI = knownInitiator.getHost();
                    if (!NullColumnValueGetter.isNullURI(hostURI) && URIUtil.isType(hostURI, Host.class)) {
                        hostURIs.add(hostURI);
                    }
                }
            }
        }
        if (knownNetworkIdSet.isEmpty()) {
            log.info(String.format("The host %s does not have any known initiators", hostId));
            continue;
        }
        if (hostURIs.size() > 1) {
            log.warn(String.format("Skip export on host %s as the initiators on the host belong to more than one hosts in DB %s", hostId, Joiner.on(",").join(hostURIs)));
            continue;
        }
        String firstNetworkId = knownNetworkIdSet.iterator().next();
        UnManagedExportMask mask = getUnManagedExportMask(firstNetworkId, dbClient, systemId);
        mask.setStorageSystemUri(systemId);
        // set the host name as the mask name
        mask.setMaskName(host.getName());
        allCurrentUnManagedExportMaskUris.add(mask.getId());
        for (UnManagedVolume hostUnManagedVol : volumes) {
            hostUnManagedVol.getInitiatorNetworkIds().addAll(knownNetworkIdSet);
            hostUnManagedVol.getInitiatorUris().addAll(knownInitSet);
            hostUnManagedVol.getUnmanagedExportMasks().add(mask.getId().toString());
            if (isVplexHost) {
                log.info("marking unmanaged unity volume {} as a VPLEX backend volume", hostUnManagedVol.getLabel());
                hostUnManagedVol.putVolumeCharacterstics(SupportedVolumeCharacterstics.IS_VPLEX_BACKEND_VOLUME.toString(), Boolean.TRUE.toString());
            }
            if (isRPHost) {
                log.info("unmanaged volume {} is an RP volume", hostUnManagedVol.getLabel());
                hostUnManagedVol.putVolumeCharacterstics(SupportedVolumeCharacterstics.IS_RECOVERPOINT_ENABLED.toString(), Boolean.TRUE.toString());
            } else {
                log.info("unmanaged volume {} is exported to something other than RP.  Marking IS_NONRP_EXPORTED.", hostUnManagedVol.forDisplay());
                hostUnManagedVol.putVolumeCharacterstics(SupportedVolumeCharacterstics.IS_NONRP_EXPORTED.toString(), Boolean.TRUE.toString());
            }
            mask.getUnmanagedVolumeUris().add(hostUnManagedVol.getId().toString());
            // update mask to HLU information
            StringSet nativeId = hostUnManagedVol.getVolumeInformation().get(SupportedVolumeInformation.NATIVE_ID.name());
            String nativeGuid = hostUnManagedVol.getNativeGuid();
            String lunId = (nativeId != null && nativeId.iterator().hasNext()) ? nativeId.iterator().next() : nativeGuid.substring(nativeGuid.lastIndexOf(Constants.PLUS) + 1);
            String idCharSequence = HostLunRequests.ID_SEQUENCE_LUN;
            if (Boolean.valueOf(hostUnManagedVol.getVolumeCharacterstics().get(SupportedVolumeCharacterstics.IS_SNAP_SHOT.name()))) {
                idCharSequence = HostLunRequests.ID_SEQUENCE_SNAP;
                Snap snap = apiClient.getSnapshot(lunId);
                // get snap's parent id
                lunId = snap.getLun().getId();
            }
            HostLun hostLun = apiClient.getHostLun(lunId, hostId, idCharSequence);
            if (hostLun != null) {
                String hostHlu = host.getName() + "=" + hostLun.getHlu();
                StringSet existingHostHlu = hostUnManagedVol.getVolumeInformation().get(SupportedVolumeInformation.HLU_TO_EXPORT_MASK_NAME_MAP.name());
                if (existingHostHlu != null) {
                    existingHostHlu.add(hostHlu);
                } else {
                    hostUnManagedVol.getVolumeInformation().put(SupportedVolumeInformation.HLU_TO_EXPORT_MASK_NAME_MAP.name(), hostHlu);
                }
            }
            unManagedExportVolumesToUpdate.add(hostUnManagedVol);
        }
        mask.replaceNewWithOldResources(knownInitSet, knownNetworkIdSet, knownVolumeSet, !matchedFCInitiators.isEmpty() ? knownFCStoragePortUris : knownIPStoragePortUris);
        updateZoningMap(mask, matchedFCInitiators, matchedFCPorts);
    }
    if (!unManagedExportMasksToCreate.isEmpty()) {
        partitionManager.insertInBatches(unManagedExportMasksToCreate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_EXPORT_MASK);
        unManagedExportMasksToCreate.clear();
    }
    if (!unManagedExportMasksToUpdate.isEmpty()) {
        partitionManager.updateInBatches(unManagedExportMasksToUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_EXPORT_MASK);
        unManagedExportMasksToUpdate.clear();
    }
    if (!unManagedExportVolumesToUpdate.isEmpty()) {
        partitionManager.updateAndReIndexInBatches(unManagedExportVolumesToUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
        unManagedExportVolumesToUpdate.clear();
    }
    DiscoveryUtils.markInActiveUnManagedExportMask(systemId, allCurrentUnManagedExportMaskUris, dbClient, partitionManager);
}
Also used : ArrayList(java.util.ArrayList) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) Snap(com.emc.storageos.vnxe.models.Snap) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) UnManagedExportMask(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask) HashSet(java.util.HashSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) Host(com.emc.storageos.db.client.model.Host) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) Map(java.util.Map) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 94 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method refreshRESTExportMask.

/**
 * Refresh the export mask with the user added configuration
 *
 * @param storage
 *            XIV sotrage system
 * @param mask
 *            Export Mask instance
 * @param _networkDeviceController
 *            Network configuration instance
 */
public void refreshRESTExportMask(StorageSystem storage, ExportMask mask, NetworkDeviceController _networkDeviceController) {
    try {
        final String storageIP = storage.getSmisProviderIP();
        final String name = mask.getNativeId();
        XIVRestClient restExportOpr = getRestClient(storage);
        StringBuilder builder = new StringBuilder();
        Set<String> discoveredPorts = new HashSet<String>();
        Set<URI> hostURIs = new HashSet<URI>();
        Set<Initiator> exportMaskInits = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, mask, null);
        Iterator<Initiator> exportMaskInitsItr = exportMaskInits.iterator();
        while (exportMaskInitsItr.hasNext()) {
            hostURIs.add(exportMaskInitsItr.next().getHost());
        }
        // Check the initiators and update the lists as necessary
        List<Host> hostList = _dbClient.queryObject(Host.class, hostURIs);
        for (Host host : hostList) {
            discoveredPorts.addAll(restExportOpr.getHostPorts(storageIP, host.getLabel()));
        }
        boolean addInitiators = false;
        List<String> initiatorsToAdd = new ArrayList<String>();
        List<Initiator> initiatorIdsToAdd = new ArrayList<>();
        for (String port : discoveredPorts) {
            String normalizedPort = Initiator.normalizePort(port);
            if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                initiatorsToAdd.add(normalizedPort);
                Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                if (existingInitiator != null) {
                    initiatorIdsToAdd.add(existingInitiator);
                }
                addInitiators = true;
            }
        }
        boolean removeInitiators = false;
        List<String> initiatorsToRemove = new ArrayList<String>();
        List<URI> initiatorIdsToRemove = new ArrayList<>();
        if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
            initiatorsToRemove.addAll(mask.getExistingInitiators());
            initiatorsToRemove.removeAll(discoveredPorts);
        }
        removeInitiators = !initiatorsToRemove.isEmpty();
        // Get Volumes mapped to a Host on Array
        Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
        final String exportType = ExportMaskUtils.getExportType(_dbClient, mask);
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
            discoveredVolumes.putAll(restExportOpr.getVolumesMappedToHost(storageIP, mask.getLabel(), null));
        } else {
            for (Host host : hostList) {
                discoveredVolumes.putAll(restExportOpr.getVolumesMappedToHost(storageIP, null, host.getLabel()));
            }
        }
        // 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 (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
            volumesToRemove.addAll(mask.getExistingVolumes().keySet());
            volumesToRemove.removeAll(discoveredVolumes.keySet());
            removeVolumes = !volumesToRemove.isEmpty();
        }
        builder.append(String.format("XM refresh: %s initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAdd), Joiner.on(',').join(initiatorsToRemove)));
        builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
        if (addInitiators || removeInitiators || addVolumes || removeVolumes) {
            builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
            mask.removeFromExistingInitiators(initiatorsToRemove);
            if (initiatorIdsToRemove != null && !initiatorIdsToRemove.isEmpty()) {
                mask.removeInitiators(_dbClient.queryObject(Initiator.class, initiatorIdsToRemove));
            }
            List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorIdsToAdd, _dbClient);
            mask.addToUserCreatedInitiators(userAddedInitiators);
            mask.addToExistingInitiatorsIfAbsent(initiatorsToAdd);
            mask.addInitiators(initiatorIdsToAdd);
            mask.removeFromExistingVolumes(volumesToRemove);
            mask.setExistingVolumes(new StringMap());
            mask.addToExistingVolumesIfAbsent(volumesToAdd);
            ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
            _dbClient.updateObject(mask);
        } else {
            builder.append("XM refresh: There are no changes to the mask\n");
        }
        _networkDeviceController.refreshZoningMap(mask, initiatorsToRemove, Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
        _log.info(builder.toString());
    } catch (Exception e) {
        String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
        _log.error(MessageFormat.format("Encountered an error when attempting to refresh existing exports: {0}", msg), e);
        throw XIVRestException.exceptions.refreshExistingMaskFailure(msg);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) HashSet(java.util.HashSet)

Example 95 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method findRESTExportMasks.

/**
 * Find Export mask
 *
 * @param storage
 *            Storage System instance
 * @param initiatorNames
 *            Initiator names
 * @param mustHaveAllPorts
 *            Must have all the ports boolean
 * @return Initiator to Export mask map.
 */
public Map<String, Set<URI>> findRESTExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
    long startTime = System.currentTimeMillis();
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    try {
        final String storageIP = storage.getSmisProviderIP();
        XIVRestClient restExportOpr = getRestClient(storage);
        StringBuilder builder = new StringBuilder();
        for (String initiatorName : initiatorNames) {
            final String hostName = restExportOpr.getHostPortContainer(storageIP, initiatorName);
            Set<String> exportMaskNames = new HashSet<String>();
            if (null != hostName) {
                exportMaskNames.add(hostName);
                final String clusterNames = restExportOpr.getHostContainer(storageIP, hostName);
                if (null != clusterNames) {
                    exportMaskNames.add(clusterNames);
                }
            }
            // Find the existing masks
            for (String exportMaskName : exportMaskNames) {
                URIQueryResultList uriQueryList = new URIQueryResultList();
                _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskByNameConstraint(exportMaskName), uriQueryList);
                ExportMask exportMask = null;
                while (uriQueryList.iterator().hasNext()) {
                    URI uri = uriQueryList.iterator().next();
                    exportMask = _dbClient.queryObject(ExportMask.class, uri);
                    if (exportMask != null && !exportMask.getInactive() && exportMask.getStorageDevice().equals(storage.getId())) {
                        ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, exportMask);
                        _dbClient.updateAndReindexObject(exportMask);
                        Set<URI> maskURIs = matchingMasks.get(initiatorName);
                        if (maskURIs == null) {
                            maskURIs = new HashSet<URI>();
                            matchingMasks.put(initiatorName, maskURIs);
                        }
                        maskURIs.add(exportMask.getId());
                        break;
                    }
                }
                // update hosts
                Initiator initiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(initiatorName), _dbClient);
                if (null != initiator && null != initiator.getHost()) {
                    Host hostIns = _dbClient.queryObject(Host.class, initiator.getHost());
                    String label = hostIns.getLabel();
                    if (label.equals(exportMaskName)) {
                        unsetTag(hostIns, storage.getSerialNumber());
                    } else {
                        setTag(hostIns, storage.getSerialNumber(), exportMaskName);
                    }
                }
            }
        }
        _log.info(builder.toString());
    } catch (Exception e) {
        String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
        _log.error(MessageFormat.format("Encountered an SMIS error when attempting to query existing exports: {0}", msg), e);
        throw XIVRestException.exceptions.queryExistingMasksFailure(msg, e);
    } finally {
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
    }
    return matchingMasks;
}
Also used : HashSet(java.util.HashSet) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) Set(java.util.Set) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) HashSet(java.util.HashSet)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16