use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class TaskService method assignTags.
/**
* @brief Assign tags to resource
* Assign tags
*
* @prereq none
*
* @param id
* the URN of a ViPR resource
* @param assignment
* tag assignments
* @return No data returned in response body
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/tags")
@Override
public Tags assignTags(@PathParam("id") URI id, TagAssignment assignment) {
Task task = queryResource(id);
verifyUserHasAccessToTenants(Collections.singletonList(task.getTenant()));
return super.assignTags(id, assignment);
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class HostService method hostHasPendingTasks.
/**
* Check for pending tasks on the Host
*
* @param hostURI Host ID
* @return true if the host has pending tasks, false otherwise
*/
private boolean hostHasPendingTasks(URI hostURI) {
boolean hasPendingTasks = false;
List<Task> taskList = TaskUtils.findResourceTasks(_dbClient, hostURI);
for (Task task : taskList) {
if (task.isPending()) {
hasPendingTasks = true;
break;
}
}
return hasPendingTasks;
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class FileService method unAssignFilePolicy.
/**
* Unassign existing file system to file policy.
*
* @param id
* the URN of a ViPR fileSystem
* @param filePolicyUri
* the URN of a Policy
* @brief Update file system with Policy detail
* @return Task resource representation
* @throws InternalException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-file-policy/{filePolicyUri}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep unAssignFilePolicy(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri) throws InternalException {
// log input received.
_log.info("Unassign Policy on File System : request received for {} with {}", id, filePolicyUri);
String task = UUID.randomUUID().toString();
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
ArgValidator.checkUri(filePolicyUri);
FilePolicy fp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
ArgValidator.checkEntityNotNull(fp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
// verify the schedule policy is associated with file system or not.
if (!fs.getFilePolicies().isEmpty() && !fs.getFilePolicies().contains(filePolicyUri.toString())) {
throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
}
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, fp.getId(), task, ResourceOperationTypeEnum.UNASSIGN_FILE_POLICY);
op.setDescription("Filesystem unassign policy");
// As the action done by tenant admin
// Set current tenant as task's tenant!!!
Task taskObj = op.getTask(fp.getId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, fp, "unassign", taskObj, fs.getTenant().getURI());
try {
Set<URI> unassignFrom = new HashSet<URI>();
unassignFrom.add(id);
_log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, fp });
controller.unassignFilePolicy(filePolicyUri, unassignFrom, task);
auditOp(OperationTypeEnum.UNASSIGN_FILE_POLICY, true, "BEGIN", fp.getId().toString(), fp.getFilePolicyName());
} catch (BadRequestException e) {
op = _dbClient.error(FilePolicy.class, fp.getId(), task, e);
_log.error("Error Unassigning File policy {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Unassigning Filesystem policy {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(fp, task, op);
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class FileService method getFileSystemSchedulePolicySnapshots.
/**
* Get file system Snapshot created by policy
*
* @param id
* The URN of a ViPR file system
* @param filePolicyUri
* The URN of a file policy schedule
* @param timeout
* Time limit in seconds to get the output .Default is 30 seconds
* @brief Get snapshots related to the specified policy
* @return List of snapshots created by a file policy
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies/{filePolicyUri}/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ScheduleSnapshotList getFileSystemSchedulePolicySnapshots(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, @QueryParam("timeout") int timeout) {
// valid value of timeout is 10 sec to 10 min
if (timeout < 10 || timeout > 600) {
// default timeout value.
timeout = 30;
}
ScheduleSnapshotList list = new ScheduleSnapshotList();
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
ArgValidator.checkUri(filePolicyUri);
FilePolicy sp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
ArgValidator.checkEntityNotNull(sp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
// verify the schedule policy is associated with file system or not.
if (!fs.getFilePolicies().contains(filePolicyUri.toString())) {
throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
}
String task = UUID.randomUUID().toString();
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE);
op.setDescription("list snapshots created by a policy");
try {
_log.info("No Errors found. Proceeding further {}, {}, {}", new Object[] { _dbClient, fs, sp });
controller.listSanpshotByPolicy(device.getId(), fs.getId(), sp.getId(), task);
Task taskObject = null;
auditOp(OperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), sp.getId());
int timeoutCounter = 0;
// wait till timeout or result from controller service ,whichever is earlier
do {
TimeUnit.SECONDS.sleep(1);
taskObject = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), task);
timeoutCounter++;
// exit the loop if task is completed with error/success or timeout
} while ((taskObject != null && !(taskObject.isReady() || taskObject.isError())) && timeoutCounter < timeout);
if (taskObject == null) {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots task information");
} else if (taskObject.isReady()) {
URIQueryResultList snapshotsURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id), snapshotsURIs);
List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapshotsURIs);
for (Snapshot snap : snapList) {
if (!snap.getInactive() && snap.getExtensions().containsKey("schedule")) {
ScheduleSnapshotRestRep snapRest = new ScheduleSnapshotRestRep();
getScheduleSnapshotRestRep(snapRest, snap);
list.getScheduleSnapList().add(snapRest);
snap.setInactive(true);
_dbClient.updateObject(snap);
}
}
} else if (taskObject.isError()) {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to" + taskObject.getMessage());
} else {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to timeout");
}
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Error while getting Filesystem policy Snapshots {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
} catch (Exception e) {
_log.error("Error while getting Filesystem policy Snapshots {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return list;
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class BucketService method syncBucketACL.
private void syncBucketACL(Bucket bucket) throws InternalException {
// Make sure that we don't have some pending
// operation against the bucket
checkForPendingTasks(Arrays.asList(bucket.getTenant().getURI()), Arrays.asList(bucket));
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, bucket.getStorageDevice());
ObjectController controller = getController(ObjectController.class, storageSystem.getSystemType());
String task = UUID.randomUUID().toString();
_log.info(String.format("SYNC Bucket ACL --- Bucket id: %1$s, Task: %2$s", bucket.getId(), task));
Operation op = _dbClient.createTaskOpStatus(Bucket.class, bucket.getId(), task, ResourceOperationTypeEnum.SYNC_BUCKET_ACL);
op.setDescription("Sync Bucket ACL");
controller.syncBucketACL(bucket.getStorageDevice(), bucket.getId(), task);
auditOp(OperationTypeEnum.SYNC_BUCKET_ACL, true, AuditLogManager.AUDITOP_BEGIN, bucket.getId().toString(), bucket.getStorageDevice().toString());
toTask(bucket, task, op);
// Waiting till the task is ready to proceed.
boolean breakLoop = false;
boolean failedOp = true;
long startTime = System.currentTimeMillis();
String READY = "ready";
String ERROR = "error";
String message = "";
int MAX_SYNC_TIMEOUT = 8000;
while (!breakLoop) {
Task dbTask = TaskUtils.findTaskForRequestId(_dbClient, bucket.getId(), task);
if (READY.equals(dbTask.getStatus())) {
breakLoop = true;
failedOp = false;
}
if (ERROR.equals(dbTask.getStatus())) {
breakLoop = true;
message = dbTask.getMessage();
}
if ((System.currentTimeMillis() - startTime) > MAX_SYNC_TIMEOUT) {
breakLoop = true;
message = "Request Time-Out Wait untill bucket sync task is finished.";
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
// When we catch the InterruptException and swallow it, we essentially prevent any higher level methods/thread groups from
// noticing the interrupt. Which may cause problems.
// By calling Thread.currentThread().interrupt(), we set the interrupt flag of the thread, so higher level interrupt
// handlers will notice it and can handle it appropriately.
Thread.currentThread().interrupt();
}
}
if (failedOp) {
throw ECSException.exceptions.bucketACLUpdateFailed(bucket.getName(), "Could not get ACL from ECS {} " + message + " Please try again later.");
}
}
Aggregations