Skip to content

Commit

Permalink
Merge branch 'feature/docker-revision' into feature/eds-revolution
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneNuts committed Oct 19, 2023
2 parents 2bd1a26 + 6ac9f55 commit 6fd8516
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,84 @@
package it.finanze.sanita.fse2.ms.gtw.rulesmanager.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;

import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.DictionaryCFG;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.EngineCFG;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.FhirStructuresCFG;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.eds.changeset.impl.TerminologyCFG;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.exceptions.eds.EdsDbException;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.repository.IExecutorRepo;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.scheduler.executors.impl.DictionaryExecutor;
import it.finanze.sanita.fse2.ms.gtw.rulesmanager.scheduler.executors.impl.EnginesExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;

@Profile(value = Constants.Profile.DOCKER)
import static it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.Constants.Profile.DOCKER;

@Profile(value = DOCKER)
@Configuration
@Slf4j
public class DockerSetup {

// Executors
@Autowired
private EnginesExecutor engineExecutors;
private EnginesExecutor engineExecutor;

@Autowired
private IExecutorRepo executorRepo;

private DictionaryExecutor dictionaryExecutor;

// Data-layer
@Autowired
private FhirStructuresCFG fhirStructuresCFG;
private IExecutorRepo repository;

// Configurations
@Autowired
private FhirStructuresCFG transforms;

@Autowired
private EngineCFG engineCFG;
private EngineCFG engine;

@Autowired
private DictionaryCFG dictionary;

@Autowired
private TerminologyCFG terminology;

@EventListener(value = ApplicationStartedEvent.class)
public void dockerInit() throws EdsDbException {
log.info("Docker init engines start");
executorRepo.drop(engineCFG.getProduction());
log.info("Delete collection engine production");
executorRepo.clone(fhirStructuresCFG.getProduction(), fhirStructuresCFG.getStaging());
engineExecutors.execute();
executorRepo.drop(fhirStructuresCFG.getStaging());
log.info("Delete collection transform-staging");
public void init() throws EdsDbException {
log.info("[DOCKER] Setup has started");
setupEngine();
setupDictionary();
log.info("[DOCKER] Setup has finished");
}


private void setupEngine() throws EdsDbException {
log.info("[DOCKER] Starting docker-routine to initialize engine");
repository.drop(engine.getProduction());
log.info("[DOCKER] Clean-up previous engines, if they exist");
repository.clone(transforms.getProduction(), transforms.getStaging());
log.info("[DOCKER] Spawning engine ...");
engineExecutor.execute();
log.info("[DOCKER] Engine spawned!");
repository.drop(transforms.getStaging());
repository.drop(engine.getBackup());
log.info("[DOCKER] Cleaning-up");
}

private void setupDictionary() throws EdsDbException {
log.info("[DOCKER] Starting docker-routine to initialize dictionary");
repository.drop(dictionary.getProduction());
log.info("[DOCKER] Clean-up previous dictionaries, if they exist");
repository.clone(terminology.getProduction(), terminology.getStaging());
log.info("[DOCKER] Creating dictionaries ...");
dictionaryExecutor.execute();
log.info("[DOCKER] Dictionaries created!");
repository.drop(terminology.getStaging());
repository.drop(dictionary.getBackup());
log.info("[DOCKER] Cleaning-up");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class Schematron {
@JsonProperty
private String version;
@JsonProperty
private String system;
@JsonProperty
private String templateIdRoot;
@JsonProperty
private Date lastUpdateDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class SchematronETY {
public static final String FIELD_FILENAME = "name_schematron";
public static final String FIELD_CONTENT = "content_schematron";
public static final String FIELD_VERSION = "version";
public static final String FIELD_ROOT = "template_id_root";
public static final String FIELD_SYSTEM = "system";
public static final String FIELD_ROOT = "template_id_root";
public static final String FIELD_LAST_UPDATE = "last_update_date";
public static final String FIELD_LAST_SYNC = "last_sync";
public static final String FIELD_DELETED = "deleted";
Expand All @@ -47,6 +48,8 @@ public class SchematronETY {
private String templateIdRoot;
@Field(name = FIELD_VERSION)
private String version;
@Field(name = FIELD_SYSTEM)
private String system;
@Field(name = FIELD_LAST_UPDATE)
private Date lastUpdateDate;
@Field(name = FIELD_LAST_SYNC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ public Document getUpsertQuery(SchematronDTO dto) {
// Get data
SchematronDTO.Schematron schematron = dto.getDocument();
// Create
return new org.bson.Document()
Document doc = new Document()
.append(FIELD_ID, new ObjectId(schematron.getId()))
.append(FIELD_FILENAME, schematron.getName())
.append(FIELD_CONTENT, new Binary(StringUtility.decodeBase64(schematron.getContent())))
.append(FIELD_VERSION, schematron.getVersion())
.append(FIELD_SYSTEM, schematron.getSystem())
.append(FIELD_ROOT, schematron.getTemplateIdRoot())
.append(FIELD_LAST_UPDATE, schematron.getLastUpdateDate())
.append(FIELD_DELETED, false);

if(schematron.getSystem() == null) doc.remove(FIELD_SYSTEM);

return doc;
}

/**
Expand Down Expand Up @@ -80,6 +85,7 @@ public Document getComparatorQuery(Document doc) {
.append(FIELD_CONTENT, doc.get(FIELD_CONTENT, Binary.class))
.append(FIELD_VERSION, doc.getString(FIELD_VERSION))
.append(FIELD_ROOT, doc.getString(FIELD_ROOT))
.append(FIELD_SYSTEM, doc.getString(FIELD_SYSTEM))
.append(FIELD_LAST_UPDATE, doc.getDate(FIELD_LAST_UPDATE))
.append(FIELD_LAST_SYNC, doc.getDate(FIELD_LAST_SYNC))
.append(FIELD_DELETED, doc.getBoolean(FIELD_DELETED));
Expand Down
25 changes: 13 additions & 12 deletions src/main/resources/application-docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ server.port=8011
management.server.port=8011

### MONGODB ###
data.mongodb.uri=mongodb://mongoadmin:[email protected]:27888/fse
data.mongodb.uri=mongodb://mongoadmin:secret@mongo:27017
data.mongodb.schema-name=FSE_GTW

### EDS CLIENT (REST) ###
eds.rest.secured=false
Expand All @@ -18,7 +19,7 @@ log.output.format=console
log.level=trace
log.kafka-log.enable=true
kafka.log.base-topic=MDS-SA-0004_FU_001_LOG
kafka.bootstrap-servers=host.docker.internal:29092
kafka.bootstrap-servers=kafka:29092
spring.sleuth.messaging.kafka.enabled=false
kafka.properties.security.protocol=PLAINTEXT
kafka.properties.sasl.mechanism=PLAINTEXT
Expand All @@ -28,17 +29,17 @@ kafka.properties.ssl.truststore.password=PLAINTEXT
kafka.enablessl=false

### EDS CLIENT (CHANGESET) ###
eds.changeset.schema.status=http://host.docker.internal:9100/v1/changeset/schema/status
eds.changeset.schema.data=http://host.docker.internal:9100/v1/schema/id/
eds.changeset.schema.status=http://it-fse-srv-syntax-rules-manager:9100/v1/changeset/schema/status
eds.changeset.schema.data=http://it-fse-srv-syntax-rules-manager:9100/v1/schema/id/
# Schematron
eds.changeset.schematron.status=http://host.docker.internal:9085/v1/changeset/schematron/status
eds.changeset.schematron.data=http://host.docker.internal:9085/v1/schematron/id/
eds.changeset.schematron.status=http://it-fse-srv-semantic-rules-manager:9085/v1/changeset/schematron/status
eds.changeset.schematron.data=http://it-fse-srv-semantic-rules-manager:9085/v1/schematron/id/
# Fhir Structures
eds.changeset.fhir.status=http://host.docker.internal:9086/v1/changeset/transform/status
eds.changeset.fhir.data=http://host.docker.internal:9086/v1/transform/id/
eds.changeset.fhir.status=http://it-fse-srv-fhir:9086/v1/changeset/transform/status
eds.changeset.fhir.data=http://it-fse-srv-fhir:9086/v1/transform/id/
# Terminology (Chunked)
eds.changeset.terminology.chunks.status=http://host.docker.internal:9088/v1/changeset/terminology/chunks
eds.changeset.terminology.chunks.ins=http://host.docker.internal:9088/v1/changeset/terminology/chunks/ins
eds.changeset.terminology.chunks.del=http://host.docker.internal:9088/v1/changeset/terminology/chunks/del
eds.changeset.terminology.chunks.status=http://it-fse-srv-dictionary:9088/v1/changeset/terminology/chunks
eds.changeset.terminology.chunks.ins=http://it-fse-srv-dictionary:9088/v1/changeset/terminology/chunks/ins
eds.changeset.terminology.chunks.del=http://it-fse-srv-dictionary:9088/v1/changeset/terminology/chunks/del

ms.url.gtw-config=http://host.docker.internal:8018
ms.url.gtw-config=http://it-fse-gtw-config:8018

0 comments on commit 6fd8516

Please sign in to comment.