Remove duplicated codes in CDH plugin
We eliminated dup codes by using common-used methods. Closes-bug: #1444816 Change-Id: Ib6ca7ef8da07769581e72cf2a15a297c81ebc6c1
This commit is contained in:
parent
e8f21cc2b1
commit
e0a8754efc
@ -23,15 +23,30 @@ from sahara import context
|
|||||||
conductor = conductor.API
|
conductor = conductor.API
|
||||||
|
|
||||||
|
|
||||||
def get_cm_password(cluster):
|
def get_password_from_db(cluster, pwname):
|
||||||
ctx = context.ctx()
|
ctx = context.ctx()
|
||||||
cluster = conductor.cluster_get(ctx, cluster.id)
|
cluster = conductor.cluster_get(ctx, cluster.id)
|
||||||
passwd = cluster.extra.get('cm_password') if cluster.extra else None
|
passwd = cluster.extra.get(pwname) if cluster.extra else None
|
||||||
if passwd:
|
if passwd:
|
||||||
return passwd
|
return passwd
|
||||||
|
|
||||||
passwd = six.text_type(uuid.uuid4())
|
passwd = six.text_type(uuid.uuid4())
|
||||||
extra = cluster.extra.to_dict() if cluster.extra else {}
|
extra = cluster.extra.to_dict() if cluster.extra else {}
|
||||||
extra['cm_password'] = passwd
|
extra[pwname] = passwd
|
||||||
cluster = conductor.cluster_update(ctx, cluster, {'extra': extra})
|
cluster = conductor.cluster_update(ctx, cluster, {'extra': extra})
|
||||||
return passwd
|
return passwd
|
||||||
|
|
||||||
|
|
||||||
|
def get_cm_password(cluster):
|
||||||
|
return get_password_from_db(cluster, 'cm_password')
|
||||||
|
|
||||||
|
|
||||||
|
def remote_execute_db_script(remote, script_content):
|
||||||
|
script_name = 'script_to_exec.sql'
|
||||||
|
remote.write_file_to(script_name, script_content)
|
||||||
|
|
||||||
|
psql_cmd = ('PGPASSWORD=$(sudo head -1 /var/lib/cloudera-scm-server-db'
|
||||||
|
'/data/generated_password.txt) psql -U cloudera-scm '
|
||||||
|
'-h localhost -p 7432 -d scm -f %s') % script_name
|
||||||
|
remote.execute_command(psql_cmd)
|
||||||
|
remote.execute_command('rm %s' % script_name)
|
||||||
|
@ -13,29 +13,12 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import uuid
|
from sahara.plugins.cdh import db_helper as dh
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from sahara import conductor
|
|
||||||
from sahara import context
|
|
||||||
from sahara.utils import files
|
from sahara.utils import files
|
||||||
|
|
||||||
conductor = conductor.API
|
|
||||||
|
|
||||||
|
|
||||||
def get_hive_db_password(cluster):
|
def get_hive_db_password(cluster):
|
||||||
ctx = context.ctx()
|
return dh.get_password_from_db(cluster, 'hive_db_password')
|
||||||
cluster = conductor.cluster_get(ctx, cluster.id)
|
|
||||||
passwd = cluster.extra.get('hive_db_password') if cluster.extra else None
|
|
||||||
if passwd:
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
passwd = six.text_type(uuid.uuid4())
|
|
||||||
extra = cluster.extra.to_dict() if cluster.extra else {}
|
|
||||||
extra['hive_db_password'] = passwd
|
|
||||||
cluster = conductor.cluster_update(ctx, cluster, {'extra': extra})
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
|
|
||||||
def create_hive_database(cluster, remote):
|
def create_hive_database(cluster, remote):
|
||||||
@ -43,11 +26,4 @@ def create_hive_database(cluster, remote):
|
|||||||
create_db_script = files.get_file_text(
|
create_db_script = files.get_file_text(
|
||||||
'plugins/cdh/v5/resources/create_hive_db.sql')
|
'plugins/cdh/v5/resources/create_hive_db.sql')
|
||||||
create_db_script = create_db_script % db_password
|
create_db_script = create_db_script % db_password
|
||||||
script_name = 'create_hive_db.sql'
|
dh.remote_execute_db_script(remote, create_db_script)
|
||||||
remote.write_file_to(script_name, create_db_script)
|
|
||||||
|
|
||||||
psql_cmd = ('PGPASSWORD=$(sudo head -1 /var/lib/cloudera-scm-server-db'
|
|
||||||
'/data/generated_password.txt) psql -U cloudera-scm '
|
|
||||||
'-h localhost -p 7432 -d scm -f %s') % script_name
|
|
||||||
remote.execute_command(psql_cmd)
|
|
||||||
remote.execute_command('rm %s' % script_name)
|
|
||||||
|
@ -13,29 +13,16 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import uuid
|
from sahara.plugins.cdh import db_helper as dh
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from sahara import conductor
|
|
||||||
from sahara import context
|
|
||||||
from sahara.utils import files
|
from sahara.utils import files
|
||||||
|
|
||||||
conductor = conductor.API
|
|
||||||
|
|
||||||
|
|
||||||
def get_hive_db_password(cluster):
|
def get_hive_db_password(cluster):
|
||||||
ctx = context.ctx()
|
return dh.get_password_from_db(cluster, 'hive_db_password')
|
||||||
cluster = conductor.cluster_get(ctx, cluster.id)
|
|
||||||
passwd = cluster.extra.get('hive_db_password') if cluster.extra else None
|
|
||||||
if passwd:
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
passwd = six.text_type(uuid.uuid4())
|
|
||||||
extra = cluster.extra.to_dict() if cluster.extra else {}
|
def get_sentry_db_password(cluster):
|
||||||
extra['hive_db_password'] = passwd
|
return dh.get_password_from_db(cluster, 'sentry_db_password')
|
||||||
cluster = conductor.cluster_update(ctx, cluster, {'extra': extra})
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
|
|
||||||
def create_hive_database(cluster, remote):
|
def create_hive_database(cluster, remote):
|
||||||
@ -43,28 +30,7 @@ def create_hive_database(cluster, remote):
|
|||||||
create_db_script = files.get_file_text(
|
create_db_script = files.get_file_text(
|
||||||
'plugins/cdh/v5_3_0/resources/create_hive_db.sql')
|
'plugins/cdh/v5_3_0/resources/create_hive_db.sql')
|
||||||
create_db_script = create_db_script % db_password
|
create_db_script = create_db_script % db_password
|
||||||
script_name = 'create_hive_db.sql'
|
dh.remote_execute_db_script(remote, create_db_script)
|
||||||
remote.write_file_to(script_name, create_db_script)
|
|
||||||
|
|
||||||
psql_cmd = ('PGPASSWORD=$(sudo head -1 /var/lib/cloudera-scm-server-db'
|
|
||||||
'/data/generated_password.txt) psql -U cloudera-scm '
|
|
||||||
'-h localhost -p 7432 -d scm -f %s') % script_name
|
|
||||||
remote.execute_command(psql_cmd)
|
|
||||||
remote.execute_command('rm %s' % script_name)
|
|
||||||
|
|
||||||
|
|
||||||
def get_sentry_db_password(cluster):
|
|
||||||
ctx = context.ctx()
|
|
||||||
cluster = conductor.cluster_get(ctx, cluster.id)
|
|
||||||
passwd = cluster.extra.get('sentry_db_password') if cluster.extra else None
|
|
||||||
if passwd:
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
passwd = six.text_type(uuid.uuid4())
|
|
||||||
extra = cluster.extra.to_dict() if cluster.extra else {}
|
|
||||||
extra['sentry_db_password'] = passwd
|
|
||||||
cluster = conductor.cluster_update(ctx, cluster, {'extra': extra})
|
|
||||||
return passwd
|
|
||||||
|
|
||||||
|
|
||||||
def create_sentry_database(cluster, remote):
|
def create_sentry_database(cluster, remote):
|
||||||
@ -72,11 +38,4 @@ def create_sentry_database(cluster, remote):
|
|||||||
create_db_script = files.get_file_text(
|
create_db_script = files.get_file_text(
|
||||||
'plugins/cdh/v5_3_0/resources/create_sentry_db.sql')
|
'plugins/cdh/v5_3_0/resources/create_sentry_db.sql')
|
||||||
create_db_script = create_db_script % db_password
|
create_db_script = create_db_script % db_password
|
||||||
script_name = 'create_sentry_db.sql'
|
dh.remote_execute_db_script(remote, create_db_script)
|
||||||
remote.write_file_to(script_name, create_db_script)
|
|
||||||
|
|
||||||
psql_cmd = ('PGPASSWORD=$(sudo head -1 /var/lib/cloudera-scm-server-db'
|
|
||||||
'/data/generated_password.txt) psql -U cloudera-scm '
|
|
||||||
'-h localhost -p 7432 -d scm -f %s') % script_name
|
|
||||||
remote.execute_command(psql_cmd)
|
|
||||||
remote.execute_command('rm %s' % script_name)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user