Search in sources :

Example 26 with WorkItem

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

the class WorkQueueMgrTest method workIsRejected.

private void workIsRejected(ProcessingStatus trStatus, WorkType wType) throws Exception {
    initTestrigMetadata(BASE_TESTRIG, BASE_ENV, trStatus);
    QueuedWork work = new QueuedWork(new WorkItem(CONTAINER, BASE_TESTRIG), new WorkDetails(BASE_TESTRIG, BASE_ENV, wType));
    _thrown.expect(BatfishException.class);
    _thrown.expectMessage("Cannot queue ");
    doAction(new Action(ActionType.QUEUE, work));
}
Also used : WorkItem(org.batfish.common.WorkItem)

Example 27 with WorkItem

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

the class WorkQueueMgrTest method listIncompleteWork.

@Test
public void listIncompleteWork() throws Exception {
    initTestrigMetadata("testrig", "env", ProcessingStatus.UNINITIALIZED);
    initTestrigMetadata("other", "testrig", "env", ProcessingStatus.UNINITIALIZED);
    QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
    QueuedWork work2 = new QueuedWork(new WorkItem("other", "testrig"), new WorkDetails("testrig", "env", WorkType.UNKNOWN));
    _workQueueMgr.queueUnassignedWork(work1);
    _workQueueMgr.queueUnassignedWork(work2);
    List<QueuedWork> works = _workQueueMgr.listIncompleteWork(CONTAINER, null, null);
    assertThat(works, equalTo(Collections.singletonList(work1)));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 28 with WorkItem

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

the class WorkQueueMgrTest method queueWork.

private void queueWork(String testrig, String environment, WorkType wType) throws Exception {
    QueuedWork work = new QueuedWork(new WorkItem(CONTAINER, testrig), new WorkDetails(testrig, environment, wType));
    _workQueueMgr.queueUnassignedWork(work);
}
Also used : WorkItem(org.batfish.common.WorkItem)

Example 29 with WorkItem

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

the class WorkQueueMgrTest method dataplaningAfterParsingFailure.

@Test
public void dataplaningAfterParsingFailure() throws Exception {
    initTestrigMetadata("other", "other", ProcessingStatus.UNINITIALIZED);
    QueuedWork work1 = new QueuedWork(new WorkItem(CONTAINER, "other"), new WorkDetails("other", "other", WorkType.PARSING));
    _workQueueMgr.queueUnassignedWork(work1);
    QueuedWork work2 = new QueuedWork(new WorkItem(CONTAINER, "other"), new WorkDetails("other", "other", WorkType.DATAPLANING));
    _workQueueMgr.queueUnassignedWork(work2);
    QueuedWork aWork1 = // should be parsing work (work1)
    doAction(new Action(ActionType.ASSIGN_SUCCESS, null));
    doAction(new Action(ActionType.STATUS_TERMINATED_ABNORMALLY, aWork1));
    // work2 should be left with terminatedqueuefail status and the testrig in parsing_fail state
    assertThat(work2.getStatus(), equalTo(WorkStatusCode.REQUEUEFAILURE));
    assertThat(TestrigMetadataMgr.getEnvironmentMetadata(CONTAINER, "other", "other").getProcessingStatus(), equalTo(ProcessingStatus.PARSING_FAIL));
}
Also used : WorkItem(org.batfish.common.WorkItem) Test(org.junit.Test)

Example 30 with WorkItem

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

the class WorkMgr method initTestrig.

@Override
public void initTestrig(String containerName, String testrigName, Path srcDir, boolean autoAnalyze) {
    /*
     * Sanity check what we got:
     *    There should be just one top-level folder.
     */
    SortedSet<Path> srcDirEntries = CommonUtil.getEntries(srcDir);
    if (srcDirEntries.size() != 1 || !Files.isDirectory(srcDirEntries.iterator().next())) {
        throw new BatfishException("Unexpected packaging of testrig. There should be just one top-level folder");
    }
    Path srcSubdir = srcDirEntries.iterator().next();
    SortedSet<Path> subFileList = CommonUtil.getEntries(srcSubdir);
    Path containerDir = getdirContainer(containerName);
    Path testrigDir = containerDir.resolve(Paths.get(BfConsts.RELPATH_TESTRIGS_DIR, testrigName));
    if (!testrigDir.toFile().mkdirs()) {
        throw new BatfishException("Failed to create directory: '" + testrigDir + "'");
    }
    // Now that the directory exists, we must also create the metadata.
    try {
        TestrigMetadataMgr.writeMetadata(new TestrigMetadata(Instant.now(), BfConsts.RELPATH_DEFAULT_ENVIRONMENT_NAME), testrigDir.resolve(BfConsts.RELPATH_METADATA_FILE));
    } catch (Exception e) {
        BatfishException metadataError = new BatfishException("Could not write testrigMetadata", e);
        try {
            CommonUtil.deleteDirectory(testrigDir);
        } catch (Exception inner) {
            metadataError.addSuppressed(inner);
        }
        throw metadataError;
    }
    Path srcTestrigDir = testrigDir.resolve(BfConsts.RELPATH_TEST_RIG_DIR);
    // create empty default environment
    Path defaultEnvironmentLeafDir = testrigDir.resolve(Paths.get(BfConsts.RELPATH_ENVIRONMENTS_DIR, BfConsts.RELPATH_DEFAULT_ENVIRONMENT_NAME, BfConsts.RELPATH_ENV_DIR));
    defaultEnvironmentLeafDir.toFile().mkdirs();
    // things look ok, now make the move
    boolean routingTables = false;
    boolean bgpTables = false;
    for (Path subFile : subFileList) {
        Path target;
        if (isEnvFile(subFile)) {
            String name = subFile.getFileName().toString();
            if (name.equals(BfConsts.RELPATH_ENVIRONMENT_ROUTING_TABLES)) {
                routingTables = true;
            }
            if (name.equals(BfConsts.RELPATH_ENVIRONMENT_BGP_TABLES)) {
                bgpTables = true;
            }
            target = defaultEnvironmentLeafDir.resolve(subFile.getFileName());
        } else {
            target = srcTestrigDir.resolve(subFile.getFileName());
        }
        CommonUtil.copy(subFile, target);
    }
    _logger.infof("Environment data for testrig:%s; bgpTables:%s, routingTables:%s\n", testrigName, bgpTables, routingTables);
    if (autoAnalyze) {
        for (WorkItem workItem : getAutoWorkQueue(containerName, testrigName)) {
            boolean queued = queueWork(workItem);
            if (!queued) {
                _logger.errorf("Unable to queue work while auto processing: %s", workItem);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) BatfishException(org.batfish.common.BatfishException) TestrigMetadata(org.batfish.datamodel.TestrigMetadata) WorkItem(org.batfish.common.WorkItem) ProcessingException(javax.ws.rs.ProcessingException) BatfishException(org.batfish.common.BatfishException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

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