diff --git a/conf/service-installer.conf b/conf/service-installer.conf index 9461aec..519baf1 100644 --- a/conf/service-installer.conf +++ b/conf/service-installer.conf @@ -1,5 +1,5 @@ [SERVICES] -service-names=["ZEPPELIN"] +service-names=["ZEPPELIN", "NIFI"] [ZEPPELIN] @@ -7,6 +7,12 @@ install-commands=[ "hdp-select status hadoop-client | sed 's/hadoop-client - \\( 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" diff --git a/scripts/service_installer.py b/scripts/service_installer.py index a016d0f..9a1c7b4 100644 --- a/scripts/service_installer.py +++ b/scripts/service_installer.py @@ -71,7 +71,6 @@ def is_ambari_installed(): return True - def install_zeppelin(conf_dir): if not conf_dir.endswith('/'): @@ -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']) diff --git a/tests/test_service_installer.py b/tests/test_service_installer.py index f99455d..369fbb1 100644 --- a/tests/test_service_installer.py +++ b/tests/test_service_installer.py @@ -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