Ejemplo n.º 1
0
def update_project(
    request: Request,
    project_id: int,
    name: Text = Form(None),
    description: Text = Form(None)
) -> JSONResponse:
    """Update project.
    Args:
        project_id {int}: project id
        name {Text}: project name
        description {Text}: project description
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request, {
        'project_id': project_id,
        'name': name,
        'description': description
    })

    project_manager = ProjectManager()
    if name is not None:
        project_manager.update_project_name(project_id, name)

    if description is not None:
        project_manager.update_project_description(project_id, description)

    project = project_manager.get_project(project_id)

    return JSONResponse(project)
Ejemplo n.º 2
0
def get_project(request: Request, project_id: int) -> JSONResponse:  # pylint: disable=invalid-name,redefined-builtin
    """Get project.
    Args:
        project_id {int}: project id
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request)

    project_manager = ProjectManager()
    project = project_manager.get_project(project_id)
    return JSONResponse(project)
Ejemplo n.º 3
0
def restore(request: Request, project_id: int) -> JSONResponse:  # pylint: disable=invalid-name,redefined-builtin
    """Restore project.
    Args:
        project_id {int}: project id
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request, {'project_id': project_id})

    project_manager = ProjectManager()
    project_manager.restore(project_id)
    project = project_manager.get_project(project_id)

    return JSONResponse(project, HTTPStatus.OK)
Ejemplo n.º 4
0
def create_project(
    request: Request, name: Text = Form(...), description: Text = Form('')
) -> JSONResponse:
    """Create project.
    Args:
        name {Text}: project name
        description {Text}: project description
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request, {'name': name, 'description': description})

    project_manager = ProjectManager()
    project_id = project_manager.create_project(name, description)
    project = project_manager.get_project(project_id)

    return JSONResponse(project, HTTPStatus.CREATED)
Ejemplo n.º 5
0
def project_healthcheck(request: Request, project_id: int) -> JSONResponse:  # pylint: disable=invalid-name,redefined-builtin
    """Get project healthcheck (check if project's tracking server process was started).
    Args:
        project_id {int}: project id
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request)

    project_manager = ProjectManager()
    project = project_manager.get_project(project_id)
    is_running = project_manager._is_running(project_id)

    if is_running:
        return JSONResponse(project, HTTPStatus.OK)
    else:
        return JSONResponse(project, HTTPStatus.BAD_REQUEST)
Ejemplo n.º 6
0
def ping(request: Request, project_id: int) -> JSONResponse:
    """Ping project's tracking server.
    Args:
        project_id {int}: project id
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request)

    project_manager = ProjectManager()
    url = project_manager.get_internal_tracking_uri(project_id)
    project = project_manager.get_project(project_id)

    try:
        requests.get(url)
        return JSONResponse(project, HTTPStatus.OK)
    except requests.exceptions.ConnectionError:
        return JSONResponse(project, HTTPStatus.BAD_REQUEST)
Ejemplo n.º 7
0
def run_project(request: Request, project_id: int) -> JSONResponse:  # pylint: disable=invalid-name,redefined-builtin
    """Run project's tracking server.
    Args:
        project_id {int}: project id
    Returns:
        starlette.responses.JSONResponse
    """

    log_request(request, {'project_id': project_id})

    project_manager = ProjectManager()
    running = project_manager.run(project_id)

    if not running:
        return error_response(
            http_response_code=HTTPStatus.INTERNAL_SERVER_ERROR,
            message='Internal error, tracking server has terminated')

    project = project_manager.get_project(project_id)
    return JSONResponse(project, HTTPStatus.OK)