def naked_main(): command_class = determine_command() parsed_args = parse_arguments(command_class) settings = load_settings(command_class.name, parsed_args) logging.config.dictConfig(settings.get('logging', defaults.DEFAULT_LOGGING_CONFIG)) initialize_metrics(settings) injector = initialize_injector(settings, command_class) flow.util.stats.increment_as_user('command', command_class.name) # XXX Hack to get the command to show up in the rabbitmq admin interface pika.connection.PRODUCT = command_class.name try: LOG.info('Loading command (%s)', command_class.name) command = injector.get(command_class) except: LOG.exception('Could not instantiate command object.') return flow.exit_codes.EXECUTE_ERROR try: exit_code = command.execute(parsed_args) except: LOG.exception('Command execution failed') return flow.exit_codes.EXECUTE_FAILURE exit_process(exit_code)
def _handle_message(self, message): try: self._handle_historian_message(message) return defer.succeed(None) except EXIT_ON: LOG.exception("This historian cannot handle messages anymore, " "because it lost access to Oracle... exiting.") exit_process(exit_codes.EXECUTE_FAILURE)
def _on_results(self, block, parsed_arguments, workflow, net, _execute_deferred): LOG.debug('Workflow execution done, block = %s', block) if block: if self.complete(): self.write_outputs(net, workflow.child_adapter.operation_id, workflow.output_properties, parsed_arguments.outputs_file) else: LOG.info('Workflow execution failed.') exit_process(exit_codes.EXECUTE_FAILURE) _execute_deferred.callback(None) return block
def _on_connectTCP_failed(self, reason): LOG.warning("Attempt %d to connect to AMQP server failed: %s", self._connection_attempts, reason) max_attempts = self.connection_params.connection_attempts if self._connection_attempts >= max_attempts: self.state = DISCONNECTED LOG.critical('Maximum number of connection attempts (%d) ' 'reached... shutting down', max_attempts) exit_process(EXECUTE_SERVICE_UNAVAILABLE) else: LOG.info("Attempting to reconnect to the AMQP " "server in %s seconds", self.connection_params.retry_delay) reactor.callLater(self.connection_params.retry_delay, self._attempt_to_connect)
def _execute(self, parsed_arguments): LOG.info("Begin LSF post exec") stat = os.environ.get('LSB_JOBEXIT_STAT', None) if stat is None: LOG.critical("LSB_JOBEXIT_STAT environment variable wasn't " "set... exiting!") exit_process(exit_codes.EXECUTE_ERROR) else: stat = int(stat) # we don't currently do migrating/checkpointing/requing so we're not # going to check for those posibilities. Instead we will assume that # the job has failed. if stat != 0: exit_code = stat >> 8 signal_number = stat & 255 token_data = { 'exit_code': exit_code, 'signal_number': signal_number, } LOG.debug( 'Job exitted with code (%s) and signal (%s) owner (%s) uid (%s)', exit_code, signal_number, pwd.getpwuid(os.getuid())[0], os.getuid()) info = os.environ.get('LSB_JOBEXIT_INFO', None) if info: LOG.info('Job exitted with LSF info: %s', info) deferred = self.orchestrator.create_token( net_key=parsed_arguments.net_key, place_idx=parsed_arguments.execute_failure, color=parsed_arguments.color, color_group_idx=parsed_arguments.color_group_idx, data=token_data) else: LOG.debug("Process exited normally") deferred = self.orchestrator.create_token( net_key=parsed_arguments.net_key, place_idx=parsed_arguments.execute_success, color=parsed_arguments.color, color_group_idx=parsed_arguments.color_group_idx) return deferred
def launch(request): reply = create_reply() try: submit_result = lsf.lsb_submit(request, reply) except: LOG.exception() raise if submit_result > 0: LOG.debug('Successfully submitted lsf job: %s', submit_result) return submit_result else: lsf.lsb_perror("lsb_submit") LOG.error('Failed to submit lsf job, return value = (%s), err = %s', submit_result, lsf.lsb_sperror("lsb_submit")) exit_process(exit_codes.EXECUTE_FAILURE)
def _exit(self, error): LOG.critical("Unexepected error in configurerabbitmq.\n%s", error.getTraceback()) exit_process(exit_codes.EXECUTE_FAILURE)
def _exit(self, error, **kwargs): LOG.critical("Unexpected error with kwargs: %s\n%s", kwargs, error.getTraceback()) exit_process(EXECUTE_SYSTEM_FAILURE)
def _handler(signum, frame): LOG.critical('Received signal %d: %s', signum, frame) exit_process(exit_codes.UNKNOWN_ERROR, child_signals=child_signals)
def _on_net_started_failed(self, error): LOG.critical("Failed to start net\n%s", error.getTraceback()) exit_process(EXECUTE_ERROR)
def _on_results_failed(self, error): LOG.critical("Failed to get results\n%s", error.getTraceback()) exit_process(EXECUTE_ERROR)
def catch_errors_and_crash(error): LOG.critical("Unexpected error in amqp_broker's channel facade.\n%s", error.getTraceback()) exit_process(EXECUTE_ERROR)
def _exit(self, error): LOG.critical("Unexpected error in workflow-wrapper:\n%s", error.getTraceback()) exit_process(EXECUTE_ERROR)
def _on_pika_connection_closed(self, connection, reply_code, reply_text): LOG.info('Connection closed with code %s: %s', reply_code, reply_text) self.state = DISCONNECTED exit_process(EXECUTE_SYSTEM_FAILURE)
def _exit(self, error, msg="Unexpected error"): LOG.critical("%s\n%s", msg, error.getTraceback()) exit_process(EXECUTE_ERROR)