Example #1
0
 def get(self, request, *args, **kwargs):
   shard = request.GET.get('shard')
   datatype = request.GET.get('datatype')
   uid = request.GET.get('uid')
   query = request.GET.get('query')
   authstring = request.GET.get('auths')
   url = "/search/?q=" + query
   auths = pysharkbite.Authorizations()
   if not authstring is None and len(authstring) > 0:
     auths.addAuthorization(authstring)
   user = pysharkbite.AuthInfo(AccumuloCluster.objects.first().user,AccumuloCluster.objects.first().password, ZkInstance().get().getInstanceId())
   connector = pysharkbite.AccumuloConnector(user, ZkInstance().get())
   tableOps = connector.tableOps(AccumuloCluster.objects.first().dataTable)
   scanner = tableOps.createScanner(auths,1)
   startKey = pysharkbite.Key(row=shard)
   endKey = pysharkbite.Key(row=shard)
   docid = datatype + "\x00" + uid;
   startKey.setColumnFamily(docid)
   endKey.setColumnFamily(docid + "\xff")
   rng = pysharkbite.Range(startKey,True,endKey,True)
   scanner.addRange(rng)
   writer = tableOps.createWriter(auths,10)
   deletes = pysharkbite.Mutation(shard)
   for keyValue in scanner.getResultSet():
      key = keyValue.getKey()
      deletes.putDelete( key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibility(), key.getTimestamp())
  ## scan for the original document
   writer.addMutation(deletes)
   writer.close()
   for auth in authstring.split("|"):
     url = url + "&auths=" + auth
   return HttpResponseRedirect(url)
Example #2
0
    def mthd(self):

        import pysharkbite

        tableOperations = super().getTableOperations()

        if not tableOperations.exists(False):
            print("Creating table")
            if not tableOperations.create(False):
                print("Could not create table")
        else:
            tableOperations.remove()
            time.sleep(2)
            tableOperations.create(False)
            print("Table already exists, so not creating it")

        tableOperations = super().newtableOperations()
        splits = {"row", "row5", "row9", "sow"}
        tableOperations.addSplits(splits)

        auths = pysharkbite.Authorizations()
        """ Add authorizations """
        """ mutation.put("cf","cq","cv",1569786960) """

        writer = tableOperations.createWriter(auths, 10)

        rng = range(0, 500)
        for i in rng:
            row = ("row%i" % (i + 5))
            mutation = pysharkbite.Mutation(row)
            rng2 = range(0, 100)
            for j in rng:
                mutation.put("cf%i" % j, "cq", "", 1569786960, "value")
            writer.addMutation(mutation)
            print("wrote %i entries" % ((i + 1) * (j + 1)))

        writer.close()

        tableOperations.compact("a", "s", True)

        print("written")

        scanner = tableOperations.createScanner(auths, 2)

        time.sleep(1)

        accumuloRange = pysharkbite.Range("a", True, "sow", False)

        scanner.addRange(accumuloRange)

        resultset = scanner.getResultSet()
        count = 0
        for keyvalue in resultset:
            key = keyvalue.getKey()
            count = count + 1
        print("count is ", count)
        """ delete your table if user did not create temp """
Example #3
0
    if not tableOperations.exists(False):
        print ("Creating table " + table)
        tableOperations.create(False)  
    else:
        print (table + " already exists, so not creating it")  
    
    
    auths = pysharkbite.Authorizations()
    
    """ Add authorizations """ 
    """ mutation.put("cf","cq","cv",1569786960) """
    
    writer = tableOperations.createWriter(auths, 10)
    
    mutation = pysharkbite.Mutation("row2");    
    
    mutation.put("cf","cq","",1569786960, "value")
    mutation.put("cf2","cq2","",1569786960, "value2")
    """ no value """
    mutation.put("cf3","cq3","",1569786960, "") 
    
    writer.addMutation( mutation )
    
    writer.close()
    
    time.sleep(2)
    
    """ auths.addAuthorization("cv") """
    
    scanner = tableOperations.createScanner(auths, 2)
