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));
}
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)));
}
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);
}
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));
}
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);
}
}
}
}
Aggregations