* @param jobId the jobId returned from a succesful commit post
* @return either success or a publish error
*/
private JobStatus getJobStatus(String datasetId, String jobId) throws
URISyntaxException, IOException, InterruptedException, HttpException {
JobStatus jobStatus = null;
String status = null;
StatusLine statusLine = null;
URI statusUri = baseUri.setPath(datasyncPath + "/" + datasetId + statusPath + "/" + jobId).build();
URI logUri = baseUri.setPath(datasyncPath + "/" + datasetId + logPath + "/" + jobId + ".json").build();
int retries = 0;
while (jobStatus == null && retries < httpRetries) {
try(CloseableHttpResponse response = http.get(statusUri, ContentType.APPLICATION_JSON.getMimeType())) {
statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
status = IOUtils.toString(response.getEntity().getContent());
System.out.print("Polling the job status: " + status);
if (status.startsWith("SUCCESS")) {
jobStatus = JobStatus.SUCCESS;
} else if (status.startsWith("FAILURE")) {
jobStatus = JobStatus.PUBLISH_ERROR;
} else {
Thread.sleep(1000);
}
} else if (statusCode != HttpStatus.SC_NOT_MODIFIED) {
retries += 1;
Thread.sleep(1000);
}
}
}
if (jobStatus == null) {
throw new HttpException(statusLine.toString());
}
jobStatus.setMessage(status + "(jobId:" + jobId + ")");
if(!jobStatus.isError()) loadStatusWithCRUD(jobStatus, logUri);
return jobStatus;
}