Search in sources :

Example 86 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VirtualPoolService method checkPoolsWithResources.

/**
 * Check whether the pools with vpool resources are part of the assigned pools.
 * We should not allow removal of pools with resources.
 *
 * @param poolAssignmentChanges
 * @param vpool
 * @param dbClient
 */
public void checkPoolsWithResources(StoragePoolAssignmentChanges poolAssignmentChanges, VirtualPool vpool, DbClient dbClient) {
    Set<String> poolsToCheck = new StringSet();
    // Find the pools which need to be checked for resources.
    if (vpool.getMatchedStoragePools() == null) {
        throw APIException.badRequests.invalidParameterNoMatchingPoolsExistToAssignPools(vpool.getId());
    }
    Set<String> vPoolMatchedPools = (StringSet) vpool.getMatchedStoragePools().clone();
    if (vpool.getAssignedStoragePools() != null && !vpool.getAssignedStoragePools().isEmpty()) {
        vPoolMatchedPools.removeAll(vpool.getAssignedStoragePools());
    }
    if (poolAssignmentChanges != null && poolAssignmentChanges.getAdd() != null) {
        if (poolAssignmentChanges.getAdd().getStoragePools() != null && !poolAssignmentChanges.getAdd().getStoragePools().isEmpty()) {
            vPoolMatchedPools.removeAll(poolAssignmentChanges.getAdd().getStoragePools());
        }
    }
    poolsToCheck.addAll(vPoolMatchedPools);
    if (poolAssignmentChanges != null && poolAssignmentChanges.getRemove() != null) {
        if (poolAssignmentChanges.getRemove().getStoragePools() != null && !poolAssignmentChanges.getRemove().getStoragePools().isEmpty()) {
            poolsToCheck.addAll(poolAssignmentChanges.getRemove().getStoragePools());
        }
    }
    Set<String> resourcePools = getPoolsWithVPoolResources(vpool, poolsToCheck, dbClient);
    if (!resourcePools.isEmpty()) {
        Set<String> poolNames = new StringSet();
        for (String poolUri : resourcePools) {
            StoragePool pool = dbClient.queryObject(StoragePool.class, URI.create(poolUri));
            poolNames.add(pool.getPoolName());
        }
        throw APIException.badRequests.cannotRemovePoolWithResources(poolNames);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 87 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VolumeGroupService method getUnlinkTargetIdsForSession.

/**
 * Gets the unlink target ids for the given session.
 *
 * @param param the VolumeGroupSnapshotSessionUnlinkTargetsParam
 * @param session the snap session
 * @return the unlink target id params for session
 */
private List<SnapshotSessionUnlinkTargetParam> getUnlinkTargetIdsForSession(final VolumeGroupSnapshotSessionUnlinkTargetsParam param, BlockSnapshotSession session) {
    List<SnapshotSessionUnlinkTargetParam> targetIds = new ArrayList<SnapshotSessionUnlinkTargetParam>();
    List<URI> selectedURIs = new ArrayList<URI>();
    StringSet sessionTargets = session.getLinkedTargets();
    if (param.getLinkedTargets() != null && !param.getLinkedTargets().isEmpty()) {
        for (SnapshotSessionUnlinkTargetParam unlinkTarget : param.getLinkedTargets()) {
            URI snapURI = unlinkTarget.getId();
            // Snapshot session targets are represented by BlockSnapshot instances in ViPR.
            ArgValidator.checkFieldUriType(snapURI, BlockSnapshot.class, "id");
            BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
            ArgValidator.checkEntityNotNull(snap, snapURI, isIdEmbeddedInURL(snapURI));
            if (sessionTargets != null && sessionTargets.contains(snapURI.toString())) {
                targetIds.add(unlinkTarget);
                selectedURIs.add(snapURI);
            }
        }
    } else {
        ArgValidator.checkFieldNotEmpty(param.getTargetName(), "target_name");
        for (String linkedTgtId : session.getLinkedTargets()) {
            URI snapURI = URI.create(linkedTgtId);
            BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
            if (StringUtils.equals(param.getTargetName(), snap.getSnapsetLabel())) {
                SnapshotSessionUnlinkTargetParam unlinkTarget = new SnapshotSessionUnlinkTargetParam();
                unlinkTarget.setId(snap.getId());
                unlinkTarget.setDeleteTarget(param.getDeleteTarget() == null ? false : param.getDeleteTarget());
                targetIds.add(unlinkTarget);
                selectedURIs.add(snapURI);
            }
        }
    }
    log.info(String.format("Target ids for snapshot session %s : %s", session.getLabel(), Joiner.on(',').join(selectedURIs)));
    if (targetIds.isEmpty()) {
        // None of the provided target belong to this snapshot session.
        throw APIException.badRequests.snapshotSessionDoesNotHaveAnyTargets(session.getId().toString());
    }
    return targetIds;
}
Also used : SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)

Example 88 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VolumeGroupService method getRelinkTargetIdsForSession.

/**
 * Gets the relink target ids for the given session.
 *
 * @param param the VolumeGroupSnapshotSessionRelinkTargetsParam
 * @param session the snap session
 * @param numberOfRequestedSessions the number of requested sessions
 * @return the relink target ids for session
 */
private List<URI> getRelinkTargetIdsForSession(final VolumeGroupSnapshotSessionRelinkTargetsParam param, BlockSnapshotSession session, int numberOfRequestedSessions) {
    List<URI> targetIds = new ArrayList<URI>();
    if (param.getLinkedTargetIds() != null && !param.getLinkedTargetIds().isEmpty() && numberOfRequestedSessions == 1) {
        /**
         * It could be a request from user to re-link targets to different snap sessions.
         * So, don't filter given targets based on snap session.
         *
         * Re-linking different targets to a snap session can be done for only one
         * Replication group at a time.
         */
        targetIds = param.getLinkedTargetIds();
    } else {
        /**
         * Re-link to same linked targets
         */
        StringSet sessionTargets = session.getLinkedTargets();
        if (param.getLinkedTargetIds() != null && !param.getLinkedTargetIds().isEmpty()) {
            for (URI snapURI : param.getLinkedTargetIds()) {
                // Snapshot session targets are represented by BlockSnapshot instances in ViPR.
                ArgValidator.checkFieldUriType(snapURI, BlockSnapshot.class, "id");
                BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
                ArgValidator.checkEntityNotNull(snap, snapURI, isIdEmbeddedInURL(snapURI));
                if (sessionTargets != null && sessionTargets.contains(snapURI.toString())) {
                    targetIds.add(snapURI);
                }
            }
        } else {
            ArgValidator.checkFieldNotEmpty(param.getTargetName(), "target_name");
            for (String linkedTgtId : session.getLinkedTargets()) {
                URI snapURI = URI.create(linkedTgtId);
                BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
                if (StringUtils.equals(param.getTargetName(), snap.getSnapsetLabel())) {
                    targetIds.add(snapURI);
                }
            }
        }
    }
    log.info(String.format("Target ids for snapshot session %s : %s", session.getLabel(), Joiner.on(',').join(targetIds)));
    if (targetIds.isEmpty()) {
        // None of the provided target belong to this snapshot session.
        throw APIException.badRequests.snapshotSessionDoesNotHaveAnyTargetsInGivenList(session.getId().toString());
    }
    return targetIds;
}
Also used : ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)

