private void saveSolverInput(Expr expr) { // synchronize to avoid z3 concurrency bugs. // use NodJob to synchronize with any other similar writers. synchronized (NodJob.class) { Path nodPath = _settings .getActiveTestrigSettings() .getBasePath() .resolve( String.format( "solverInput-%s-%d.smt2", Instant.now(), Thread.currentThread().getId())); try (FileWriter writer = new FileWriter(nodPath.toFile())) { writer.write(expr.toString()); } catch (IOException e) { _logger.warnf("Error saving Nod program to file: %s", Throwables.getStackTraceAsString(e)); } } }
private void saveNodProgram(NodProgram program) { // synchronize to avoid z3 concurrency bugs. TODO: is this really needed? // other writers also use NodJob.class to synchronize writes. synchronized (NodJob.class) { Path nodPath = _settings .getActiveTestrigSettings() .getBasePath() .resolve( String.format( "nodProgram-%s-%d.smt2", Instant.now(), Thread.currentThread().getId())); try (FileWriter writer = new FileWriter(nodPath.toFile())) { writer.write(program.toSmt2String()); } catch (IOException e) { _logger.warnf("Error saving Nod program to file: %s", Throwables.getStackTraceAsString(e)); } } }
@Override public @Nullable SortedSet<Edge> loadEdgeBlacklist(NetworkId network, SnapshotId snapshot) { Path path = _d.getSnapshotDir(network, snapshot) .resolve(Paths.get(BfConsts.RELPATH_INPUT, BfConsts.RELPATH_EDGE_BLACKLIST_FILE)); if (!Files.exists(path)) { return null; } String fileText = CommonUtil.readFile(path); try { return BatfishObjectMapper.mapper() .readValue(fileText, new TypeReference<SortedSet<Edge>>() {}); } catch (IOException e) { _logger.warnf( "Unexpected exception caught while loading edge blacklist for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return null; } }
@Override public @Nullable SortedSet<String> loadNodeBlacklist(NetworkId network, SnapshotId snapshot) { Path path = _d.getSnapshotDir(network, snapshot) .resolve(Paths.get(BfConsts.RELPATH_INPUT, BfConsts.RELPATH_NODE_BLACKLIST_FILE)); if (!Files.exists(path)) { return null; } String fileText = CommonUtil.readFile(path); try { return BatfishObjectMapper.mapper() .readValue(fileText, new TypeReference<SortedSet<String>>() {}); } catch (IOException e) { _logger.warnf( "Unexpected exception caught while loading node blacklist for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return null; } }
@Override public @Nullable SortedSet<NodeInterfacePair> loadInterfaceBlacklist( NetworkId network, SnapshotId snapshot) { Path path = _d.getSnapshotDir(network, snapshot) .resolve(Paths.get(BfConsts.RELPATH_INPUT, BfConsts.RELPATH_INTERFACE_BLACKLIST_FILE)); if (!Files.exists(path)) { return null; } String fileText = CommonUtil.readFile(path); try { return BatfishObjectMapper.mapper() .readValue(fileText, new TypeReference<SortedSet<NodeInterfacePair>>() {}); } catch (IOException e) { _logger.warnf( "Unexpected exception caught while loading interface blacklist for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return null; } }
@Override public @Nullable Layer1Topology loadLayer1Topology(NetworkId network, SnapshotId snapshot) { Path path = _d.getSnapshotDir(network, snapshot) .resolve(Paths.get(BfConsts.RELPATH_INPUT, BfConsts.RELPATH_L1_TOPOLOGY_PATH)); if (!Files.exists(path)) { // (deprecated) path = _d.getSnapshotDir(network, snapshot) .resolve(Paths.get(BfConsts.RELPATH_INPUT, "testrig_layer1_topology")); } if (!Files.exists(path)) { return null; } AtomicInteger counter = _newBatch.apply("Reading layer-1 topology", 1); String topologyFileText = CommonUtil.readFile(path); try { return BatfishObjectMapper.mapper().readValue(topologyFileText, Layer1Topology.class); } catch (IOException e) { _logger.warnf( "Unexpected exception caught while loading layer-1 topology for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return null; } finally { counter.incrementAndGet(); } }
private boolean cachedConfigsAreCompatible(NetworkId network, SnapshotId snapshot) { try { ConvertConfigurationAnswerElement ccae = loadConvertConfigurationAnswerElement(network, snapshot); return ccae != null && Version.isCompatibleVersion( FileBasedStorage.class.getCanonicalName(), "Old processed configurations", ccae.getVersion()); } catch (BatfishException e) { _logger.warnf( "Unexpected exception caught while deserializing configs for snapshot %s: %s", snapshot, Throwables.getStackTraceAsString(e)); return false; } }
@VisibleForTesting static String readQuestionTemplate(Path file, Map<String, String> templates) throws JSONException, IOException { String questionText = CommonUtil.readFile(file); JSONObject questionObj = new JSONObject(questionText); if (questionObj.has(BfConsts.PROP_INSTANCE) && !questionObj.isNull(BfConsts.PROP_INSTANCE)) { JSONObject instanceDataObj = questionObj.getJSONObject(BfConsts.PROP_INSTANCE); String instanceDataStr = instanceDataObj.toString(); InstanceData instanceData = BatfishObjectMapper.mapper().readValue(instanceDataStr, InstanceData.class); String name = instanceData.getInstanceName(); String key = name.toLowerCase(); if (templates.containsKey(key) && _logger != null) { _logger.warnf( "Found duplicate template having instance name %s, only the last one in the list of templatedirs will be loaded\n", name); } templates.put(key, questionText); return name; } else { throw new BatfishException(String.format("Question in file:%s has no instance name", file)); } }
_logger.warnf( "WARNING: Unsupported switch port mode %s, assuming no VLANs allowed: \"%s:%s\"\n", iface.getSwitchportMode(), hostname, iface.getName()); Interface iface = vlanInterfaces.get(vlanNumber); if ((iface != null) && iface.getAutoState()) { _logger.warnf( "WARNING: Disabling unusable vlan interface because no switch port is assigned " + "to it: \"%s:%d\"\n",
private void updateSnapshotNodeRoles() { // Compute new auto role data and updates existing auto data with it NetworkId networkId = _settings.getContainer(); SnapshotId snapshotId = _settings.getTestrig(); NodeRolesId snapshotNodeRolesId = _idResolver.getSnapshotNodeRolesId(networkId, snapshotId); Set<String> nodeNames = loadConfigurations().keySet(); Topology rawLayer3Topology = _topologyProvider.getRawLayer3Topology(getNetworkSnapshot()); SortedSet<NodeRoleDimension> autoRoles = new InferRoles(nodeNames, rawLayer3Topology).inferRoles(); NodeRolesData.Builder snapshotNodeRoles = NodeRolesData.builder(); try { if (!autoRoles.isEmpty()) { snapshotNodeRoles.setDefaultDimension(autoRoles.first().getName()); snapshotNodeRoles.setRoleDimensions(autoRoles); } _storage.storeNodeRoles(snapshotNodeRoles.build(), snapshotNodeRolesId); } catch (IOException e) { _logger.warnf("Could not update node roles: %s", e); } }
answerStringToPrint = answer.prettyPrint(); } catch (IOException e) { _logger.warnf( "Using Json for pretty printing because could not deserialize response as %s: %s", Answer.class.getSimpleName(), e.getMessage());
_logger.warnf( "Error listing snapshot %s in network %s: %s", networkName, snapshot, Throwables.getStackTraceAsString(e));