use of org.onosproject.workflow.api.WorkflowException 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);
}
}
use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.
the class OfOverlayWorkflowRegister method registerWorkflows.
/**
* Registers workflows.
*/
private void registerWorkflows() {
try {
// registering class-loader
workflowStore.registerLocal(this.getClass().getClassLoader());
// registering new workflow definition
URI uri = URI.create("of-overlay.workflow-nova");
Workflow workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-int").build()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()).build();
workflowStore.register(workflow);
// registering new workflow definition based on multi-event handling
uri = URI.create("of-overlay.workflow-nova-multiEvent-test");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(Ovs.CreateOverlayBridgeMultiEvent.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.clean-workflow-nova");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.DeleteOverlayBridgeConfig.class.getName()).chain(Ovs.RemoveOverlayBridgeOfDevice.class.getName()).chain(Ovs.DeleteUnderlayBridgeConfig.class.getName()).chain(Ovs.RemoveUnderlayBridgeOfDevice.class.getName()).chain(Ovs.RemoveOvsdbDevice.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.clean-workflow-nova-waitAll-Bridge-Del");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.DeleteOverlayBridgeConfig.class.getName()).chain(Ovs.DeleteUnderlayBridgeConfig.class.getName()).chain(Ovs.RemoveBridgeOfDevice.class.getName()).chain(Ovs.RemoveOvsdbDevice.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.workflow-ovs-leaf");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).build();
workflowStore.register(workflow);
uri = URI.create("of-overlay.workflow-ovs-spine");
workflow = ImmutableListWorkflow.builder().id(uri).chain(Ovs.CreateOvsdbDevice.class.getName()).chain(Ovs.UpdateOvsVersion.class.getName()).chain(Ovs.UpdateBridgeId.class.getName()).chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName()).staticDataModel(BRIDGE_NAME, "br-phy").build()).chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName()).build();
workflowStore.register(workflow);
deviceService.addListener(event -> {
// trigger EventTask for DeviceEvent
eventMapTriggerExecutor.submit(() -> workflowExecutionService.eventMapTrigger(event, // event hint supplier
(ev) -> {
if (ev == null || ev.subject() == null) {
return null;
}
String hint = event.subject().id().toString();
log.debug("hint: {}", hint);
return hint;
}));
});
} catch (WorkflowException e) {
e.printStackTrace();
}
}
use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.
the class WorkflowManager method getJsonNodeDataError.
private Optional<String> getJsonNodeDataError(JsonNode dataNode, Worklet worklet, Field field, String path, boolean isOptional) throws WorkflowException {
// Checking the existence of path in dataNode
JsonNode pathNode = dataNode.get(path);
if (Objects.isNull(pathNode) || pathNode instanceof MissingNode) {
if (isOptional) {
return Optional.empty();
} else {
return Optional.of("data doesn't have '" + path + "' in worklet<" + worklet.tag() + ">");
}
}
// Checking the type of path
JsonNodeType type = pathNode.getNodeType();
if (Objects.isNull(type)) {
throw new WorkflowException("Invalid type for " + pathNode);
}
switch(type) {
case NUMBER:
if (!(field.getType().isAssignableFrom(Integer.class))) {
return Optional.of("'" + path + "<NUMBER>' cannot be assigned to " + field.getName() + "<" + field.getType() + "> in worklet<" + worklet.tag() + ">");
}
break;
case STRING:
if (!(field.getType().isAssignableFrom(String.class))) {
return Optional.of("'" + path + "<STRING>' cannot be assigned to " + field.getName() + "<" + field.getType() + "> in worklet<" + worklet.tag() + ">");
}
break;
case BOOLEAN:
if (!(field.getType().isAssignableFrom(Boolean.class))) {
return Optional.of("'" + path + "<BOOLEAN>' cannot be assigned to " + field.getName() + "<" + field.getType() + "> in worklet<" + worklet.tag() + ">");
}
break;
case OBJECT:
if (!(field.getType().isAssignableFrom(JsonNode.class))) {
return Optional.of("'" + path + "<OBJECT>' cannot be assigned to " + field.getName() + "<" + field.getType() + "> in worklet<" + worklet.tag() + ">");
}
break;
case ARRAY:
if (!(field.getType().isAssignableFrom(ArrayNode.class))) {
return Optional.of("'" + path + "<ARRAY>' cannot be assigned to " + field.getName() + "<" + field.getType() + "> in worklet<" + worklet.tag() + ">");
}
break;
default:
return Optional.of("'" + path + "<" + type + ">' is not supported");
}
return Optional.empty();
}
use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.
the class NetconfAccessInfo method valueOf.
/**
* Builds NetconfAccessInfo from json.
* @param root json root node for NetconfAccessinfo
* @return NETCONF access information
* @throws WorkflowException workflow exception
*/
public static NetconfAccessInfo valueOf(JsonNode root) throws WorkflowException {
JsonNode node = root.at(ptr(REMOTE_IP));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid remoteIp for " + root);
}
IpAddress remoteIp = IpAddress.valueOf(node.asText());
node = root.at(ptr(PORT));
if (node == null || !(node instanceof NumericNode)) {
throw new WorkflowException("invalid port for " + root);
}
TpPort tpPort = TpPort.tpPort(node.asInt());
node = root.at(ptr(USER));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid user for " + root);
}
String strUser = node.asText();
node = root.at(ptr(PASSWORD));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid password for " + root);
}
String strPassword = node.asText();
return new NetconfAccessInfo(remoteIp, tpPort, strUser, strPassword);
}
use of org.onosproject.workflow.api.WorkflowException in project onos by opennetworkinglab.
the class WorkFlowTestCommand method defineInvalidWorkflow.
private void defineInvalidWorkflow() {
WorkflowService service = get(WorkflowService.class);
try {
URI uri = URI.create("sample.workflow-invalid-datamodel-type");
Workflow workflow = ImmutableListWorkflow.builder().id(uri).chain(SampleWorkflow.SampleWorklet5.class.getName()).chain(SampleWorkflow.SampleWorklet6.class.getName()).build();
service.register(workflow);
} catch (WorkflowException e) {
error(e.getMessage() + ", trace: " + Arrays.asList(e.getStackTrace()));
}
}
Aggregations