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

Commit

Permalink
[#6] - Adding in NiFi installer function (#14)
Browse files Browse the repository at this point in the history
NiFi can now be installed as an ambari service via `service_installer.install_nifi`
  • Loading branch information
ZacBlanco authored Jun 23, 2016
1 parent 9a15fdc commit e485ad7
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
8 changes: 7 additions & 1 deletion conf/service-installer.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
[SERVICES]
service-names=["ZEPPELIN"]
service-names=["ZEPPELIN", "NIFI"]


[ZEPPELIN]
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


[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 @@ -71,7 +71,6 @@ def is_ambari_installed():
return True



def install_zeppelin(conf_dir):

if not conf_dir.endswith('/'):
Expand Down Expand Up @@ -126,6 +125,65 @@ def install_zeppelin(conf_dir):
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
46 changes: 46 additions & 0 deletions tests/test_service_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,53 @@ def test_ambari_check_false(self, mock, mock2):
def test_ambari_check_many_attempts(self, mock, mock2):
conf = scripts.config.read_config('../conf/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


@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_nifi_no_ambari_contact_no_continue(self, mock, mock2, mock3, mock4, mock5):
assert service_installer.install_nifi('../conf') == False



Expand Down

0 comments on commit e485ad7

Please sign in to comment.