use of com.emc.storageos.storagedriver.DriverTask.TaskStatus in project coprhd-controller by CoprHD.
the class ExternalDeviceJob method poll.
/**
* {@inheritDoc}
*/
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
s_logger.info("Polled external device job for driver task {} on storage system {}", _driverTaskId, _storageSystemURI);
DriverTask driverTask = null;
DbClient dbClient = jobContext.getDbClient();
try {
// Update the job info.
_pollResult.setJobName(_driverTaskId);
_pollResult.setJobId(_driverTaskId);
_pollResult.setJobPercentComplete(0);
// Get the external storage system on which the driver task is running.
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, _storageSystemURI);
if (storageSystem == null) {
s_logger.error("Could not find external storage system {}", _storageSystemURI);
throw ExternalDeviceException.exceptions.cantFindStorageSystemForDriverTask(_storageSystemURI.toString(), _driverTaskId);
}
String systemType = storageSystem.getSystemType();
// Get the external storage driver for the system on which the task is executing.
BlockStorageDriver driver = ExternalBlockStorageDevice.getBlockStorageDriver(systemType);
if (driver == null) {
s_logger.error("Could not find storage driver for system type {}", systemType);
throw ExternalDeviceException.exceptions.noDriverDefinedForDevice(systemType);
}
// Get the storage driver task.
driverTask = driver.getTask(_driverTaskId);
if (driverTask == null) {
s_logger.error("Could not find storage driver task {} for storage system {}", _driverTaskId, _storageSystemURI.toString());
throw ExternalDeviceException.exceptions.cantFindDriverTaskOnSystem(_driverTaskId, _storageSystemURI.toString());
}
TaskStatus taskStatus = driverTask.getStatus();
String taskStatusMsg = driverTask.getMessage();
if (isTaskSuccessful(taskStatus)) {
// Completed successfully
s_logger.info(String.format("Task %s completed successfully with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
doTaskSucceeded(driverTask, dbClient);
_pollResult.setJobPercentComplete(100);
_status = JobStatus.SUCCESS;
} else if (isTaskFailed(taskStatus)) {
// Failed.
s_logger.info(String.format("Task %s failed with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
doTaskFailed(driverTask, dbClient);
_pollResult.setJobPercentComplete(100);
_errorDescription = taskStatusMsg;
_status = JobStatus.FAILED;
}
} catch (Exception e) {
_errorDescription = e.getMessage();
s_logger.error(String.format("Unexpected error getting external driver task status for task %s on storage system %s: %s", _driverTaskId, _storageSystemURI.toString(), _errorDescription), e);
try {
doTaskFailed(driverTask, dbClient);
} catch (Exception dtfe) {
s_logger.error("Unexpected error handling task failed", e);
}
_status = JobStatus.FAILED;
} finally {
updateStatus(dbClient);
}
_pollResult.setJobStatus(_status);
_pollResult.setErrorDescription(_errorDescription);
return _pollResult;
}
Aggregations