use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class BlockSnapshotSessions method deactivate.
/**
* Begins deactivating a given block snapshot session by ID.
* <p>
* API Call: <tt>POST /block/snapshot-sessions/{id}/deactivate</tt>
*
* @param id
* the ID of the snapshot session to deactivate.
* @param type
* {@code FULL} or {@code VIPR_ONLY}
*
* @return a task for monitoring the progress of the operation.
*/
public Tasks<BlockSnapshotSessionRestRep> deactivate(URI id, VolumeDeleteTypeEnum type) {
URI uri = client.uriBuilder(getDeactivateUrl()).queryParam("type", type).build(id);
TaskList tasks = client.postURI(TaskList.class, uri);
return new Tasks<>(client, tasks.getTaskList(), resourceClass);
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class FileService method deactivateContinuousCopies.
/**
* Deactivate Continuous Copies
*
* @param id
* the URN of a ViPR fileSystem
* @param param
* File System Delete parameter
* @brief Delete continuous copies
* @return TaskResponse
* @throws InternalException
* @throws APIException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateContinuousCopies(@PathParam("id") URI id, FileSystemDeleteParam param) throws InternalException, APIException {
_log.info("Request to deactivate replication copies for filesystem {}", id);
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
FileShare orgFs = queryResource(id);
String task = UUID.randomUUID().toString();
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
TaskList taskList = new TaskList();
// Make sure that we don't have some pending
// operation against the file system!!!
checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
// Get the project.
URI projectURI = fs.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found filesystem project {}", projectURI);
VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the file system and its vPool are capable of doing replication!!!
if (!FileSystemReplicationUtils.validateDeleteMirrorCopies(fs, currentVpool, notSuppReasonBuff)) {
_log.error("delete mirror copies is not supported for file system {} due to {}", fs.getId().toString(), notSuppReasonBuff.toString());
throw APIException.badRequests.unableToDeleteMirrorCopies(fs.getId(), notSuppReasonBuff.toString());
}
// Get the virtual array!!!
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
// New operation
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.DELETE_MIRROR_FILE_SYSTEMS);
op.setDescription("Deactivate file system mirror operation");
op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
TaskResourceRep fileSystemTask = toTask(fs, task, op);
taskList.getTaskList().add(fileSystemTask);
List<URI> fileShareURIs = new ArrayList<URI>();
fileShareURIs.add(id);
boolean deleteMirrorCopies = true;
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
try {
fileServiceApi.deleteFileSystems(device.getId(), fileShareURIs, param.getDeleteType(), param.getForceDelete(), deleteMirrorCopies, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("deactivate continuous copies error ", e);
}
FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
op = fs.getOpStatus().get(task);
op.error(e);
fileShare.getOpStatus().updateTaskStatus(task, op);
// Revert the file system to original state!!!
restoreFromOriginalFs(orgFs, fs);
_dbClient.updateObject(fs);
throw e;
}
auditOp(OperationTypeEnum.DELETE_MIRROR_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getLabel(), currentVpool.getLabel(), fs.getLabel(), project == null ? null : project.getId().toString());
return taskList.getTaskList().get(0);
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class FileService method createContinuousCopies.
/**
* Create Continuous Copies
*
* @param id
* the URN of a ViPR fileSystem
* @param param
* File Replication Create parameter
* @brief Define continuous copies
* @return TaskResponse
* @throws InternalException
* @throws APIException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/create")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createContinuousCopies(@PathParam("id") URI id, FileReplicationCreateParam param) throws InternalException, APIException {
_log.info("Request to create replication copies for filesystem {}", id);
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
FileShare orgFs = queryResource(id);
String task = UUID.randomUUID().toString();
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
TaskList taskList = new TaskList();
// Make sure that we don't have some pending
// operation against the file system!!!
checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
// Get the project.
URI projectURI = fs.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found filesystem project {}", projectURI);
VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the file system and its vPool are capable of doing replication!!!
if (!FileSystemReplicationUtils.isSupportedFileReplicationCreate(fs, currentVpool, notSuppReasonBuff)) {
_log.error("create mirror copies is not supported for file system {} due to {}", fs.getId().toString(), notSuppReasonBuff.toString());
throw APIException.badRequests.unableToCreateMirrorCopies(fs.getId(), notSuppReasonBuff.toString());
}
// Get the virtual array!!!
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
// New operation
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_MIRROR_COPIES);
op.setDescription("Create file system mirror operation");
op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
TaskResourceRep fileSystemTask = toTask(fs, task, op);
taskList.getTaskList().add(fileSystemTask);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
// prepare vpool capability values
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, fs.getCapacity());
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(currentVpool.getSupportedProvisioningType())) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.TRUE);
}
// Set the source file system details
// source fs details used in finding recommendations for target fs!!
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_SYSTEM_CREATE_MIRROR_COPY, Boolean.TRUE);
capabilities.put(VirtualPoolCapabilityValuesWrapper.EXISTING_SOURCE_FILE_SYSTEM, fs);
capabilities.put(VirtualPoolCapabilityValuesWrapper.SOURCE_STORAGE_SYSTEM, device);
StringBuilder errorMsg = new StringBuilder();
if (!FilePolicyServiceUtils.updatePolicyCapabilities(_dbClient, varray, currentVpool, project, null, capabilities, errorMsg)) {
_log.error("File system can not be created, ", errorMsg.toString());
throw APIException.badRequests.unableToProcessRequest(errorMsg.toString());
}
if (param.getCopyName() != null && !param.getCopyName().isEmpty()) {
// No need to generate any name -- Since the requirement is to use the customizing label we should use the
// same.
// Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
String convertedName = param.getCopyName().replaceAll("[^\\dA-Za-z\\_]", "");
_log.info("Original copy name {} and converted copy name {}", param.getCopyName(), convertedName);
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_TARGET_COPY_NAME, convertedName);
}
FileServiceApi fileServiceApi = getFileShareServiceImpl(capabilities, _dbClient);
try {
// Call out placementManager to get the recommendation for placement.
List recommendations = _filePlacementManager.getRecommendationsForFileCreateRequest(varray, project, currentVpool, capabilities);
// Verify the source virtual pool recommendations meets source fs storage!!!
fileServiceApi.createTargetsForExistingSource(fs, project, currentVpool, varray, taskList, task, recommendations, capabilities);
} catch (BadRequestException e) {
// Revert the file system to original state!!!
restoreFromOriginalFs(orgFs, fs);
_dbClient.updateObject(fs);
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
throw e;
} catch (InternalException e) {
// Revert the file system to original state!!!
restoreFromOriginalFs(orgFs, fs);
_dbClient.updateObject(fs);
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
auditOp(OperationTypeEnum.CREATE_MIRROR_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getLabel(), currentVpool.getLabel(), fs.getLabel(), project == null ? null : project.getId().toString());
return taskList.getTaskList().get(0);
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class HostService method doDiscoverHost.
/**
* Host Discovery
*
* @param host {@link Host} The Host to be discovered.
* @param taskId {@link String} taskId for the host discovery. as new taskId is generated if null passed.
* @param updateTaskStatus if true, mark the task status as completed for non-discovered host
* @return the task used to track the discovery job
*/
protected TaskResourceRep doDiscoverHost(URI hostId, String taskId, boolean updateTaskStatus) {
Host host = queryObject(Host.class, hostId, true);
if (taskId == null) {
taskId = UUID.randomUUID().toString();
}
if (host.getDiscoverable() != null && !host.getDiscoverable()) {
host.setDiscoveryStatus(DataCollectionJobStatus.COMPLETE.name());
_dbClient.updateObject(host);
}
if ((host.getDiscoverable() == null || host.getDiscoverable())) {
ComputeSystemController controller = getController(ComputeSystemController.class, "host");
DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new DiscoverJobExec(controller));
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
tasks.add(new AsyncTask(Host.class, host.getId(), taskId));
TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
return taskList.getTaskList().iterator().next();
} else {
// if not discoverable, manually create a ready task
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.DISCOVER_HOST);
if (updateTaskStatus) {
op.ready("Host is not discoverable");
} else {
op.pending();
}
_dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
return toTask(host, taskId, op);
}
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class HostService method createHostArrayAffinityTasks.
/**
* Create array affinity tasks for hosts.
*
* @param hostIds
* the hosts whose preferred systems need to be discovered
*/
public TaskList createHostArrayAffinityTasks(List<URI> hostIds) {
TaskList taskList = new TaskList();
String taskId = UUID.randomUUID().toString();
String jobType = "";
Map<URI, List<URI>> providerToSystemsMap = new HashMap<URI, List<URI>>();
Map<URI, String> providerToSystemTypeMap = new HashMap<URI, String>();
List<URI> sysURIs = _dbClient.queryByType(StorageSystem.class, true);
Iterator<StorageSystem> storageSystems = _dbClient.queryIterativeObjects(StorageSystem.class, sysURIs);
while (storageSystems.hasNext()) {
StorageSystem systemObj = storageSystems.next();
if (systemObj == null) {
_log.warn("StorageSystem is no longer in the DB. It could have been deleted or decommissioned");
continue;
}
if (systemObj.deviceIsType(Type.vmax) || systemObj.deviceIsType(Type.vnxblock) || systemObj.deviceIsType(Type.xtremio)) {
if (systemObj.getActiveProviderURI() == null || NullColumnValueGetter.getNullURI().equals(systemObj.getActiveProviderURI())) {
_log.info("Skipping {} Job : StorageSystem {} does not have an active provider", jobType, systemObj.getLabel());
continue;
}
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, systemObj.getActiveProviderURI());
if (provider == null || provider.getInactive()) {
_log.info("Skipping {} Job : StorageSystem {} does not have a valid active provider", jobType, systemObj.getLabel());
continue;
}
List<URI> systemIds = providerToSystemsMap.get(provider.getId());
if (systemIds == null) {
systemIds = new ArrayList<URI>();
providerToSystemsMap.put(provider.getId(), systemIds);
providerToSystemTypeMap.put(provider.getId(), systemObj.getSystemType());
}
systemIds.add(systemObj.getId());
} else if (systemObj.deviceIsType(Type.unity)) {
List<URI> systemIds = new ArrayList<URI>();
systemIds.add(systemObj.getId());
providerToSystemsMap.put(systemObj.getId(), systemIds);
providerToSystemTypeMap.put(systemObj.getId(), systemObj.getSystemType());
} else {
_log.info("Skip unsupported system {}, system type {}", systemObj.getLabel(), systemObj.getSystemType());
continue;
}
}
for (Map.Entry<URI, List<URI>> entry : providerToSystemsMap.entrySet()) {
List<URI> systemIds = entry.getValue();
BlockController controller = getController(BlockController.class, providerToSystemTypeMap.get(entry.getKey()));
DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new StorageSystemService.ArrayAffinityJobExec(controller));
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
tasks.add(new ArrayAffinityAsyncTask(StorageSystem.class, systemIds, hostIds, taskId));
taskList.getTaskList().addAll(scheduler.scheduleAsyncTasks(tasks).getTaskList());
}
return taskList;
}
Aggregations