Search in sources :

Example 1 with StoragePortGroupChangeList

use of com.emc.storageos.model.portgroup.StoragePortGroupChangeList in project coprhd-controller by CoprHD.

the class ExportGroupService method getPortGroupsForPortGroupChange.

/**
 * Get list of eligible port groups for Change Port Group for Host operation.
 * This API returns the list of Port Groups that a user can choose from for the Change Port Group for Host operation. Currently this API
 * is available only for VMAX systems
 *
 * @param currentPortGroupURI contains CurrentPortGroup
 * @param hostOrClusterIDURI contains Host/ClusterID
 * @param varrayIDURI contains varrayID
 * @return the list of port groups that are eligible for CHnage Port Group for Host
 * @throws ControllerException
 */
@GET
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/target-storage-port-groups")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public StoragePortGroupChangeList getPortGroupsForPortGroupChange(@QueryParam("currentPortGroup") String currentPortGroupURI, @QueryParam("hostOrClusterID") String hostOrClusterIDURI, @QueryParam("varrayID") String varrayIDURI) throws ControllerException {
    ArgValidator.checkFieldNotEmpty(currentPortGroupURI, "currentPortGroup");
    ArgValidator.checkFieldNotEmpty(hostOrClusterIDURI, "hostOrClusterID");
    ArgValidator.checkFieldNotEmpty(varrayIDURI, "varrayID");
    ArgValidator.checkUri(URIUtil.uri(currentPortGroupURI));
    _log.info("verfying Port Group id: {}", currentPortGroupURI);
    ArgValidator.checkUri(URIUtil.uri(hostOrClusterIDURI));
    _log.info("verfying Host/Cluster id: {}", hostOrClusterIDURI);
    ArgValidator.checkUri(URIUtil.uri(varrayIDURI));
    _log.info("verfying Virtual Array id: {}", varrayIDURI);
    // Get the current port group
    StoragePortGroup currentPortGroup = queryObject(StoragePortGroup.class, URIUtil.uri(currentPortGroupURI), true);
    // Get the storage system of current port group
    URI currrentPortGroupStorageSystem = currentPortGroup.getStorageDevice();
    StorageSystem currentStorageSystem = queryObject(StorageSystem.class, currrentPortGroupStorageSystem, true);
    _log.info("storage system of current port group: {}", currentStorageSystem.getId());
    // Get the ports of the current port group
    StringSet currentPortGroupPorts = currentPortGroup.getStoragePorts();
    // Get the current Export Group
    URIQueryResultList exportMasksURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMasksByPortGroup(currentPortGroup.getId().toString()), exportMasksURIs);
    Set<URI> exportMaskURI = new HashSet<URI>();
    for (URI exportMaskURIiterator : exportMasksURIs) {
        exportMaskURI.add(exportMaskURIiterator);
    }
    ExportGroup currentExportGroup = new ExportGroup();
    URIQueryResultList exportGroupURIs = new URIQueryResultList();
    for (URI exportMaskURIiterator : exportMaskURI) {
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getExportMaskExportGroupConstraint(exportMaskURIiterator), exportGroupURIs);
        int flag = 0;
        for (URI exportGroupURIiterator : exportGroupURIs) {
            ExportGroup trialExportGroup = queryObject(ExportGroup.class, exportGroupURIiterator, true);
            Set<String> hostsInExportGroup = trialExportGroup.getHosts();
            Set<String> clustersInExportGroup = trialExportGroup.getClusters();
            if ((hostsInExportGroup != null && hostsInExportGroup.contains(URIUtil.uri(hostOrClusterIDURI).toString())) || (clustersInExportGroup != null && clustersInExportGroup.contains(URIUtil.uri(hostOrClusterIDURI).toString()))) {
                currentExportGroup = trialExportGroup;
                _log.info("the ExportGroup of current port group is: {}", currentExportGroup.getId());
                flag = 1;
                break;
            }
        }
        if (flag == 1) {
            break;
        }
    }
    // Get volumes currently in Export Group
    List<URI> volumes = new ArrayList<URI>();
    for (Map.Entry<String, String> entry : currentExportGroup.getVolumes().entrySet()) {
        URI volumeToAdd = URI.create(entry.getKey().toString());
        if (volumeToAdd != null) {
            volumes.add(volumeToAdd);
        }
    }
    // Get current ExportPathParams
    ExportPathParams pathParams = _blockStorageScheduler.calculateExportPathParamForVolumes(volumes, currentExportGroup.getNumPaths(), currentStorageSystem.getId(), currentExportGroup.getId());
    // Get initiators of Export Group
    List<Initiator> currentInitiators = getInitiators(currentExportGroup);
    StoragePortGroupChangeList invalidPortGroupList = new StoragePortGroupChangeList();
    // Get the port groups associated with the ports in the varray and the storage system
    List<StoragePortGroup> listOfPortGroups = new ArrayList<StoragePortGroup>();
    Set<URI> setOfpgURIs = new HashSet<URI>();
    Set<String> currentSystemPortsInVarray = ExportMaskUtils.getStoragePortUrisAssociatedWithVarrayAndStorageArray(currentPortGroup.getStorageDevice(), URIUtil.uri(varrayIDURI), _dbClient);
    if (null != currentSystemPortsInVarray && !currentSystemPortsInVarray.isEmpty()) {
        for (String portUriStr : currentSystemPortsInVarray) {
            URIQueryResultList pgURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortPortGroupConstraint(URIUtil.uri(portUriStr)), pgURIs);
            setOfpgURIs.addAll(pgURIs);
        }
        Iterator<StoragePortGroup> _dbIterator = _dbClient.queryIterativeObjects(StoragePortGroup.class, setOfpgURIs);
        listOfPortGroups = IteratorUtils.toList(_dbIterator);
    }
    // remove port groups from the list if they do not follow conditions
    for (Iterator<StoragePortGroup> it = listOfPortGroups.iterator(); it.hasNext(); ) {
        StoragePortGroup trialPortGroup = it.next();
        StringBuffer notAllowedReasonBuff = new StringBuffer();
        // Remove trialPortGroup if it is inactive or not usable
        if (trialPortGroup == null || trialPortGroup.getInactive() || !trialPortGroup.isUsable()) {
            it.remove();
            notAllowedReasonBuff.append("Is either Inactive or not usable");
            invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
            continue;
        }
        // Remove trialPortGroup if it is the same as the currentPortGroup
        if (trialPortGroup.getId().equals(currentPortGroup.getId())) {
            _log.info("filtered out port group {} because it is the same as the current port group", trialPortGroup.getId());
            it.remove();
            notAllowedReasonBuff.append("Same as the current port group");
            invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
            continue;
        }
        // Remove trialPortGroup if it has overlapping ports with currentPortGroup
        StringSet trialPortGroupPorts = trialPortGroup.getStoragePorts();
        if (!Collections.disjoint(trialPortGroupPorts, currentPortGroupPorts)) {
            _log.info("filtered out port group {}  because it has ports overlapping the current port group", trialPortGroup.getId());
            it.remove();
            notAllowedReasonBuff.append("Ports overlapping with current port group");
            invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
            continue;
        }
        // Remove trialPortGroup if its ports do not fulfill ExportPathParams of the currentPortGroup
        pathParams.setStoragePorts(trialPortGroup.getStoragePorts());
        Map<URI, List<URI>> assignment = null;
        try {
            assignment = _blockStorageScheduler.verifyStoragePortGroups(currentStorageSystem, currentExportGroup.getVirtualArray(), currentInitiators, pathParams, new StringSetMap(), volumes);
            if (CollectionUtils.isEmpty(assignment)) {
                _log.info("filtered out port group {}  because it does not fulfil ExportPathParams of existing PortGroup", trialPortGroup.getId());
                it.remove();
                notAllowedReasonBuff.append("Does not fulfil ExportPathParams of existing PortGroup");
                invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
                continue;
            }
        } catch (Exception e) {
            _log.debug("filtered out the current port group because: {}", e.getMessage());
            if (CollectionUtils.isEmpty(assignment)) {
                it.remove();
                notAllowedReasonBuff.append(e.getMessage());
                invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
                continue;
            }
        }
    }
    StoragePortGroupChangeList changePortGroupList = new StoragePortGroupChangeList();
    // Sort the list based on its metrics
    Collections.sort(listOfPortGroups, new StoragePortGroupComparator());
    // Add the valid PGs
    for (StoragePortGroup portGroup : listOfPortGroups) {
        StoragePortGroupChangeRep changePG = new StoragePortGroupChangeRep(null, true);
        StoragePortGroupRestRep pgRep = MapStoragePortGroup.getInstance(_dbClient).toStoragePortGroupRestRep(portGroup);
        changePG.setChangePGOtherParams(pgRep);
        changePortGroupList.getPortGroups().add(changePG);
    }
    // Add invalid PGs
    for (StoragePortGroupChangeRep invalidPG : invalidPortGroupList.getPortGroups()) {
        changePortGroupList.getPortGroups().add(invalidPG);
    }
    return changePortGroupList;
}
Also used : MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) ArrayList(java.util.ArrayList) 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) StoragePortGroupRestRep(com.emc.storageos.model.portgroup.StoragePortGroupRestRep) StoragePortGroupComparator(com.emc.storageos.api.service.impl.resource.utils.StoragePortGroupComparator) StringSet(com.emc.storageos.db.client.model.StringSet) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) StoragePortGroupChangeList(com.emc.storageos.model.portgroup.StoragePortGroupChangeList) 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) HashSet(java.util.HashSet) StoragePortGroupChangeList(com.emc.storageos.model.portgroup.StoragePortGroupChangeList) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StoragePortGroupChangeRep(com.emc.storageos.model.portgroup.StoragePortGroupChangeRep) 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) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) PlacementException(com.emc.storageos.volumecontroller.placement.PlacementException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with StoragePortGroupChangeList

use of com.emc.storageos.model.portgroup.StoragePortGroupChangeList in project coprhd-controller by CoprHD.

the class BlockExports method getPortGroupsForPortGroupChange.

/**
 * Generate a list of Target Port Groups
 * <p>
 * API Call: <tt>GET /block/exports/target-storage-port-groups</tt>
 *
 * @param currentPortGroup has input details of current port group
 * @param hostOrClusterID has input details of host or cluster ID
 * @param varrayID has input details of current virtual array id
 * @return List of Port Groups that are eligible
 */
public List<StoragePortGroupChangeRep> getPortGroupsForPortGroupChange(URI currentPortGroup, URI hostOrClusterID, URI varrayID) {
    Properties queryParam = new Properties();
    queryParam.setProperty("currentPortGroup", currentPortGroup.toString());
    queryParam.setProperty("hostOrClusterID", hostOrClusterID.toString());
    queryParam.setProperty("varrayID", varrayID.toString());
    StoragePortGroupChangeList response = client.get(StoragePortGroupChangeList.class, baseUrl + "/target-storage-port-groups", queryParam);
    return defaultList(response.getPortGroups());
}
Also used : StoragePortGroupChangeList(com.emc.storageos.model.portgroup.StoragePortGroupChangeList) Properties(java.util.Properties)

Aggregations

StoragePortGroupChangeList (com.emc.storageos.model.portgroup.StoragePortGroupChangeList)2 MapStoragePortGroup (com.emc.storageos.api.mapper.functions.MapStoragePortGroup)1 StoragePortGroupComparator (com.emc.storageos.api.service.impl.resource.utils.StoragePortGroupComparator)1 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)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 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 StoragePortGroup (com.emc.storageos.db.client.model.StoragePortGroup)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1