From 460fbdbcc584451c4aa4162a2fc84f4d03293d0b Mon Sep 17 00:00:00 2001 From: fsoldatos <fsoldatos@ubitech.eu> Date: Mon, 15 Nov 2021 12:54:26 +0200 Subject: [PATCH] feat(automation): implement readiness probe funtionality --- src/automation/.env.example | 4 ++-- .../teraflow/automation/ContextSubscriber.java | 11 ++++++++++- .../automation/SimpleLivenessCheck.java | 2 +- .../automation/SimpleReadinessCheck.java | 17 +++++++++++++++++ .../src/main/resources/application.yaml | 4 ++-- .../target/kubernetes/kubernetes.yml | 18 +++++++++--------- 6 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 src/automation/src/main/java/eu/teraflow/automation/SimpleReadinessCheck.java diff --git a/src/automation/.env.example b/src/automation/.env.example index 35c4e0b97..98c75623c 100644 --- a/src/automation/.env.example +++ b/src/automation/.env.example @@ -1,5 +1,5 @@ # Define the host for the Context Service -quarkus.kubernetes.env.vars.context-service-host=context +quarkus.kubernetes.env.vars.context-service-host=ContextService # Define the host for the Device Service -quarkus.kubernetes.env.vars.device-service-host=device \ No newline at end of file +quarkus.kubernetes.env.vars.device-service-host=DeviceService \ No newline at end of file diff --git a/src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java b/src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java index cedbce546..195634d00 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java +++ b/src/automation/src/main/java/eu/teraflow/automation/ContextSubscriber.java @@ -4,6 +4,7 @@ import eu.teraflow.automation.context.ContextService; import eu.teraflow.automation.device.model.DeviceEvent; import io.quarkus.runtime.StartupEvent; import io.smallrye.mutiny.Multi; +import java.time.Duration; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; import javax.inject.Inject; @@ -29,7 +30,15 @@ public class ContextSubscriber { } public void listenForDeviceEvents() { - Multi<DeviceEvent> deviceEventsMulti = contextService.getDeviceEvents(); + + Multi<DeviceEvent> deviceEventsMulti = + contextService + .getDeviceEvents() + .onFailure() + .retry() + .withBackOff(Duration.ofSeconds(1)) + .withJitter(0.2) + .atMost(10); deviceEventsMulti .onItem() diff --git a/src/automation/src/main/java/eu/teraflow/automation/SimpleLivenessCheck.java b/src/automation/src/main/java/eu/teraflow/automation/SimpleLivenessCheck.java index ee4686b63..28c896fbd 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/SimpleLivenessCheck.java +++ b/src/automation/src/main/java/eu/teraflow/automation/SimpleLivenessCheck.java @@ -11,6 +11,6 @@ public class SimpleLivenessCheck implements HealthCheck { @Override public HealthCheckResponse call() { - return HealthCheckResponse.up("Automation Service"); + return HealthCheckResponse.up("Automation Service is live"); } } diff --git a/src/automation/src/main/java/eu/teraflow/automation/SimpleReadinessCheck.java b/src/automation/src/main/java/eu/teraflow/automation/SimpleReadinessCheck.java new file mode 100644 index 000000000..e542a3582 --- /dev/null +++ b/src/automation/src/main/java/eu/teraflow/automation/SimpleReadinessCheck.java @@ -0,0 +1,17 @@ +package eu.teraflow.automation; + +import javax.enterprise.context.ApplicationScoped; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.Readiness; + +@Readiness +@ApplicationScoped +public class SimpleReadinessCheck implements HealthCheck { + + @Override + public HealthCheckResponse call() { + + return HealthCheckResponse.up("Automation Service is ready"); + } +} diff --git a/src/automation/src/main/resources/application.yaml b/src/automation/src/main/resources/application.yaml index 2ea1ef12a..8d5ae6ed5 100644 --- a/src/automation/src/main/resources/application.yaml +++ b/src/automation/src/main/resources/application.yaml @@ -38,5 +38,5 @@ quarkus: container-port: 9999 env: vars: - context-service-host: context - device-service-host: device \ No newline at end of file + context-service-host: ContextService + device-service-host: DeviceService \ No newline at end of file diff --git a/src/automation/target/kubernetes/kubernetes.yml b/src/automation/target/kubernetes/kubernetes.yml index 51af1ccf1..73d19dc1f 100644 --- a/src/automation/target/kubernetes/kubernetes.yml +++ b/src/automation/target/kubernetes/kubernetes.yml @@ -3,8 +3,8 @@ apiVersion: v1 kind: Service metadata: annotations: - app.quarkus.io/commit-id: 43db942bd5641ae293df75b65cd1eefd40b8085e - app.quarkus.io/build-timestamp: 2021-11-17 - 06:42:01 +0000 + app.quarkus.io/commit-id: 6b96f471f66e6bb59357856c635f8d7e1ce98a5c + app.quarkus.io/build-timestamp: 2021-11-19 - 15:03:07 +0000 labels: app.kubernetes.io/name: automationservice app.kubernetes.io/version: 0.0.1 @@ -27,8 +27,8 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - app.quarkus.io/commit-id: 43db942bd5641ae293df75b65cd1eefd40b8085e - app.quarkus.io/build-timestamp: 2021-11-17 - 06:42:01 +0000 + app.quarkus.io/commit-id: 6b96f471f66e6bb59357856c635f8d7e1ce98a5c + app.quarkus.io/build-timestamp: 2021-11-19 - 15:03:07 +0000 labels: app: automationservice app.kubernetes.io/name: automationservice @@ -43,8 +43,8 @@ spec: template: metadata: annotations: - app.quarkus.io/commit-id: 43db942bd5641ae293df75b65cd1eefd40b8085e - app.quarkus.io/build-timestamp: 2021-11-17 - 06:42:01 +0000 + app.quarkus.io/commit-id: 6b96f471f66e6bb59357856c635f8d7e1ce98a5c + app.quarkus.io/build-timestamp: 2021-11-19 - 15:03:07 +0000 labels: app: automationservice app.kubernetes.io/name: automationservice @@ -56,10 +56,10 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - - name: CONTEXT_SERVICE_HOST - value: context - name: DEVICE_SERVICE_HOST - value: device + value: DeviceService + - name: CONTEXT_SERVICE_HOST + value: ContextService image: registry.gitlab.com/teraflow-h2020/controller/automation:0.0.1 imagePullPolicy: Always livenessProbe: -- GitLab