diff --git a/message-bus-kafka/package-metadata.json b/message-bus-kafka/package-metadata.json index 965c2d72..02922a18 100644 --- a/message-bus-kafka/package-metadata.json +++ b/message-bus-kafka/package-metadata.json @@ -11,7 +11,7 @@ "KAFKA_CPU_RESERVE": "0.05", "KAFKA_MEMORY_LIMIT": "3G", "KAFKA_MEMORY_RESERVE": "500M", - "KAFKA_TOPICS": "2xx,reprocess,3xx,metrics:3:1", + "KAFKA_TOPICS": "2xx,2xx-async,3xx,reprocess,errors,metrics:3:1", "KAFDROP_CPU_LIMIT": "0", "KAFDROP_CPU_RESERVE": "0.05", "KAFDROP_MEMORY_LIMIT": "3G", diff --git a/mpi-mediator/docker-compose.yml b/mpi-mediator/docker-compose.yml index 72bf2af3..b6944cdc 100644 --- a/mpi-mediator/docker-compose.yml +++ b/mpi-mediator/docker-compose.yml @@ -22,6 +22,7 @@ services: FHIR_DATASTORE_PROTOCOL: ${FHIR_DATASTORE_PROTOCOL} FHIR_DATASTORE_HOST: ${FHIR_DATASTORE_HOST} FHIR_DATASTORE_PORT: ${FHIR_DATASTORE_PORT} + DISABLE_VALIDATION: ${DISABLE_VALIDATION} deploy: placement: max_replicas_per_node: 1 diff --git a/mpi-mediator/importer/docker-compose.config.yml b/mpi-mediator/importer/docker-compose.config.yml new file mode 100644 index 00000000..c492b242 --- /dev/null +++ b/mpi-mediator/importer/docker-compose.config.yml @@ -0,0 +1,35 @@ +version: '3.9' + +services: + # container for executing config import scripts for creating the OpenHIM channels used by the Mediator + mpi-mediator-config-importer: + image: node:erbium-alpine + environment: + OPENHIM_CORE_SERVICE_NAME: ${OPENHIM_CORE_SERVICE_NAME} + OPENHIM_MEDIATOR_API_PORT: ${OPENHIM_MEDIATOR_API_PORT} + OPENHIM_API_USERNAME: ${OPENHIM_USERNAME} + OPENHIM_API_PASSWORD: ${OPENHIM_PASSWORD} + # Reject unauthorised is only needed if the OpenHIM's SSL is not setup + NODE_TLS_REJECT_UNAUTHORIZED: 0 + command: sh -c "node openhimConfig.js" + configs: + - source: mpi-mediator-config-importer-openhimConfig.js + target: /openhimConfig.js + - source: mpi-mediator-config-importer-openhim-import.json + target: /openhim-import.json + deploy: + replicas: 1 + restart_policy: + condition: none + +configs: + mpi-mediator-config-importer-openhimConfig.js: + file: ./volume/openhimConfig.js + name: mpi-mediator-config-importer-openhimConfig.js-${mpi_mediator_config_importer_openhimConfig_js_DIGEST:?err} + labels: + name: mpi-mediator + mpi-mediator-config-importer-openhim-import.json: + file: ./volume/openhim-import.json + name: mpi-mediator-config-importer-openhim-import.json-${mpi_mediator_config_importer_openhim_import_js_DIGEST:?err} + labels: + name: mpi-mediator diff --git a/mpi-mediator/importer/volume/openhim-import.json b/mpi-mediator/importer/volume/openhim-import.json new file mode 100644 index 00000000..142f3dc8 --- /dev/null +++ b/mpi-mediator/importer/volume/openhim-import.json @@ -0,0 +1,206 @@ +{ + "Users": [ + { + "groups": [ + "admin" + ], + "firstname": "Super", + "surname": "User", + "email": "root@openhim.org", + "passwordAlgorithm": "sha512", + "passwordHash": "ea3824f17cf1379eb118a36bc7c8cf0f45712e2af7748567fca5313dec6fa66d61064e82a5e5cb88e998486ee3c7d0dac235bbeda8c341d6edc1c77406be2ab6", + "passwordSalt": "d4f622c0404f09bd959bfb263efa3452", + "expiry": null, + "locked": false, + "token": null, + "tokenType": null + } + ], + "Clients": [ + { + "roles": [ + "instant" + ], + "customTokenID": "test", + "clientID": "test", + "name": "Test Client" + } + ], + "Channels": [ + { + "methods": [ + "GET", + "POST" + ], + "type": "http", + "allow": [ + "instant" + ], + "whitelist": [], + "authType": "private", + "matchContentTypes": [], + "properties": [], + "txViewAcl": [], + "txViewFullAcl": [], + "txRerunAcl": [], + "status": "enabled", + "rewriteUrls": false, + "addAutoRewriteRules": true, + "autoRetryEnabled": false, + "autoRetryPeriodMinutes": 60, + "routes": [ + { + "type": "http", + "status": "enabled", + "forwardAuthHeader": false, + "name": "MPI Mediator", + "secured": false, + "host": "mpi-mediator", + "port": 3000, + "path": "", + "pathTransform": "", + "primary": true, + "username": "", + "password": "" + } + ], + "requestBody": true, + "responseBody": true, + "rewriteUrlsConfig": [], + "name": "MPI Orchestrations - Create/Read operations for patients and their clinical data", + "urlPattern": "^/fhir.*$", + "priority": null, + "matchContentRegex": null, + "matchContentXpath": null, + "matchContentValue": null, + "matchContentJson": null, + "pollingSchedule": null, + "tcpHost": null, + "tcpPort": null, + "updatedBy": { + "id": "63cd5092c962240014b87c59", + "name": "Super User" + }, + "alerts": [], + "description": "" + }, + { + "methods": [ + "POST" + ], + "type": "http", + "allow": [ + "instant" + ], + "whitelist": [], + "authType": "private", + "matchContentTypes": [], + "properties": [], + "txViewAcl": [], + "txViewFullAcl": [], + "txRerunAcl": [], + "status": "enabled", + "rewriteUrls": false, + "addAutoRewriteRules": true, + "autoRetryEnabled": false, + "autoRetryPeriodMinutes": 60, + "updatedBy": { + "id": "63cd5092c962240014b87c59", + "name": "Super User" + }, + "routes": [ + { + "type": "http", + "status": "enabled", + "forwardAuthHeader": false, + "name": "MPI Mediator", + "secured": false, + "host": "mpi-mediator", + "port": 3000, + "path": "", + "pathTransform": "", + "primary": true, + "username": "", + "password": "" + } + ], + "requestBody": true, + "responseBody": true, + "rewriteUrlsConfig": [], + "urlPattern": "^/async/fhir/?$", + "priority": null, + "matchContentRegex": null, + "matchContentXpath": null, + "matchContentValue": null, + "matchContentJson": null, + "pollingSchedule": null, + "tcpHost": null, + "tcpPort": null, + "alerts": [], + "name": "MPI Orchestration for fhir bundles - Asynchronous flow" + } + ], + "Mediators": [ + { + "urn": "urn:mediator:mpi-mediator", + "version": "1.0.0", + "name": "MPI mediator", + "description": "A mediator handling interactions between the OpenHIM Core service, Sante MPI, Hapi-FHIR, and Kafka", + "defaultChannelConfig": [ + { + "methods": [ + "POST", + "GET" + ], + "type": "http", + "allow": [ + "instant" + ], + "whitelist": [], + "authType": "private", + "matchContentTypes": [], + "properties": [], + "txViewAcl": [], + "txViewFullAcl": [], + "txRerunAcl": [], + "status": "enabled", + "rewriteUrls": false, + "addAutoRewriteRules": true, + "autoRetryEnabled": false, + "autoRetryPeriodMinutes": 60, + "name": "MPI mediator", + "urlPattern": "^(/async)?/fhir.*$", + "routes": [ + { + "type": "http", + "status": "enabled", + "forwardAuthHeader": false, + "name": "MPI Endpoint", + "host": "mpi-mediator", + "port": 3000, + "primary": true + } + ], + "alerts": [], + "rewriteUrlsConfig": [] + } + ], + "endpoints": [ + { + "type": "http", + "status": "enabled", + "forwardAuthHeader": false, + "name": "MPI Endpoint", + "host": "mpi-mediator", + "path": "/fhir", + "port": 3000, + "primary": true + } + ], + "configDefs": [], + "_lastHeartbeat": "2023-01-23T09:40:21.368Z", + "_uptime": 52784.4956787 + } + ], + "ContactGroups": [] +} diff --git a/mpi-mediator/importer/volume/openhimConfig.js b/mpi-mediator/importer/volume/openhimConfig.js new file mode 100644 index 00000000..c175f1c5 --- /dev/null +++ b/mpi-mediator/importer/volume/openhimConfig.js @@ -0,0 +1,54 @@ +'use strict' + +const fs = require('fs') +const https = require('https') +const path = require('path') + +const OPENHIM_CORE_SERVICE_NAME = process.env.OPENHIM_CORE_SERVICE_NAME || 'openhim-core' +const OPENHIM_API_PASSWORD = + process.env.OPENHIM_API_PASSWORD || 'openhim-password' +const OPENHIM_MEDIATOR_API_PORT = process.env.OPENHIM_MEDIATOR_API_PORT || 8080 +const OPENHIM_API_USERNAME = + process.env.OPENHIM_API_USERNAME || 'root@openhim.org' + +const authHeader = new Buffer.from( + `${OPENHIM_API_USERNAME}:${OPENHIM_API_PASSWORD}` +).toString('base64') + +const jsonData = JSON.parse( + fs.readFileSync(path.resolve(__dirname, 'openhim-import.json')) +) + +const data = JSON.stringify(jsonData) + +const options = { + protocol: 'https:', + hostname: OPENHIM_CORE_SERVICE_NAME, + port: OPENHIM_MEDIATOR_API_PORT, + path: '/metadata', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': data.length, + Authorization: `Basic ${authHeader}` + } +} + +const req = https.request(options, res => { + if (res.statusCode == 401) { + throw new Error(`Incorrect OpenHIM API credentials`) + } + + if (res.statusCode != 201) { + throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`) + } + + console.log('Successfully Imported OpenHIM Config') +}) + +req.on('error', error => { + throw new Error(`Failed to import OpenHIM config: ${error}`) +}) + +req.write(data) +req.end() diff --git a/mpi-mediator/package-metadata.json b/mpi-mediator/package-metadata.json index 3bfb2ce1..962e63c5 100644 --- a/mpi-mediator/package-metadata.json +++ b/mpi-mediator/package-metadata.json @@ -17,6 +17,8 @@ "TRUST_SELF_SIGNED": "true", "OPENHIM_USERNAME": "root@openhim.org", "OPENHIM_PASSWORD": "instant101", + "OPENHIM_CORE_SERVICE_NAME": "openhim-core", + "OPENHIM_MEDIATOR_API_PORT": 8080, "REGISTER_MEDIATOR": "true", "MPI_CLIENT_ID": "fiddler", "MPI_CLIENT_SECRET": "fiddler", @@ -30,6 +32,7 @@ "KAFKA_ERROR_TOPIC": "errors", "FHIR_DATASTORE_PROTOCOL": "http", "FHIR_DATASTORE_HOST": "hapi-fhir", - "FHIR_DATASTORE_PORT": 8080 + "FHIR_DATASTORE_PORT": 8080, + "DISABLE_VALIDATION": "false" } } diff --git a/mpi-mediator/swarm.sh b/mpi-mediator/swarm.sh index f71c77ce..8f1989ac 100644 --- a/mpi-mediator/swarm.sh +++ b/mpi-mediator/swarm.sh @@ -49,10 +49,13 @@ function initialize_package() { log error "Failed to deploy package" exit 1 } + docker::deploy_config_importer "$COMPOSE_FILE_PATH/importer/docker-compose.config.yml" "mpi-mediator-config-importer" "mpi-mediator" } function destroy_package() { - docker::service_destroy "${SERVICE_NAMES}" + docker::service_destroy "${SERVICE_NAMES}" "mpi-mediator-config-importer" + + docker::prune_configs "mpi-mediator" } main() {