Пример #1
0
def connect():
    #nodes = []
    #for ip in ["45.55.0.44", "107.170.224.168", "45.55.1.236"]:
    #    nodes.append(dict(host=ip, http_port=RIAK_HTTP_PORT, pb_port=RIAK_PBC_PORT))
    nodes = [
        dict(host=RIAK_HOST, http_port=RIAK_HTTP_PORT, pb_port=RIAK_PBC_PORT)
    ]
    client = RiakClient(nodes=nodes)
    assert client.ping(), "Failed to connect to client"
    return client
Пример #2
0
def configureRiak(riakIPs, riakPort,logger):


    initial_attempts = 5
    num_attempts = 0

    initial_delay = 5      # 5 seconds between between initial attempts
    longer_delay = 5*60    # 5 minutes = 300 seconds
    delay_time = initial_delay

    nodes=[]
    for eachNode in riakIPs.split(","):
        thisNode= { 'host': eachNode, 'pb_port': riakPort}
        nodes.append(thisNode)

    riakIP=""
    for node in nodes:
        riakIP=json.dumps(node)+ " - " +riakIP

    logger.info('[STATE] Connecting to Riak...')

    connected = False  
    client = RiakClient(protocol='pbc',nodes=nodes)
    while not connected:
	   try:
            logger.info("Attempting to PING....")
            client.ping()
            connected = True
	   except:
            num_attempts += 1
            logger.error('EXCP: No Riak server found')
            if num_attempts == initial_attempts:
                delay_time = longer_delay
                # Wait to issue next connection attempt
                time.sleep(delay_time)

    logger.info('[STATE] Connected to Riak. Successful PING')
    return client
Пример #3
0
def testCluster(IPs, login, password):

        initial_attempts = 5
        port = 8087
        num_attempts = 0

        nodes = []
        for eachNode in IPs.split(","):
            thisNode = {'host': eachNode, 'pb_port': port}
            nodes.append(thisNode)

        connected = False
        client = RiakClient(protocol='pbc', nodes=nodes)
        try:
            with client.retry_count(initial_attempts):
                connected = client.ping()
        except Exception as e:
            print('[EXCP] No Riak server found after ' + str(initial_attempts) + " tries. Error: " + str(e))

        if connected:
            print('[STATE] Successful PING! Connected to Riak!')
Пример #4
0
#
#
#Will iterate through the demo-data-extract csv file and put into Riak in batches of 100
#SMDE 29/4/16

from riak import RiakClient
from datetime import datetime
import calendar
import csv
def changetime(stime):
            dt=datetime.strptime(stime,'%Y-%m-%dT%H:%M:%S')
            #print dt
            return calendar.timegm(datetime.timetuple(dt))*1000
            
c=RiakClient()
c.ping()


#to load data in the table

totalcount=0
batchcount=0
batchsize=100
ds=[]
t=c.table('aarhus')
print t


with open('./demo-data-extract.csv', 'rU') as infile:
    r=csv.reader(infile)
    for l in r:
Пример #5
0
#!/usr/bin/python

from riak import RiakClient, RiakNode
from riak.riak_object import RiakObject

client = RiakClient(protocal='http', host='127.0.0.1', http_port=8098)

res = client.ping()

bucket = client.bucket('xxx')

#res = client.get_keys(res[0])

#obj = RiakObject(client, res, 'xxx')

obj = bucket.new('a', 'hello', 'text/plain')

obj.store()

res = bucket.get('a')

n = 0
Пример #6
0
from riak import RiakClient, RiakNode

client = RiakClient(protocol='pbc', host='127.0.0.1', http_port=8098)
print(client.ping())
tweetBucket = client.bucket("tweets")
print(tweetBucket.get_properties())
print(client.get_buckets())
print(client.bucket_type("tweets"))
allKeysInTweets = client.get_keys(tweetBucket)
print("Number of keys... ",len(allKeysInTweets))


stream = client.stream_keys(tweetBucket)
for key_list in stream:
     print("key_list;" , key_list)
stream.close()
Пример #7
0
#
#
#Will iterate through the all-data-2.csv csv file and put into Riak in batches of 100
#SMDE 09/05/16

from riak import RiakClient
from riak.util import unix_time_millis, datetime_from_unit_time_millis

from datetime import datetime
import calendar
import csv

c = RiakClient()
c.ping()

#to load data in the table

totalcount = 0
batchcount = 0
batchsize = 100  #most efficient batch size per documentation and testing
ds = []
t = c.table('aarhus13-4')
print t

with open(
        './traffic_feb_june/all-data-2.csv', 'rU'
) as infile:  #need to change pathing to match where source file is as necessary
    r = csv.reader(infile)
    for l in r:
        if l[0] != 'status':
            newl = [
Пример #8
0
import json
from riak import RiakClient, RiakNode

parser = argparse.ArgumentParser(description='Takes a list of redis keys and deletes them')
parser.add_argument('--host', dest='dest_riak', default='10.228.39.181', help='The host we delete the riak data from')
args = parser.parse_args()

# map arguments
dest_riak_host = args.dest_riak
print 'Targeted Riak Host ' + dest_riak_host

base_dir = os.path.dirname(os.path.realpath(__file__))

# connect to live riak
riak_connection = RiakClient(protocol='http', host=dest_riak_host, http_port=8098)
print riak_connection.ping()

riak_bucket = riak_connection.bucket('ez')

# Parses the keys.txt file and writes url
def readRiakKeys():
    keyListFilename = os.path.join(base_dir, 'keys.txt')
    return  [line.strip() for line in open(keyListFilename, 'r')]

imgs = readRiakKeys()
print 'Deleting Riak Keys: \n' + '\n'.join(imgs)

# get and save all images
for img in imgs:
    obj = riak_bucket.get(img)
    print 'Image exists? %s' % str(obj.exists)
Пример #9
0
import os
from riak import RiakClient, RiakNode

r = RiakClient()
r(protocol='http', host=os.getenv('MJDSYS_RIAK_HTTPCONNECT'), http_port=8098)
r(nodes=[{'host': os.getenv('MJDSYS_RIAK_HTTPCONNECT'), 'http_port': 8098}])
r(protocol='http', nodes=[RiakNode()])

r.ping()

print r.ping()
Пример #10
0
import os
from riak import RiakClient, RiakNode

r= RiakClient()
r(protocol='http', host=os.getenv('MJDSYS_RIAK_HTTPCONNECT'), http_port=8098)
r(nodes=[{'host': os.getenv('MJDSYS_RIAK_HTTPCONNECT'),'http_port':8098}])
r(protocol='http', nodes=[RiakNode()])

r.ping()

print r.ping()

Пример #11
0
from riak import RiakClient

c=RiakClient()
print c.ping()

fmt="""
	CREATE TABLE stratalaptimes (
		event varchar not null,
		ts timestamp not null,
		email varchar not null,
		laptime double not null,
		PRIMARY KEY(
			(event,quantum(ts, 5,'d')),
			event,ts)
			)
"""
c.ts_query('stratalaptimes',fmt)