Search in sources :

Example 41 with StringSet

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;
}
Also used : Network(com.emc.storageos.db.client.model.Network) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments) URI(java.net.URI) HashSet(java.util.HashSet)

Example 42 with StringSet

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();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 43 with StringSet

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);
}
Also used : UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) IOException(java.io.IOException) URI(java.net.URI)

Example 44 with StringSet

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;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ProjectList(com.emc.storageos.model.project.ProjectList) StringSet(com.emc.storageos.db.client.model.StringSet) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 45 with StringSet

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();
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)753 URI (java.net.URI)366 ArrayList (java.util.ArrayList)274 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)173 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)135 HashMap (java.util.HashMap)129 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)119 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)111 HashSet (java.util.HashSet)105 List (java.util.List)105 StoragePort (com.emc.storageos.db.client.model.StoragePort)86 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)72 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)55 Initiator (com.emc.storageos.db.client.model.Initiator)54 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 Map (java.util.Map)47