From 38dd99cfa0a4bace25e667b7f89cc87f7def42da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6sle?= Date: Wed, 10 Apr 2024 14:30:02 +0200 Subject: [PATCH] feature: add miranum deployment to the example --- examples/pom.xml | 14 +++++++++ .../single-deployment-unit-example/pom.xml | 12 ++++++++ .../deployment/DeploymentReceiverAdapter.java | 30 +++++++++++++++++++ .../handler/BpmnDeploymentHandler.java | 25 ++++++++++++++++ .../ConfigurationDeploymentHandler.java | 30 +++++++++++++++++++ .../deployment/handler/DeploymentHandler.java | 16 ++++++++++ .../handler/DmnDeploymentHandler.java | 27 +++++++++++++++++ .../handler/FormDeploymentHandler.java | 26 ++++++++++++++++ resources/example-process/miranum.json | 4 +++ resources/example-process/package.json | 3 +- 10 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/DeploymentReceiverAdapter.java create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/BpmnDeploymentHandler.java create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/ConfigurationDeploymentHandler.java create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DeploymentHandler.java create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DmnDeploymentHandler.java create mode 100644 examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/FormDeploymentHandler.java diff --git a/examples/pom.xml b/examples/pom.xml index ec165c8ec..ef69089ac 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -17,7 +17,21 @@ pom + + + + io.miranum.platform + miranum-deployment-server-embedded-starter + ${project.version} + + + io.miranum.platform + miranum-unit-test + ${project.version} + test + + diff --git a/examples/single-deployment-unit-example/pom.xml b/examples/single-deployment-unit-example/pom.xml index 9f7a801d2..4cbee0f0a 100644 --- a/examples/single-deployment-unit-example/pom.xml +++ b/examples/single-deployment-unit-example/pom.xml @@ -16,6 +16,18 @@ org.springframework.boot spring-boot-starter-web + + + io.miranum.platform + miranum-deployment-server-embedded-starter + + + + + io.miranum.platform + miranum-unit-test + test + diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/DeploymentReceiverAdapter.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/DeploymentReceiverAdapter.java new file mode 100644 index 000000000..7d05cebe4 --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/DeploymentReceiverAdapter.java @@ -0,0 +1,30 @@ +package io.miranum.platform.example.adapter.out.deployment; + +import io.miranum.platform.deploymentreceiver.application.DeploymentFailedException; +import io.miranum.platform.deploymentreceiver.application.ports.out.MiranumDeploymentReceiver; +import io.miranum.platform.deploymentreceiver.domain.Deployment; +import io.miranum.platform.example.adapter.out.deployment.handler.DeploymentHandler; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DeploymentReceiverAdapter implements MiranumDeploymentReceiver { + + private final List deploymentHandlers; + + @Override + public void deploy(final Deployment deployment) { + this.deploymentHandlers.stream() + .filter(handler -> handler.isResponsibleFor(deployment.getType())) + .findFirst() + .ifPresentOrElse(handler -> handler.deployArtifact(deployment), () -> { + throw new DeploymentFailedException("No handler found for deployment type " + deployment.getType()); + }); + } + +} diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/BpmnDeploymentHandler.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/BpmnDeploymentHandler.java new file mode 100644 index 000000000..7c9acec86 --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/BpmnDeploymentHandler.java @@ -0,0 +1,25 @@ +package io.miranum.platform.example.adapter.out.deployment.handler; + +import io.miranum.platform.deploymentreceiver.application.DeploymentFailedException; +import io.miranum.platform.deploymentreceiver.domain.Deployment; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class BpmnDeploymentHandler implements DeploymentHandler { + @Override + public boolean isResponsibleFor(final String artifactType) { + return artifactType.equalsIgnoreCase("bpmn"); + } + + @Override + public void deployArtifact(final Deployment artifact) throws DeploymentFailedException { + // TODO implement me + log.info("Deploy file {} of type {} to namespace {} with tags {}", + artifact.getFilename(), artifact.getType(), artifact.getNamespace(), artifact.getTags()); + } + +} diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/ConfigurationDeploymentHandler.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/ConfigurationDeploymentHandler.java new file mode 100644 index 000000000..a29966883 --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/ConfigurationDeploymentHandler.java @@ -0,0 +1,30 @@ +package io.miranum.platform.example.adapter.out.deployment.handler; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.miranum.platform.deploymentreceiver.application.DeploymentFailedException; +import io.miranum.platform.deploymentreceiver.domain.Deployment; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ConfigurationDeploymentHandler implements DeploymentHandler { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public boolean isResponsibleFor(final String artifactType) { + return artifactType.equalsIgnoreCase("config"); + } + + @Override + public void deployArtifact(final Deployment artifact) throws DeploymentFailedException { + // TODO implement me + log.info("Deploy file {} of type {} to namespace {} with tags {}", + artifact.getFilename(), artifact.getType(), artifact.getNamespace(), artifact.getTags()); + } + +} diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DeploymentHandler.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DeploymentHandler.java new file mode 100644 index 000000000..85681655d --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DeploymentHandler.java @@ -0,0 +1,16 @@ +package io.miranum.platform.example.adapter.out.deployment.handler; + +import io.miranum.platform.deploymentreceiver.application.DeploymentFailedException; +import io.miranum.platform.deploymentreceiver.domain.Deployment; + +/** + * Handle deployment for specific types + */ +public interface DeploymentHandler { + + boolean isResponsibleFor(String artifactType); + + void deployArtifact(final Deployment artifact) throws DeploymentFailedException; + + +} diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DmnDeploymentHandler.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DmnDeploymentHandler.java new file mode 100644 index 000000000..2e0f54416 --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/DmnDeploymentHandler.java @@ -0,0 +1,27 @@ +package io.miranum.platform.example.adapter.out.deployment.handler; + + +import io.miranum.platform.deploymentreceiver.application.DeploymentFailedException; +import io.miranum.platform.deploymentreceiver.domain.Deployment; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DmnDeploymentHandler implements DeploymentHandler { + + @Override + public boolean isResponsibleFor(final String artifactType) { + return artifactType.equalsIgnoreCase("dmn"); + } + + @Override + public void deployArtifact(Deployment artifact) throws DeploymentFailedException { + // TODO implement me + log.info("Deploy file {} of type {} to namespace {} with tags {}", + artifact.getFilename(), artifact.getType(), artifact.getNamespace(), artifact.getTags()); + } + +} diff --git a/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/FormDeploymentHandler.java b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/FormDeploymentHandler.java new file mode 100644 index 000000000..10d570a3d --- /dev/null +++ b/examples/single-deployment-unit-example/src/main/java/io/miranum/platform/example/adapter/out/deployment/handler/FormDeploymentHandler.java @@ -0,0 +1,26 @@ +package io.miranum.platform.example.adapter.out.deployment.handler; + + +import io.miranum.platform.deploymentreceiver.domain.Deployment; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class FormDeploymentHandler implements DeploymentHandler { + + @Override + public boolean isResponsibleFor(final String artifactType) { + return artifactType.equalsIgnoreCase("form"); + } + + @Override + public void deployArtifact(final Deployment artifact) { + // TODO implement me + log.info("Deploy file {} of type {} to namespace {} with tags {}", + artifact.getFilename(), artifact.getType(), artifact.getNamespace(), artifact.getTags()); + } + +} diff --git a/resources/example-process/miranum.json b/resources/example-process/miranum.json index f0ce9aa15..75c3f91ee 100644 --- a/resources/example-process/miranum.json +++ b/resources/example-process/miranum.json @@ -19,6 +19,10 @@ { "name": "rest", "url": "http://localhost:9001" + }, + { + "name": "singleDeploymentUnit", + "url": "http://localhost:8083" } ] } diff --git a/resources/example-process/package.json b/resources/example-process/package.json index fe792473f..5ce80816b 100644 --- a/resources/example-process/package.json +++ b/resources/example-process/package.json @@ -5,7 +5,8 @@ "scripts": { "deploy:all": "npm run deploy:embedded && npm run deploy:rest", "deploy:embedded": "npx @miragon/miranum-cli deploy -d . -t embedded", - "deploy:rest": "npx @miragon/miranum-cli deploy -d . -t rest" + "deploy:rest": "npx @miragon/miranum-cli deploy -d . -t rest", + "deploy:singleDeploymentUnit": "npx @miragon/miranum-cli deploy -d . -t singleDeploymentUnit" }, "author": "lmoesle", "license": "MIT",