use of com.emc.storageos.vnxe.models.MessageOut in project coprhd-controller by CoprHD.
the class VNXeJob method poll.
@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
String currentJob = _jobIds.get(0);
try {
_logger.info("VNXeJob: Looking up job: id {}", _jobIds.get(0));
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
StringBuilder prettyMsg = new StringBuilder();
if (vnxeApiClient == null) {
String errorMessage = "No VNXe client found for: " + _storageSystemUri;
processTransientError(currentJob, trackingPeriodInMillis, errorMessage, null);
} else {
_pollResult.setJobName(_jobName);
_pollResult.setJobId(_taskCompleter.getOpId());
int completeCount = 0;
boolean isSuccess = true;
StringBuilder msg = new StringBuilder();
for (String jobId : _jobIds) {
currentJob = jobId;
VNXeCommandJob jobResult = vnxeApiClient.getJob(jobId);
MessageOut msgOut = jobResult.getMessageOut();
int progressPct = jobResult.getProgressPct();
int state = jobResult.getState();
if (state == VNXeCommandJob.JobStatusEnum.FAILED.getValue()) {
completeCount++;
isSuccess = false;
msg.append("Async task failed for jobID ");
msg.append(jobId);
if (msgOut != null) {
msg.append(" " + msgOut.getMessage());
String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
prettyMsg.append(cleanMsg);
}
continue;
}
if (progressPct == 100 && state != VNXeCommandJob.JobStatusEnum.RUNNING.getValue()) {
completeCount++;
if (state != VNXeCommandJob.JobStatusEnum.COMPLETED.getValue()) {
msg.append("Async task failed for jobID ");
msg.append(jobId);
if (msgOut != null) {
msg.append(" " + msgOut.getMessage());
String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
prettyMsg.append(cleanMsg);
}
}
}
}
if (completeCount == _jobIds.size()) {
// all completed
_pollResult.setJobPercentComplete(100);
if (isSuccess) {
_status = JobStatus.SUCCESS;
_logger.info("Job: {} succeeded", _jobName);
} else {
_status = JobStatus.FAILED;
_errorDescription = prettyMsg.toString();
_logger.info(msg.toString());
}
} else {
_pollResult.setJobPercentComplete(100 * completeCount / _jobIds.size());
}
}
} catch (Exception e) {
processTransientError(currentJob, trackingPeriodInMillis, e.getMessage(), e);
} finally {
try {
updateStatus(jobContext);
} catch (Exception e) {
setErrorStatus(e.getMessage());
_logger.error("Problem while trying to update status", e);
}
}
_pollResult.setJobStatus(_status);
_pollResult.setErrorDescription(_errorDescription);
return _pollResult;
}
Aggregations