[docs]defdeployment(args:'Namespace'):""" Start a Deployment :param args: arguments coming from the CLI. """fromjina.orchestrate.deploymentsimportDeploymenttry:withDeployment(args)asd:d.join()exceptKeyboardInterrupt:pass
[docs]defpod(args:'Namespace'):""" Start a Pod :param args: arguments coming from the CLI. """fromjina.orchestrate.pods.factoryimportPodFactorytry:withPodFactory.build_pod(args)asp:p.join()exceptKeyboardInterrupt:pass
[docs]defexecutor_native(args:'Namespace'):""" Starts an Executor in a WorkerRuntime :param args: arguments coming from the CLI. """ifargs.runtime_cls=='WorkerRuntime':fromjina.serve.runtimes.workerimportWorkerRuntimeruntime_cls=WorkerRuntimeelifargs.runtime_cls=='HeadRuntime':fromjina.serve.runtimes.headimportHeadRuntimeruntime_cls=HeadRuntimeelse:raiseRuntimeError(f' runtime_cls {args.runtime_cls} is not supported with `--native` argument. `WorkerRuntime` is supported')withruntime_cls(args)asrt:name=(rt._data_request_handler._executor.metas.nameifhasattr(rt,'_data_request_handler')elsert.name)rt.logger.success(f' Executor {name} started')rt.run_forever()
[docs]defexecutor(args:'Namespace'):""" Starts an Executor in any Runtime :param args: arguments coming from the CLI. :returns: return the same as `pod` or `worker_runtime` """ifargs.native:returnexecutor_native(args)else:returnpod(args)
[docs]defworker_runtime(args:'Namespace'):""" Starts a WorkerRuntime :param args: arguments coming from the CLI. """fromjina.serve.runtimes.workerimportWorkerRuntimewithWorkerRuntime(args)asruntime:runtime.logger.success(f' Executor {runtime._data_request_handler._executor.metas.name} started')runtime.run_forever()
[docs]defgateway(args:'Namespace'):""" Start a Gateway Deployment :param args: arguments coming from the CLI. """fromjina.enumsimportGatewayProtocolTypefromjina.serve.runtimesimportget_runtimegateway_runtime_dict={GatewayProtocolType.GRPC:'GRPCGatewayRuntime',GatewayProtocolType.WEBSOCKET:'WebSocketGatewayRuntime',GatewayProtocolType.HTTP:'HTTPGatewayRuntime',}runtime_cls=get_runtime(gateway_runtime_dict[args.protocol])withruntime_cls(args)asruntime:runtime.logger.success(f' Gateway with protocol {gateway_runtime_dict[args.protocol]} started')runtime.run_forever()
[docs]defping(args:'Namespace'):""" Check the connectivity of a Pod :param args: arguments coming from the CLI. """fromjina.checkerimportNetworkCheckerNetworkChecker(args)
[docs]defclient(args:'Namespace'):""" Start a client connects to the gateway :param args: arguments coming from the CLI. """fromjina.clientsimportClientClient(args)
[docs]defexport_api(args:'Namespace'):""" Export the API :param args: arguments coming from the CLI. """importjsonfromcli.exportimportapi_to_dictfromjina.jamlimportJAMLfromjinaimport__version__fromjina.logging.predefinedimportdefault_loggerfromjina.schemasimportget_full_schemaifargs.yaml_path:dump_api=api_to_dict()forypinargs.yaml_path:f_name=(yp%__version__)if'%s'inypelseypwithopen(f_name,'w',encoding='utf8')asfp:JAML.dump(dump_api,fp)default_logger.info(f'API is exported to {f_name}')ifargs.json_path:dump_api=api_to_dict()forjpinargs.json_path:f_name=(jp%__version__)if'%s'injpelsejpwithopen(f_name,'w',encoding='utf8')asfp:json.dump(dump_api,fp,sort_keys=True)default_logger.info(f'API is exported to {f_name}')ifargs.schema_path:dump_api=get_full_schema()forjpinargs.schema_path:f_name=(jp%__version__)if'%s'injpelsejpwithopen(f_name,'w',encoding='utf8')asfp:json.dump(dump_api,fp,sort_keys=True)default_logger.info(f'API is exported to {f_name}')
[docs]defhello(args:'Namespace'):""" Run any of the hello world examples :param args: arguments coming from the CLI. """ifargs.hello=='fashion':fromjina.helloworld.fashion.appimporthello_worldhello_world(args)elifargs.hello=='chatbot':fromjina.helloworld.chatbot.appimporthello_worldhello_world(args)elifargs.hello=='multimodal':fromjina.helloworld.multimodal.appimporthello_worldhello_world(args)elifargs.hello=='fork':fromjina.helloworld.forkimportfork_hellofork_hello(args)else:raiseValueError(f'must be one of [`fashion`, `chatbot`, `multimodal`, `fork`]')
[docs]defflow(args:'Namespace'):""" Start a Flow from a YAML file or a docker image :param args: arguments coming from the CLI. """fromjinaimportFlowifargs.uses:f=Flow.load_config(args.uses)withf:f.block()else:raiseValueError('start a flow from CLI requires a valid `--uses`')
[docs]defhub(args:'Namespace'):""" Start a hub builder for push, pull :param args: arguments coming from the CLI. """fromjina.hubble.hubioimportHubIOgetattr(HubIO(args),args.hub)()
[docs]defnew(args:'Namespace'):""" Create a new jina project :param args: arguments coming from the CLI. """importshutil,osfromjinaimport__resources_path__shutil.copytree(os.path.join(__resources_path__,'project-template'),os.path.abspath(args.name))
[docs]defhelp(args:'Namespace'):""" Lookup the usage of certain argument in Jina API. :param args: arguments coming from the CLI. """fromcli.lookupimportlookup_and_printlookup_and_print(args.query.lower())