use of org.batfish.common.Container in project batfish by batfish.
the class BfCoordWorkHelper method getContainer.
/**
* Returns a {@link Container Container} that contains information of '{@code containerName}',
* returns null if container '{@code containerName}' does not exist or the api key that is using
* has no access to the container
*/
@Nullable
public Container getContainer(String containerName) {
try {
WebTarget webTarget = getTargetV2(Lists.newArrayList(CoordConsts.SVC_KEY_CONTAINERS, containerName));
Response response = webTarget.request(MediaType.APPLICATION_JSON).header(CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey()).header(CoordConsts.SVC_KEY_VERSION, Version.getVersion()).get();
_logger.debug(response.getStatus() + " " + response.getStatusInfo() + " " + response + "\n");
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
_logger.error("GetContainer: Did not get the expected response\n");
_logger.error(response.readEntity(String.class) + "\n");
return null;
}
String containerStr = response.readEntity(String.class);
Container container = BatfishObjectMapper.mapper().readValue(containerStr, Container.class);
return container;
} catch (Exception e) {
_logger.errorf("Exception in getContainer from %s for %s\n", _coordWorkMgrV2, containerName);
_logger.error(ExceptionUtils.getStackTrace(e) + "\n");
return null;
}
}
use of org.batfish.common.Container in project batfish by batfish.
the class WorkMgr method listContainers.
public SortedSet<String> listContainers(String apiKey) {
Path containersDir = Main.getSettings().getContainersLocation();
if (!Files.exists(containersDir)) {
containersDir.toFile().mkdirs();
}
SortedSet<String> authorizedContainers = new TreeSet<>(CommonUtil.getSubdirectories(containersDir).stream().map(dir -> dir.getFileName().toString()).filter(container -> Main.getAuthorizer().isAccessibleContainer(apiKey, container, false)).collect(Collectors.toSet()));
return authorizedContainers;
}
use of org.batfish.common.Container in project batfish by batfish.
the class WorkMgrServiceTest method getNonEmptyContainer.
@Test
public void getNonEmptyContainer() throws Exception {
initContainerEnvironment();
Path containerPath = _containersFolder.getRoot().toPath().resolve(_containerName);
Path testrigPath = containerPath.resolve(BfConsts.RELPATH_TESTRIGS_DIR).resolve("testrig");
assertThat(testrigPath.toFile().mkdirs(), is(true));
Response response = _service.getContainer("100", "0.0.0", _containerName);
Container container = BatfishObjectMapper.mapper().readValue(response.getEntity().toString(), Container.class);
Container expected = Container.of(_containerName, Sets.newTreeSet(Collections.singleton("testrig")));
assertThat(container, equalTo(expected));
}
use of org.batfish.common.Container in project batfish by batfish.
the class WorkMgrServiceV2Test method testGetContainer.
@Test
public void testGetContainer() {
String containerName = "someContainer";
Main.getWorkMgr().initContainer(containerName, null);
Response response = getContainersTarget().path(containerName).request().get();
assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
assertThat(response.readEntity(new GenericType<Container>() {
}).getName(), equalTo(containerName));
}
use of org.batfish.common.Container in project batfish by batfish.
the class WorkMgrServiceV2Test method getContainers.
@Test
public void getContainers() {
Response response = getContainersTarget().request().get();
assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
assertThat(response.readEntity(new GenericType<List<Container>>() {
}), empty());
Main.getWorkMgr().initContainer("someContainer", null);
response = getContainersTarget().request().get();
assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
assertThat(response.readEntity(new GenericType<List<Container>>() {
}), hasSize(1));
}
Aggregations