Beispiel #1
0
def collections_remove(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    collections = json.loads(request.POST.get('collections', '[]'))

    if not collections:
        response['message'] = _('No collections to remove.')

    if response.get('message', None) is None:
        searcher = CollectionManagerController(request.user)
        solr_collections = searcher.get_collections()

        for collection in collections:
            if collection.get('name') in solr_collections:
                # Remove collection and instancedir
                searcher.delete_collection(collection.get('name'),
                                           collection.get('isCoreOnly'))

        response['status'] = 0
        response['message'] = _('Collections removed!')

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #2
0
def collections_data(request, collection):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    source = request.POST.get('source')

    if source == 'file':
        searcher = CollectionManagerController(request.user)

        searcher.update_data_from_hdfs(
            request.fs,
            collection,
            None,
            request.POST.get('path'),
            request.POST.get('type'),
            separator=request.POST.get('separator'),
            quote_character=request.POST.get('quote'))

        response['status'] = 0
        response['message'] = _('Index imported!')
    else:
        response['message'] = _('Unsupported source %s') % source

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #3
0
def collections_import(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  collection = json.loads(request.POST.get('collection', '{}'))

  if collection:
    searcher = CollectionManagerController(request.user)
    unique_key, fields = searcher.get_fields(collection.get('name'))

    # Create collection and metadata.
    hue_collection, created = Collection.objects.get_or_create(name=collection.get('name'), solr_properties='{}', is_enabled=True, user=request.user)
    properties_dict = hue_collection.properties_dict
    properties_dict['data_type'] = 'separated'
    properties_dict['field_order'] = [field_name for field_name in fields]
    hue_collection.properties = json.dumps(properties_dict)
    hue_collection.save()

    response['status'] = 0
    response['message'] = _('Collection created!')
  else:
    response['message'] = _('Collection missing.')

  return JsonResponse(response)
Beispiel #4
0
def collections_import(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    collection = json.loads(request.POST.get('collection', '{}'))

    if collection:
        searcher = CollectionManagerController(request.user)
        unique_key, fields = searcher.get_fields(collection.get('name'))

        # Create collection and metadata.
        hue_collection, created = Collection.objects.get_or_create(
            name=collection.get('name'),
            solr_properties='{}',
            is_enabled=True,
            user=request.user)
        properties_dict = hue_collection.properties_dict
        properties_dict['data_type'] = 'separated'
        properties_dict['field_order'] = [field_name for field_name in fields]
        hue_collection.properties = json.dumps(properties_dict)
        hue_collection.save()

        response['status'] = 0
        response['message'] = _('Collection created!')
    else:
        response['message'] = _('Collection missing.')

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #5
0
def collections_data(request, collection):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  source = request.POST.get('source')

  if source == 'file':
    searcher = CollectionManagerController(request.user)

    searcher.update_data_from_hdfs(request.fs,
                                   collection,
                                   None,
                                   request.POST.get('path'),
                                   request.POST.get('type'),
                                   separator=request.POST.get('separator'),
                                   quote_character=request.POST.get('quote'))

    response['status'] = 0
    response['message'] = _('Index imported!')
  else:
    response['message'] = _('Unsupported source %s') % source

  return JsonResponse(response)
Beispiel #6
0
def collections(request):
  searcher = CollectionManagerController(request.user)
  solr_collections = searcher.get_collections()

  response = {
    'status': 0,
    'collections': [{'name': collection} for collection in solr_collections]
  }

  return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #7
0
def collections(request):
    searcher = CollectionManagerController(request.user)
    solr_collections = searcher.get_collections()

    response = {
        'status': 0,
        'collections': [{
            'name': collection
        } for collection in solr_collections]
    }

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #8
0
def collections(request):
    searcher = CollectionManagerController(request.user)
    solr_collections = searcher.get_collections()
    massaged_collections = []
    for collection in solr_collections:
        massaged_collections.append({
            'name':
            collection,
            'isCoreOnly':
            solr_collections[collection]['isCoreOnly']
        })
    response = {'status': 0, 'collections': massaged_collections}

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #9
0
def collections_fields(request, collection):
  if request.method != 'GET':
    raise PopupException(_('GET request required.'))

  response = {}

  searcher = CollectionManagerController(request.user)
  unique_key, fields = searcher.get_fields(collection)

  response['status'] = 0
  response['fields'] = [(field, fields[field]['type'], fields[field].get('indexed', None), fields[field].get('stored', None)) for field in fields]
  response['unique_key'] = unique_key

  return JsonResponse(response)
Beispiel #10
0
def collections(request):
    searcher = CollectionManagerController(request.user)
    solr_collections = searcher.get_collections()
    massaged_collections = []
    for collection in solr_collections:
        massaged_collections.append({
            'name':
            collection,
            'isCoreOnly':
            solr_collections[collection]['isCoreOnly']
        })
    response = {'status': 0, 'collections': massaged_collections}

    return JsonResponse(response)
Beispiel #11
0
def collections(request):
  searcher = CollectionManagerController(request.user)
  solr_collections = searcher.get_collections()
  massaged_collections = []
  for collection in solr_collections:
    massaged_collections.append({
      'name': collection,
      'isCoreOnly': solr_collections[collection]['isCoreOnly']
    })
  response = {
    'status': 0,
    'collections': massaged_collections
  }

  return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #12
0
def collections(request):
  searcher = CollectionManagerController(request.user)
  solr_collections = searcher.get_collections()
  massaged_collections = []
  for collection in solr_collections:
    massaged_collections.append({
      'name': collection,
      'isCoreOnly': solr_collections[collection]['isCoreOnly']
    })
  response = {
    'status': 0,
    'collections': massaged_collections
  }

  return JsonResponse(response)
Beispiel #13
0
def collections_update(request, collection):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  collection = json.loads(request.POST.get('collection', '{}'))

  if not collection:
    response['message'] = _('No collection to update.')

  if response.get('message', None) is None:
    searcher = CollectionManagerController(request.user)
    searcher.update_collection(collection.get('name'), collection.get('fields', []))

    response['status'] = 0
    response['message'] = _('Collection updated!')

  return JsonResponse(response)
Beispiel #14
0
def collections_create(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

    collection = json.loads(request.POST.get('collection', '{}'))

    if collection:
        searcher = CollectionManagerController(request.user)

        # Create instance directory, collection, and add fields
        searcher.create_collection(collection.get('name'),
                                   collection.get('fields', []),
                                   collection.get('uniqueKeyField'),
                                   collection.get('df'))

        try:
            if request.POST.get('source') == 'file':
                # Index data
                searcher.update_data_from_hdfs(
                    request.fs,
                    collection.get('name'),
                    collection.get('fields', []),
                    request.POST.get('path'),
                    request.POST.get('type'),
                    separator=request.POST.get('separator'),
                    quote_character=request.POST.get('quote'))

            elif request.POST.get('source') == 'hive':
                # Run a custom hive query and post data to collection
                from beeswax.server import dbms

                db = dbms.get(request.user)

                database = request.POST.get('database')
                table = request.POST.get('table')
                columns = [
                    field['name'] for field in collection.get('fields', [])
                ]

                searcher.update_data_from_hive(db, collection.get('name'),
                                               database, table, columns)

            response['status'] = 0
            response['message'] = _('Collection created!')
        except Exception, e:
            LOG.error(e)
            raise
Beispiel #15
0
def collections_remove(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  collections = json.loads(request.POST.get('collections', '[]'))

  if not collections:
    response['message'] = _('No collections to remove.')

  if response.get('message', None) is None:
    searcher = CollectionManagerController(request.user)
    solr_collections = searcher.get_collections()

    for collection in collections:
      if collection.get('name') in solr_collections:
        # Remove collection and instancedir
        searcher.delete_collection(collection.get('name'), collection.get('isCoreOnly'))

    response['status'] = 0
    response['message'] = _('Collections removed!')

  return JsonResponse(response)
Beispiel #16
0
def collections_create(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

  collection = json.loads(request.POST.get('collection', '{}'))

  if collection:
    searcher = CollectionManagerController(request.user)

    # Create instance directory, collection, and add fields
    searcher.create_collection(collection.get('name'), collection.get('fields', []), collection.get('uniqueKeyField'), collection.get('df'))

    try:
      if request.POST.get('source') == 'file':
        # Index data
        searcher.update_data_from_hdfs(request.fs,
                                       collection.get('name'),
                                       collection.get('fields', []),
                                       request.POST.get('path'),
                                       request.POST.get('type'),
                                       separator=request.POST.get('separator'),
                                       quote_character=request.POST.get('quote'))

      elif request.POST.get('source') == 'hive':
        # Run a custom hive query and post data to collection
        from beeswax.server import dbms

        db = dbms.get(request.user)

        database = request.POST.get('database')
        table = request.POST.get('table')
        columns = [field['name'] for field in collection.get('fields', [])]

        searcher.update_data_from_hive(db, collection.get('name'), database, table, columns)

      response['status'] = 0
      response['message'] = _('Collection created!')
    except Exception, e:
      LOG.error(e)
      raise