Esempio n. 1
0
def set_hw_parser(parser=None):
    """Set the hello world parser

    :param parser: the parser configure
    :return: the new parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_hw_base_parser(parser)
    gp = add_arg_group(parser, title='Index')
    gp.add_argument(
        '--index-data-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz',
        help='The url of index data (should be in idx3-ubyte.gz format)',
    )
    gp.add_argument(
        '--index-labels-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz',
        help='The url of index labels data (should be in idx3-ubyte.gz format)',
    )

    gp = add_arg_group(parser, title='Search')
    gp.add_argument(
        '--query-data-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz',
        help='The url of query data (should be in idx3-ubyte.gz format)',
    )
    gp.add_argument(
        '--query-labels-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz',
        help='The url of query labels data (should be in idx3-ubyte.gz format)',
    )

    gp.add_argument('--num-query',
                    type=int,
                    default=128,
                    help='The number of queries to visualize')
    gp.add_argument('--top-k',
                    type=int,
                    default=50,
                    help='Top-k results to retrieve and visualize')
    return parser
Esempio n. 2
0
def mixin_gateway_parser(parser):
    """Add the options for remote expose at the Gateway
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='Gateway')
    _add_host(gp)
    _add_proxy(gp)

    gp.add_argument(
        '--port-expose',
        type=int,
        default=helper.random_port(),
        help='The port that the gateway exposes for clients for GRPC connections.',
    )

    parser.add_argument(
        '--graph-description',
        type=str,
        help='Routing graph for the gateway',
        default='{}',
    )

    parser.add_argument(
        '--deployments-addresses',
        type=str,
        help='dictionary JSON with the input addresses of each Deployment',
        default='{}',
    )
Esempio n. 3
0
def mixin_distributed_feature_parser(parser):
    """Mixing in arguments required by :class:`BasePod` into the given parser. """
    gp = add_arg_group(parser, title='Distributed')

    gp.add_argument(
        '--silent-remote-logs',
        action='store_true',
        default=False,
        help='Do not display the streaming of remote logs on local console')

    gp.add_argument('--upload-files',
                    type=str,
                    nargs='*',
                    metavar='FILE',
                    help='''
The files on the host to be uploaded to the remote
workspace. This can be useful when your Pod has more
file dependencies beyond a single YAML file, e.g.
Python files, data files.

Note,
- currently only flatten structure is supported, which means if you upload `[./foo/a.py, ./foo/b.pp, ./bar/c.yml]`, then they will be put under the _same_ workspace on the remote, losing all hierarchies.
- by default, `--uses` YAML file is always uploaded.
- uploaded files are by default isolated across the runs. To ensure files are submitted to the same workspace across different runs, use `--workspace-id` to specify the workspace.
''')

    gp.add_argument(
        '--workspace-id',
        type=str,
        default=random_identity(),
        help=
        'the UUID for identifying the workspace. When not given a random id will be assigned.'
        'Multiple Pea/Pod/Flow will work under the same workspace if they share the same '
        '`workspace-id`.')
Esempio n. 4
0
def mixin_distributed_feature_parser(parser):
    """Mixing in arguments required by :class:`BaseDeployment` into the given parser.
    :param parser: the parser instance to which we add arguments
    """

    gp = add_arg_group(parser, title='Distributed')

    gp.add_argument(
        '--quiet-remote-logs',
        action='store_true',
        default=False,
        help='Do not display the streaming of remote logs on local console',
    )

    gp.add_argument(
        '--upload-files',
        type=str,
        nargs='*',
        metavar='FILE',
        help='''
The files on the host to be uploaded to the remote
workspace. This can be useful when your Deployment has more
file dependencies beyond a single YAML file, e.g.
Python files, data files.

Note,
- currently only flatten structure is supported, which means if you upload `[./foo/a.py, ./foo/b.pp, ./bar/c.yml]`, then they will be put under the _same_ workspace on the remote, losing all hierarchies.
- by default, `--uses` YAML file is always uploaded.
- uploaded files are by default isolated across the runs. To ensure files are submitted to the same workspace across different runs, use `--workspace-id` to specify the workspace.
''',
    )
