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 0000000000000000000000000000000000000000..d8b338f4fb8f12bd77749529a92f920c525af5b7 --- /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 0000000000000000000000000000000000000000..b69994ce42c81a0b52bec02b34ac5a4572bfe800 --- /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 0000000000000000000000000000000000000000..e6ab0871f0e5f7d8392cc6a3358b584e11911a6a --- /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 0000000000000000000000000000000000000000..921560e0f3d1805d9307d73fa7942ceeb451fb1d --- /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 273778787a08fae57ed9282d075950041fc2f010..d70d05ad91cface20dd5ad1fc15ec1578a0767ca 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: