Search in sources :

Example 1 with StoragePortGroupRestRep

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

the class MapStoragePortGroup method apply.

@Override
public StoragePortGroupRestRep apply(StoragePortGroup resource) {
    StoragePortGroupRestRep storagePortGroupRestRep = SystemsMapper.map(resource);
    applyPortsToStoragePortGroupRestRep(storagePortGroupRestRep, resource);
    return storagePortGroupRestRep;
}
Also used : StoragePortGroupRestRep(com.emc.storageos.model.portgroup.StoragePortGroupRestRep)

Example 2 with StoragePortGroupRestRep

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

the class BlockProvider method getExportPortGroups.

@Asset("exportChangePortGroup")
@AssetDependencies({ "host", "exportPathStorageSystem", "exportPathVirtualArray", "exportCurrentPortGroup" })
public List<AssetOption> getExportPortGroups(AssetOptionsContext ctx, URI hostOrClusterId, URI storageSystemId, URI varrayId, URI exportCurrentPortGroupId) {
    final ViPRCoreClient client = api(ctx);
    List<AssetOption> options = Lists.newArrayList();
    SimpleValueRep value = client.customConfigs().getCustomConfigTypeValue(VMAX_PORT_GROUP_ENABLED, VMAX);
    if (value.getValue().equalsIgnoreCase("true")) {
        StoragePortGroupRestRepList portGroupsRestRep = client.varrays().getStoragePortGroups(varrayId, null, storageSystemId, null, null, true);
        // Get a handle of the actual port group list
        List<StoragePortGroupRestRep> portGroups = portGroupsRestRep.getStoragePortGroups();
        // Filter out the current port group as we do not want the user to see this an a valid option
        ResourceFilter<StoragePortGroupRestRep> filterExistingPG = new DefaultResourceFilter<StoragePortGroupRestRep>() {

            @Override
            public boolean accept(StoragePortGroupRestRep pg) {
                return !pg.getId().equals(exportCurrentPortGroupId);
            }
        };
        ResourceUtils.applyFilter(portGroups, filterExistingPG);
        return createPortGroupOptions(portGroups);
    }
    return options;
}
Also used : SimpleValueRep(com.emc.storageos.model.customconfig.SimpleValueRep) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) StoragePortGroupRestRep(com.emc.storageos.model.portgroup.StoragePortGroupRestRep) DefaultResourceFilter(com.emc.vipr.client.core.filters.DefaultResourceFilter) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 3 with StoragePortGroupRestRep

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

the class BlockProvider method createPortGroupOptions.

private List<AssetOption> createPortGroupOptions(List<StoragePortGroupRestRep> portGroups) {
    List<AssetOption> options = Lists.newArrayList();
    for (StoragePortGroupRestRep group : portGroups) {
        String portMetric = (group.getPortMetric() != null) ? String.valueOf(Math.round(group.getPortMetric() * 100 / 100)) + "%" : "N/A";
        String volumeCount = (group.getVolumeCount() != null) ? String.valueOf(group.getVolumeCount()) : "N/A";
        String nGuid = group.getNativeGuid();
        String nativeGuid = EMPTY_STRING;
        try {
            // Remove the PG name from the native GUID.
            // Ex:
            // From -> SYMMETRIX+000196801518+lglw7136_pg
            // To -> SYMMETRIX+000196801518
            nativeGuid = nGuid.substring(0, nGuid.lastIndexOf("+", nGuid.length()));
        } catch (Exception e) {
            nativeGuid = nGuid;
            warn("Issue encountered parsing native guid %s, exception: %s", nativeGuid, e.getMessage());
        }
        String label = getMessage("exportPortGroup.portGroups", group.getName(), nativeGuid, portMetric, volumeCount);
        options.add(new AssetOption(group.getId(), label));
    }
    return options;
}
Also used : AssetOption(com.emc.vipr.model.catalog.AssetOption) StoragePortGroupRestRep(com.emc.storageos.model.portgroup.StoragePortGroupRestRep)

Example 4 with StoragePortGroupRestRep

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

the class BlockProvider method getExportPathPorts.