Esempio n. 5
0
File: base.py Progetto: jina-ai/jina
def mixin_essential_parser(parser):
    """Mixing in arguments required by every module into the given parser.
    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='Essential')
    gp.add_argument(
        '--name',
        type=str,
        help='''
    The name of this object.

    This will be used in the following places:
    - how you refer to this object in Python/YAML/CLI
    - visualization
    - log message header
    - ...

    When not given, then the default naming strategy will apply.
                        ''',
    )

    gp.add_argument(
        '--workspace',
        type=str,
        default=None,
        help='The working directory for any IO operations in this object. '
        'If not set, then derive from its parent `workspace`.',
    )

    gp.add_argument(
        '--log-config',
        type=str,
        default='default',
        help='The YAML config of the logger used in this object.',
    )

    gp.add_argument(
        '--quiet',
        action='store_true',
        default=False,
        help='If set, then no log will be emitted from this object.',
    )

    gp.add_argument(
        '--quiet-error',
        action='store_true',
        default=False,
        help=
        'If set, then exception stack information will not be added to the log',
    )

    gp.add_argument(
        '--workspace-id',
        type=str,
        default=random_identity(),
        help=
        'the UUID for identifying the workspace. When not given a random id will be assigned.'
        'Multiple Pod/Deployment/Flow will work under the same workspace if they share the same '
        '`workspace-id`.' if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
Esempio n. 6
0
def mixin_base_pod_parser(parser):
    """Mixing in arguments required by :class:`BasePod` into the given parser. """
    gp = add_arg_group(parser, title='Pod')

    gp.add_argument('--uses-before', type=str,
                    help='The executor attached after the Peas described by --uses, typically before sending to all '
                         'parallels, accepted type follows "--uses"')
    gp.add_argument('--uses-after', type=str,
                    help='The executor attached after the Peas described by --uses, typically used for receiving from '
                         'all parallels, accepted type follows "--uses"')
    gp.add_argument('--remove-uses-ba', action='store_true', default=False,
                    help='If set, disable `uses-before` or `uses-after` if parallel is equal to 1. Useful'
                         'to parametrize parallelization and sharding without having `uses_after` or `uses_before` '
                         'taking extra processes and network hops')
    gp.add_argument('--parallel', '--shards', type=int, default=1,
                    help='The number of parallel peas in the pod running at the same time, '
                         '`port_in` and `port_out` will be set to random, '
                         'and routers will be added automatically when necessary')
    gp.add_argument('--polling', type=PollingType.from_string, choices=list(PollingType),
                    default=PollingType.ANY,
                    help='''
The polling strategy of the Pod (when `parallel>1`) 
- ANY: only one (whoever is idle) Pea polls the message
- ALL: all Peas poll the message (like a broadcast)
''')
    gp.add_argument('--scheduling', type=SchedulerType.from_string, choices=list(SchedulerType),
                    default=SchedulerType.LOAD_BALANCE,
                    help='The strategy of scheduling workload among Peas')

    # hidden CLI used for internal only

    gp.add_argument('--pod-role', type=PodRoleType.from_string, choices=list(PodRoleType),
                    help='The role of this pod in the flow' if _SHOW_ALL_ARGS else argparse.SUPPRESS)
Esempio n. 7
0
def mixin_compressor_parser(parser=None):
    """Add the options for compressors
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='Compression')

    gp.add_argument(
        '--compress',
        type=CompressAlgo.from_string,
        choices=list(CompressAlgo),
        default=CompressAlgo.NONE,
        help='''
    The compress algorithm used over the entire Flow.

    Note that this is not necessarily effective,
    it depends on the settings of `--compress-min-bytes` and `compress-min-ratio`''',
    )

    gp.add_argument(
        '--compress-min-bytes',
        type=int,
        default=1024,
        help='The original message size must be larger than this number to trigger the compress algorithm, '
        '-1 means disable compression.',
    )

    gp.add_argument(
        '--compress-min-ratio',
        type=float,
        default=1.1,
        help='The compression ratio (uncompressed_size/compressed_size) must be higher than this number '
        'to trigger the compress algorithm.',
    )
