Browse Source

Refactored API and views

Steve L. Nyemba 8 years ago
parent
commit
75f948bf97
2 changed files with 48 additions and 24 deletions
  1. 1 1
      couchdb/views.js
  2. 47 23
      src/api/index.py

File diff suppressed because it is too large
+ 1 - 1
couchdb/views.js


+ 47 - 23
src/api/index.py

@@ -48,19 +48,39 @@ class_write= CONFIG['store']['class']['write']
 factory = DataSourceFactory()
 factory = DataSourceFactory()
 # gReader = factory.instance(type=class_read,args=p)
 # gReader = factory.instance(type=class_read,args=p)
 
 
-@app.route('/1/get/apps')
+@app.route('/1/get/nodes')
 def get_apps():
 def get_apps():
     """
     """
 		This function returns the labels of applications for every node registered
 		This function returns the labels of applications for every node registered
+		@param None
 		e.g: apps@zulu.org
 		e.g: apps@zulu.org
 	"""
 	"""
 	r = []
 	r = []
 	try:
 	try:
+		gReader = factory.instance(type=class_read,args=p)
+		r =  gReader.view('summary/nodes',key=p['uid'])
+	except Exception,e:
+		print (e)
+	return json.dumps(r)
+
+@app.route('/1/get/apps')
+def get_apps():
+    """
+		This function returns the applications for a given node
+		@param node identifier e.g: apps@zulu.org
+	"""
+	r = []
+	try:
+		node_id = request.args.get('node')
 		gReader = factory.instance(type=class_read,args=p)
 		gReader = factory.instance(type=class_read,args=p)
 		r =  gReader.view('summary/app_names',key=p['uid'])
 		r =  gReader.view('summary/app_names',key=p['uid'])
+		r = r[node_id]
 	except Exception,e:
 	except Exception,e:
 		print (e)
 		print (e)
 	return json.dumps(r)
 	return json.dumps(r)
+
+
+
 @app.route('/1/get/summary/<id>')
 @app.route('/1/get/summary/<id>')
 def get_summary(id):
 def get_summary(id):
     """
     """
@@ -88,7 +108,7 @@ def get_usage_trend():
 	"""
 	"""
 
 
 		This function returns cpu/memory usage for the entire system being monitored. It will return the 24 most recent observations in the logs
 		This function returns cpu/memory usage for the entire system being monitored. It will return the 24 most recent observations in the logs
-		No parameters should be passed.
+		@param 	None
 		@return {memory_usage:[],cpu_usage:[],app_count:value,memory_available:[]}
 		@return {memory_usage:[],cpu_usage:[],app_count:value,memory_available:[]}
 	"""
 	"""
 	r = {}
 	r = {}
@@ -104,37 +124,41 @@ def get_usage_trend():
 def get_usage_detail():
 def get_usage_detail():
 	"""
 	"""
 		This function returns detailed information about usage per application monitored. It will return the 24 most recent observations in the logs
 		This function returns detailed information about usage per application monitored. It will return the 24 most recent observations in the logs
-		No parameters should be passed
-		@return {app_1:{memory_usage:[],cpu_usage:[]},app_2:{memory_usage:[],cpu_usage:[]},...}
-		@TODO: 
-			- add node references because if the same application lives on other nodes the info will be overriden
-			- parameters to be passed will be the node information
+		
+		@param node	node identifier e.g: apps@zulu.io
+		@return {node_x:{app_1:{memory_usage:[],cpu_usage:[]}},...}
 	"""
 	"""
 	r = {}
 	r = {}
 	try:
 	try:
+		id = request.args.get('node')
 		gReader = factory.instance(type=class_read,args=p)
 		gReader = factory.instance(type=class_read,args=p)
 		r = gReader.view('summary/app_resource_usage_details',key=p['uid'])
 		r = gReader.view('summary/app_resource_usage_details',key=p['uid'])
+		r = r[id]
 	except Exception,e:
 	except Exception,e:
 		print (e)
 		print (e)
 	return json.dumps(r)
 	return json.dumps(r)
-@app.route('/1/app/status/<id>')
-def app_status(id) :
+@app.route('/1/app/status')
+def app_status() :
     	"""
     	"""
-			This function aggregates the number of crashes/running/idle instances found in the past 24 log entries
-			@TODO: The back-end doesn't allow nodes to be specified
-			@param id	node that contains an app
-		"""
-		r = []
+		This function aggregates the number of crashes/running/idle instances found in the past 24 log entries
+		
+		@param nid	node identifier e.g: app@zulu.io
+		@param aid	application identifier e.g: kate, firefox, chrome ... specified in the configuraiton
+	"""
+	r = []
     	try:
     	try:
-			gReader = factory.instance(type=class_read,args=p)
-			r = gReader.view('summary/app_status_details',key=p['uid'])
-			#
-			#@TODO: Once the back-end enables the nodes in which the application is running, uncomment the line below
-			#
-			#r = r[id]
-		except Exception,e:
-			print e
-		return r	
+		nid = request.args.get('node') # Node identifier
+		aid = request.args.get('app') # application identifier
+		
+		gReader = factory.instance(type=class_read,args=p)
+		r = gReader.view('summary/app_status_details',key=p['uid'])
+		#
+		#@TODO: Once the back-end enables the nodes in which the application is running, uncomment the line below
+		#
+		r = r[nid][aid]
+	except Exception,e:
+		print e
+	return r	
 @app.route('/get/<id>')
 @app.route('/get/<id>')
 def procs(id):
 def procs(id):
 	try:
 	try: