Adapter example
This tutorial is a step-by-step instruction on building an example adapter using the Workflow Adapter SDK. It gives an idea on the adapter structure and on how you provide input to define adapter activities to be consumed by a workflow worker. Before you start, you need to go through the Prerequisites section to set up your development environment.
Step 1: Create new adapter
In a terminal window, open your cwmsdk
repository directory and run:
cwm-sdk create-adapter -location ~/your_repo/adapters -vendor companyX -feature featureX -product productX
Now you have a directory in adapters
named companyX.productX
with the following contents:
Makefile
adapter.properties
go
proto
./go:
common
go.mod
featureX
./go/common:
./go/featureX:
./proto:
cisco.cwm.sdk.resource.proto
companyX.productX.common.adapter.proto
companyX.productX.featureX.adapter.proto
Step 2: Define mock activity
The Adapter SDK has generated the .proto
files. In the companyX.productX.featureX.adapter.proto
file, define the interface of the adapter:
Procedure
Step 1 |
Open the
|
Step 2 |
To define your activity, replace the placeholder 'MyActivity' with a mock 'Hello' activity, along with the MyRequest and MyResponse placeholder names and message parameters as shown below:
|
Step 3: Generate adapter source code
Procedure
Step 1 |
Based on the
|
Step 2 |
Now generate the go code for the defined activities. In the main adapter directory, run:
The generated
|
Step 3 |
Edit the file to return a message:
|
Define another activity
If you wish to add another activity to the existing feature set (go package),
Procedure
Step 1 |
Open and edit the
|
Step 2 |
Update the activities go code using the SDK:
Once the code is generated, the |
Step 4: Add another feature
If you wish to add another feature (go package) to the example adapter, use the extend-adapter
command. Open your cwmsdk
repository directory in a terminal and run:
cwm-sdk extend-adapter -feature featureY
Procedure
Step 1 |
A new
|
Step 2 |
To define activities for the new feature, open the
|
Step 3 |
Generate the code for the 'featureY' package and activities.
|
Step 5: Create an installable archive
cwm-sdk create-installable
The generated archive contains the all required files of the adapter. The go vendor command has been executed in order to eliminate any external dependencies.