Search in sources :

Example 1 with ResourceAndUUIDNameGenerator

use of com.emc.storageos.db.client.util.ResourceAndUUIDNameGenerator in project coprhd-controller by CoprHD.

the class UnManagedVolumeService method ingestExportedVolumes.

/**
 * Ingest Exported Volumes
 *
 * For each UnManaged Volume Find the list of masking views this volume
 * is exposed to.
 *
 * If only 1 masking view verify if all the initiators are available on
 * the existing MV. Verify the storage Ports are available in given
 * VArray Verify if this export mask is available already If not, then
 * create a new Export Mask with the storage Ports, initiators from
 * ViPr. Else, add volume to export mask.
 *
 * If more than 1 masking view verify if all the initiators are
 * available on all existing MVs. Verify the storage Ports within each
 * Masking view are available in given VArray. Verify if this export
 * mask is available already If not, then create a new Export Mask with
 * the storage Ports, initiators from ViPr. Else, add volume to export
 * mask.
 *
 * @param exportIngestParam
 * @brief Add volumes to new or existing export masks; create masks when needed
 * @return TaskList
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/ingest-exported")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskList ingestExportedVolumes(VolumeExportIngestParam exportIngestParam) throws InternalException {
    TaskList taskList = new TaskList();
    Map<String, TaskResourceRep> taskMap = new HashMap<String, TaskResourceRep>();
    BaseIngestionRequestContext requestContext = null;
    try {
        if (exportIngestParam.getUnManagedVolumes().size() > getMaxBulkSize()) {
            throw APIException.badRequests.exceedingLimit("unmanaged volumes", getMaxBulkSize());
        }
        Project project = _permissionsHelper.getObjectById(exportIngestParam.getProject(), Project.class);
        ArgValidator.checkEntity(project, exportIngestParam.getProject(), false);
        VirtualArray varray = VolumeIngestionUtil.getVirtualArrayForVolumeCreateRequest(project, exportIngestParam.getVarray(), _permissionsHelper, _dbClient);
        VirtualPool vpool = VolumeIngestionUtil.getVirtualPoolForVolumeCreateRequest(project, exportIngestParam.getVpool(), _permissionsHelper, _dbClient);
        // allow ingestion for VPool without Virtual Arrays
        if (null != vpool.getVirtualArrays() && !vpool.getVirtualArrays().isEmpty() && !vpool.getVirtualArrays().contains(exportIngestParam.getVarray().toString())) {
            throw APIException.internalServerErrors.virtualPoolNotMatchingVArray(exportIngestParam.getVarray());
        }
        // check for Quotas
        long unManagedVolumesCapacity = VolumeIngestionUtil.getTotalUnManagedVolumeCapacity(_dbClient, exportIngestParam.getUnManagedVolumes());
        _logger.info("UnManagedVolume provisioning quota validation successful");
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
        CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, unManagedVolumesCapacity, "volume");
        VolumeIngestionUtil.checkIngestionRequestValidForUnManagedVolumes(exportIngestParam.getUnManagedVolumes(), vpool, _dbClient);
        requestContext = new BaseIngestionRequestContext(_dbClient, exportIngestParam.getUnManagedVolumes(), vpool, varray, project, tenant, exportIngestParam.getVplexIngestionMethod());
        while (requestContext.hasNext()) {
            UnManagedVolume unManagedVolume = requestContext.next();
            if (null == unManagedVolume) {
                _logger.warn("No Unmanaged Volume with URI {} found in database. Continuing...", requestContext.getCurrentUnManagedVolumeUri());
                continue;
            }
            String taskId = UUID.randomUUID().toString();
            Operation operation = _dbClient.createTaskOpStatus(UnManagedVolume.class, requestContext.getCurrentUnManagedVolumeUri(), taskId, ResourceOperationTypeEnum.INGEST_EXPORTED_BLOCK_OBJECTS);
            TaskResourceRep task = toTask(unManagedVolume, taskId, operation);
            taskMap.put(unManagedVolume.getId().toString(), task);
        }
        taskList.getTaskList().addAll(taskMap.values());
        // find or create ExportGroup for this set of volumes being ingested
        URI exportGroupResourceUri = null;
        String resourceType = ExportGroupType.Host.name();
        String computeResourcelabel = null;
        if (null != exportIngestParam.getCluster()) {
            resourceType = ExportGroupType.Cluster.name();
            Cluster cluster = _dbClient.queryObject(Cluster.class, exportIngestParam.getCluster());
            exportGroupResourceUri = cluster.getId();
            computeResourcelabel = cluster.getLabel();
            requestContext.setCluster(exportIngestParam.getCluster());
        } else {
            Host host = _dbClient.queryObject(Host.class, exportIngestParam.getHost());
            exportGroupResourceUri = host.getId();
            computeResourcelabel = host.getHostName();
            requestContext.setHost(exportIngestParam.getHost());
        }
        ExportGroup exportGroup = VolumeIngestionUtil.verifyExportGroupExists(requestContext, requestContext.getProject().getId(), exportGroupResourceUri, exportIngestParam.getVarray(), resourceType, _dbClient);
        if (null == exportGroup) {
            _logger.info("Creating Export Group with label {}", computeResourcelabel);
            ResourceAndUUIDNameGenerator nameGenerator = new ResourceAndUUIDNameGenerator();
            exportGroup = VolumeIngestionUtil.initializeExportGroup(requestContext.getProject(), resourceType, exportIngestParam.getVarray(), computeResourcelabel, _dbClient, nameGenerator, requestContext.getTenant());
            requestContext.setExportGroupCreated(true);
        }
        requestContext.setExportGroup(exportGroup);
        _logger.info("ExportGroup {} created ", exportGroup.forDisplay());
        IngestVolumesExportedSchedulingThread.executeApiTask(_asyncTaskService.getExecutorService(), requestContext, ingestStrategyFactory, this, _dbClient, taskMap, taskList);
    } catch (InternalException e) {
        _logger.error("InternalException occurred due to: {}", e);
        throw e;
    } catch (Exception e) {
        _logger.error("Unexpected exception occurred due to: {}", e);
        throw APIException.internalServerErrors.genericApisvcError(ExceptionUtils.getExceptionMessage(e), e);
    }
    return taskList;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) HashMap(java.util.HashMap) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BaseIngestionRequestContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BaseIngestionRequestContext) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) ResourceAndUUIDNameGenerator(com.emc.storageos.db.client.util.ResourceAndUUIDNameGenerator) 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)

Aggregations

BaseIngestionRequestContext (com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BaseIngestionRequestContext)1 Cluster (com.emc.storageos.db.client.model.Cluster)1 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)1 Host (com.emc.storageos.db.client.model.Host)1 Operation (com.emc.storageos.db.client.model.Operation)1 Project (com.emc.storageos.db.client.model.Project)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 ResourceAndUUIDNameGenerator (com.emc.storageos.db.client.util.ResourceAndUUIDNameGenerator)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 TaskList (com.emc.storageos.model.TaskList)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Consumes (javax.ws.rs.Consumes)1