use of org.onosproject.workflow.api.WorkflowDataModelException in project onos by opennetworkinglab.
the class WorkflowManager method checkWorkflowDataModelSchema.
/**
* Checks the schema of workflow data.
*
* @param workflow workflow
* @param worklowDescJson jsonNode
* @throws WorkflowException workflow exception
*/
private void checkWorkflowDataModelSchema(Workflow workflow, JsonNode worklowDescJson) throws WorkflowException {
List<String> errors = new ArrayList<>();
JsonNode dataNode = worklowDescJson.get("data");
if (Objects.isNull(dataNode) || dataNode instanceof MissingNode) {
errors.add("workflow description json does not have 'data'");
throw new WorkflowDataModelException(workflow.id(), worklowDescJson, errors);
}
for (ProgramCounter pc : workflow.getProgram()) {
Worklet worklet = workflow.getWorkletInstance(pc);
if (Worklet.Common.COMPLETED.equals(worklet) || Worklet.Common.INIT.equals(worklet)) {
continue;
}
Class cls = worklet.getClass();
for (Field field : cls.getDeclaredFields()) {
if (field.isSynthetic()) {
continue;
}
for (Annotation annotation : field.getAnnotations()) {
if (!(annotation instanceof JsonDataModel)) {
continue;
}
JsonDataModel jsonDataModel = (JsonDataModel) annotation;
Matcher matcher = Pattern.compile("(\\w+)").matcher(jsonDataModel.path());
if (!matcher.find()) {
throw new WorkflowException("Invalid Json Data Model Path(" + jsonDataModel.path() + ") in " + worklet.tag());
}
String path = matcher.group(1);
Optional<String> optError = getJsonNodeDataError(dataNode, worklet, field, path, jsonDataModel.optional());
if (optError.isPresent()) {
errors.add(optError.get());
}
}
}
}
if (!errors.isEmpty()) {
throw new WorkflowDataModelException(workflow.id(), worklowDescJson, errors);
}
}
Aggregations