Search in sources :

Example 36 with WorkItem

use of org.batfish.common.WorkItem in project batfish by batfish.

the class WorkQueueMgr method generateAndQueueDataplaneWork.

private QueuedWork generateAndQueueDataplaneWork(String container, String testrig, String environment) throws Exception {
    WorkItem newWItem = WorkItemBuilder.getWorkItemGenerateDataPlane(container, testrig, environment);
    WorkDetails details = new WorkDetails(testrig, environment, null, null, false, WorkType.DATAPLANING);
    QueuedWork newWork = new QueuedWork(newWItem, details);
    boolean queued = queueUnassignedWork(newWork);
    if (!queued) {
        throw new BatfishException("Failed to auto-queue dataplane work");
    }
    return newWork;
}
Also used : BatfishException(org.batfish.common.BatfishException) WorkItem(org.batfish.common.WorkItem)

Example 37 with WorkItem

use of org.batfish.common.WorkItem in project batfish by batfish.

the class WorkQueueMgr method getBlockerForDataplaningWork.

private QueuedWork getBlockerForDataplaningWork(QueuedWork work) throws IOException {
    WorkItem wItem = work.getWorkItem();
    WorkDetails wDetails = work.getDetails();
    QueuedWork currentParsingWork = getIncompleteWork(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv, WorkType.PARSING);
    EnvironmentMetadata envMetadata = TestrigMetadataMgr.getEnvironmentMetadata(wItem.getContainerName(), wDetails.baseTestrig, wDetails.baseEnv);
    switch(envMetadata.getProcessingStatus()) {
        case UNINITIALIZED:
        case PARSING_FAIL:
        case PARSING:
            if (currentParsingWork == null) {
                throw new BatfishException(String.format("Cannot queue dataplane work for %s / %s: " + "Status is %s but no incomplete parsing work exists", wDetails.baseTestrig, wDetails.baseEnv, envMetadata.getProcessingStatus()));
            }
            return currentParsingWork;
        case PARSED:
            return currentParsingWork;
        case DATAPLANING:
            // we get here only when currentDataplaningWork is null; by virtue of the calling context
            throw new BatfishException(String.format("Cannot queue dataplane work for %s / %s: " + "Status is %s but no incomplete dataplaning work exists", wDetails.baseTestrig, wDetails.baseEnv, envMetadata.getProcessingStatus()));
        case DATAPLANED:
        case DATAPLANING_FAIL:
            return null;
        default:
            throw new BatfishException("Unknown testrig processingStatus: " + envMetadata.getProcessingStatus());
    }
}
Also used : BatfishException(org.batfish.common.BatfishException) WorkItem(org.batfish.common.WorkItem) EnvironmentMetadata(org.batfish.datamodel.EnvironmentMetadata)

Example 38 with WorkItem

use of org.batfish.common.WorkItem in project batfish by batfish.

the class Client method handleSigInt.

public void handleSigInt() {
    _logger.info("Got SIGINT\n");
    WorkItem wItem = _polledWorkItem;
    if (wItem != null) {
        _logger.outputf("Killing %s\n", wItem.getId());
        boolean result = _workHelper.killWork(_polledWorkItem.getId());
        _logger.outputf("Result of killing %s: %s\n", wItem.getId(), result);
    } else {
        _logger.output("No work being polled\n");
    }
}
Also used : WorkItem(org.batfish.common.WorkItem)

Example 39 with WorkItem

use of org.batfish.common.WorkItem in project batfish by batfish.

the class Client method reinitTestrig.

private boolean reinitTestrig(@Nullable FileWriter outWriter, List<String> options, List<String> parameters, boolean delta) {
    Command command = delta ? Command.REINIT_DELTA_TESTRIG : Command.REINIT_TESTRIG;
    if (!isValidArgument(options, parameters, 0, 0, 0, command)) {
        return false;
    }
    String testrig;
    if (!delta) {
        _logger.output("Reinitializing testrig. Parsing now.\n");
        testrig = _currTestrig;
    } else {
        _logger.output("Reinitializing delta testrig. Parsing now.\n");
        testrig = _currDeltaTestrig;
    }
    WorkItem wItemParse = WorkItemBuilder.getWorkItemParse(_currContainerName, testrig);
    if (!execute(wItemParse, outWriter)) {
        return false;
    }
    return true;
}
Also used : WorkItem(org.batfish.common.WorkItem)

Example 40 with WorkItem

use of org.batfish.common.WorkItem in project batfish by batfish.

the class Client method answerFile.

private boolean answerFile(Path questionFile, boolean isDifferential, boolean isDelta, FileWriter outWriter) {
    if (!Files.exists(questionFile)) {
        throw new BatfishException("Question file not found: " + questionFile);
    }
    String questionName = DEFAULT_QUESTION_PREFIX + "_" + UUID.randomUUID();
    // upload the question
    boolean resultUpload = _workHelper.uploadQuestion(_currContainerName, isDelta ? _currDeltaTestrig : _currTestrig, questionName, questionFile.toAbsolutePath().toString());
    if (!resultUpload) {
        return false;
    }
    _logger.debug("Uploaded question. Answering now.\n");
    // answer the question
    WorkItem wItemAs = WorkItemBuilder.getWorkItemAnswerQuestion(questionName, _currContainerName, _currTestrig, _currEnv, _currDeltaTestrig, _currDeltaEnv, isDifferential, isDelta);
    return execute(wItemAs, outWriter);
}
Also used : BatfishException(org.batfish.common.BatfishException) WorkItem(org.batfish.common.WorkItem)

Aggregations

WorkItem (org.batfish.common.WorkItem)44 Test (org.junit.Test)15 BatfishException (org.batfish.common.BatfishException)14 IOException (java.io.IOException)6 EnvironmentMetadata (org.batfish.datamodel.EnvironmentMetadata)5 JSONObject (org.codehaus.jettison.json.JSONObject)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FileNotFoundException (java.io.FileNotFoundException)3 Path (java.nio.file.Path)3 AccessControlException (java.security.AccessControlException)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 FileExistsException (org.apache.commons.io.FileExistsException)3 JSONException (org.codehaus.jettison.json.JSONException)3 LinkedList (java.util.LinkedList)2 Task (org.batfish.common.Task)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1