Commit b95fdd5a authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

PathComp component

- Added curl as dependency for unitary tests
- Added configuration settings in Frontend
- Removed unneeded logs
parent 4b6b4ee5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ FROM ubuntu:20.04 AS builder
ARG DEBIAN_FRONTEND=noninteractive

# Install build software
RUN apt-get update -y && apt-get install build-essential gcovr libglib2.0-dev -y
RUN apt-get update -y && apt-get install build-essential curl gcovr libglib2.0-dev -y

# mkdir
RUN mkdir -p /var/teraflow
+14 −3
Original line number Diff line number Diff line
@@ -12,6 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

BACKEND_URL  = 'http://{:s}:{:d}/pathComp/api/v1/compRoute'
BACKEND_HOST = '172.28.0.2'
BACKEND_PORT = 8081
import os

DEFAULT_PATHCOMP_BACKEND_SCHEME  = 'http'
DEFAULT_PATHCOMP_BACKEND_HOST    = '127.0.0.1'
DEFAULT_PATHCOMP_BACKEND_PORT    = 8081
DEFAULT_PATHCOMP_BACKEND_BASEURL = '/pathComp/api/v1/compRoute'

PATHCOMP_BACKEND_SCHEME  = str(os.environ.get('PATHCOMP_BACKEND_SCHEME',  DEFAULT_PATHCOMP_BACKEND_SCHEME ))
PATHCOMP_BACKEND_HOST    = str(os.environ.get('PATHCOMP_BACKEND_HOST',    DEFAULT_PATHCOMP_BACKEND_HOST   ))
PATHCOMP_BACKEND_PORT    = int(os.environ.get('PATHCOMP_BACKEND_PORT',    DEFAULT_PATHCOMP_BACKEND_PORT   ))
PATHCOMP_BACKEND_BASEURL = str(os.environ.get('PATHCOMP_BACKEND_BASEURL', DEFAULT_PATHCOMP_BACKEND_BASEURL))

BACKEND_URL = '{:s}://{:s}:{:d}{:s}'.format(
    PATHCOMP_BACKEND_SCHEME, PATHCOMP_BACKEND_HOST, PATHCOMP_BACKEND_PORT, PATHCOMP_BACKEND_BASEURL)
+2 −6
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer
from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method
from common.tools.grpc.Tools import grpc_message_to_json_string
from context.client.ContextClient import ContextClient
from pathcomp.frontend.Config import BACKEND_HOST, BACKEND_PORT, BACKEND_URL
from pathcomp.frontend.Config import BACKEND_URL
from pathcomp.frontend.service.tools.ComposeRequest import compose_device, compose_link, compose_service
#from pathcomp.frontend.service.tools.Constants import CapacityUnit

@@ -37,9 +37,6 @@ class PathCompServiceServicerImpl(PathCompServiceServicer):

    @safe_and_metered_rpc_method(METRICS, LOGGER)
    def Compute(self, request : PathCompRequest, context : grpc.ServicerContext) -> PathCompReply:
        import os
        LOGGER.info('os.environ={:s}'.format(str(os.environ)))

        LOGGER.info('[Compute] begin ; request = {:s}'.format(grpc_message_to_json_string(request)))

        algorithm = request.WhichOneof('algorithm')
@@ -105,8 +102,7 @@ class PathCompServiceServicerImpl(PathCompServiceServicer):
        #with open('pc-req.json', 'w', encoding='UTF-8') as f:
        #    f.write(json.dumps(request, sort_keys=True, indent=4))

        backend_url = BACKEND_URL.format(BACKEND_HOST, BACKEND_PORT)
        reply = requests.post(backend_url, json=request)
        reply = requests.post(BACKEND_URL, json=request)
        if reply.status_code not in {requests.codes.ok}:
            raise Exception('Backend error({:s}) for request({:s})'.format(
                str(reply.content.decode('UTF-8')), json.dumps(request, sort_keys=True)))