Beispiel #1
0
def init():
    cluster = Cluster()
    cluster.protocol_version = 5
    cluster.allow_beta_protocol_version = True
    session = cluster.connect()
    session.execute("use facebook_keyspace")
    return session
def getCluster():
    #Connect to Cassandra
    objCC = CassandraConnection()
    cloud_config = {}
    if objControl.heroku:
        cloud_config[
            'secure_connect_bundle'] = objControl.rutaHeroku + '/secure-connect-dbtest_serverless.zip'
    else:
        cloud_config[
            'secure_connect_bundle'] = objControl.rutaLocal + 'secure-connect-dbtest_serverless.zip'

    cloud_config['init-query-timeout'] = 10
    cloud_config['connect_timeout'] = 10
    cloud_config['set-keyspace-timeout'] = 10

    auth_provider = PlainTextAuthProvider(objCC.cc_user_test,
                                          objCC.cc_pwd_test)
    cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
    cluster.protocol_version = 66

    return cluster
    def connect(self, nodes):
        print nodes
        cluster = Cluster(nodes)
        metadata = cluster.metadata	
		
        #for i in range(0, len(self.connList)):
            #self.connList[i] = cluster.connect()
            #print self.connList[i]
		
        cluster.protocol_version = 3
        #cluster.default_retry_policy = cassandra.policies.FallthroughRetryPolicy
        
        print "Maxconn local: ", cluster.get_max_connections_per_host(0)
        print "Maxconn remote: ", cluster.get_max_connections_per_host(1)
        
        self.session = cluster.connect()
        self.session.default_timeout = 120
        
        
        print('Connected to cluster: ' + metadata.cluster_name)
        
        for host in metadata.all_hosts():
            print('Datacenter: %s; Host: %s; Rack: %s', host.datacenter, host.address, host.rack)