Esempio n. 8
0
def mixin_daemon_parser(parser):
    """
    # noqa: DAR101
    # noqa: DAR102
    # noqa: DAR103
    """
    gp = add_arg_group(parser, title='Daemon')
    gp.add_argument(
        '--no-fluentd',
        action='store_true',
        default=False,
        help='do not start fluentd, no log streaming',
    )
    gp.add_argument(
        '--no-store',
        action='store_true',
        default=False,
        help='''
    Disable loading from local store (if any), while starting JinaD
    ''',
    )
    gp.add_argument(
        '--mode',
        type=str,
        choices=list(PartialDaemonModes),
        default=None,
        help=
        'Mode for partial jinad. Can be flow/pod/pea. If none provided main jinad is run.'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
Esempio n. 9
0
def mixin_flow_features_parser(parser):
    """Add the arguments for the Flow features to the parser

    :param parser: the parser configure
    """
    from jina.enums import FlowInspectType

    gp = add_arg_group(parser, title='Flow Feature')

    gp.add_argument('--uses', type=str, help='The YAML file represents a flow')
    gp.add_argument(
        '--env',
        action=KVAppendAction,
        metavar='KEY: VALUE',
        nargs='*',
        help='The map of environment variables that are available inside runtime',
    )

    gp.add_argument(
        '--inspect',
        type=FlowInspectType.from_string,
        choices=list(FlowInspectType),
        default=FlowInspectType.COLLECT,
        help='''
    The strategy on those inspect deployments in the flow.

    If `REMOVE` is given then all inspect deployments are removed when building the flow.
    ''',
    )
Esempio n. 10
0
def mixin_container_runtime_parser(parser):
    """Mixing in arguments required by :class:`ContainerRuntime` into the given parser.
    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='ContainerRuntime')

    gp.add_argument(
        '--entrypoint',
        type=str,
        help='The entrypoint command overrides the ENTRYPOINT in Docker image. '
        'when not set then the Docker image ENTRYPOINT takes effective.',
    )
    gp.add_argument(
        '--docker-kwargs',
        action=KVAppendAction,
        metavar='KEY: VALUE',
        nargs='*',
        help='''
Dictionary of kwargs arguments that will be passed to Docker SDK when starting the docker '
container. 

More details can be found in the Docker SDK docs:  https://docker-py.readthedocs.io/en/stable/

''',
    )
    gp.add_argument(
        '--pull-latest',
        action='store_true',
        default=False,
        help='Pull the latest image before running',
    )
    gp.add_argument(
        '--volumes',
        type=str,
        nargs='*',
        metavar='DIR',
        help='''
The path on the host to be mounted inside the container. 

Note, 
- If separated by `:`, then the first part will be considered as the local host path and the second part is the path in the container system. 
- If no split provided, then the basename of that directory will be mounted into container's root path, e.g. `--volumes="/user/test/my-workspace"` will be mounted into `/my-workspace` inside the container. 
- All volumes are mounted with read-write mode.
''',
    )
    gp.add_argument(
        '--gpus',
        type=str,
        help='''
    This argument allows dockerized Jina executor discover local gpu devices.

    Note, 
    - To access all gpus, use `--gpus all`.
    - To access multiple gpus, e.g. make use of 2 gpus, use `--gpus 2`.
    - To access specified gpus based on device id, use `--gpus device=[YOUR-GPU-DEVICE-ID]`
    - To access specified gpus based on multiple device id, use `--gpus device=[YOUR-GPU-DEVICE-ID1],device=[YOUR-GPU-DEVICE-ID2]`
    - To specify more parameters, use `--gpus device=[YOUR-GPU-DEVICE-ID],runtime=nvidia,capabilities=display
    ''',
    )
Esempio n. 11
0
def mixin_base_pod_parser(parser):
    """Add mixin arguments required by :class:`BasePod` into the given parser.

    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='Pod')

    gp.add_argument(
        '--uses-before',
        type=str,
        help=
        'The executor attached after the Peas described by --uses, typically before sending to all '
        'parallels, accepted type follows `--uses`',
    )
    gp.add_argument(
        '--uses-after',
        type=str,
        help=
        'The executor attached after the Peas described by --uses, typically used for receiving from '
        'all parallels, accepted type follows `--uses`',
    )
    gp.add_argument(
        '--parallel',
        '--shards',
        type=int,
        default=1,
        help='The number of parallel peas in the pod running at the same time, '
        '`port_in` and `port_out` will be set to random, '
        'and routers will be added automatically when necessary',
    )
    gp.add_argument(
        '--polling',
        type=PollingType.from_string,
        choices=list(PollingType),
        default=PollingType.ANY,
        help='''
The polling strategy of the Pod (when `parallel>1`) 
- ANY: only one (whoever is idle) Pea polls the message
- ALL: all Peas poll the message (like a broadcast)
''',
    )
    gp.add_argument(
        '--scheduling',
        type=SchedulerType.from_string,
        choices=list(SchedulerType),
        default=SchedulerType.LOAD_BALANCE,
        help='The strategy of scheduling workload among Peas',
    )

    # hidden CLI used for internal only

    gp.add_argument(
        '--pod-role',
        type=PodRoleType.from_string,
        choices=list(PodRoleType),
        help='The role of this pod in the flow'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
Esempio n. 12
0
def mixin_base_deployment_parser(parser):
    """Add mixin arguments required by :class:`BaseDeployment` into the given parser.

    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='Deployment')

    gp.add_argument(
        '--uses-before',
        type=str,
        help='The executor attached before the Pods described by --uses, typically before sending to all '
        'shards, accepted type follows `--uses`. This argument only applies for sharded Deployments (shards > 1).',
    )
    gp.add_argument(
        '--uses-after',
        type=str,
        help='The executor attached after the Pods described by --uses, typically used for receiving from '
        'all shards, accepted type follows `--uses`. This argument only applies for sharded Deployments (shards > 1).',
    )

    gp.add_argument(
        '--when',
        action=KVAppendAction,
        metavar='KEY: VALUE',
        nargs='*',
        help='The condition that the documents need to fulfill before reaching the Executor.'
        'The condition can be defined in the form of a `DocArray query condition <https://docarray.jina.ai/fundamentals/documentarray/find/#query-by-conditions>`',
    )

    gp.add_argument(
        '--external',
        action='store_true',
        default=False,
        help='The Deployment will be considered an external Deployment that has been started independently from the Flow.'
        'This Deployment will not be context managed by the Flow.',
    )

    # hidden CLI used for internal only

    gp.add_argument(
        '--deployment-role',
        type=DeploymentRoleType.from_string,
        choices=list(DeploymentRoleType),
        help='The role of this deployment in the flow'
        if _SHOW_ALL_ARGS
        else argparse.SUPPRESS,
    )

    gp.add_argument(
        '--tls',
        action='store_true',
        default=False,
        help='If set, connect to deployment using tls encryption',
    )
Esempio n. 13
0
def mixin_head_parser(parser):
    """Mixing in arguments required by head pods and runtimes into the given parser.
    :param parser: the parser instance to which we add arguments
    """

    gp = add_arg_group(parser, title='Head')

    try:
        gp.add_argument(
            '--compression',
            type=str,
            default='NoCompression',
            help=
            'The compression mechanism used when sending requests from the Head to the WorkerRuntimes. Possibilities '
            'are `NoCompression, Gzip, Deflate`. For more details, '
            'check https://grpc.github.io/grpc/python/grpc.html#compression.',
        )
    except argparse.ArgumentError:
        pass

    gp.add_argument(
        '--uses-before-address',
        type=str,
        help='The address of the uses-before runtime',
    )

    gp.add_argument(
        '--uses-after-address',
        type=str,
        help='The address of the uses-before runtime',
    )

    gp.add_argument(
        '--connection-list',
        type=str,
        help='dictionary JSON with a list of connections to configure',
    )

    gp.add_argument(
        '--disable-reduce',
        action='store_true',
        default=False,
        help=
        'Disable the built-in reduce mechanism, set this if the reduction is to be handled by the Executor connected to this Head',
    )

    gp.add_argument(
        '--timeout-send',
        type=int,
        default=None,
        help=
        'The timeout in milliseconds used when sending data requests to Executors, -1 means no timeout, disabled by default',
    )
Esempio n. 14
0
def mixin_daemon_parser(parser):
    gp = add_arg_group(parser, title='Daemon')

    gp.add_argument('--no-fluentd',
                    action='store_true',
                    default=False,
                    help='do not start fluentd, no log streaming')

    gp.add_argument('--workspace',
                    type=str,
                    default='/tmp/jinad',
                    help='the directory for storing all uploaded dependencies')
Esempio n. 15
0
def mixin_remote_runtime_parser(parser):
    """Add the options for a remote Executor
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='RemoteRuntime')
    _add_host(gp)

    gp.add_argument(
        '--port-jinad',
        type=int,
        default=8000,
        help='The port of the remote machine for usage with JinaD.',
    )
