-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.gradle
148 lines (117 loc) · 4.8 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// set the dependencies for running the groovy script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy:groovy-all:2.0.5'
classpath 'org.apache.knox:gateway-shell:0.8.0'
}
}
plugins {
id 'groovy'
id 'org.hidetake.ssh' version '1.5.0'
}
// load some common helper methods
apply from: "${projectDir}/../../shared/common-helpers.gradle"
// get the cluster connection details
Properties props = new Properties()
props.load(new FileInputStream("$projectDir/../../connection.properties"))
// set the dependencies for compiling the groovy script
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.0.5'
compile 'org.apache.knox:gateway-shell:0.8.0'
// include the bigsql jar files
runtime fileTree(dir: 'lib', include: '*.jar')
}
// tell gradle the groovy script is in the same folder as the build.gradle file
sourceSets {
main {
groovy {
srcDirs = ['.']
}
// You can update log4j.properties under resources directory
// to set logging level e.g. DEBUG
resources {
srcDirs = ['resources']
}
}
}
clean {
delete './lib'
delete './truststore.jks'
}
task ('CreateTrustStore') {
// this build step will fail if we try to import the certificate into an existing truststore
println ">> Remove key store"
delete './truststore.jks'
// ensure the ssl certificate exists
if (!file("${projectDir}/../../certificate").exists()) {
throw new GradleException("'certificate' file could not be found in ${projectDir.parentFile.parentFile}")
}
// import the BigInsights manager certificate
println ">> Create key store"
ant.exec(executable: "${getKeytoolPath()}", dir:'./') {
arg(line: '-import -trustcacerts -alias biginsights -file ../../certificate -keystore ./truststore.jks -storepass mypassword -noprompt')
}
}
// Create helper scripts
task ('SetupFederation') {
def hostIP, hostPort, keyPassword, certificate
project.hasProperty('dashIP') ? (hostIP = dashIP) : (hostIP = props.dashIP)
project.hasProperty('dashPort') ? (hostPort = dashPort) : (hostPort = props.dashPort)
project.hasProperty('kdbPassword') ? (keyPassword = kdbPassword) : (keyPassword = 'myCli3ntPassw0rd')
project.hasProperty('dashDBCertificate') ? (certificate = dashDBCertificate) : (certificate = 'DigiCertGlobalRootCA.crt')
mkdir ('scripts')
def certificateFile = '/home/bigsql/sqllib/security/keystore/' + certificate
def configSsl = """# Create keystore db
cd /home/bigsql/sqllib/security/keystore
/home/bigsql/sqllib/gskit/bin/gsk8capicmd_64 -keydb -create -db "dashclient.kdb" -pw "${keyPassword}" -stash
/home/bigsql/sqllib/gskit/bin/gsk8capicmd_64 -cert -add -db "dashclient.kdb" -pw "${keyPassword}" -label "DigiCert" -file "${certificateFile}" -format ascii -fips
# Update database manager configuration to use key and stash file
db2 update dbm cfg using SSL_CLNT_KEYDB /home/bigsql/sqllib/security/keystore/dashclient.kdb
db2 update dbm cfg using SSL_CLNT_STASH /home/bigsql/sqllib/security/keystore/dashclient.sth"""
def catalogDb = """# Uncatalog if needed
db2 UNCATALOG DATABASE BLUDB
db2 UNCATALOG NODE DASHNODE
# Catalog the remote server
db2 CATALOG TCPIP NODE DASHNODE REMOTE ${hostIP} SERVER ${hostPort} SECURITY SSL
# Catalog the remote database
db2 CATALOG DATABASE BLUDB AS BLUDB AT NODE DASHNODE"""
file('scripts/configSSL.sh').text = configSsl
file('scripts/catalogDB.sh').text = catalogDb
}
// task to run groovy script
['Connect', 'Insert', 'Load', 'CreateExternal', 'CreateCsv', 'Hbase', 'Federation'].each { taskName ->
task "$taskName" (type: JavaExec) {
// if running this task with clean, ensure clean runs first
mustRunAfter clean
dependsOn CreateTrustStore
dependsOn SetupLibs
def bigsql_hostname
try {
bigsql_hostname = getMasters(props)['BIGSQL_HEAD'][0]
} catch (Exception e) {
throw new GradleException('Could not find a BIGSQL host for this cluster.')
}
environment 'gateway', props.gateway
environment 'hostname', bigsql_hostname
environment 'username', props.username
environment 'password', props.password
environment 'dashUser', props.dashUser
environment 'dashPassword', props.dashPassword
environment 'dashHost', props.dashHost
environment 'dashPort', props.dashPort
main = taskName
classpath = sourceSets.main.runtimeClasspath
}
}
// Disable task if some props not set
( props.dashHost =~ /changeme/ || props.dashHost == null ) ? ( Federation.enabled = false ) : ( Federation.enabled = true )
// Main example task
task('Example') {
dependsOn Connect, Insert, Load, Hbase, CreateExternal, CreateCsv, Federation
}