Search in sources :

Example 1 with JobStatus

use of com.emc.storageos.volumecontroller.Job.JobStatus 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 JobStatus

use of com.emc.storageos.volumecontroller.Job.JobStatus in project coprhd-controller by CoprHD.

the class XIVSmisCommandHelper method waitForSmisJob.

private JobStatus waitForSmisJob(StorageSystem storageDevice, SmisJob job, int pollCycleLimit) throws SmisException {
    JobStatus status = JobStatus.IN_PROGRESS;
    JobContext jobContext = new JobContext(_dbClient, _cimConnection, null, null, null, null, null, this);
    long startTime = System.currentTimeMillis();
    int pollCycleCount = 0;
    while (true) {
        JobPollResult result = job.poll(jobContext, SYNC_WRAPPER_WAIT);
        pollCycleCount++;
        if (result.getJobStatus().equals(JobStatus.IN_PROGRESS)) {
            if (pollCycleCount > pollCycleLimit) {
                throw new SmisException("Reached maximum number of poll " + pollCycleLimit);
            } else 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 {
            status = result.getJobStatus();
            if (!status.equals(JobStatus.SUCCESS)) {
                throw new SmisException("Smis job failed: " + result.getErrorDescription());
            }
            break;
        }
    }
    return status;
}
Also used : JobStatus(com.emc.storageos.volumecontroller.Job.JobStatus) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) JobContext(com.emc.storageos.volumecontroller.JobContext) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult)

Aggregations

JobStatus (com.emc.storageos.volumecontroller.Job.JobStatus)2 JobContext (com.emc.storageos.volumecontroller.JobContext)2 JobPollResult (com.emc.storageos.volumecontroller.impl.JobPollResult)2 DbClient (com.emc.storageos.db.client.DbClient)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)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