Example #4
0
    def mthd(self):

        import pysharkbite

        tableOperations = super().getTableOperations()

        ## validate that table is removed
        try:
            if not tableOperations.exists(False):
                print("Creating table")
                if not tableOperations.create(False):
                    print("Could not create table")
            else:
                print("Table already exists, so not creating it")

            auths = pysharkbite.Authorizations()
            """ Add authorizations """
            """ mutation.put("cf","cq","cv",1569786960) """

            tableOperations.remove()

            time.sleep(1)

            writer = tableOperations.createWriter(auths, 10)

            mutation = pysharkbite.Mutation("sow2")

            mutation.put("cf", "cq", "", 1569786960, "value")
            mutation.put("cf2", "cq2", "", 1569786960, "value2")
            """ no value """
            mutation.put("cf3", "cq3", "", 1569786960, "")

            writer.addMutation(mutation)

            writer.close()

            writer = tableOperations.createWriter(auths, 10)

            rng = range(0, 1000)
            for i in rng:
                row = ("row%i" % (i + 5))
                mutation = pysharkbite.Mutation(row)
                mutation.put("cf", "cq", "", 1569786960, "value")
                writer.addMutation(mutation)

            writer.close()

            print("Table not removed")
            sys.exit(1)
        except (RuntimeError, TypeError, NameError):
            print("Table successfully removed")
            # this is okay

        try:
            testzk = pysharkbite.ZookeeperInstance(None, None, 1000, None)
            print("Table not removed")
            sys.exit(1)
        except (RuntimeError, TypeError, NameError):
            print("Caught expected error")
            # this is okay

        try:
            writer = tableOperations.createWriter(None, 10)
            print("Expected error passing None")
            sys.exit(1)
        except (RuntimeError, TypeError, NameError):
            print("Caught expected error")
            # this is okay

        tableOperations.remove()
Example #5
0
	def mthd(self):
	
		import pysharkbite
		#pysharkbite.LoggingConfiguration.enableTraceLogger()
		
		tableOperations = super().getTableOperations()
			
		if not tableOperations.exists(False):
		    print ("Creating table")
		    tableOperations.create(False)  
		else:
		    print ("Table already exists, so not creating it")  
		
		
		auths = pysharkbite.Authorizations()
		auths.addAuthorization("blah1")
		auths.addAuthorization("blah2")
		
		securityOps = super().getConnector().securityOps()
		
		securityOps.grantAuthorizations(auths,"root")
		
		""" Add authorizations """ 
		""" mutation.put("cf","cq","cv",1569786960) """
		
		writer = tableOperations.createWriter(auths, 10)
		
		mutation = pysharkbite.Mutation("row2");    
		
		mutation.put("cf","cq","blah1",1569786960, "value")
		mutation.put("cf2","cq2","blah1",1569786960, "value2")
		""" no value """
		mutation.put("cf3","cq3","blah2",1569786960, "") 
		
		writer.addMutation( mutation )
		
		writer.close()
		
		print("written")
		
		auths = pysharkbite.Authorizations()
		
		auths.addAuthorization("blah1")
		
		scanner = tableOperations.createScanner(auths, 2)
		
		startKey = pysharkbite.Key()
		
		endKey = pysharkbite.Key()
		
		startKey.setRow("row")
		
		endKey.setRow("row3")
		
		# test single range
		range = pysharkbite.Range("row2")
		
		scanner.addRange( range )
		
		resultset = scanner.getResultSet()
		
		for keyvalue in resultset:
			key = keyvalue.getKey()
			assert( "row2" == key.getRow() )
			value = keyvalue.getValue()
			if "cf" == key.getColumnFamily():
				assert( "value"  == value.get() )
			if ("cf2" == key.getColumnFamily() ):
				assert( "value2" == value.get() )
			if ("cf3" == key.getColumnFamily() ):
				print("Unexpected column cf3")
				sys.exit(1)
		    
		range = pysharkbite.Range("row1",True,"row1.5",True)
		
		scanner.addRange( range )
		
		resultset = scanner.getResultSet()
		
		for keyvalue in resultset:
			print("Unexpected result")
			sys.exit(1)
		    
		# test single range
		range = pysharkbite.Range("row",False,"row3",True)
		
		scanner = tableOperations.createScanner(auths, 2)
		
		scanner.addRange( range )
		
		resultset = scanner.getResultSet()
		
		count =0
		for keyvalue in resultset:
			key = keyvalue.getKey()
			assert( "row2" == key.getRow() )
			value = keyvalue.getValue()
			if "cf" == key.getColumnFamily():
				assert( "value"  == value.get() )
			if ("cf2" == key.getColumnFamily() ):
				assert( "value2" == value.get() )
			if ("cf3" == key.getColumnFamily() ):
				print("Unexpected column cf3")
				sys.exit(1)
			count=count+1
		if count <= 0:
			print("Expected results")
			sys.exit(1)
			
		
		# test infinite range
		range = pysharkbite.Range("",False,"row3",True)
		
		scanner = tableOperations.createScanner(auths, 2)
		
		scanner.addRange( range )
		
		resultset = scanner.getResultSet()
		
		count =0
		for keyvalue in resultset:
			key = keyvalue.getKey()
			assert( "row2" == key.getRow() )
			value = keyvalue.getValue()
			if "cf" == key.getColumnFamily():
				assert( "value"  == value.get() )
			if ("cf2" == key.getColumnFamily() ):
				assert( "value2" == value.get() )
			if ("cf3" == key.getColumnFamily() ):
				print("Unexpected column cf3")
				sys.exit(1)
			count=count+1
		if count <= 0:
			print("Expected results")
			sys.exit(1)
			
		startKey = pysharkbite.Key("row3")
			
		range = pysharkbite.Range(None,False,startKey,True)
		
		scanner = tableOperations.createScanner(auths, 2)
		
		scanner.addRange( range )
		
		resultset = scanner.getResultSet()
		
		count =0
		for keyvalue in resultset:
			key = keyvalue.getKey()
			assert( "row2" == key.getRow() )
			value = keyvalue.getValue()
			if "cf" == key.getColumnFamily():
				assert( "value"  == value.get() )
			if ("cf2" == key.getColumnFamily() ):
				assert( "value2" == value.get() )
			if ("cf3" == key.getColumnFamily() ):
				print("Unexpected column cf3")
				sys.exit(1)
			count=count+1
		if count <= 0:
			print("Expected results")
			sys.exit(1)
		
		
		""" delete your table if user did not create temp """
		
		tableOperations.remove()