Example 89 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method updateBackendVolumeToMirrorVpoolMap.

/**
 * Convenience method to update backendVolumeToMirrorVpoolMap for the VPLEX Distributed volume.
 * In case if there is already mirror for the vplex volume, this method ensures
 * to add entry to the map only if there isn't already mirror on either leg.
 *
 * @param vplexVolume The reference to vplex distributed volume
 * @param associatedVolumeIds URIs of the associated volumes
 * @param sourceVirtualPool The reference to virtual pool to which vplex volume is associated with
 * @param sourceMirrorVPool The reference to virtual pool for the mirror on the source side
 * @param haMirrorVPool The reference to virtual pool for the mirror on the HA side
 * @param backendVolumeToMirrorVpoolMap OUT param containing map of backend volume to mirror vpool
 */
private void updateBackendVolumeToMirrorVpoolMap(Volume vplexVolume, StringSet associatedVolumeIds, VirtualPool sourceVirtualPool, VirtualPool sourceMirrorVPool, VirtualPool haMirrorVPool, Map<Volume, VirtualPool> backendVolumeToMirrorVpoolMap) {
    Set<String> vplexClusterWithMirrorForVolume = new HashSet<String>();
    // Set vplexClusterWithMirrorForVolume contains Vplex Cluster on which mirror already exist for the vplex volume
    if (vplexVolume.getMirrors() != null && !vplexVolume.getMirrors().isEmpty()) {
        StringSet existingMirrors = vplexVolume.getMirrors();
        for (String existingMirrorURI : existingMirrors) {
            VplexMirror existingMirror = _dbClient.queryObject(VplexMirror.class, URI.create(existingMirrorURI));
            if (existingMirror != null && !existingMirror.getInactive()) {
                String cluster = ConnectivityUtil.getVplexClusterForVarray(existingMirror.getVirtualArray(), vplexVolume.getStorageController(), _dbClient);
                checkIfClusterIsUnknown(cluster, existingMirror.getVirtualArray().toString(), vplexVolume.getStorageController().toString());
                vplexClusterWithMirrorForVolume.add(cluster);
            }
        }
        s_logger.info("Vplex Mirror(s) already exists for Vplex volume" + vplexVolume.getLabel() + " " + vplexVolume.getId() + " on cluster " + vplexClusterWithMirrorForVolume);
    }
    for (String associatedVolumeId : associatedVolumeIds) {
        if (sourceMirrorVPool != null && sourceVirtualPool.getMaxNativeContinuousCopies() > 0) {
            // Get the source backend volume
            Volume associatedVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, true, _dbClient);
            if (associatedVolume != null && associatedVolume.getId().toString().equals(associatedVolumeId)) {
                if (!vplexClusterWithMirrorForVolume.isEmpty()) {
                    // Get the vplex cluster for the source varray
                    String cluster = ConnectivityUtil.getVplexClusterForVarray(vplexVolume.getVirtualArray(), vplexVolume.getStorageController(), _dbClient);
                    checkIfClusterIsUnknown(cluster, vplexVolume.getVirtualArray().toString(), vplexVolume.getStorageController().toString());
                    // If there isn't already mirror on the source side then add entry to backendVolumeToMirrorVpoolMap
                    if (!vplexClusterWithMirrorForVolume.contains(cluster)) {
                        backendVolumeToMirrorVpoolMap.put(associatedVolume, sourceMirrorVPool);
                    }
                } else {
                    backendVolumeToMirrorVpoolMap.put(associatedVolume, sourceMirrorVPool);
                }
            }
        } else {
            s_logger.info("The max native continuous copies for the source Vpool {} is {} ", sourceVirtualPool.getLabel(), sourceVirtualPool.getMaxNativeContinuousCopies());
            if (sourceMirrorVPool == null) {
                s_logger.info("The mirror will not be created on the source side as the source mirror pool is not provided " + "in the virtual pool {} {}", sourceVirtualPool.getLabel(), sourceVirtualPool.getId());
            }
        }
        VirtualPool haVPool = VirtualPool.getHAVPool(sourceVirtualPool, _dbClient);
        if (haMirrorVPool != null && haVPool != null && haVPool.getMaxNativeContinuousCopies() > 0) {
            // Get the HA backend volume
            Volume associatedVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, false, _dbClient);
            if (associatedVolume != null && associatedVolume.getId().toString().equals(associatedVolumeId)) {
                if (!vplexClusterWithMirrorForVolume.isEmpty()) {
                    // Get HA varray
                    URI haVarrayURI = VPlexUtil.getHAVarray(sourceVirtualPool);
                    if (haVarrayURI != null) {
                        // Get the vplex cluster for the HA varray
                        String cluster = ConnectivityUtil.getVplexClusterForVarray(haVarrayURI, vplexVolume.getStorageController(), _dbClient);
                        checkIfClusterIsUnknown(cluster, haVarrayURI.toString(), vplexVolume.getStorageController().toString());
                        // If there isn't already mirror on the HA side then add entry to backendVolumeToMirrorVpoolMap
                        if (!vplexClusterWithMirrorForVolume.contains(cluster)) {
                            backendVolumeToMirrorVpoolMap.put(associatedVolume, haMirrorVPool);
                        }
                    }
                } else {
                    backendVolumeToMirrorVpoolMap.put(associatedVolume, haMirrorVPool);
                }
            }
        } else {
            if (haVPool != null) {
                s_logger.info("The max native continuous copies for the HA Vpool {} is {} ", haVPool.getLabel(), haVPool.getMaxNativeContinuousCopies());
                if (haMirrorVPool == null) {
                    s_logger.info("The mirror will not be created on the HA side as the HA mirror pool is not provided " + "in the virtual pool {} {}", haVPool.getLabel(), haVPool.getId());
                }
            }
        }
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCTN_VPLEX_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI) HashSet(java.util.HashSet)

