@Override public @Nullable Answerer createAnswerer(@Nonnull Question question) { AnswererCreator creator = _answererCreators.get(question.getName()); return creator != null ? creator.create(question, this) : null; } }
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; }
@Override public String loadQuestionClassId( NetworkId networkId, QuestionId questionId, AnalysisId analysisId) throws IOException { return Question.parseQuestion(loadQuestion(networkId, questionId, analysisId)).getName(); }
@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); } }
@Override protected final void pluginInitialize() { Question question = createQuestion(); String questionName = question.getName(); String questionClassName = question.getClass().getCanonicalName(); switch (_pluginConsumer.getType()) { case BATFISH: { IBatfish batfish = (IBatfish) _pluginConsumer; batfish.registerAnswerer(questionName, questionClassName, this::createAnswerer); break; } case CLIENT: { IClient client = (IClient) _pluginConsumer; client.registerQuestion(questionName, this::createQuestion); break; } default: break; } } }
} else { throw new BatfishException( "The question " + innerQuestion.getName() + " does not implement INodeRegexQuestion");
@Test public void testGetAnswerMetadataAnalysisMissingQuestion() throws JsonProcessingException, FileNotFoundException { String networkName = "network1"; String snapshotName = "snapshot1"; String analysisName = "analysis1"; Question question = new TestQuestion(); String questionName = "question1"; _manager.initNetwork(networkName, null); _manager.configureAnalysis( networkName, true, analysisName, ImmutableMap.of(), ImmutableList.of(), null); NetworkId networkId = _idManager.getNetworkId(networkName); SnapshotId snapshotId = _idManager.generateSnapshotId(); _idManager.assignSnapshot(snapshotName, networkId, snapshotId); QuestionSettingsId questionSettingsId = new QuestionSettingsId("blah"); _idManager.assignQuestionSettingsId(question.getName(), networkId, questionSettingsId); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage(containsString(questionName)); _manager.getAnswerMetadata(networkName, snapshotName, questionName, null, analysisName); }
@Test public void testGetAnswerMetadataAnalysisMissingAnalysis() throws JsonProcessingException, FileNotFoundException { String networkName = "network1"; String snapshotName = "snapshot1"; String analysisName = "analysis1"; Question question = new TestQuestion(); String questionName = "question1"; _manager.initNetwork(networkName, null); NetworkId networkId = _idManager.getNetworkId(networkName); SnapshotId snapshotId = _idManager.generateSnapshotId(); _idManager.assignSnapshot(snapshotName, networkId, snapshotId); // the analysis id is not assigned, so the analysis is effectively missing QuestionSettingsId questionSettingsId = new QuestionSettingsId("blah"); _idManager.assignQuestionSettingsId(question.getName(), networkId, questionSettingsId); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage(containsString(analysisName)); _manager.getAnswerMetadata(networkName, snapshotName, questionName, null, analysisName); }
QuestionId questionId = _idManager.getQuestionId(questionName, networkId, null); QuestionSettingsId questionSettingsId = new QuestionSettingsId("blah"); _idManager.assignQuestionSettingsId(question.getName(), networkId, questionSettingsId); AnswerId baseAnswerId = _idManager.getBaseAnswerId(