Skip to content

Commit

Permalink
Merge pull request #134 from batfish/unstable
Browse files Browse the repository at this point in the history
Unstable
  • Loading branch information
arifogel committed May 24, 2017
2 parents 478c5bd + 0b9e597 commit 3d094f6
Show file tree
Hide file tree
Showing 104 changed files with 6,029 additions and 2,135 deletions.
3 changes: 1 addition & 2 deletions projects/allinone/allinone
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
ALLINONE="${BASH_SOURCE[0]}"
ALLINONE_PATH=$(dirname "$ALLINONE")
ALLINONE_JAR="$ALLINONE_PATH/out/allinone.jar"
ALLINONE_JAVA_ARGS=
if batfish_cygwin; then
ALLINONE_JAR="$(cygpath -w $ALLINONE_JAR)"
ALLINONE_JAVA_ARGS="-Djline.terminal=jline.UnixTerminal"
ALLINONE_JAVA_ARGS="$ALLINONE_JAVA_ARGS -Djline.terminal=jline.UnixTerminal"
stty -icanon min 1 -echo
fi
if [ -n "${BATFISH_PLUGIN_DIRS}" ]; then
Expand Down
3 changes: 2 additions & 1 deletion projects/allinone/src/org/batfish/allinone/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class Settings extends BaseSettings {

public Settings(String[] args) throws Exception {
super(CommonUtil.getConfigProperties(ConfigurationLocator.class,
BfConsts.RELPATH_CONFIG_FILE_NAME_ALLINONE));
BfConsts.RELPATH_CONFIG_FILE_NAME_ALLINONE,
BfConsts.PROP_ALLINONE_PROPERTIES_PATH));

initConfigDefaults();

Expand Down
3 changes: 1 addition & 2 deletions projects/batfish-client/batfish-client
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
BATFISH_CLIENT=${BASH_SOURCE[0]}
BATFISH_CLIENT_PATH=$(dirname $BATFISH_CLIENT)
BATFISH_CLIENT_JAR=$BATFISH_CLIENT_PATH/out/batfish-client.jar
BATFISH_CLIENT_JAVA_ARGS=
if batfish_cygwin; then
BATFISH_CLIENT_JAR="$(cygpath -w $BATFISH_CLIENT_JAR)"
BATFISH_CLIENT_JAVA_ARGS="-Djline.terminal=jline.UnixTerminal"
BATFISH_CLIENT_JAVA_ARGS="$BATFISH_CLIENT_JAVA_ARGS -Djline.terminal=jline.UnixTerminal"
stty -icanon min 1 -echo
fi
if [ -n "${BATFISH_PLUGIN_DIRS}" ]; then
Expand Down
154 changes: 83 additions & 71 deletions projects/batfish-client/src/org/batfish/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -472,13 +471,14 @@ private Path createTempFile(String filePrefix, String content) {
return tempFilePath;
}

private boolean delAnalysis(FileWriter outWriter, List<String> options,
private boolean delAnalysis(FileWriter outWriter, List<String> options,
List<String> parameters) {
if (!isSetContainer(true)) {
return false;
}
if (options.size() != 0 || parameters.size() != 1) {
_logger.errorf("Invalid arguments: %s %s\n", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s\n", options.toString(),
parameters.toString());
printUsage(Command.DEL_ANALYSIS);
return false;
}
Expand All @@ -488,18 +488,19 @@ private boolean delAnalysis(FileWriter outWriter, List<String> options,
boolean result = _workHelper.delAnalysis(_currContainerName,
analysisName);

logOutput(outWriter, "Result of deleting analysis "
+ analysisName + ": " + result + "\n");
logOutput(outWriter, "Result of deleting analysis " + analysisName + ": "
+ result + "\n");
return result;
}

private boolean delAnalysisQuestions(FileWriter outWriter, List<String> options,
List<String> parameters) {
private boolean delAnalysisQuestions(FileWriter outWriter,
List<String> options, List<String> parameters) {
if (!isSetContainer(true)) {
return false;
}
if (options.size() != 0 || parameters.size() < 2) {
_logger.errorf("Invalid arguments: %s %s\n", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s\n", options.toString(),
parameters.toString());
printUsage(Command.DEL_ANALYSIS_QUESTIONS);
return false;
}
Expand All @@ -522,7 +523,8 @@ private boolean delAnalysisQuestions(FileWriter outWriter, List<String> options,
boolean result = _workHelper.configureAnalysis(_currContainerName, false,
analysisName, null, delQuestionsStr);

logOutput(outWriter, "Result of deleting analysis questions: " + result + "\n");
logOutput(outWriter,
"Result of deleting analysis questions: " + result + "\n");
return result;
}

Expand Down Expand Up @@ -872,13 +874,14 @@ private boolean get(String[] words, FileWriter outWriter,
}

private boolean getAnalysisAnswers(FileWriter outWriter,
List<String> options, List<String> parameters,
boolean delta, boolean differential) {
List<String> options, List<String> parameters, boolean delta,
boolean differential) {
if (!isSetTestrig() || !isSetContainer(true)) {
return false;
}
if (options.size() != 0 || parameters.size() != 1) {
_logger.errorf("Invalid arguments: %s %s\n", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s\n", options.toString(),
parameters.toString());
printUsage(Command.GET_ANALYSIS_ANSWERS);
return false;
}
Expand Down Expand Up @@ -914,7 +917,7 @@ else if (delta) {
if (answer == null) {
return false;
}

logOutput(outWriter, answer + "\n");

return true;
Expand Down Expand Up @@ -1138,13 +1141,14 @@ private void initHelpers() {
}
}

private boolean initOrAddAnalysis(FileWriter outWriter, List<String> options,
private boolean initOrAddAnalysis(FileWriter outWriter, List<String> options,
List<String> parameters, boolean newAnalysis) {
if (!isSetContainer(true)) {
return false;
}
if (options.size() != 0 || parameters.size() != 2) {
_logger.errorf("Invalid arguments: %s %s", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s", options.toString(),
parameters.toString());
printUsage(Command.INIT_ANALYSIS);
return false;
}
Expand Down Expand Up @@ -1176,13 +1180,13 @@ private boolean initOrAddAnalysis(FileWriter outWriter, List<String> options,
boolean result = _workHelper.configureAnalysis(_currContainerName,
newAnalysis, analysisName, analysisFile.toAbsolutePath().toString(),
null);

if (analysisFile != null) {
CommonUtil.delete(analysisFile);
}

logOutput(outWriter, "Output of configuring analysis "
+ analysisName + ": " + result + "\n");
logOutput(outWriter, "Output of configuring analysis " + analysisName
+ ": " + result + "\n");
return result;
}

Expand Down Expand Up @@ -1281,53 +1285,55 @@ private boolean isSetTestrig() {
return true;
}

private boolean listAnalyses(FileWriter outWriter, List<String> options,
private boolean listAnalyses(FileWriter outWriter, List<String> options,
List<String> parameters) {
if (!isSetContainer(true)) {
return false;
}
if (options.size() != 0 || parameters.size() != 0) {
_logger.errorf("Invalid arguments: %s %s\n", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s\n", options.toString(),
parameters.toString());
printUsage(Command.LIST_TESTRIGS);
return false;
}

JSONObject analysisList = _workHelper.listAnalyses(_currContainerName);
logOutput(outWriter, String.format("Found %d analyses\n", analysisList.length()));

logOutput(outWriter,
String.format("Found %d analyses\n", analysisList.length()));

try {
logOutput(outWriter, analysisList.toString(1));
}
catch (JSONException e) {
throw new BatfishException("Failed to print analysis list", e);
}
// if (analysisList != null) {
// Iterator<?> aIterator = analysisList.keys();
// while (aIterator.hasNext()) {
// String aName = (String) aIterator.next();
// _logger.outputf("Analysis: %s\n", aName);
//
// try {
// JSONObject questionList = analysisList.getJSONObject(aName);
// _logger.outputf("Found %d questions\n", questionList.length());
//
// Iterator<?> qIterator = questionList.keys();
// while (qIterator.hasNext()) {
// String qName = (String) qIterator.next();
// _logger.outputf(" Question: %s\n", qName);
//
// JSONObject questionJson = questionList.getJSONObject(qName);
// _logger.outputf("%s\n", questionJson.toString(1));
// }
//
// }
// catch (JSONException e) {
// throw new BatfishException("Failed to process analysis list", e);
// }
// }
// }

// if (analysisList != null) {
// Iterator<?> aIterator = analysisList.keys();
// while (aIterator.hasNext()) {
// String aName = (String) aIterator.next();
// _logger.outputf("Analysis: %s\n", aName);
//
// try {
// JSONObject questionList = analysisList.getJSONObject(aName);
// _logger.outputf("Found %d questions\n", questionList.length());
//
// Iterator<?> qIterator = questionList.keys();
// while (qIterator.hasNext()) {
// String qName = (String) qIterator.next();
// _logger.outputf(" Question: %s\n", qName);
//
// JSONObject questionJson = questionList.getJSONObject(qName);
// _logger.outputf("%s\n", questionJson.toString(1));
// }
//
// }
// catch (JSONException e) {
// throw new BatfishException("Failed to process analysis list", e);
// }
// }
// }

return true;
}

Expand Down Expand Up @@ -1359,10 +1365,11 @@ private boolean listQuestions() {
return true;
}

private boolean listTestrigs(FileWriter outWriter, List<String> options,
private boolean listTestrigs(FileWriter outWriter, List<String> options,
List<String> parameters) {
if (options.size() != 0 || parameters.size() != 0) {
_logger.errorf("Invalid arguments: %s %s\n", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s\n", options.toString(),
parameters.toString());
printUsage(Command.LIST_TESTRIGS);
return false;
}
Expand All @@ -1371,9 +1378,8 @@ private boolean listTestrigs(FileWriter outWriter, List<String> options,
.listTestrigs(_currContainerName);
if (testrigs != null) {
for (String testrigName : testrigs.keySet()) {
logOutput(outWriter,
String.format("Testrig: %s\n%s\n", testrigName,
testrigs.get(testrigName)));
logOutput(outWriter, String.format("Testrig: %s\n%s\n", testrigName,
testrigs.get(testrigName)));
}
}
return true;
Expand Down Expand Up @@ -1469,7 +1475,7 @@ public FileVisitResult visitFile(Path file,
if (outWriter == null && _settings.getPrettyPrintAnswers()) {
answerStringToPrint = answer.prettyPrint();
}

logOutput(outWriter, answerStringToPrint);
return true;
}
Expand All @@ -1483,8 +1489,7 @@ private void logOutput(FileWriter outWriter, String message) {
outWriter.write(message);
}
catch (IOException e) {
throw new BatfishException(
"Failed to log output to outWriter", e);
throw new BatfishException("Failed to log output to outWriter", e);
}
}
}
Expand Down Expand Up @@ -1639,11 +1644,14 @@ private boolean processCommand(String[] words, FileWriter outWriter) {
case GET_DELTA:
return get(words, outWriter, options, parameters, true);
case GET_ANALYSIS_ANSWERS:
return getAnalysisAnswers(outWriter, options, parameters, false, false);
return getAnalysisAnswers(outWriter, options, parameters, false,
false);
case GET_ANALYSIS_ANSWERS_DELTA:
return getAnalysisAnswers(outWriter, options, parameters, true, false);
return getAnalysisAnswers(outWriter, options, parameters, true,
false);
case GET_ANALYSIS_ANSWERS_DIFFERENTIAL:
return getAnalysisAnswers(outWriter, options, parameters, false, true);
return getAnalysisAnswers(outWriter, options, parameters, false,
true);
case GET_ANSWER:
return getAnswer(outWriter, parameters, false, false);
case GET_ANSWER_DELTA:
Expand Down Expand Up @@ -1871,13 +1879,14 @@ public void run(List<String> initialCommands) {

}

private boolean runAnalysis(FileWriter outWriter, List<String> options,
private boolean runAnalysis(FileWriter outWriter, List<String> options,
List<String> parameters, boolean delta, boolean differential) {
if (!isSetContainer(true) || !isSetTestrig()) {
return false;
}
if (options.size() != 0 || parameters.size() != 1) {
_logger.errorf("Invalid arguments: %s %s", options.toString(), parameters.toString());
_logger.errorf("Invalid arguments: %s %s", options.toString(),
parameters.toString());
printUsage(Command.RUN_ANALYSIS);
return false;
}
Expand Down Expand Up @@ -2114,22 +2123,23 @@ private boolean test(List<String> parameters) throws IOException {
.readFile(Paths.get(testoutFile.getAbsolutePath()));

String testAnswerString = testOutput;

try {
Answer testAnswer = mapper.readValue(testOutput, Answer.class);
testAnswerString = mapper.writeValueAsString(testAnswer);
}
catch (JsonParseException | UnrecognizedPropertyException e) {
//not all outputs of process command are of Answer.class type
//in that case, we use the exact string as initialized above for comparison
// not all outputs of process command are of Answer.class type
// in that case, we use the exact string as initialized above for
// comparison
}

if (!missingReferenceFile) {
String referenceOutput = CommonUtil
.readFile(Paths.get(referenceFileName));

String referenceAnswerString = referenceOutput;

// rewrite reference string using local implementation
Answer referenceAnswer;
try {
Expand All @@ -2139,11 +2149,13 @@ private boolean test(List<String> parameters) throws IOException {
.writeValueAsString(referenceAnswer);
}
catch (JsonParseException | UnrecognizedPropertyException e) {
//throw new BatfishException(
// "Error reading reference output using current schema (reference output is likely obsolete)",
// e);
//not all outputs of process command are of Answer.class type
//in that case, we use the exact string as initialized above for comparison
// throw new BatfishException(
// "Error reading reference output using current schema
// (reference output is likely obsolete)",
// e);
// not all outputs of process command are of Answer.class type
// in that case, we use the exact string as initialized above
// for comparison
}

// due to options chosen in BatfishObjectMapper, if json
Expand Down
3 changes: 2 additions & 1 deletion projects/batfish-client/src/org/batfish/client/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public enum RunMode {

public Settings(String[] args) throws Exception {
super(CommonUtil.getConfigProperties(ConfigurationLocator.class,
BfConsts.RELPATH_CONFIG_FILE_NAME_CLIENT));
BfConsts.RELPATH_CONFIG_FILE_NAME_CLIENT,
BfConsts.PROP_CLIENT_PROPERTIES_PATH));

initConfigDefaults();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public enum TaskStatus {

public static final String KEY_BGP_ANNOUNCEMENTS = "Announcements";

public static final String PROP_ALLINONE_PROPERTIES_PATH = "batfishAllinonePropertiesPath";
public static final String PROP_BATFISH_PROPERTIES_PATH = "batfishBatfishPropertiesPath";
public static final String PROP_CLIENT_PROPERTIES_PATH = "batfishClientPropertiesPath";
public static final String PROP_COORDINATOR_PROPERTIES_PATH = "batfishCoordinatorPropertiesPath";
public static final String PROP_QUESTION_PLUGIN_DIR = "batfishQuestionPluginDir";

public static final String RELPATH_ANALYSES_DIR = "analyses";
Expand Down Expand Up @@ -127,4 +131,5 @@ public enum TaskStatus {
public static final String SVC_SUCCESS_KEY = "success";
public static final String SVC_TASK_KEY = "task";
public static final String SVC_TASKID_KEY = "taskid";

}

0 comments on commit 3d094f6

Please sign in to comment.