Skip to content

Commit

Permalink
Merge pull request #452 from medizininformatik-initiative/451-more-lo…
Browse files Browse the repository at this point in the history
…gs-for-transfer-observability

More Logs for CDA Transfer
  • Loading branch information
knoppiks authored Dec 9, 2024
2 parents 997465e + a40d0c6 commit 1128ee2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -39,9 +39,8 @@ public DefaultTransferProcessRunner(

@Override
public String start(TransferProcessDefinition process, List<String> pids) {
var processId = UUID.randomUUID().toString();
log.info("Run process with processId: {}", processId);
log.info("Project configuration: {}", asJson(om, process.rawConfig()));
var processId = nanoId(6);
log.info("[Process {}] Created, config: {}", processId, asJson(om, process.rawConfig()));
var transferProcessInstance = new TransferProcessInstance(process, processId, pids);

startOrQueue(processId, transferProcessInstance);
Expand All @@ -56,6 +55,7 @@ private synchronized void startOrQueue(
transferProcessInstance.execute();
instances.put(processId, transferProcessInstance);
} else {
log.info("[Process {}] Queued", processId);
queued.add(transferProcessInstance);
}
}
Expand Down Expand Up @@ -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<ConsentedPatient> selectCohort(List<String> pids) {
Expand Down Expand Up @@ -159,8 +160,9 @@ private Flux<Result> sendBundles(Flux<TransportBundle> 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) {
Expand Down
6 changes: 6 additions & 0 deletions util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<artifactId>jakarta.validation-api</artifactId>
</dependency>

<dependency>
<groupId>com.aventrix.jnanoid</groupId>
<artifactId>jnanoid</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions util/src/main/java/care/smith/fts/util/NanoIdUtils.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
34 changes: 34 additions & 0 deletions util/src/test/java/care/smith/fts/util/NanoIdUtilsTest.java
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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));
}
}

0 comments on commit 1128ee2

Please sign in to comment.