Example #6
0
    def mthd(self):

        import pysharkbite

        tableOperations = super().getTableOperations()

        if not tableOperations.exists(False):
            print("Creating table")
            if not tableOperations.create(False):
                print("Could not create table")
        else:
            print("Table already exists, so not creating it")

        auths = pysharkbite.Authorizations()
        """ Add authorizations """
        """ mutation.put("cf","cq","cv",1569786960) """

        writer = tableOperations.createWriter(auths, 10)

        mutation = pysharkbite.Mutation("sow2")

        mutation.put("cf", "cq", "", 1569786960, "value")
        mutation.put("cf2", "cq2", "", 1569786960, "value2")
        """ no value """
        mutation.put("cf3", "cq3", "", 1569786960, "")

        writer.addMutation(mutation)

        writer.close()

        writer = tableOperations.createWriter(auths, 10)

        rng = range(0, 1000)
        for i in rng:
            row = ("row%i" % (i + 5))
            mutation = pysharkbite.Mutation(row)
            mutation.put("cf", "cq", "", 1569786960, "value")
            writer.addMutation(mutation)

        writer.close()

        print("written")
        """ auths.addAuthorization("cv") """

        scanner = tableOperations.createScanner(auths, 2)

        startKey = pysharkbite.Key()

        endKey = pysharkbite.Key()

        startKey.setRow("sow")

        endKey.setRow("sow3")

        accumuloRange = pysharkbite.Range(startKey, True, endKey, False)

        scanner.addRange(accumuloRange)

        resultset = scanner.getResultSet()

        for keyvalue in resultset:
            key = keyvalue.getKey()
            assert ("sow2" == key.getRow())
            value = keyvalue.getValue()
            if "cf" == key.getColumnFamily():
                assert ("value" == value.get())
            if ("cf2" == key.getColumnFamily()):
                assert ("value2" == value.get())
            if ("cf3" == key.getColumnFamily()):
                assert ("" == value.get())

        scanner = tableOperations.createScanner(auths, 2)

        accumuloRange = pysharkbite.Range("row", True, "", False)

        scanner.addRange(accumuloRange)

        resultset = scanner.getResultSet()
        count = 0
        for keyvalue in resultset:
            key = keyvalue.getKey()
            count = count + 1
        print("count is ", count)
        assert (count == 1003)  # all rows + sows
        """ delete your table if user did not create temp """

        tableOperations.remove()