Esempio n. 16
0
def mixin_graphql_parser(parser=None):
    """Add the options to rest server

    :param parser: the parser
    """

    gp = add_arg_group(parser, title='GraphQL')
    gp.add_argument(
        '--expose-graphql-endpoint',
        action='store_true',
        default=False,
        help='If set, /graphql endpoint is added to HTTP interface. ',
    )
Esempio n. 17
0
def mixin_remote_jinad_parser(parser):
    """Add the networking options for JinaD
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='RemoteJinad')
    _add_host(gp)

    gp.add_argument(
        '--port',
        type=int,
        default=8000,
        help='The port of the host exposed for connecting to.',
    )
Esempio n. 18
0
File: base.py Progetto: jina-ai/jina
def mixin_base_ppr_parser(parser):
    """Mixing in arguments required by pod/deployment/runtime module into the given parser.
    :param parser: the parser instance to which we add arguments
    """

    mixin_essential_parser(parser)

    gp = add_arg_group(parser, title='Base Deployment')

    gp.add_argument(
        '--extra-search-paths',
        type=str,
        default=[],
        nargs='*',
        help=
        'Extra search paths to be used when loading modules and finding YAML config files.'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )

    gp.add_argument(
        '--timeout-ctrl',
        type=int,
        default=int(os.getenv('JINA_DEFAULT_TIMEOUT_CTRL', '60')),
        help=
        'The timeout in milliseconds of the control request, -1 for waiting forever',
    )

    parser.add_argument(
        '--k8s-namespace',
        type=str,
        help=
        'Name of the namespace where Kubernetes deployment should be deployed, to be filled by flow name'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )

    gp.add_argument(
        '--polling',
        type=str,
        default=PollingType.ANY.name,
        help='''
    The polling strategy of the Deployment and its endpoints (when `shards>1`).
    Can be defined for all endpoints of a Deployment or by endpoint.
    Define per Deployment:
    - ANY: only one (whoever is idle) Pod polls the message
    - ALL: all Pods poll the message (like a broadcast)
    Define per Endpoint:
    JSON dict, {endpoint: PollingType}
    {'/custom': 'ALL', '/search': 'ANY', '*': 'ANY'}
    
    ''',
    )
Esempio n. 19
0
def mixin_daemon_parser(parser):
    """
    # noqa: DAR101
    # noqa: DAR102
    # noqa: DAR103
    """
    gp = add_arg_group(parser, title='Daemon')

    gp.add_argument(
        '--no-fluentd',
        action='store_true',
        default=False,
        help='do not start fluentd, no log streaming',
    )
Esempio n. 20
0
def mixin_prefetch_parser(parser=None):
    """Add the options for prefetching
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='Prefetch')

    gp.add_argument(
        '--prefetch',
        type=int,
        default=0,
        help='''
    Number of requests fetched from the client before feeding into the first Executor. 
    
    Used to control the speed of data input into a Flow. 0 disables prefetch (disabled by default)''',
    )
