def install_hive(hadoop): ''' Anytime our dependencies are available, check to see if we have a valid reason to (re)install. These include: - initial install - HBase has joined/departed ''' # Hive cannot handle - in the metastore db name and # mysql uses the service name to name the db if "-" in hookenv.service_name(): hookenv.status_set('blocked', "application name may not contain '-'; " "redeploy with a different name") return # Get hbase connection dict if it's available if is_state('hbase.ready'): hbase = RelationBase.from_state('hbase.ready') hbserver = hbase.hbase_servers()[0] else: hbserver = None # Use this to determine if we need to reinstall deployment_matrix = { 'hbase': hbserver, } # Handle nuances when installing versus re-installing if not is_state('hive.installed'): prefix = "installing" # On initial install, prime our kv with the current deployment matrix. # Subsequent calls will use this to determine if a reinstall is needed. data_changed('deployment_matrix', deployment_matrix) else: prefix = "configuring" # Return if our matrix has not changed if not data_changed('deployment_matrix', deployment_matrix): return hookenv.status_set('maintenance', '{} hive'.format(prefix)) hookenv.log("{} hive with: {}".format(prefix, deployment_matrix)) hive = Hive() hive.install(hbase=hbserver) hive.restart() hive.open_ports() set_state('hive.installed') report_status() # set app version string for juju status output hive_version = get_package_version('hive') or 'unknown' hookenv.application_version_set(hive_version)
def configure_with_remote_db(db): hookenv.status_set('maintenance', 'configuring external database') hive = Hive() hive.configure_remote_db(db) hive.restart() set_state('hive.db.configured') report_status()
def stop_hive(): ''' Hive depends on Hadoop. If we are installed and hadoop goes away, shut down services and remove our installed state. ''' hive = Hive() hive.close_ports() hive.stop() remove_state('hive.installed') report_status()
def configure_with_local_db(): ''' Reconfigure Hive using a local metastore db. The initial installation will configure Hive with a local metastore_db. Once an external db becomes available, we reconfigure Hive to use it. If that external db goes away, we'll use this method to set Hive back into local mode. ''' hookenv.status_set('maintenance', 'configuring local database') hive = Hive() hive.configure_local_db() hive.restart() remove_state('hive.db.configured') report_status()
def config_changed(): hookenv.status_set('maintenance', 'configuring with new options') hive = Hive() hive.configure_hive() hive.restart() report_status()