Browse Source

add path_prefix argument for start command

tags/v0.5.0-beta
liangyongxiong 5 years ago
parent
commit
f2f80b177a
12 changed files with 50 additions and 22 deletions
  1. +1
    -1
      mindinsight/backend/application.py
  2. +6
    -8
      mindinsight/backend/datavisual/static_resource_api.py
  3. +1
    -1
      mindinsight/backend/datavisual/task_manager_api.py
  4. +1
    -1
      mindinsight/backend/datavisual/train_visual_api.py
  5. +1
    -1
      mindinsight/backend/lineagemgr/lineage_api.py
  6. +1
    -1
      mindinsight/backend/profiler/profile_api.py
  7. +1
    -1
      mindinsight/backend/run.py
  8. +2
    -2
      mindinsight/conf/constants.py
  9. +1
    -0
      mindinsight/conf/defaults.py
  10. +31
    -0
      mindinsight/scripts/start.py
  11. +1
    -1
      mindinsight/ui/src/services/fetcher.js
  12. +3
    -5
      tests/ut/backend/datavisual/conftest.py

+ 1
- 1
mindinsight/backend/application.py View File

@@ -107,7 +107,7 @@ def before_request():

def create_app():
"""Set flask APP config, and start the data manager."""
static_url_path = "/static"
static_url_path = settings.URL_PATH_PREFIX + "/static"
static_folder_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'ui', 'dist', 'static'))

app = Flask(__name__, static_url_path=static_url_path, static_folder=static_folder_path)


+ 6
- 8
mindinsight/backend/datavisual/static_resource_api.py View File

@@ -20,20 +20,18 @@ from flask import current_app
from flask import send_from_directory
from flask import Blueprint

from mindinsight.conf import settings

APP_PATH = os.path.realpath(os.path.dirname(sys.argv[0]))
BLUEPRINT = Blueprint("static_resource", __name__)
BLUEPRINT = Blueprint("static_resource", __name__, url_prefix=settings.URL_PATH_PREFIX)


@BLUEPRINT.route("/", methods=["GET"])
def index():
"""Interface to return static index.html."""
return send_from_directory(get_index_resource_dir(), "index.html")


def get_index_resource_dir():
"""Interface to return index.html resource directory."""
return os.path.realpath(os.path.join(APP_PATH, current_app.static_folder, os.pardir))
app_path = os.path.realpath(os.path.dirname(sys.argv[0]))
index_resource_dir = os.path.realpath(os.path.join(app_path, current_app.static_folder, os.pardir))
return send_from_directory(index_resource_dir, "index.html")


def init_module(app):


+ 1
- 1
mindinsight/backend/datavisual/task_manager_api.py View File

@@ -34,7 +34,7 @@ from mindinsight.datavisual.processors.train_task_manager import TrainTaskManage
from mindinsight.datavisual.data_transform.data_manager import DATA_MANAGER


BLUEPRINT = Blueprint("task_manager", __name__, url_prefix=settings.URL_PREFIX)
BLUEPRINT = Blueprint("task_manager", __name__, url_prefix=settings.URL_PATH_PREFIX+settings.API_PREFIX)


@BLUEPRINT.route("/datavisual/single-job", methods=["GET"])


+ 1
- 1
mindinsight/backend/datavisual/train_visual_api.py View File

@@ -31,7 +31,7 @@ from mindinsight.datavisual.processors.graph_processor import GraphProcessor
from mindinsight.datavisual.data_transform.data_manager import DATA_MANAGER


BLUEPRINT = Blueprint("train_visual", __name__, url_prefix=settings.URL_PREFIX)
BLUEPRINT = Blueprint("train_visual", __name__, url_prefix=settings.URL_PATH_PREFIX+settings.API_PREFIX)


@BLUEPRINT.route("/datavisual/image/metadata", methods=["GET"])


+ 1
- 1
mindinsight/backend/lineagemgr/lineage_api.py View File

@@ -25,7 +25,7 @@ from mindinsight.lineagemgr.api.model import general_filter_summary_lineage, gen
from mindinsight.utils.exceptions import MindInsightException, ParamValueError
from mindinsight.lineagemgr.cache_item_updater import update_lineage_object

BLUEPRINT = Blueprint("lineage", __name__, url_prefix=settings.URL_PREFIX.rstrip("/"))
BLUEPRINT = Blueprint("lineage", __name__, url_prefix=settings.URL_PATH_PREFIX+settings.API_PREFIX)


@BLUEPRINT.route("/lineagemgr/lineages", methods=["POST"])


+ 1
- 1
mindinsight/backend/profiler/profile_api.py View File

