From c6b44fa03cfdc8113c239f9ee67db8fa25dcbaf4 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Thu, 5 Dec 2024 14:28:18 +0100 Subject: [PATCH 1/2] Add More Logs for Transfer Process --- .../smith/fts/cda/DefaultTransferProcessRunner.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java b/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java index 35838fa5..f4c7f065 100644 --- a/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java +++ b/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java @@ -40,8 +40,7 @@ public DefaultTransferProcessRunner( @Override public String start(TransferProcessDefinition process, List pids) { var processId = UUID.randomUUID().toString(); - log.info("Run process with processId: {}", processId); - log.info("Project configuration: {}", asJson(om, process.rawConfig())); + log.info("[Process {}] Created, config: {}", processId, asJson(om, process.rawConfig())); var transferProcessInstance = new TransferProcessInstance(process, processId, pids); startOrQueue(processId, transferProcessInstance); @@ -56,6 +55,7 @@ private synchronized void startOrQueue( transferProcessInstance.execute(); instances.put(processId, transferProcessInstance); } else { + log.info("[Process {}] Queued", processId); queued.add(transferProcessInstance); } } @@ -126,9 +126,10 @@ public void execute() { .transform(this::selectData) .transform(this::deidentify) .transform(this::sendBundles) - .doOnComplete(this::updateStatus) + .doOnComplete(this::onComplete) .doOnComplete(DefaultTransferProcessRunner.this::onComplete) .subscribe(); + log.info("[Process {}] Started", processId()); } private Flux selectCohort(List pids) { @@ -159,8 +160,9 @@ private Flux sendBundles(Flux deidentification) { .onErrorContinue((e, r) -> status.updateAndGet(TransferProcessStatus::incSkippedBundles)); } - private void updateStatus() { - status.updateAndGet(s -> s.phase() != Phase.FATAL ? checkCompletion(s) : s); + private void onComplete() { + var status = this.status.updateAndGet(s -> s.phase() != Phase.FATAL ? checkCompletion(s) : s); + log.info("[Process {}] Finished with: {}", processId(), status.phase()); } private TransferProcessStatus checkCompletion(TransferProcessStatus s) { From a40d0c604453c9d37167f6ce1f271b9919911f6d Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Thu, 5 Dec 2024 14:29:13 +0100 Subject: [PATCH 2/2] Use NanoID for Log Readability --- .../fts/cda/DefaultTransferProcessRunner.java | 4 +-- util/pom.xml | 6 ++++ .../java/care/smith/fts/util/NanoIdUtils.java | 12 +++++++ .../care/smith/fts/util/NanoIdUtilsTest.java | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 util/src/main/java/care/smith/fts/util/NanoIdUtils.java create mode 100644 util/src/test/java/care/smith/fts/util/NanoIdUtilsTest.java diff --git a/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java b/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java index f4c7f065..c3d64035 100644 --- a/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java +++ b/clinical-domain-agent/src/main/java/care/smith/fts/cda/DefaultTransferProcessRunner.java @@ -1,6 +1,7 @@ package care.smith.fts.cda; import static care.smith.fts.util.JsonLogFormatter.asJson; +import static care.smith.fts.util.NanoIdUtils.nanoId; import static java.util.stream.Stream.concat; import care.smith.fts.api.ConsentedPatient; @@ -14,7 +15,6 @@ import java.util.List; import java.util.Map; import java.util.Queue; -import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +39,7 @@ public DefaultTransferProcessRunner( @Override public String start(TransferProcessDefinition process, List pids) { - var processId = UUID.randomUUID().toString(); + var processId = nanoId(6); log.info("[Process {}] Created, config: {}", processId, asJson(om, process.rawConfig())); var transferProcessInstance = new TransferProcessInstance(process, processId, pids); diff --git a/util/pom.xml b/util/pom.xml index 6c3d4b7b..d3e553ed 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -35,6 +35,12 @@ jakarta.validation-api + + com.aventrix.jnanoid + jnanoid + 2.0.0 + + org.junit.jupiter junit-jupiter diff --git a/util/src/main/java/care/smith/fts/util/NanoIdUtils.java b/util/src/main/java/care/smith/fts/util/NanoIdUtils.java new file mode 100644 index 00000000..92365db4 --- /dev/null +++ b/util/src/main/java/care/smith/fts/util/NanoIdUtils.java @@ -0,0 +1,12 @@ +package care.smith.fts.util; + +import static com.aventrix.jnanoid.jnanoid.NanoIdUtils.DEFAULT_ALPHABET; +import static com.aventrix.jnanoid.jnanoid.NanoIdUtils.DEFAULT_NUMBER_GENERATOR; +import static com.aventrix.jnanoid.jnanoid.NanoIdUtils.randomNanoId; + +public interface NanoIdUtils { + + static String nanoId(int size) { + return randomNanoId(DEFAULT_NUMBER_GENERATOR, DEFAULT_ALPHABET, size); + } +} diff --git a/util/src/test/java/care/smith/fts/util/NanoIdUtilsTest.java b/util/src/test/java/care/smith/fts/util/NanoIdUtilsTest.java new file mode 100644 index 00000000..ebc9b97e --- /dev/null +++ b/util/src/test/java/care/smith/fts/util/NanoIdUtilsTest.java @@ -0,0 +1,34 @@ +package care.smith.fts.util; + +import static care.smith.fts.util.NanoIdUtils.nanoId; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class NanoIdUtilsTest { + private static Stream significantSizes() { + return IntStream.rangeClosed(1, 21).mapToObj(Arguments::of); + } + + @ParameterizedTest(name = "size of {0}") + @MethodSource("significantSizes") + public void idHasSpecifiedSize(int size) { + assertThat(nanoId(size)).hasSize(size); + } + + @Test + public void zeroSizeNotAllowed() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> nanoId(0)); + } + + @Test + public void negativeSizeNotAllowed() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> nanoId(-1)); + } +}