Search in sources :

Example 41 with Initiator

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

the class ExportGroupService method validatePortAssignmentOnStorageSystems.

/**
 * Validate that we can assign the required number of ports for the varray(s)
 * required to complete the export. Multiple varrays could be used if VPLEX.
 *
 * @param storageSystemURIs
 * @param exportGroup
 * @param initiatorURIs
 * @param volumes
 * @param pathParam optional ExportPathParameter block to override validation check
 */
private void validatePortAssignmentOnStorageSystems(Collection<URI> storageSystemURIs, ExportGroup exportGroup, List<URI> initiatorURIs, Collection<URI> volumes, ExportPathParameters pathParam) {
    // Do not validate ExportGroup Initiator type exports
    if (exportGroup.forInitiator()) {
        return;
    }
    for (URI storageSystemURI : storageSystemURIs) {
        StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        // Validate the initiators in their respective varrays.
        if (storageSystem.getSystemType().equals(DiscoveredDataObject.Type.vplex.name())) {
            List<URI> varrays = new ArrayList<URI>();
            Map<URI, Set<URI>> varrayToVolumes = VPlexUtil.mapBlockObjectsToVarrays(_dbClient, volumes, storageSystemURI, exportGroup);
            varrays.addAll(varrayToVolumes.keySet());
            Map<URI, List<URI>> varrayToInitiatorsMap = VPlexUtil.partitionInitiatorsByVarray(_dbClient, initiatorURIs, varrays, storageSystem);
            int nValidations = 0;
            for (URI varrayKey : varrays) {
                if (varrayToInitiatorsMap.get(varrayKey) == null || varrayToInitiatorsMap.get(varrayKey).isEmpty()) {
                    continue;
                }
                List<Initiator> initiators = _dbClient.queryObject(Initiator.class, varrayToInitiatorsMap.get(varrayKey));
                if (varrayToVolumes.get(varrayKey) != null) {
                    nValidations++;
                    Collection<String> initiatorAddresses = Collections2.transform(initiators, CommonTransformerFunctions.fctnInitiatorToPortName());
                    _log.info(String.format("Validating port assignments varray %s initiators %s", varrayKey.toString(), initiatorAddresses));
                    validatePortAssignment(storageSystem, varrayKey, _blockStorageScheduler, initiators, varrayToVolumes.get(varrayKey), exportGroup.getId(), pathParam);
                }
            }
            if (nValidations == 0) {
                _log.info("No validations made for VPlex port assignment");
            }
        } else {
            List<Initiator> initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
            URI varray = exportGroup.getVirtualArray();
            Collection<String> initiatorAddresses = Collections2.transform(initiators, CommonTransformerFunctions.fctnInitiatorToPortName());
            _log.info(String.format("Validating port assignments varray %s initiators %s", varray.toString(), initiatorAddresses));
            validatePortAssignment(storageSystem, varray, _blockStorageScheduler, initiators, volumes, exportGroup.getId(), pathParam);
        }
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Initiator(com.emc.storageos.db.client.model.Initiator) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 42 with Initiator

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

the class ExportGroupService method validateNoConflictingExports.

/**
 * Throw an error if we cannot override the Vpool path parameters because there is already
 * an existing export from the indicated host(s) to storage array(s).
 *
 * @param exportGroup
 * @param arrayURIs
 * @param pathParam -- New ExportPathParams to be used
 */
private void validateNoConflictingExports(ExportGroup exportGroup, Set<URI> arrayURIs, ExportPathParams pathParam) {
    _log.info("Requested path parameters: " + pathParam.toString());
    Map<String, String> conflictingMasks = new HashMap<String, String>();
    StringSet initiators = exportGroup.getInitiators();
    if (initiators == null) {
        // No initiators currently in export, nothing to do
        return;
    }
    for (String initiatorId : initiators) {
        Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorId));
        if (initiator == null || initiator.getInactive()) {
            continue;
        }
        // Look up all the Export Masks for this Initiator
        List<ExportMask> exportMasks = ExportUtils.getInitiatorExportMasks(initiator, _dbClient);
        for (ExportMask exportMask : exportMasks) {
            // If this mask is for the same Host and Storage combination, we cannot override
            if (arrayURIs.contains(exportMask.getStorageDevice())) {
                ExportPathParams maskParam = BlockStorageScheduler.calculateExportPathParamForExportMask(_dbClient, exportMask);
                _log.info(String.format("Existing mask %s (%s) parameters: %s", exportMask.getMaskName(), exportMask.getId(), maskParam));
                // i.e. maskParams.ppi = pathParms.ppi and pathParams.minPath <= maskParams.maxpath <= pathParams.maxPath
                if (pathParam.getPathsPerInitiator() == maskParam.getPathsPerInitiator() && (pathParam.getMinPaths() <= maskParam.getMaxPaths() && maskParam.getMaxPaths() <= pathParam.getMaxPaths())) {
                    _log.info(String.format("Export mask %s is compatible with the requested parameters", exportMask.getMaskName()));
                } else {
                    StorageSystem system = _dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice());
                    String hostName = (initiator.getHostName() != null) ? initiator.getHostName() : initiatorId;
                    String systemName = (system != null) ? system.getLabel() : exportMask.getStorageDevice().toString();
                    if (!conflictingMasks.containsKey(hostName)) {
                        String msg = String.format("Export Mask %s for Host %s and Array %s has %d paths and paths_per_initiator %d", exportMask.getMaskName(), hostName, systemName, maskParam.getMaxPaths(), maskParam.getPathsPerInitiator());
                        conflictingMasks.put(hostName, msg);
                    }
                }
            }
        }
    }
    if (!conflictingMasks.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        for (Entry<String, String> entry : conflictingMasks.entrySet()) {
            if (builder.length() != 0) {
                builder.append("; ");
            }
            builder.append(entry.getValue());
        }
        throw APIException.badRequests.cannotOverrideVpoolPathsBecauseExistingExports(builder.toString());
    }
}
Also used : HashMap(java.util.HashMap) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) StringSet(com.emc.storageos.db.client.model.StringSet) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 43 with Initiator

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

