use of org.batfish.datamodel.TestrigMetadata in project batfish by batfish.
the class TestrigMetadataMgr method initializeEnvironment.
public static synchronized void initializeEnvironment(String container, String testrig, String envName) throws IOException {
Path metadataPath = WorkMgr.getpathTestrigMetadata(container, testrig);
TestrigMetadata metadata = readMetadata(metadataPath);
metadata.initializeEnvironment(envName);
writeMetadata(metadata, metadataPath);
}
use of org.batfish.datamodel.TestrigMetadata in project batfish by batfish.
the class WorkQueueMgrTest method initTestrigMetadata.
private void initTestrigMetadata(String container, String testrig, String environment, ProcessingStatus status) throws JsonProcessingException {
Path metadataPath = WorkMgr.getpathTestrigMetadata(container, testrig);
metadataPath.getParent().toFile().mkdirs();
TestrigMetadata trMetadata = new TestrigMetadata(Instant.now(), environment);
EnvironmentMetadata envMetadata = trMetadata.getEnvironments().get(environment);
envMetadata.updateStatus(status, null);
TestrigMetadataMgr.writeMetadata(trMetadata, metadataPath);
}
use of org.batfish.datamodel.TestrigMetadata 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);
}
}
}
}
use of org.batfish.datamodel.TestrigMetadata in project batfish by batfish.
the class WorkMgrService method listTestrigs.
/**
* List the testrigs under the specified container
*
* @param apiKey The API key of the client
* @param clientVersion The version of the client
* @param containerName The name of the container whose testrigs are to be listed
* @return TODO: document JSON response
*/
@POST
@Path(CoordConsts.SVC_RSC_LIST_TESTRIGS)
@Produces(MediaType.APPLICATION_JSON)
public JSONArray listTestrigs(@FormDataParam(CoordConsts.SVC_KEY_API_KEY) String apiKey, @FormDataParam(CoordConsts.SVC_KEY_VERSION) String clientVersion, @FormDataParam(CoordConsts.SVC_KEY_CONTAINER_NAME) String containerName) {
try {
_logger.infof("WMS:listTestrigs %s %s\n", apiKey, containerName);
checkStringParam(apiKey, "API key");
checkStringParam(clientVersion, "Client version");
checkStringParam(containerName, "Container name");
checkApiKeyValidity(apiKey);
checkClientVersion(clientVersion);
checkContainerAccessibility(apiKey, containerName);
JSONArray retArray = new JSONArray();
List<String> testrigList = Main.getWorkMgr().listTestrigs(containerName);
for (String testrig : testrigList) {
try {
String testrigInfo = Main.getWorkMgr().getTestrigInfo(containerName, testrig);
TestrigMetadata trMetadata = Main.getWorkMgr().getTestrigMetadata(containerName, testrig);
JSONObject jObject = new JSONObject().put(CoordConsts.SVC_KEY_TESTRIG_NAME, testrig).put(CoordConsts.SVC_KEY_TESTRIG_INFO, testrigInfo).put(CoordConsts.SVC_KEY_TESTRIG_METADATA, BatfishObjectMapper.writePrettyString(trMetadata));
retArray.put(jObject);
} catch (Exception e) {
_logger.warnf("Error listing testrig %s in container %s: %s", containerName, testrig, Throwables.getStackTraceAsString(e));
}
}
return successResponse(new JSONObject().put(CoordConsts.SVC_KEY_TESTRIG_LIST, retArray));
} catch (Exception e) {
_logger.errorf("WMS:listTestrigs exception: %s", ExceptionUtils.getStackTrace(e));
return failureResponse(e.getMessage());
}
}
use of org.batfish.datamodel.TestrigMetadata in project batfish by batfish.
the class TestrigMetadataMgr method updateEnvironmentStatus.
public static synchronized void updateEnvironmentStatus(String container, String testrig, String envName, ProcessingStatus status, String errMessage) throws IOException {
Path metadataPath = WorkMgr.getpathTestrigMetadata(container, testrig);
TestrigMetadata trMetadata = readMetadata(metadataPath);
EnvironmentMetadata environmentMetadata = trMetadata.getEnvironments().get(envName);
environmentMetadata.updateStatus(status, errMessage);
writeMetadata(trMetadata, metadataPath);
}
Aggregations