186
185
config['commitlog_directory'] or 'commitlog'),
187
186
saved_caches_directory=get_database_directory(
188
187
config['saved_caches_directory'] or 'saved_caches'))
189
if has_cassandra_version('3.0'):
190
# Not yet configurable. Make configurable with Juju native storage.
191
dirs['hints_directory'] = get_database_directory('hints')
195
190
# FOR CHARMHELPERS
309
304
def get_cassandra_version():
310
305
if get_cassandra_edition() == 'dse':
311
dse_ver = get_package_version('dse-full')
314
elif LooseVersion(dse_ver) >= LooseVersion('4.7'):
306
return '2.1' if get_package_version('dse-full') else None
318
307
return get_package_version('cassandra')
321
def has_cassandra_version(minimum_ver):
322
cassandra_version = get_cassandra_version()
323
assert cassandra_version is not None, 'Cassandra package not yet installed'
324
return LooseVersion(cassandra_version) >= LooseVersion(minimum_ver)
327
310
def get_cassandra_config_dir():
328
311
if get_cassandra_edition() == 'dse':
329
312
return '/etc/dse/cassandra'
374
# NB. OpenJDK 8 not available in trusty. This needs to come
375
# from a PPA or some other configured source.
376
packages.add('openjdk-8-jre-headless')
357
# NB. OpenJDK 8 not available in trusty.
358
packages.add('openjdk-7-jre-headless')
452
434
# harmless, it causes shutil.chown() to fail.
453
435
assert not is_cassandra_running()
454
436
db_dirs = get_all_database_directories()
455
ensure_database_directory(db_dirs['commitlog_directory'])
456
ensure_database_directory(db_dirs['saved_caches_directory'])
457
if 'hints_directory' in db_dirs:
458
ensure_database_directory(db_dirs['hints_directory'])
459
for db_dir in db_dirs['data_file_directories']:
437
unpacked_db_dirs = (db_dirs['data_file_directories'] +
438
[db_dirs['commitlog_directory']] +
439
[db_dirs['saved_caches_directory']])
440
for db_dir in unpacked_db_dirs:
460
441
ensure_database_directory(db_dir)
550
531
hookenv.log('Creating SUPERUSER {}'.format(username))
552
533
hookenv.log('Creating user {}'.format(username))
553
if has_cassandra_version('2.2'):
555
'INSERT INTO system_auth.roles '
556
'(role, can_login, is_superuser, salted_hash) '
557
'VALUES (%s, TRUE, %s, %s)',
558
ConsistencyLevel.ALL,
559
(username, superuser, encrypted_password))
562
'INSERT INTO system_auth.users (name, super) VALUES (%s, %s)',
563
ConsistencyLevel.ALL, (username, superuser))
565
'INSERT INTO system_auth.credentials (username, salted_hash) '
567
ConsistencyLevel.ALL, (username, encrypted_password))
535
'INSERT INTO system_auth.users (name, super) VALUES (%s, %s)',
536
ConsistencyLevel.ALL, (username, superuser))
538
'INSERT INTO system_auth.credentials (username, salted_hash) '
540
ConsistencyLevel.ALL, (username, encrypted_password))
748
721
# with the system_auth keyspace replication settings.
749
722
cassandra_yaml['endpoint_snitch'] = 'GossipingPropertyFileSnitch'
751
# Per Bug #1523546 and CASSANDRA-9319, Thrift is disabled by default in
752
# Cassandra 2.2. Ensure it is enabled if rpc_port is non-zero.
753
if int(config['rpc_port']) > 0:
754
cassandra_yaml['start_rpc'] = True
756
724
cassandra_yaml.update(overrides)
758
726
write_cassandra_yaml(cassandra_yaml)
807
775
def get_auth_keyspace_replication(session):
808
if has_cassandra_version('3.0'):
809
statement = dedent('''\
810
SELECT replication FROM system_schema.keyspaces
811
WHERE keyspace_name='system_auth'
813
r = query(session, statement, ConsistencyLevel.QUORUM)
816
statement = dedent('''\
817
SELECT strategy_options FROM system.schema_keyspaces
818
WHERE keyspace_name='system_auth'
820
r = query(session, statement, ConsistencyLevel.QUORUM)
821
return json.loads(r[0][0])
776
statement = dedent('''\
777
SELECT strategy_options FROM system.schema_keyspaces
778
WHERE keyspace_name='system_auth'
780
r = query(session, statement, ConsistencyLevel.QUORUM)
781
return json.loads(r[0][0])