Esempio n. 21
0
def mixin_hw_base_parser(parser):
    """Add the arguments for hello world to the parser

    :param parser: the parser configure
    """
    gp = add_arg_group(parser, title='General')
    gp.add_argument(
        '--workdir',
        type=str,
        default=random_identity(),
        help='The workdir for hello-world demo'
        'all data, indices, shards and outputs will be saved there',
    )
    gp.add_argument(
        '--download-proxy', type=str, help='The proxy when downloading sample data'
    )
Esempio n. 22
0
File: new.py Progetto: srbhr/jina
def mixin_hub_new_parser(parser):
    """Add the arguments for hub new to the parser
    :param parser: the parser configure
    """
    gp = add_arg_group(parser, title='Create Executor')
    gp.add_argument(
        '--name',
        help='the name of the Executor',
        type=str,
    )

    gp.add_argument(
        '--path',
        help='the path to store the Executor',
        type=str,
    )

    gp.add_argument(
        '--advance-configuration',
        help='If set, always set up advance configuration like description, keywords and url',
        action='store_true',
    )

    gp.add_argument(
        '--description',
        help='the short description of the Executor',
        type=str,
    )

    gp.add_argument(
        '--keywords',
        help='some keywords to help people search your Executor (separated by comma)',
        type=str,
    )

    gp.add_argument(
        '--url',
        help='the URL of your GitHub repo',
        type=str,
    )

    gp.add_argument(
        '--add-dockerfile',
        help='If set, add a Dockerfile to the created Executor bundle',
        action='store_true',
    )
