Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Adding Zeppelin installer function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacBlanco committed Jun 23, 2016
1 parent ea74338 commit 0eea835
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 11 deletions.
8 changes: 7 additions & 1 deletion conf/service-installer.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[SERVICES]
service-names=["ZEPPELIN"]


[ZEPPELIN]
install-commands=[ "VERSION=`hdp-select status hadoop-client | sed 's/hadoop-client - \\([0-9]\\.[0-9]\\).*/\\1/'`", "cp -r ambari-services/ambari-zeppelin-service /var/lib/ambari-server/resources/stacks/HDP/$VERSION/services/ZEPPELIN", "ambari-server restart"]
install-commands=[ "hdp-select status hadoop-client | sed 's/hadoop-client - \\([0-9]\\.[0-9]\\).*/\\1/'", "cp -r ../ambari-services/ambari-zeppelin-service /var/lib/ambari-server/resources/stacks/HDP/$VERSION/services/ZEPPELIN", "ambari-server restart"]
server=localhost
port=9995

# Repo Links for HDP-SELECT
[HDP-SELECT]
Expand Down
63 changes: 56 additions & 7 deletions scripts/service_installer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Script which installs Zeppelin as an Ambari Service
import config, sys, platform, json
import config, sys, platform, json, time
from shell import Shell
from curl_client import CurlClient

def install_hdp_select():
dist_info = platform.linux_distribution()
Expand Down Expand Up @@ -55,6 +56,7 @@ def install_hdp_select():
def is_hdp_select_installed():
sh = Shell()
output = sh.run('which hdp-select')

if len(output[0]) == 0:
return False
else:
Expand All @@ -69,7 +71,11 @@ def is_ambari_installed():
return True


def install_zeppelin(conf_file):

def install_zeppelin(conf_dir):

if not conf_dir.endswith('/'):
conf_dir += '/'

if not is_ambari_installed():
raise EnvironmentError('You must install the demo on the same node as the Ambari server. Install Ambari here or move to another node with Ambari installed before continuing')
Expand All @@ -80,20 +86,63 @@ def install_zeppelin(conf_file):
if not installed:
raise EnvironmentError('hdp-select could not be installed. Please install it manually and then re-run the setup.')

conf = config.read_config(conf_file)
conf = config.read_config(conf_dir + 'service-installer.conf')
cmds = conf['ZEPPELIN']['install-commands']
cmds = json.loads(conf['ZEPPELIN']['install-commands'])

sh = Shell()
# print(sh.run('pwd')[0])
version = sh.run(cmds[0])

fixed_cmd = cmds[1].replace('$VERSION', str(version))
copy = sh.run(fixed_ver)

# print("HDP-VERSION: " + str(version[0]))
fixed_cmd = cmds[1].replace('$VERSION', str(version[0])).replace('\n', '')
# print('FIXED COPY COMMAND: ' + fixed_cmd)
copy = sh.run(fixed_cmd)
# print("COPY OUTPUT: " + copy[0])
restart = sh.run(cmds[2])
# print("Restart output: " + restart[0])


print("Please open the Ambari Interface and manually deploy the Zeppelin Service.")
raw_input("Press enter twice to continue...")
raw_input("Press enter once to continue...")

# We've copied the necessary files. Once that completes we need to add it to Ambari

print('Checking to make sure service is installed')
ambari = config.read_config(conf_dir + 'global-config.conf')['AMBARI']
installed = check_ambari_service_installed('ZEPPELIN', ambari)
cont = ''
if not installed:
print('Unable to contact Ambari Server. Unsure whether or not Zeppelin was installed')
while not (cont == 'y' or cont == 'n'):
cont = raw_input('Continue attempt to set up Zeppelin for demo?(y/n)')
if not (cont == 'y' or cont == 'n'):
print('Please enter "y" or "n"')
else:
cont = 'y'

if cont == 'n':
return False
elif cont == 'y':
return True

def check_ambari_service_installed(service_name, ambari_config):

curl = CurlClient(username=ambari_config['username'], password=ambari_config['password'], port=ambari_config['port'], server=ambari_config['server'], proto=ambari_config['proto'])

cluster_name = ambari_config['cluster_name']
request = '/api/v1/clusters/' + cluster_name + '/services/' + service_name
attempts = 0
while attempts < 10:
output = curl.make_request('GET', request, '-i')
if '200 OK' in output[0]:
print('Service Installed Sucessfully')
return True
else:
attempts += 1
raw_input('Could not connect.' + str(10-attempts) + ' remaining. Press any key to continue')

return False



