Example #1
0
def acq_wakeup(wakeup_key):
    """- wake up and expire the session
    - acquire a mutex on the acquisition key
    - query for the instrument
    - run the copy job
    - schedule the accession job
    - wakeup accession workers"""
    # figure out if this wakeup matters to us
    if not is_acq_key(wakeup_key):
        return
    instrument_name = get_instrument_name(wakeup_key)
    # attempt to acquire mutex. if fails, that's fine,
    # that means acquisition is aready underway
    try:
        with Mutex(wakeup_key,ttl=45) as mutex:
            # get the instrument info
            session.expire_all() # don't be stale!
            instrument = session.query(Instrument).\
                         filter(Instrument.name==instrument_name).\
                         first()
            if instrument is None:
                logging.warn('ERROR cannot find instrument named "%s"' % instrument_name)
                return
            ts_label = instrument.time_series.label
            logging.warn('%s: starting acquisition cycle' % instrument_name)
            def callback(lid):
                logging.warn('%s: copied %s from %s' % (ts_label, lid, instrument_name))
                mutex.heartbeat() # still alive
                # schedule an accession job and wake up accession workers
                pid = '%s%s/%s' % (URL_PREFIX, ts_label, lid)
                schedule_accession(client,pid)
                client.wakeup()
                logging.warn('%s: scheduled accession for %s' % (ts_label, lid))
            copy_work(instrument, callback=callback)
            logging.warn('%s: acquisition cycle complete' % ts_label)
    except Busy:
        pass
import sys

from oii.ifcb2.session import session
from oii.ifcb2.orm import TimeSeries, Bin

if len(sys.argv) < 2:
    print "no time series label specified"
    sys.exit(-1)
else:
    LABEL = sys.argv[1]

# clean up dashboard database
ts = session.query(TimeSeries).filter(TimeSeries.label == LABEL).first()
if ts is not None:
    session.delete(ts)

for b in session.query(Bin).filter(Bin.ts_label == LABEL):
    session.delete(b)

session.commit()

# now clean up workflow database
from dashboard_conf import DASHBOARD_BASE_URL, WORKFLOW_DATABASE_URL
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

from oii.workflow import orm as worm

dbengine = create_engine(WORKFLOW_DATABASE_URL)
worm.Base.metadata.create_all(dbengine)
session = scoped_session(sessionmaker(bind=dbengine))()
Example #3
0
import sys

from oii.ifcb2.session import session
from oii.ifcb2.orm import TimeSeries, Bin

if len(sys.argv) < 2:
   print 'no time series label specified'
   sys.exit(-1)
else:
   LABEL = sys.argv[1]

# clean up dashboard database
ts = session.query(TimeSeries).filter(TimeSeries.label==LABEL).first()
if ts is not None:
    session.delete(ts)

for b in session.query(Bin).filter(Bin.ts_label==LABEL):
    session.delete(b)

session.commit()

# now clean up workflow database
from dashboard_conf import DASHBOARD_BASE_URL, WORKFLOW_DATABASE_URL
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

from oii.workflow import orm as worm

dbengine = create_engine(WORKFLOW_DATABASE_URL)
worm.Base.metadata.create_all(dbengine)
session = scoped_session(sessionmaker(bind=dbengine))()
Example #4
0
from oii.utils import gen_id

from oii.ifcb2.session import dbengine, session
from oii.ifcb2.orm import User, Role

from oii.ifcb2.dashboard.flasksetup import user_manager

if __name__=='__main__':
    print 'Searching for default admin user in database ...'
    user = session.query(User).filter_by(email='*****@*****.**').first()
    if user is not None:
        print 'Found user. Deleting ...'
        session.delete(user)
        session.commit()
    else:
        print 'Not found.'
    print 'Creating recovery user/password ...'
    username = '******'
    password = gen_id()[:8]
    u = User(
        first_name='Admin',
        last_name='User',
        email=username,
        username=username,
        password=user_manager.hash_password(password),
        is_enabled=True
    )
    r = session.query(Role).filter_by(name='Admin').first()
    u.roles.append(r)
    session.add(u)
    session.commit()
Example #5
0
from oii.ifcb2.session import dbengine, session
from oii.ifcb2.orm import User, Role

from oii.ifcb2.dashboard.flasksetup import user_manager

if __name__ == '__main__':
    try:
        password = sys.argv[1]
    except IndexError:
        password = gen_id()[:8]
    try:
        email = sys.argv[2]
    except IndexError:
        email = '*****@*****.**'
    user = session.query(User).filter_by(email=email).first()
    if user is not None:
        session.delete(user)
        session.commit()
    u = User(first_name='Admin',
             last_name='User',
             email=email,
             username=email,
             password=user_manager.hash_password(password),
             is_enabled=True)
    r = session.query(Role).filter_by(name='Admin').first()
    u.roles.append(r)
    session.add(u)
    session.commit()
    print "%s|%s" % (email, password)
from oii.ifcb2.session import dbengine, session
from oii.ifcb2.orm import User, Role

from oii.ifcb2.dashboard.flasksetup import user_manager

if __name__=='__main__':
    try:
        password = sys.argv[1]
    except IndexError:
        password = gen_id()[:8]
    try:
        email = sys.argv[2]
    except IndexError:
        email = '*****@*****.**'
    user = session.query(User).filter_by(email=email).first()
    if user is not None:
        session.delete(user)
        session.commit()
    u = User(
        first_name='Admin',
        last_name='User',
        email=email,
        username=email,
        password=user_manager.hash_password(password),
        is_enabled=True
    )
    r = session.query(Role).filter_by(name='Admin').first()
    u.roles.append(r)
    session.add(u)
    session.commit()