Example #7
0
    def post(self, request, *args, **kwargs):
        query = request.POST.get('query')
        shard = request.POST.get('shard')
        authstring = request.POST.get('auths')
        datatype = request.POST.get('datatype')
        uid = request.POST.get('uid')
        originals = {}
        news = {}
        for key, value in request.POST.items():
            if key == "query":
                query = value
            elif key.startswith("original"):
                split = key.split(".")
                originals[split[1]] = value
            elif key == "shard" or key == "datatype" or key == "uid" or key == "auths":
                pass
            elif key == "csrfmiddlewaretoken":
                pass
            else:
                news[key] = value
        user = pysharkbite.AuthInfo(AccumuloCluster.objects.first().user,
                                    AccumuloCluster.objects.first().password,
                                    ZkInstance().get().getInstanceId())
        connector = pysharkbite.AccumuloConnector(user, ZkInstance().get())

        auths = pysharkbite.Authorizations()
        #for auth in
        if not authstring is None and len(authstring) > 0:
            auths.addAuthorization(authstring)
        table = AccumuloCluster.objects.first().dataTable
        index_table = AccumuloCluster.objects.first().indexTable
        table_operations = connector.tableOps(table)
        index_table_ops = connector.tableOps(index_table)
        writer = table_operations.createWriter(auths, 10)
        indexWriter = index_table_ops.createWriter(auths, 5)
        mutation = pysharkbite.Mutation(shard)
        diff = 0
        for key, value in news.items():
            if news[key] != originals[key]:
                import datetime
                ts = int(datetime.datetime.now().timestamp()) * 1000
                mutation.putDelete(datatype + "\x00" + uid,
                                   key + "\x00" + originals[key], authstring,
                                   ts)
                ts = int(datetime.datetime.now().timestamp()) * 1000 + 100
                mutation.put(datatype + "\x00" + uid, key + "\x00" + news[key],
                             authstring, ts)
                originalIndexMutation = pysharkbite.Mutation(
                    originals[key].lower())
                indexMutation = pysharkbite.Mutation(news[key].lower())
                protobuf = Uid_pb2.List()
                protobuf.COUNT = 1
                protobuf.IGNORE = False
                protobuf.UID.append(uid)
                indexMutation.put(key, shard + "\x00" + datatype, authstring,
                                  ts, protobuf.SerializeToString())
                originalprotobuf = Uid_pb2.List()
                indexWriter.addMutation(indexMutation)
                originalprotobuf.COUNT = 1
                originalprotobuf.IGNORE = False
                originalprotobuf.REMOVEDUID.append(uid)
                originalIndexMutation.put(key, shard + "\x00" + datatype,
                                          authstring, ts,
                                          originalprotobuf.SerializeToString())
                indexWriter.addMutation(originalIndexMutation)
                diff = diff + 1
            else:
                pass
        if diff > 0:
            writer.addMutation(mutation)
        indexWriter.close()
        writer.close()
        authy = ""
        url = "/search/?q=" + query
        for auth in authstring.split("|"):
            url = url + "&auths=" + auth
        return HttpResponseRedirect(url)
