Search in sources :

Example 1 with WorkStatus

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;
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) JSONObject(org.codehaus.jettison.json.JSONObject) WorkStatus(org.batfish.datamodel.pojo.WorkStatus) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) BatfishException(org.batfish.common.BatfishException) ProcessingException(javax.ws.rs.ProcessingException) Nullable(javax.annotation.Nullable)

Example 2 with WorkStatus

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());
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WorkStatus(org.batfish.datamodel.pojo.WorkStatus) AccessControlException(java.security.AccessControlException) LinkedList(java.util.LinkedList) BatfishException(org.batfish.common.BatfishException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileExistsException(org.apache.commons.io.FileExistsException) AccessControlException(java.security.AccessControlException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

BatfishException (org.batfish.common.BatfishException)2 WorkStatus (org.batfish.datamodel.pojo.WorkStatus)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 AccessControlException (java.security.AccessControlException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ProcessingException (javax.ws.rs.ProcessingException)1 Produces (javax.ws.rs.Produces)1 WebTarget (javax.ws.rs.client.WebTarget)1 FileExistsException (org.apache.commons.io.FileExistsException)1 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)1