Search in sources :

Example 6 with Task

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);
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 7 with Task

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;
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task)

Example 8 with Task

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);
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) 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)

Example 9 with Task

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;
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileController(com.emc.storageos.volumecontroller.FileController) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ScheduleSnapshotRestRep(com.emc.storageos.model.file.ScheduleSnapshotRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with Task

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.");
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) ObjectController(com.emc.storageos.volumecontroller.ObjectController) Operation(com.emc.storageos.db.client.model.Operation) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Task (com.emc.storageos.db.client.model.Task)57 URI (java.net.URI)21 Operation (com.emc.storageos.db.client.model.Operation)20 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)17 DataObject (com.emc.storageos.db.client.model.DataObject)15 NamedURI (com.emc.storageos.db.client.model.NamedURI)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)8 MapTask (com.emc.storageos.api.mapper.functions.MapTask)7 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)7 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)7 Volume (com.emc.storageos.db.client.model.Volume)6 WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)5