Exemple #1
0
def query(ctx, q, schema_file, ignore_cycles, cache_file, cache_host, cache_port, cache_db, resource_cache,
          fragment_cache, host, port):
    check_init(ctx)

    q = q.replace("'", '"')
    if cache_file:
        path_parts = cache_file.split('/')
        cache_base = '/'.join(cache_file.split('/')[:-1])
        cache_file = path_parts[-1]

    if resource_cache or fragment_cache:
        remote_cache = all([cache_host, cache_port, cache_db])
        cache = RedisCache(redis_file=None if remote_cache else (cache_file or 'data.db'),
                           base='.agora/store' if not cache_file else cache_base,
                           path='',
                           redis_host=cache_host,
                           redis_db=cache_db,
                           redis_port=cache_port)
    else:
        cache = None

    ctx.obj['gw'].data_cache = cache
    processor = GraphQLProcessor(ctx.obj['gw'], schema_path=schema_file, scholar=fragment_cache, host=host,
                                 port=port, follow_cycles=not ignore_cycles, base='.agora/store/fragments')
    res = processor.query(q)
    click.echo(jsonify(res.to_dict()))
Exemple #2
0
def publish_gql(ctx, schema_file, ignore_cycles, cache_file, cache_host,
                cache_port, cache_db, resource_cache, fragment_cache,
                age_gql_cache, len_gql_cache, host, port):
    check_init(ctx)

    if cache_file:
        path_parts = cache_file.split('/')
        cache_base = '/'.join(cache_file.split('/')[:-1])
        cache_file = path_parts[-1]

    if resource_cache or fragment_cache:
        remote_cache = all([cache_host, cache_port, cache_db])
        cache = RedisCache(
            redis_file=None if remote_cache else (cache_file or 'data.db'),
            base='.agora/store' if not cache_file else cache_base,
            path='',
            redis_host=cache_host,
            redis_db=cache_db,
            redis_port=cache_port)
    else:
        cache = None

    app = Flask(__name__)
    CORS(app)

    ctx.obj['gw'].data_cache = cache
    gql_processor = GraphQLProcessor(ctx.obj['gw'],
                                     schema_path=schema_file,
                                     scholar=fragment_cache,
                                     host=host,
                                     port=80,
                                     follow_cycles=not ignore_cycles,
                                     base='.agora/store/fragments',
                                     data_gw_cache={
                                         'max_age_seconds': age_gql_cache,
                                         'max_len': len_gql_cache
                                     })

    app.add_url_rule('/graphql',
                     view_func=AgoraGraphQLView.as_view(
                         'graphql',
                         schema=gql_processor.schema,
                         executor=gql_processor.executor,
                         middleware=gql_processor.middleware,
                         graphiql=True))

    options = {
        'bind': '%s:%s' % ('0.0.0.0', str(port)),
        'workers': 1,
        'threads': number_of_workers(),
        'workerconnections': 1000,
        'timeout': 4000,
        'workerclass': 'gthread',
        'errorlog': '-',
        'accesslog': '-'
    }
    GQLApplication(app, options).run()
Exemple #3
0
def query(ctx, q, arg, incremental, ignore_cycles, cache_file, cache_host,
          cache_port, cache_db, resource_cache, fragment_cache, host, port):
    check_init(ctx)

    args = dict(map(lambda a: split_arg(a), arg))

    if cache_file:
        path_parts = cache_file.split('/')
        cache_base = '/'.join(cache_file.split('/')[:-1])
        cache_file = path_parts[-1]

    if resource_cache or fragment_cache:
        remote_cache = all([cache_host, cache_port, cache_db])
        cache = RedisCache(
            redis_file=None if remote_cache else (cache_file or 'data.db'),
            base='.agora/store' if not cache_file else cache_base,
            path='',
            redis_host=cache_host,
            redis_db=cache_db,
            redis_port=cache_port)
    else:
        cache = None
    stop = Semaphore()
    queue = Queue()

    dgw = ctx.obj['gw'].data(q,
                             cache=cache,
                             lazy=False,
                             host=host,
                             port=port,
                             base='.agora/store/fragments')
    gen = dgw.query(q,
                    incremental=incremental,
                    stop_event=stop,
                    scholar=fragment_cache,
                    follow_cycles=not ignore_cycles,
                    **args)

    request_status = {'completed': False, 'exception': None}
    stream_th = Thread(target=gen_thread, args=(request_status, queue, gen))
    stream_th.daemon = False
    stream_th.start()

    for chunk in gen_queue(request_status, stop, queue):
        click.echo(chunk, nl=False)

    click.echo()
Exemple #4
0
def publish_ui(ctx, query, incremental, ignore_cycles, cache_file, cache_host,
               cache_port, cache_db, resource_cache, fragment_cache, host,
               port):
    check_init(ctx)

    if cache_file:
        path_parts = cache_file.split('/')
        cache_base = '/'.join(cache_file.split('/')[:-1])
        cache_file = path_parts[-1]

    if resource_cache or fragment_cache:
        remote_cache = all([cache_host, cache_port, cache_db])
        cache = RedisCache(
            redis_file=None if remote_cache else (cache_file or 'data.db'),
            base='.agora/store' if not cache_file else cache_base,
            path='',
            redis_host=cache_host,
            redis_db=cache_db,
            redis_port=cache_port)
    else:
        cache = None

    click.echo('Discovering ecosystem...', nl=False)
    dgw = ctx.obj['gw'].data(query,
                             cache=cache,
                             lazy=False,
                             host=host,
                             port=80,
                             base='.agora/store/fragments')
    click.echo('Done')

    server = fs(ctx.obj['gw'].agora.fountain)
    frs(ctx.obj['gw'].agora,
        server=server,
        fragment_function=fragment_f(dgw, fragment_cache, ignore_cycles))
    ss(ctx.obj['gw'].agora,
       server=server,
       query_function=query_f(dgw, incremental, fragment_cache, ignore_cycles))
    CORS(server)
    server.run(host='0.0.0.0', port=port, threaded=True)
    click.echo()
Exemple #5
0
def discover(ctx):
    check_init(ctx)
Exemple #6
0
def export(ctx):
    check_init(ctx)
    compress('.agora', 'agora.zip')
Exemple #7
0
def compute(ctx):
    check_init(ctx)
Exemple #8
0
def delete(ctx):
    check_init(ctx)
Exemple #9
0
def gql(ctx):
    check_init(ctx)
Exemple #10
0
def list(ctx):
    check_init(ctx)
Exemple #11
0
def publish(ctx):
    check_init(ctx)
Exemple #12
0
def learn(ctx):
    check_init(ctx)
Exemple #13
0
def add(ctx):
    check_init(ctx)
Exemple #14
0
def get(ctx):
    check_init(ctx)
Exemple #15
0
def show(ctx):
    check_init(ctx)