Commit 226d1087 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Adapted Compute to common proto folder

- Moved imports from *.proto folder to common.proto folder
- Removed compute's genproto.sh script
- Minor code and linting fixing
- Arranged requirements to accelerate Docker image creation
- Updated Dockerfile
- Arranged GitLab CI/CD pipeline
parent e64a8f9d
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -21,16 +21,17 @@ build compute:
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
    - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    - docker images --filter="dangling=true" --quiet | xargs -r docker rmi
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
@@ -65,6 +66,8 @@ unit test compute:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
+3 −3
Original line number Diff line number Diff line
@@ -15,11 +15,11 @@
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.compute_pb2_grpc import ComputeServiceStub
from common.proto.context_pb2 import (
    AuthenticationResult, Empty, Service, ServiceId, ServiceIdList, ServiceStatus, TeraFlowController)
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string
from compute.proto.compute_pb2_grpc import ComputeServiceStub
from compute.proto.context_pb2 import (
    AuthenticationResult, Empty, Service, ServiceId, ServiceIdList, ServiceStatus, TeraFlowController)

LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15

src/compute/genproto.sh

deleted100755 → 0
+0 −51
Original line number Diff line number Diff line
#!/bin/bash -eu
#
# 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.

# Make folder containing the script the root folder for its execution
cd $(dirname $0)

rm -rf proto/*.py
rm -rf proto/__pycache__
tee proto/__init__.py << EOF > /dev/null
# 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.

EOF

python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto context.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto service.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto compute.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto kpi_sample_types.proto

rm proto/context_pb2_grpc.py
rm proto/service_pb2_grpc.py
rm proto/kpi_sample_types_pb2_grpc.py

sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/context_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/service_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/compute_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/compute_pb2_grpc.py

src/compute/proto/__init__.py

deleted100644 → 0
+0 −14
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.

src/compute/proto/compute_pb2.py

deleted100644 → 0
+0 −118
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: compute.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()


from . import context_pb2 as context__pb2


DESCRIPTOR = _descriptor.FileDescriptor(
  name='compute.proto',
  package='compute',
  syntax='proto3',
  serialized_options=None,
  create_key=_descriptor._internal_create_key,
  serialized_pb=b'\n\rcompute.proto\x12\x07\x63ompute\x1a\rcontext.proto2\x89\x04\n\x0e\x43omputeService\x12P\n\x10\x43heckCredentials\x12\x1b.context.TeraFlowController\x1a\x1d.context.AuthenticationResult\"\x00\x12L\n\x1cGetConnectivityServiceStatus\x12\x12.context.ServiceId\x1a\x16.context.ServiceStatus\"\x00\x12\x43\n\x19\x43reateConnectivityService\x12\x10.context.Service\x1a\x12.context.ServiceId\"\x00\x12\x41\n\x17\x45\x64itConnectivityService\x12\x10.context.Service\x1a\x12.context.ServiceId\"\x00\x12?\n\x19\x44\x65leteConnectivityService\x12\x10.context.Service\x1a\x0e.context.Empty\"\x00\x12L\n GetAllActiveConnectivityServices\x12\x0e.context.Empty\x1a\x16.context.ServiceIdList\"\x00\x12@\n\x1c\x43learAllConnectivityServices\x12\x0e.context.Empty\x1a\x0e.context.Empty\"\x00\x62\x06proto3'
  ,
  dependencies=[context__pb2.DESCRIPTOR,])



_sym_db.RegisterFileDescriptor(DESCRIPTOR)



_COMPUTESERVICE = _descriptor.ServiceDescriptor(
  name='ComputeService',
  full_name='compute.ComputeService',
  file=DESCRIPTOR,
  index=0,
  serialized_options=None,
  create_key=_descriptor._internal_create_key,
  serialized_start=42,
  serialized_end=563,
  methods=[
  _descriptor.MethodDescriptor(
    name='CheckCredentials',
    full_name='compute.ComputeService.CheckCredentials',
    index=0,
    containing_service=None,
    input_type=context__pb2._TERAFLOWCONTROLLER,
    output_type=context__pb2._AUTHENTICATIONRESULT,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='GetConnectivityServiceStatus',
    full_name='compute.ComputeService.GetConnectivityServiceStatus',
    index=1,
    containing_service=None,
    input_type=context__pb2._SERVICEID,
    output_type=context__pb2._SERVICESTATUS,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='CreateConnectivityService',
    full_name='compute.ComputeService.CreateConnectivityService',
    index=2,
    containing_service=None,
    input_type=context__pb2._SERVICE,
    output_type=context__pb2._SERVICEID,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='EditConnectivityService',
    full_name='compute.ComputeService.EditConnectivityService',
    index=3,
    containing_service=None,
    input_type=context__pb2._SERVICE,
    output_type=context__pb2._SERVICEID,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='DeleteConnectivityService',
    full_name='compute.ComputeService.DeleteConnectivityService',
    index=4,
    containing_service=None,
    input_type=context__pb2._SERVICE,
    output_type=context__pb2._EMPTY,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='GetAllActiveConnectivityServices',
    full_name='compute.ComputeService.GetAllActiveConnectivityServices',
    index=5,
    containing_service=None,
    input_type=context__pb2._EMPTY,
    output_type=context__pb2._SERVICEIDLIST,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
  _descriptor.MethodDescriptor(
    name='ClearAllConnectivityServices',
    full_name='compute.ComputeService.ClearAllConnectivityServices',
    index=6,
    containing_service=None,
    input_type=context__pb2._EMPTY,
    output_type=context__pb2._EMPTY,
    serialized_options=None,
    create_key=_descriptor._internal_create_key,
  ),
])
_sym_db.RegisterServiceDescriptor(_COMPUTESERVICE)

DESCRIPTOR.services_by_name['ComputeService'] = _COMPUTESERVICE

# @@protoc_insertion_point(module_scope)
Loading