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
173 lines (137 sloc) 6.33 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 org.cloudifysource.utilitydomain.context.ServiceContextFactory
import java.util.concurrent.TimeUnit
import org.cloudifysource.domain.context.ServiceInstance;
config = new ConfigSlurper().parse(new File("play-service.properties").toURL())
serviceContext = ServiceContextFactory.getServiceContext()
def useDB
def dbHost
def dbPort
if ( !(config.dbServiceName) || "${config.dbServiceName}"=="NO_DB_REQUIRED") {
println "play_preStart.groovy: Your application doesn't use a database"
useDB=false
}
else {
useDB = true
if ( !(config.dbHost) || "${config.dbHost}"=="DB_INSTALLED_BY_CLOUDIFY") {
dbService = serviceContext.waitForService(config.dbServiceName, 180, TimeUnit.SECONDS)
if (dbService == null) {
throw new IllegalStateException("${config.dbServiceName} service not found.");
}
ServiceInstance[] dbInstances = dbService.waitForInstances(dbService.numberOfPlannedInstances, 180, TimeUnit.SECONDS)
if (dbInstances == null) {
throw new IllegalStateException("dbInstances not found.");
}
dbHost = dbInstances[0].getHostAddress()
println "play_preStart.groovy: dbHost is ${dbHost}"
def dbServiceInstances=serviceContext.attributes[config.dbServiceName].instances
dbServiceInstance=dbServiceInstances[1]
dbPort=dbServiceInstance["dbPort"]
println "play_preStart.groovy: dbPort is ${dbPort}"
}
else {
dbHost = config.dbHost
println "play_preStart.groovy: Using (external db) dbHost : ${dbHost}"
dbPort = config.dbPort
println "play_preStart.groovy: Using (external db) dbPort : ${dbPort}"
}
}
applicationNameStr="application.name"
playRootFolder=serviceContext.serviceDirectory + "/${config.name}"
println "play_preStart.groovy: playRootFolder is ${playRootFolder}"
applicationRootFolder="${playRootFolder}/playApps/${config.applicationName}"
println "play_preStart.groovy: applicationRootFolder is ${applicationRootFolder}"
confFolder="${applicationRootFolder}/conf"
println "play_preStart.groovy: confFolder is ${confFolder}"
frameworkFolder="${playRootFolder}/framework"
println "play_preStart.groovy: frameworkFolder is ${frameworkFolder}"
confFilePath = "${confFolder}/application.conf"
println "play_preStart.groovy: confFilePath is ${confFilePath}"
def confFile = new File(confFilePath)
text = confFile.text
if ( config.useAkka ) {
println "play_preStart.groovy: Using akka ..."
akkaLogLevelStr="akka.loglevel=DEBUG"
akkaParserTimeoutStr="play.akka.actor.retrieveBodyParserTimeout=30 second"
akkaTypedTimeoutStr="promise.akka.actor.typed.timeout=30s"
text = text.replace("${applicationNameStr}", "${akkaLogLevelStr}\n${applicationNameStr}")
text = text.replace("${applicationNameStr}", "${akkaParserTimeoutStr}\n${applicationNameStr}")
text = text.replace("${applicationNameStr}", "${akkaTypedTimeoutStr}\n${applicationNameStr}")
}
if ( config.productionMode ) {
println "play_preStart.groovy: Using productionMode ..."
applicationModeStr="application.mode=prod"
text = text.replace("${applicationNameStr}", "${applicationModeStr}\n${applicationNameStr}")
}
if ( useDB ) {
println "play_preStart.groovy: Setting DB host and port in ${confFilePath} ..."
if ( "${config.dbServiceName}" == "mysql" ) {
dbDriverStr="db.default.driver=com.mysql.jdbc.Driver"
dbUrlStr="db.default.url=\"jdbc:mysql://${dbHost}:${dbPort}/${config.dbName}\""
}
else {
println "play_preStart.groovy: You need to implement the dbDriverStr and dbUrlStr according to your db type : ${dbServiceName}"
}
dbUserStr="db.default.user=${config.dbUser}"
dbPassStr="db.default.password=${config.dbPassW}"
dbTimeoutStr="db.default.pool.timeout=30000"
text = text.replace("db.default.driver=org.h2.Driver", "${dbDriverStr}")
text = text.replace("db.default.url=\"jdbc:h2:mem:play\"","${dbUrlStr}\n${dbUserStr}\n${dbPassStr}\n${dbTimeoutStr}")
if ( config.applyEvolutions ) {
println "play_preStart.groovy: Setting applyEvolutions=true in ${confFilePath} ..."
text = text + "\n\napplyEvolutions.default=true\n"
}
if ( config.useLoadBalancer ) {
println "play_preStart.groovy: Setting XForwardedSupport in ${confFilePath} ..."
xFwdSupportStr="trustxforwarded=true"
text = text + "\n\n${xFwdSupportStr}\n"
}
if ( config.replace1Sql ) {
new1Sql="${confFolder}/evolutions/default/1.sql"
new AntBuilder().sequential {
echo(message:"Copying 1.sql to ${new1Sql} ...")
copy(tofile: "${new1Sql}", file:"1.sql", overwrite:true)
}
}
}
confFile.text = text
if ( config.useAkka ) {
referenceConfPath="${frameworkFolder}/src/play/src/main/resources/reference.conf"
println "play_preStart.groovy: Replacing 1.0 with 24 in ${referenceConfPath} - this increases timeout"
def referenceConfFile = new File(referenceConfPath)
referenceText = referenceConfFile.text
if ( config.akkaParallelismFactor ) {
referenceText = referenceText.replaceAll("1.0","${config.akkaParallelismFactor}")
}
if ( config.retrieveBodyParserTimeout ) {
referenceText = referenceText.replaceAll("1 second","${config.retrieveBodyParserTimeout}")
}
referenceConfFile.text = referenceText
}
if ( useDB ) {
buildFilePath = "${applicationRootFolder}/project/Build.scala"
def buildfile = new File(buildFilePath)
text = buildfile.text
if ( "${config.dbServiceName}" == "mysql" ) {
println "play_preStart.groovy: Setting MySQL driver dependencies in " + buildFilePath + "..."
text = text.replace("// Add your project dependencies here,", "\"mysql\" % \"mysql-connector-java\" % \"5.1.18\"")
buildfile.text = text
}
else {
println "play_preStart.groovy: You need to implement the project dependencies according to your db type : ${dbServiceName}"
}
}