@Asset("exportPathPorts")
@AssetDependencies({ "exportPathVirtualArray", "exportPathStorageSystem", "exportPathExport" })
public List<AssetOption> getExportPathPorts(AssetOptionsContext ctx, URI vArrayId, URI storageSystemId, URI exportId) {
    ViPRCoreClient client = api(ctx);
    List<AssetOption> options = Lists.newArrayList();
    // Get all the PGs for the varray/storage system/EG combo then check to
    // see if there are any non-mutable PGs;
    // if there are the storage ports displayed to the user would be limited
    // to just those ones.
    StoragePortGroupRestRepList portGroupsRestRep = client.varrays().getStoragePortGroups(vArrayId, exportId, storageSystemId, null, null, false);
    // Keep a list of ports from the non-mutable PGs. This could remain
    // empty if there are no PGs or none that are non-mutable.
    List<URI> nonMutablePGPortURIs = new ArrayList<URI>();
    if (portGroupsRestRep != null) {
        // Drill down to get the PG and the storage ports
        List<StoragePortGroupRestRep> portGroups = portGroupsRestRep.getStoragePortGroups();
        if (!CollectionUtils.isEmpty(portGroups)) {
            for (StoragePortGroupRestRep pg : portGroups) {
                // Check to see if the PG is non-mutable
                if (!pg.getMutable()) {
                    // Keep track of these storage ports, they will be used
                    // to filter out
                    // other storage ports.
                    StoragePortList pgPortsList = pg.getStoragePorts();
                    List<NamedRelatedResourceRep> pgPorts = pgPortsList.getPorts();
                    for (NamedRelatedResourceRep pgPort : pgPorts) {
                        nonMutablePGPortURIs.add(pgPort.getId());
                    }
                }
            }
        }
    }
    List<StoragePortRestRep> ports = client.storagePorts().getByVirtualArray(vArrayId);
    for (StoragePortRestRep port : ports) {
        // Check to see if this port needs to be filtered out.
        boolean filterOutPortBasedOnPG = (!nonMutablePGPortURIs.isEmpty()) ? !nonMutablePGPortURIs.contains(port.getId()) : false;
        if (!filterOutPortBasedOnPG) {
            if (port.getPortType().equals(StoragePort.PortType.frontend.toString()) && port.getStorageDevice().getId().equals(storageSystemId) && port.getOperationalStatus().equals(StoragePort.OperationalStatus.OK.toString())) {
                if (port.getNetwork() != null) {
                    String portPercentBusy = (port.getPortPercentBusy() != null) ? String.valueOf(Math.round(port.getPortPercentBusy() * 100 / 100)) + "%" : "N/A";
                    String networkName = client.networks().get(port.getNetwork().getId()).getName();
                    String label = getMessage("exportPathAdjustment.ports", port.getPortName(), networkName, port.getPortNetworkId(), portPercentBusy);
                    options.add(new AssetOption(port.getId(), label));
                }
            }
        }
    }
    AssetOptionsUtils.sortOptionsByLabel(options);
    return options;
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) ArrayList(java.util.ArrayList) StoragePortRestRep(com.emc.storageos.model.ports.StoragePortRestRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) StoragePortGroupRestRep(com.emc.storageos.model.portgroup.StoragePortGroupRestRep) StoragePortList(com.emc.storageos.model.ports.StoragePortList) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 5 with StoragePortGroupRestRep

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

the class VirtualArrayService method getVirtualArrayStoragePortGroups.

