Siddhi App Management - madhawav/DASPythonClient GitHub Wiki

Using DAS Python Client following operations can be undertaken on Siddhi App Management of WSO2 DAS 4.0.

  • List all Siddhi Apps.
  • Retrieve Siddhi App using name.
  • Retrieve Status of Siddhi App.
  • Save a new Siddhi App in DAS.
  • Update a Siddhi App stored in DAS.
  • Delete a Siddhi App stored in DAS.

Pre-requisites

  1. Install DAS Python Client by following Installation Guide.
  2. WSO2 DAS 4.0 must be already installed and running. If not, follow the steps below.

List all Siddhi Apps

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient

dasPythonClient = DAS4PythonClient('http://localhost:9090') # host URL of DAS
siddhiAppManagementClient = dasPythonClient.getSiddhiAppManagementClient()

print(siddhiAppManagementClient.listSiddhiApps()) # prints a list of siddhi apps

Retrieve Siddhi App using Name

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient
dasPythonClient = DAS4PythonClient('http://localhost:9090') # host URL of DAS
siddhiAppManagementClient = dasPythonClient.getSiddhiAppManagementClient()

app = siddhiAppManagementClient.retrieveSiddhiApp("TestSiddhiApp")
print(app)

Retrieve Siddhi App Status

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient
dasPythonClient = DAS4PythonClient('http://localhost:9090') # host URL of DAS
siddhiAppManagementClient = dasPythonClient.getSiddhiAppManagementClient()

status = siddhiAppManagementClient.retrieveStatusSiddhiApp("TestSiddhiApp")
print (status) # prints status of siddhi app (active)

Save new Siddhi App

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient

dasPythonClient = DAS4PythonClient('http://localhost:9090') # host URL of DAS
siddhiAppManagerClient = dasPythonClient.getSiddhiAppManagementClient()

siddhiApp = "@App:name('TestSiddhiApp1') \n" \
               "define stream FooStream (symbol string, price float, volume long); \n" \
               "@source(type='inMemory', topic='symbol', @map(type='passThrough')) \n" \
               "define stream BarStream (symbol string, price float, volume long); \n" \
               "from FooStream select symbol, price, volume insert into BarStream; \n"

if siddhiAppManagerClient.saveSiddhiApp(siddhiApp):
    print("Successfully saved!")

Update a saved Siddhi App

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient
from DAS4PythonAPI.SiddhiAppManagement.SiddhiAppManagementClient import UpdateAppStatusResponse

dasPythonClient = DAS4PythonClient('http://localhost:9090') # Host URL of DAS
siddhiAppManagerClient = dasPythonClient.getSiddhiAppManagementClient()

siddhiApp = "@App:name('TestSiddhiApp1') \n" \
               "define stream FooStream (symbol string, price float, volume long); \n" \
               "@source(type='inMemory', topic='symbol', @map(type='passThrough')) \n" \
               "define stream BarStream (symbol string, price float, volume long); \n" \
               "from FooStream select symbol, price, volume insert into BarStream; \n"

result = siddhiAppManagerClient.updateSiddhiApp(siddhiApp)
if result.name == UpdateAppStatusResponse.savedNew.name:
    print("Saved new Siddhi App")
elif result.name == UpdateAppStatusResponse.updated.name:
    print("Updated saved Siddhi App")

Delete a Siddhi App

from DAS4PythonAPI.DAS4PythonClient import DAS4PythonClient

dasPythonClient = DAS4PythonClient('http://localhost:9090') # host URL of DAS
siddhiAppManagerClient = dasPythonClient.getSiddhiAppManagementClient()

siddhiAppManagerClient.deleteSiddhiApp("TestSiddhiApp1") # returns True if successfully deleted