Expand Down
73 changes: 70 additions & 3 deletions tests/test_service_installer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest, json, mock
import unittest, json, mock, scripts
from env import scripts
from mock import Mock
from scripts import service_installer
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_hdp_select_other_linux(self, mock, mock2):
except EnvironmentError as e:
assert str(e.message) == 'Must be using one of: CentOS 6.x, CentOS 7.x, Ubuntu 12.x, Ubuntu 14.x'

class TestHDPSelectCheck(unittest.TestCase):
class TestComponentCheck(unittest.TestCase):

@mock.patch('scripts.shell.Shell.run', return_value=['/usr/bin/hdp-select', ''])
def test_hdp_select_good(self, mock):
Expand All @@ -92,9 +92,76 @@ def test_hdp_select_good(self, mock):
@mock.patch('scripts.shell.Shell.run', return_value=['', ''])
def test_hdp_select_bad(self, mock):
assert service_installer.is_hdp_select_installed() == False

@mock.patch('scripts.shell.Shell.run', return_value=['/usr/bin/ambari-server', ''])
def test_ambari_good(self, mock):
assert service_installer.is_ambari_installed() == True

@mock.patch('scripts.shell.Shell.run', return_value=['', ''])
def test_ambari_bad(self, mock):
assert service_installer.is_ambari_installed() == False

class TestZeppelinInstall(unittest.TestCase):


@mock.patch('scripts.service_installer.is_ambari_installed', return_value=False)
def test_zeppelin_ambari_bad(self, mock):
try:
service_installer.install_zeppelin('../conf/service-installer.conf')
self.fail('Cannot continue installation without Ambari')
except EnvironmentError as e:
assert str(e.message) == 'You must install the demo on the same node as the Ambari server. Install Ambari here or move to another node with Ambari installed before continuing'

@mock.patch('scripts.service_installer.is_ambari_installed', return_value=True)
@mock.patch('scripts.service_installer.is_hdp_select_installed', return_value=False)
@mock.patch('scripts.service_installer.install_hdp_select', return_value=False)
def test_zeppelin_ambari_good(self, mock, mock2, mock3): #Also HDP select bad
try:
service_installer.install_zeppelin('../conf/service-installer.conf')
self.fail('Cannot continue installation without hdp-select')
except EnvironmentError as e:
assert str(e.message) == 'hdp-select could not be installed. Please install it manually and then re-run the setup.'

@mock.patch('scripts.service_installer.is_ambari_installed', return_value=True)
@mock.patch('scripts.service_installer.is_hdp_select_installed', return_value=True)
@mock.patch('scripts.service_installer.install_hdp_select', return_value=True)
@mock.patch('scripts.service_installer.check_ambari_service_installed', return_value=True)
@mock.patch('__builtin__.raw_input', return_value='y')
def test_zeppelin_check_is_good(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_zeppelin('../conf') == True


@mock.patch('scripts.service_installer.is_ambari_installed', return_value=True)
@mock.patch('scripts.service_installer.is_hdp_select_installed', return_value=True)
@mock.patch('scripts.service_installer.install_hdp_select', return_value=True)
@mock.patch('scripts.service_installer.check_ambari_service_installed', return_value=False)
@mock.patch('__builtin__.raw_input', side_effect=['\n', '\n', 'v', 'y'])
def test_zeppelin_no_ambari_contact_continue(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_zeppelin('../conf') == True


@mock.patch('scripts.service_installer.is_ambari_installed', return_value=True)
@mock.patch('scripts.service_installer.is_hdp_select_installed', return_value=True)
@mock.patch('scripts.service_installer.install_hdp_select', return_value=True)
@mock.patch('scripts.service_installer.check_ambari_service_installed', return_value=False)
@mock.patch('__builtin__.raw_input', side_effect=['\n', '\n', 'v', 'n'])
def test_zeppelin_no_ambari_contact_no_continue(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_zeppelin('../conf') == False

class TestAmbariServiceCheck(unittest.TestCase):


@mock.patch('scripts.curl_client.CurlClient.make_request', side_effect=[['', ''], ['200 OK', '']])
@mock.patch('__builtin__.raw_input', side_effect=['\n', '\n', 'v', 'n'])
def test_ambari_check_good(self, mock, mock2):
conf = scripts.config.read_config('../conf/global-config.conf')['AMBARI']
assert service_installer.check_ambari_service_installed('ZEPPELIN', conf) == True

@mock.patch('scripts.curl_client.CurlClient.make_request', side_effect=[['200 OK', ''], ['200 OK', '']])
@mock.patch('__builtin__.raw_input', side_effect=['\n', '\n', 'v', 'n'])
def test_ambari_check_good(self, mock, mock2):
conf = scripts.config.read_config('../conf/global-config.conf')['AMBARI']
assert service_installer.check_ambari_service_installed('ZEPPELIN', conf) == True




Expand Down

0 comments on commit 0eea835

Please sign in to comment.