def view_container():
    container_name = request.args.get('container_name')
    cell_name = request.args.get('cell')
    start_time = request.args.get('start_time')
    container_info, operators_info, all_past_run = get_container_info(
        container_name=container_name,
        cell_name=cell_name,
        start_time=start_time
    )
    try:
        return render_template(
            'container_backend_container_viewer.html',
            container_name=container_name,
            container_info=container_info,
            operators_info=operators_info,
            all_past_run=all_past_run
        )
    except Exception as err:
        pslx_frontend_logger.error(
            "Got error rendering container_backend.html: " + str(err) + '.')
        return render_template(
            'container_backend_container_viewer.html',
            container_name=str(err),
            container_info=container_info,
            operators_info=[],
            all_past_run=[]
        )
예제 #2
0
def load_user(user_id):
    try:
        return User.query.get(int(user_id))
    except Exception as err:
        pslx_frontend_logger.error("Load user with error message: " +
                                   str(err) + '.')
        return None
def view_proto_table():
    value_types = EnvUtil.get_all_schemas(
        pslx_frontend_ui_app.config['schemas'])
    if request.method == 'POST':
        try:
            proto_table_path = request.form['proto_table_path'].strip()
            selected_value_type = request.form['value_type'].strip()
            modules = selected_value_type.split('.')
            module, value_type = '.'.join(modules[:-1]), modules[-1]
            pslx_frontend_logger.info("Proto table viewer input path [" +
                                      proto_table_path +
                                      '] with value type [' + value_type +
                                      '] in module name [' + module + '].')
            result = FileUtil.read_proto_from_file(proto_type=ProtoTable,
                                                   file_name=proto_table_path)
            value_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=value_type, modules=module)
            proto_contents = []
            result_content = dict(result.data)
            for key in sorted(result_content.keys()):
                proto_val = ProtoUtil.any_to_message(
                    message_type=value_type, any_message=result_content[key])
                try:
                    proto_contents.append({
                        'key':
                        key,
                        'val':
                        ProtoUtil.message_to_text(proto_message=proto_val),
                    })
                except Exception as err:
                    pslx_frontend_logger.error(
                        "Proto table viewer Parsing proto with error " +
                        str(err) + '.')
                    proto_contents.append({
                        'key': key,
                        'val': str(proto_val),
                    })
            value_types.remove(selected_value_type)
            return render_template('proto_table_viewer.html',
                                   proto_contents=proto_contents,
                                   value_types=value_types,
                                   selected_value_type=selected_value_type)
        except Exception as err:
            pslx_frontend_logger.error(
                "Got error rendering proto_table_viewer.html: " + str(err) +
                '.')
            return render_template('proto_table_viewer.html',
                                   proto_contents=[],
                                   value_types=value_types,
                                   selected_value_type='')
    else:
        return render_template('proto_table_viewer.html',
                               proto_contents=[],
                               value_types=value_types,
                               selected_value_type='')
def container_backend():
    containers_info = get_containers_info()
    try:
        return render_template(
            'container_backend.html',
            containers_info=sorted(
                containers_info, key=lambda x: x['container_name'])
        )
    except Exception as err:
        pslx_frontend_logger.error(
            "Got error rendering container_backend.html: " + str(err) + '.')
        return render_template(
            'container_backend.html',
            containers_info=[]
        )
예제 #5
0
def view_proto():
    all_urls = sorted(server_urls)
    if request.method == 'POST':
        try:
            server_url = request.form['server_url'].strip()
            proto_file_path = request.form['proto_file_path'].strip()
            message_type = request.form['message_type'].strip()
            module = request.form['module'].strip()
            pslx_frontend_logger.info("Proto viewer selecting url [" + server_url + '] and input path [' +
                                      proto_file_path + '] with message type [' + message_type +
                                      '] in module name [' + module + '].')
            result = client_map[server_url]['client'].view_proto(
                proto_file_path=proto_file_path,
                message_type=message_type,
                module=module,
                root_certificate=client_map[server_url]['root_certificate']
            )
            result_ui = ''
            for key in sorted(result.keys()):
                if key == 'proto_content':
                    result_ui += key + ':\n\n' + result[key] + '\n\n'
                else:
                    result_ui += key + ': ' + result[key] + '\n\n'
            all_urls.remove(server_url)
            all_urls = [server_url] + all_urls
            return render_template(
                'proto_viewer.html',
                proto_content=result_ui,
                server_urls=all_urls
            )
        except Exception as err:
            pslx_frontend_logger.error("Got error rendering proto_viewer.html: " + str(err) + '.')
            return render_template(
                'proto_viewer.html',
                proto_content="Got error rendering proto_viewer.html: " + str(err) + '.',
                server_urls=all_urls
            )
    else:
        return render_template(
            'proto_viewer.html',
            proto_content="",
            selected_server_url='',
            server_urls=server_urls
        )
