Search in sources :

Example 11 with VirtualArrayAssignments

use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.

the class VirtualArrays method removeVirtualArray.

/**
 * Creates a change to remove a virtual array.
 *
 * @param virtualArray
 *            the virtual array to remove.
 * @return the virtual array assignment changes.
 */
private static VirtualArrayAssignmentChanges removeVirtualArray(VirtualArrayRestRep virtualArray) {
    VirtualArrayAssignmentChanges changes = new VirtualArrayAssignmentChanges();
    changes.setRemove(new VirtualArrayAssignments(Sets.newHashSet(stringId(virtualArray))));
    return changes;
}
Also used : VirtualArrayAssignmentChanges(com.emc.storageos.model.pools.VirtualArrayAssignmentChanges) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments)

Example 12 with VirtualArrayAssignments

use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolService method updateVirtualArrays.

/**
 * Updates the virtual arrays to which the compute virtual pool is assigned.
 *
 * @param cvp - A reference to the compute virtual pool.
 *
 * @return true if there was a virtual array assignment change, false otherwise.
 */
private boolean updateVirtualArrays(ComputeVirtualPool cvp, VirtualArrayAssignmentChanges varrayAssignmentChanges) {
    // Validate that the Virtual Arrays to be assigned to the Compute Virtual Pool
    // reference existing Virtual Arrays in the database and add them to
    // to the CVP.
    boolean varraysForCvpUpdated = false;
    Set<String> varraysAddedToCvp = new HashSet<String>();
    Set<String> varraysRemovedFromCvp = new HashSet<String>();
    if (varrayAssignmentChanges != null) {
        _log.debug("Update request has virtual array assignment changes for compute virtual pool {}", cvp.getId());
        // Verify the assignment changes in the request.
        verifyAssignmentChanges(cvp, varrayAssignmentChanges);
        _log.debug("Requested virtual array assignment changes verified.");
        VirtualArrayAssignments addAssignments = varrayAssignmentChanges.getAdd();
        if (addAssignments != null) {
            Set<String> addVArrays = addAssignments.getVarrays();
            if ((addVArrays != null) && (!addVArrays.isEmpty())) {
                _log.debug("Request specifies virtual arrays to be added.");
                // Validate the requested URIs.
                VirtualArrayService.checkVirtualArrayURIs(addVArrays, _dbClient);
                // Iterate over the virtual arrays and assign them to the CVP.
                StringSet currentAssignments = cvp.getVirtualArrays();
                Iterator<String> addVArraysIter = addVArrays.iterator();
                while (addVArraysIter.hasNext()) {
                    String addVArrayId = addVArraysIter.next();
                    if ((currentAssignments != null) && (currentAssignments.contains(addVArrayId))) {
                        // Just ignore those already assigned
                        _log.debug("Compute Virtual Pool already assigned to virtual array {}", addVArrayId);
                        continue;
                    }
                    // Verify that the Virtual Array is active
                    URI virtualArrayURI = null;
                    virtualArrayURI = URI.create(addVArrayId);
                    this.queryObject(VirtualArray.class, virtualArrayURI, true);
                    varraysAddedToCvp.add(addVArrayId);
                    varraysForCvpUpdated = true;
                    _log.debug("Compute Virtual Pool will be assigned to virtual array {}", addVArrayId);
                }
            }
        }
        // Validate that the Virtual Arrays to be unassigned from the
        // Compute Virtual Pool reference existing Virtual Arrays in the database
        // and remove them from the CVP.
        VirtualArrayAssignments removeAssignments = varrayAssignmentChanges.getRemove();
        if (removeAssignments != null) {
            Set<String> removeVArrays = removeAssignments.getVarrays();
            // If the vcp is in use, varrays cannot be removed from the vcp.
            if (isComputeVirtualPoolInUse(cvp)) {
                throw APIException.badRequests.cannotRemoveVarraysFromCVP(cvp.getLabel());
            }
            if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
                _log.debug("Request specifies virtual arrays to be removed.");
                // Iterate over the virtual arrays and unassign from the CVP
                StringSet currentAssignments = cvp.getVirtualArrays();
                Iterator<String> removeVArraysIter = removeVArrays.iterator();
                while (removeVArraysIter.hasNext()) {
                    String removeVArrayId = removeVArraysIter.next();
                    if ((currentAssignments == null) || (!currentAssignments.contains(removeVArrayId))) {
                        // Just ignore those not assigned.
                        _log.debug("Compute Virtual Pool is not assigned to virtual array {}", removeVArrayId);
                        continue;
                    }
                    varraysRemovedFromCvp.add(removeVArrayId);
                    varraysForCvpUpdated = true;
                    _log.debug("Compute Virtual Pool will be unassigned from virtual array {}", removeVArrayId);
                }
            }
        }
    }
    // Persist virtual array changes for the Compute Virtual Pool, if any.
    if (varraysForCvpUpdated) {
        if (!varraysAddedToCvp.isEmpty()) {
            cvp.addVirtualArrays(varraysAddedToCvp);
        }
        if (!varraysRemovedFromCvp.isEmpty()) {
            cvp.removeVirtualArrays(varraysRemovedFromCvp);
        }
    }
    return varraysForCvpUpdated;
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

VirtualArrayAssignments (com.emc.storageos.model.pools.VirtualArrayAssignments)12 HashSet (java.util.HashSet)7 URI (java.net.URI)4 StringSet (com.emc.storageos.db.client.model.StringSet)3 VirtualArrayAssignmentChanges (com.emc.storageos.model.pools.VirtualArrayAssignmentChanges)3 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 StoragePort (com.emc.storageos.db.client.model.StoragePort)2 MapStoragePort (com.emc.storageos.api.mapper.functions.MapStoragePort)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 Network (com.emc.storageos.db.client.model.Network)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1 VirtualNAS (com.emc.storageos.db.client.model.VirtualNAS)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 NetworkLite (com.emc.storageos.util.NetworkLite)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PUT (javax.ws.rs.PUT)1