def job(environment_id, job_id): session = get_db_session() environ = session.query(Environment).get(environment_id) job = session.query(Job).get(job_id) helper = FabricHelper(environ.execute_path) error_message = None form = JobForm( name=job.name, description=job.description, environment_id=job.environment_id, tasks=job.tasks ) if not environ: abort(404) if form.validate_on_submit(): not_found_tasks = helper.get_tasks(form.tasks.data.split(' ')).get('not_found') if len(not_found_tasks) == 0: job.name = form.name.data job.description = form.description.data job.tasks = form.tasks.data job.environment = environ session.commit() return redirect(url_for('environment', environment_id=environment_id)) error_message = 'tasks [{0}] not found.'.format(','.join(not_found_tasks)) form.environment_id.data = environ.id return render_template('job.html', form=form, environ=environ, job=job, error_message=error_message)
def jobset(jobset_id): session = get_db_session() jobset = session.query(Jobset).get(jobset_id) return render_template('jobset.html', jobset=jobset, job_list=session.query(Job).all(), executelog_list=jobset.execute_logs[:10])
def get_execute_log(id): session = get_db_session() executelog = session.query(ExecuteLog).get(id) if not executelog.logfile: abort(404) with open(executelog.logfile, 'r') as f: logs = f.read() return Response(logs, mimetype='text/plain')
def list_jobsets(*args): from oozappa.records import Jobset, get_db_session session = get_db_session() jobset_list = session.query(Jobset).all() print('-' * 40) for jobset in jobset_list: print(u'|id:{0:03d}|CLI_ONLY:{1}|title:{2}|'.format(jobset.id, jobset.cli_only, jobset.title)) print('-' * 40)
def index(): session = get_db_session() jobset_list = session.query(Jobset).all() executelog_list = session.query(ExecuteLog).order_by( ExecuteLog.id.desc()).all()[:20] return render_template('index.html', jobset_list=jobset_list, executelog_list=executelog_list)
def run_jobset(ws): message = ws.receive() if not message: return lock = filelock.FileLock(LOCK_FILE_NAME) try: with lock.acquire(timeout=1): data = json.loads(message) jobset_id = data.get('jobset_id') session = get_db_session() jobset = session.query(Jobset).get(jobset_id) executelog = ExecuteLog() executelog.jobset = jobset session.add(executelog) session.commit() logfile = None if _settings.OOZAPPA_LOG: executelog.logfile = os.path.join(_settings.OOZAPPA_LOG_BASEDIR, '{0}.log'.format(uuid4().hex)) logfile = open(executelog.logfile, 'w') ws.send(json.dumps({'message_type': exec_fabric.PROGRESS_BEGIN})) for job in jobset.jobs: with exec_fabric(ws, job.environment.execute_path) as executor: if executor.doit(job.tasks.split(' '), logfile) != 0: executelog.success = False executelog.finished = datetime.now() session.commit() ws.send(json.dumps({'output': '\n \n \n'})) ws.send(json.dumps({'output': '=' * 35})) ws.send(json.dumps({'output': '\n'})) ws.send(json.dumps({'output': u'[Oozappa:FAILES] Jobset: {0} in {1} seconds.'.format(jobset.title, executelog.execute_time()).encode('utf8')})) ws.send(json.dumps({'output': '\n'})) ws.send(json.dumps({'output': '=' * 35})) ws.send(json.dumps({'output': '\n \n \n'})) ws.send(json.dumps({'message_type': exec_fabric.EXEC_FAILED})) break else: executelog.success = True executelog.finished = datetime.now() session.commit() ws.send(json.dumps({'output': '\n \n \n'})) ws.send(json.dumps({'output': '=' * 35})) ws.send(json.dumps({'output': '\n'})) ws.send(json.dumps({'output': u'[Oozappa:FINISHED] Jobset: {0} in {1} seconds.'.format(jobset.title, executelog.execute_time()).encode('utf8')})) ws.send(json.dumps({'output:': '\n'})) ws.send(json.dumps({'output': '=' * 35})) ws.send(json.dumps({'output': '\n \n \n'})) ws.send(json.dumps({'message_type': exec_fabric.EXEC_SUCESSFUL})) if logfile: logfile.close() except filelock.Timeout as err: ws.send(json.dumps({'output': ''' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Lock aquired another jobset from {0} !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '''.format(_locked_time())}))
def change_cli_flag(): from oozappa.records import Jobset, get_db_session session = get_db_session() list_jobsets() x = raw_input(u'Which Jobset id?') jobset = session.query(Jobset).get(x) if jobset: jobset.cli_only = not jobset.cli_only session.commit() list_jobsets()
def reorder_jobset(): if request.headers['Content-Type'] != 'application/json': print(request.headers['Content-Type']) return jsonify(res='error'), 400 jobset_id_ordered = [int(x) for x in urlparse.parse_qs(request.json).get('jobset[]', [])] session = get_db_session() for i, jobset_id in enumerate(jobset_id_ordered): _sort_order = i + 1 _jobset = session.query(Jobset).get(jobset_id) if _jobset.sort_order != _sort_order: _jobset.sort_order = _sort_order session.commit() return jsonify(res='ok')
def add_environment(): form = EnvironmentForm() if form.validate_on_submit(): session = get_db_session() #TODO environ = Environment() environ.name = form.name.data environ.sort_order = form.sort_order.data environ.execute_path = form.execute_path.data session.add(environ) session.commit() return redirect(url_for('environments')) return render_template('environment_list.html', form=form)
def create_jobset(): form = JobSetForm() form.job_id.choices = Job.choices() session = get_db_session() if form.validate_on_submit(): jobset = Jobset() jobset.title = form.title.data jobset.description = form.description.data session.add(jobset) for id in form.job_id.data: j = session.query(Job).get(id) jsl = JobsetJobList() jsl.jobset = jobset jsl.job = j session.add(jsl) session.commit() return redirect(url_for('jobsets')) return render_template('create_jobset.html', form=form, job_list=session.query(Job).all())
def jobsets(): session = get_db_session() jobset_list = session.query(Jobset).all() return render_template('jobset_list.html', jobset_list=jobset_list)
def environments(): session = get_db_session() environment_list = session.query(Environment).all() return render_template('environment_list.html', environment_list=environment_list, form=EnvironmentForm())
def index(): session = get_db_session() jobset_list = session.query(Jobset).all() executelog_list = session.query(ExecuteLog).order_by(ExecuteLog.id.desc()).all()[:20] return render_template('index.html', jobset_list=jobset_list, executelog_list=executelog_list)