You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by sm...@apache.org on 2014/08/12 22:45:26 UTC
[04/12] git commit: SLIDER-285. Slider Agents to bind and work with
restarted AM (Gour Saha via smohanty)
SLIDER-285. Slider Agents to bind and work with restarted AM (Gour Saha via smohanty)
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/4c62ca5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/4c62ca5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/4c62ca5b
Branch: refs/heads/feature/SLIDER-285_Restart_AM
Commit: 4c62ca5bb7e6a6fa463c4be002e92ce041917d1a
Parents: 58014d8
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Mon Aug 11 18:37:24 2014 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Mon Aug 11 20:15:38 2014 -0700
----------------------------------------------------------------------
slider-agent/src/main/python/agent/AgentConfig.py | 4 ++--
slider-agent/src/main/python/agent/Registry.py | 6 ++++--
.../src/test/python/agent/TestHeartbeat.py | 12 +++++++-----
slider-agent/src/test/python/agent/TestMain.py | 18 +++++++-----------
4 files changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4c62ca5b/slider-agent/src/main/python/agent/AgentConfig.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/main/python/agent/AgentConfig.py b/slider-agent/src/main/python/agent/AgentConfig.py
index 9adace1..e45ba23 100644
--- a/slider-agent/src/main/python/agent/AgentConfig.py
+++ b/slider-agent/src/main/python/agent/AgentConfig.py
@@ -33,8 +33,8 @@ content = """
hostname=localhost
port=8440
secured_port=8441
-zk-quorum=localhost:2181
-zk-reg-path=/register/org-apache-slider/cl1
+zk_quorum=localhost:2181
+zk_reg_path=/register/org-apache-slider/cl1
check_path=/ws/v1/slider/agents/
register_path=/ws/v1/slider/agents/{name}/register
heartbeat_path=/ws/v1/slider/agents/{name}/heartbeat
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4c62ca5b/slider-agent/src/main/python/agent/Registry.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/main/python/agent/Registry.py b/slider-agent/src/main/python/agent/Registry.py
index 256509f..99d7f08 100644
--- a/slider-agent/src/main/python/agent/Registry.py
+++ b/slider-agent/src/main/python/agent/Registry.py
@@ -32,6 +32,7 @@ class Registry:
def readAMHostPort(self):
amHost = ""
amSecuredPort = ""
+ zk = None
try:
zk = KazooClient(hosts=self.zk_quorum, read_only=True)
zk.start()
@@ -45,10 +46,11 @@ class Registry:
amSecuredPort = amSecuredPort.encode('utf8', 'ignore')
except Exception:
# log and let empty strings be returned
- logger.error("Could not connect to zk registry at {} in quorum {}" %
+ logger.error("Could not connect to zk registry at %s in quorum %s" %
(self.zk_reg_path, self.zk_quorum))
pass
finally:
- zk.close()
+ if not zk == None:
+ zk.close()
logger.info("AM Host = %s, AM Secured Port = %s" % (amHost, amSecuredPort))
return amHost, amSecuredPort
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4c62ca5b/slider-agent/src/test/python/agent/TestHeartbeat.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/agent/TestHeartbeat.py b/slider-agent/src/test/python/agent/TestHeartbeat.py
index b60c14c..a9da65d 100644
--- a/slider-agent/src/test/python/agent/TestHeartbeat.py
+++ b/slider-agent/src/test/python/agent/TestHeartbeat.py
@@ -30,7 +30,7 @@ from mock.mock import patch, MagicMock, call
import StringIO
import sys
import logging
-
+from Controller import State
class TestHeartbeat(TestCase):
def setUp(self):
@@ -50,7 +50,7 @@ class TestHeartbeat(TestCase):
dummy_controller = MagicMock()
actionQueue = ActionQueue(config, dummy_controller)
heartbeat = Heartbeat(actionQueue, config)
- result = heartbeat.build({}, 100)
+ result = heartbeat.build({}, State.STARTED, 100)
print "Heartbeat: " + str(result)
self.assertEquals(result['hostname'] != '', True,
"hostname should not be empty")
@@ -63,8 +63,9 @@ class TestHeartbeat(TestCase):
self.assertEquals(len(result['nodeStatus']), 2)
self.assertEquals(result['nodeStatus']['cause'], "NONE")
self.assertEquals(result['nodeStatus']['status'], "HEALTHY")
+ self.assertEquals(result['agentState'], State.STARTED)
# result may or may NOT have an agentEnv structure in it
- self.assertEquals((len(result) is 5) or (len(result) is 6), True)
+ self.assertEquals((len(result) is 6) or (len(result) is 7), True)
self.assertEquals(not heartbeat.reports, True,
"Heartbeat should not contain task in progress")
@@ -129,7 +130,8 @@ class TestHeartbeat(TestCase):
],
}
heartbeat = Heartbeat(actionQueue, config)
- hb = heartbeat.build({}, 10)
+ # State.STARTED results in agentState to be set to 4 (enum order)
+ hb = heartbeat.build({}, State.STARTED, 10)
hb['hostname'] = 'hostname'
hb['timestamp'] = 'timestamp'
hb['fqdn'] = 'fqdn'
@@ -137,7 +139,7 @@ class TestHeartbeat(TestCase):
{'status': 'HEALTHY',
'cause': 'NONE'},
'timestamp': 'timestamp', 'hostname': 'hostname', 'fqdn': 'fqdn',
- 'responseId': 10, 'reports': [
+ 'agentState': 4, 'responseId': 10, 'reports': [
{'status': 'IN_PROGRESS', 'roleCommand': u'INSTALL',
'serviceName': u'HDFS', 'role': u'DATANODE', 'actionId': '1-1',
'stderr': 'Read from /tmp/errors-3.txt',
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4c62ca5b/slider-agent/src/test/python/agent/TestMain.py
----------------------------------------------------------------------
diff --git a/slider-agent/src/test/python/agent/TestMain.py b/slider-agent/src/test/python/agent/TestMain.py
index 0d1e1de..bc68582 100644
--- a/slider-agent/src/test/python/agent/TestMain.py
+++ b/slider-agent/src/test/python/agent/TestMain.py
@@ -260,15 +260,12 @@ class TestMain(unittest.TestCase):
self.assertTrue(start_mock.called)
class AgentOptions:
- def __init__(self, label, host, port, secured_port, zk_quorum, zk_reg_path, verbose, debug):
+ def __init__(self, label, zk_quorum, zk_reg_path, verbose, debug):
self.label = label
- self.host = host
- self.port = port
- self.secured_port = secured_port
- self.verbose = verbose
- self.debug = debug
self.zk_quorum = zk_quorum
self.zk_reg_path = zk_reg_path
+ self.verbose = verbose
+ self.debug = debug
@patch.object(main, "setup_logging")
@patch.object(main, "bind_signal_handlers")
@@ -294,17 +291,16 @@ class TestMain(unittest.TestCase):
Controller_init_mock.return_value = None
isAlive_mock.return_value = False
parse_args_mock.return_value = (
- TestMain.AgentOptions("agent", "host1", "8080", "8081", "host1:2181", "/registry/org-apache-slider/cl1", True, ""), [])
+ TestMain.AgentOptions("agent", "host1:2181", "/registry/org-apache-slider/cl1", True, ""), [])
tmpdir = tempfile.gettempdir()
#testing call without command-line arguments
os.environ["AGENT_WORK_ROOT"] = os.path.join(tmpdir, "work")
os.environ["AGENT_LOG_ROOT"] = os.path.join(tmpdir, "log")
main.main()
- self.assertTrue(AgentConfig_set_mock.call_count == 4)
- AgentConfig_set_mock.assert_any_call("server", "hostname", "host1")
- AgentConfig_set_mock.assert_any_call("server", "port", "8080")
- AgentConfig_set_mock.assert_any_call("server", "secured_port", "8081")
+ self.assertTrue(AgentConfig_set_mock.call_count == 3)
+ AgentConfig_set_mock.assert_any_call("server", "zk_quorum", "host1:2181")
+ AgentConfig_set_mock.assert_any_call("server", "zk_reg_path", "/registry/org-apache-slider/cl1")
if __name__ == "__main__":