Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

Let's begin by writing a very simple graph to get acquainted with directed graph. To follow this tutorial you need to already have you Ubuntu VM setup with SLI. The tutorial to do this is at Install Oracle VM and Ubuntu. (fill in link)

...

You should be familiar with calling REST APIs with a JSON payload. Postman is a popular and features a GUI. Command line options like curl are fine as well.

Your First Nodes

Open your browser and go to your directed graph instance. The default should be http://localhost:3100/# you can check the console you started dgbuilder in to confirm the URL.

...

By deffault it will have rpc='', click between the single quotes and type in helloWorld like in the screen shot below then click Ok.

Your First Graph

From the left hand palette drag in a record node onto the screen.

...

Upload and activate your graph, doing this through dgbuilder is the most convenient method. If you are unsure how to do this visit Your first First Graph

Now that the graph is uploaded and activated we can invoke it.

...

Based on this output we can see the graph which was just written, uploaded and activated has finally been executed. It executes a single node which we can see is writing a hardcoded string to the log file.

Using A Block Node

Let's make this into a simple 2 node graph, one node will record "Hello World!" the second node will record "Goodbye".

...

  • Block nodes are needed whenever multiple nodes need to be executed
  • Graphs execute from top to bottom, because the first node is above the second Hello World is printed before Goodbye. To test this you can drag the lower node above the other node and re-test. You can also experiment with moving nodes horizontally, the horizontal position does not matter.

Reading User Input

At this point the graph prints only static messages. To make it more interactive we can start passing and reading parameters.

...

We can see that the value of the parameter named customerName is now printed out in the log.

Return an Error

Currently no matter what the caller passes the graph returns success. For this example we have decided if the customer name is john we should stop processing and return an error. This is because john has been known to steal service.

...

We can see the print statements are working and success is returned.

Checking For Null Values

The current code prevents john from using this service, but the client can enter a null or empty customerName.

...

Code Block
2017-03-14T19:04:39.618Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|INFO |SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|About to execute graph SvcLogicGraph [module=TUTORIAL, rpc=helloWorld, mode=sync, version=1]
2017-03-14T19:04:39.618Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|INFO |SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing root node
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|INFO |SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|About to execute node # 1 (block)
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node 1
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type block - com.att.sdnctl.sli.provider.BlockNodeExecutor
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|BlockNodeExecutor               |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Block - executing outcome 1
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node 2
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type switch - com.att.sdnctl.sli.provider.SwitchNodeExecutor
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SwitchNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing switch node
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SwitchNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression ($customerName) evaluates to 
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SwitchNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Next node to execute is node 4
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node 4
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|SvcLogicServiceImpl             |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type return - com.att.sdnctl.sli.provider.ReturnNodeExecutor
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|ReturnNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Returning status failure
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|ReturnNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute error-message to customer name was null.
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|DEBUG|ReturnNodeExecutor              |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute error-code to 400
2017-03-14T19:04:39.619Z|72f0cbcf-69c6-4b93-92aa-0cd5da32112b|qtp1849298247-45|INFO |BlockNodeExecutor               |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Block - stopped executing nodes due to failure status

The Other Outcome

Let's refactor the code to use an "other" outcome.

...

We can see the code is working as expected. This refactoring wasn't necessary, but there are cases when an other outcome is highly useful.

Context Memory

Behind the scenes memory is nothing more than a HashMap<String,String> in java. We can read and modify values in this hashmap.

...

These values will all be put into context memory so they can be read.

Looping

Currently only For loops are supported. Let's loop over the greeting array. Drag a for node onto the page. One of the record nodes can be deleted.

...

We can see it is looping over the greeting array and exiting.

Calling Subgraphs

It is possible for any graph to call any other graph. The word subgraph here means a graph that is only intended to be called by another graph and not invoked alone.

...

Sharing memory makes passing data very simple, but can have unintended consequences. When writing subgraphs this must be understood.

Conclusion

At the end of this guide you should be familiar with:

...

This covers the base functionality of directed graph. You can now continue with Your first First Graph.