From 2327668a219e37938d2a7955413d0c50016a1e8e Mon Sep 17 00:00:00 2001 From: Fotis Soldatos <fsoldatos@ubitech.eu> Date: Wed, 27 Jul 2022 15:55:27 +0300 Subject: [PATCH] feat(policy): introduce ServiceService & ServiceGateway interfaces --- .../policy/service/ServiceGateway.java | 26 ++++++++++ .../policy/service/ServiceGatewayImpl.java | 50 +++++++++++++++++++ .../policy/service/ServiceService.java | 26 ++++++++++ .../policy/service/ServiceServiceImpl.java | 39 +++++++++++++++ src/policy/target/kubernetes/kubernetes.yml | 28 +++++------ 5 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 src/policy/src/main/java/eu/teraflow/policy/service/ServiceGateway.java create mode 100644 src/policy/src/main/java/eu/teraflow/policy/service/ServiceGatewayImpl.java create mode 100644 src/policy/src/main/java/eu/teraflow/policy/service/ServiceService.java create mode 100644 src/policy/src/main/java/eu/teraflow/policy/service/ServiceServiceImpl.java diff --git a/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGateway.java b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGateway.java new file mode 100644 index 000000000..d8b338f4f --- /dev/null +++ b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGateway.java @@ -0,0 +1,26 @@ +/* +* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package eu.teraflow.policy.service; + +import eu.teraflow.policy.context.model.Service; +import eu.teraflow.policy.context.model.ServiceId; +import io.smallrye.mutiny.Uni; + +public interface ServiceGateway { + + Uni<ServiceId> updateService(Service service); +} diff --git a/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGatewayImpl.java b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGatewayImpl.java new file mode 100644 index 000000000..b69994ce4 --- /dev/null +++ b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceGatewayImpl.java @@ -0,0 +1,50 @@ +/* +* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package eu.teraflow.policy.service; + +import eu.teraflow.policy.Serializer; +import eu.teraflow.policy.context.model.Service; +import eu.teraflow.policy.context.model.ServiceId; +import io.quarkus.grpc.GrpcClient; +import io.smallrye.mutiny.Uni; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import service.MutinyServiceServiceGrpc.MutinyServiceServiceStub; + +@ApplicationScoped +public class ServiceGatewayImpl implements ServiceGateway { + + @GrpcClient("service") + MutinyServiceServiceStub streamingDelegateService; + + private final Serializer serializer; + + @Inject + public ServiceGatewayImpl(Serializer serializer) { + this.serializer = serializer; + } + + @Override + public Uni<ServiceId> updateService(Service service) { + final var serializedService = serializer.serialize(service); + + return streamingDelegateService + .updateService(serializedService) + .onItem() + .transform(serializer::deserialize); + } +} diff --git a/src/policy/src/main/java/eu/teraflow/policy/service/ServiceService.java b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceService.java new file mode 100644 index 000000000..e6ab0871f --- /dev/null +++ b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceService.java @@ -0,0 +1,26 @@ +/* +* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package eu.teraflow.policy.service; + +import eu.teraflow.policy.context.model.Service; +import eu.teraflow.policy.context.model.ServiceId; +import io.smallrye.mutiny.Uni; + +public interface ServiceService { + + Uni<ServiceId> updateService(Service service); +} diff --git a/src/policy/src/main/java/eu/teraflow/policy/service/ServiceServiceImpl.java b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceServiceImpl.java new file mode 100644 index 000000000..921560e0f --- /dev/null +++ b/src/policy/src/main/java/eu/teraflow/policy/service/ServiceServiceImpl.java @@ -0,0 +1,39 @@ +/* +* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package eu.teraflow.policy.service; + +import eu.teraflow.policy.context.model.Service; +import eu.teraflow.policy.context.model.ServiceId; +import io.smallrye.mutiny.Uni; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +@ApplicationScoped +public class ServiceServiceImpl implements ServiceService { + + private final ServiceGateway serviceGateway; + + @Inject + public ServiceServiceImpl(ServiceGateway serviceGateway) { + this.serviceGateway = serviceGateway; + } + + @Override + public Uni<ServiceId> updateService(Service service) { + return serviceGateway.updateService(service); + } +} diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml index 273778787..d70d05ad9 100644 --- a/src/policy/target/kubernetes/kubernetes.yml +++ b/src/policy/target/kubernetes/kubernetes.yml @@ -3,20 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - app.quarkus.io/commit-id: 57e16fed85037f2415bac3b1a55997ac4967fd99 - app.quarkus.io/build-timestamp: 2022-07-27 - 11:40:31 +0000 + app.quarkus.io/commit-id: 4a11d9130e05e969e9370636484943e1fe2f8bd1 + app.quarkus.io/build-timestamp: 2022-07-27 - 12:54:10 +0000 labels: app.kubernetes.io/name: policyservice app: policyservice name: policyservice spec: ports: - - name: http - port: 8080 - targetPort: 8080 - name: grpc port: 6060 targetPort: 6060 + - name: http + port: 8080 + targetPort: 8080 selector: app.kubernetes.io/name: policyservice type: ClusterIP @@ -25,8 +25,8 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - app.quarkus.io/commit-id: 57e16fed85037f2415bac3b1a55997ac4967fd99 - app.quarkus.io/build-timestamp: 2022-07-27 - 11:40:31 +0000 + app.quarkus.io/commit-id: 4a11d9130e05e969e9370636484943e1fe2f8bd1 + app.quarkus.io/build-timestamp: 2022-07-27 - 12:54:10 +0000 labels: app: policyservice app.kubernetes.io/name: policyservice @@ -39,8 +39,8 @@ spec: template: metadata: annotations: - app.quarkus.io/commit-id: 57e16fed85037f2415bac3b1a55997ac4967fd99 - app.quarkus.io/build-timestamp: 2022-07-27 - 11:40:31 +0000 + app.quarkus.io/commit-id: 4a11d9130e05e969e9370636484943e1fe2f8bd1 + app.quarkus.io/build-timestamp: 2022-07-27 - 12:54:10 +0000 labels: app: policyservice app.kubernetes.io/name: policyservice @@ -51,12 +51,12 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - - name: MONITORING_SERVICE_HOST - value: monitoringservice - name: CONTEXT_SERVICE_HOST value: contextservice - name: SERVICE_SERVICE_HOST value: serviceservice + - name: MONITORING_SERVICE_HOST + value: monitoringservice image: registry.gitlab.com/teraflow-h2020/controller/policy:0.1.0 imagePullPolicy: Always livenessProbe: @@ -71,12 +71,12 @@ spec: timeoutSeconds: 10 name: policyservice ports: - - containerPort: 8080 - name: http - protocol: TCP - containerPort: 6060 name: grpc protocol: TCP + - containerPort: 8080 + name: http + protocol: TCP readinessProbe: failureThreshold: 3 httpGet: -- GitLab