Search in sources :

Example 6 with StoragePortGroupRestRepList

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

the class BlockProvider method getExportContinousCopyForHostPortGroups.

@Asset("exportContinousCopyForHostPortGroups")
@AssetDependencies({ "volumeWithContinuousCopies", "unassignedBlockContinuousCopies", "host", "project" })
public List<AssetOption> getExportContinousCopyForHostPortGroups(AssetOptionsContext ctx, URI volumeId, String selectedCopies, URI hostOrClusterId, URI projectId) {
    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")) {
        List<URI> snapshotIds = Lists.newArrayList();
        info("Continous Copies selected by user: %s", selectedCopies);
        List<String> parsedCopiesIds = TextUtils.parseCSV(selectedCopies);
        for (String id : parsedCopiesIds) {
            snapshotIds.add(uri(id));
        }
        List<BlockMirrorRestRep> copies = client.blockVolumes().getContinuousCopies(volumeId);
        Set<URI> virtualArrays = new HashSet<URI>();
        Set<URI> storageSystems = new HashSet<URI>();
        Set<URI> virtualPools = new HashSet<URI>();
        for (BlockMirrorRestRep copy : copies) {
            virtualArrays.add(copy.getVirtualArray().getId());
            storageSystems.add(copy.getStorageController());
            virtualPools.add(copy.getVirtualPool().getId());
        }
        if (virtualArrays.size() == 1 && storageSystems.size() == 1 && virtualPools.size() == 1) {
            Iterator<URI> it = virtualArrays.iterator();
            URI varrayId = it.next();
            ExportGroupRestRep export = findExportGroup(hostOrClusterId, projectId, varrayId, client);
            Iterator<URI> ssIt = storageSystems.iterator();
            Iterator<URI> vpIt = virtualPools.iterator();
            StoragePortGroupRestRepList portGroups = client.varrays().getStoragePortGroups(varrayId, export != null ? export.getId() : null, ssIt.next(), vpIt.next(), null, true);
            return createPortGroupOptions(portGroups.getStoragePortGroups());
        }
    }
    return options;
}
Also used : SimpleValueRep(com.emc.storageos.model.customconfig.SimpleValueRep) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) BlockMirrorRestRep(com.emc.storageos.model.block.BlockMirrorRestRep) URI(java.net.URI) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) HashSet(java.util.HashSet) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 7 with StoragePortGroupRestRepList

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

the class BlockProvider method getExportVolumePortGroups.

@Asset("exportVolumePortGroups")
@AssetDependencies({ "unassignedBlockVolume", "host", "project" })
public List<AssetOption> getExportVolumePortGroups(AssetOptionsContext ctx, String selectedVolumes, URI hostOrClusterId, URI projectId) {
    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")) {
        List<URI> volumeIds = Lists.newArrayList();
        info("Volumes selected by user: %s", selectedVolumes);
        List<String> parsedVolumeIds = TextUtils.parseCSV(selectedVolumes);
        for (String id : parsedVolumeIds) {
            volumeIds.add(uri(id));
        }
        List<VolumeRestRep> volumes = client.blockVolumes().getByIds(volumeIds);
        Set<URI> virtualArrays = new HashSet<URI>();
        Set<URI> storageSystems = new HashSet<URI>();
        Set<URI> virtualPools = new HashSet<URI>();
        for (VolumeRestRep volume : volumes) {
            virtualArrays.add(volume.getVirtualArray().getId());
            storageSystems.add(volume.getStorageController());
            virtualPools.add(volume.getVirtualPool().getId());
        }
        if (virtualArrays.size() == 1 && storageSystems.size() == 1 && virtualPools.size() == 1) {
            Iterator<URI> it = virtualArrays.iterator();
            URI varrayId = it.next();
            ExportGroupRestRep export = findExportGroup(hostOrClusterId, projectId, varrayId, client);
            Iterator<URI> ssIt = storageSystems.iterator();
            Iterator<URI> vpIt = virtualPools.iterator();
            StoragePortGroupRestRepList portGroups = client.varrays().getStoragePortGroups(varrayId, export != null ? export.getId() : null, ssIt.next(), vpIt.next(), null, true);
            return createPortGroupOptions(portGroups.getStoragePortGroups());
        }
    }
    return options;
}
Also used : SimpleValueRep(com.emc.storageos.model.customconfig.SimpleValueRep) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) URI(java.net.URI) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) HashSet(java.util.HashSet) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 8 with StoragePortGroupRestRepList

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

the class BlockProvider method getExportSnapshotForHostPortGroups.

@Asset("exportSnapshotForHostPortGroups")
@AssetDependencies({ "unassignedBlockSnapshot", "host", "project" })
public List<AssetOption> getExportSnapshotForHostPortGroups(AssetOptionsContext ctx, String selectedSnapshots, URI hostOrClusterId, URI projectId) {
    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")) {
        List<URI> snapshotIds = Lists.newArrayList();
        info("Snapshots selected by user: %s", selectedSnapshots);
        List<String> parsedSnapshotIds = TextUtils.parseCSV(selectedSnapshots);
        for (String id : parsedSnapshotIds) {
            snapshotIds.add(uri(id));
        }
        List<BlockSnapshotRestRep> snapshots = client.blockSnapshots().getByIds(snapshotIds);
        Set<URI> virtualArrays = new HashSet<URI>();
        Set<URI> storageSystems = new HashSet<URI>();
        for (BlockSnapshotRestRep snapshot : snapshots) {
            virtualArrays.add(snapshot.getVirtualArray().getId());
            storageSystems.add(snapshot.getStorageController());
        }
        if (virtualArrays.size() == 1 && storageSystems.size() == 1) {
            Iterator<URI> it = virtualArrays.iterator();
            URI varrayId = it.next();
            ExportGroupRestRep export = findExportGroup(hostOrClusterId, projectId, varrayId, client);
            Iterator<URI> ssIt = storageSystems.iterator();
            StoragePortGroupRestRepList portGroups = client.varrays().getStoragePortGroups(varrayId, export != null ? export.getId() : null, ssIt.next(), null, null, true);
            return createPortGroupOptions(portGroups.getStoragePortGroups());
        }
    }
    return options;
}
Also used : SimpleValueRep(com.emc.storageos.model.customconfig.SimpleValueRep) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AssetOption(com.emc.vipr.model.catalog.AssetOption) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) URI(java.net.URI) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) HashSet(java.util.HashSet) AssetDependencies(com.emc.sa.asset.annotation.AssetDependencies) Asset(com.emc.sa.asset.annotation.Asset)

Example 9 with StoragePortGroupRestRepList

use of com.emc.storageos.model.portgroup.StoragePortGroupRestRepList 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

StoragePortGroupRestRepList (com.emc.storageos.model.portgroup.StoragePortGroupRestRepList)9 Asset (com.emc.sa.asset.annotation.Asset)8 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)8 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)8 AssetOption (com.emc.vipr.model.catalog.AssetOption)8 SimpleValueRep (com.emc.storageos.model.customconfig.SimpleValueRep)7 URI (java.net.URI)5 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)4 HashSet (java.util.HashSet)4 StoragePortGroupRestRep (com.emc.storageos.model.portgroup.StoragePortGroupRestRep)3 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