@@ -41,7 +41,7 @@ from mindinsight.profiler.common.validator.validate_path import validate_and_nor
from mindinsight.profiler.proposer.compose_proposer import ComposeProposal
from mindinsight.utils.exceptions import ParamValueError
BLUEPRINT = Blueprint("profile", __name__, url_prefix=settings.URL_PREFIX)
BLUEPRINT = Blueprint("profile", __name__, url_prefix=settings.URL_PATH_PREFIX+settings.API_PREFIX)
@BLUEPRINT.route("/profile/ops/search", methods=["POST"])


+ 1
- 1
mindinsight/backend/run.py View File

@@ -252,7 +252,7 @@ def start():
else:
state_result = _check_server_start_stat(errorlog_abspath, log_size)
# print gunicorn start state to stdout
console.info('Web address: http://%s:%s', settings.HOST, settings.PORT)
console.info('Web address: http://%s:%s%s', settings.HOST, settings.PORT, settings.URL_PATH_PREFIX)
for line in state_result["prompt_message"]:
console.info(line)



+ 2
- 2
mindinsight/conf/constants.py View File

@@ -41,8 +41,8 @@ ENABLE_CORS = False

SUPPORT_REQUEST_METHODS = {'POST', 'GET', 'PUT', 'DELETE'}

# url prefix should not end with slash, correct format is /v1/url
URL_PREFIX = '/v1/mindinsight'
# api prefix should not end with slash, correct format is /v1/url
API_PREFIX = '/v1/mindinsight'

####################################
# Datavisual default settings.


+ 1
- 0
mindinsight/conf/defaults.py View File

@@ -24,6 +24,7 @@ WORKSPACE = os.path.join(os.environ['HOME'], 'mindinsight')
# Web default settings.
####################################
PORT = 8080
URL_PATH_PREFIX = ''

####################################
# Datavisual default settings.


+ 31
- 0
mindinsight/scripts/start.py View File

@@ -16,6 +16,7 @@

import os
import sys
import re
import argparse
from importlib import import_module

@@ -118,6 +119,28 @@ class PortAction(argparse.Action):
setattr(namespace, self.dest, port)


class UrlPathPrefixAction(argparse.Action):
"""Url Path prefix action class definition."""

REGEX = r'^(\/[a-zA-Z0-9-\-\.]+)+$'

def __call__(self, parser, namespace, values, option_string=None):
"""
Inherited __call__ method from argparse.Action.

Args:
parser (ArgumentParser): Passed-in argument parser.
namespace (Namespace): Namespace object to hold arguments.
values (object): Argument values with type depending on argument definition.
option_string (str): Optional string for specific argument name. Default: None.
"""
prefix = values
if not re.match(self.REGEX, prefix):
parser.error(f'{option_string} value is invalid url path prefix')

setattr(namespace, self.dest, prefix)


class Command(BaseCommand):
"""
Start mindinsight service.
@@ -158,6 +181,14 @@ class Command(BaseCommand):
Custom port ranging from %s to %s. Default value is %s.
""" % (PortAction.MIN_PORT, PortAction.MAX_PORT, settings.PORT))

parser.add_argument(
'--url-path-prefix',
type=str,
action=UrlPathPrefixAction,
help="""
Custom path prefix for web page address. Default value is ''.
""")

for hook in HookUtils.instance().hooks():
hook.register_startup_arguments(parser)



+ 1
- 1
mindinsight/ui/src/services/fetcher.js View File

@@ -20,7 +20,7 @@ import axios from 'axios';
import Vue from 'vue';

export {default} from 'axios';
export const basePath = location.origin;
export const basePath = location.origin + location.pathname;

axios.defaults.timeout = 30000;
axios.defaults.baseURL = basePath;


+ 3
- 5
tests/ut/backend/datavisual/conftest.py View File

@@ -21,7 +21,7 @@ import pytest
from flask import Response

from mindinsight.backend import datavisual
from mindinsight.datavisual import utils
from mindinsight.datavisual.utils import tools


@pytest.fixture
@@ -31,12 +31,10 @@ def client():
mock_data_manager.start_load_data = Mock()
datavisual.DATA_MANAGER = mock_data_manager

packages = ["mindinsight.backend.raw_dataset",
"mindinsight.backend.train_dataset",
"mindinsight.backend.data_visual"]
packages = ["mindinsight.backend.data_visual"]

mock_obj = Mock(return_value=packages)
utils.find_app_package = mock_obj
tools.find_app_package = mock_obj

from mindinsight.backend.application import APP
APP.response_class = Response


Loading…
Cancel
Save