use of org.batfish.common.CoordConsts.WorkStatusCode in project batfish by batfish.
the class Client method printWorkStatusResponse.
private void printWorkStatusResponse(Pair<WorkStatusCode, String> response, boolean unconditionalPrint) {
if (unconditionalPrint || _logger.getLogLevel() >= BatfishLogger.LEVEL_INFO) {
WorkStatusCode status = response.getFirst();
_logger.outputf("status: %s\n", status);
Task task;
try {
task = BatfishObjectMapper.mapper().readValue(response.getSecond(), Task.class);
} catch (IOException e) {
_logger.errorf("Could not deserialize task object: %s\n", e);
return;
}
if (task == null) {
_logger.outputf(".... no task information\n");
return;
}
List<Batch> batches = task.getBatches();
// else print all
for (int i = 0; i < batches.size(); i++) {
if (i == batches.size() - 1 || status.isTerminated()) {
_logger.outputf(".... %s\n", batches.get(i));
} else {
_logger.debugf(".... %s\n", batches.get(i));
}
}
if (status.isTerminated()) {
_logger.outputf(".... %s: %s\n", task.getTerminated(), status);
}
}
}
use of org.batfish.common.CoordConsts.WorkStatusCode in project batfish by batfish.
the class Client method pollWork.
private boolean pollWork(UUID wItemId, @Nullable FileWriter outWriter) {
Pair<WorkStatusCode, String> response;
try (ActiveSpan workStatusSpan = GlobalTracer.get().buildSpan("Waiting for work status").startActive()) {
// avoid unused warning
assert workStatusSpan != null;
// Poll the work item until it finishes or fails.
response = _workHelper.getWorkStatus(wItemId);
if (response == null) {
return false;
}
WorkStatusCode status = response.getFirst();
Backoff backoff = Backoff.builder().withMaximumBackoff(Duration.ofSeconds(1)).build();
while (!status.isTerminated() && backoff.hasNext()) {
printWorkStatusResponse(response, false);
try {
Thread.sleep(backoff.nextBackoff().toMillis());
} catch (InterruptedException e) {
throw new BatfishException("Interrupted while waiting for work item to complete", e);
}
response = _workHelper.getWorkStatus(wItemId);
if (response == null) {
return false;
}
status = response.getFirst();
}
printWorkStatusResponse(response, false);
}
return true;
}
use of org.batfish.common.CoordConsts.WorkStatusCode in project batfish by batfish.
the class Client method getWorkStatus.
private boolean getWorkStatus(@Nullable FileWriter outWriter, List<String> options, List<String> parameters) {
if (!isValidArgument(options, parameters, 0, 1, 1, Command.GET_WORK_STATUS)) {
return false;
}
UUID workId = UUID.fromString(parameters.get(0));
Pair<WorkStatusCode, String> response = _workHelper.getWorkStatus(workId);
if (response == null) {
return false;
}
printWorkStatusResponse(response, true);
logOutput(outWriter, "status: " + response.getFirst());
return true;
}
use of org.batfish.common.CoordConsts.WorkStatusCode in project batfish by batfish.
the class BfCoordWorkHelper method getWorkStatus.
@Nullable
public Pair<WorkStatusCode, String> getWorkStatus(UUID workId) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_GET_WORKSTATUS);
MultiPart multiPart = new MultiPart();
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey());
addTextMultiPart(multiPart, CoordConsts.SVC_KEY_WORKID, workId.toString());
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_WORKSTATUS)) {
_logger.errorf("workstatus key not found in: %s\n", jObj);
return null;
}
WorkStatusCode workStatus = WorkStatusCode.valueOf(jObj.getString(CoordConsts.SVC_KEY_WORKSTATUS));
if (!jObj.has(CoordConsts.SVC_KEY_TASKSTATUS)) {
_logger.errorf("taskstatus key not found in: %s\n", jObj);
}
String taskStr = jObj.getString(CoordConsts.SVC_KEY_TASKSTATUS);
return new Pair<>(workStatus, taskStr);
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
Aggregations