private static void validateInstanceData(InstanceData instanceData) { String description = instanceData.getDescription(); String q = "Question: '" + instanceData.getInstanceName() + "'"; if (description == null || description.length() == 0) { throw new BatfishException(q + " is missing question description"); } for (Entry<String, Variable> e : instanceData.getVariables().entrySet()) { String variableName = e.getKey(); Variable variable = e.getValue(); String v = "Variable: '" + variableName + "' in " + q; String variableDescription = variable.getDescription(); if (variableDescription == null || variableDescription.length() == 0) { throw new BatfishException(v + " is missing description"); } } }
@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)); } }
@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()); }
@Override public int hashCode() { return Objects.hash(getInstance().getInstanceName(), getInstance().getDescription()); } };
.setTag("testrig_name", getTestrigName().getId()); if (question.getInstance() != null) { activeSpan.setTag("question-name", question.getInstance().getInstanceName());