Search in sources :

Example 1 with JobPollResult

use of com.emc.storageos.volumecontroller.impl.JobPollResult in project coprhd-controller by CoprHD.

the class HDSMetaVolumeOperations method waitForAsyncHDSJob.

/**
 * Waits the thread to till the operation completes.
 *
 * @param storageDeviceURI
 * @param messageId
 * @param job
 * @param hdsApiFactory
 * @return
 * @throws HDSException
 */
private JobStatus waitForAsyncHDSJob(URI storageDeviceURI, String messageId, HDSJob job, HDSApiFactory hdsApiFactory) throws HDSException {
    JobStatus status = JobStatus.IN_PROGRESS;
    if (job == null) {
        TaskCompleter taskCompleter = new TaskCompleter() {

            @Override
            public void ready(DbClient dbClient) throws DeviceControllerException {
            }

            @Override
            public void error(DbClient dbClient, ServiceCoded serviceCoded) throws DeviceControllerException {
            }

            @Override
            protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
            }
        };
        job = new HDSJob(messageId, storageDeviceURI, taskCompleter, "");
    } else {
        job.setHDSJob(messageId);
    }
    JobContext jobContext = new JobContext(dbClient, null, null, hdsApiFactory, null, null, null, null);
    long startTime = System.currentTimeMillis();
    while (true) {
        JobPollResult result = job.poll(jobContext, SYNC_WRAPPER_WAIT);
        if (result.getJobStatus().equals(JobStatus.IN_PROGRESS) || result.getJobStatus().equals(JobStatus.ERROR)) {
            if (System.currentTimeMillis() - startTime > SYNC_WRAPPER_TIME_OUT) {
                HDSException.exceptions.asyncTaskFailedTimeout(System.currentTimeMillis() - startTime);
            } else {
                try {
                    Thread.sleep(SYNC_WRAPPER_WAIT);
                } catch (InterruptedException e) {
                    log.error("Thread waiting for hds job to complete was interrupted and " + "will be resumed");
                }
            }
        } else {
            status = result.getJobStatus();
            if (!status.equals(JobStatus.SUCCESS)) {
                HDSException.exceptions.asyncTaskFailedWithErrorResponseWithoutErrorCode(messageId, result.getErrorDescription());
            }
            break;
        }
    }
    return status;
}
Also used : JobStatus(com.emc.storageos.volumecontroller.Job.JobStatus) JobStatus(com.emc.storageos.volumecontroller.Job.JobStatus) DbClient(com.emc.storageos.db.client.DbClient) HDSJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MetaVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MetaVolumeTaskCompleter) JobContext(com.emc.storageos.volumecontroller.JobContext) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult)

Example 2 with JobPollResult

use of com.emc.storageos.volumecontroller.impl.JobPollResult in project coprhd-controller by CoprHD.

the class QueueJobTracker method run.

