use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.
the class StoragePortService method updatevNasVirtualArrays.
/**
* Updates the virtual arrays to which the port of virtual nas is assigned.
*
* @param storagePort A reference to the storage port.
* @param newNetwork Network service assicated with varray
* @param varrayAssignmentChanges The virtual array changes.
* @param removePort - is port remove or add
* @return true if there was a virtual array assignment change, false otherwise.
*/
private boolean updatevNasVirtualArrays(StoragePort storagePort, Network newNetwork, VirtualArrayAssignmentChanges varrayAssignmentChanges, boolean removePort) {
_log.info("StoragePort:updatevNasVirtualArrays {} ", storagePort.getLabel());
// Validate that the virtual arrays to be assigned to the vnas
// reference existing virtual arrays in the database and add them to
// the vnas.
Set<String> varraysAddedTovNas = new HashSet<String>();
Set<String> varraysRemovedFromvNas = new HashSet<String>();
boolean varraysForvNasUpdated = false;
VirtualNAS vNas = getVirtualNasForStoragePort(storagePort);
if (vNas == null) {
_log.info("No Virtual NAS found for port {} ", storagePort.getLabel());
return false;
}
VirtualArrayAssignments addAssignments = null;
VirtualArrayAssignments removeAssignments = null;
StringSet currentAssignmentsForvNas = null;
if (varrayAssignmentChanges != null) {
addAssignments = varrayAssignmentChanges.getAdd();
removeAssignments = varrayAssignmentChanges.getRemove();
currentAssignmentsForvNas = vNas.getAssignedVirtualArrays();
}
// Update the vNas virtual arrays from network!!!
if (newNetwork != null) {
StringSet vArrays = newNetwork.getAssignedVirtualArrays();
if (vArrays != null && !vArrays.isEmpty()) {
if (!removePort) {
vNas.addAssignedVirtualArrays(vArrays);
varraysForvNasUpdated = true;
} else {
// Removing storage port from netwok!!!
_log.info("Step to Removing storage port from netwok");
StringSet vNasVarrys = new StringSet();
StringSet vNasVarryOther = new StringSet();
for (String sp : vNas.getStoragePorts()) {
StoragePort vNasSp = _dbClient.queryObject(StoragePort.class, URI.create(sp));
if (!sp.equalsIgnoreCase(storagePort.getId().toString())) {
if (vNasSp.getConnectedVirtualArrays() != null && !vNasSp.getConnectedVirtualArrays().isEmpty()) {
vNasVarrys.addAll(vNasSp.getConnectedVirtualArrays());
}
}
}
if (!vNasVarrys.isEmpty()) {
_log.info("varrays of vNas other ports {} and varrays of a network {}", vNasVarrys.toString(), vArrays.toString());
}
/*
If the varray of the port to be deleted is common with another port then we should not update vnas.
because the other ports of vnas may exist with same network of deleting port
*/
if ((vNasVarrys.isEmpty()) || (!vNasVarrys.isEmpty() && !vNasVarrys.containsAll(vArrays))) {
_log.info("Remove the varray from vNAS {} ", vNasVarrys.toString());
vNas.getAssignedVirtualArrays().removeAll(vArrays);
// remaining vNASvarray of other ports
vNas.getAssignedVirtualArrays().addAll(vNasVarrys);
varraysForvNasUpdated = true;
}
}
}
}
if (varrayAssignmentChanges != null) {
if (addAssignments != null) {
Set<String> addVArrays = addAssignments.getVarrays();
if ((addVArrays != null) && (!addVArrays.isEmpty())) {
// Iterate over the virtual arrays and assign them
// to the virtual NAS.
Iterator<String> addVArraysIterForvNas = addVArrays.iterator();
while (addVArraysIterForvNas.hasNext()) {
String addVArrayId = addVArraysIterForvNas.next();
if ((currentAssignmentsForvNas != null) && (currentAssignmentsForvNas.contains(addVArrayId))) {
// Just ignore those already assigned
_log.info("Virtual Nas already assigned to virtual array {}", addVArrayId);
continue;
}
varraysAddedTovNas.add(addVArrayId);
_log.info("virtual nas will be assigned to virtual array {}", addVArrayId);
}
if (!varraysAddedTovNas.isEmpty()) {
vNas.addAssignedVirtualArrays(varraysAddedTovNas);
_log.info("virtual nas assigned with virtual arrays size {}", varraysAddedTovNas.size());
varraysForvNasUpdated = true;
}
}
}
if (removeAssignments != null) {
Set<String> removeVArrays = removeAssignments.getVarrays();
if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
// Iterate over the virtual arrays and assign them
// to the virtual NAS.
_log.info("Virtual Nas that has virtual array to remove {}", removeVArrays.toString());
Iterator<String> removeVArraysIterForvNas = removeVArrays.iterator();
while (removeVArraysIterForvNas.hasNext()) {
String removeVArrayId = removeVArraysIterForvNas.next();
if ((currentAssignmentsForvNas != null) && (!currentAssignmentsForvNas.contains(removeVArrayId))) {
// Just ignore those already assigned
_log.info("Virtual Nas not assigned to virtual array {}", removeVArrayId);
continue;
}
varraysRemovedFromvNas.add(removeVArrayId);
_log.info("virtual nas will be unassigned to virtual array {}", removeVArrayId);
}
if (!varraysRemovedFromvNas.isEmpty()) {
vNas.removeAssignedVirtualArrays(varraysRemovedFromvNas);
_log.info("virtual nas un-assigned with virtual arrays size {}", varraysRemovedFromvNas.size());
varraysForvNasUpdated = true;
}
}
}
} else {
_log.info("Ignored assignment of varray to virtual nas as the storage port not belongs to vnx file");
}
if (varraysForvNasUpdated) {
_dbClient.persistObject(vNas);
}
return varraysForvNasUpdated;
}
use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.
the class StoragePortService method updateStoragePortVirtualArrays.
/**
* Updates the virtual arrays to which the port is assigned.
*
* @param storagePort A reference to the storage port.
* @param varrayChanges The virtual array changes.
*
* @return true if there was a virtual array assignment change, false otherwise.
*/
private boolean updateStoragePortVirtualArrays(StoragePort storagePort, VirtualArrayAssignmentChanges varrayAssignmentChanges) {
// Validate that the virtual arrays to be assigned to the storage port
// reference existing virtual arrays in the database and add them to
// the storage port.
boolean varraysForPortUpdated = false;
Set<String> varraysAddedToPort = new HashSet<String>();
Set<String> varraysRemovedFromPort = new HashSet<String>();
if (varrayAssignmentChanges != null) {
_log.info("Update request has virtual array assignment changes for storage port {}", storagePort.getId());
// Verify the assignment changes in the request.
verifyAssignmentChanges(storagePort, varrayAssignmentChanges);
_log.info("Requested virtual array assignment changes verified.");
VirtualArrayAssignments addAssignments = varrayAssignmentChanges.getAdd();
if (addAssignments != null) {
Set<String> addVArrays = addAssignments.getVarrays();
if ((addVArrays != null) && (!addVArrays.isEmpty())) {
_log.info("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 storage port.
StringSet currentAssignments = storagePort.getAssignedVirtualArrays();
Iterator<String> addVArraysIter = addVArrays.iterator();
while (addVArraysIter.hasNext()) {
String addVArrayId = addVArraysIter.next();
if ((currentAssignments != null) && (currentAssignments.contains(addVArrayId))) {
// Just ignore those already assigned
_log.info("Storage port already assigned to virtual array {}", addVArrayId);
continue;
}
varraysAddedToPort.add(addVArrayId);
varraysForPortUpdated = true;
_log.info("Storage port will be assigned to virtual array {}", addVArrayId);
}
}
}
// Validate that the virtual arrays to be unassigned from the
// storage port reference existing virtual arrays in the database
// and remove them from the storage port.
VirtualArrayAssignments removeAssignments = varrayAssignmentChanges.getRemove();
if (removeAssignments != null) {
Set<String> removeVArrays = removeAssignments.getVarrays();
if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
_log.info("Request specifies virtual arrays to be removed.");
// Validate the requested URIs.
VirtualArrayService.checkVirtualArrayURIs(removeVArrays, _dbClient);
// Iterate over the virtual arrays and unassign from
// the storage port.
StringSet currentAssignments = storagePort.getAssignedVirtualArrays();
Iterator<String> removeVArraysIter = removeVArrays.iterator();
while (removeVArraysIter.hasNext()) {
String removeVArrayId = removeVArraysIter.next();
if ((currentAssignments == null) || (!currentAssignments.contains(removeVArrayId))) {
// Just ignore those not assigned.
_log.info("Storage port is not assigned to virtual array {}", removeVArrayId);
continue;
}
// storagePort.removeAssignedVirtualArray(removeVArrayId);
varraysRemovedFromPort.add(removeVArrayId);
varraysForPortUpdated = true;
_log.info("Storage port will be unassigned from virtual array {}", removeVArrayId);
}
}
}
}
// Persist virtual array changes for storage port, if any.
if (varraysForPortUpdated) {
storagePort.addAssignedVirtualArrays(varraysAddedToPort);
storagePort.removeAssignedVirtualArrays(varraysRemovedFromPort);
// Check the new virtual array assignment does
// not remove the port from varrays where it is used
verifyPortNoInUseInRemovedVarrays(storagePort);
_dbClient.updateAndReindexObject(storagePort);
// Because the storage port virtual array assignments have
// changed, we may have to update the implicit connected
// virtual arrays for the storage port's network.
URI storagePortNetworkURI = storagePort.getNetwork();
if (storagePortNetworkURI != null) {
// TODO - I need to find a way around using a full network retrieval
Network storagePortNetwork = _dbClient.queryObject(Network.class, storagePortNetworkURI);
if (storagePortNetwork != null) {
if (!varraysRemovedFromPort.isEmpty()) {
// if varrays were removed, it will be a full reset
// this will take care of both add and remove, but costly
NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork, Collections.singletonList(storagePort), false, _dbClient);
} else if (!varraysAddedToPort.isEmpty()) {
// if varrays were only added, do add only, cheaper
NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork, Collections.singletonList(storagePort), true, _dbClient);
}
}
}
}
return varraysForPortUpdated;
}
use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.
the class StoragePoolService method updateStoragePool.
/**
* This API call only allows user to update virtual array & virtual pool
* assignments for the registered storage pool.
* <p>
* A pool can be associated with a virtual array either implicitly or explicitly. A pool is implicitly associated with a virtual array
* when the pool's storage system has one or more ports in the virtual array (see {@link StoragePool#getConnectedVirtualArrays()}). the
* pool's implicit virtual arrays are the union of all the tagged virtual arrays of the storage array ports. This implicit association
* cannot be changed or removed, it can only be overridden by an explicit assignment (see {@link StoragePool#getAssignedVirtualArrays()}
* ). A pool's effective virtual array association is {@link StoragePool#getTaggedVirtualArrays()})
* <p>
* Managing pools associated virtual arrays requires planning. In general, pools should be assigned to virtual arrays only when it is
* desired to limit the virtual arrays where they can be used.
*
* @param id the URN of a ViPR storage pool.
* @param storagePoolUpdates Specifies the updates to be made to the storage
* pool.
*
* @brief Update storage pool
* @return A StoragePoolRestRep specifying the updated storage pool info.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePoolRestRep updateStoragePool(@PathParam("id") URI id, StoragePoolUpdate storagePoolUpdates) {
// Get the storage pool with the passed id.
ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
StoragePool storagePool = queryRegisteredResource(id);
ArgValidator.checkEntity(storagePool, id, isIdEmbeddedInURL(id));
boolean neighborhoodChange = false;
// the storage pool.
if (storagePoolUpdates.getVarrayChanges() != null) {
VirtualArrayAssignments addedNH = storagePoolUpdates.getVarrayChanges().getAdd();
if ((addedNH != null) && (!addedNH.getVarrays().isEmpty())) {
VirtualArrayService.checkVirtualArrayURIs(addedNH.getVarrays(), _dbClient);
storagePool.addAssignedVirtualArrays(addedNH.getVarrays());
}
// Validate that the neighborhoods to be unassigned from the storage
// pool reference existing neighborhoods in the database and remove
// them from the storage pool.
VirtualArrayAssignments removedNH = storagePoolUpdates.getVarrayChanges().getRemove();
if ((removedNH != null) && (!removedNH.getVarrays().isEmpty())) {
VirtualArrayService.checkVirtualArrayURIs(removedNH.getVarrays(), _dbClient);
storagePool.removeAssignedVirtualArrays(removedNH.getVarrays());
}
verifyPoolNoInUseInVarrays(storagePool);
neighborhoodChange = true;
}
// for all VirtualPool.
if (neighborhoodChange) {
StringBuffer errorMessage = new StringBuffer();
ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVirtualPool(Arrays.asList(storagePool), _dbClient, _coordinator, errorMessage);
}
Integer currentMaxSubscriptionPercentFromArray = storagePool.getMaxThinPoolSubscriptionPercentageFromArray();
_logger.info(String.format("Current maximum subscription percent in storage pool from array : %s ", currentMaxSubscriptionPercentFromArray));
if (null != storagePoolUpdates.getMaxPoolUtilizationPercentage()) {
if (storagePoolUpdates.getMaxPoolUtilizationPercentage() < 0 || storagePoolUpdates.getMaxPoolUtilizationPercentage() > 100) {
throw APIException.badRequests.invalidParameterPercentageExpected("max_pool_utilization_percentage", storagePoolUpdates.getMaxPoolUtilizationPercentage());
}
// check that a new value does not exceed array limit
if (currentMaxSubscriptionPercentFromArray != null && storagePoolUpdates.getMaxPoolUtilizationPercentage() > currentMaxSubscriptionPercentFromArray) {
throw APIException.badRequests.invalidParameterValueExceedsArrayLimit("max_pool_utilization_percentage", storagePoolUpdates.getMaxPoolUtilizationPercentage(), currentMaxSubscriptionPercentFromArray);
}
storagePool.setMaxPoolUtilizationPercentage(storagePoolUpdates.getMaxPoolUtilizationPercentage());
}
if (null != storagePoolUpdates.getMaxThinPoolSubscriptionPercentage()) {
ArgValidator.checkFieldMinimum(storagePoolUpdates.getMaxThinPoolSubscriptionPercentage(), 0, "max_thin_pool_subscription_percentage");
if (!validateMaxThinPoolSubscriptionInput(storagePool, storagePoolUpdates.getMaxThinPoolSubscriptionPercentage())) {
throw APIException.badRequests.parameterIsOnlyApplicableTo("max_thin_pool_subscription_percentage", "Thin Pool");
}
// check that a new value does not exceed array limit
if (currentMaxSubscriptionPercentFromArray != null && storagePoolUpdates.getMaxThinPoolSubscriptionPercentage() > currentMaxSubscriptionPercentFromArray) {
throw APIException.badRequests.invalidParameterValueExceedsArrayLimit("max_thin_pool_subscription_percentage", storagePoolUpdates.getMaxThinPoolSubscriptionPercentage(), currentMaxSubscriptionPercentFromArray);
}
storagePool.setMaxThinPoolSubscriptionPercentage(storagePoolUpdates.getMaxThinPoolSubscriptionPercentage());
}
// If unlimited resources is set to false, then max resources should also be specified. If not specified, throw error
if (null != storagePoolUpdates.getIsUnlimitedResourcesSet()) {
if (storagePoolUpdates.getIsUnlimitedResourcesSet()) {
storagePool.setIsResourceLimitSet(false);
} else {
if (null != storagePoolUpdates.getMaxResources()) {
storagePool.setIsResourceLimitSet(true);
storagePool.setMaxResources(storagePoolUpdates.getMaxResources());
} else {
throw APIException.badRequests.parameterMaxResourcesMissing();
}
}
} else if (null != storagePoolUpdates.getMaxResources()) {
storagePool.setMaxResources(storagePoolUpdates.getMaxResources());
storagePool.setIsResourceLimitSet(true);
}
// Persist the changes and return a successful response.
_dbClient.updateAndReindexObject(storagePool);
// Record the storage pool update event.
recordStoragePoolEvent(OperationTypeEnum.STORAGE_POOL_UPDATE, STORAGEPOOL_UPDATED_DESCRIPTION, storagePool.getId());
auditOp(OperationTypeEnum.UPDATE_STORAGE_POOL, true, null, id.toString());
return toStoragePoolRep(storagePool, _dbClient, _coordinator);
}
use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.
the class ComputeVirtualPoolService method verifyAssignmentChanges.
/**
* Verifies the virtual array assignment changes in the update request are
* valid, else throws a bad request exception.
*
* @param cvp - A reference to a Compute Virtual Pool.
* @param varrayAssignmentChanges The virtual array assignment changes in a
* compute virtual pool update request.
*/
private void verifyAssignmentChanges(ComputeVirtualPool cvp, VirtualArrayAssignmentChanges varrayAssignmentChanges) {
// Verify the add/remove sets do not overlap.
VirtualArrayAssignments addAssignments = varrayAssignmentChanges.getAdd();
VirtualArrayAssignments removeAssignments = varrayAssignmentChanges.getRemove();
if ((addAssignments != null) && (removeAssignments != null)) {
Set<String> addVArrays = addAssignments.getVarrays();
Set<String> removeVArrays = removeAssignments.getVarrays();
if ((addVArrays != null) && (removeVArrays != null)) {
Set<String> addSet = new HashSet<String>(addVArrays);
Set<String> removeSet = new HashSet<String>(removeVArrays);
addSet.retainAll(removeSet);
if (!addSet.isEmpty()) {
_log.error("Request specifies the same virtual array(s) in both the add and remove lists {}", addSet);
throw APIException.badRequests.sameVirtualArrayInAddRemoveList();
}
}
}
}
use of com.emc.storageos.model.pools.VirtualArrayAssignments in project coprhd-controller by CoprHD.
the class VirtualPoolUpdateBuilder method setVirtualArrays.
public VirtualPoolUpdateBuilder setVirtualArrays(Collection<String> virtualArrays) {
List<String> oldVirtualArrays = stringRefIds(oldVirtualPool.getVirtualArrays());
Set<String> add = Sets.newHashSet(CollectionUtils.subtract(virtualArrays, oldVirtualArrays));
Set<String> remove = Sets.newHashSet(CollectionUtils.subtract(oldVirtualArrays, virtualArrays));
VirtualArrayAssignmentChanges changes = new VirtualArrayAssignmentChanges();
if (!add.isEmpty()) {
changes.setAdd(new VirtualArrayAssignments(add));
}
if (!remove.isEmpty()) {
changes.setRemove(new VirtualArrayAssignments(remove));
}
virtualPool.setVarrayChanges(changes);
return this;
}
Aggregations