-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
207 lines (175 loc) · 6.71 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
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
apply plugin: 'eclipse'
apply plugin: 'java'
defaultTasks 'distTar'
task wrapper(type: Wrapper) {
description = "Updates gradlew and supporting files."
gradleVersion = '2.3'
}
version = "$SAMZA_VERSION"
repositories {
mavenCentral()
maven { url "https://repository.apache.org/content/groups/public" }
}
// a configuration for dependencies that need exploding into package
configurations {
explode
}
dependencies {
compile(group: 'org.codehaus.jackson', name: 'jackson-jaxrs', version: '1.8.5')
compile(group: 'org.slf4j', name: 'slf4j-api', version: "$SLF4J_VERSION")
compile(group: 'org.slf4j', name: 'slf4j-log4j12', version: "$SLF4J_VERSION")
compile(group: 'org.schwering', name: 'irclib', version: '1.10')
compile(group: 'org.apache.samza', name: 'samza-api', version: "$SAMZA_VERSION")
compile(group: 'org.apache.samza', name: 'samza-kv_2.10', version: "$SAMZA_VERSION")
explode (group: 'org.apache.samza', name: 'samza-shell', ext: 'tgz', classifier: 'dist', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-core_2.10', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-log4j', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-shell', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-yarn_2.10', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-kv-rocksdb_2.10', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.samza', name: 'samza-kafka_2.10', version: "$SAMZA_VERSION")
runtime(group: 'org.apache.kafka', name: 'kafka_2.10', version: "$KAFKA_VERSION")
runtime(group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: "$HADOOP_VERSION")
}
// make the samza distribution .tgz file
task distTar(dependsOn: build, type: Tar) {
destinationDir(new File(project.buildDir, "/distributions"))
compression(Compression.GZIP)
classifier('dist')
extension('tar.gz')
into("config") {
from("src/main/config") {
include "wikipedia-feed.properties"
include "wikipedia-parser.properties"
include "wikipedia-stats.properties"
// expand the Maven tokens with Gradle equivalents. Also change 'target' (Maven) to 'build/distributions' (Gradle)
filter { String line ->
line.replaceAll('[\$][{]basedir[}]', project.projectDir.toString()).replaceAll('[\$][{]project.artifactId[}]', project.name.toString()).replaceAll('/target/', '/build/distributions/').replaceAll('[\$][{]pom.version[}]', version)
}
}
}
into("bin") {
from {
configurations.explode.collect { tarTree(it) }
}
}
into("lib") {
from configurations.runtime
from configurations.runtime.artifacts.files
from("src/main/resources/") {
include "log4j.xml"
}
}
}
// install everything
task installGrid(type: Exec) {
workingDir(project.projectDir)
commandLine("bin/grid", "install", "all")
outputs.upToDateWhen {
["kafka", "zookeeper", "yarn"].every {
(new File(project.projectDir, "deploy/" + it)).exists()
}
}
}
// update the Samza job
task deployHelloSamza(dependsOn: [distTar, installGrid], type: Sync) {
into(new File(project.projectDir, "/deploy/samza"))
from(tarTree(distTar.archivePath))
}
// run everything
task startGrid(type: Exec) {
workingDir(project.projectDir)
commandLine("bin/grid", "start", "all")
outputs.upToDateWhen {
// use running zookeeper as proxy
File zookeeperPidFile = new File("/tmp/zookeeper/zookeeper_server.pid")
zookeeperPidFile.exists() &&
"kill -0 ${zookeeperPidFile.text}".execute().waitFor() == 0
}
}
// stop everything
task stopGrid(type: Exec) {
workingDir(project.projectDir)
commandLine("bin/grid", "stop", "all")
}
//
// Samza helpers
//
// helper task to run Samza jobs
class SamzaTask extends DefaultTask {
String configFile;
@TaskAction
def startSamza() {
project.exec {
workingDir(project.projectDir)
commandLine("deploy/samza/bin/run-job.sh",
"--config-factory=org.apache.samza.config.factories.PropertiesConfigFactory",
"--config-path=file://${project.projectDir}/deploy/samza/config/${configFile}")
}
}
}
// helper to run the Samza job to retrieve Wikipedia data
task runWikiFeed(dependsOn: [startGrid, deployHelloSamza], type: SamzaTask) {
configFile("wikipedia-feed.properties")
}
// helper to run the Samza job process Wikipedia data
task runWikiParser(dependsOn: [startGrid, deployHelloSamza], type: SamzaTask) {
configFile("wikipedia-parser.properties")
}
// helper to run the Samza job to summarize stats on Wikipedia edits
task runWikiStats(dependsOn: [startGrid, deployHelloSamza], type: SamzaTask) {
configFile("wikipedia-stats.properties")
}
//
// Kafka helpers
//
// show all Kafka topics
task listKafkaTopics(type: Exec) {
workingDir(project.projectDir)
commandLine("deploy/kafka/bin/kafka-topics.sh",
"--zookeeper", "localhost:2181",
"--list")
}
// helper task to monitor a Kafka topic
class KafkaDumpTask extends DefaultTask {
String topic;
@TaskAction
def dumpTopic() {
project.exec {
workingDir(project.projectDir)
commandLine("deploy/kafka/bin/kafka-console-consumer.sh",
"--zookeeper", "localhost:2181",
"--topic", "${topic}")
}
}
}
// helper to dump the wikipedia-raw topic
task dumpWikiRaw(dependsOn: startGrid, type: KafkaDumpTask) {
topic("wikipedia-raw")
}
// helper to dump the wikipedia-edits topic
task dumpWikiEdits(dependsOn: startGrid, type: KafkaDumpTask) {
topic("wikipedia-edits")
}
// helper to dump the wikipedia-stats topic
task dumpWikiStats(dependsOn: startGrid, type: KafkaDumpTask) {
topic("wikipedia-stats")
}