Prechádzať zdrojové kódy

Icon for downloads requirements and bug fix for Queue reading

Steve L. Nyemba 8 rokov pred
rodič
commit
a04c916e62
3 zmenil súbory, kde vykonal 52 pridanie a 22 odobranie
  1. 12 4
      src/api/index.py
  2. 9 1
      src/api/static/js/dashboard.js
  3. 31 17
      src/utils/transport.py

+ 12 - 4
src/api/index.py

@@ -59,7 +59,7 @@ class_write= CONFIG['store']['class']['write']
 factory = DataSourceFactory()
 #gWriter = factory.instance(type='CouchdbWritera',args=p)
 #gReader = factory.instance(type='CouchdbReader',args=p)
-
+p['qid'] = HANDLERS['processes']['config'].keys()
 gReader = factory.instance(type=class_read,args=p)
 gWriter = factory.instance(type=class_write,args=p)
 mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
@@ -67,7 +67,8 @@ mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
 @app.route('/get/<id>')
 def procs(id):	
 	try:
-		d =  gReader.basic_read()
+		d =  gReader.read()
+		
 		r = {}
 		for label in d :
 			index = len(d[label]) - 1
@@ -101,11 +102,18 @@ def sandbox():
 def trends ():
 	id = request.args.get('id')
 	app = request.args.get('app').strip()
-	r = gReader.basic_read()
+	p = CONFIG['store']['args']
+	class_read = CONFIG['store']['class']['read']
+
+	p['qid'] =[id] #HANDLERS['processes']['config'].keys()
+	gReader = factory.instance(type=class_read,args=p)
+	
+	r = gReader.read()
 	if id in r:
 		r = r[id] #--matrix
 		series = []
 		for row in r:
+			
 			series += [item for item in row if str(item['label'])== app]
 		if len(series) > 12 :
 			beg = len(series) - 13
@@ -116,7 +124,7 @@ def trends ():
 @app.route('/download',methods=['POST'])
 def requirements():
 	stream = request.form['missing']
-	print stream
+	
 	stream = "\n".join(json.loads(stream))
 	headers = {"content-disposition":"attachment; filename=requirements.txt"}
 	return Response(stream,mimetype='text/plain',headers=headers)

+ 9 - 1
src/api/static/js/dashboard.js

@@ -282,7 +282,14 @@ monitor.sandbox.render = function (logs) {
 	var d = ([logs[0].day, '-', months[logs[0].month], '-', logs[0].year, ' ', logs[0].hour, ':', logs[0].minute]).join('')
 	jx.dom.set.value('sandbox_date', d)
 	var options = { width: $('#sandbox_status').width(), height: 'auto' }
-	options.data = logs
+	options.data = jx.utils.patterns.visitor(logs, function (item) { 
+		if (item.value == 100) {
+			item.status = '<i class="fa fa-check" style="color:green"></i>'
+		} else {
+			item.status = '<i class="fa fa-download" style="color:black"></i>'
+		}
+		return item		
+	})
 	options.paging = true
 	options.pageSize = 4
 	options.pageIndex = 1
@@ -318,6 +325,7 @@ monitor.sandbox.render = function (logs) {
 		}
 	}
 	options.fields = [
+		{name:"status",title:"",width:20},
 		{ name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' },
 		{ name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' }
 		

+ 31 - 17
src/utils/transport.py

@@ -301,7 +301,10 @@ class QueueWriter(MessageQueue,Writer):
 			_type = 'text/plain'
 		else:
 			stream = json.dumps(object)
-			_type = params['type']
+			if 'type' in params :
+				_type = params['type']
+			else:
+				_type = 'application/json'
 
 		self.channel.basic_publish(
 			exchange=self.uid,
@@ -329,15 +332,16 @@ class QueueReader(MessageQueue,Reader):
 		#self.qid = params['qid']
 		MessageQueue.__init__(self,**params);
 		self.size = -1
-		self.data = []
+		self.data = {}
 	
-	def init(self):
+	def init(self,qid):
+		
 		properties = pika.ConnectionParameters(host=self.host)
 		self.connection = pika.BlockingConnection(properties)
 		self.channel	= self.connection.channel()
 		self.channel.exchange_declare(exchange=self.uid,type='direct',durable=True)
 
-		self.info = self.channel.queue_declare(queue=self.qid,durable=True)
+		self.info = self.channel.queue_declare(queue=qid,durable=True)
 	
 
 
@@ -346,13 +350,19 @@ class QueueReader(MessageQueue,Reader):
 
 	"""
 	def callback(self,channel,method,header,stream):
+		r = []
 		if re.match("^\{|\[",stream) is not None:
-			self.data = json.loads(stream)
+			r = json.loads(stream)
 		else:
 			
-			self.data.append(stream)
+			r = stream
+		
+		qid = self.info.method.queue
+		if qid not in self.data :
+			self.data[qid] = []
 		
-		if self.size == len(self.data) or len(self.data) == self.info.method.message_count:		
+		self.data[qid].append(r)
+		if self.size == len(self.data[qid]) or len(self.data[qid]) == self.info.method.message_count:		
 			self.close()
 
 	"""
@@ -362,18 +372,22 @@ class QueueReader(MessageQueue,Reader):
 		Have the number of messages retrieved be specified by size (parameter)
 	"""
 	def read(self,size=-1):
-		
+		r = {}
 		self.size = size
-		self.init()
-		self.data = []
-		if self.info.method.message_count > 0:
+		for qid in self.qid:
+			self.init(qid)
+			# r[qid] = []
+			if self.info.method.message_count > 0:
+				
+				self.channel.basic_consume(self.callback,queue=qid,no_ack=False);
+				self.channel.start_consuming()
+			else:
+				
+				pass
+				#self.close()
 			
-			self.channel.basic_consume(self.callback,queue=self.qid,no_ack=False);
-			self.channel.start_consuming()
-		else:
-			self.data = []
-			self.close()
-		
+			# r[qid].append( self.data)
+		print self.data
 		return self.data
 		
 """