def dispatch(self): db_session = DBSession() try: # Check if Scheduled Installs are allowed to run. if not db_session.query(SystemOption).first().can_install: return install_jobs = db_session.query(InstallJob).filter( InstallJob.scheduled_time <= datetime.datetime.utcnow()).order_by(InstallJob.scheduled_time.asc()).all() download_job_key_dict = get_download_job_key_dict() if len(install_jobs) > 0: for install_job in install_jobs: if install_job.status != JobStatus.FAILED: # If there is pending download, don't submit the install job if self.is_pending_on_download(download_job_key_dict, install_job): continue # This install job has a dependency, check if the expected criteria is met if install_job.dependency is not None: dependency_completed = self.get_install_job_dependency_completed(db_session, install_job) # If the dependency has not been completed, don't proceed if len(dependency_completed) == 0: continue self.submit_job(InstallWorkUnit(install_job.host_id, install_job.id)) except Exception: # print(traceback.format_exc()) # Purpose ignore. Otherwise, it may generate continue exception pass finally: db_session.close()
def dispatch(self): db_session = DBSession() try: # Check if Scheduled Installs are allowed to run. if not db_session.query(SystemOption).first().can_install: return install_jobs = db_session.query(InstallJob).filter( InstallJob.scheduled_time <= datetime.datetime.utcnow()).all() download_job_key_dict = get_download_job_key_dict() if len(install_jobs) > 0: for install_job in install_jobs: if install_job.status != JobStatus.FAILED: # If there is pending download, don't submit the install job if self.is_pending_on_download(download_job_key_dict, install_job): continue # This install job has a dependency, check if the expected criteria is met if install_job.dependency is not None: dependency_completed = self.get_install_job_dependency_completed(db_session, install_job) # If the dependency has not been completed, don't proceed if len(dependency_completed) == 0: continue self.submit_job(InstallWorkUnit(install_job.host_id, install_job.id)) except Exception: # print(traceback.format_exc()) # Purpose ignore. Otherwise, it may generate continue exception pass finally: db_session.close()
def is_pending_on_download(db_session, filename, server_id, server_directory): download_job_key_dict = get_download_job_key_dict() download_job_key = get_download_job_key(current_user.id, filename, server_id, server_directory) if download_job_key in download_job_key_dict: download_job = download_job_key_dict[download_job_key] # Resurrect the download job if download_job is not None and download_job.status == JobStatus.FAILED: download_job.status = None download_job.status_time = None db_session.commit() return True return False
def dispatch(self): db_session = DBSession() try: # Check if Scheduled Installs are allowed to run. if not can_install(db_session): return resultSet = db_session.query(InstallJob).filter( InstallJob.scheduled_time <= datetime.datetime.utcnow()).all() download_job_key_dict = get_download_job_key_dict() if len(resultSet) > 0: for install_job in resultSet: if install_job.status != JobStatus.FAILED: # If there is pending download, don't submit the install job if is_pending_on_download(download_job_key_dict, install_job): continue # This install job has a dependency, check if the expected criteria is met if install_job.dependency is not None: dependency_completed = self.get_install_job_dependency_completed( db_session, install_job) # If the dependency has not been completed, don't proceed if len(dependency_completed) == 0: continue with lock: # If another install job for the same host is already in progress, # the install job will not be queued for processing if install_job.host_id in in_progress_hosts: continue in_progress_hosts.append(install_job.host_id) # Allow the install job to proceed install_work_unit = InstallWorkUnit( install_job.id, install_job.host_id) self.pool.submit(install_work_unit) except: # Purpose ignore. Otherwise, it may generate continue exception pass finally: db_session.close()
def get_install_job_json_dict(install_jobs): """ install_jobs is a list of install_job instances from the install_job or install_job_history table. Schema in the install_job_history table is a superset of the install_job table. """ download_job_key_dict = get_download_job_key_dict() rows = [] for install_job in install_jobs: if isinstance(install_job, InstallJob) or isinstance( install_job, InstallJobHistory): row = dict() row['install_job_id'] = install_job.id row['hostname'] = install_job.host.hostname row['dependency'] = '' if install_job.dependency is None else 'Another Installation' row['install_action'] = install_job.install_action row['scheduled_time'] = install_job.scheduled_time # Retrieve the pending download status of the scheduled download job. # The install job has not been started if its status is None. if install_job.status is None: row['dependency'] = get_download_job_status( download_job_key_dict, install_job, row['dependency']) row['start_time'] = install_job.start_time row['packages'] = install_job.packages if isinstance(install_job, InstallJob): row['server_id'] = install_job.server_id row['server_directory'] = install_job.server_directory row['user_id'] = install_job.user_id row['status'] = install_job.status row['status_time'] = install_job.status_time row['created_by'] = install_job.created_by if install_job.session_log is not None: row['session_log'] = install_job.session_log if install_job.trace is not None: row['trace'] = install_job.id rows.append(row) return {'data': rows}
def get_install_job_json_dict(install_jobs): """ install_jobs is a list of install_job instances from the install_job or install_job_history table. Schema in the install_job_history table is a superset of the install_job table. """ download_job_key_dict = get_download_job_key_dict() rows = [] for install_job in install_jobs: if isinstance(install_job, InstallJob) or isinstance(install_job, InstallJobHistory): row = dict() row['install_job_id'] = install_job.id row['hostname'] = install_job.host.hostname row['dependency'] = '' if install_job.dependency is None else 'Another Installation' row['install_action'] = install_job.install_action row['scheduled_time'] = install_job.scheduled_time # Retrieve the pending download status of the scheduled download job. # The install job has not been started if its status is None. if install_job.status is None: row['dependency'] = get_download_job_status(download_job_key_dict, install_job, row['dependency']) row['start_time'] = install_job.start_time row['packages'] = install_job.packages if isinstance(install_job, InstallJob): row['server_id'] = install_job.server_id row['server_directory'] = install_job.server_directory row['user_id'] = install_job.user_id row['status'] = install_job.status row['status_time'] = install_job.status_time row['created_by'] = install_job.created_by if install_job.session_log is not None: row['session_log'] = install_job.session_log if install_job.trace is not None: row['trace'] = install_job.id rows.append(row) return {'data': rows}
def dispatch(self): db_session = DBSession() try: # Check if Scheduled Installs are allowed to run. if not can_install(db_session): return resultSet = db_session.query(InstallJob).filter(InstallJob.scheduled_time <= datetime.datetime.utcnow()).all() download_job_key_dict = get_download_job_key_dict() if len(resultSet)> 0: for install_job in resultSet: if install_job.status != JobStatus.FAILED: # If there is pending download, don't submit the install job if is_pending_on_download(download_job_key_dict, install_job): continue # This install job has a dependency, check if the expected criteria is met if install_job.dependency is not None: dependency_completed = self.get_install_job_dependency_completed(db_session, install_job) # If the dependency has not been completed, don't proceed if len(dependency_completed) == 0: continue with lock: # If another install job for the same host is already in progress, # the install job will not be queued for processing if install_job.host_id in in_progress_hosts: continue in_progress_hosts.append(install_job.host_id) # Allow the install job to proceed install_work_unit = InstallWorkUnit(install_job.id, install_job.host_id) self.pool.submit(install_work_unit) except: # Purpose ignore. Otherwise, it may generate continue exception pass finally: db_session.close()