Search in sources :

Example 1 with TestrigMetadata

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);
}
Also used : Path(java.nio.file.Path) TestrigMetadata(org.batfish.datamodel.TestrigMetadata)

Example 2 with TestrigMetadata

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);
}
Also used : Path(java.nio.file.Path) TestrigMetadata(org.batfish.datamodel.TestrigMetadata) EnvironmentMetadata(org.batfish.datamodel.EnvironmentMetadata)

Example 3 with TestrigMetadata

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

Example 4 with TestrigMetadata

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());
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) TestrigMetadata(org.batfish.datamodel.TestrigMetadata) 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)

Example 5 with TestrigMetadata

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);
}
Also used : Path(java.nio.file.Path) TestrigMetadata(org.batfish.datamodel.TestrigMetadata) EnvironmentMetadata(org.batfish.datamodel.EnvironmentMetadata)

Aggregations

TestrigMetadata (org.batfish.datamodel.TestrigMetadata)5 Path (java.nio.file.Path)4 IOException (java.io.IOException)2 BatfishException (org.batfish.common.BatfishException)2 EnvironmentMetadata (org.batfish.datamodel.EnvironmentMetadata)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 FileNotFoundException (java.io.FileNotFoundException)1 AccessControlException (java.security.AccessControlException)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 FileExistsException (org.apache.commons.io.FileExistsException)1 WorkItem (org.batfish.common.WorkItem)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1