Exemplo n.º 1
0
def calculate_url(host: str,
                  url: str = None,
                  model_route: str = None,
                  model_deployment: str = None,
                  url_prefix: str = None,
                  mr_client: ModelRouteClient = None):
    """
    Calculate url for model

    :param host: edge host
    :param url: full url to model api
    :param model_route: model route name
    :param model_deployment: model deployment name
    :param url_prefix: model prefix
    :return: model url
    """
    if url:
        return url

    if url_prefix:
        LOGGER.debug('')
        return f'{host}{url_prefix}'

    model_route = model_route or model_deployment
    if model_route:
        if mr_client is None:
            mr_client = ModelRouteClient()

        model_route = mr_client.get(model_route)

        LOGGER.debug('Found model route: %s', model_route)
        return model_route.status.edge_url

    raise NotImplementedError("Cannot create a model url")
Exemplo n.º 2
0
def get(client: ModelRouteClient, mr_id: str, output_format: str):
    """
    Get routes.\n
    The command without id argument retrieve all routes.\n
    Get all routes in json format:\n
        odahuflowctl route get --output-format json\n
    Get model route with "git-repo" id:\n
        odahuflowctl route get --id git-repo\n
    Using jsonpath:\n
        odahuflowctl route get -o 'jsonpath=[*].spec.reference'
    \f
    :param client: ModelRoute HTTP client
    :param mr_id: ModelRoute ID
    :param output_format: Output format
    :return:
    """
    routes = [client.get(mr_id)] if mr_id else client.get_all()

    format_output(routes, output_format)
Exemplo n.º 3
0
def wait_operation_finish(timeout: int, wait: bool, mr_id: str,
                          mr_client: ModelRouteClient):
    """
    Wait route to finish according command line arguments

    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until operation will be finished
    :param mr_id: Model Route id
    :param mr_client: Model Route Client

    :return: None
    """
    if not wait:
        return

    start = time.time()
    if timeout <= 0:
        raise Exception(
            'Invalid --timeout argument: should be positive integer')

    while True:
        elapsed = time.time() - start
        if elapsed > timeout:
            raise Exception(TIMEOUT_ERROR_MESSAGE)

        try:
            mr = mr_client.get(mr_id)
            if mr.status.state == READY_STATE:
                print(f'Model Route {mr_id} is ready')
                return
            elif mr.status.state == "":
                print(f"Can't determine the state of {mr.id}. Sleeping...")
            else:
                print(f'Current route state is {mr.status.state}. Sleeping...')
        except WrongHttpStatusCode:
            LOGGER.info(
                'Callback have not confirmed completion of the operation')

        LOGGER.debug('Sleep before next request')
        time.sleep(DEFAULT_WAIT_TIMEOUT)