From a1115e862c42ae59e94465f4d3b365905fc6f526 Mon Sep 17 00:00:00 2001 From: Dylan Hall Date: Thu, 30 Nov 2023 16:12:56 -0500 Subject: [PATCH] Backend job to start up sessions on HL7 validator wrapper (#406) * FI-2234: starting point for a backend job that starts a validator session * FI-2234: migrate job to start via boot process * FI-2234: rework job to call Validator directly, DRY * Fix variable in error message * Add custom dockerfile for fhir_resource_validator to load SSL certs * Inherit dockerfile CMD from parent, don't just copy&paste it --- Dockerfile.fhir_resource_validator | 10 +++++++++ docker-compose.background.yml | 10 ++++++++- lib/inferno/config/boot/validator.rb | 19 ++++++++++++++++ lib/inferno/dsl/fhir_resource_validation.rb | 1 + lib/inferno/jobs.rb | 1 + lib/inferno/jobs/invoke_validator_session.rb | 23 ++++++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.fhir_resource_validator create mode 100644 lib/inferno/config/boot/validator.rb create mode 100644 lib/inferno/jobs/invoke_validator_session.rb diff --git a/Dockerfile.fhir_resource_validator b/Dockerfile.fhir_resource_validator new file mode 100644 index 000000000..8fdab5547 --- /dev/null +++ b/Dockerfile.fhir_resource_validator @@ -0,0 +1,10 @@ +FROM markiantorno/validator-wrapper + +USER root +# Java certs need to be installed as root, so switch to that user for this step only +# (the image does not contain 'sudo') +RUN wget https://gitlab.mitre.org/mitre-scripts/mitre-pki/-/raw/master/tool_scripts/install_certs.sh -O - | MODE=java sh + +USER $APPLICATION_USER + +# CMD is inherited from parent image as long as we don't override it or ENTRYPOINT diff --git a/docker-compose.background.yml b/docker-compose.background.yml index c03de0b16..41c6cf003 100644 --- a/docker-compose.background.yml +++ b/docker-compose.background.yml @@ -32,6 +32,14 @@ services: # the section in nginx.background.conf need to be uncommented # hl7_validator_service: # image: markiantorno/validator-wrapper + # # If running on the MITRE network, comment out the "image" line above + # # and uncomment the "build" section below + # # build: + # # context: . + # # dockerfile: Dockerfile.fhir_resource_validator # # Update this path to match your directory structure # volumes: - # - ./igs:/home/igs \ No newline at end of file + # - ./igs:/home/igs + # # To let the service share your local FHIR package cache, + # # uncomment the below line + # # - ~/.fhir:/home/ktor/.fhir \ No newline at end of file diff --git a/lib/inferno/config/boot/validator.rb b/lib/inferno/config/boot/validator.rb new file mode 100644 index 000000000..0e4b252b9 --- /dev/null +++ b/lib/inferno/config/boot/validator.rb @@ -0,0 +1,19 @@ +Inferno::Application.boot(:validator) do + init do + use :suites + + # This process should only run once, to start one job per validator, + # so skipping it on workers will start it only once from the "web" process + next if Sidekiq.server? + + Inferno::Repositories::TestSuites.new.all.each do |suite| + suite.fhir_validators.each do |name, validators| + validators.each_with_index do |validator, index| + if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator + Inferno::Jobs.perform(Inferno::Jobs::InvokeValidatorSession, suite.id, name.to_s, index) + end + end + end + end + end +end diff --git a/lib/inferno/dsl/fhir_resource_validation.rb b/lib/inferno/dsl/fhir_resource_validation.rb index 3d9d5bb03..86fbd0526 100644 --- a/lib/inferno/dsl/fhir_resource_validation.rb +++ b/lib/inferno/dsl/fhir_resource_validation.rb @@ -27,6 +27,7 @@ def self.included(klass) class Validator attr_reader :requirements + attr_accessor :session_id # @private def initialize(requirements = nil, &) diff --git a/lib/inferno/jobs.rb b/lib/inferno/jobs.rb index 350540028..ece844a51 100644 --- a/lib/inferno/jobs.rb +++ b/lib/inferno/jobs.rb @@ -2,6 +2,7 @@ require_relative 'jobs/execute_test_run' require_relative 'jobs/resume_test_run' +require_relative 'jobs/invoke_validator_session' module Inferno module Jobs diff --git a/lib/inferno/jobs/invoke_validator_session.rb b/lib/inferno/jobs/invoke_validator_session.rb new file mode 100644 index 000000000..314017e21 --- /dev/null +++ b/lib/inferno/jobs/invoke_validator_session.rb @@ -0,0 +1,23 @@ +module Inferno + module Jobs + class InvokeValidatorSession + include Sidekiq::Worker + + def perform(suite_id, validator_name, validator_index) + suite = Inferno::Repositories::TestSuites.new.find suite_id + validator = suite.fhir_validators[validator_name.to_sym][validator_index] + + response_body = validator.validate(FHIR::Patient.new, 'http://hl7.org/fhir/StructureDefinition/Patient') + + if response_body.start_with? '{' + res = JSON.parse(response_body) + session_id = res['sessionId'] + # TODO: (FI-2311) store this session ID so it can be referenced as needed + validator.session_id = session_id + else + Inferno::Application['logger'].error("InvokeValidatorSession - error from validator: #{response_body}") + end + end + end + end +end