1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 | # File-arrival demo: one workflow shows the common automation building blocks.
# File Monitor trigger -> event-based start
# Linux script -> shell scripts with parameters
# SQL task + variable -> a value from a database, kept for later tasks
# ${_date(..., -1)} -> date calculations
# Web Service task -> REST API call
# PowerShell task -> PowerShell on Windows
# Stop / Start service -> central control of Windows services
#
# Before import: change the agents (linux-agent, windows-agent), the database
# connection (Demo_Mysql) and the credentials (Controller API, linux-admin).
# Run "HUB-DEMO SETUP Workflow" once, then copy a .csv file to /demo/hub_demo/in/.
version: 1
style: compact
create_only: [business_services, credentials, database_connections]
business_services:
- HUB-DEMO: File-arrival demo objects
scripts:
hub_demo_check_file.sh:
scriptType: Script
description: Checks the file that started the workflow.
content: |-
#!/bin/bash
# $1 = the file that the File Monitor trigger found
FILE="$1"
echo "File-arrival demo - file check on $(hostname)"
echo "File: $FILE"
if [ ! -f "$FILE" ]; then
echo "ERROR: file not found"
exit 1
fi
if [ ! -s "$FILE" ]; then
echo "ERROR: file is empty"
exit 2
fi
LINES=$(wc -l < "$FILE")
echo "Size : $(stat -c %s "$FILE") bytes"
echo "Lines: $LINES"
echo "Header: $(head -1 "$FILE")"
echo "File is OK"
exit 0
hub_demo_setup.sh:
scriptType: Script
description: Creates the demo folders and a sample file on the Linux agent. Runs as a sudo user, then gives the folders to ubroker.
content: |-
#!/bin/bash
# Setup for the File-arrival demo. Safe to run again.
# Runs as a sudo user: sudo creates the folders, then ubroker becomes the owner.
BASE=/demo/hub_demo
OWNER=ubroker
echo "Running as: $(id -un)"
if ! sudo -n true 2>/dev/null; then
echo "ERROR: $(id -un) cannot use sudo without a password"
exit 1
fi
sudo mkdir -p "$BASE/in" "$BASE/samples" || exit 1
sudo tee "$BASE/samples/sample.csv" > /dev/null <<'CSV'
period,site,item,count
CURRENT,Site-A,Orders,124
CURRENT,Site-A,Returns,87
CURRENT,Site-B,Orders,96
CURRENT,Site-B,Invoices,231
CSV
sudo chown -R "$OWNER:$(id -gn $OWNER)" "$BASE" || exit 1
sudo chmod -R 775 "$BASE" || exit 1
echo "Demo folders are ready:"
ls -ld /demo
ls -lR "$BASE"
echo
echo "To start the demo (trigger enabled), copy the sample into the inbound folder:"
echo " cp $BASE/samples/sample.csv $BASE/in/data_\$(date +%Y%m%d%H%M%S).csv"
exit 0
hub_demo_report.ps1:
scriptType: Data
description: Writes a small report with the period and the business date.
content: |-
param(
[string]$Period,
[string]$BusinessDate,
[string]$SourceFile
)
Write-Output "File-arrival demo - PowerShell on $env:COMPUTERNAME"
Write-Output "Period name : $Period"
Write-Output "Business date : $BusinessDate (today - 1 day)"
Write-Output "Source file : $SourceFile"
$dir = "C:\demo\hub_demo"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
$out = Join-Path $dir "report_$BusinessDate.txt"
"Period=$Period`r`nBusinessDate=$BusinessDate`r`nSourceFile=$SourceFile`r`nCreated=$(Get-Date -Format s)" |
Out-File -FilePath $out -Encoding utf8
Write-Output "Report written: $out"
exit 0
tasks:
# 1. Event-based trigger: the monitor that the trigger uses
HUB-DEMO Watch Inbound File:
type: File Monitor
agent: linux-agent
fileName: /demo/hub_demo/in/*.csv
fmtype: Created
business_services: [HUB-DEMO]
# 2. Linux script: check the file
HUB-DEMO 01 Check File (Linux):
type: Unix
agent: linux-agent
commandOrScript: Script
script: hub_demo_check_file.sh
parameters: ${_resolve('ops_trigger_file_name', '/demo/hub_demo/samples/sample.csv')}
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
# 3. SQL: get the period name, put it in a variable
HUB-DEMO 02 Get Period Name (SQL):
type: Sql
connection: Demo_Mysql
sqlCommand: SELECT UPPER(DATE_FORMAT(CURDATE(), '%b-%y')) AS PERIOD_NAME
actions:
setVariableActions:
- status: Success
variableName: period_name
variableValue: ${_resultsColumn('PERIOD_NAME')}
variableScope: Top Level Parent
business_services: [HUB-DEMO]
# 4. Web Service: call a REST API
HUB-DEMO 03 Call REST API:
type: Web Service
url: https://your-controller.example.com/resources/agents/list
httpMethod: GET
httpAuth: Basic
credentials: Controller API
httpHeaders:
- Accept: application/json
business_services: [HUB-DEMO]
# 5. PowerShell on Windows, with the period and the date - 1 day
HUB-DEMO 04 PowerShell Report (Windows):
type: Windows
agent: windows-agent
command: powershell -NoProfile -ExecutionPolicy Bypass -File "${_scriptPath('hub_demo_report.ps1')}"
-Period "${period_name}" -BusinessDate "${business_date}"
-SourceFile "${_resolve('ops_trigger_file_name', 'manual run')}"
variables:
- business_date: ${_date('yyyy-MM-dd', -1)}
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
# 6. Windows service: stop and start
HUB-DEMO 05 Stop Windows Service:
type: Windows
agent: windows-agent
command: powershell -NoProfile -Command "Stop-Service -Name '${win_service}' -Force -ErrorAction Stop;
Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize"
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
HUB-DEMO 06 Start Windows Service:
type: Windows
agent: windows-agent
command: powershell -NoProfile -Command "Start-Service -Name '${win_service}' -ErrorAction Stop;
Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize"
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
# Setup: folders and files for the demo
HUB-DEMO SETUP Linux Folders:
type: Unix
agent: linux-agent
commandOrScript: Script
script: hub_demo_setup.sh
credentials: linux-admin
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
HUB-DEMO SETUP Windows Folder:
type: Windows
agent: windows-agent
command: powershell -NoProfile -Command "New-Item -ItemType Directory -Force -Path 'C:\demo\hub_demo' | Out-Null;
Get-Item 'C:\demo\hub_demo' | Format-List FullName, CreationTime;
Get-Service -Name '${win_service}' | Format-Table Name, DisplayName, Status -AutoSize"
outputReturnType: OUTERR
outputReturnSline: '1'
outputReturnNline: '100'
business_services: [HUB-DEMO]
HUB-DEMO SETUP Workflow:
type: Workflow
summary: Creates the folders and the sample file for the File-arrival demo. Run it once before the demo.
variables:
- win_service: Spooler
business_services: [HUB-DEMO]
tasks:
HUB-DEMO SETUP Linux Folders:
position: [60, 120]
HUB-DEMO SETUP Windows Folder:
position: [60, 260]
HUB-DEMO Inbound File Workflow:
type: Workflow
summary: File-arrival demo - file arrives, Linux, SQL, REST, PowerShell, Windows service.
variables:
- win_service: Spooler
business_services: [HUB-DEMO]
tasks:
HUB-DEMO 01 Check File (Linux):
position: [60, 120]
HUB-DEMO 02 Get Period Name (SQL):
after: HUB-DEMO 01 Check File (Linux)
position: [300, 120]
HUB-DEMO 03 Call REST API:
after: HUB-DEMO 02 Get Period Name (SQL)
position: [540, 120]
HUB-DEMO 04 PowerShell Report (Windows):
after: HUB-DEMO 03 Call REST API
position: [780, 120]
HUB-DEMO 05 Stop Windows Service:
after: HUB-DEMO 04 PowerShell Report (Windows)
position: [1020, 120]
HUB-DEMO 06 Start Windows Service:
after: HUB-DEMO 05 Stop Windows Service
position: [1260, 120]
triggers:
HUB-DEMO File Arrived:
type: File Monitor
description: Starts the File-arrival demo workflow when a .csv file arrives in /demo/hub_demo/in.
taskMonitor: HUB-DEMO Watch Inbound File
tasks: [HUB-DEMO Inbound File Workflow]
calendar: System Default
business_services: [HUB-DEMO]
|