Search in sources :

Example 51 with Task

use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.

the class AbstractVdcTaskOp method completeVdcAsyncTask.

protected void completeVdcAsyncTask(Operation.Status status, ServiceCoded coded) {
    try {
        List<Task> tasks = TaskUtils.findTasksForRequestId(dbClient, operateTaskId);
        URI vdcId = tasks.get(0).getResource().getURI();
        switch(status) {
            case error:
                // mark the task as failed
                dbClient.error(VirtualDataCenter.class, vdcId, operateTaskId, coded);
                break;
            default:
                dbClient.ready(VirtualDataCenter.class, vdcId, operateTaskId);
        }
        // TODO: add audit log here
        log.info("Done vdc Op {}, with Status: {}", operateTaskId, status.name());
    } catch (Exception e) {
        log.error("Failed updating status, for task " + operateTaskId, e);
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) CertificateException(java.security.cert.CertificateException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException)

Example 52 with Task

use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.

the class VolumeGroupService method checkForPendingTask.

/**
 * Check pending tasks. if preventAnyPendingTask is true, it will throw exception if there is any pending task
 * if preventAnyPendingTask is false, it will only throw exception if the pending task is in the PENDING_TASK_NAMES
 * (restore, delete snapshot and snapshotSession, detach full copy and delete volume)
 *
 * @param id the resource URI
 * @param dbClient
 * @param preventAnyPendingTask If throw error when there is any pending task
 */
private void checkForPendingTask(URI id, DbClient dbClient, boolean preventAnyPendingTask) {
    List<Task> newTasks = TaskUtils.findResourceTasks(dbClient, id);
    if (newTasks != null) {
        for (Task task : newTasks) {
            if (task != null && !task.getInactive() && task.isPending()) {
                if (preventAnyPendingTask) {
                    throw APIException.badRequests.cannotExecuteOperationWhilePendingTask(id.toString());
                } else {
                    String taskName = task.getLabel();
                    log.info(String.format("The pending task is %s", taskName));
                    if (taskName != null && PENDING_TASK_NAMES.contains(taskName)) {
                        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask(id.toString());
                    }
                }
            }
        }
    }
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task)

Example 53 with Task

use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.

the class ConsistencyGroupSnapshotService method getConsistencyGroupSnapshotDetail.

/**
 * Get Consistency Group Snapshot info
 *
 * @param openstackTenantId
 *            openstack tenant Id
 * @param consistencyGroupSnapshotId
 *            Consistency Group Snapshot Id
 * @param isV1Call
 *            Cinder V1 api
 * @param header
 *            HTTP Header
 * @brief
 *      Get Consistency Group Snapshot info
 * @return Response
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{consistencyGroupSnapshot_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getConsistencyGroupSnapshotDetail(@PathParam("tenant_id") String openstackTenantId, @PathParam("consistencyGroupSnapshot_id") String consistencyGroupSnapshotId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    if (project == null) {
        String message = "Bad Request: Project with the OpenStack Tenant Id : " + openstackTenantId + " does not exist";
        _log.error(message);
        return CinderApiUtils.createErrorResponse(400, message);
    }
    final BlockSnapshot snapshot = findSnapshot(consistencyGroupSnapshotId, openstackTenantId);
    if (null == snapshot) {
        _log.error("Bad Request : Invalid Snapshot Id {}", consistencyGroupSnapshotId);
        return CinderApiUtils.createErrorResponse(400, "Bad Request: No such snapshot id exist");
    } else if (!consistencyGroupSnapshotId.equals(CinderApiUtils.splitString(snapshot.getId().toString(), ":", 3))) {
        _log.error("Bad Request : Invalid Snapshot Id {} : Please enter valid or full Id", consistencyGroupSnapshotId);
        return CinderApiUtils.createErrorResponse(400, "Bad Request: No such snapshot id exist, Please enter valid or full Id");
    }
    ConsistencyGroupSnapshotDetail cgSnapshotDetail = new ConsistencyGroupSnapshotDetail();
    cgSnapshotDetail.id = consistencyGroupSnapshotId;
    cgSnapshotDetail.name = snapshot.getLabel();
    cgSnapshotDetail.created_at = CinderApiUtils.timeFormat(snapshot.getCreationTime());
    cgSnapshotDetail.consistencygroup_id = CinderApiUtils.splitString(snapshot.getConsistencyGroup().toString(), ":", 3);
    StringMap extensions = snapshot.getExtensions();
    String description = null;
    if (extensions != null) {
        description = extensions.get("display_description");
        _log.debug("Retreiving the tasks for snapshot id {}", snapshot.getId());
        List<Task> taskLst = TaskUtils.findResourceTasks(_dbClient, snapshot.getId());
        _log.debug("Retreived the tasks for snapshot id {}", snapshot.getId());
        String taskInProgressId = null;
        if (snapshot.getExtensions().containsKey("taskid")) {
            taskInProgressId = snapshot.getExtensions().get("taskid");
            Task acttask = TaskUtils.findTaskForRequestId(_dbClient, snapshot.getId(), taskInProgressId);
            for (Task tsk : taskLst) {
                if (tsk.getId().toString().equals(taskInProgressId)) {
                    if (tsk.getStatus().equals("ready")) {
                        cgSnapshotDetail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                    } else if (tsk.getStatus().equals("pending")) {
                        if (tsk.getDescription().equals(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT.getDescription())) {
                            cgSnapshotDetail.status = CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase();
                        } else if (tsk.getDescription().equals(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT.getDescription())) {
                            cgSnapshotDetail.status = CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase();
                        }
                    } else if (tsk.getStatus().equals("error")) {
                        cgSnapshotDetail.status = CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                    }
                    _dbClient.updateObject(snapshot);
                    break;
                }
            }
        } else if (snapshot.getExtensions().containsKey("status") && !snapshot.getExtensions().get("status").toString().toLowerCase().equals("")) {
            cgSnapshotDetail.status = snapshot.getExtensions().get("status").toString().toLowerCase();
        } else {
            // status is available
            cgSnapshotDetail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
        }
    }
    cgSnapshotDetail.description = (description == null) ? "" : description;
    return CinderApiUtils.getCinderResponse(cgSnapshotDetail, header, true, CinderConstants.STATUS_OK);
}
Also used : Project(com.emc.storageos.db.client.model.Project) StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ConsistencyGroupSnapshotDetail(com.emc.storageos.cinder.model.ConsistencyGroupSnapshotDetail) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 54 with Task

use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.

the class SnapshotService method getSnapshotDetail.

// INTERNAL FUNCTIONS
protected CinderSnapshot getSnapshotDetail(BlockSnapshot snapshot, String isV1Call, String openstack_tenant_id) {
    CinderSnapshot detail = new CinderSnapshot();
    detail.id = getCinderHelper().trimId(snapshot.getId().toString());
    detail.volume_id = getCinderHelper().trimId(snapshot.getParent().getURI().toString());
    detail.created_at = date(snapshot.getCreationTime().getTimeInMillis());
    detail.project_id = openstack_tenant_id;
    detail.size = (int) ((snapshot.getProvisionedCapacity() + HALF_GB) / GB);
    StringMap extensions = snapshot.getExtensions();
    String description = null;
    Map<String, String> metaMap = new HashMap<String, String>();
    if (extensions != null) {
        description = extensions.get("display_description");
        _log.debug("Retreiving the tasks for snapshot id {}", snapshot.getId());
        List<Task> taskLst = TaskUtils.findResourceTasks(_dbClient, snapshot.getId());
        _log.debug("Retreived the tasks for snapshot id {}", snapshot.getId());
        String taskInProgressId = null;
        if (snapshot.getExtensions().containsKey("taskid")) {
            taskInProgressId = snapshot.getExtensions().get("taskid");
            // Task acttask = TaskUtils.findTaskForRequestId(_dbClient, snapshot.getId(), taskInProgressId);
            for (Task tsk : taskLst) {
                if (tsk.getId().toString().equals(taskInProgressId)) {
                    if (tsk.getStatus().equals("ready")) {
                        detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                        _dbClient.updateObject(snapshot);
                    } else if (tsk.getStatus().equals("pending")) {
                        if (tsk.getDescription().equals(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT.getDescription())) {
                            detail.status = CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase();
                        } else if (tsk.getDescription().equals(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT.getDescription())) {
                            detail.status = CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase();
                        }
                    } else if (tsk.getStatus().equals("error")) {
                        detail.status = CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase();
                        snapshot.getExtensions().put("status", CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase());
                        snapshot.getExtensions().remove("taskid");
                        _dbClient.updateObject(snapshot);
                    }
                    break;
                }
            }
        } else if (snapshot.getExtensions().containsKey("status") && !snapshot.getExtensions().get("status").toString().toLowerCase().equals("")) {
            detail.status = snapshot.getExtensions().get("status").toString().toLowerCase();
        } else {
            // "available";
            detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
        }
        for (String mapEntry : extensions.keySet()) {
            if (mapEntry.startsWith("METADATA_")) {
                String value = extensions.get(mapEntry);
                metaMap.put(mapEntry.substring("METADATA_".length()), value);
            }
        }
    }
    if (isV1Call != null) {
        detail.display_name = snapshot.getLabel();
        detail.display_description = (description == null) ? "" : description;
    } else {
        detail.name = snapshot.getLabel();
        detail.description = (description == null) ? "" : description;
    }
    // default
    detail.progress = ZERO_PERCENT_COMPLETION;
    if ((detail.status == CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.ERROR.getStatus().toLowerCase()) || (detail.status == CinderConstants.ComponentStatus.ERROR_DELETING.getStatus().toLowerCase())) {
        detail.progress = ZERO_PERCENT_COMPLETION;
    } else if (detail.status == CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase()) {
        detail.progress = HUNDRED_PERCENT_COMPLETION;
    }
    detail.metadata = metaMap;
    return detail;
}
Also used : CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) HashMap(java.util.HashMap)

Example 55 with Task

use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.

the class BlockServiceUtils method checkForPendingTasks.

/**
 * Given a Tenant and DataObject references, check if any of the DataObjects have pending
 * Tasks against them. If so, generate an error that this cannot be deleted.
 *
 * @param tenant - [in] Tenant URI
 * @param dataObjects - [in] List of DataObjects to check
 * @param dbClient - Reference to a database client
 */
public static void checkForPendingTasks(URI tenant, Collection<? extends DataObject> dataObjects, DbClient dbClient) {
    // First, find tasks for the resources sent in.
    Set<URI> objectURIsThatHavePendingTasks = new HashSet<URI>();
    // Get a unique list of Task objects associated with the data objects
    for (DataObject dataObject : dataObjects) {
        List<Task> newTasks = TaskUtils.findResourceTasks(dbClient, dataObject.getId());
        for (Task newTask : newTasks) {
            if (newTask.isPending() && newTask.getTenant().equals(tenant)) {
                objectURIsThatHavePendingTasks.add(dataObject.getId());
            }
        }
    }
    // Search through the list of Volumes to see if any are in the pending list
    List<String> pendingObjectLabels = new ArrayList<>();
    for (DataObject dataObject : dataObjects) {
        if (dataObject.getInactive()) {
            continue;
        }
        String label = dataObject.getLabel();
        if (label == null) {
            label = dataObject.getId().toString();
        }
        if (objectURIsThatHavePendingTasks.contains(dataObject.getId())) {
            pendingObjectLabels.add(label);
            // Remove entry, since we already found it was matched.
            objectURIsThatHavePendingTasks.remove(dataObject.getId());
        }
    }
    // a pending task against them. Need to signal an error
    if (!pendingObjectLabels.isEmpty()) {
        String pendingListStr = Joiner.on(',').join(pendingObjectLabels);
        _log.warn(String.format("Attempted to execute operation against these resources while there are tasks pending against them: %s", pendingListStr));
        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask(pendingListStr);
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) HashSet(java.util.HashSet)

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