Commit 8c503768 authored by Manuel Angel Jimenez Quesada's avatar Manuel Angel Jimenez Quesada
Browse files

Add HTTP Server and gRPC Server

Add manifest.yaml
Add DockerFile

Solve some typo on .proto file
parent ea3a17d4
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
@@ -12,24 +12,67 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from flask.json import jsonify
from jsonschema import _utils
from jsonschema.validators import validator_for
from jsonschema.protocols import Validator
from jsonschema.exceptions import ValidationError
from werkzeug.exceptions import BadRequest
from .HttpStatusCodes import HTTP_BADREQUEST

def validate_message(schema, message):
    validator_class = validator_for(schema)
    validator : Validator = validator_class(schema)
    errors : List[ValidationError] = sorted(validator.iter_errors(message), key=str)
    if len(errors) == 0: return
    response = jsonify([
        {'message': str(error.message), 'schema': str(error.schema), 'validator': str(error.validator),
         'where': str(_utils.format_as_index(container='message', indices=error.relative_path))}
        for error in errors
    ])
    response.status_code = HTTP_BADREQUEST
    raise BadRequest(response=response)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ztp_serverservice
spec:
  selector:
    matchLabels:
      app: ztp_serverservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: ztp_serverservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/ztp_server:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8005
            - containerPort: 5051
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5051"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5051"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: ztp_serverservice
  labels:
    app: ztp_serverservice
spec:
  type: ClusterIP
  selector:
    app: ztp_serverservice
  ports:
    - name: http
      protocol: TCP
      port: 8005
      targetPort: 8005
    - name: grpc
      protocol: TCP
      port: 5051
      targetPort: 5051
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 
---
+2 −2
Original line number Diff line number Diff line
@@ -25,11 +25,11 @@ service ZtpServerService {

// Define the request message for both methods
message ProvisioningScriptName {
  string input = 1;
  string scriptname = 1;
}

message ZtpFileName {
  string input = 1;
  string filename = 1;
}

message ProvisioningScript {
+3 −2
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
DEFAULT_SERVICE_HTTP_PORTS = {
    ServiceNameEnum.NBI  .value      : 8080,
    ServiceNameEnum.WEBUI.value      : 8004,
    ServiceNameEnum.ZTP_SERVER.value : 8005,
}

# Default HTTP/REST-API service base URLs
+9 −34
Original line number Diff line number Diff line
@@ -19,21 +19,6 @@ RUN apt-get --yes --quiet --quiet update && \
    apt-get --yes --quiet --quiet install wget g++ git build-essential cmake libpcre2-dev python3-dev python3-cffi && \
    rm -rf /var/lib/apt/lists/*

# Download, build and install libyang. Note that APT package is outdated
# - Ref: https://github.com/CESNET/libyang
# - Ref: https://github.com/CESNET/libyang-python/
RUN mkdir -p /var/libyang
RUN git clone https://github.com/CESNET/libyang.git /var/libyang
WORKDIR /var/libyang
RUN git fetch
RUN git checkout v2.1.148
RUN mkdir -p /var/libyang/build
WORKDIR /var/libyang/build
RUN cmake -D CMAKE_BUILD_TYPE:String="Release" ..
RUN make
RUN make install
RUN ldconfig

# Set Python to show logs as they occur
ENV PYTHONUNBUFFERED=0

@@ -69,29 +54,19 @@ RUN rm *.proto
RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \;

# Create component sub-folders, get specific Python packages
RUN mkdir -p /var/teraflow/nbi
WORKDIR /var/teraflow/nbi
COPY src/nbi/requirements.in requirements.in
RUN mkdir -p /var/teraflow/ztp_server
WORKDIR /var/teraflow/ztp_server
COPY src/ztp_server/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN python3 -m pip install -r requirements.txt

# Add component files into working directory
WORKDIR /var/teraflow
COPY src/nbi/. nbi/
COPY src/context/__init__.py context/__init__.py
COPY src/context/client/. context/client/
COPY src/device/__init__.py device/__init__.py
COPY src/device/client/. device/client/
COPY src/service/__init__.py service/__init__.py
COPY src/service/client/. service/client/
COPY src/slice/__init__.py slice/__init__.py
COPY src/slice/client/. slice/client/
COPY src/qkd_app/__init__.py qkd_app/__init__.py
COPY src/qkd_app/client/. qkd_app/client/
COPY src/vnt_manager/__init__.py vnt_manager/__init__.py
COPY src/vnt_manager/client/. vnt_manager/client/
RUN mkdir -p /var/teraflow/tests/tools
COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/
COPY src/ztp_server/. ztp_server/

#ToDo Implement Test
#RUN mkdir -p /var/teraflow/tests/tools
#COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/

# Start the service
ENTRYPOINT ["python", "-m", "nbi.service"]
ENTRYPOINT ["python", "-m", "ztp_server.service"]

src/ztp_server/README.md

deleted100755 → 0
+0 −35
Original line number Diff line number Diff line
# NBI Component

The NBI component uses libyang to validate and process messages. Follow instructions below to install it.

## Install libyang
- Ref: https://github.com/CESNET/libyang
- Ref: https://github.com/CESNET/libyang-python/

__NOTE__: APT package is extremely outdated and does not work for our purposes.

### Build Requisites
```bash
sudo apt-get install build-essential cmake libpcre2-dev
sudo apt-get install python3-dev gcc python3-cffi
```

### Build from source
```bash
mkdir ~/tfs-ctrl/libyang
git clone https://github.com/CESNET/libyang.git ~/tfs-ctrl/libyang
cd ~/tfs-ctrl/libyang
git fetch
git checkout v2.1.148
mkdir ~/tfs-ctrl/libyang/build
cd ~/tfs-ctrl/libyang/build
cmake -D CMAKE_BUILD_TYPE:String="Release" ..
make
sudo make install
sudo ldconfig
```

### Install Python bindings
```bash
pip install libyang==2.8.0
```
Loading