@ -11,29 +11,10 @@ var gulp = require('gulp'),
stringifyObject = require ( 'stringify-object' ) ,
hawtio = require ( 'hawtio-node-backend' ) ,
argv = require ( 'yargs' ) . argv ,
del = require ( 'del' ) ,
xml2js = require ( 'xml2js' ) ,
multipart = require ( 'connect-multiparty' ) ,
resumable = require ( './app/resumable-node.js' ) ( _ _dirname + '/uploads' ) ,
app = hawtio . app ,
shellprocess = require ( 'child_process' ) ,
xmloperation = require ( './app/xmloperation' ) ,
K8s = require ( 'k8s' ) ,
crontab = require ( 'node-crontab' ) ,
async = require ( 'async' ) ,
myjs = require ( './app/my.js' ) ;
del = require ( 'del' ) ;
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'
} ) ;
var config = {
main : '.' ,
@ -75,7 +56,8 @@ gulp.task('tsc', ['clean-defs'], function() {
. pipe ( plugins . sourcemaps . init ( ) )
. pipe ( plugins . typescript ( config . tsProject ) )
. on ( 'error' , plugins . notify . onError ( {
message : '<%= error.message =>' ,
onLast : true ,
message : '<%= error.message %>' ,
title : 'Typescript compilation error'
} ) ) ;
@ -101,6 +83,7 @@ gulp.task('less', function () {
paths : [ path . join ( _ _dirname , 'less' , 'includes' ) ]
} ) )
. on ( 'error' , plugins . notify . onError ( {
onLast : true ,
message : '<%= error.message %>' ,
title : 'less file compilation error'
} ) )
@ -153,6 +136,7 @@ gulp.task('connect', ['watch'], function() {
var kubeBase = process . env . KUBERNETES _MASTER || 'https://localhost:8443' ;
console . log ( "==== using KUBERNETES URL: " + kubeBase ) ;
var kube = uri ( urljoin ( kubeBase , 'api' ) ) ;
var kubeapis = uri ( urljoin ( kubeBase , 'apis' ) ) ;
var oapi = uri ( urljoin ( kubeBase , 'oapi' ) ) ;
console . log ( "Connecting to Kubernetes on: " + kube ) ;
@ -207,15 +191,43 @@ gulp.task('connect', ['watch'], function() {
path : '/kubernetes/api/v1/proxy/services/gogs-http-service' ,
targetPath : "/"
} ) ;
console . log ( "because of LOCAL_GOGS_HOST being set we are using a local proxy for /kubernetes/api/v1/proxy/services/gogs-http-service to point to http://"
+ process . env . LOCAL _GOGS _HOST + ":" + gogsPort ) ;
console . log ( "because of LOCAL_GOGS_HOST being set we are using a local proxy for /kubernetes/api/v1/proxy/services/gogs-http-service to point to http://" + process . env . LOCAL _GOGS _HOST + ":" + gogsPort ) ;
}
if ( process . env . LOCAL _JENKINSHIFT ) {
var jenkinshiftPort = process . env . LOCAL _JENKINSHIFT _PORT || "9090" ;
var jenkinshiftHost = process . env . LOCAL _JENKINSHIFT ;
console . log ( "Using jenkinshift host: " + jenkinshiftHost ) ;
var proxyPath = '/api/v1/proxy/namespaces/default/services/templates/oapi/v1' ;
console . log ( "Using jenkinshift host: " + jenkinshiftHost ) ;
localProxies . push ( {
proto : "http" ,
port : jenkinshiftPort ,
hostname : jenkinshiftHost ,
path : proxyPath ,
targetPath : "/oapi/v1"
} ) ;
localProxies . push ( {
proto : "http" ,
port : jenkinshiftPort ,
hostname : jenkinshiftHost ,
path : "/oapi/v1" ,
targetPath : "/oapi/v1"
} ) ;
console . log ( "because of LOCAL_JENKINSHIFT being set we are using a local proxy for " + proxyPath + " to point to http://" + jenkinshiftHost + ":" + jenkinshiftPort ) ;
}
var defaultProxies = [ {
proto : kube . protocol ( ) ,
port : kube . port ( ) ,
hostname : kube . hostname ( ) ,
path : '/kubernetes/api' ,
targetPath : kube . path ( )
} , {
proto : kubeapis . protocol ( ) ,
port : kubeapis . port ( ) ,
hostname : kubeapis . hostname ( ) ,
path : '/apis' ,
targetPath : kubeapis . path ( )
} , {
proto : oapi . protocol ( ) ,
port : oapi . port ( ) ,
@ -234,6 +246,12 @@ gulp.task('connect', ['watch'], function() {
port : kube . port ( ) ,
path : '/git' ,
targetPath : '/hawtio/git'
} , {
proto : "http" ,
port : "8080" ,
hostname : "192.168.0.102" ,
path : '/java/console/api' ,
targetPath : "/"
} ] ;
var staticProxies = localProxies . concat ( defaultProxies ) ;
@ -286,16 +304,12 @@ gulp.task('connect', ['watch'], function() {
oauth _client _id : 'fabric8'
} ;
}
var answer = "window.OPENSHIFT _CONFIG = " + stringifyObject ( config ) ;
var answer = "window.OPENSHIFT _CONFIG = window.HAWTIO_OAUTH _CONFIG = " + stringifyObject ( config ) ;
res . set ( 'Content-Type' , 'application/javascript' ) ;
res . send ( answer ) ;
} ) ;
app . use ( multipart ( ) ) ;
hawtio . use ( '/' , function ( req , res , next ) {
// console.log(req.connection.remoteAddress);
var path = req . originalUrl ;
// avoid returning these files, they should get pulled from js
if ( s . startsWith ( path , '/plugins/' ) && s . endsWith ( path , 'html' ) ) {
@ -309,525 +323,6 @@ gulp.task('connect', ['watch'], function() {
next ( ) ;
}
} ) ;
hawtio . use ( '/xmlformserver' , function ( req , res , next ) {
if ( req . method == 'POST' ) {
var data = [ ] ;
var parser = new xml2js . Parser ( ) ;
fs . readFile ( rootdir + '/data.xml' , function ( err , xml ) {
parser . parseString ( xml , function ( err , result ) {
myjs . Recursion ( result . node ) ;
data . push ( result . node ) ;
res . send ( data ) ;
} ) ;
} ) ;
}
} ) ;
hawtio . use ( "/oracleAppPath" , function ( req , res ) {
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 ) {
time = timestamp . getTime ( ) ;
var id = fs . readFileSync ( "./app/version.txt" ) ;
var dirName = "huizongshuju-" + id ;
dataPath = dataPath + dirName + "/" ;
fs . mkdirSync ( dataPath ) ;
//path.exists(tmpPath,function(exists){if(exists) console.log("exists");});
fs . renameSync ( tmpPath , dataPath + "app" ) ;
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 } ) ;
res . end ( ) ;
shellprocess . exec ( "cp -rp " + appSource + " " + tmpPath ) ;
} else {
res . send ( 403 , { } ) ;
res . end ( ) ;
}
}
//}
} ) ;
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 ;
var fileName = req . body . resumableFilename ;
var rootpath = req . body . resumableRootPath ;
console . log ( "--------------------------req.body-----------------" ) ;
if ( req . body . resumableTotalSize == "0" ) {
fs . writeFile ( "uploads/" + fileName , "" ) ;
// 去掉系统路径(地区及系统编号): eg: 321100_1/
relativePath = relativePath . replace ( /^\w*\/*[0-9_]+\// , "" ) ;
console . log ( "*************-----clean------*****************" ) ;
var serverRelativePath = rootdir + rootpath + relativePath ;
console . log ( serverRelativePath ) ;
fileName = "uploads/" + fileName ;
console . log ( fileName ) ;
changefilename ( fileName , serverRelativePath ) ;
}
resumable . post ( req , function ( status , filename , original _filename , identifier ) {
if ( status === 'done' ) {
var stream = fs . createWriteStream ( './uploads/' + filename ) ;
console . log ( "//ºÏ²¢Îļþ" ) ;
//ºÏ²¢Îļþ
resumable . write ( identifier , stream ) ;
stream . on ( 'data' , function ( data ) { } ) ;
stream . on ( 'end' , function ( ) { } ) ;
//ɾ³ý·Ö¿é
//µÈ´ýÁ÷½áÊø
stream . on ( 'finish' , function ( ) {
console . log ( "*************-----clean------*****************" ) ;
// 去掉系统路径(地区及系统编号): eg: 321100_1/
relativePath = relativePath . replace ( /^\w*\/*[0-9_]+\// , "" ) ;
relativePath = rootdir + rootpath + relativePath ;
console . log ( relativePath ) ;
fileName = "uploads/" + fileName ;
console . log ( fileName ) ;
changefilename ( fileName , relativePath ) ;
resumable . clean ( identifier ) ;
} ) ;
}
console . log ( status + "---------------------" ) ;
res . send ( 200 , {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
} ) ;
} ) ;
}
if ( req . method === "GET" ) {
resumable . get ( req , function ( status , filename , original _filename , identifier ) {
console . log ( 'GET' , status ) ;
res . send ( ( status == 'found' ? 200 : 404 ) , status ) ;
} ) ;
}
//next();
} ) ;
hawtio . use ( '/download/:identifier' , function ( req , res ) {
resumable . write ( req . params . identifier , res ) ;
} ) ;
app . get ( '/getclientip' , function ( req , res ) {
var ip = req . connection . remoteAddress ;
ip = ip . replace ( /\./gim , "" ) ;
ip = ip . replace ( /\:/gim , "" ) ;
res . send ( ip ) ;
} ) ;
app . get ( '/getversion' , function ( req , res ) {
var version = req . query ;
var objid = version . id ;
var realversion = xmloperation . getVersionPath ( objid ) ;
res . send ( 200 , { id : realversion } ) ;
} ) ;
app . get ( '/sendDateMessage' , function ( req , res ) {
var jsonobj = req . query ;
console . log ( "---------------------------------------------------" ) ;
console . log ( jsonobj ) ;
var objid = jsonobj . id ;
var objname = jsonobj . name ;
var objcity = jsonobj . city ;
var objcounty = jsonobj . county ;
var objsystem = jsonobj . system ;
var objtype = jsonobj . type ;
var objbatch = jsonobj . batch ;
var province = jsonobj . province ;
var code = jsonobj . code ;
var character _set = jsonobj . character _set ;
var sys _name _code = jsonobj . sys _name _code ;
var contact = jsonobj . contact ;
var phone = jsonobj . phone ;
var collecttime = jsonobj . date ;
var realversion = xmloperation . getVersionPath ( objid ) ;
var realpath = objtype + "/" + objbatch + "/" + objid + "/" + realversion + "/"
realpath = rootdir + realpath ;
//saveByIdToXml("001001", "B", "321200_0", "泰州市_绩效管理系统2","江苏" , "泰州2", "市本级", "绩效管理系统", "321200_0", "0000", "lim", "13323225656",5);
xmloperation . saveByIdToXml ( collecttime , objtype , objbatch , objid , objname , province , objcity , objcounty , objsystem , code , sys _name _code , contact , phone , realversion , realpath )
xmloperation . mkdataForPage ( collecttime , objtype , realpath , objbatch , objid , objname , realversion ) ;
res . send ( 200 ) ;
} ) ;
// 路径必须存在
function changefilename ( oldfilepath , newfilepath ) {
fs . stat ( oldfilepath , function ( err , stats ) {
if ( err ) {
changefilename ( oldfilepath , newfilepath ) ;
}
else {
//console.log("-------------------------------changefilename----");
if ( stats . isFile ( ) ) {
// 修改文件名
fs . rename ( oldfilepath , newfilepath , function ( err ) {
if ( err ) {
var dirs = newfilepath . split ( "/" ) ;
var dirLength = dirs . length ;
var dirpath = "" ;
//var isSuccess = "false";
for ( var i = 0 ; i < dirLength - 1 ; i ++ ) {
dirpath = dirpath + dirs [ i ] + "/" ;
fs . mkdir ( dirpath , 0777 , function ( err ) {
if ( err ) {
//console.log("creat dir fail: "+dirpath);
}
} ) ;
}
changefilename ( oldfilepath , newfilepath )
}
} ) ;
} else if ( stats . isDirectory ( ) ) {
var dirs = newfilepath . split ( "/" ) ;
var dirLength = dirs . length ;
var dirpath = "" ;
for ( var i = 0 ; i < dirLength ; i ++ ) {
dirpath = dirpath + dirs [ i ] + "/" ;
fs . mkdir ( dirpath , 0777 , function ( err ) {
if ( err ) {
//console.log("creat dir fail: "+dirpath);
}
} ) ;
}
console . log ( " fail: this is Directory" ) ;
} else {
console . log ( "unknow type of file" ) ;
}
}
} ) ;
}
app . get ( '/setchmod2dir' , function ( req , res ) {
console . log ( "----------- setchmod2dir -------------------" )
console . log ( req . query ) ;
var path = rootdir + req . query . path ;
var tempfilesNum = req . query . filenum ;
var realfilesnum = geFileList ( path ) ;
if ( tempfilesNum <= realfilesnum ) {
shellprocess . exec ( "chmod -R 777 " + path ) ;
console . log ( "------------------------------------------ " + path ) ;
console . log ( realfilesnum ) ;
res . send ( 200 , "chmod" ) ;
}
else {
console . log ( realfilesnum ) ;
res . send ( 200 , "fail" ) ;
}
} ) ;
hawtio . use ( '/resumable.js' , function ( req , res ) {
res . setHeader ( "content-type" , "text/javascript" ) ;
fs . createReadStream ( "./app/resumable.js" ) . pipe ( res ) ;
} ) ;
/ * h a w t i o . u s e ( ' / s t y l e . c s s ' , f u n c t i o n ( r e q , r e s ) {
res . setHeader ( "content-type" , "text/css" ) ;
fs . createReadStream ( "./app/style.css" ) . pipe ( res ) ;
} ) ; * /
hawtio . use ( '/connectToOracle' , function ( req , res ) {
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 ( ) ;
} ) ;
} ) ;
hawtio . use ( '/cancelOracleConection' , function ( req , res ) {
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 ;
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 ) {
var host = server . address ( ) . address ;
var port = server . address ( ) . port ;
@ -861,54 +356,3 @@ gulp.task('site', ['clean', 'build'], function() {
} ) ;
gulp . task ( 'default' , [ 'connect' ] ) ;
function cancelOracleConectionTask ( taskName ) {
var taskIndex = - 1 ;
for ( var index in schedule ) {
var connectionTask = schedule [ index ] ;
if ( connectionTask . hasOwnProperty ( "taskName" ) && connectionTask . taskName === taskName ) {
crontab . cancelJob ( connectionTask . taskCrontab ) ;
console . log ( "Connection Task(taskName: " + taskName + ")" + " Canceled!" ) ;
taskIndex = index ;
break ;
}
}
if ( taskIndex !== - 1 ) {
schedule . splice ( taskIndex , 1 ) ;
console . log ( "Remove task(taskName: " + taskName + ") from schedule" ) ;
} else {
console . log ( "There Are No Connection Task(taskName: " + taskName + ")" + " Can be Canceled!" ) ;
}
}
function geFileList ( path )
{
var filesList = [ ] ;
readFile ( path , filesList ) ;
return filesList . length ;
}
//遍历读取文件
function readFile ( path , filesList )
{
files = fs . readdirSync ( path ) ; //需要用到同步读取
files . forEach ( walk ) ;
function walk ( file )
{
states = fs . statSync ( path + '/' + file ) ;
if ( states . isDirectory ( ) )
{
readFile ( path + '/' + file , filesList ) ;
}
else {
//创建一个对象保存信息
var obj = new Object ( ) ;
obj . size = states . size ; //文件大小,以字节为单位
obj . name = file ; //文件名
obj . path = path + '/' + file ; //文件绝对路径
filesList . push ( obj ) ;
}
}
}