Esempio n. 23
0
File: pull.py Progetto: srbhr/jina
def mixin_hub_pull_options_parser(parser):
    """Add the arguments for hub pull options to the parser
    :param parser: the parser configure
    """

    gp = add_arg_group(parser, title='Pull')
    gp.add_argument(
        '--install-requirements',
        action='store_true',
        default=False,
        help=
        'If set, install `requirements.txt` in the Hub Executor bundle to local',
    ),
    gp.add_argument(
        '--force-update',
        '--force',
        action='store_true',
        default=False,
        help=
        'If set, always pull the latest Hub Executor bundle even it exists on local',
    )
Esempio n. 24
0
def mixin_client_gateway_parser(parser):
    """Add the options for the client connecting to the Gateway
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='ClientGateway')
    _add_host(gp)
    _add_proxy(gp)

    gp.add_argument(
        '--port',
        type=int,
        default=None,
        help='The port of the Gateway, which the client should connect to.',
    )

    gp.add_argument(
        '--tls',
        action='store_true',
        default=False,
        help='If set, connect to gateway using tls encryption',
    )
Esempio n. 25
0
def mixin_base_deployment_parser(parser):
    """Add mixin arguments required by :class:`BaseDeployment` into the given parser.

    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='Deployment')

    gp.add_argument(
        '--uses-before',
        type=str,
        help=
        'The executor attached after the Pods described by --uses, typically before sending to all '
        'shards, accepted type follows `--uses`',
    )
    gp.add_argument(
        '--uses-after',
        type=str,
        help=
        'The executor attached after the Pods described by --uses, typically used for receiving from '
        'all shards, accepted type follows `--uses`',
    )

    gp.add_argument(
        '--external',
        action='store_true',
        default=False,
        help=
        'The Deployment will be considered an external Deployment that has been started independently from the Flow.'
        'This Deployment will not be context managed by the Flow.',
    )

    # hidden CLI used for internal only

    gp.add_argument(
        '--deployment-role',
        type=DeploymentRoleType.from_string,
        choices=list(DeploymentRoleType),
        help='The role of this deployment in the flow'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
Esempio n. 26
0
File: head.py Progetto: srbhr/jina
def mixin_head_parser(parser):
    """Mixing in arguments required by head pods and runtimes into the given parser.
    :param parser: the parser instance to which we add arguments
    """

    gp = add_arg_group(parser, title='Head')

    gp.add_argument(
        '--uses-before-address',
        type=str,
        help='The address of the uses-before runtime',
    )

    gp.add_argument(
        '--uses-after-address',
        type=str,
        help='The address of the uses-before runtime',
    )

    gp.add_argument(
        '--connection-list',
        type=str,
        help='dictionary JSON with a list of connections to configure',
    )
Esempio n. 27
0
def mixin_base_pod_parser(parser):
    """Add mixin arguments required by :class:`BasePod` into the given parser.

    :param parser: the parser instance to which we add arguments
    """
    gp = add_arg_group(parser, title='Pod')

    gp.add_argument(
        '--uses-before',
        type=str,
        help=
        'The executor attached after the Peas described by --uses, typically before sending to all '
        'parallels, accepted type follows `--uses`',
    )
    gp.add_argument(
        '--uses-after',
        type=str,
        help=
        'The executor attached after the Peas described by --uses, typically used for receiving from '
        'all parallels, accepted type follows `--uses`',
    )
    gp.add_argument(
        '--parallel',
        '--shards',
        type=int,
        default=1,
        help='The number of parallel peas in the pod running at the same time, '
        '`port_in` and `port_out` will be set to random, '
        'and routers will be added automatically when necessary',
    )
    gp.add_argument(
        '--replicas',
        type=int,
        default=1,
        help='The number of replicas in the pod, '
        '`port_in` and `port_out` will be set to random, '
        'and routers will be added automatically when necessary',
    )
    gp.add_argument(
        '--polling',
        type=PollingType.from_string,
        choices=list(PollingType),
        default=PollingType.ANY,
        help='''
The polling strategy of the Pod (when `parallel>1`)
- ANY: only one (whoever is idle) Pea polls the message
- ALL: all Peas poll the message (like a broadcast)
''',
    )

    gp.add_argument(
        '--scheduling',
        type=SchedulerType.from_string,
        choices=list(SchedulerType),
        default=SchedulerType.LOAD_BALANCE,
        help='The strategy of scheduling workload among Peas',
    )

    gp.add_argument(
        '--external',
        action='store_true',
        default=False,
        help=
        'The Pod will be considered an external Pod that has been started independently from the Flow.'
        'This Pod will not be context managed by the Flow.',
    )

    gp.add_argument(
        '--peas-hosts',
        nargs='+',
        type=str,
        help='''The hosts of the peas when parallel greater than 1.
        Peas will be evenly distributed among the hosts. By default,
        peas are running on host provided by the argument ``host``''',
    )

    # hidden CLI used for internal only

    gp.add_argument(
        '--pod-role',
        type=PodRoleType.from_string,
        choices=list(PodRoleType),
        help='The role of this pod in the flow'
        if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )

    parser.add_argument(
        '--no-dynamic-routing',
        action='store_false',
        dest='dynamic_routing',
        default=True,
        help=
        'The Pod will setup the socket types of the HeadPea and TailPea depending on this argument.',
    )

    parser.add_argument(
        '--connect-to-predecessor',
        action='store_true',
        default=False,
        help=
        'The head Pea of this Pod will connect to the TailPea of the predecessor Pod.',
    )
Esempio n. 28
0
def mixin_remote_runtime_parser(parser):
    """Add the options for a remote Executor
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='RemoteRuntime')
    _add_host(gp)
Esempio n. 29
0
def mixin_gateway_parser(parser):
    """Add the options for remote expose at the Gateway
    :param parser: the parser
    """
    gp = add_arg_group(parser, title='Gateway')
    _add_host(gp)
    _add_proxy(gp)

    gp.add_argument(
        '--port-expose',
        type=int,
        dest='port',
        default=helper.random_port(),
        help=
        'The port that the gateway exposes for clients for GRPC connections.',
    )

    parser.add_argument(
        '--graph-description',
        type=str,
        help='Routing graph for the gateway',
        default='{}',
    )

    parser.add_argument(
        '--graph-conditions',
        type=str,
        help=
        'Dictionary stating which filtering conditions each Executor in the graph requires to receive Documents.',
        default='{}',
    )

    parser.add_argument(
        '--deployments-addresses',
        type=str,
        help='dictionary JSON with the input addresses of each Deployment',
        default='{}',
    )

    parser.add_argument(
        '--deployments-disable-reduce',
        type=str,
        help=
        'list JSON disabling the built-in merging mechanism for each Deployment listed',
        default='[]',
    )

    gp.add_argument(
        '--compression',
        choices=['NoCompression', 'Deflate', 'Gzip'],
        help=
        'The compression mechanism used when sending requests from the Head to the WorkerRuntimes. For more details, '
        'check https://grpc.github.io/grpc/python/grpc.html#compression.',
    )

    gp.add_argument(
        '--timeout-send',
        type=int,
        default=None,
        help=
        'The timeout in milliseconds used when sending data requests to Executors, -1 means no timeout, disabled by default',
    )
Esempio n. 30
0
def mixin_http_gateway_parser(parser=None):
    """Add the options to rest server

    :param parser: the parser
    """
    gp = add_arg_group(parser, title='HTTP Gateway')

    gp.add_argument(
        '--title',
        type=str,
        help=
        'The title of this HTTP server. It will be used in automatics docs such as Swagger UI.',
    )

    gp.add_argument(
        '--description',
        type=str,
        help=
        'The description of this HTTP server. It will be used in automatics docs such as Swagger UI.',
    )

    gp.add_argument(
        '--cors',
        action='store_true',
        default=False,
        help='''
        If set, a CORS middleware is added to FastAPI frontend to allow cross-origin access.
        ''',
    )

    gp.add_argument(
        '--no-debug-endpoints',
        action='store_true',
        default=False,
        help=
        'If set, `/status` `/post` endpoints are removed from HTTP interface. ',
    )

    gp.add_argument(
        '--no-crud-endpoints',
        action='store_true',
        default=False,
        help='''
        If set, `/index`, `/search`, `/update`, `/delete` endpoints are removed from HTTP interface.

        Any executor that has `@requests(on=...)` bind with those values will receive data requests.
        ''',
    )

    gp.add_argument(
        '--expose-endpoints',
        type=str,
        help='''
        A JSON string that represents a map from executor endpoints (`@requests(on=...)`) to HTTP endpoints.
        ''',
    )

    gp.add_argument(
        '--uvicorn-kwargs',
        action=KVAppendAction,
        metavar='KEY: VALUE',
        nargs='*',
        help='''
Dictionary of kwargs arguments that will be passed to Uvicorn server when starting the server

More details can be found in Uvicorn docs: https://www.uvicorn.org/settings/

''',
    )

    gp.add_argument(
        '--grpc-server-kwargs',
        action=KVAppendAction,
        metavar='KEY: VALUE',
        nargs='*',
        help='''
    Dictionary of kwargs arguments that will be passed to the grpc server when starting the server # todo update
    ''',
    )

    gp.add_argument(
        '--ssl-certfile',
        type=str,
        help='''
        the path to the certificate file
        ''',
        dest='ssl_certfile',
    )

    gp.add_argument(
        '--ssl-keyfile',
        type=str,
        help='''
        the path to the key file
        ''',
        dest='ssl_keyfile',
    )