Commit 06e1e2a2 authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Implementing refinements in the webui: dividing forms for selecting the...

Implementing refinements in the webui: dividing forms for selecting the context and uploading json files in the home page; listing and detailing existing services.
parent 2394134e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ K8S_NAMESPACE=${K8S_NAMESPACE:-'tf-dev'}
WEBUI_SERVICE_NAME="webuiservice-public"
WEBUI_PROTO=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.ports[0].name}'`
WEBUI_IP=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}'`
WEBUI_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==8004)].nodePort}')
GRAFANA_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}')
# WEBUI_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==8004)].nodePort}')
WEBUI_PORT=8004
# GRAFANA_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}')
GRAFANA_PORT=3000

# Open WebUI
URL=${WEBUI_PROTO}://${WEBUI_IP}:${WEBUI_PORT}
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import os
import json

from flask import Flask, session
from flask import Flask, request, session
from flask_healthz import healthz, HealthError

from webui.proto.context_pb2 import Empty
+8 −3
Original line number Diff line number Diff line
@@ -16,16 +16,21 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed
from wtforms import SelectField, FileField, SubmitField
#from wtforms.validators import DataRequired, Length
from wtforms.validators import DataRequired, Length


class ContextForm(FlaskForm):
    context = SelectField(  'Context',
                            choices=[],
                            validators=[
                                #DataRequired(),
                                #Length(min=1)
                                DataRequired(),
                                Length(min=1)
                            ])
    
    submit = SubmitField('Submit')


class DescriptorForm(FlaskForm):
    descriptors = FileField('Descriptors',
                            validators=[
                                FileAllowed(['json'], 'JSON Descriptors only!')
+17 −15
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ from webui.Config import (CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT,
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from webui.proto.context_pb2 import Context, Device, Empty, Link, Topology
from webui.service.main.forms import ContextForm
from webui.service.main.forms import ContextForm, DescriptorForm

main = Blueprint('main', __name__)

@@ -66,27 +66,29 @@ def process_descriptors(descriptors):
def home():
    context_client.connect()
    device_client.connect()
    try:
    response = context_client.ListContextIds(Empty())
    context_form: ContextForm = ContextForm()
    context_form.context.choices.append(('', 'Select...'))
    for context in response.context_ids:
        context_form.context.choices.append((context.context_uuid.uuid, context.context_uuid))
    if context_form.validate_on_submit():
            if context_form.context.data:
        session['context_uuid'] = context_form.context.data
        flash(f'The context was successfully set to `{context_form.context.data}`.', 'success')
            if context_form.descriptors.data:
                process_descriptors(context_form.descriptors)
        return redirect(url_for("main.home"))
    if 'context_uuid' in session:
        context_form.context.data = session['context_uuid']
        return render_template('main/home.html', context_form=context_form)
    descriptor_form: DescriptorForm = DescriptorForm()
    try:
        if descriptor_form.validate_on_submit():
            process_descriptors(descriptor_form.descriptors)
            return redirect(url_for("main.home"))
    except Exception as e:
        logger.exception('Descriptor load failed')
        flash(f'Descriptor load failed: `{str(e)}`', 'danger')
    finally:
        context_client.close()
        device_client.close()
    return render_template('main/home.html', context_form=context_form, descriptor_form=descriptor_form)

@main.route('/topology', methods=['GET'])
def topology():
+6 −1
Original line number Diff line number Diff line
@@ -75,8 +75,13 @@ def detail(service_uuid: str):
        context_client.connect()
        response: Service = context_client.GetService(request)
        context_client.close()
        return render_template('service/detail.html', service=response)
    except Exception as e:
        flash('The system encountered an error and cannot show the details of this service.', 'warning')
        current_app.logger.exception(e)
        return redirect(url_for('service.home'))
    return render_template('service/detail.html', service=response)


@service.get('delete/<path:service_uuid>')
def delete(service_uuid: str):
    pass
Loading