forked from kairosdb/kairosdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.groovy
executable file
·242 lines (197 loc) · 7.54 KB
/
build.groovy
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import org.freecompany.redline.Builder
import org.freecompany.redline.header.Architecture
import org.freecompany.redline.header.Os
import org.freecompany.redline.header.RpmType
import tablesaw.AbstractFileSet
import tablesaw.Tablesaw
import tablesaw.RegExFileSet
import tablesaw.addons.GZipRule
import tablesaw.addons.ZipRule
import tablesaw.addons.TarRule
import tablesaw.rules.*
import tablesaw.addons.java.*
import tablesaw.addons.ivy.IvyAddon
import tablesaw.addons.junit.JUnitRule
import javax.swing.JLabel
import javax.swing.JOptionPane
import javax.swing.JPasswordField
println("===============================================");
programName = "kairosdb"
version = "1.0.0-alpha-4a"
release = "1" //package release number
summary = "KairosDB"
description = """\
KairosDB is a time series database that stores numeric values along
with key/value tags to a nosql data store. Currently supported
backends are Cassandra and HBase. An H2 implementation is provided
for development work.
KairosDB is a rewrite of OpenTSDB to support modular interfaces.
"""
saw = Tablesaw.getCurrentTablesaw()
saw.includeDefinitionFile("definitions.xml")
ivyConfig = ["default"]
rpmDir = "build/rpm"
new DirectoryRule("build")
rpmDirRule = new DirectoryRule(rpmDir)
ivy = new IvyAddon().setup()
jp = new JavaProgram().setProgramName(programName)
.setup()
jp.getCompileRule().getDefinition().set("target", "1.6")
jp.getCompileRule().getDefinition().set("source", "1.6")
additionalFiles = new RegExFileSet("src/main/java", ".*\\.sql").recurse()
jp.getJarRule().addFileSet(additionalFiles)
jp.getJarRule().addFiles("src/main/resources", "kairosdb.properties",
"logback.xml")
saw.setDefaultTarget("jar")
testClasspath = new Classpath(jp.getLibraryJars())
testClasspath.addPath(jp.getJarRule().getTarget())
testSources = new RegExFileSet("src/test/java", ".*Test\\.java").recurse()
.addExcludeFiles("CassandraDatastoreTest.java", "HBaseDatastoreTest.java")
.getFilePaths()
testCompileRule = jp.getTestCompileRule()
junitClasspath = new Classpath(testCompileRule.getClasspath())
junitClasspath.addPaths(testClasspath)
junitClasspath.addPath("src/main/java")
junitClasspath.addPath("src/test/resources")
junitClasspath.addPath("src/main/resources")
junit = new JUnitRule().addSources(testSources)
.setClasspath(junitClasspath)
.addDepends(testCompileRule)
if (saw.getProperty("jacoco", "false").equals("true"))
junit.addJvmArgument("-javaagent:lib_test/jacocoagent.jar=destfile=build/jacoco.exec")
//------------------------------------------------------------------------------
//Build zip deployable application
rpmFile = "$programName-$version-1.rpm"
srcRpmFile = "$programName-$version-1.src.rpm"
libFileSets = [
new RegExFileSet("build/jar", ".*\\.jar"),
new RegExFileSet("lib", ".*\\.jar"),
new RegExFileSet("lib/ivy/default", ".*\\.jar")
]
scriptsFileSet = new RegExFileSet("src/scripts", ".*")
webrootFileSet = new RegExFileSet("webroot", ".*").recurse()
zipLibDir = "$programName/lib"
zipBinDir = "$programName/bin"
zipConfDir = "$programName/conf"
zipWebRootDir = "$programName/webroot"
tarRule = new TarRule("build/${programName}-${version}.tar")
.addDepend(jp.getJarRule())
.addFileSetTo(zipBinDir, scriptsFileSet)
.addFileSetTo(zipWebRootDir, webrootFileSet)
.addFileTo(zipConfDir, "src/main/resources", "kairosdb.properties")
.setFilePermission(".*\\.sh", 0755)
for (AbstractFileSet fs in libFileSets)
tarRule.addFileSetTo(zipLibDir, fs)
gzipRule = new GZipRule("package").setSource(tarRule.getTarget())
.setDescription("Create deployable tar file")
.setTarget("build/${programName}-${version}.tar.gz")
.addDepend(tarRule)
rpmBaseInstallDir = "/opt/$programName"
rpmRule = new SimpleRule("package-rpm").setDescription("Build RPM Package")
.addDepend(jp.getJarRule())
.addDepend(rpmDirRule)
.addTarget("$rpmDir/$rpmFile")
.setMakeAction("doRPM")
def doRPM(Rule rule)
{
host = InetAddress.getLocalHost().getHostName()
rpmBuilder = new Builder()
rpmBuilder.with
{
description = description
group = "System Environment/Daemons"
license = "license"
setPackage(programName, version, release)
setPlatform(Architecture.NOARCH, Os.LINUX)
summary = summary
type = RpmType.BINARY
url = "http://code.google.com/p/kairosdb/"
vendor = "Proofpoint Inc."
addDependencyMore("java", "1.6.0")
provides = programName
prefixes = rpmBaseInstallDir
buildHost = host
sourceRpm = srcRpmFile
}
rpmBuilder.setPostInstallScript("chkconfig --add kairosdb\nchkconfig kairosdb on")
for (AbstractFileSet fs in libFileSets)
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib", fs)
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/bin", scriptsFileSet)
rpmBuilder.addFile("/etc/init.d/kairosdb", new File("src/scripts/kairosdb-service.sh"), 0755)
rpmBuilder.addFile("$rpmBaseInstallDir/conf/kairosdb.properties", new File("src/main/resources/kairosdb.properties"))
for (AbstractFileSet.File f : webrootFileSet.getFiles())
rpmBuilder.addFile("$rpmBaseInstallDir/webroot/$f.file", new File(f.getBaseDir(), f.getFile()))
println("Building RPM to $rpmDir")
outputFile = new FileOutputStream(rule.getTarget())
rpmBuilder.build(outputFile.channel)
outputFile.close()
}
def addFileSetToRPM(Builder builder, String destination, AbstractFileSet files)
{
for (String filePath : files.getFullFilePaths())
{
File f = new File(filePath)
if (f.getName().endsWith(".sh"))
builder.addFile(destination + "/" +f.getName(), f, 0755)
else
builder.addFile(destination + "/" + f.getName(), f)
}
}
debRule = new SimpleRule("package-deb").setDescription("Build Deb Package")
.addDepend(rpmRule)
.setMakeAction("doDeb")
def doDeb(Rule rule)
{
//Prompt the user for the sudo password
def jpf = new JPasswordField()
def resp = JOptionPane.showConfirmDialog(null,
jpf, "Enter sudo password:",
JOptionPane.OK_CANCEL_OPTION)
if (resp == 0)
{
def password = jpf.getPassword()
sudo = saw.createAsyncProcess(rpmDir, "sudo -S alien --to-deb $rpmFile")
sudo.run()
//pass the password to the process on stdin
sudo.sendMessage("$password\n")
sudo.waitForProcess();
}
}
//------------------------------------------------------------------------------
//Run the tsd application
new SimpleRule("run-debug").setDescription("Runs kairosdb so a debugger can attach to port 5005")
.addDepends(jp.getJarRule())
.setMakeAction("doRun")
.setProperty("DEBUG", true)
new SimpleRule("run").setDescription("Runs kairosdb")
.addDepends(jp.getJarRule())
.setMakeAction("doRun")
.setProperty("DEBUG", false)
def doRun(Rule rule)
{
//args = "-c import -f export.txt"
//args = "-c export -f test_export.txt"
args = "-c run"
//Check if you have a custom kairosdb.properties file and load it.
customProps = new File("kairosdb.properties")
if (customProps.exists())
args += " -p kairosdb.properties"
debug = ""
if (rule.getProperty("DEBUG"))
debug = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
saw.exec("java ${debug} -Dio.netty.epollBugWorkaround=true -cp ${testClasspath} org.kairosdb.core.Main ${args}")
}
//------------------------------------------------------------------------------
//Generate GenORM Files for H2 module
genormDefinition = saw.getDefinition("genormous")
genormDefinition.set("genorm")
new SimpleRule("genorm").setDescription("Generate ORM files")
.setMakeAction("doGenorm")
def doGenorm(Rule rule)
{
genormClasspath = new Classpath(jp.getLibraryJars())
genormDefinition.set("classpath", genormClasspath.toString())
genormDefinition.set("source", "src/main/conf/tables.xml");
cmd = genormDefinition.getCommand();
saw.exec(cmd);
}