Permalink
Switch branches/tags
ver2.2.m4 vXAP9.0.2 vXAP-9.0.2 v2.2.0m2 v2.2.0M3_2491_59 v2.2.m5 v2.2.m4 v2.1.1GA Chef-10.12.0-Cloudify-2.2m4 2.7.1_m5_build6205_04_13_2014 2.7.1_m4_build6204_04_01_2014 2.7.1_m3_build6203_03_18_2014 2.7.1_m2_build6202_03_03_2014 2.7.1_m1_build6201_02_17_2014 2.7.1_ga_build6300_08_14_2014 2.7.1_ga_build6210_08_07_2014 2.7.0_rc2_build6000_11_27_2014 2.7.0_rc2_build5999_04_08_2014 2.7.0_rc2_build5999_03_26_2014 2.7.0_rc2_build5998_03_28_2014 2.7.0_rc2_build5997_03_25_2014 2.7.0_rc2_build5995_01_07_2014 2.7.0_rc_build5994_12_23_2013 2.7.0_m8_build5993_12_11_2013 2.7.0_m7_build5992_11_27_2013 2.7.0_m6_build5991_11_13_2013 2.7.0_m5_build5988_10_30_2013 2.7.0_m4_build5987_10_01_2013 2.7.0_m3_build5985_09_08_2013 2.7.0_m2_build5984_08_19_2013 2.7.0_m1_build5985_08_06_2013 2.7.0_m1_build5981_08_01_2013 2.7.0_ga_build5996_01_20_2014 2.6.2_ga_build5400_10_13_2013 2.6.1_ga_build5223_11_25_2013 2.6.1_ga_build5222_11_22_2013 2.6.1_ga_build5221_11_12_2013 2.6.1_ga_build5220_10_29_2013 2.6.1_ga_build5210_10_25_2013 2.6.1_ga_build5200_08_29_2013 2.6.0_rc_build4986_06_26_2013 2.6.0_rc_build4985_06_11_2013 2.6.0_m4_build4985_06_12_2013 2.6.0_m4_build4984_06_11_2013 2.6.0_m3_build4983_05_21_2013 2.6.0_m2_build4982_05_06_2013 2.6.0_m1_build4981_04_22_2013 2.6.0_ga_build5000_07_09_2013 2.5.2_ga_build4400_06_23_2013 2.5.1_ga_build4200_05_01_2013 2.5.0_rc_build3993_03_11_2013 2.5.0_m7_build3991_02_27_2013 2.5.0_m6_build3987_02_04_2013 2.5.0_m5_build3986_01_24_2013 2.5.0_m4_build3985_01_06_2013 2.5.0_m3_build3984_12_30_2012 2.5.0_ga_build4510_04_09_2013 2.5.0_ga_build4023_07_03_2013 2.5.0_ga_build4022_04_28_2013 2.5.0_ga_build4021_04_28_2013 2.5.0_ga_build4020_04_23_2013 2.5.0_ga_build4010_04_10_2013 2.5.0_ga_build4000_04_03_2013 2.3.1_ga_build3720_02_10_2013 2.3.1_ga_build3720_02_09_2013 2.3.1_ga_build3700_01_23_2013 2.3.0_rc_build3483_12_06_2012 2.3.0_m2_build3482_11_20_2012 2.3.0_m1_build3481_11_06_2012 2.3.0_ga_build3510_01_14_2013 2.3.0_ga_build3500_12_16_2012 2.3.0_ga_build3500_12_13_2012 2.2.0_rc_build2496_10_03_2012 2.2.0_m5_build2495_09_21_2012 2.2.0_m4_build2494_09_09_2012 2.2.0_ga_build2500_10_19_2012
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
223 lines (183 sloc) 7.77 KB
/*******************************************************************************
* Copyright (c) 2012 GigaSpaces Technologies Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
import java.text.SimpleDateFormat
def static runMysqlQuery(binFolder,execFile,osName,currQuery,dbName,dbUser,debugMsg,outputpropertyName,displayOutputProperty) {
return runMysqlQuery(binFolder,execFile,osName,currQuery,dbName,dbUser,"",debugMsg,outputpropertyName,displayOutputProperty)
}
def static runMysqlQuery(binFolder,execFile,osName,currQuery,dbName,dbUser,dbUserPassword,debugMsg,outputpropertyName,displayOutputProperty) {
def outputPropertyStr
def builder
def currPassword = ""
if ( dbUserPassword.length() > 0 ) {
currPassword = "-p${dbUserPassword}"
}
try {
builder = new AntBuilder()
builder.sequential {
echo(message:"runMysqlQuery: os ${osName}: ${debugMsg}")
echo(message:"runMysqlQuery: ${binFolder}/${execFile} -u ${dbUser} ${currPassword} -D ${dbName} -e ${currQuery}")
exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}", outputproperty:"${outputpropertyName}") {
arg(line:"-u ${dbUser} ${currPassword} -D ${dbName} -e ${currQuery}")
}
}
}
catch (Exception ioe) {
println "runMysqlQuery: Connection Failed!"
ioe.printStackTrace();
}
outputPropertyStr = builder.project.properties."${outputpropertyName}"
if ( displayOutputProperty ) {
println "runMysqlQuery: outputproperty (${outputpropertyName}) is : ${outputPropertyStr}"
}
println "runMysqlQuery: Ended"
return outputPropertyStr
}
def static importMysqlDB(binFolder,execFile,osName,importedFile,dbName,dbUser,debugMsg,outputpropertyName,displayOutputProperty) {
def outputPropertyStr
def builder
try {
builder = new AntBuilder()
builder.sequential {
echo(message:"importMysqlDB: ${debugMsg}")
exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}" ,input:"${importedFile}", outputproperty:"${outputpropertyName}") {
arg(value:"-u")
arg(value:"${dbUser}")
arg(value:"${dbName}")
}
}
}
catch (Exception ioe) {
println "importMysqlDB: Connection Failed!"
ioe.printStackTrace();
}
outputPropertyStr = builder.project.properties."${outputpropertyName}"
if ( displayOutputProperty ) {
println "importMysqlDB: outputproperty (${outputpropertyName}) is : ${outputPropertyStr}"
}
println "importMysqlDB: Ended"
return outputPropertyStr
}
def static runMysqlAdmin(binFolder,execFile,osName,actionName,dbName,dbUser,debugMsg,outputpropertyName,displayOutputProperty) {
def outputPropertyStr
def builder
try {
builder = new AntBuilder()
builder.sequential {
echo(message:"runMysqlAdmin: ${debugMsg}")
exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}", outputproperty:"${outputpropertyName}") {
arg(value:"-u")
arg(value:"${dbUser}")
arg(value:"${actionName}")
arg(value:"${dbName}")
}
}
}
catch (Exception ioe) {
println "runMysqlAdmin: Connection Failed!"
ioe.printStackTrace();
}
outputPropertyStr = builder.project.properties."${outputpropertyName}"
if ( displayOutputProperty ) {
println "runMysqlAdmin: outputproperty (${outputpropertyName}) is : ${outputPropertyStr}"
}
println "runMysqlAdmin: Ended"
return outputPropertyStr
}
def static runMysqlDump(binFolder,execFile,osName,actionArgs,dbName,dbUser,debugMsg,dumpFolder,dumpPrefix,requiredBackupType,bucketName,backupFile,s3Folder) {
try {
def dbFlag
if ( "${dbName}" == "" ) {
dbFlag = "--all-databases"
}
else {
dbFlag = "--databases ${dbName}"
}
def argsLine = "-u ${dbUser} ${actionArgs} ${dbFlag} "
def currMillis=System.currentTimeMillis()
def currTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(currMillis)
def baseDumpName = "${dumpPrefix}${currTime}"
def sqlFileName = "${baseDumpName}.sql"
def baseRootName = "${dumpFolder}/${baseDumpName}"
def dumpSqlFullPath = "${baseRootName}.sql"
def dumpZipFullPath = "${baseRootName}.zip"
def builder = new AntBuilder()
builder.sequential {
echo(message:"runMysqlDump: ${debugMsg}")
exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}", output:"${dumpSqlFullPath}") {
arg(line:"${argsLine}")
}
zip(destFile:"${dumpZipFullPath}", basedir: "${dumpFolder}" ,includes:"${sqlFileName}", update:true )
if ( requiredBackupType == "s3" ) {
if ( bucketName != "" ) {
def baseFolder = System.properties["user.home"]
exec(executable:"${backupFile}", osfamily:"${osName}") {
arg(value:"${baseFolder}")
arg(value:"${s3Folder}")
arg(value:"${bucketName}")
arg(value:"${dumpZipFullPath}")
arg(value:"${baseDumpName}.zip")
}
}
}
delete(file:"${dumpSqlFullPath}")
delete(file:"${dumpZipFullPath}")
}
}
catch (Exception ioe) {
println "runMysqlDump: Connection Failed!"
ioe.printStackTrace();
}
println "runMysqlDump: Ended"
}
def static importFileToDB(binFolder,osConfig,currOsName,currActionDbName,currImportZip,importedFile,importedFileUrl,builder,context,currActionUser,currDebugMsg,config) {
builder.sequential {
echo(message:"importFileToDB: Getting ${importedFileUrl} to ${currImportZip} ...")
get(src:"${importedFileUrl}", dest:"${currImportZip}", skipexisting:true)
echo(message:"importFileToDB: Unzipping ${currImportZip} to ${context.serviceDirectory} ...")
unzip(src:"${currImportZip}", dest:"${context.serviceDirectory}", overwrite:true)
}
def fullPathToImport="${context.serviceDirectory}/${importedFile}"
def currImportFile = new File(fullPathToImport)
def importText = currImportFile.text
println "importFileToDB: Replacing REPLACE_WITH_DB_NAME with ${config.dbName} in ${context.serviceDirectory}/${importedFile} ..."
currImportFile.text = importText.replace("REPLACE_WITH_DB_NAME",currActionDbName)
importMysqlDB(binFolder,osConfig.mysqlProgram,currOsName,fullPathToImport,currActionDbName,currActionUser,currDebugMsg,"dummy",false)
}
def static showMasterStatus(context,binFolder,execFile,currOsName,currQuery,currActionDbName,currActionUser,currDebugMsg,outputpropertyName,displayOutputProperty) {
def binLogData = runMysqlQuery(binFolder,execFile,currOsName,currQuery,currActionDbName,currActionUser,currDebugMsg,outputpropertyName,displayOutputProperty)
def binLogName="mysql-bin"
println "showMasterStatus: binLogData is "+binLogData
println "showMasterStatus: binLogData length is "+binLogData.length()
if ( binLogData.length() > 0 && binLogData.contains("Position") ) {
println "showMasterStatus: splitting binLogData ... "
def rawData = binLogData.split(binLogName)[1]
println "showMasterStatus: splitting rawData ... "
def dataArr = rawData.split()
println "showMasterStatus: setting binLog ... "
def binLog=binLogName+dataArr[0].trim()
println "showMasterStatus: setting logPos ... "
def logPos=dataArr[1].trim()
println "showMasterStatus: masterBinLogFile is "+binLog
println "showMasterStatus: masterBinLogPos is "+logPos
context.attributes.thisApplication["masterBinLogFile"] = binLog
context.attributes.thisApplication["masterBinLogPos"] = logPos
return true
}
else {
println "showMasterStatus: master is NOT ready yet"
return false
}
}