def process(self): db_session = DBSession() ctx = None try: install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first() if install_job is None: # This is normal because of race condition. It means the job is already deleted (completed). return if not can_install(db_session): # This will halt this host that has already been queued return host = db_session.query(Host).filter(Host.id == self.host_id).first() if host is None: logger.error('Unable to retrieve host %s', self.host_id) return handler_class = get_install_handler_class(host.platform) if handler_class is None: logger.error('Unable to get handler for %s, install job %s', host.platform, self.job_id) install_job.start_time = datetime.datetime.utcnow() install_job.set_status(JobStatus.PROCESSING) install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id) db_session.commit() ctx = InstallContext(host, db_session, install_job) ctx.operation_id = get_last_operation_id(db_session, install_job) handler = handler_class() handler.execute(ctx) if ctx.success: # Update the software self.get_software(db_session, ctx) archive_install_job(db_session, ctx, install_job, JobStatus.COMPLETED) else: archive_install_job(db_session, ctx, install_job, JobStatus.FAILED) db_session.commit() except: try: logger.exception('InstallManager hit exception - install job = %s', self.job_id) archive_install_job(db_session, ctx, install_job, JobStatus.FAILED, trace=traceback.format_exc()) db_session.commit() except: logger.exception('InstallManager hit exception - install job = %s', self.job_id) finally: # Must remove the host from the in progress list remove_host_from_in_progress(self.host_id) db_session.close()
def start(self, db_session, logger, process_name): ctx = None try: install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first() if install_job is None: # This is normal because of race condition. It means the job is already deleted (completed). return if not db_session.query(SystemOption).first().can_install: # This will halt this host that has already been queued return host = db_session.query(Host).filter(Host.id == self.host_id).first() if host is None: logger.error('Unable to retrieve host %s', self.host_id) return ctx = InstallContext(db_session, host, install_job) handler_class = get_install_handler_class(ctx) if handler_class is None: logger.error('Unable to get handler for %s, install job %s', host.software_platform, self.job_id) install_job.start_time = datetime.datetime.utcnow() install_job.set_status(JobStatus.PROCESSING) install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id) ctx.operation_id = self.get_last_operation_id(db_session, install_job) db_session.commit() handler = handler_class() handler.execute(ctx) if ctx.success: # Update the software self.get_software(ctx, logger) self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.COMPLETED, process_name) else: self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name) except Exception: try: logger.exception('InstallManager hit exception - install job = %s', self.job_id) self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name, trace=traceback.format_exc()) except Exception: logger.exception('InstallManager hit exception - install job = %s', self.job_id) finally: db_session.close()
def start(self, db_session, logger, process_name): ctx = None try: install_job = db_session.query(InstallJob).filter( InstallJob.id == self.job_id).first() if install_job is None: # This is normal because of race condition. It means the job is already deleted (completed). return if not db_session.query(SystemOption).first().can_install: # This will halt this host that has already been queued return host = db_session.query(Host).filter( Host.id == self.host_id).first() if host is None: logger.error('Unable to retrieve host %s', self.host_id) return ctx = InstallContext(db_session, host, install_job) handler_class = get_install_handler_class(ctx) if handler_class is None: logger.error('Unable to get handler for %s, install job %s', host.software_platform, self.job_id) install_job.start_time = datetime.datetime.utcnow() install_job.set_status(JobStatus.PROCESSING) install_job.session_log = create_log_directory( host.connection_param[0].host_or_ip, install_job.id) ctx.operation_id = self.get_last_operation_id( db_session, install_job) db_session.commit() handler = handler_class() handler.execute(ctx) if ctx.success: # Update the software self.get_software(ctx, logger) self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.COMPLETED, process_name) else: self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name) except Exception: try: logger.exception( 'InstallManager hit exception - install job = %s', self.job_id) self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name, trace=traceback.format_exc()) except Exception: logger.exception( 'InstallManager hit exception - install job = %s', self.job_id) finally: db_session.close()
def process(self): db_session = DBSession() ctx = None try: install_job = db_session.query(InstallJob).filter( InstallJob.id == self.job_id).first() if install_job is None: # This is normal because of race condition. It means the job is already deleted (completed). return if not can_install(db_session): # This will halt this host that has already been queued return host = db_session.query(Host).filter( Host.id == self.host_id).first() if host is None: logger.error('Unable to retrieve host %s', self.host_id) return handler_class = get_install_handler_class(host.platform) if handler_class is None: logger.error('Unable to get handler for %s, install job %s', host.platform, self.job_id) install_job.start_time = datetime.datetime.utcnow() install_job.set_status(JobStatus.PROCESSING) install_job.session_log = create_log_directory( host.connection_param[0].host_or_ip, install_job.id) db_session.commit() ctx = InstallContext(host, db_session, install_job) ctx.operation_id = get_last_operation_id(db_session, install_job) handler = handler_class() handler.execute(ctx) if ctx.success: # Update the software self.get_software(db_session, ctx) archive_install_job(db_session, ctx, install_job, JobStatus.COMPLETED) else: archive_install_job(db_session, ctx, install_job, JobStatus.FAILED) db_session.commit() except: try: logger.exception( 'InstallManager hit exception - install job = %s', self.job_id) archive_install_job(db_session, ctx, install_job, JobStatus.FAILED, trace=traceback.format_exc()) db_session.commit() except: logger.exception( 'InstallManager hit exception - install job = %s', self.job_id) finally: # Must remove the host from the in progress list remove_host_from_in_progress(self.host_id) db_session.close()