Ejemplo n.º 1
0
def overview():
    if request.method == 'GET':
        # reload, cleanup might delete jsons while webserver is running
        simulations = load_simulations(sims_path)
        deadline = to_esmf(datetime.now() - timedelta(seconds=5))
        # only update stale & running simulations in overview
        kk = simulations.keys()
        for sim_id in kk:
            sim = simulations[sim_id]
            if sim['state']['wrf'] != 'complete':
                last_upd = sim.get('last_updated', '2000-01-01_00:00:00')
                if last_upd < deadline:
                    sim['state'] = get_simulation_state(sim['log_file'])
                    sim['last_updated'] = to_esmf(datetime.now())
                    f = sims_path + '/' + sim_id + '.json'
                    if osp.isfile(f):
                        json.dump(sim,
                                  open(f, 'w'),
                                  indent=4,
                                  separators=(',', ': '))
                        simulations[sim_id] = sim
                    else:
                        print('File %s no longer exists, deleting simulation' %
                              f)
                        del simulations[sim_id]
        return render_template('overview.html',
                               simulations=simulations,
                               urls=urls)
    elif request.method == 'POST':
        print 'Values returned by overview page:'
        sims_checked = request.form.getlist('sim_chk')
        print(sims_checked)
        for sim_id in sims_checked:  # Only the simulation(s) checked in checkbox.
            if 'RemoveB' in request.form:
                print('Remove Sim: box checked= %s' % (sim_id))
                cleanup_delete(sim_id)
            else:
                if 'CancelB' in request.form:
                    print('Cancel Sim: box checked= %s' % (sim_id))
                    cleanup_cancel(sim_id)
                else:
                    print('Error-No button push detected: box checked= %s' %
                          (sim_id))
        simulations = load_simulations(sims_path)
        return render_template('overview.html',
                               simulations=simulations,
                               urls=urls)
Ejemplo n.º 2
0
def cleanup_workspace(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Cleanup workspace for %s' % sim_id)
        sim_info = simulations[sim_id]
        cleanup_sim_workspace(sim_info, conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
Ejemplo n.º 3
0
def cleanup_cancel(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Canceling simulation %s' % sim_id)
        sim_info = simulations[sim_id]
        cancel_simulation(sim_info, conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
Ejemplo n.º 4
0
def cleanup_workspace(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Cleanup workspace for %s' % sim_id)
        sim_info = simulations[sim_id]
        cleanup_sim_workspace(sim_info,conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
Ejemplo n.º 5
0
def cleanup_cancel(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Canceling simulation %s' % sim_id)
        sim_info = simulations[sim_id]
        cancel_simulation(sim_info,conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
Ejemplo n.º 6
0
def cleanup_delete(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Deleting simulation %s' % sim_id)
        sim_info = simulations[sim_id]
        delete_simulation(sim_info, conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
        delete_simulation_files(sim_id, conf)  # rm any stray files
Ejemplo n.º 7
0
def cleanup_delete(sim_id):
    simulations = load_simulations(sims_path)
    try:
        logging.info('Deleting simulation %s' % sim_id)
        sim_info = simulations[sim_id]
        delete_simulation(sim_info,conf)
    except KeyError:
        logging.error('Simulation %s not found.' % sim_id)
        delete_simulation_files(sim_id,conf) # rm any stray files
Ejemplo n.º 8
0
def overview():
    if request.method == 'GET':
        # reload, cleanup might delete jsons while webserver is running 
        simulations = load_simulations(sims_path)
        deadline = to_esmf(datetime.now() - timedelta(seconds=5))
        # only update stale & running simulations in overview
        kk = simulations.keys()   
        for sim_id in kk:
            sim = simulations[sim_id]
            if sim['state']['wrf'] != 'complete':
                last_upd = sim.get('last_updated', '2000-01-01_00:00:00')
                if last_upd < deadline:
                    sim['state'] = get_simulation_state(sim['log_file'])
                    sim['last_updated'] = to_esmf(datetime.now())
                    f = sims_path + '/' + sim_id + '.json'
                    if osp.isfile(f):
                        json.dump(sim, open(f,'w'), indent=4, separators=(',', ': '))
                        simulations[sim_id]=sim
                    else:
                        print('File %s no longer exists, deleting simulation' % f)
                        del simulations[sim_id]
        return render_template('overview.html', simulations = simulations, urls=urls)
    elif request.method == 'POST':
        print 'Values returned by overview page:'
        sims_checked= request.form.getlist('sim_chk')
        print (sims_checked)
        for sim_id in sims_checked:  # Only the simulation(s) checked in checkbox.
            if 'RemoveB' in request.form:
                print ('Remove Sim: box checked= %s' % (sim_id)) 
                cleanup_delete(sim_id)
            else:
                if 'CancelB' in request.form:
                    print ('Cancel Sim: box checked= %s' % (sim_id))
                    cleanup_cancel(sim_id)
                else:
                    print ('Error-No button push detected: box checked= %s' % (sim_id))
        simulations = load_simulations(sims_path)
        return render_template('overview.html', simulations = simulations, urls=urls)
Ejemplo n.º 9
0
def cleanup_list():
    simulations = load_simulations(sims_path)
    print('%-30s desc' % 'id')
    print('-' * 40)
    for k in sorted(simulations):
        print('%-30s %s' % (k, simulations[k]['description']))
Ejemplo n.º 10
0
def cleanup_list():
    simulations = load_simulations(sims_path)
    print('%-30s desc' % 'id') 
    print('-' * 40)
    for k in sorted(simulations):
        print('%-30s %s' % (k, simulations[k]['description']))
Ejemplo n.º 11
0
import stat
import os.path as osp
from subprocess import Popen
from functools import wraps, update_wrapper
import sys
from cleanup import cleanup_delete, cleanup_cancel

# global objects tracking state
cluster = None
simulations = {}
profiles = None

#conf params and state
conf = load_sys_cfg()
sims_path = conf['sims_path']
simulations = load_simulations(sims_path)

root = conf['root']
host = conf['host']
debug = conf['debug'] in ['T' 'True' 't' 'true']
port=conf['port']
urls = {'submit': root+'/submit', 'welcome': root+'/start', 'overview': root+'/overview'}
print ('Welcome page is http://%s:%s%s' % (host, port, urls['welcome']) )

app = Flask(__name__)

# lifted from: http://arusahni.net/blog/2014/03/flask-nocache.html
def nocache(view):
    @wraps(view)
    def no_cache(*args, **kwargs):
        response = make_response(view(*args, **kwargs))
Ejemplo n.º 12
0
import stat
import os.path as osp
from subprocess import Popen
from functools import wraps, update_wrapper
import sys
from cleanup import cleanup_delete, cleanup_cancel

# global objects tracking state
cluster = None
simulations = {}
profiles = None

#conf params and state
conf = load_sys_cfg()
sims_path = conf['sims_path']
simulations = load_simulations(sims_path)

root = conf['root']
host = conf['host']
debug = conf['debug'] in ['T' 'True' 't' 'true']
port = conf['port']
urls = {
    'submit': root + '/submit',
    'welcome': root + '/start',
    'overview': root + '/overview'
}
print('Welcome page is http://%s:%s%s' % (host, port, urls['welcome']))

app = Flask(__name__)