Repository: incubator-atlas Updated Branches: refs/heads/master e48dbc9d6 -> c93e0972a
ATLAS-238 atlas_start.py- the Atlas server wonât restart after improper shutdown(ndjouri via sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/c93e0972 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/c93e0972 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/c93e0972 Branch: refs/heads/master Commit: c93e0972a1201dcd0d5ce8a9286a4c96348c6b44 Parents: e48dbc9 Author: Suma Shivaprasad <[email protected]> Authored: Mon Nov 9 17:53:24 2015 +0530 Committer: Suma Shivaprasad <[email protected]> Committed: Mon Nov 9 17:53:24 2015 +0530 ---------------------------------------------------------------------- distro/src/bin/atlas_config.py | 40 +++++++++++++++++++-- distro/src/bin/atlas_start.py | 32 +++++++++++++++-- distro/src/test/python/scripts/TestMetadata.py | 20 ++++++++--- release-log.txt | 1 + 4 files changed, 84 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c93e0972/distro/src/bin/atlas_config.py ---------------------------------------------------------------------- diff --git a/distro/src/bin/atlas_config.py b/distro/src/bin/atlas_config.py index a3a23ef..f545a30 100755 --- a/distro/src/bin/atlas_config.py +++ b/distro/src/bin/atlas_config.py @@ -16,14 +16,15 @@ # See the License for the specific language governing permissions and # limitations under the License. import getpass - import os import platform import subprocess from threading import Thread +from signal import SIGTERM import sys import time import errno +from re import split LIB = "lib" CONF = "conf" @@ -288,4 +289,39 @@ def writePid(metadata_pid_file, process): f.write(str(process.pid)) f.close() - +def unix_exist_pid(pid): + #check if process id exist in the current process table + #See man 2 kill - Linux man page for info about the kill(pid,0) system function + + try: + os.kill(pid, 0) + except OSError as e : + + return e.errno == errno.EPERM + + else: + return True + + +def win_exist_pid(pid): + #The os.kill approach does not work on Windows with python 2.7 + #the output from tasklist command is searched for the process id + + command='tasklist /fi "pid eq '+ pid + '"' + sub_process=subprocess.Popen(command, stdout = subprocess.PIPE, shell=False) + sub_process.communicate() + output = subprocess.check_output(command) + output=split(" *",output) + for line in output: + + if pid in line: + return True + + return False + +def server_already_running(pid): + print "Atlas server is already running under process %s" % pid + sys.exit() + +def server_pid_not_running(pid): + print "The Server is no longer running with pid %s" %pid http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c93e0972/distro/src/bin/atlas_start.py ---------------------------------------------------------------------- diff --git a/distro/src/bin/atlas_start.py b/distro/src/bin/atlas_start.py index 0d37732..27a8365 100755 --- a/distro/src/bin/atlas_start.py +++ b/distro/src/bin/atlas_start.py @@ -56,11 +56,37 @@ def main(): + os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "*" ) + p \ + os.path.join(metadata_home, "libext", "*") + metadata_pid_file = mc.pidFile(metadata_home) - + + if os.path.isfile(metadata_pid_file): - print "%s already exists, exiting" % metadata_pid_file - sys.exit() + #Check if process listed in atlas.pid file is still running + pf = file(metadata_pid_file, 'r') + pid = pf.read().strip() + pf.close() + + + if mc.ON_POSIX: + + if mc.unix_exist_pid((int)(pid)): + mc.server_already_running(pid) + else: + mc.server_pid_not_running(pid) + + + else: + if mc.IS_WINDOWS: + if mc.win_exist_pid(pid): + mc.server_already_running(pid) + else: + mc.server_pid_not_running(pid) + + else: + #os other than nt or posix - not supported - need to delete the file to restart server if pid no longer exist + mc.server_already_running(pid) + + args = ["-app", os.path.join(web_app_dir, "atlas")] args.extend(sys.argv[1:]) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c93e0972/distro/src/test/python/scripts/TestMetadata.py ---------------------------------------------------------------------- diff --git a/distro/src/test/python/scripts/TestMetadata.py b/distro/src/test/python/scripts/TestMetadata.py index d47be69..762e0ff 100644 --- a/distro/src/test/python/scripts/TestMetadata.py +++ b/distro/src/test/python/scripts/TestMetadata.py @@ -18,7 +18,6 @@ See the License for the specific language governing permissions and limitations under the License. ''' import sys - from os import environ from mock import patch import unittest @@ -28,36 +27,49 @@ import atlas_start as metadata import platform IS_WINDOWS = platform.system() == "Windows" - logger = logging.getLogger() class TestMetadata(unittest.TestCase): - + @patch.object(mc,"win_exist_pid") + @patch.object(mc,"unix_exist_pid") @patch.object(mc,"writePid") @patch.object(mc, "executeEnvSh") @patch.object(mc,"metadataDir") @patch.object(mc, "expandWebApp") @patch("os.path.exists") @patch.object(mc, "java") - def test_main(self, java_mock, exists_mock, expandWebApp_mock, metadataDir_mock, executeEnvSh_mock, writePid_mock): + + def test_main(self, java_mock, exists_mock, expandWebApp_mock, metadataDir_mock, executeEnvSh_mock, writePid_mock, unix_exist_pid_mock, win_exist_pid_mock): sys.argv = [] exists_mock.return_value = True expandWebApp_mock.return_value = "webapp" metadataDir_mock.return_value = "metadata_home" + + win_exist_pid_mock("789") + win_exist_pid_mock.assert_called_with((str)(789)) + unix_exist_pid_mock(789) + unix_exist_pid_mock.assert_called_with(789) metadata.main() self.assertTrue(java_mock.called) if IS_WINDOWS: + java_mock.assert_called_with( 'org.apache.atlas.Atlas', ['-app', 'metadata_home\\server\\webapp\\atlas'], 'metadata_home\\conf;metadata_home\\server\\webapp\\atlas\\WEB-INF\\classes;metadata_home\\server\\webapp\\atlas\\WEB-INF\\lib\\*;metadata_home\\libext\\*', ['-Datlas.log.dir=metadata_home\\logs', '-Datlas.log.file=application.log', '-Datlas.home=metadata_home', '-Datlas.conf=metadata_home\\conf', '-Xmx1024m', '-XX:MaxPermSize=512m', '-Dlog4j.configuration=atlas-log4j.xml'], 'metadata_home\\logs') + + + + else: java_mock.assert_called_with( 'org.apache.atlas.Atlas', ['-app', 'metadata_home/server/webapp/atlas'], 'metadata_home/conf:metadata_home/server/webapp/atlas/WEB-INF/classes:metadata_home/server/webapp/atlas/WEB-INF/lib/*:metadata_home/libext/*', ['-Datlas.log.dir=metadata_home/logs', '-Datlas.log.file=application.log', '-Datlas.home=metadata_home', '-Datlas.conf=metadata_home/conf', '-Xmx1024m', '-XX:MaxPermSize=512m', '-Dlog4j.configuration=atlas-log4j.xml'], 'metadata_home/logs') + + pass def test_jar_java_lookups_fail(self): http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c93e0972/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 050e455..bfc1b43 100644 --- a/release-log.txt +++ b/release-log.txt @@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags) ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags) ALL CHANGES: +ATALS-238 atlas_start.py- the Atlas server wonât restart after improper shutdown(ndjouri via sumasai) ATLAS-293 UI Requires Internet Access For UI Facelift (darshankumar89 via shwethags) ATLAS-292 The artifactId 'dashboard' should be 'atlas-dashboard' in the webapp/pom.xml (ltfxyz via shwethags) ATLAS-208 Remove "\n" characters in the REST API json response (patel_satya via shwethags)
