Пример #1
0
def regenerate_api_key(request, store_name):
  try:
    store = request.user.my_stores.get(name=store_name)
  except ContentStore.DoesNotExist:
    resp = {
      'ok' : False,
      'msg' : 'You do not own a store with the name "%s".' % store_name
    }
    return HttpResponse(json.dumps(resp))
  store.api_key = generate_api_key()
  store.save()
  resp = {
    'ok': True,
    'api_key': store.api_key,
  }
  return HttpResponse(json.dumps(resp))
Пример #2
0
def regenerate_api_key(request, store_name):
  try:
    store = request.user.my_stores.get(name=store_name)
  except ContentStore.DoesNotExist:
    resp = {
      'ok' : False,
      'msg' : 'You do not own a store with the name "%s".' % store_name
    }
    return HttpResponse(json.dumps(resp))
  store.api_key = generate_api_key()
  store.save()
  resp = {
    'ok': True,
    'api_key': store.api_key,
  }
  return HttpResponse(json.dumps(resp))
Пример #3
0
def newStore(request,store_name):
  if ContentStore.objects.filter(name=store_name).exists():
    resp = {
      'ok' : False,
      'error' : 'store: %s already exists, please choose another name.' % store_name
    }
    return HttpResponse(json.dumps(resp))

  replica = int(request.POST.get('replica','2'))
  partitions = int(request.POST.get('partitions','2'))
  desc = request.POST.get('desc',"")

  num_nodes = Node.objects.count()

  # Check for nodes:
  if num_nodes == 0:
    n = Node.objects.create(host=get_local_pub_ip(), online=True, group=Group(pk=1))
    num_nodes = 1

  if replica > num_nodes:
    resp = {'ok': False, 'error':'Num of replicas is too big'}
    return HttpResponse(json.dumps(resp))

  store = ContentStore(
    name=store_name,
    api_key=generate_api_key(),
    replica=replica,
    partitions=partitions,
    description=desc
  )
  store.save()
  store.collaborators.add(request.user)
  store.save()

  setupCluster(store)

  resp = store.to_map(True)
  resp.update({
    'ok' : True,
    'kafkaHost' : kafkaHost,
    'kafkaPort' : kafkaPort,
  })
  return HttpResponse(json.dumps(resp, ensure_ascii=False, cls=DateTimeAwareJSONEncoder))
Пример #4
0
def newStore(request,store_name):
  if ContentStore.objects.filter(name=store_name).exists():
    resp = {
      'ok' : False,
      'error' : 'store: %s already exists, please choose another name.' % store_name
    }
    return HttpResponse(json.dumps(resp))

  replica = int(request.POST.get('replica','2'))
  partitions = int(request.POST.get('partitions','2'))
  desc = request.POST.get('desc',"")

  num_nodes = Node.objects.count()

  # Check for nodes:
  if num_nodes == 0:
    n = Node.objects.create(host=get_local_pub_ip(), online=True, group=Group(pk=1))
    num_nodes = 1

  if replica > num_nodes:
    resp = {'ok': False, 'error':'Num of replicas is too big'}
    return HttpResponse(json.dumps(resp))

  store = ContentStore(
    name=store_name,
    api_key=generate_api_key(),
    replica=replica,
    partitions=partitions,
    description=desc
  )
  store.save()
  store.collaborators.add(request.user)
  store.save()

  setupCluster(store)

  resp = store.to_map(True)
  resp.update({
    'ok' : True,
  })
  return HttpResponse(json.dumps(resp, ensure_ascii=False, cls=DateTimeAwareJSONEncoder))