use of org.batfish.common.BatfishLogger in project batfish by batfish.
the class Batfish method deserializeObjects.
/**
* Deserialize a bunch of objects
*
* @param namesByPath Mapping of object paths to their names
* @param outputClass the class type for {@link S}
* @param <S> desired type of objects
* @return a map of objects keyed by their name (from {@code namesByPath})
*/
public <S extends Serializable> SortedMap<String, S> deserializeObjects(Map<Path, String> namesByPath, Class<S> outputClass) {
String outputClassName = outputClass.getName();
BatfishLogger logger = getLogger();
AtomicInteger readCompleted = newBatch("Reading, unpacking, and deserializing files containing '" + outputClassName + "' instances", namesByPath.size());
return namesByPath.entrySet().parallelStream().map(e -> {
logger.debugf("Reading and unzipping: %s '%s' from %s%n", outputClassName, e.getValue(), e.getKey());
S object = deserializeObject(e.getKey(), outputClass);
logger.debug(" ...OK\n");
readCompleted.incrementAndGet();
return new SimpleImmutableEntry<>(e.getValue(), object);
}).collect(ImmutableSortedMap.toImmutableSortedMap(String::compareTo, Entry::getKey, Entry::getValue));
}
use of org.batfish.common.BatfishLogger in project batfish by batfish.
the class Driver method main.
public static void main(String[] args) {
mainInit(args);
_mainLogger = new BatfishLogger(_mainSettings.getLogLevel(), _mainSettings.getTimestamp(), _mainSettings.getLogFile(), _mainSettings.getLogTee(), true);
mainRun();
}
use of org.batfish.common.BatfishLogger in project batfish by batfish.
the class Driver method runBatfishThroughService.
public static List<String> runBatfishThroughService(final String taskId, String[] args) {
final Settings settings;
try {
settings = new Settings(_mainSettings);
settings.setRunMode(RunMode.WORKER);
settings.parseCommandLine(args);
// assign taskId for status updates, termination requests
settings.setTaskId(taskId);
} catch (Exception e) {
return Arrays.asList("failure", "Initialization failed: " + ExceptionUtils.getStackTrace(e));
}
try {
Batfish.initTestrigSettings(settings);
} catch (Exception e) {
return Arrays.asList("failure", "Failed while applying auto basedir. (All arguments are supplied?): " + e.getMessage());
}
if (settings.canExecute()) {
if (claimIdle()) {
try {
final BatfishLogger jobLogger = new BatfishLogger(settings.getLogLevel(), settings.getTimestamp(), settings.getLogFile(), settings.getLogTee(), false);
settings.setLogger(jobLogger);
final Task task = new Task(args);
logTask(taskId, task);
@Nullable SpanContext runTaskSpanContext = GlobalTracer.get().activeSpan() == null ? null : GlobalTracer.get().activeSpan().context();
// run batfish on a new thread and set idle to true when done
Thread thread = new Thread() {
@Override
public void run() {
try (ActiveSpan runBatfishSpan = GlobalTracer.get().buildSpan("Initialize Batfish in a new thread").addReference(References.FOLLOWS_FROM, runTaskSpanContext).startActive()) {
// avoid unused warning
assert runBatfishSpan != null;
task.setStatus(TaskStatus.InProgress);
String errMsg = runBatfish(settings);
if (errMsg == null) {
task.setStatus(TaskStatus.TerminatedNormally);
} else {
task.setStatus(TaskStatus.TerminatedAbnormally);
task.setErrMessage(errMsg);
}
task.setTerminated(new Date());
jobLogger.close();
makeIdle();
}
}
};
thread.start();
return Arrays.asList(BfConsts.SVC_SUCCESS_KEY, "running now");
} catch (Exception e) {
_mainLogger.error("Exception while running task: " + e.getMessage());
makeIdle();
return Arrays.asList(BfConsts.SVC_FAILURE_KEY, e.getMessage());
}
} else {
return Arrays.asList(BfConsts.SVC_FAILURE_KEY, "Not idle");
}
} else {
return Arrays.asList(BfConsts.SVC_FAILURE_KEY, "Non-executable command");
}
}
use of org.batfish.common.BatfishLogger in project batfish by batfish.
the class WorkMgrServiceTest method initContainerEnvironment.
private void initContainerEnvironment() throws Exception {
Settings settings = new Settings(new String[] {});
BatfishLogger logger = new BatfishLogger("debug", false);
Main.mainInit(new String[] { "-containerslocation", _containersFolder.getRoot().toString(), "-templatedirs", _questionsTemplatesFolder.getRoot().toString() });
Main.setLogger(logger);
Main.initAuthorizer();
WorkMgr manager = new WorkMgr(settings, logger);
Main.setWorkMgr(manager);
manager.initContainer(_containerName, null);
_service = new WorkMgrService();
}
use of org.batfish.common.BatfishLogger in project batfish by batfish.
the class BdpDataPlanePluginTest method testStaticInterfaceRoutesWithoutEdge.
@Test
public void testStaticInterfaceRoutesWithoutEdge() {
NetworkFactory nf = new NetworkFactory();
Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
Vrf vrf = nf.vrfBuilder().setOwner(c).setName(DEFAULT_VRF_NAME).build();
Interface i = nf.interfaceBuilder().setOwner(c).setVrf(vrf).setAddress(new InterfaceAddress("10.0.0.0/24")).setActive(true).build();
StaticRoute srBoth = StaticRoute.builder().setNetwork(Prefix.parse("10.0.1.0/24")).setNextHopInterface(i.getName()).setNextHopIp(new Ip("10.0.0.1")).build();
vrf.getStaticRoutes().add(srBoth);
StaticRoute srJustInterface = StaticRoute.builder().setNetwork(Prefix.parse("10.0.2.0/24")).setNextHopInterface(i.getName()).build();
vrf.getStaticRoutes().add(srJustInterface);
BdpEngine engine = new BdpEngine(new MockBdpSettings(), new BatfishLogger(BatfishLogger.LEVELSTR_DEBUG, false), (a, b) -> new AtomicInteger());
Topology topology = new Topology(Collections.emptySortedSet());
BdpDataPlane dp = engine.computeDataPlane(false, ImmutableMap.of(c.getName(), c), topology, Collections.emptySet(), new BdpAnswerElement());
// generating fibs should not crash
dp.getFibs();
}
Aggregations