Search in sources :

Example 6 with ExportPathsAdjustmentPreviewRestRep

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

the class ExportGroupService method pathsAdjustmentPreview.

/**
 * Paths Adjustment Preview
 *
 * This call does a PORT Allocation which is used for a path adjustment preview operation.
 * If the user is satisfied with the ports that are selected, they will invoke the provisioning through a
 * separate API.
 *
 * Inputs are the the Export Group URI, Storage System URI, an optional Varray URI, and the ExportPath parameters.
 * There is also a boolean that specifies the allocation should start assuming the existing paths are used (or not).
 *
 * @param id the URN of a ViPR export group to be updated; ports will be allocated in this context
 * @param param -- ExportPortAllocateParam block containing Storage System URI, Varray URI, ExportPathParameters
 *
 * @brief Preview port allocation paths for export
 * @return a PortAllocatePreviewRestRep rest response which contains the new or existing paths that will be provisioned
 * or kept; the removed paths; and any other Export Groups that will be affected.
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/paths-adjustment-preview")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public ExportPathsAdjustmentPreviewRestRep pathsAdjustmentPreview(@PathParam("id") URI id, ExportPathsAdjustmentPreviewParam param) throws ControllerException {
    // Basic validation of ExportGroup and update request
    ExportGroup exportGroup = queryObject(ExportGroup.class, id, true);
    if (exportGroup.checkInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS)) {
        throw BadRequestException.badRequests.deletionInProgress(exportGroup.getClass().getSimpleName(), exportGroup.getLabel());
    }
    validateExportGroupNoPendingEvents(exportGroup);
    validateHostsInExportGroup(exportGroup, param.getHosts());
    // Validate storage system
    ArgValidator.checkUri(param.getStorageSystem());
    StorageSystem system = queryObject(StorageSystem.class, param.getStorageSystem(), true);
    // Get the virtual array, default to Export Group varray. Validate it matches.
    URI varray = param.getVirtualArray();
    if (varray != null) {
        boolean validVarray = varray.equals(exportGroup.getVirtualArray());
        if (exportGroup.getAltVirtualArrays() != null && varray.toString().equals(exportGroup.getAltVirtualArrays().get(system.getId().toString()))) {
            validVarray = true;
        }
        if (!validVarray) {
            throw APIException.badRequests.varrayNotInExportGroup(varray.toString());
        }
    } else {
        varray = exportGroup.getVirtualArray();
    }
    // Validate the hosts, if supplied.
    for (URI hostId : param.getHosts()) {
        // Throw exception of thoe hostId is invalid
        queryObject(Host.class, hostId, true);
    }
    // Get the initiators and validate the ExportMasks are usable.
    ExportPathsAdjustmentPreviewRestRep response = new ExportPathsAdjustmentPreviewRestRep();
    String storageSystem = system.getNativeGuid();
    if (Type.vplex.equals(Type.valueOf(system.getSystemType()))) {
        String vplexCluster = ConnectivityUtil.getVplexClusterForVarray(varray, system.getId(), _dbClient);
        storageSystem = storageSystem + STORAGE_SYSTEM_CLUSTER + vplexCluster;
    }
    response.setStorageSystem(storageSystem);
    List<Initiator> initiators = getInitiators(exportGroup);
    StringSetMap existingPathMap = new StringSetMap();
    StringSet storagePorts = new StringSet();
    validatePathAdjustment(exportGroup, initiators, system, varray, param.getHosts(), response, existingPathMap, param.getUseExistingPaths(), storagePorts);
    try {
        // Manufacture an ExportPathParams structure from the REST ExportPathParameters structure
        ExportPathParams pathParam = new ExportPathParams(param.getExportPathParameters(), exportGroup);
        if (!storagePorts.isEmpty()) {
            // check if storage ports are specified
            StringSet paramPorts = pathParam.getStoragePorts();
            if (paramPorts != null && !paramPorts.isEmpty()) {
                if (!storagePorts.containsAll(paramPorts)) {
                    _log.error("Selected ports are not in the port group");
                    throw APIException.badRequests.pathAdjustmentSelectedPortsNotInPortGroup(Joiner.on(',').join(paramPorts), Joiner.on(',').join(storagePorts));
                }
            } else {
                pathParam.setStoragePorts(storagePorts);
            }
        }
        // Call the storage port allocator/assigner for all initiators (host or cluster) in
        // the Export Group. Pass in the existing paths if requested in the parameters.
        List<URI> volumes = StringSetUtil.stringSetToUriList(exportGroup.getVolumes().keySet());
        Map<URI, List<URI>> zoningMap = _blockStorageScheduler.assignStoragePorts(system, varray, initiators, pathParam, (param.getUseExistingPaths() ? existingPathMap : new StringSetMap()), volumes);
        for (Entry<URI, List<URI>> entry : zoningMap.entrySet()) {
            InitiatorPortMapRestRep zone = new InitiatorPortMapRestRep();
            Initiator initiator = queryObject(Initiator.class, entry.getKey(), false);
            zone.setInitiator(HostMapper.map(initiator));
            for (URI portURI : entry.getValue()) {
                StoragePort port = queryObject(StoragePort.class, portURI, false);
                zone.getStoragePorts().add(toNamedRelatedResource(port, port.getPortName()));
            }
            response.getAdjustedPaths().add(zone);
        }
        addRetainedPathsFromHosts(response, existingPathMap, param.getHosts());
        Collections.sort(response.getAdjustedPaths(), response.new InitiatorPortMapRestRepComparator());
        calculateRemovedPaths(response, zoningMap, exportGroup, system, varray, param.getHosts());
        response.logResponse(_log);
        return response;
    } catch (ControllerException ex) {
        _log.error(ex.getLocalizedMessage());
        throw (ex);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ExportPathsAdjustmentPreviewRestRep(com.emc.storageos.model.block.export.ExportPathsAdjustmentPreviewRestRep) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) InitiatorPortMapRestRep(com.emc.storageos.model.block.export.InitiatorPortMapRestRep) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ExportPathsAdjustmentPreviewRestRep (com.emc.storageos.model.block.export.ExportPathsAdjustmentPreviewRestRep)6 URI (java.net.URI)6 Asset (com.emc.sa.asset.annotation.Asset)4 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)4 InitiatorPortMapRestRep (com.emc.storageos.model.block.export.InitiatorPortMapRestRep)4 ArrayList (java.util.ArrayList)3 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)2 AssetOption (com.emc.vipr.model.catalog.AssetOption)2 ExportPathsPreview (com.emc.sa.service.vipr.block.tasks.ExportPathsPreview)1 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 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)1 ExportPathParams (com.emc.storageos.db.client.model.ExportPathParams)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 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1