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;
}
Aggregations