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

Commit

Permalink
Merge branch 'master' into add-zeppelin-notebook
Browse files Browse the repository at this point in the history
# Conflicts:
#	scripts/service_installer.py
#	tests/test_service_installer.py
  • Loading branch information
ZacBlanco committed Jun 23, 2016
2 parents 0ebcb31 + e485ad7 commit 2e7b047
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
8 changes: 7 additions & 1 deletion conf/service-installer.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[SERVICES]
service-names=["ZEPPELIN"]
service-names=["ZEPPELIN", "NIFI"]


[ZEPPELIN]
Expand All @@ -8,6 +8,12 @@ protocol=http
server=localhost
port=9995


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

# Repo Links for HDP-SELECT
[HDP-SELECT]
ubuntu12="http://public-repo-1.hortonworks.com/HDP/ubuntu12/2.x/updates/2.4.2.0/pool/main/h/hdp-select/hdp-select_2.4.2.0-258_all.deb"
Expand Down
60 changes: 59 additions & 1 deletion scripts/service_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def post_notebook(notebook_path):
return False

def install_zeppelin():

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 Down Expand Up @@ -149,6 +148,65 @@ def install_zeppelin():
elif cont == 'y':
return True



def install_nifi(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')


if not is_hdp_select_installed():
installed = install_hdp_select()
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_dir + 'service-installer.conf')
cmds = json.loads(conf['NIFI']['install-commands'])

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


print("Please open the Ambari Interface and manually deploy the NiFi 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('NIFI', 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 NiFi 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'])
Expand Down
44 changes: 39 additions & 5 deletions tests/test_service_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,45 @@ def test_ambari_check_false(self, mock, mock2):
def test_ambari_check_many_attempts(self, mock, mock2):
conf = scripts.config.read_config('global-config.conf')['AMBARI']
assert service_installer.check_ambari_service_installed('ZEPPELIN', conf) == False



class TestNiFiInstall(unittest.TestCase):

@mock.patch('scripts.service_installer.is_ambari_installed', return_value=False)
def test_nifi_ambari_bad(self, mock):
try:
service_installer.install_nifi('../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_nifi_ambari_good(self, mock, mock2, mock3): #Also HDP select bad
try:
service_installer.install_nifi('../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_nifi_check_is_good(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_nifi('../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_nifi_no_ambari_contact_continue(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_nifi('../conf') == True


class TestZeppelinAddNotebook(unittest.TestCase):

Expand Down Expand Up @@ -209,9 +247,5 @@ def test_post_notebook(self, mock1, mock2):









0 comments on commit 2e7b047

Please sign in to comment.