Search in sources :

Example 1 with InitiatorPathParam

use of com.emc.storageos.model.block.export.InitiatorPathParam in project coprhd-controller by CoprHD.

the class ExportGroupService method validatePathAdjustment.

/**
 * Validate the path adjustment request parameters
 *
 * @param exportGroup ExportGroup object
 * @param system StorageSystem object
 * @param param Export Path Adjustment Parameters
 * @param varray URI of the virtual array, used to check any supplied ports are in correct varray
 */
private void validatePathAdjustment(ExportGroup exportGroup, StorageSystem system, ExportPathsAdjustmentParam param, URI varray) {
    String systemType = system.getSystemType();
    if (!Type.vmax.name().equalsIgnoreCase(systemType) && !Type.vplex.name().equalsIgnoreCase(systemType)) {
        throw APIException.badRequests.exportPathAdjustmentSystemNotSupported(systemType);
    }
    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, system.getId());
    if (exportMasks.isEmpty()) {
        throw APIException.badRequests.exportPathAdjustmentSystemExportGroupNotMatch(exportGroup.getLabel(), system.getNativeGuid());
    }
    ExportPathParameters pathParam = param.getExportPathParameters();
    if (pathParam == null) {
        throw APIException.badRequests.exportPathAdjustementNoPathParameters();
    }
    URI pgURI = pathParam.getPortGroup();
    // Check if exportMask has existing volumes, if it does, make sure no remove paths.
    for (ExportMask exportMask : exportMasks) {
        List<InitiatorPathParam> removePaths = param.getRemovedPaths();
        if (removePaths.isEmpty() || !exportMask.hasAnyExistingVolumes()) {
            continue;
        }
        Map<URI, List<URI>> removes = new HashMap<URI, List<URI>>();
        for (InitiatorPathParam initPath : removePaths) {
            removes.put(initPath.getInitiator(), initPath.getStoragePorts());
        }
        Map<URI, List<URI>> removedPathForMask = ExportMaskUtils.getRemovePathsForExportMask(exportMask, removes);
        if (removedPathForMask != null && !removedPathForMask.isEmpty() && pgURI == null) {
            _log.error("It has removed path for the ExportMask with existing volumes: " + exportMask.getMaskName());
            throw APIException.badRequests.externallyAddedVolumes(exportMask.getMaskName(), exportMask.getExistingVolumes().toString());
        }
    }
    // check adjusted paths are valid. initiators are in the export group, and the targets are in the storage system, and
    // in valid state.
    Map<URI, List<URI>> adjustedPaths = convertInitiatorPathParamToMap(param.getAdjustedPaths());
    List<URI> pathInitiatorURIs = new ArrayList<URI>(adjustedPaths.keySet());
    StringSet initiatorIds = exportGroup.getInitiators();
    if (!initiatorIds.containsAll(StringSetUtil.uriListToStringSet(pathInitiatorURIs))) {
        // Determine all the host URIs for the egInitiators
        Set<URI> egHostURIs = new HashSet<URI>();
        List<Initiator> egInitiators = ExportUtils.getExportGroupInitiators(exportGroup, _dbClient);
        for (Initiator egInitiator : egInitiators) {
            if (!NullColumnValueGetter.isNullURI(egInitiator.getHost())) {
                egHostURIs.add(egInitiator.getHost());
            }
        }
        // Now, only throw error if there are initiators that are not of any of the egHostURIs
        List<Initiator> pathInitiators = _dbClient.queryObject(Initiator.class, pathInitiatorURIs);
        List<String> badInitiators = new ArrayList<String>();
        for (Initiator pathInitiator : pathInitiators) {
            // Bad if not in the EG initiatorIds AND not from an identifiable host or not from a host in EG
            if (!initiatorIds.contains(pathInitiator.getId().toString())) {
                if (pathInitiator.getHost() == null || !egHostURIs.contains(pathInitiator.getHost())) {
                    badInitiators.add(pathInitiator.getHostName() + "-" + pathInitiator.getInitiatorPort());
                }
            }
        }
        if (!badInitiators.isEmpty()) {
            throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(", ").join(badInitiators));
        }
    }
    Set<URI> pathTargets = new HashSet<URI>();
    for (List<URI> targets : adjustedPaths.values()) {
        pathTargets.addAll(targets);
    }
    Set<URI> systemPorts = new HashSet<URI>();
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(system.getId()), storagePortURIs);
    // Validate the targets to be provisioned have a valid state (COMPATIBLE, REGISTERED, and VISIBLE) and
    // that their tagged virtual array contains our varray.
    List<StoragePort> storagePorts = _dbClient.queryObject(StoragePort.class, storagePortURIs);
    for (StoragePort port : storagePorts) {
        if (!port.getInactive() && port.getCompatibilityStatus().equals(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name()) && port.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) && port.getDiscoveryStatus().equals(DiscoveryStatus.VISIBLE.name()) && port.getTaggedVirtualArrays() != null && port.getTaggedVirtualArrays().contains(varray.toString())) {
            systemPorts.add(port.getId());
        }
    }
    if (!systemPorts.containsAll(pathTargets)) {
        // List only the invalid targets
        pathTargets.removeAll(systemPorts);
        throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(",").join(pathTargets));
    }
}
Also used : HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) 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) InitiatorPathParam(com.emc.storageos.model.block.export.InitiatorPathParam) ExportPathParameters(com.emc.storageos.model.block.export.ExportPathParameters) HashSet(java.util.HashSet)

