Example #1
0
def fdb_cluster():
    """
    Provision an fdb cluster for the entire test session, and call
    joshua_model.open() Tear down when the test session ends.
    """
    # Setup
    tmp_dir = tempfile.mkdtemp()
    port = getFreePort()
    cluster_file = os.path.join(tmp_dir, "fdb.cluster")
    with open(cluster_file, "w") as f:
        f.write("abdcefg:[email protected]:{}".format(port))
    proc = subprocess.Popen(
        ["fdbserver", "-p", "auto:{}".format(port), "-C", cluster_file],
        cwd=tmp_dir)

    subprocess.check_output(
        ["fdbcli", "-C", cluster_file, "--exec", "configure new single ssd"])

    joshua_model.open(cluster_file)
    yield cluster_file

    # Teardown
    proc.kill()
    proc.wait()
    shutil.rmtree(tmp_dir)
Example #2
0
def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    migrate.init_app(app, db)
    bootstrap.init_app(app)

    # Make sure cluster file is present
    if not os.path.exists(app.config['JOSHUA_FDB_CLUSTER_FILE']):
        raise Exception('JOSHUA_FDB_CLUSTER_FILE {} not found'.format(
            app.config['JOSHUA_FDB_CLUSTER_FILE']))
    joshua_model.open(app.config['JOSHUA_FDB_CLUSTER_FILE'],
                      (app.config['JOSHUA_NAMESPACE'], ))
    app.logger.info('Using cluster file: {}'.format(
        app.config['JOSHUA_FDB_CLUSTER_FILE']))

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))

    # blueprint for auth routes in our app
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    # blueprint for non-auth parts of app
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    # blueprint for REST APIs
    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')

    return app
Example #3
0
            'You have requested more Agents: {} than available CPUs: {} for system with {} CPUs and {} free CPUs.'
            .format(args.number, total_cpus - args.free_cpus, total_cpus,
                    args.free_cpus))

    if args.mgr_sleep <= 0:
        logger.info(
            'Hey slick, you must sleep some between checks: {} -> {}'.format(
                args.mgr_sleep, 1))
        args.mgr_sleep = 1

    if args.priority != 0:
        agent_pid = os.getpid()
        agent_process = psutil.Process(agent_pid)
        logger.info('Agent PID %6d  updating priority: %2d -> %2d ' %
                    (agent_pid, agent_process.nice(), args.priority))
        agent_process.nice(args.priority)

    # Initialize the agent variables
    children = {}

    # Initialize the joshua model
    joshua_model.open(args.cluster_file, (args.name_space,))

    # Manage and launch the agents
    manage_agents(total_cpus, max_agents, joshua_stopfile, children)

    # Always reap any dead children
    reap_deadchildren()

    sys.exit()