use of org.batfish.datamodel.pojo.WorkStatus in project batfish by batfish.
the class BfCoordWorkHelper method listIncompleteWork.
@Nullable
public List<WorkStatus> listIncompleteWork(String containerName) {
try {
WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_LIST_INCOMPLETE_WORK);
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_CONTAINER_NAME, containerName);
JSONObject jObj = postData(webTarget, multiPart);
if (jObj == null) {
return null;
}
if (!jObj.has(CoordConsts.SVC_KEY_WORK_LIST)) {
_logger.errorf("work list key not found in: %s\n", jObj);
return null;
}
String result = jObj.getString(CoordConsts.SVC_KEY_WORK_LIST);
List<WorkStatus> workList = BatfishObjectMapper.mapper().readValue(result, new TypeReference<List<WorkStatus>>() {
});
return workList;
} catch (Exception e) {
_logger.errorf("exception: ");
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
use of org.batfish.datamodel.pojo.WorkStatus in project batfish by batfish.
the class WorkMgrService method listIncompleteWork.
/**
* List incomplete work of the specified type for the specified container and testrig
*
* @param apiKey The API key of the client
* @param clientVersion The version of the client
* @param containerName The name of the container for which to list work
* @param testrigName (optional) The name of the testrig for which to list work
* @param workType (optional) The type of work to list
* @return TODO: document JSON response
*/
@POST
@Path(CoordConsts.SVC_RSC_LIST_INCOMPLETE_WORK)
@Produces(MediaType.APPLICATION_JSON)
public JSONArray listIncompleteWork(@FormDataParam(CoordConsts.SVC_KEY_API_KEY) String apiKey, @FormDataParam(CoordConsts.SVC_KEY_VERSION) String clientVersion, @FormDataParam(CoordConsts.SVC_KEY_CONTAINER_NAME) String containerName, @Nullable @FormDataParam(CoordConsts.SVC_KEY_TESTRIG_NAME) String testrigName, /* optional */
@Nullable @FormDataParam(CoordConsts.SVC_KEY_WORK_TYPE) WorkType workType) /* optional */
{
try {
_logger.infof("WMS:listIncompleteWork %s %s\n", apiKey, containerName);
checkStringParam(apiKey, "API key");
checkStringParam(clientVersion, "Client version");
checkStringParam(containerName, "Container name");
if (testrigName != null) {
checkStringParam(testrigName, "Base testrig name");
}
checkApiKeyValidity(apiKey);
checkClientVersion(clientVersion);
checkContainerAccessibility(apiKey, containerName);
List<WorkStatus> workList = new LinkedList<>();
for (QueuedWork work : Main.getWorkMgr().listIncompleteWork(containerName, testrigName, workType)) {
WorkStatus workStatus = new WorkStatus(work.getWorkItem(), work.getStatus(), work.getLastTaskCheckResult());
workList.add(workStatus);
}
return successResponse(new JSONObject().put(CoordConsts.SVC_KEY_WORK_LIST, BatfishObjectMapper.writePrettyString(workList)));
} catch (IllegalArgumentException | AccessControlException e) {
_logger.errorf("WMS:listIncompleteWork exception: %s\n", e.getMessage());
return failureResponse(e.getMessage());
} catch (Exception e) {
String stackTrace = ExceptionUtils.getStackTrace(e);
_logger.errorf("WMS:listIncompleteWork exception: %s", stackTrace);
return failureResponse(e.getMessage());
}
}
Aggregations