the class ExportGroupService method validateInitiatorHostOS.

/**
 * Validate that all the initiators to be added to the export group belong to the same host type
 *
 * @param initiators the list of initiators to validate
 */
private void validateInitiatorHostOS(Set<URI> initiators) {
    Set<String> hostTypes = new HashSet<String>();
    List<URI> hostList = new ArrayList<URI>();
    // Dummy URI used in case we encounter null values
    URI fillerHostURI = NullColumnValueGetter.getNullURI();
    if (initiators != null && !initiators.isEmpty()) {
        for (URI initiatorUri : initiators) {
            Initiator ini = queryObject(Initiator.class, initiatorUri, true);
            // If ini.getHost() returns a null value, set hostURI to fillerHostURI
            URI hostURI = (ini.getHost() == null) ? fillerHostURI : ini.getHost();
            // no need to go to the DB again..
            if (!hostList.isEmpty() && hostList.contains(hostURI)) {
                continue;
            } else {
                // add the hostURI to the hostList so that it can
                // help in the next iteration.
                hostList.add(hostURI);
            }
            if (hostURI == fillerHostURI) {
                hostTypes.add(String.valueOf(fillerHostURI));
            } else {
                Host host = queryObject(Host.class, hostURI, true);
                hostTypes.add(host.getType());
            }
        }
        if (hostTypes.size() != 1) {
            throw APIException.badRequests.initiatorHostsInSameOS();
        }
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 44 with Initiator

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

the class ExportGroupService method getInitiatorExportGroupHost.

/**
 * For Initiator type export groups, find the host to which the initiators belong.
 *
 * @param exportGroup the export group
 * @return the URI of the initiators host
 */
private URI getInitiatorExportGroupHost(ExportGroup exportGroup) {
    URI hostUri = null;
    StringSet exportGroupInitiators = exportGroup.getInitiators();
    if (exportGroup.forInitiator() && exportGroupInitiators != null) {
        for (String uri : exportGroupInitiators) {
            Initiator initiator = queryObject(Initiator.class, URI.create(uri), false);
            hostUri = initiator.getHost();
            break;
        }
    }
    return hostUri;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 45 with Initiator

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

the class ExportGroupService method removeClusterData.

/**
 * Updates the lists of hosts and initiator when a cluster is removed.
 *
 * @param cluster the cluster being removed
 * @param newHosts the list of hosts to update
 * @param newInitiators the list of initiators to update
 */
private void removeClusterData(URI cluster, List<URI> newHosts, List<URI> newInitiators) {
    List<URI> hostUris = ComputeSystemHelper.getChildrenUris(_dbClient, cluster, Host.class, "cluster");
    for (URI hosturi : hostUris) {
        newHosts.remove(hosturi);
        newInitiators.removeAll(ComputeSystemHelper.getChildrenUris(_dbClient, hosturi, Initiator.class, "host"));
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54