|
|
|
@ -18,18 +18,18 @@ var gulp = require('gulp'),
|
|
|
|
|
app = hawtio.app,
|
|
|
|
|
shellprocess = require('child_process'),
|
|
|
|
|
xmloperation = require('./app/xmloperation'),
|
|
|
|
|
rootdir = process.env.STORAGE_PATH || '/home/server_data/',
|
|
|
|
|
K8s = require('k8s'),
|
|
|
|
|
crontab = require('node-crontab'),
|
|
|
|
|
async = require('async'),
|
|
|
|
|
myjs=require('./app/my.js');
|
|
|
|
|
|
|
|
|
|
var oracledb = require('oracledb');
|
|
|
|
|
|
|
|
|
|
var plugins = gulpLoadPlugins({});
|
|
|
|
|
var pkg = require('./package.json');
|
|
|
|
|
var time =0;
|
|
|
|
|
var schedule = [];
|
|
|
|
|
|
|
|
|
|
var allDataPath = process.env.ALL_DATA || '/home/all_data';
|
|
|
|
|
var rootdir = allDataPath + "/collecting_data/";
|
|
|
|
|
var kubectl = K8s.kubectl({
|
|
|
|
|
endpoint: process.env.KUBERNETES_MASTER,
|
|
|
|
|
binary: '/usr/bin/kubectl'
|
|
|
|
@ -313,7 +313,7 @@ gulp.task('connect', ['watch'], function() {
|
|
|
|
|
if(req.method=='POST') {
|
|
|
|
|
var data = [];
|
|
|
|
|
var parser = new xml2js.Parser();
|
|
|
|
|
fs.readFile(rootdir + 'data.xml', function(err, xml) {
|
|
|
|
|
fs.readFile(rootdir + '/data.xml', function(err, xml) {
|
|
|
|
|
parser.parseString(xml, function (err, result) {
|
|
|
|
|
myjs.Recursion(result.node);
|
|
|
|
|
data.push(result.node);
|
|
|
|
@ -324,9 +324,9 @@ gulp.task('connect', ['watch'], function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hawtio.use("/oracleAppPath",function(req,res){
|
|
|
|
|
var dataPath = "/home/ubuntu/data/";
|
|
|
|
|
var tmpPath = "/home/ubuntu/tmp/app";
|
|
|
|
|
var appSource="/home/app";
|
|
|
|
|
var dataPath = allDataPath + "/tabulate_data/";
|
|
|
|
|
var tmpPath = allDataPath + "/tmp_data/app";
|
|
|
|
|
var appSource=allDataPath + "/template/app";
|
|
|
|
|
if(req.method="POST"){
|
|
|
|
|
var timestamp=new Date();
|
|
|
|
|
if((timestamp.getTime() - time) >= 2*60*1000){
|
|
|
|
@ -337,7 +337,7 @@ gulp.task('connect', ['watch'], function() {
|
|
|
|
|
fs.mkdirSync(dataPath);
|
|
|
|
|
//path.exists(tmpPath,function(exists){if(exists) console.log("exists");});
|
|
|
|
|
fs.renameSync(tmpPath, dataPath+"app");
|
|
|
|
|
console.log("move 'home/ubuntu/tmp/app' to " + dataPath);
|
|
|
|
|
console.log("move '" + tmpPath + "' to " + dataPath);
|
|
|
|
|
xmloperation.savehuizong(timestamp.Format('yyyy-MM-dd hh:mm:ss'), '10', id, "汇总数据库("+ id +")", dataPath, dirName);
|
|
|
|
|
fs.writeFileSync('./app/version.txt', 2);
|
|
|
|
|
res.send(200,{path: dataPath+"app/", name: dirName});
|
|
|
|
@ -352,6 +352,18 @@ gulp.task('connect', ['watch'], function() {
|
|
|
|
|
//}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hawtio.use('/oracleExtractLog', function(req,res){
|
|
|
|
|
var path = allDataPath + "/tabulate_logs/" + req.query.rcName;
|
|
|
|
|
if(fs.existsSync(path)){
|
|
|
|
|
var log = fs.readFileSync(path, 'utf-8');
|
|
|
|
|
res.send(200,{logContent: log.toString()});
|
|
|
|
|
res.end();
|
|
|
|
|
}else{
|
|
|
|
|
res.send(200,{logContent: "当前没有日志可以查看!"});
|
|
|
|
|
res.end();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hawtio.use('/uploadfiles',function(req,res){
|
|
|
|
|
if(req.method==="POST"){
|
|
|
|
|
var relativePath = req.body.resumableRelativePath;
|
|
|
|
@ -549,95 +561,271 @@ gulp.task('connect', ['watch'], function() {
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
hawtio.use('/connectToOracle',function(req,res){
|
|
|
|
|
var rcName = req.query.oracleName;
|
|
|
|
|
var rcName = req.query.oracleName;
|
|
|
|
|
|
|
|
|
|
cancelOracleConectionTask(rcName);
|
|
|
|
|
|
|
|
|
|
kubectl.rc.get(rcName,function(err, rc){
|
|
|
|
|
//console.log(rc);
|
|
|
|
|
if(err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if(rc && rc.status.replicas === 1 && rc.metadata.labels.hasOwnProperty("style") && rc.metadata.labels.style === "oracle"){
|
|
|
|
|
var selector = rc.spec.selector;
|
|
|
|
|
var task = {
|
|
|
|
|
taskName: rcName,
|
|
|
|
|
taskTime: 0,
|
|
|
|
|
taskCrontab: crontab.scheduleJob("*/1 * * * *", function(){ //This will call this function every 2 minutes
|
|
|
|
|
//console.log(rcName + "it's been 1 minutes!");
|
|
|
|
|
if(task.taskTime === 9){
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + task.taskName + " status=1", function(err, data){
|
|
|
|
|
if(err)
|
|
|
|
|
console.log(err);
|
|
|
|
|
crontab.cancelJob(task.taskCrontab);
|
|
|
|
|
cancelOracleConectionTask(task.rcName);
|
|
|
|
|
return;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var selectorPods = [];
|
|
|
|
|
kubectl.pod.list(function(err, pods){
|
|
|
|
|
if(!err){
|
|
|
|
|
pods.items.forEach(function(item){
|
|
|
|
|
if(myjs.selectorMatches(selector, item.metadata.labels))
|
|
|
|
|
selectorPods.push(item);
|
|
|
|
|
});
|
|
|
|
|
if(selectorPods.length === 0)
|
|
|
|
|
return;
|
|
|
|
|
var host = selectorPods[0].status.hostIP
|
|
|
|
|
var port = selectorPods[0].spec.containers[0].ports[0].hostPort;
|
|
|
|
|
|
|
|
|
|
if(host && port){
|
|
|
|
|
oracledb.getConnection(
|
|
|
|
|
{
|
|
|
|
|
user : "system",
|
|
|
|
|
password : "oracle",
|
|
|
|
|
connectString : host + ":" + port + "/orcl"
|
|
|
|
|
},function(err, connection){
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log("connection failed! message" + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + task.taskName + " status=2", function(err, data){
|
|
|
|
|
if(err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
console.log("update replicationControllers " + rcName + " success");
|
|
|
|
|
if(connection !== null){
|
|
|
|
|
connection.close(function(err){
|
|
|
|
|
if (err){
|
|
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
|
|
|
|
console.log(rcName + "connect success!");
|
|
|
|
|
crontab.cancelJob(task.taskCrontab);
|
|
|
|
|
cancelOracleConectionTask(task.rcName);
|
|
|
|
|
console.log(rcName + "connection closed!");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
task.taskTime++;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
schedule.push(task);
|
|
|
|
|
}
|
|
|
|
|
res.send(200,"Ok");
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
cancelOracleConectionTask(rcName);
|
|
|
|
|
|
|
|
|
|
kubectl.rc.get(rcName,function(err, rc){
|
|
|
|
|
//console.log(rc);
|
|
|
|
|
if(err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if(rc && rc.status.replicas === 1 && rc.metadata.labels.hasOwnProperty("style") && rc.metadata.labels.style === "oracle"){
|
|
|
|
|
var selector = rc.spec.selector;
|
|
|
|
|
var task = {
|
|
|
|
|
taskName: rcName,
|
|
|
|
|
taskTime: 0,
|
|
|
|
|
taskCrontab: crontab.scheduleJob("*/1 * * * *", function(){ //This will call this function every 2 minutes
|
|
|
|
|
//console.log(rcName + "it's been 1 minutes!");
|
|
|
|
|
if(task.taskTime === 9){
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + task.taskName + " status=1", function(err, data){
|
|
|
|
|
if(err)
|
|
|
|
|
console.log(err);
|
|
|
|
|
crontab.cancelJob(task.taskCrontab);
|
|
|
|
|
cancelOracleConectionTask(task.rcName);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var selectorPods = [];
|
|
|
|
|
kubectl.pod.list(function(err, pods){
|
|
|
|
|
if(!err){
|
|
|
|
|
pods.items.forEach(function(item){
|
|
|
|
|
if(myjs.selectorMatches(selector, item.metadata.labels))
|
|
|
|
|
selectorPods.push(item);
|
|
|
|
|
});
|
|
|
|
|
if(selectorPods.length === 0)
|
|
|
|
|
return;
|
|
|
|
|
var host = selectorPods[0].status.hostIP
|
|
|
|
|
var port = selectorPods[0].spec.containers[0].ports[0].hostPort;
|
|
|
|
|
|
|
|
|
|
if(host && port){
|
|
|
|
|
oracledb.getConnection(
|
|
|
|
|
{
|
|
|
|
|
user : "system",
|
|
|
|
|
password : "oracle",
|
|
|
|
|
connectString : host + ":" + port + "/orcl"
|
|
|
|
|
},function(err, connection){
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log("connection failed! message" + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("connect success!");
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + task.taskName + " status=2", function(err, data){
|
|
|
|
|
if(err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
console.log("update replicationControllers " + rcName + " success");
|
|
|
|
|
if(connection !== null){
|
|
|
|
|
connection.close(function(err){
|
|
|
|
|
if (err){
|
|
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
|
|
|
|
crontab.cancelJob(task.taskCrontab);
|
|
|
|
|
cancelOracleConectionTask(task.rcName);
|
|
|
|
|
console.log("connection closed!");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
task.taskTime++;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
schedule.push(task);
|
|
|
|
|
}
|
|
|
|
|
res.send(200,"Ok");
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
hawtio.use('/cancelOracleConection', function(req,res){
|
|
|
|
|
var rcName = req.query.oracleName;
|
|
|
|
|
cancelOracleConectionTask(rcName);
|
|
|
|
|
res.send(200,"Ok");
|
|
|
|
|
res.end();
|
|
|
|
|
var rcName = req.query.oracleName;
|
|
|
|
|
var operation = req.query.operation;
|
|
|
|
|
if(operation !== 'stop')
|
|
|
|
|
cancelOracleConectionTask(rcName);
|
|
|
|
|
else{
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + rcName + " status=0", function(err, data){
|
|
|
|
|
if(err)
|
|
|
|
|
console.error(err.message);
|
|
|
|
|
console.log("update replicationControllers " + rcName + " success");
|
|
|
|
|
cancelOracleConectionTask(rcName);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
res.send(200,"Ok");
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hawtio.use('/extractOracleData', function(req,res){
|
|
|
|
|
var data = req.query.param;
|
|
|
|
|
console.log(data);
|
|
|
|
|
var poolOracle;
|
|
|
|
|
var collectOracle = [];
|
|
|
|
|
data.forEach(function(item){
|
|
|
|
|
var obj = JSON.parse(item);
|
|
|
|
|
if(obj.isTarget)
|
|
|
|
|
poolOracle = obj;
|
|
|
|
|
else{
|
|
|
|
|
var names = obj.OracleName.split("-");
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + obj.OracleName + " isExtract=1", function(err, data){
|
|
|
|
|
if(err)
|
|
|
|
|
console.error(err);
|
|
|
|
|
console.log("update replicationControllers " + obj.OracleName + " success");
|
|
|
|
|
});
|
|
|
|
|
obj["name"] = "J" + names[0] + "_" + names[1];
|
|
|
|
|
collectOracle.push(obj);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
var poolOracleParam = poolOracle.connectHost + ":" +poolOracle.connectPort;
|
|
|
|
|
var logMessage = "";
|
|
|
|
|
|
|
|
|
|
oracledb.getConnection({
|
|
|
|
|
user : "system",
|
|
|
|
|
password : "oracle",
|
|
|
|
|
connectString : poolOracleParam + "/orcl"
|
|
|
|
|
}, function(err, connection){
|
|
|
|
|
if (err) {
|
|
|
|
|
console.error(err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var logPath = allDataPath + "/tabulate_logs/";
|
|
|
|
|
async.eachSeries(collectOracle, function(item, callback){
|
|
|
|
|
var strTUser = item.name + "_20152016";
|
|
|
|
|
var message = "-------------------------------------------采集库:" + item.name + "执行汇总-------------------------------------------";
|
|
|
|
|
console.log(message);
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, message + "\n\n");
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(cb){
|
|
|
|
|
var dbLinkSql = "create public database link linkTo" + item.name + " connect to system IDENTIFIED BY oracle using "
|
|
|
|
|
+"'(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = "
|
|
|
|
|
+ item.connectHost + ")(PORT = " + item.connectPort + ")))(CONNECT_DATA = (SERVICE_NAME = orcl)))'";
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + dbLinkSql + "\n\n");
|
|
|
|
|
connection.execute(dbLinkSql, function(err, result){
|
|
|
|
|
if(err){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
cb(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "数据库链接已创建。" + "\n\n");
|
|
|
|
|
cb(null);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(cb){
|
|
|
|
|
connection.execute("select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = 'TS_JSSJBS'", function(err, result){
|
|
|
|
|
if(err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(result.rows.length !== 0)
|
|
|
|
|
cb(null, false);
|
|
|
|
|
else
|
|
|
|
|
cb(null, true);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(arg, cb){
|
|
|
|
|
if(!arg){
|
|
|
|
|
cb(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var sql = "create tablespace TS_JSSJBS datafile '/opt/oracle/app/oradata/orcl/ts_jssjbs.dbf' size 512M autoextend on next 512M maxsize unlimited";
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + sql + ";\n\n");
|
|
|
|
|
connection.execute(sql, function(err, result){
|
|
|
|
|
if (err){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
cb(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "表空间已创建。" + "\n\n");
|
|
|
|
|
cb(null);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(cb){
|
|
|
|
|
var sql = "Create user " + strTUser + " default tablespace TS_JSSJBS identified by 1";
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + sql + ";\n\n");
|
|
|
|
|
connection.execute(sql, function(err, result){
|
|
|
|
|
if (err){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
cb(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "用户已创建。" + "\n\n");
|
|
|
|
|
//console.log("create us");
|
|
|
|
|
cb(null);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(cb){
|
|
|
|
|
var sql = "grant connect, resource, dba to " + strTUser;
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + sql + ";\n\n");
|
|
|
|
|
connection.execute(sql, function(err, result){
|
|
|
|
|
if(err)
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "授权成功。" + "\n\n");
|
|
|
|
|
//console.log("grant dba");
|
|
|
|
|
cb(null);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(cb){
|
|
|
|
|
var sql = "SELECT 'create table " + strTUser + ".J'|| substr(t.OWNER||'_'||t.TABLE_NAME,0,29)||' as select * from '||t.OWNER||'.'||t.TABLE_NAME||"
|
|
|
|
|
+"'@linkTo" + item.name + ";' FROM dba_tables@linkTo" + item.name + " t WHERE t.TABLESPACE_NAME NOT IN ('SYSTEM','SYSAUX')"
|
|
|
|
|
+ " and t.owner||t.table_name not in (select owner||table_name from dba_tables@linkTo" + item.name + " where 'data_type'='CLOB')";
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + sql + ";\n\n");
|
|
|
|
|
connection.execute(sql, function(err, result){
|
|
|
|
|
if(err){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
preSql = [];
|
|
|
|
|
result.rows.forEach(function(row){
|
|
|
|
|
row.forEach(function(it){
|
|
|
|
|
preSql.push(it.replace(/;$/, ""));
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, it + "\n");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "\n");
|
|
|
|
|
cb(null, preSql);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(arg, cb){
|
|
|
|
|
async.eachSeries(arg, function(sql, cback){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "SQL> " + sql + ";\n\n");
|
|
|
|
|
connection.execute(sql, function(err, result){
|
|
|
|
|
if(err){
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, err + "\n\n");
|
|
|
|
|
cback(null, !err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fs.appendFileSync(logPath + poolOracle.OracleName, "表已创建。" + "\n\n");
|
|
|
|
|
cback(null, !err);
|
|
|
|
|
});
|
|
|
|
|
}, function(err, result){
|
|
|
|
|
cb(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], function(err, result){
|
|
|
|
|
if(err)
|
|
|
|
|
console.error(err);
|
|
|
|
|
kubectl.rc.command("label --overwrite rc " + item.OracleName + " isExtract=2", function(err, data){
|
|
|
|
|
if(err)
|
|
|
|
|
console.err(err);
|
|
|
|
|
console.log("update replicationControllers " + item.OracleName + " success");
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}, function(err, result){
|
|
|
|
|
if(err)
|
|
|
|
|
console.error(err);
|
|
|
|
|
connection.close(function(err){
|
|
|
|
|
if(err)
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
res.send(200,"Ok");
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hawtio.listen(function(server) {
|
|
|
|
|