def testSetupCluster(): """Testing cluster setup for stores.""" # Create some nodes nodes = [] for i in range(10): nodes.append(Node.objects.create(host="ela4-be80%d" % i, online=True, group=Group(pk=1))) # Create test store 1 print "==== [ Test Store 1] ======================================" store1 = ContentStore(name = "test-store1", replica = 3, partitions = 10, description = "This is test store one") store1.save() setupCluster(store1) for node in store1.nodes.all(): print node.host for member in store1.members.order_by("node"): print member.node.host, member.replica, member.parts buildClusterSVG(store1, file("/tmp/%s.svg" % store1.name, "w+"), True) # Remove one node, and redraw cluster layout for store 1 nodes[4].online = False nodes[4].save() buildClusterSVG(store1, file("/tmp/%s.svg" % store1.name, "w+"), True) # Create test store 2 print "==== [ Test Store 2] ======================================" store2 = ContentStore(name = "test-store2", replica = 2, partitions = 5, description = "This is test store two") store2.save() setupCluster(store2) for node in store2.nodes.all(): print node.host for member in store2.members.order_by("node"): print member.node.host, member.replica, member.parts buildClusterSVG(store2, file("/tmp/%s.svg" % store2.name, "w+"), True) # Delete all the testing nodes and stores for node in nodes: node.delete() store1.delete() store2.delete()
def newStore(request,index_name): store = ContentStore(name=index_name, sensei_port=random.randint(10000, 15000), brocker_port=random.randint(15000, 20000)) store.save() resp = { 'id': store.id, 'name': store.name, 'sensei_port': store.sensei_port, 'brocker_port': store.brocker_port, 'config': store.config, 'created': store.created, 'status': store.status, } return HttpResponse(json.json_encode(resp))
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))
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))