Example #8
0
    def mthd(self):

        import pysharkbite

        securityOps = super().getSecurityOperations()

        auths = pysharkbite.Authorizations()
        auths.addAuthorization("blah1")
        auths.addAuthorization("blah2")

        securityOps.grantAuthorizations(auths, "root")

        tableOperations = super().getTableOperations()
        tableOperations.create(False)

        ## validate that we DO see the permissions
        """ Add authorizations """
        """ mutation.put("cf","cq","cv",1569786960) """

        with tableOperations.createWriter(auths, 10) as writer:
            mutation = pysharkbite.Mutation("row2")
            mutation.put("cf", "cq", "blah1", 1569786960, "value")
            mutation.put("cf2", "cq2", "blah1", 1569786960, "value2")
            """ no value """
            mutation.put("cf3", "cq3", "blah2", 1569786960, "")
            writer.addMutation(mutation)
            mutation = pysharkbite.Mutation("row4")
            mutation.put("cf", "cq", "blah1", 1569786960, "value")
            mutation.put("cf2", "cq2", "blah1", 1569786960, "value2")
            """ no value """
            mutation.put("cf3", "cq3", "blah2", 1569786960, "")
            writer.addMutation(mutation)

        auths = pysharkbite.Authorizations()

        auths.addAuthorization("blah1")
        auths.addAuthorization("blah2")
        count = 0
        with tableOperations.createScanner(auths, 2).withRange(
                pysharkbite.Range("row", True, "row3", False)) as scanner:
            resultset = scanner.getResultSet()

            for keyvalue in resultset:
                count = count + 1
                key = keyvalue.getKey()
                assert ("row2" == key.getRow())
                value = keyvalue.getValue()

                if "cf" == key.getColumnFamily():
                    assert ("value" == value.get())
                if ("cf2" == key.getColumnFamily()):
                    assert ("value2" == value.get())
        with tableOperations.createScanner(auths, 2).withRange(
                pysharkbite.Range("row4", True, "row5", False)) as scanner:
            resultset = scanner.getResultSet()

            for keyvalue in resultset:
                count = count + 1
                key = keyvalue.getKey()
                print("%r %r" % (keyvalue.getKey(), str(keyvalue.getValue())))
                assert ("row4" == key.getRow())
                value = keyvalue.getValue()
                if "cf" == key.getColumnFamily():
                    assert ("value" == value.get())
                if ("cf2" == key.getColumnFamily()):
                    assert ("value2" == value.get())
        """ delete your table if user did not create temp """
        tableOperations.remove()
        print("count is " + str(count))
        assert (count == 6)
Example #9
0
    def mthd(self):

        import pysharkbite

        tableOperations = super().getTableOperations()

        if not tableOperations.exists(False):
            print("Creating table")
            if not tableOperations.create(False):
                print("Could not create table")
        else:
            print("Table already exists, so not creating it")

        auths = pysharkbite.Authorizations()
        """ Add authorizations """
        """ mutation.put("cf","cq","cv",1569786960) """

        writer = tableOperations.createWriter(auths, 10)

        mutation = pysharkbite.Mutation("sow2")

        mutation.put("cf", "cq", "", 1569786960, "value")
        mutation.put("cf2", "cq", "", 1569786960, "value")
        """ no value """
        mutation.put("cf3", "cq", "", 1569786960, "value")

        writer.addMutation(mutation)

        writer.close()

        writer = tableOperations.createWriter(auths, 10)

        rng = range(0, 1000)
        for i in rng:
            row = ("row%i" % (i + 5))
            mutation = pysharkbite.Mutation(row)
            mutation.put("cf", "cq", "", 1569786960, "value")
            writer.addMutation(mutation)

        writer.close()

        print("written")
        """ auths.addAuthorization("cv") """

        scanner = tableOperations.createScanner(auths, 2)

        accumuloRange = pysharkbite.Range("sow", True, "sow3", False)

        scanner.addRange(accumuloRange)

        iterator = pysharkbite.PythonIterator("PythonIterator", 100)
        iterator = iterator.onNext(
            "lambda x : KeyValue( Key( x.getKey().getRow(), 'new cf', x.getKey().getColumnQualifier()), Value()) "
        )
        scanner.addIterator(iterator)

        resultset = scanner.getResultSet()

        for keyvalue in resultset:
            key = keyvalue.getKey()
            assert ("sow2" == key.getRow())
            value = keyvalue.getValue()
            if "cf" == key.getColumnFamily():
                sys.exit(154)
            if "new cf" == key.getColumnFamily():
                assert ("" == value.get())

        scanner = tableOperations.createScanner(auths, 2)

        accumuloRange = pysharkbite.Range("sow", True, "sow3", False)

        scanner.addRange(accumuloRange)

        iterator = pysharkbite.PythonIterator("PythonIterator", 100)
        iterator = iterator.onNext(
            "lambda x : Key( x.getKey().getRow(), x.getKey().getColumnFamily(), 'new cq') "
        )
        scanner.addIterator(iterator)

        resultset = scanner.getResultSet()

        for keyvalue in resultset:
            key = keyvalue.getKey()
            assert ("sow2" == key.getRow())
            value = keyvalue.getValue()
            if "cq" == key.getColumnQualifier():
                sys.exit(154)
        """ delete your table if user did not create temp """

        tableOperations.remove()