Example 2 with InitiatorPathParam

use of com.emc.storageos.model.block.export.InitiatorPathParam in project coprhd-controller by CoprHD.

the class ExportPathAdjustmentService method execute.

@Override
public void execute() throws Exception {
    // build affect paths
    List<InitiatorPathParam> toSendAffectedPaths = new ArrayList<InitiatorPathParam>();
    for (Map.Entry<URI, List<URI>> entry : resultingPathsMap.entrySet()) {
        InitiatorPathParam pathParam = new InitiatorPathParam();
        pathParam.setInitiator(entry.getKey());
        pathParam.setStoragePorts(entry.getValue());
        toSendAffectedPaths.add(pathParam);
    }
    // build removed paths
    List<InitiatorPathParam> toSendRemovedPaths = new ArrayList<InitiatorPathParam>();
    for (Map.Entry<URI, List<URI>> entry : removedPathsMap.entrySet()) {
        InitiatorPathParam pathParam = new InitiatorPathParam();
        pathParam.setInitiator(entry.getKey());
        pathParam.setStoragePorts(entry.getValue());
        toSendRemovedPaths.add(pathParam);
    }
    BlockStorageUtils.adjustExportPaths(virtualArray, minPaths, maxPaths, pathsPerInitiator, storageSystem, exportId, toSendAffectedPaths, toSendRemovedPaths, suspendWait);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InitiatorPathParam(com.emc.storageos.model.block.export.InitiatorPathParam) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI)

Example 3 with InitiatorPathParam

use of com.emc.storageos.model.block.export.InitiatorPathParam in project coprhd-controller by CoprHD.

the class AdjustExportPaths method buildPathDetails.

private String buildPathDetails(List<InitiatorPathParam> param) {
    StringBuilder builder = new StringBuilder();
    for (InitiatorPathParam ini : param) {
        builder.append(" " + ini.getInitiator().toString() + ": [");
        List<String> ports = new ArrayList<String>();
        for (URI uri : ini.getStoragePorts()) {
            ports.add(uri.toString());
        }
        builder.append(String.join(", ", ports));
        builder.append("],");
    }
    return builder.toString();
}
Also used : ArrayList(java.util.ArrayList) InitiatorPathParam(com.emc.storageos.model.block.export.InitiatorPathParam) URI(java.net.URI)

Aggregations

InitiatorPathParam (com.emc.storageos.model.block.export.InitiatorPathParam)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ExportMask (com.emc.storageos.db.client.model.ExportMask)1 Initiator (com.emc.storageos.db.client.model.Initiator)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 ExportPathParameters (com.emc.storageos.model.block.export.ExportPathParameters)1 ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1