You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ey...@apache.org on 2011/10/07 21:49:53 UTC
svn commit: r1180184 - in /incubator/ambari/trunk:
agent/src/main/python/ambari_agent/
controller/src/main/java/org/apache/ambari/controller/rest/agent/
Author: eyang
Date: Fri Oct 7 19:49:52 2011
New Revision: 1180184
URL: http://svn.apache.org/viewvc?rev=1180184&view=rev
Log:
AMBARI-44. Implemented blueprint name and revision in heartbeat. (Eric Yang)
Modified:
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py
incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py?rev=1180184&r1=1180183&r2=1180184&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py Fri Oct 7 19:49:52 2011
@@ -28,9 +28,12 @@ from shell import shellRunner
logger = logging.getLogger()
class ActionQueue(threading.Thread):
- global q, r
+ global q, r, clusterId, bluePrintName, bluePrintRevision
q = Queue.Queue()
r = Queue.Queue()
+ clusterId = 'unknown'
+ bluePrintName = 'unknown'
+ bluePrintRevision = 'unknown'
def __init__(self):
threading.Thread.__init__(self)
@@ -43,6 +46,7 @@ class ActionQueue(threading.Thread):
# dispatch action types
def run(self):
+ global clusterId, bluePrintName, bluePrintRevision
while True:
while not q.empty():
action = q.get()
@@ -52,6 +56,9 @@ class ActionQueue(threading.Thread):
'RUN_ACTION': self.runAction
}
result = switches.get(action['kind'], self.unknownAction)(action)
+ clusterId = action['clusterId']
+ bluePrintName = action['bluePrintName']
+ bluePrintRevision = action['bluePrintRevision']
r.put(result)
def result(self):
@@ -64,11 +71,13 @@ class ActionQueue(threading.Thread):
# track the liveness of the children process
def startAction(self, action):
result = {
- 'id' : action['id'],
- 'clusterId' : action['clusterId'],
- 'kind' : action['kind'],
- 'component' : action['component'],
- 'role' : action['role']
+ 'id' : action['id'],
+ 'clusterId' : action['clusterId'],
+ 'kind' : action['kind'],
+ 'component' : action['component'],
+ 'role' : action['role'],
+ 'bluePrintName' : action['bluePrintName'],
+ 'bluePrintRevision' : action['bluePrintRevision']
}
self.sh.startProcess(action['component'], action['role'], action['commands'][0]['cmd'], action['user'])
return result
@@ -76,11 +85,13 @@ class ActionQueue(threading.Thread):
# Run stop action, stop a server process.
def stopAction(self, action):
result = {
- 'id' : action['id'],
- 'kind' : action['kind'],
- 'clusterId' : action['clusterId'],
- 'component' : action['component'],
- 'role' : action['role']
+ 'id' : action['id'],
+ 'kind' : action['kind'],
+ 'clusterId' : action['clusterId'],
+ 'component' : action['component'],
+ 'role' : action['role'],
+ 'bluePrintName' : action['bluePrintName'],
+ 'bluePrintRevision' : action['bluePrintRevision']
}
self.sh.stopProcess(action['component'], action['role'], action['signal'])
return result
@@ -88,9 +99,11 @@ class ActionQueue(threading.Thread):
# Run commands action
def runAction(self, action):
result = {
- 'id': action['id'],
- 'clusterId' : action['clusterId'],
- 'kind' : action['kind']
+ 'id' : action['id'],
+ 'clusterId' : action['clusterId'],
+ 'kind' : action['kind'],
+ 'bluePrintName' : action['bluePrintName'],
+ 'bluePrintRevision' : action['bluePrintRevision']
}
return self.runCommands(action['commands'], action['cleanUpCommands'], result)
@@ -133,3 +146,15 @@ class ActionQueue(threading.Thread):
# Discover agent idle state
def isIdle(self):
return q.empty()
+
+ # Report current clusterId
+ def getClusterId(self):
+ return clusterId
+
+ # Report blue print name
+ def getBluePrintName(self):
+ return bluePrintName
+
+ # Report blue print revision
+ def getBluePrintRevision(self):
+ return bluePrintRevision
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py?rev=1180184&r1=1180183&r2=1180184&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py Fri Oct 7 19:49:52 2011
@@ -43,7 +43,7 @@ class Controller(threading.Thread):
self.lock = threading.Lock()
self.safeMode = True
self.credential = credential
- self.url = url + '/agent/' + socket.gethostname()
+ self.url = url + '/agent/controller/heartbeat/' + socket.gethostname()
def start(self):
self.actionQueue = ActionQueue()
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py?rev=1180184&r1=1180183&r2=1180184&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py Fri Oct 7 19:49:52 2011
@@ -26,27 +26,31 @@ import socket
import time
class Heartbeat:
+
def __init__(self, actionQueue):
self.actionQueue = actionQueue
+ self.hardware = Hardware()
def build(self, id='unknown'):
- hardware = Hardware()
+ global clusterId, bluePrintName, bluePrintRevision
serverStatus = ServerStatus()
timestamp = int(time.time()*1000)
- heartbeat = { 'responseId' : id,
- 'timestamp' : timestamp,
- 'clusterId' : 'unknown',
- 'stackId' : 'unknown',
- 'hostname' : socket.gethostname(),
- 'hardwareProfile' : hardware.get(),
- 'actionResults' : self.actionQueue.result(),
- 'serversStatus' : serverStatus.build(),
- 'idle' : self.actionQueue.isIdle()
+ heartbeat = { 'responseId' : id,
+ 'timestamp' : timestamp,
+ 'clusterId' : self.actionQueue.getClusterId(),
+ 'bluePrintName' : self.actionQueue.getBluePrintName(),
+ 'bluePrintRevision' : self.actionQueue.getBluePrintRevision(),
+ 'hostname' : socket.gethostname(),
+ 'hardwareProfile' : self.hardware.get(),
+ 'actionResults' : self.actionQueue.result(),
+ 'serversStatus' : serverStatus.build(),
+ 'idle' : self.actionQueue.isIdle()
}
return heartbeat
def main(argv=None):
- heartbeat = Heartbeat()
+ actionQueue = ActionQueue()
+ heartbeat = Heartbeat(actionQueue)
print json.dumps(heartbeat.build())
if __name__ == '__main__':
Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java?rev=1180184&r1=1180183&r2=1180184&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java Fri Oct 7 19:49:52 2011
@@ -50,7 +50,7 @@ import org.apache.ambari.common.rest.ent
* as well as report the node attributes and state of services running the on
* the cluster nodes
*/
-@Path(value = "/controller")
+@Path("controller")
public class ControllerResource {
/**
@@ -62,7 +62,7 @@ public class ControllerResource {
* @response.representation.500.doc Error in accepting heartbeat message
* @param message Heartbeat message
*/
- @Path(value = "/agent/{hostname}")
+ @Path("heartbeat/{hostname}")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -87,6 +87,8 @@ public class ControllerResource {
action.setKind(Kind.STOP_ACTION);
action.setSignal(Signal.KILL);
action.setClusterId("cluster-001");
+ action.setBluePrintName("blueprint");
+ action.setBluePrintRevision("0.1");
action.setId("action-001");
Action action2 = new Action();
@@ -97,12 +99,16 @@ public class ControllerResource {
action2.setCommands(commands);
action2.setCleanUpCommands(cleanUps);
action2.setComponent("hdfs");
+ action2.setBluePrintName("blueprint");
+ action2.setBluePrintRevision("0.2");
action2.setRole("datanode");
Action action3 = new Action();
action3.setUser("hdfs");
action3.setKind(Kind.RUN_ACTION);
action3.setId("action-003");
+ action3.setBluePrintName("blueprint");
+ action3.setBluePrintRevision("0.2");
action3.setClusterId("cluster-003");
action3.setCommands(commands);
action3.setCleanUpCommands(cleanUps);
@@ -123,7 +129,7 @@ public class ControllerResource {
* @param stackId Stack ID
* @return Heartbeat message
*/
- @Path("agent/heartbeat/sample")
+ @Path("heartbeat/sample")
@GET
@Produces(MediaType.APPLICATION_JSON)
public HeartBeat getHeartBeat(@DefaultValue("stack-123")