public void run() {
    HashMap<String, HashMap<String, Integer>> jobProgressMap = new HashMap<String, HashMap<String, Integer>>();
    while (true) {
        JobWrapper jobWrapper = null;
        _logger.debug("Tracker: Will check job status after {} ms...", _trackingPeriodInMillis);
        try {
            ArrayList<String> completedJobs = new ArrayList<String>();
            Thread.sleep(_trackingPeriodInMillis);
            _logger.debug("Tracker: Checking status of {} jobs", _activeJobs.size());
            for (Iterator<JobWrapper> iter = _activeJobs.iterator(); iter.hasNext(); ) {
                jobWrapper = iter.next();
                Job job = jobWrapper.getJob();
                try {
                    setPollingStartTime(job);
                    JobPollResult result = job.poll(_jobContext, _trackingPeriodInMillis);
                    updateJobProgress(jobProgressMap, result);
                    boolean stopJobTracking = false;
                    String msg = null;
                    // Check if we have to stop job tracking.
                    if (result.isJobInTerminalState()) {
                        // stop tracking jobs in final status and final post processing status
                        msg = String.format("Tracker: Stopping tracking job %s with status: %s and post-processing status %s", result.getJobId(), result.getJobStatus(), result.getJobPostProcessingStatus());
                        stopJobTracking = true;
                    } else {
                        long trackingTime = System.currentTimeMillis() - job.getPollingStartTime();
                        if (trackingTime > job.getTimeoutTimeMsec()) {
                            // Stop tracking job if maximum job tracking time was reached.
                            msg = String.format("Tracker: Stopping tracking job %s with status: %s and post-processing status %s .\n" + "The job tracking time reached job tracking time limit %d hours, job tracking time %d hours.", result.getJobId(), result.getJobStatus(), result.getJobPostProcessingStatus(), job.getTimeoutTimeMsec() / (60 * 60 * 1000), trackingTime / (60 * 60 * 1000));
                            _logger.info(msg);
                            String errorMsg = String.format("Could not execute job %s on backend device. Exceeded time limit for job status tracking.", result.getJobName());
                            if (job instanceof VPlexMigrationJob) {
                                errorMsg = String.format("Could not execute VPlex Migration Job %s on backend device. Exceeded time limit for VPLEX migration timeout.", result.getJobName());
                            }
                            ServiceError error = DeviceControllerException.errors.unableToExecuteJob(errorMsg);
                            job.getTaskCompleter().error(_jobContext.getDbClient(), error);
                            stopJobTracking = true;
                        }
                    }
                    if (stopJobTracking) {
                        _logger.info(msg);
                        stopTrackingJob(jobWrapper);
                        completedJobs.add(result.getJobId());
                    }
                } catch (Exception ex) {
                    _logger.error("Tracker: Unexpected exception.", ex);
                }
            }
            if (!jobProgressMap.isEmpty()) {
                _logger.info(String.format("Progress of jobs - %n %s", jobProgressMap.toString()));
            }
            removeCompletedJobProgressItems(jobProgressMap, completedJobs);
        } catch (InterruptedException ie) {
            _logger.info("Tracker: Unexpected Interrupted exception.", ie);
        } catch (Exception e) {
            _logger.info("Tracker: Unexpected exception.", e);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VPlexMigrationJob(com.emc.storageos.vplexcontroller.job.VPlexMigrationJob) VPlexMigrationJob(com.emc.storageos.vplexcontroller.job.VPlexMigrationJob) Job(com.emc.storageos.volumecontroller.Job) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult)

Example 3 with JobPollResult

use of com.emc.storageos.volumecontroller.impl.JobPollResult in project coprhd-controller by CoprHD.

the class SmisCommandHelper method waitForAsyncSmisJob.

private void waitForAsyncSmisJob(StorageSystem storageDevice, CIMObjectPath cimJobPath, SmisJob job) throws SmisException {
    if (job == null) {
        TaskCompleter taskCompleter = new TaskCompleter() {

            @Override
            public void ready(DbClient dbClient) throws DeviceControllerException {
            }

            @Override
            public void error(DbClient dbClient, ServiceCoded serviceCoded) throws DeviceControllerException {
            }

            @Override
            protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
            }
        };
        job = new SmisJob(cimJobPath, storageDevice.getId(), taskCompleter, "");
    } else {
        job.setCimJob(cimJobPath);
    }
    JobContext jobContext = new JobContext(_dbClient, _cimConnection, null, null, null, null, this);
    long startTime = System.currentTimeMillis();
    int sync_wrapper_time_out = InvokeTestFailure.internalOnlyOverrideSyncWrapperTimeOut(SYNC_WRAPPER_TIME_OUT);
    while (true) {
        JobPollResult result = job.poll(jobContext, SYNC_WRAPPER_WAIT);
        if (!result.isJobInTerminalState()) {
            if (System.currentTimeMillis() - startTime > sync_wrapper_time_out) {
                throw new SmisException("Timed out waiting on smis job to complete after " + (System.currentTimeMillis() - startTime) + " milliseconds");
            } else {
                try {
                    Thread.sleep(SYNC_WRAPPER_WAIT);
                } catch (InterruptedException e) {
                    _log.error("Thread waiting for smis job to complete was interrupted and " + "will be resumed");
                }
            }
        } else {
            if (result.isJobInTerminalFailedState()) {
                throw new SmisException("Smis job failed: " + result.getErrorDescription());
            }
            break;
        }
    }
}
Also used : LinkStatus(com.emc.storageos.db.client.model.Volume.LinkStatus) DbClient(com.emc.storageos.db.client.DbClient) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) SmisJob(com.emc.storageos.volumecontroller.impl.smis.job.SmisJob) JobContext(com.emc.storageos.volumecontroller.JobContext) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 4 with JobPollResult

use of com.emc.storageos.volumecontroller.impl.JobPollResult in project coprhd-controller by CoprHD.

the class SmisWaitForGroupSynchronizedJob method poll.

