Commit c93e0972 by Suma Shivaprasad

ATLAS-238 atlas_start.py- the Atlas server won’t restart after improper…

ATLAS-238 atlas_start.py- the Atlas server won’t restart after improper shutdown(ndjouri via sumasai)
parent e48dbc9d
...@@ -16,14 +16,15 @@ ...@@ -16,14 +16,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import getpass import getpass
import os import os
import platform import platform
import subprocess import subprocess
from threading import Thread from threading import Thread
from signal import SIGTERM
import sys import sys
import time import time
import errno import errno
from re import split
LIB = "lib" LIB = "lib"
CONF = "conf" CONF = "conf"
...@@ -288,4 +289,39 @@ def writePid(metadata_pid_file, process): ...@@ -288,4 +289,39 @@ def writePid(metadata_pid_file, process):
f.write(str(process.pid)) f.write(str(process.pid))
f.close() 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
...@@ -56,11 +56,37 @@ def main(): ...@@ -56,11 +56,37 @@ def main():
+ os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "*" ) + p \ + os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "*" ) + p \
+ os.path.join(metadata_home, "libext", "*") + os.path.join(metadata_home, "libext", "*")
metadata_pid_file = mc.pidFile(metadata_home) metadata_pid_file = mc.pidFile(metadata_home)
if os.path.isfile(metadata_pid_file): if os.path.isfile(metadata_pid_file):
print "%s already exists, exiting" % metadata_pid_file #Check if process listed in atlas.pid file is still running
sys.exit() 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 = ["-app", os.path.join(web_app_dir, "atlas")]
args.extend(sys.argv[1:]) args.extend(sys.argv[1:])
......
...@@ -18,7 +18,6 @@ See the License for the specific language governing permissions and ...@@ -18,7 +18,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
''' '''
import sys import sys
from os import environ from os import environ
from mock import patch from mock import patch
import unittest import unittest
...@@ -28,36 +27,49 @@ import atlas_start as metadata ...@@ -28,36 +27,49 @@ import atlas_start as metadata
import platform import platform
IS_WINDOWS = platform.system() == "Windows" IS_WINDOWS = platform.system() == "Windows"
logger = logging.getLogger() logger = logging.getLogger()
class TestMetadata(unittest.TestCase): class TestMetadata(unittest.TestCase):
@patch.object(mc,"win_exist_pid")
@patch.object(mc,"unix_exist_pid")
@patch.object(mc,"writePid") @patch.object(mc,"writePid")
@patch.object(mc, "executeEnvSh") @patch.object(mc, "executeEnvSh")
@patch.object(mc,"metadataDir") @patch.object(mc,"metadataDir")
@patch.object(mc, "expandWebApp") @patch.object(mc, "expandWebApp")
@patch("os.path.exists") @patch("os.path.exists")
@patch.object(mc, "java") @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 = [] sys.argv = []
exists_mock.return_value = True exists_mock.return_value = True
expandWebApp_mock.return_value = "webapp" expandWebApp_mock.return_value = "webapp"
metadataDir_mock.return_value = "metadata_home" 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() metadata.main()
self.assertTrue(java_mock.called) self.assertTrue(java_mock.called)
if IS_WINDOWS: if IS_WINDOWS:
java_mock.assert_called_with( java_mock.assert_called_with(
'org.apache.atlas.Atlas', 'org.apache.atlas.Atlas',
['-app', 'metadata_home\\server\\webapp\\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\\*', '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') ['-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: else:
java_mock.assert_called_with( java_mock.assert_called_with(
'org.apache.atlas.Atlas', 'org.apache.atlas.Atlas',
['-app', 'metadata_home/server/webapp/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/*', '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') ['-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 pass
def test_jar_java_lookups_fail(self): def test_jar_java_lookups_fail(self):
......
...@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags) ...@@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags)
ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags) ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags)
ALL CHANGES: 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-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-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) ATLAS-208 Remove "\n" characters in the REST API json response (patel_satya via shwethags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment