@Override public String loadQuestionClassId( NetworkId networkId, QuestionId questionId, AnalysisId analysisId) throws IOException { return Question.parseQuestion(loadQuestion(networkId, questionId, analysisId)).getName(); }
@Override public boolean getDataPlane() { return _innerQuestion.getDataPlane(); }
public String prettyPrint() { StringBuilder string = new StringBuilder(); if (_status != null) { string.append("Status: " + _status + "\n"); } if (_question != null) { string.append("Question: " + _question.prettyPrint() + "\n"); } for (AnswerElement ae : _answerElements) { string.append(ae.prettyPrint() + "\n"); } if (_summary != null) { string.append("Summary: " + _summary.prettyPrint() + "\n"); } return string.toString(); }
question = Question.parseQuestion(rawQuestionStr); } catch (Exception e) { Answer answer = new Answer(); .setTag("container-name", getContainerName().getId()) .setTag("testrig_name", getTestrigName().getId()); if (question.getInstance() != null) { activeSpan.setTag("question-name", question.getInstance().getInstanceName()); question.setDifferential(true); boolean dp = question.getDataPlane(); boolean diff = question.getDifferential(); boolean diffActive = _settings.getDiffActive() && !diff; _settings.setDiffActive(diffActive); try (ActiveSpan getAnswerSpan = GlobalTracer.get().buildSpan("Get answer").startActive()) { assert getAnswerSpan != null; // avoid not used warning if (question.getDifferential()) { answerElement = Answerer.create(question, this).answerDiff(); } else {
@Override public @Nullable Answerer createAnswerer(@Nonnull Question question) { AnswererCreator creator = _answererCreators.get(question.getName()); return creator != null ? creator.create(question, this) : null; } }
@VisibleForTesting void uploadQuestion(String network, String question, String questionJson, boolean validate) { if (validate) { // Validate the question before saving it to disk. try { Question.parseQuestion(questionJson); } catch (Exception e) { throw new BatfishException( String.format("Invalid question %s/%s: %s", network, question, e.getMessage()), e); } } NetworkId networkId; try { networkId = _idManager.getNetworkId(network); } catch (IllegalArgumentException e) { throw new InternalServerErrorException( String.format("Error uploading question: network=%s, question=%s", network, question), e); } QuestionId questionId = _idManager.generateQuestionId(); _storage.storeQuestion(questionJson, networkId, questionId, null); _idManager.assignQuestion(question, networkId, questionId, null); }
Question.parseQuestion( getQuestion( workItem.getContainerName(), WorkItemBuilder.getAnalysisName(workItem))); workType = question.getIndependent() ? WorkType.INDEPENDENT_ANSWERING : question.getDataPlane() ? WorkType.DATAPLANE_DEPENDENT_ANSWERING : WorkType.PARSING_DEPENDENT_ANSWERING; for (String qName : qNames) { Question question = Question.parseQuestion(getQuestion(workItem.getContainerName(), qName, aName)); if (question.getDataPlane()) { workType = WorkType.DATAPLANE_DEPENDENT_ANSWERING; break; if (!question.getIndependent()) { workType = WorkType.PARSING_DEPENDENT_ANSWERING;
checkClientVersion(clientVersion); Question inputQuestion = Question.parseQuestion(questionTemplate); Question outputQuestion = inputQuestion.configureTemplate(exceptions, assertion); String outputQuestionStr = BatfishObjectMapper.writePrettyString(outputQuestion);
"Modified question is no longer valid, likely due to invalid parameters", e); if (modifiedQuestion.getDifferential() && _currDeltaTestrig == null) { _logger.output(DIFF_NOT_READY_MSG); return false; questionFile.toFile().deleteOnExit(); boolean result = answerFile(questionFile, modifiedQuestion.getDifferential(), isDelta, outWriter); if (questionFile != null) { CommonUtil.deleteIfExists(questionFile);
getTaskId(), currentAnswer.getSummary().getNumFailed() > 0 ? "failed" : "passed", currentAnswer.getQuestion().getDataPlane(), BatfishObjectMapper.writeString( currentAnswer.getQuestion().getInstance().getVariables())); } catch (JsonProcessingException e) { throw new BatfishException(
/** * Creates a {@link TableMetadata} object from the question. * * @param question The question * @return The resulting {@link TableMetadata} object */ public static TableMetadata createMetadata(Question question) { List<ColumnMetadata> columnMetadata = COLUMN_METADATA.values().stream().collect(ImmutableList.toImmutableList()); String textDesc = String.format( "Filters {%s} contain an unreachable line: ${%s}", COL_SOURCES, COL_UNREACHABLE_LINE); DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(columnMetadata, textDesc); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Question other = (Question) obj; return Objects.equals( getInstance().getInstanceName(), other.getInstance().getInstanceName()) && Objects.equals( getInstance().getDescription(), other.getInstance().getDescription()); }
public static Answerer create(Question question, IBatfish batfish) { String questionName = question.getName(); Answerer answerer = batfish.createAnswerer(question); if (answerer == null) { throw new BatfishException( "Cannot create answerer for missing question with name: " + questionName); } return answerer; }
return Question.parseQuestion(fillTemplate(questionJson, parsedParameters, "qname").toString());
Answerer innerAnswerer = _batfish.createAnswerer(innerQuestion); AnswerElement innerAnswer = (innerQuestion.getDifferential()) ? innerAnswerer.answerDiff() : innerAnswerer.answer();
public static TableMetadata createMetadata(Question question) { String textDesc = DEFAULT_TEXT_DESC; DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(COLUMN_METADATA, textDesc); } }
@Override public @Nullable String loadQuestionSettings(@Nonnull Question question) { String questionClassId = question.getName(); NetworkId networkId = _settings.getContainer(); if (!_idResolver.hasQuestionSettingsId(questionClassId, networkId)) { return null; } try { QuestionSettingsId questionSettingsId = _idResolver.getQuestionSettingsId(questionClassId, networkId); return _storage.loadQuestionSettings(_settings.getContainer(), questionSettingsId); } catch (IOException e) { throw new BatfishException( String.format("Failed to read question settings for question: '%s'", questionClassId), e); } }
Question questionObj = Question.parseQuestion(questionStr);
@Override public boolean getDataPlane() { for (Question question : _questions) { if (question.getDataPlane()) { return true; } } return false; }
/** * This procedure proceeds as follows: * * <ul> * <li>First, compute the inner answer * <li>Then, run {@link #computeAnswerTable(String, JsonPathToTableQuestion)}, which produces a * set of result minus exclusions * </ul> */ @Override public TableAnswerElement answer() { JsonPathToTableQuestion question = (JsonPathToTableQuestion) _question; Question innerQuestion = question.getInnerQuestion(); Answerer innerAnswerer = _batfish.createAnswerer(innerQuestion); AnswerElement innerAnswer = (innerQuestion.getDifferential()) ? innerAnswerer.answerDiff() : innerAnswerer.answer(); String innerAnswerStr = null; try { innerAnswerStr = BatfishObjectMapper.writeStringWithNulls(innerAnswer); } catch (IOException e) { throw new BatfishException("Could not get JSON string from inner answer", e); } TableAnswerElement answer = computeAnswerTable(innerAnswerStr, question); return answer; }