Commit 2327668a authored by Fotis Soldatos's avatar Fotis Soldatos
Browse files

feat(policy): introduce ServiceService & ServiceGateway interfaces

parent 4a11d913
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
/*
* 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);
}
+50 −0
Original line number Diff line number Diff line
/*
* 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);
    }
}
+26 −0
Original line number Diff line number Diff line
/*
* 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);
}
+39 −0
Original line number Diff line number Diff line
/*
* 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);
    }
}
+14 −14
Original line number Diff line number Diff line
@@ -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: