Skip to content

Commit

Permalink
♻️ refactor(log-service): Refactor server and log service for docker …
Browse files Browse the repository at this point in the history
…packaging.
  • Loading branch information
sinaci committed Oct 20, 2023
1 parent 925e765 commit 3978ec3
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 95 deletions.
21 changes: 9 additions & 12 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@ version: '3.9'
services:
tofhir-log-server:
image: srdc/tofhir-log-server:latest
container_name: tofhir-log
hostname: tofhir-log
environment:
- APP_CONF_FILE=/tofhir/conf/log-service.conf
container_name: tofhir-log-server
hostname: tofhir-log-server
ports:
- "8086:8086"
networks:
- tofhir-network
volumes:
- './data-ingestion-suite:/tofhir/conf'
- './tofhir-docker-logs:/tofhir/logs'
- './tofhir-docker-logs:/usr/local/tofhir/logs'
tofhir-server:
image: srdc/tofhir-server:latest
container_name: tofhir
hostname: tofhir
environment:
- LOG_SERVER_BASE_URL=http://tofhir-log:8086
- LOG_SERVICE_ENDPOINT=http://tofhir-log-server:8086/tofhir-logs
- FHIR_DEFINITIONS_ENDPOINT=http://onfhir:8080/fhir
- FHIR_REPO_URL=http://onfhir:8080/fhir
- APP_CONF_FILE=/tofhir/conf/application.conf
- APP_CONF_FILE=/usr/local/tofhir/conf/docker/tofhir-server.conf
- CONTEXT_PATH=conf
ports:
- "8085:8085"
networks:
- tofhir-network
volumes:
- './data-ingestion-suite:/tofhir/conf'
- './tofhir-docker-logs:/tofhir/logs'
- './data-integration-suite:/usr/local/tofhir/conf'
- './tofhir-docker-logs:/usr/local/tofhir/logs'
tofhir-web:
image: srdc/tofhir-web:latest
container_name: tofhir-web
Expand All @@ -39,5 +38,3 @@ networks:
tofhir-network:
name: onfhir-network
external: true
volumes:
fhirdb: {}
2 changes: 1 addition & 1 deletion docker/engine/Dockerfile-addJar
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV TOFHIR_HOME /usr/local/tofhir
RUN mkdir -p "$TOFHIR_HOME"
WORKDIR $TOFHIR_HOME

COPY ./tofhir-engine/target/tofhir-standalone.jar .
COPY ./tofhir-engine/target/tofhir-engine-standalone.jar .
COPY ./docker/engine/docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh

Expand Down
2 changes: 1 addition & 1 deletion docker/engine/Dockerfile-buildJar
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV TOFHIR_HOME /usr/local/tofhir
RUN mkdir -p "$TOFHIR_HOME"
WORKDIR $TOFHIR_HOME

COPY --from=builder $TOFHIR_HOME/tofhir-engine/target/tofhir-standalone.jar .
COPY --from=builder $TOFHIR_HOME/tofhir-engine/target/tofhir-engine-standalone.jar .

COPY docker/engine/docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh
Expand Down
4 changes: 2 additions & 2 deletions docker/engine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if [ ! -z "$FHIR_BATCH_SIZE" ]; then
JAVA_CMD+="-Dtofhir.fhir-writer.batch-group-size=$FHIR_BATCH_SIZE "
fi
if [ ! -z "$DB_PATH" ]; then
JAVA_CMD+="-Dtofhir.db=$DB_PATH "
JAVA_CMD+="-Dtofhir.db-path=$DB_PATH "
fi

# Delay the execution for this amount of seconds
Expand All @@ -46,6 +46,6 @@ if [ ! -z "$DELAY_EXECUTION" ]; then
fi

# Finally, tell which jar to run
JAVA_CMD+="tofhir-standalone.jar"
JAVA_CMD+="tofhir-engine-standalone.jar"

eval $JAVA_CMD "$@"
13 changes: 5 additions & 8 deletions docker/log-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
FROM openjdk:11-jre-slim

# Create folders
RUN mkdir -p /tofhir
WORKDIR /tofhir
ENV TOFHIR_HOME /usr/local/tofhir
RUN mkdir -p "$TOFHIR_HOME"
WORKDIR $TOFHIR_HOME

# Add Files
COPY ./tofhir-log-server/target/tofhir-log-server-standalone.jar .
COPY ./docker/log-server/docker-entrypoint.sh .
COPY ./tofhir-log-server/src/main/resources/logback.xml .
RUN chmod +x docker-entrypoint.sh

RUN chmod +x /tofhir/docker-entrypoint.sh

ENTRYPOINT ["/tofhir/docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/log-server/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Execute one of the following commands from the project.root.directory (../../)

docker build -f docker/log-server/Dockerfile -t srdc/tofhir-log-server:latest -t srdc/tofhir-log-server:1.0 .
docker build -f docker/log-server/Dockerfile -t srdc/tofhir-log-server:latest .

41 changes: 34 additions & 7 deletions docker/log-server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
#!/bin/bash
#!/usr/bin/env bash

JAVA_CMD="java -jar "
JAVA_CMD="java -Xms256m -Xmx3g -jar "

# Configure application.conf path
if [ ! -z "$APP_CONF_FILE" ]; then
JAVA_CMD+="-Dconfig.file=$APP_CONF_FILE "
JAVA_CMD+="-Dconfig.file=$APP_CONF_FILE "
fi

# Finally, tell which jar to run
JAVA_CMD+="/tofhir/tofhir-log-server-standalone.jar"
# Configure logback configuration file
if [ ! -z "$LOGBACK_CONF_FILE" ]; then
JAVA_CMD+="-Dlogback.configurationFile=$LOGBACK_CONF_FILE "
fi

# Configure Spark
if [ ! -z "$SPARK_APPNAME" ]; then
JAVA_CMD+="-Dspark.app-name=$SPARK_APPNAME "
fi
if [ ! -z "$SPARK_MASTER" ]; then
JAVA_CMD+="-Dspark.master=$SPARK_MASTER "
fi

# Configure tofhir-server web server
if [ ! -z "$WEBSERVER_HOST" ]; then
JAVA_CMD+="-Dwebserver.host=$WEBSERVER_HOST "
fi
if [ ! -z "$WEBSERVER_PORT" ]; then
JAVA_CMD+="-Dwebserver.port=$WEBSERVER_PORT "
fi
if [ ! -z "$WEBSERVER_BASEURI" ]; then
JAVA_CMD+="-Dwebserver.base-uri=$WEBSERVER_BASEURI "
fi

echo "Running command: $JAVA_CMD"
# Delay the execution for this amount of seconds
if [ ! -z "$DELAY_EXECUTION" ]; then
sleep $DELAY_EXECUTION
fi

# Finally, tell which jar to run
JAVA_CMD+="tofhir-log-server-standalone.jar"

eval $JAVA_CMD
eval $JAVA_CMD "$@"
13 changes: 5 additions & 8 deletions docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
FROM openjdk:11-jre-slim

# Create folders
RUN mkdir -p /tofhir
WORKDIR /tofhir
ENV TOFHIR_HOME /usr/local/tofhir
RUN mkdir -p "$TOFHIR_HOME"
WORKDIR $TOFHIR_HOME

# Add Files
COPY ./tofhir-server/target/tofhir-server-standalone.jar .
COPY ./docker/server/docker-entrypoint.sh .
COPY ./tofhir-server/src/main/resources/logback.xml .
RUN chmod +x docker-entrypoint.sh

RUN chmod +x /tofhir/docker-entrypoint.sh

ENTRYPOINT ["/tofhir/docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/server/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Execute one of the following commands from the project.root.directory (../../)

docker build -f docker/server/Dockerfile -t srdc/tofhir-server:latest -t srdc/tofhir-server:1.0 .
docker build -f docker/server/Dockerfile -t srdc/tofhir-server:latest .

83 changes: 72 additions & 11 deletions docker/server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,84 @@
#!/bin/bash
#!/usr/bin/env bash

JAVA_CMD="java -jar "
JAVA_CMD="java -Xms256m -Xmx3g -jar "

# Configure application.conf path
if [ ! -z "$APP_CONF_FILE" ]; then
JAVA_CMD+="-Dconfig.file=$APP_CONF_FILE "
JAVA_CMD+="-Dconfig.file=$APP_CONF_FILE "
fi

if [ ! -z "$FHIR_REPO_URL" ]; then
JAVA_CMD+="-Dfhir.definitions-fhir-endpoint=$FHIR_REPO_URL "
# Configure logback configuration file
if [ ! -z "$LOGBACK_CONF_FILE" ]; then
JAVA_CMD+="-Dlogback.configurationFile=$LOGBACK_CONF_FILE "
fi

if [ ! -z "$LOG_SERVER_BASE_URL" ]; then
JAVA_CMD+="-webserver.log-server-base-url=$LOG_SERVER_BASE_URL "
# Configure Spark
if [ ! -z "$SPARK_APPNAME" ]; then
JAVA_CMD+="-Dspark.app-name=$SPARK_APPNAME "
fi
if [ ! -z "$SPARK_MASTER" ]; then
JAVA_CMD+="-Dspark.master=$SPARK_MASTER "
fi

# Finally, tell which jar to run
JAVA_CMD+="/tofhir/tofhir-server-standalone.jar"
# Configure toFHIR mapping-related paths
if [ ! -z "$CONTEXT_PATH" ]; then
JAVA_CMD+="-Dtofhir.context-path=$CONTEXT_PATH "
fi
if [ ! -z "$MAPPINGS_FOLDER" ]; then
JAVA_CMD+="-Dtofhir.mappings.repository.folder-path=$MAPPINGS_FOLDER "
fi
if [ ! -z "$SCHEMAS_FOLDER" ]; then
JAVA_CMD+="-Dtofhir.mappings.schemas.repository.folder-path=$SCHEMAS_FOLDER "
fi
if [ ! -z "$MAPPING_JOB" ]; then
JAVA_CMD+="-Dtofhir.mapping-jobs.initial-job-file-path=$MAPPING_JOB "
fi
if [ ! -z "$FHIR_BATCH_SIZE" ]; then
JAVA_CMD+="-Dtofhir.fhir-writer.batch-group-size=$FHIR_BATCH_SIZE "
fi
if [ ! -z "$DB_PATH" ]; then
JAVA_CMD+="-Dtofhir.db-path=$DB_PATH "
fi

echo "Running command: $JAVA_CMD"
# Configure the FHIR endpoint to which this toFHIR can connect to retrieve resource definitions etc.
if [ ! -z "$FHIR_DEFINITIONS_ENDPOINT" ]; then
JAVA_CMD+="-Dfhir.definitions-fhir-endpoint=$FHIR_DEFINITIONS_ENDPOINT "
fi
if [ ! -z "$FHIR_DEFINITIONS_ROOT_URL" ]; then
JAVA_CMD+="-Dfhir.definitions-root-urls=$FHIR_DEFINITIONS_ROOT_URL "
fi
if [ ! -z "$FHIR_DEFINITIONS_PROFILES_PATH" ]; then
JAVA_CMD+="-Dfhir.profiles-path=$FHIR_DEFINITIONS_ROOT_URL "
fi
if [ ! -z "$FHIR_DEFINITIONS_VALUESETS_PATH" ]; then
JAVA_CMD+="-Dfhir.valuesets-path=$FHIR_DEFINITIONS_VALUESETS_PATH "
fi
if [ ! -z "$FHIR_DEFINITIONS_CODESYSTEMS_URL" ]; then
JAVA_CMD+="-Dfhir.codesystems-path=$FHIR_DEFINITIONS_CODESYSTEMS_URL "
fi

# Configure tofhir-server web server
if [ ! -z "$WEBSERVER_HOST" ]; then
JAVA_CMD+="-Dwebserver.host=$WEBSERVER_HOST "
fi
if [ ! -z "$WEBSERVER_PORT" ]; then
JAVA_CMD+="-Dwebserver.port=$WEBSERVER_PORT "
fi
if [ ! -z "$WEBSERVER_BASEURI" ]; then
JAVA_CMD+="-Dwebserver.base-uri=$WEBSERVER_BASEURI "
fi

# Configure log service
if [ ! -z "$LOG_SERVICE_ENDPOINT" ]; then
JAVA_CMD+="-Dlog-service.endpoint=$LOG_SERVICE_ENDPOINT "
fi

# Delay the execution for this amount of seconds
if [ ! -z "$DELAY_EXECUTION" ]; then
sleep $DELAY_EXECUTION
fi

# Finally, tell which jar to run
JAVA_CMD+="tofhir-server-standalone.jar"

eval $JAVA_CMD
eval $JAVA_CMD "$@"
2 changes: 1 addition & 1 deletion tofhir-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>tofhir-standalone</finalName>
<finalName>tofhir-engine-standalone</finalName>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ToFhirEngine(mappingRepository: Option[IFhirMappingCachedRepository] = Non

//Spark configurations
private val sparkConf: SparkConf = ToFhirConfig.createSparkConf

val engineConfig: ToFhirEngineConfig = ToFhirConfig.engineConfig

val sparkSession: SparkSession = SparkSession.builder().config(sparkConf).getOrCreate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object ToFhirConfig {
lazy val sparkAppName: String = Try(sparkConfig.getString("app.name")).getOrElse("AICCELERATE Data Integration Suite")
/** Master url of the Spark cluster */
lazy val sparkMaster: String = Try(sparkConfig.getString("master")).getOrElse("local[4]")

/**
* Default configurations for spark
*/
Expand Down
2 changes: 1 addition & 1 deletion tofhir-log-server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ webserver = {
port = 8086

# Base Uri for server e.g. With this default configuration, the root path of toFHIR server will be http://localhost:8085/tofhir
base-uri = tofhir
base-uri = tofhir-logs

ssl {
# Path to the java keystore for enabling ssl for toFHIR server, use null to disable ssl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class JobEndpoint() extends LazyLogging {
}
}


/**
* Route to get executions of a mapping job
* */
Expand All @@ -59,6 +58,7 @@ class JobEndpoint() extends LazyLogging {

/**
* Route to get execution logs of a mapping job execution
*
* @param projectId
* @param jobId
* @param executionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class ProjectEndpoint() extends LazyLogging {

def route(request: ToFhirRestCall): Route = {
pathPrefix(SEGMENT_PROJECTS) {
pathPrefix(Segment) { projectId: String =>
{
request.projectId = Some(projectId)
jobEndpoint.route(request)
}
}
pathPrefix(Segment) { projectId: String => {
request.projectId = Some(projectId)
jobEndpoint.route(request)
}
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions tofhir-server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ webserver = {
# Base Uri for server e.g. With this default configuration, the root path of toFHIR server will be http://localhost:8085/tofhir
base-uri = tofhir

log-server-base-url = "http://localhost:8086"

ssl {
# Path to the java keystore for enabling ssl for toFHIR server, use null to disable ssl
keystore = null
Expand All @@ -118,6 +116,11 @@ webserver = {
}
}

# The service from where tofhir-server will read the logs.
log-service = {
endpoint = "http://localhost:8086/tofhir-logs"
}

# Spark configurations
spark = {
app.name = "AICCELERATE Data Integration Suite"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.tofhir.server

import io.tofhir.engine.config.ToFhirConfig
import io.tofhir.server.config.WebServerConfig
import io.tofhir.server.config.{LogServiceConfig, WebServerConfig}
import io.tofhir.server.endpoint.ToFhirServerEndpoint
import io.tofhir.server.fhir.FhirDefinitionsConfig

Expand All @@ -11,7 +11,8 @@ object ToFhirServer {

val webServerConfig = new WebServerConfig(actorSystem.settings.config.getConfig("webserver"))
val fhirDefinitionsConfig = new FhirDefinitionsConfig(actorSystem.settings.config.getConfig("fhir"))
val endpoint = new ToFhirServerEndpoint(ToFhirConfig.engineConfig, webServerConfig, fhirDefinitionsConfig)
val logServiceConfig = new LogServiceConfig(actorSystem.settings.config.getConfig("log-service"))
val endpoint = new ToFhirServerEndpoint(ToFhirConfig.engineConfig, webServerConfig, fhirDefinitionsConfig, logServiceConfig)

ToFhirHttpServer.start(endpoint.toFHIRRoute, webServerConfig)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.tofhir.server.config

import com.typesafe.config.Config

import scala.util.Try

class LogServiceConfig(logServiceConfig: Config) {
/** Host name/address to start service on. */
lazy val logServiceEndpoint: String = Try(logServiceConfig.getString("endpoint")).getOrElse("http://localhost:8086/tofhir-log")
}
Loading

0 comments on commit 3978ec3

Please sign in to comment.