Class: ActiveColumn::Tasks::Keyspace
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
current_env, #current_env, #log, #testing?
Constructor Details
Returns a new instance of Keyspace.
17
18
19
20
|
# File 'lib/active_column/tasks/keyspace.rb', line 17
def initialize
c = ActiveColumn.connection
@cassandra = Cassandra.new('system', c.servers, c.thrift_client_options)
end
|
Instance Method Details
58
59
60
61
|
# File 'lib/active_column/tasks/keyspace.rb', line 58
def clear
return log 'Cannot clear system keyspace' if @cassandra.keyspace == 'system'
@cassandra.clear_keyspace!
end
|
#create(name, options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/active_column/tasks/keyspace.rb', line 26
def create(name, options = {})
if exists? name
log "Keyspace '#{name}' already exists - cannot create"
return nil
end
opts = { :name => name.to_s,
:strategy_class => 'org.apache.cassandra.locator.LocalStrategy',
:replication_factor => 1,
:cf_defs => [] }.merge(options)
ks = Cassandra::Keyspace.new.with_fields(opts)
@cassandra.add_keyspace ks
ks
end
|
#drop(name) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/active_column/tasks/keyspace.rb', line 42
def drop(name)
return log 'Cannot drop system keyspace' if name == 'system'
return log "Keyspace '#{name}' does not exist - cannot drop" if !exists? name
@cassandra.drop_keyspace name.to_s
true
end
|
#exists?(name) ⇒ Boolean
22
23
24
|
# File 'lib/active_column/tasks/keyspace.rb', line 22
def exists?(name)
@cassandra.keyspaces.include? name.to_s
end
|
54
55
56
|
# File 'lib/active_column/tasks/keyspace.rb', line 54
def get
@cassandra.keyspace
end
|
#schema_dump ⇒ Object
63
64
65
|
# File 'lib/active_column/tasks/keyspace.rb', line 63
def schema_dump
@cassandra.schema
end
|
#schema_load(schema) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/active_column/tasks/keyspace.rb', line 67
def schema_load(schema)
@cassandra.schema.cf_defs.each do |cf|
@cassandra.drop_column_family cf.name
end
keyspace = get
schema.cf_defs.each do |cf|
cf.keyspace = keyspace
@cassandra.add_column_family cf
end
end
|
#set(name) ⇒ Object
49
50
51
52
|
# File 'lib/active_column/tasks/keyspace.rb', line 49
def set(name)
return log "Keyspace '#{name}' does not exist - cannot set" if !exists? name
@cassandra.keyspace = name.to_s
end
|