/**
 * This method gets storage port groups for a given virtual array. The storage ports in the port group
 * should all be assigned or connected to the virtual array.
 * If export group is specified, it will return the port group used in the export masks belonging to the export
 * group, plus
 * the port groups in the virtual array, but in different storage system from the export masks.
 * If storage system is specified, it will only return the port groups belonging to the storage system.
 * If vpool is specified, it will get the port groups from the same storage system as vpool's storage pools reside.
 * If consistency group is specified, it will return the port groups in the same storage system as the consistency
 * group
 * This API is used by UI to get storage port group list for create and export volumes related catalog services
 *
 * @param id
 *            - Virtual array URI
 * @param storageURI
 *            - OPTIONAL Storage system URI
 * @param exportGroupURI
 *            - OPTIONAL Export group URI
 * @param vpoolURI
 *            - OPTIONAL virtual pool URI
 * @param cgURI
 *            - OPTIONAL consistency group URI
 * @param registeredOnly
 *            - OPTIONAL if true, only registered port group would be returned
 *            if false, both registered and deregistered port group would be returned
 *            if not set, default to true
 * @return - Storage port group list
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public StoragePortGroupRestRepList getVirtualArrayStoragePortGroups(@PathParam("id") URI id, @QueryParam("storage_system") URI storageURI, @QueryParam("export_group") URI exportGroupURI, @QueryParam("vpool") URI vpoolURI, @QueryParam("consistency_group") URI cgURI, @QueryParam("registered_only") Boolean registeredOnly) {
    // Get and validate the varray with the passed id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntity(varray, id, isIdEmbeddedInURL(id));
    Set<URI> portURIs = new HashSet<URI>();
    // Query the database for the storage ports associated with the
    // VirtualArray.
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
    for (URI portURI : storagePortURIs) {
        portURIs.add(portURI);
    }
    Set<URI> portGroupURIs = new HashSet<URI>();
    StoragePortGroupRestRepList portGroups = new StoragePortGroupRestRepList();
    Set<URI> excludeSystem = new HashSet<URI>();
    if (storageURI != null) {
        StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageURI);
        if (!Type.vmax.name().equals(storageSystem.getSystemType())) {
            _log.info(String.format("The specified storage system %s is type %s, no port group supported", storageURI.toString(), storageSystem.getSystemType()));
            return portGroups;
        }
    }
    if (cgURI != null) {
        BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgURI);
        if (cg != null) {
            URI cgStorage = cg.getStorageController();
            if (!NullColumnValueGetter.isNullURI(cgStorage)) {
                if (storageURI != null && !storageURI.equals(cgStorage)) {
                    _log.error(String.format("The consistency group %s storage system %s does not match the passed in storageURI %s", cg.getLabel(), cgStorage.toString(), storageURI.toString()));
                    return portGroups;
                } else if (storageURI == null) {
                    StorageSystem cgSystem = _dbClient.queryObject(StorageSystem.class, cgStorage);
                    if (Type.vmax.name().equals(cgSystem.getSystemType())) {
                        storageURI = cgStorage;
                    } else {
                        _log.info(String.format("The consistency group %s storage system %s is %s. port group is not supported", cg.getLabel(), cgSystem.getNativeGuid(), cgSystem.getSystemType()));
                        return portGroups;
                    }
                }
            }
        }
    }
    Set<URI> includedSystems = new HashSet<URI>();
    if (storageURI != null) {
        includedSystems.add(storageURI);
    }
    if (vpoolURI != null) {
        // vpool is specified. Get storage port groups belonging to the same storage system as the vpool
        // valid storage pools.
        ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
        VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
        if (VirtualPool.vPoolSpecifiesHighAvailability(vpool)) {
            // This is vplex, return empty
            _log.warn(String.format("The vpool %s is for vplex, no port group is supported", vpool.getLabel()));
            return portGroups;
        }
        List<StoragePool> pools = VirtualPool.getValidStoragePools(vpool, _dbClient, true);
        Set<URI> poolSystems = new HashSet<URI>();
        if (!CollectionUtils.isEmpty(pools)) {
            for (StoragePool pool : pools) {
                URI poolSystemURI = pool.getStorageDevice();
                if (storageURI != null && storageURI.equals(poolSystemURI)) {
                    poolSystems.add(poolSystemURI);
                } else if (storageURI == null) {
                    poolSystems.add(poolSystemURI);
                }
            }
            if (poolSystems.isEmpty()) {
                // No valid storage system belong to the vpool
                _log.info(String.format("The virtual pool %s does not have any pool in the valid storage system", vpool.getLabel()));
                return portGroups;
            } else {
                includedSystems.addAll(poolSystems);
            }
        } else {
            _log.warn(String.format("The vpool %s does not have any valid storage pools, no port group returned", vpool.getLabel()));
            return portGroups;
        }
    }
    if (exportGroupURI != null) {
        // When export group URI is specified, it would return all the port groups current used in the export masks,
        // (no other port groups in the same storage system will be returned.) plus the port groups in the other
        // storage systems
        // which are available in the virtual array.
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        if (exportGroup == null || !id.equals(exportGroup.getVirtualArray())) {
            _log.error(String.format("The export group %s is not valid", exportGroupURI.toString()));
            return portGroups;
        }
        StringSet exportMasks = exportGroup.getExportMasks();
        if (!CollectionUtils.isEmpty(exportMasks)) {
            for (String emStr : exportMasks) {
                URI maskUri = URI.create(emStr);
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, maskUri);
                if (exportMask == null) {
                    continue;
                }
                if (NullColumnValueGetter.isNullURI(exportMask.getPortGroup())) {
                    continue;
                }
                if ((!NullColumnValueGetter.isNullURI(storageURI) && storageURI.equals(exportMask.getStorageDevice())) || includedSystems.isEmpty() || includedSystems.contains(exportMask.getStorageDevice())) {
                    portGroupURIs.add(exportMask.getPortGroup());
                }
                // Add the export mask storage system to the exclude systems, so that no other port groups from the
                // same storage system would be returned
                excludeSystem.add(exportMask.getStorageDevice());
            }
        }
    }
    for (URI portURI : portURIs) {
        // Get port groups for each port
        StoragePort port = _dbClient.queryObject(StoragePort.class, portURI);
        if (port == null || (storageURI != null && !storageURI.equals(port.getStorageDevice())) || excludeSystem.contains(port.getStorageDevice())) {
            continue;
        }
        if (!includedSystems.isEmpty() && !includedSystems.contains(port.getStorageDevice())) {
            continue;
        }
        if ((port != null) && (RegistrationStatus.REGISTERED.toString().equals(port.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(port.getDiscoveryStatus())) {
            URIQueryResultList pgURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortPortGroupConstraint(portURI), pgURIs);
            for (URI groupURI : pgURIs) {
                portGroupURIs.add(groupURI);
            }
        }
    }
    // Sort the list based on its metrics
    Iterator<StoragePortGroup> it = _dbClient.queryIterativeObjects(StoragePortGroup.class, portGroupURIs, true);
    List<StoragePortGroup> sortPGs = new ArrayList<StoragePortGroup>();
    while (it.hasNext()) {
        sortPGs.add(it.next());
    }
    Collections.sort(sortPGs, new StoragePortGroupComparator());
    boolean checkRegistered = (registeredOnly != null ? registeredOnly : true);
    // return the result.
    for (StoragePortGroup portGroup : sortPGs) {
        if (portGroup != null && !portGroup.getInactive() && (!checkRegistered || portGroup.isUsable()) && portURIs.containsAll(StringSetUtil.stringSetToUriList(portGroup.getStoragePorts()))) {
            StoragePortGroupRestRep pgRep = MapStoragePortGroup.getInstance(_dbClient).toStoragePortGroupRestRep(portGroup);
            portGroups.getStoragePortGroups().add(pgRep);
        }
    }
    return portGroups;
}
Also used : MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StoragePool(com.emc.storageos.db.client.model.StoragePool) ExportMask(com.emc.storageos.db.client.model.ExportMask) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) 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) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StoragePortGroupRestRep (com.emc.storageos.model.portgroup.StoragePortGroupRestRep)6 StoragePortGroupRestRepList (com.emc.storageos.model.portgroup.StoragePortGroupRestRepList)3 AssetOption (com.emc.vipr.model.catalog.AssetOption)3 Asset (com.emc.sa.asset.annotation.Asset)2 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)2 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MapStoragePortGroup (com.emc.storageos.api.mapper.functions.MapStoragePortGroup)1 MapVirtualArray (com.emc.storageos.api.mapper.functions.MapVirtualArray)1 StoragePortGroupComparator (com.emc.storageos.api.service.impl.resource.utils.StoragePortGroupComparator)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)1 ExportMask (com.emc.storageos.db.client.model.ExportMask)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)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