@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    JobPollResult pollResult = new JobPollResult();
    DbClient dbClient = jobContext.getDbClient();
    CIMConnectionFactory factory = jobContext.getCimConnectionFactory();
    WBEMClient client = getWBEMClient(dbClient, factory);
    TaskCompleter completer = getTaskCompleter();
    List<Volume> clones = dbClient.queryObject(Volume.class, completer.getIds());
    try {
        pollResult.setJobName(getJobName());
        pollResult.setJobId(SmisConstants.CP_PERCENT_SYNCED);
        pollResult.setJobStatus(JobStatus.IN_PROGRESS);
        CIMObjectPath path = getGroupSyncPath();
        // no corresponding sync obj, set to complete
        if (SmisConstants.NULL_IBM_CIM_OBJECT_PATH.equals(path)) {
            log.info("Sync complete");
            pollResult.setJobPercentComplete(100);
            pollResult.setJobStatus(JobStatus.SUCCESS);
            completer.ready(dbClient);
            return pollResult;
        }
        String[] propertyKeys = { SmisConstants.CP_SYNC_STATE, SmisConstants.CP_SYNC_TYPE, SmisConstants.CP_PERCENT_SYNCED, SmisConstants.CP_PROGRESS_STATUS };
        CIMInstance syncInstance = client.getInstance(path, false, false, propertyKeys);
        if (syncInstance != null) {
            String state = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_STATE);
            String type = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_TYPE);
            String percent = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PERCENT_SYNCED);
            String status = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PROGRESS_STATUS);
            String msg = String.format("Target=%s, State=%s, Type=%s, Percent=%s, Status=%s", clones.get(0).getId(), state, type, percent, status);
            log.info(msg);
            pollResult.setJobPercentComplete(Integer.parseInt(percent));
            if (COMPLETE.equals(percent)) {
                pollResult.setJobStatus(JobStatus.SUCCESS);
                completer.ready(dbClient);
            }
        } else {
            pollResult.setJobStatus(JobStatus.FAILED);
        }
    } catch (Exception e) {
        log.error("Failed to update synchronization", e);
        pollResult.setJobStatus(JobStatus.FAILED);
        completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
    }
    return pollResult;
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) CIMObjectPath(javax.cim.CIMObjectPath) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 5 with JobPollResult

use of com.emc.storageos.volumecontroller.impl.JobPollResult in project coprhd-controller by CoprHD.

the class SmisWaitForSynchronizedJob method poll.

@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    JobPollResult pollResult = new JobPollResult();
    DbClient dbClient = jobContext.getDbClient();
    CIMConnectionFactory factory = jobContext.getCimConnectionFactory();
    WBEMClient client = getWBEMClient(dbClient, factory);
    TaskCompleter completer = getTaskCompleter();
    BlockObject target = dbClient.queryObject(clazz, completer.getId());
    CloseableIterator<CIMInstance> references = null;
    try {
        pollResult.setJobName(getJobName());
        pollResult.setJobId(SmisConstants.CP_PERCENT_SYNCED);
        pollResult.setJobStatus(JobStatus.IN_PROGRESS);
        CIMObjectPath path = getTargetPath();
        // no corresponding sync obj, set to complete
        if (SmisConstants.NULL_IBM_CIM_OBJECT_PATH.equals(path)) {
            log.info("Sync complete");
            pollResult.setJobPercentComplete(100);
            pollResult.setJobStatus(JobStatus.SUCCESS);
            completer.ready(dbClient);
            return pollResult;
        }
        references = client.referenceInstances(getTargetPath(), SmisConstants.CIM_STORAGE_SYNCHRONIZED, null, false, null);
        if (references.hasNext()) {
            CIMInstance syncInstance = references.next();
            String state = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_STATE);
            String type = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_TYPE);
            String percent = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PERCENT_SYNCED);
            String status = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PROGRESS_STATUS);
            String msg = String.format("Target=%s, State=%s, Type=%s, Percent=%s, Status=%s", target.getId(), state, type, percent, status);
            log.info(msg);
            pollResult.setJobPercentComplete(Integer.parseInt(percent));
            if (COMPLETE.equals(percent)) {
                pollResult.setJobStatus(JobStatus.SUCCESS);
                completer.ready(dbClient);
            }
        } else {
            pollResult.setJobStatus(JobStatus.FAILED);
        }
    } catch (Exception e) {
        log.error("Failed to update synchronization", e);
        pollResult.setJobStatus(JobStatus.FAILED);
        completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
    } finally {
        if (references != null) {
            references.close();
        }
    }
    return pollResult;
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) CIMObjectPath(javax.cim.CIMObjectPath) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult) WBEMClient(javax.wbem.client.WBEMClient) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

JobPollResult (com.emc.storageos.volumecontroller.impl.JobPollResult)7 DbClient (com.emc.storageos.db.client.DbClient)4 JobContext (com.emc.storageos.volumecontroller.JobContext)4 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)2 JobStatus (com.emc.storageos.volumecontroller.Job.JobStatus)2 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)2 CIMInstance (javax.cim.CIMInstance)2 CIMObjectPath (javax.cim.CIMObjectPath)2 WBEMClient (javax.wbem.client.WBEMClient)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 Volume (com.emc.storageos.db.client.model.Volume)1 LinkStatus (com.emc.storageos.db.client.model.Volume.LinkStatus)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 Job (com.emc.storageos.volumecontroller.Job)1 MetaVolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.MetaVolumeTaskCompleter)1 HDSJob (com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob)1 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)1