Skip to content

Commit d7e2c4b

Browse files
authored
Merge pull request #217 from jembi/PLAT-641-update-mpi-mediator-package
Plat 641 update mpi mediator package
2 parents c6cb4ce + d39ae31 commit d7e2c4b

File tree

7 files changed

+305
-3
lines changed

7 files changed

+305
-3
lines changed

message-bus-kafka/package-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"KAFKA_CPU_RESERVE": "0.05",
1212
"KAFKA_MEMORY_LIMIT": "3G",
1313
"KAFKA_MEMORY_RESERVE": "500M",
14-
"KAFKA_TOPICS": "2xx,reprocess,3xx,metrics:3:1",
14+
"KAFKA_TOPICS": "2xx,2xx-async,3xx,reprocess,errors,metrics:3:1",
1515
"KAFDROP_CPU_LIMIT": "0",
1616
"KAFDROP_CPU_RESERVE": "0.05",
1717
"KAFDROP_MEMORY_LIMIT": "3G",

mpi-mediator/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
FHIR_DATASTORE_PROTOCOL: ${FHIR_DATASTORE_PROTOCOL}
2323
FHIR_DATASTORE_HOST: ${FHIR_DATASTORE_HOST}
2424
FHIR_DATASTORE_PORT: ${FHIR_DATASTORE_PORT}
25+
DISABLE_VALIDATION: ${DISABLE_VALIDATION}
2526
deploy:
2627
placement:
2728
max_replicas_per_node: 1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3.9'
2+
3+
services:
4+
# container for executing config import scripts for creating the OpenHIM channels used by the Mediator
5+
mpi-mediator-config-importer:
6+
image: node:erbium-alpine
7+
environment:
8+
OPENHIM_CORE_SERVICE_NAME: ${OPENHIM_CORE_SERVICE_NAME}
9+
OPENHIM_MEDIATOR_API_PORT: ${OPENHIM_MEDIATOR_API_PORT}
10+
OPENHIM_API_USERNAME: ${OPENHIM_USERNAME}
11+
OPENHIM_API_PASSWORD: ${OPENHIM_PASSWORD}
12+
# Reject unauthorised is only needed if the OpenHIM's SSL is not setup
13+
NODE_TLS_REJECT_UNAUTHORIZED: 0
14+
command: sh -c "node openhimConfig.js"
15+
configs:
16+
- source: mpi-mediator-config-importer-openhimConfig.js
17+
target: /openhimConfig.js
18+
- source: mpi-mediator-config-importer-openhim-import.json
19+
target: /openhim-import.json
20+
deploy:
21+
replicas: 1
22+
restart_policy:
23+
condition: none
24+
25+
configs:
26+
mpi-mediator-config-importer-openhimConfig.js:
27+
file: ./volume/openhimConfig.js
28+
name: mpi-mediator-config-importer-openhimConfig.js-${mpi_mediator_config_importer_openhimConfig_js_DIGEST:?err}
29+
labels:
30+
name: mpi-mediator
31+
mpi-mediator-config-importer-openhim-import.json:
32+
file: ./volume/openhim-import.json
33+
name: mpi-mediator-config-importer-openhim-import.json-${mpi_mediator_config_importer_openhim_import_js_DIGEST:?err}
34+
labels:
35+
name: mpi-mediator
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"Users": [
3+
{
4+
"groups": [
5+
"admin"
6+
],
7+
"firstname": "Super",
8+
"surname": "User",
9+
"email": "root@openhim.org",
10+
"passwordAlgorithm": "sha512",
11+
"passwordHash": "ea3824f17cf1379eb118a36bc7c8cf0f45712e2af7748567fca5313dec6fa66d61064e82a5e5cb88e998486ee3c7d0dac235bbeda8c341d6edc1c77406be2ab6",
12+
"passwordSalt": "d4f622c0404f09bd959bfb263efa3452",
13+
"expiry": null,
14+
"locked": false,
15+
"token": null,
16+
"tokenType": null
17+
}
18+
],
19+
"Clients": [
20+
{
21+
"roles": [
22+
"instant"
23+
],
24+
"customTokenID": "test",
25+
"clientID": "test",
26+
"name": "Test Client"
27+
}
28+
],
29+
"Channels": [
30+
{
31+
"methods": [
32+
"GET",
33+
"POST"
34+
],
35+
"type": "http",
36+
"allow": [
37+
"instant"
38+
],
39+
"whitelist": [],
40+
"authType": "private",
41+
"matchContentTypes": [],
42+
"properties": [],
43+
"txViewAcl": [],
44+
"txViewFullAcl": [],
45+
"txRerunAcl": [],
46+
"status": "enabled",
47+
"rewriteUrls": false,
48+
"addAutoRewriteRules": true,
49+
"autoRetryEnabled": false,
50+
"autoRetryPeriodMinutes": 60,
51+
"routes": [
52+
{
53+
"type": "http",
54+
"status": "enabled",
55+
"forwardAuthHeader": false,
56+
"name": "MPI Mediator",
57+
"secured": false,
58+
"host": "mpi-mediator",
59+
"port": 3000,
60+
"path": "",
61+
"pathTransform": "",
62+
"primary": true,
63+
"username": "",
64+
"password": ""
65+
}
66+
],
67+
"requestBody": true,
68+
"responseBody": true,
69+
"rewriteUrlsConfig": [],
70+
"name": "MPI Orchestrations - Create/Read operations for patients and their clinical data",
71+
"urlPattern": "^/fhir.*$",
72+
"priority": null,
73+
"matchContentRegex": null,
74+
"matchContentXpath": null,
75+
"matchContentValue": null,
76+
"matchContentJson": null,
77+
"pollingSchedule": null,
78+
"tcpHost": null,
79+
"tcpPort": null,
80+
"updatedBy": {
81+
"id": "63cd5092c962240014b87c59",
82+
"name": "Super User"
83+
},
84+
"alerts": [],
85+
"description": ""
86+
},
87+
{
88+
"methods": [
89+
"POST"
90+
],
91+
"type": "http",
92+
"allow": [
93+
"instant"
94+
],
95+
"whitelist": [],
96+
"authType": "private",
97+
"matchContentTypes": [],
98+
"properties": [],
99+
"txViewAcl": [],
100+
"txViewFullAcl": [],
101+
"txRerunAcl": [],
102+
"status": "enabled",
103+
"rewriteUrls": false,
104+
"addAutoRewriteRules": true,
105+
"autoRetryEnabled": false,
106+
"autoRetryPeriodMinutes": 60,
107+
"updatedBy": {
108+
"id": "63cd5092c962240014b87c59",
109+
"name": "Super User"
110+
},
111+
"routes": [
112+
{
113+
"type": "http",
114+
"status": "enabled",
115+
"forwardAuthHeader": false,
116+
"name": "MPI Mediator",
117+
"secured": false,
118+
"host": "mpi-mediator",
119+
"port": 3000,
120+
"path": "",
121+
"pathTransform": "",
122+
"primary": true,
123+
"username": "",
124+
"password": ""
125+
}
126+
],
127+
"requestBody": true,
128+
"responseBody": true,
129+
"rewriteUrlsConfig": [],
130+
"urlPattern": "^/async/fhir/?$",
131+
"priority": null,
132+
"matchContentRegex": null,
133+
"matchContentXpath": null,
134+
"matchContentValue": null,
135+
"matchContentJson": null,
136+
"pollingSchedule": null,
137+
"tcpHost": null,
138+
"tcpPort": null,
139+
"alerts": [],
140+
"name": "MPI Orchestration for fhir bundles - Asynchronous flow"
141+
}
142+
],
143+
"Mediators": [
144+
{
145+
"urn": "urn:mediator:mpi-mediator",
146+
"version": "1.0.0",
147+
"name": "MPI mediator",
148+
"description": "A mediator handling interactions between the OpenHIM Core service, Sante MPI, Hapi-FHIR, and Kafka",
149+
"defaultChannelConfig": [
150+
{
151+
"methods": [
152+
"POST",
153+
"GET"
154+
],
155+
"type": "http",
156+
"allow": [
157+
"instant"
158+
],
159+
"whitelist": [],
160+
"authType": "private",
161+
"matchContentTypes": [],
162+
"properties": [],
163+
"txViewAcl": [],
164+
"txViewFullAcl": [],
165+
"txRerunAcl": [],
166+
"status": "enabled",
167+
"rewriteUrls": false,
168+
"addAutoRewriteRules": true,
169+
"autoRetryEnabled": false,
170+
"autoRetryPeriodMinutes": 60,
171+
"name": "MPI mediator",
172+
"urlPattern": "^(/async)?/fhir.*$",
173+
"routes": [
174+
{
175+
"type": "http",
176+
"status": "enabled",
177+
"forwardAuthHeader": false,
178+
"name": "MPI Endpoint",
179+
"host": "mpi-mediator",
180+
"port": 3000,
181+
"primary": true
182+
}
183+
],
184+
"alerts": [],
185+
"rewriteUrlsConfig": []
186+
}
187+
],
188+
"endpoints": [
189+
{
190+
"type": "http",
191+
"status": "enabled",
192+
"forwardAuthHeader": false,
193+
"name": "MPI Endpoint",
194+
"host": "mpi-mediator",
195+
"path": "/fhir",
196+
"port": 3000,
197+
"primary": true
198+
}
199+
],
200+
"configDefs": [],
201+
"_lastHeartbeat": "2023-01-23T09:40:21.368Z",
202+
"_uptime": 52784.4956787
203+
}
204+
],
205+
"ContactGroups": []
206+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const https = require('https')
5+
const path = require('path')
6+
7+
const OPENHIM_CORE_SERVICE_NAME = process.env.OPENHIM_CORE_SERVICE_NAME || 'openhim-core'
8+
const OPENHIM_API_PASSWORD =
9+
process.env.OPENHIM_API_PASSWORD || 'openhim-password'
10+
const OPENHIM_MEDIATOR_API_PORT = process.env.OPENHIM_MEDIATOR_API_PORT || 8080
11+
const OPENHIM_API_USERNAME =
12+
process.env.OPENHIM_API_USERNAME || 'root@openhim.org'
13+
14+
const authHeader = new Buffer.from(
15+
`${OPENHIM_API_USERNAME}:${OPENHIM_API_PASSWORD}`
16+
).toString('base64')
17+
18+
const jsonData = JSON.parse(
19+
fs.readFileSync(path.resolve(__dirname, 'openhim-import.json'))
20+
)
21+
22+
const data = JSON.stringify(jsonData)
23+
24+
const options = {
25+
protocol: 'https:',
26+
hostname: OPENHIM_CORE_SERVICE_NAME,
27+
port: OPENHIM_MEDIATOR_API_PORT,
28+
path: '/metadata',
29+
method: 'POST',
30+
headers: {
31+
'Content-Type': 'application/json',
32+
'Content-Length': data.length,
33+
Authorization: `Basic ${authHeader}`
34+
}
35+
}
36+
37+
const req = https.request(options, res => {
38+
if (res.statusCode == 401) {
39+
throw new Error(`Incorrect OpenHIM API credentials`)
40+
}
41+
42+
if (res.statusCode != 201) {
43+
throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`)
44+
}
45+
46+
console.log('Successfully Imported OpenHIM Config')
47+
})
48+
49+
req.on('error', error => {
50+
throw new Error(`Failed to import OpenHIM config: ${error}`)
51+
})
52+
53+
req.write(data)
54+
req.end()

mpi-mediator/package-metadata.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"TRUST_SELF_SIGNED": "true",
1818
"OPENHIM_USERNAME": "root@openhim.org",
1919
"OPENHIM_PASSWORD": "instant101",
20+
"OPENHIM_CORE_SERVICE_NAME": "openhim-core",
21+
"OPENHIM_MEDIATOR_API_PORT": 8080,
2022
"REGISTER_MEDIATOR": "true",
2123
"MPI_CLIENT_ID": "fiddler",
2224
"MPI_CLIENT_SECRET": "fiddler",
@@ -30,6 +32,7 @@
3032
"KAFKA_ERROR_TOPIC": "errors",
3133
"FHIR_DATASTORE_PROTOCOL": "http",
3234
"FHIR_DATASTORE_HOST": "hapi-fhir",
33-
"FHIR_DATASTORE_PORT": 8080
35+
"FHIR_DATASTORE_PORT": 8080,
36+
"DISABLE_VALIDATION": "false"
3437
}
3538
}

mpi-mediator/swarm.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ function initialize_package() {
4949
log error "Failed to deploy package"
5050
exit 1
5151
}
52+
docker::deploy_config_importer "$COMPOSE_FILE_PATH/importer/docker-compose.config.yml" "mpi-mediator-config-importer" "mpi-mediator"
5253
}
5354

5455
function destroy_package() {
55-
docker::service_destroy "${SERVICE_NAMES}"
56+
docker::service_destroy "${SERVICE_NAMES}" "mpi-mediator-config-importer"
57+
58+
docker::prune_configs "mpi-mediator"
5659
}
5760

5861
main() {

0 commit comments

Comments
 (0)