예제 #6
0
def view_file():
    all_urls = sorted(server_urls)
    request_file_path = request.args.get('file_path')
    if request.method == 'POST' or request_file_path:
        try:
            server_url = request.form['server_url'].strip() if not request.args.get('server_url') else \
                request.args.get('server_url')
            file_path = request.form['file_path'].strip(
            ) if not request_file_path else request_file_path

            pslx_frontend_logger.info("Select url " + server_url +
                                      ' and input path ' + file_path + '.')
            result = client_map[server_url]['client'].view_file(
                file_path=file_path,
                root_certificate=client_map[server_url]['root_certificate'])
            all_urls.remove(server_url)
            all_urls = [server_url] + all_urls
            return render_template(
                'file_viewer.html',
                files_info=sorted(result['files_info'].values(),
                                  key=lambda item: item['file_path']),
                directories_info=sorted(result['directories_info']),
                file_path=file_path,
                selected_server_url=server_url,
                server_urls=all_urls)
        except Exception as err:
            pslx_frontend_logger.error("File viewer got error: " + str(err) +
                                       '.')
            return render_template('file_viewer.html',
                                   files_info={},
                                   directories_info=[],
                                   file_path='Got error: ' + str(err),
                                   selected_server_url='',
                                   server_urls=all_urls)
    elif request.method == 'GET':
        return render_template('file_viewer.html',
                               files_info={},
                               directories_info=[],
                               file_path='',
                               selected_server_url='',
                               server_urls=all_urls)
예제 #7
0
def view_proto():
    value_types = EnvUtil.get_all_schemas(pslx_frontend_ui_app.config['schemas'])
    if request.method == 'POST':
        try:
            proto_file_path = request.form['proto_file_path'].strip()
            selected_value_type = request.form['value_type'].strip()
            modules = selected_value_type.split('.')
            module, message_type_str = '.'.join(modules[:-1]), modules[-1]
            pslx_frontend_logger.info("Proto viewer input path [" + proto_file_path + '] with message type [' +
                                      message_type_str + '] in module name [' + module + '].')
            message_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=message_type_str,
                modules=module
            )
            proto_message = FileUtil.read_proto_from_file(
                proto_type=message_type, file_name=proto_file_path)

            result_ui = ProtoUtil.message_to_text(proto_message=proto_message)

            return render_template(
                'proto_viewer.html',
                proto_content=result_ui,
                value_types=value_types,
                selected_value_type=selected_value_type
            )
        except Exception as err:
            pslx_frontend_logger.error("Got error rendering proto_viewer.html: " + str(err) + '.')
            return render_template(
                'proto_viewer.html',
                proto_content="Got error rendering proto_viewer.html: " + str(err) + '.',
                value_types=value_types,
                selected_value_type=''
            )
    else:
        return render_template(
            'proto_viewer.html',
            proto_content="",
            value_types=value_types,
            selected_value_type=''
        )
예제 #8
0
def view_proto_table():
    all_urls = sorted(server_urls)
    if request.method == 'POST':
        try:
            server_url = request.form['server_url'].strip()
            proto_table_path = request.form['proto_table_path'].strip()
            value_type = request.form['value_type'].strip()
            module = request.form['module'].strip()
            pslx_frontend_logger.info("Proto table viewer selecting url [" + server_url + '] and input path [' +
                                      proto_table_path + '] with value type [' + value_type +
                                      '] in module name [' + module + '].')
            result = client_map[server_url]['client'].view_proto(
                proto_file_path=proto_table_path,
                message_type="ProtoTable",
                module="",
                root_certificate=client_map[server_url]['root_certificate']
            )
            value_type = ProtoUtil.infer_message_type_from_str(
                message_type_str=value_type,
                modules=module
            )
            result_content = ProtoUtil.text_to_message(message_type=ProtoTable, text_str=result['proto_content'])
            proto_contents = []
            result_content = dict(result_content.data)
            for key in sorted(result_content.keys()):
                proto_val = ProtoUtil.any_to_message(
                    message_type=value_type,
                    any_message=result_content[key]
                )
                try:
                    proto_contents.append(
                        {
                            'key': key,
                            'val': ProtoUtil.message_to_text(proto_message=proto_val),
                        }
                    )
                except Exception as err:
                    pslx_frontend_logger.error("Proto table viewer Parsing proto with error " + str(err) + '.')
                    proto_contents.append(
                        {
                            'key': key,
                            'val': str(proto_val),
                        }
                    )

            all_urls.remove(server_url)
            all_urls = [server_url] + all_urls
            return render_template(
                'proto_table_viewer.html',
                proto_contents=proto_contents,
                server_urls=all_urls
            )
        except Exception as err:
            pslx_frontend_logger.error("Got error rendering proto_table_viewer.html: " + str(err) + '.')
            return render_template(
                'proto_table_viewer.html',
                proto_contents=[],
                server_urls=all_urls
            )
    else:
        return render_template(
            'proto_table_viewer.html',
            proto_contents=[],
            selected_server_url='',
            server_urls=server_urls
        )