Example 90 with StringSet

use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method isNativeVolumeExpansionSupported.

/**
 * Determines if the VPlex volume can be expanded by natively expanding
 * the backend volumes.
 *
 * @param vplexVolume A reference to the VPlex volume.
 * @param newSize The new desired size.
 *
 * @return true if the volume can be expanded natively, false otherwise.
 */
private boolean isNativeVolumeExpansionSupported(Volume vplexVolume, Long newSize) {
    // Determine if native volume expansion should be used or VPlex
    // migration to a larger target volume(s).
    boolean useNativeVolumeExpansion = true;
    StringSet assocVolumeIds = vplexVolume.getAssociatedVolumes();
    if (null == assocVolumeIds) {
        s_logger.warn("VPLEX volume {} has no backend volumes. It was probably ingested 'Virtual Volume Only'.", vplexVolume.forDisplay());
        useNativeVolumeExpansion = false;
    } else {
        for (String assocVolumeId : assocVolumeIds) {
            Volume assocVolume = _permissionsHelper.getObjectById(URI.create(assocVolumeId), Volume.class);
            // we use migration to expand the VPlex volume.
            try {
                super.verifyVolumeExpansionRequest(assocVolume, newSize);
            } catch (Exception e) {
                useNativeVolumeExpansion = false;
                break;
            }
        }
    }
    return useNativeVolumeExpansion;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)760 URI (java.net.URI)371 ArrayList (java.util.ArrayList)278 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)176 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)137 HashMap (java.util.HashMap)132 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)124 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)116 List (java.util.List)108 HashSet (java.util.HashSet)106 StoragePort (com.emc.storageos.db.client.model.StoragePort)90 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)74 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 Initiator (com.emc.storageos.db.client.model.Initiator)60 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)50 Map (java.util.Map)48