Icon for downloads requirements and bug fix for Queue reading

master
Steve L. Nyemba 8 years ago
parent a374e06721
commit a04c916e62

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

@ -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('') 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) jx.dom.set.value('sandbox_date', d)
var options = { width: $('#sandbox_status').width(), height: 'auto' } 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.paging = true
options.pageSize = 4 options.pageSize = 4
options.pageIndex = 1 options.pageIndex = 1
@ -318,6 +325,7 @@ monitor.sandbox.render = function (logs) {
} }
} }
options.fields = [ options.fields = [
{name:"status",title:"",width:20},
{ name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' }, { name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' },
{ name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' } { name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' }

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

Loading…
Cancel
Save