use of com.emc.storageos.db.client.model.StringSet 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.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class StorageProviderService method deleteStorageProvider.
/**
* Delete Storage Provider
*
* @param id
* @brief Delete a storage provider
* @return
*/
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteStorageProvider(@PathParam("id") URI id) {
// Validate the provider
ArgValidator.checkFieldUriType(id, StorageProvider.class, "id");
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id);
ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id));
// Verify the provider can be removed without leaving "dangling" storages.
StringSet providerStorageSystems = provider.getStorageSystems();
if (null != providerStorageSystems && !providerStorageSystems.isEmpty()) {
// First we need to verify that all related storage systems has at least 2 providers
for (String system : providerStorageSystems) {
StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system));
if (storageSys != null && !storageSys.getInactive() && storageSys.getProviders() != null && storageSys.getProviders().size() == 1) {
throw APIException.badRequests.cannotDeleteProviderWithManagedStorageSystems(storageSys.getId());
}
}
// Next we can clear this provider from storage systems.
for (String system : providerStorageSystems) {
StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system));
provider.removeStorageSystem(_dbClient, storageSys);
}
}
StringSet decommissionedSystems = provider.getDecommissionedSystems();
if (null != decommissionedSystems && !decommissionedSystems.isEmpty()) {
for (String decommissioned : decommissionedSystems) {
DecommissionedResource oldRes = _dbClient.queryObject(DecommissionedResource.class, URI.create(decommissioned));
if (oldRes != null) {
_dbClient.markForDeletion(oldRes);
}
}
}
// Set to inactive.
_dbClient.markForDeletion(provider);
auditOp(OperationTypeEnum.DELETE_STORAGEPROVIDER, true, null, provider.getId().toString(), provider.getLabel(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName(), provider.getInterfaceType());
return Response.ok().build();
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class StorageSystemService method toRDFGroupRep.
private RDFGroupRestRep toRDFGroupRep(RemoteDirectorGroup rdfGroup, DbClient dbClient, CoordinatorClient coordinator) {
List<URI> volumeList = new ArrayList<URI>();
StringSet volumes = rdfGroup.getVolumes();
if (volumes != null) {
for (String volNativeGuid : volumes) {
try {
Volume vol = DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, volNativeGuid);
if (vol != null && vol.isSRDFSource()) {
volumeList.add(vol.getId());
}
} catch (IOException e) {
_log.error(e.getMessage(), e);
}
}
}
return map(rdfGroup, volumeList);
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class TenantsService method listVolumeGroups.
/**
* List volume groups the user is authorized to see
*
* @param id the URN of a ViPR Tenant/Subtenant
* @prereq none
* @brief List volume groups
* @return List of volume groups
*/
@GET
@Path("/{id}/volume-groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList listVolumeGroups(@PathParam("id") URI id) {
// tenant id and user permission will get validated in listProjects()
ProjectList projectList = listProjects(id);
Set<URI> projects = new HashSet<URI>();
for (NamedRelatedResourceRep projectRep : projectList.getProjects()) {
projects.add(projectRep.getId());
}
// for each project, get all volumes. Collect volume group ids for all volumes
StringSet volumeGroups = new StringSet();
for (URI project : projects) {
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project), list);
Iterator<Volume> resultsIt = _dbClient.queryIterativeObjects(Volume.class, list);
while (resultsIt.hasNext()) {
volumeGroups.addAll(resultsIt.next().getVolumeGroupIds());
}
}
// form Volume Group list response
VolumeGroupList volumeGroupList = new VolumeGroupList();
for (String vg : volumeGroups) {
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, URI.create(vg));
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(volumeGroup));
}
return volumeGroupList;
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ProjectService method unassignVNasServersFromProject.
/**
* Unassigns VNAS server from project.
*
* @param id the URN of a ViPR Project
* @param param Assign virtual NAS server parameters
* @prereq none
* @brief Unassign VNAS servers from project
* @return No data returned in response body
* @throws BadRequestException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-vnas-servers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ALL, ACL.OWN })
public Response unassignVNasServersFromProject(@PathParam("id") URI id, VirtualNasParam param) {
checkCompatibleVersion();
Project project = getProjectById(id, true);
Set<String> vNasIds = param.getVnasServers();
if (vNasIds != null && !vNasIds.isEmpty()) {
StringSet vnasServers = project.getAssignedVNasServers();
if (!vnasServers.containsAll(vNasIds)) {
throw APIException.badRequests.vNasServersNotAssociatedToProject();
}
if (vnasServers != null && !vnasServers.isEmpty()) {
for (String vId : vNasIds) {
URI vnasURI = URI.create(vId);
VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
if (vnasServers.contains(vId)) {
vnas.dissociateProject(id.toString());
_dbClient.updateObject(vnas);
project.getAssignedVNasServers().remove(vId);
}
}
_dbClient.updateObject(project);
_log.info("Successfully unassigned the VNAS servers from project : {} ", project.getLabel());
} else {
throw APIException.badRequests.noVNasServersAssociatedToProject(project.getLabel());
}
} else {
throw APIException.badRequests.invalidEntryForProjectVNAS();
}
return Response.ok().build();
}
Aggregations