Commit 10d66e4b authored by project's avatar project

--no commit message

--no commit message
parent 7ad6dace
{ {
"type" : "redis", "type" : "redis",
"url" : "redis://:lab1.igridproject.info:6380/1" "url" : "redis://:@lab1.igridproject.info:6379/1"
} }
var Redis = require('ioredis');
const PREFIX = 'bs:http:acl';
module.exports.create = function(cfg)
{
return new HttpACL(cfg);
}
module.exports.mkACL = function(appkey,method,jobid,opt)
{
var a = {
'appkey' : appkey,
'method' : method,
'jobid' : jobid
}
if(opt){a.opt = opt}
return a;
}
function HttpACL(cfg)
{
this.config = cfg;
if(cfg.conn){
this.mem = new Redis(cfg.conn);
}else if(cfg.redis){
this.mem = cfg.redis;
}else{
this.mem = null;
}
this.acl = [];
}
HttpACL.prototype.add = function(acl)
{
var found = false;
this.acl.forEach( function (val) {
if(val.appkey == acl.appkey && val.method == acl.method && val.jobid == acl.jobid){
found = true;
}
});
if(!found){
this.acl.push(acl);
}
}
HttpACL.prototype.clean = function()
{
this.acl = [];
}
HttpACL.prototype.update = function(cb)
{
var self=this;
this.mem.get(PREFIX, function (err, result) {
if(!err && result){
self.acl = JSON.parse(result);
}
cb(err);
});
}
HttpACL.prototype.commit = function(cb)
{
var stracl = JSON.stringify(this.acl);
this.mem.set(PREFIX,stracl);
if(typeof cb == 'function'){
cb();
}
}
HttpACL.prototype.findJob= function(appkey,method)
{
var jobs = [];
this.acl.forEach( function (val) {
if(val.appkey == appkey && val.method == method){
jobs.push(val);
}
});
return jobs;
}
function ResourceStore(prm)
{
}
...@@ -29,9 +29,9 @@ const crypto = require("crypto"); ...@@ -29,9 +29,9 @@ const crypto = require("crypto");
// console.log('open'); // console.log('open');
// }); // });
var Db = ctx.getLib('storage-service/lib/db'); //var Db = ctx.getLib('storage-service/lib/db');
var database = Db.create({'repos_dir':'D:/testfile'}); //var database = Db.create({'repos_dir':'D:/testfile'});
// var req = { // var req = {
// 'object_type' : 'storage_request', // 'object_type' : 'storage_request',
...@@ -62,20 +62,33 @@ var database = Db.create({'repos_dir':'D:/testfile'}); ...@@ -62,20 +62,33 @@ var database = Db.create({'repos_dir':'D:/testfile'});
// database.request(req,function(err,res){ // database.request(req,function(err,res){
// console.log(res); // console.log(res);
// }); // });
var cluster = require('cluster');
var http = require('http');
var numCPUs = 4;
if (cluster.isMaster) { // var Redis = require("ioredis");
for (var i = 0; i < numCPUs; i++) { // var redis = new Redis({
cluster.fork(); // port: 6379, // Redis port
} // host: 'lab1.igridproject.info', // Redis host
} else { // db: 0
console.log('process ' + process.pid + ' says hello!'); // })
http.createServer(function(req, res) { // var redis = new Redis('redis://:@lab1.igridproject.info:6379/4')
// var a = [];
// a.push({'appkey':'test-igrid','method':'get','jobid':'igrid'});
// a.push({'appkey':'ibitz-test','method':'get','jobid':'ibitz'});
res.writeHead(200); // atext = JSON.stringify(a);
res.end('process ' + process.pid + ' says hello!'); // redis.set('a',atext)
}).listen(8000);
} var HttpACL = ctx.getLib('lib/mems/http-acl');
var httpacl = HttpACL.create({'conn':'redis://:@lab1.igridproject.info:6379/1'});
httpacl.add({'appkey':'app1','method':'get','jobid':'job1'})
httpacl.add({'appkey':'app2','method':'get','jobid':'job2'})
httpacl.add({'appkey':'app1','method':'get','jobid':'job3'})
httpacl.commit();
httpacl.update(function(err){
//console.log(httpacl.acl);
var j = httpacl.findJob('app1','get');
console.log(j);
});
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://lab1.igridproject.info', function(err, conn) {
conn.createChannel(function(err, ch) {
var ex = 'topic_logs';
var key = 'q.test.t1';
var msg = 'Hello World!';
ch.assertExchange(ex, 'topic', {durable: false});
ch.publish(ex, key, new Buffer(msg));
console.log(" [x] Sent %s:'%s'", key, msg);
// ch.publish(ex, key, new Buffer(msg),function(err){
// console.log(" [x] Sent %s:'%s'", key, msg);
// conn.close()
// });
// conn.close(function(err){
// console.log('cloased');
// });
});
//setTimeout(function() { conn.close(); process.exit(0) }, 15000);
});
#!/usr/bin/env node
var ctx = require('../context');
var cfg = ctx.config;
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://lab1.igridproject.info', function(err, conn) {
conn.createChannel(function(err, ch) {
var ex = 'topic_logs';
ch.assertExchange(ex, 'topic', {durable: false});
ch.assertQueue('', {exclusive: true}, function(err, q) {
console.log(' [*] Waiting for logs. To exit press CTRL+C');
ch.bindQueue(q.queue, ex, 'q.test.t1');
ch.consume(q.queue, function(msg) {
console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString());
}, {noAck: true});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment