Class: Eurydice::Pelops::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/eurydice/pelops/cluster.rb

Instance Method Summary collapse

Constructor Details

#initialize(cluster, driver = ::Pelops::Pelops) ⇒ Cluster

Returns a new instance of Cluster.



6
7
8
9
# File 'lib/eurydice/pelops/cluster.rb', line 6

def initialize(cluster, driver=::Pelops::Pelops)
  @cluster = cluster
  @driver = driver
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/eurydice/pelops/cluster.rb', line 11

def connected?
  @driver.create_cluster_manager(@cluster).cassandra_version
  true
rescue Exception => e
  false
end

#keyspace(keyspace_name, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/eurydice/pelops/cluster.rb', line 18

def keyspace(keyspace_name, options={})
  pool_name = options.fetch(:pool_name, "eurydice_#{keyspace_name}_pool")
  create = options.fetch(:create, true)
  unless @driver.get_db_conn_pool(pool_name)
    @driver.add_pool(pool_name, @cluster, keyspace_name)
  end
  keyspace = Keyspace.new(keyspace_name, @cluster, pool_name, @driver)
  keyspace.create! if create && !keyspace.exists?
  keyspace
end

#keyspacesObject



29
30
31
# File 'lib/eurydice/pelops/cluster.rb', line 29

def keyspaces
  keyspace_manager.keyspace_names.map { |ks_def| ks_def.name }
end

#nodesObject



33
34
35
# File 'lib/eurydice/pelops/cluster.rb', line 33

def nodes
  @cluster.nodes.map { |n| n.address }
end