def __init__(self, runtime): self.runtime = runtime self.options = runtime.options self.options.model_config = read_model_metadata_yaml( self.options.code_dir) self.logger = CMRunner._config_logger(runtime.options) self.verbose = runtime.options.verbose self.run_mode = RunMode(runtime.options.subparser_name) self.raw_arguments = sys.argv self.target_type = None self._resolve_target_type() self._resolve_class_labels() self._functional_pipelines = { (RunMode.FIT, RunLanguage.PYTHON): "python_fit.json.j2", (RunMode.FIT, RunLanguage.R): "r_fit.json.j2", } # require metadata for push mode if self.run_mode == RunMode.PUSH: get_metadata(self.options) if self.run_mode in [RunMode.FIT, RunMode.PUSH]: # always populate the validator, even if info isn't provided. If no info then the validators will be empty # and pass by default. self.schema_validator = SchemaValidator( self.options.model_config.get("typeSchema", {}) if self.options.model_config is not None else {}, self.options.disable_strict_validation, ) self._input_df = None
def __exit__(self, exc_type, exc_value, exc_traceback): if not exc_type: return True # no exception, just return if not self.options: # exception occurred before args were parsed return False # propagate exception further # log exception exc_msg_lines = traceback.format_exception(exc_type, exc_value, exc_traceback) exc_msg = "".join(exc_msg_lines) run_mode = RunMode(self.options.subparser_name) if (not hasattr(self.options, "show_stacktrace") or self.options.show_stacktrace or (run_mode == RunMode.SERVER and self.options.with_error_server)): logger.error(exc_msg) else: if exc_type == DrumCommonException: print(exc_value) return True else: return False if run_mode != RunMode.SERVER: # drum is not run in server mode return False # propagate exception further if getattr(self.options, "docker", None): # when run in docker mode, # drum is started from docker with the same options except `--docker`. # thus error server is started in docker as well. # return here two avoid starting error server 2nd time. return False # propagate exception further if not self.options.with_error_server: # force start is not set return False # propagate exception further if self.initialization_succeeded: # pipeline initialization was successful. # exceptions that occur during pipeline running # must be propagated further return False # propagate exception further # start 'error server' host_port_list = self.options.address.split(":", 1) host = host_port_list[0] port = int(host_port_list[1]) if len(host_port_list) == 2 else None with verbose_stdout(self.options.verbose): run_error_server(host, port, exc_value) return False # propagate exception further
def __init__(self, runtime): self.runtime = runtime self.options = runtime.options self.logger = CMRunner._config_logger(runtime.options) self.verbose = runtime.options.verbose self.run_mode = RunMode(runtime.options.subparser_name) self.raw_arguments = sys.argv self._functional_pipelines = { (RunMode.FIT, RunLanguage.PYTHON): "python_fit.json.j2", (RunMode.FIT, RunLanguage.R): "r_fit.json.j2", }
def __init__(self, runtime): self.runtime = runtime self.options = runtime.options self.options.model_config = read_model_metadata_yaml( self.options.code_dir) self.logger = CMRunner._config_logger(runtime.options) self.verbose = runtime.options.verbose self.run_mode = RunMode(runtime.options.subparser_name) self.raw_arguments = sys.argv self.target_type = None self._resolve_target_type() self._functional_pipelines = { (RunMode.FIT, RunLanguage.PYTHON): "python_fit.json.j2", (RunMode.FIT, RunLanguage.R): "r_fit.json.j2", }
def __init__(self, runtime): self.runtime = runtime self.options = runtime.options self.logger = CMRunner._config_logger(runtime.options) self.verbose = runtime.options.verbose self.run_mode = RunMode(runtime.options.subparser_name) self._functional_pipelines = { (RunMode.SCORE, RunLanguage.PYTHON): "python_predictor.json.j2", (RunMode.SERVER, RunLanguage.PYTHON): "python_predictor_for_server.json.j2", (RunMode.SCORE, RunLanguage.R): "r_predictor.json.j2", (RunMode.SERVER, RunLanguage.R): "r_predictor_for_server.json.j2", (RunMode.SCORE, RunLanguage.JAVA): "java_predictor.json.j2", (RunMode.SERVER, RunLanguage.JAVA): "java_predictor_for_server.json.j2", (RunMode.FIT, RunLanguage.PYTHON): "python_fit.json.j2", }
def signal_handler(sig, frame): # The signal is assigned so the stacktrace is not presented when Ctrl-C is pressed. # The cleanup itself is done only if we are NOT running in performance test mode which # has its own cleanup print("\nCtrl+C pressed, aborting drum") if (runtime.options and runtime.options.docker and RunMode( runtime.options.subparser_name) == RunMode.SERVER): try: import requests except ImportError: print( "WARNING: 'requests' package is not found - " "cannot send shutdown to server", file=sys.stderr, ) else: url = "http://{}/shutdown/".format(runtime.options.address) print("Sending shutdown to server: {}".format(url)) requests.post(url, timeout=2) os._exit(130)
def __exit__(self, exc_type, exc_value, exc_traceback): if not exc_type: return True # no exception, just return if not self.options: # exception occurred before args were parsed return False # propagate exception further run_mode = RunMode(self.options.subparser_name) if run_mode != RunMode.SERVER: # drum is not run in server mode return False # propagate exception further # TODO: add docker support if getattr(self.options, "docker", None): # running 'error server' in docker mode is not supported return False # propagate exception further if not self.options.with_error_server: # force start is not set return False # propagate exception further if self.initialization_succeeded: # pipeline initialization was successful. # exceptions that occur during pipeline running # must be propagated further return False # propagate exception further # start 'error server' host_port_list = self.options.address.split(":", 1) host = host_port_list[0] port = int(host_port_list[1]) if len(host_port_list) == 2 else None with verbose_stdout(self.options.verbose): run_error_server(host, port, exc_value) return False # propagate exception further