forked from mongodb/mongo-hadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoHadoopBuild.scala
374 lines (308 loc) · 16.6 KB
/
MongoHadoopBuild.scala
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import sbt._
import Keys._
import Reference._
import sbtassembly.Plugin._
import Process._
import AssemblyKeys._
object MongoHadoopBuild extends Build {
lazy val buildSettings = Seq(
version := "1.1.0",
crossScalaVersions := Nil,
crossPaths := false,
organization := "org.mongodb"
)
/** The version of Hadoop to build against. */
lazy val hadoopRelease = SettingKey[String]("hadoop-release", "Hadoop Target Release Distro/Version")
val loadSampleData = TaskKey[Unit]("load-sample-data", "Loads sample data for example programs")
private val stockPig = "0.9.2"
private val stockHive = "0.10.0"
private val cdh3Rel = "cdh3u3"
private val cdh3Hadoop = "0.20.2-%s".format(cdh3Rel) // current "base" version they patch against
private val cdh3Pig = "0.8.1-%s".format(cdh3Rel)
private val cdh4Rel = "cdh4.3.0"
private val cdh4YarnHadoop = "2.0.0-%s".format(cdh4Rel) // current "base" version they patch against
private val cdh4CoreHadoop = "2.0.0-mr1-%s".format(cdh4Rel)
private val cdh4Pig = "0.11.0-%s".format(cdh4Rel)
private val coreHadoopMap = Map("0.20" -> hadoopDependencies("0.20.205.0", false, stockPig, stockHive),
"0.20.x" -> hadoopDependencies("0.20.205.0", false, stockPig, stockHive),
"0.21" -> hadoopDependencies("0.21.0", true, stockPig, stockHive),
"0.21.x" -> hadoopDependencies("0.21.0", true, stockPig, stockHive),
"0.22" -> hadoopDependencies("0.22.0", true, stockPig, stockHive, nextGen=true),
"0.22.x" -> hadoopDependencies("0.22.0", true, stockPig, stockHive, nextGen=true),
"0.23" -> hadoopDependencies("0.23.1", true, stockPig, stockHive, nextGen=true),
"0.23.x" -> hadoopDependencies("0.23.1", true, stockPig, stockHive, nextGen=true),
"cdh4" -> hadoopDependencies(cdh4CoreHadoop, true, cdh4Pig, stockHive, Some(cdh4YarnHadoop), nextGen=true),
/** Hive in mongo-hadoop is not supported for cdh3*/
"cdh3" -> hadoopDependencies(cdh3Hadoop, true, cdh3Pig, ""),
"1.0" -> hadoopDependencies("1.0.4", false, stockPig, stockHive),
"1.0.x" -> hadoopDependencies("1.0.4", false, stockPig, stockHive),
"1.1" -> hadoopDependencies("1.1.2", true, stockPig, stockHive),
"1.1.x" -> hadoopDependencies("1.1.2", true, stockPig, stockHive),
"default" -> hadoopDependencies("1.0.4", false, stockPig, stockHive)
)
lazy val root = Project( id = "mongo-hadoop",
base = file("."),
settings = dependentSettings ++ Seq(loadSampleDataTask)) aggregate(core, flume, pig, hive)
lazy val core = Project( id = "mongo-hadoop-core",
base = file("core"),
settings = coreSettings )
lazy val hive = Project( id = "mongo-hadoop-hive",
base = file("hive"),
settings = hiveSettings ) dependsOn( core )
lazy val pig = Project( id = "mongo-hadoop-pig",
base = file("pig"),
settings = pigSettings ) dependsOn( core )
lazy val streaming = Project( id = "mongo-hadoop-streaming",
base = file("streaming"),
settings = streamingSettings ) dependsOn( core )
lazy val flume = Project( id = "mongo-flume",
base = file("flume"),
settings = flumeSettings )
lazy val ufo = Project( id = "ufo-example",
base = file("examples/ufo_sightings"),
settings = exampleSettings ) dependsOn( core )
lazy val cohort = Project( id = "cohort",
base = file("examples/cohort"),
settings = exampleSettings ) dependsOn( core )
lazy val treasuryExample = Project( id = "treasury-example",
base = file("examples/treasury_yield"),
settings = exampleSettings ) dependsOn( core )
lazy val enronExample = Project( id = "enron-example",
base = file("examples/enron"),
settings = exampleSettings ) dependsOn( core )
lazy val sensorsExample = Project( id = "sensors",
base = file("examples/sensors"),
settings = exampleSettings ) dependsOn( core )
lazy val baseSettings = Defaults.defaultSettings ++ buildSettings ++ Seq(
resolvers ++= Seq(Resolvers.mitSimileRepo, Resolvers.clouderaRepo, Resolvers.mavenOrgRepo, Resolvers.sonatypeRels),
libraryDependencies += ("com.novocode" % "junit-interface" % "0.8" % "test"),
libraryDependencies += ("commons-lang" % "commons-lang" % "2.3"),
libraryDependencies <<= (libraryDependencies) { deps =>
val scala: ModuleID = deps.find { x => x.name == "scala-library" }.map ( y =>
y.copy(configurations = Some("test"))
).get
val newDeps = deps.filterNot { x => x.name == "scala-library" }
newDeps :+ scala
},
javacOptions ++= Seq("-source", "1.5", "-target", "1.5"),
javacOptions in doc := Seq("-source", "1.5")
)
/** Settings that are dependent on a hadoop version */
lazy val dependentSettings = baseSettings ++ Seq(
moduleName <<= (hadoopRelease, moduleName) { (hr, mod) =>
if (hr == "default")
mod
else {
val rel = coreHadoopMap.getOrElse(hr,
sys.error("Hadoop Release '%s' is an invalid/unsupported release. " +
" Valid entries are in %s".format(hr, coreHadoopMap.keySet))
)._3
if (hr == "cdh3")
"%s_%s".format(mod, cdh3Rel)
else if (hr == "cdh4")
"%s_%s".format(mod, cdh4Rel)
else
"%s_%s".format(mod, rel)
}
})
lazy val parentSettings = baseSettings ++ Seq(
publishArtifact := false
)
lazy val flumeSettings = baseSettings ++ Seq(
libraryDependencies ++= Seq(Dependencies.mongoJavaDriver, Dependencies.flume)
)
lazy val streamingSettings = dependentSettings ++ assemblySettings ++ Seq(
mainClass in assembly := Some("com.mongodb.hadoop.streaming.MongoStreamJob"),
excludedJars in assembly <<= (fullClasspath in assembly) map ( cp =>
cp filterNot { x =>
x.data.getName.startsWith("hadoop-streaming") || x.data.getName.startsWith("mongo-java-driver") /*||
x.data.getName.startsWith("mongo-hadoop-core") */
}
),
excludedFiles in assembly := { (bases: Seq[File]) => bases flatMap { base =>
((base * "*").get collect {
case f if f.getName.toLowerCase == "git-hash" => f
case f if f.getName.toLowerCase == "license" => f
}) ++
((base / "META-INF" * "*").get collect {
case f if f.getName.toLowerCase == "license" => f
case f if f.getName.toLowerCase == "manifest.mf" => f
})
} },
libraryDependencies <++= (scalaVersion, libraryDependencies, hadoopRelease) { (sv, deps, hr: String) =>
val streamingDeps = coreHadoopMap.getOrElse(hr, sys.error("Hadoop Release '%s' is an invalid/unsupported release. Valid entries are in %s".format(hr, coreHadoopMap.keySet)))
streamingDeps._1.getOrElse(() => Seq.empty[ModuleID])()
},
skip in Compile <<= hadoopRelease.map(hr => {
val skip = !coreHadoopMap.getOrElse(hr,
sys.error("Hadoop Release '%s' is an invalid/unsupported release. " +
" Valid entries are in %s".format(hr, coreHadoopMap.keySet))
)._1.isDefined
if (skip) System.err.println("*** Will not compile Hadoop Streaming, which is unsupported in this build of Hadoop")
skip
}),
publishArtifact <<= (hadoopRelease) (hr => {
!coreHadoopMap.getOrElse(hr, sys.error("Hadoop Release '%s' is an invalid/unsupported release. " +
" Valid entries are in %s".format(hr, coreHadoopMap.keySet)))._1.isDefined
}),
assembly ~= { (jar) =>
println("*** Constructed Assembly Jar: %s".format(jar))
jar
}
)
val exampleSettings = dependentSettings
val pigSettings = dependentSettings ++ assemblySettings ++ Seq(
excludedJars in assembly <<= (fullClasspath in assembly) map ( cp =>
cp filterNot { x =>
x.data.getName.startsWith("mongo-hadoop-core") || x.data.getName.startsWith("mongo-java-driver") || x.data.getName.startsWith("mongo-hadoop-pig")
}
),
excludedFiles in assembly := { (bases: Seq[File]) => bases flatMap { base =>
((base * "*").get collect {
case f if f.getName.toLowerCase == "git-hash" => f
case f if f.getName.toLowerCase == "license" => f
}) ++
((base / "META-INF" * "*").get collect {
case f if f.getName.toLowerCase == "license" => f
case f if f.getName.toLowerCase == "manifest.mf" => f
})
} },
resolvers ++= Seq(Resolvers.rawsonApache), /** Seems to have thrift deps I need*/
libraryDependencies <++= (scalaVersion, libraryDependencies, hadoopRelease) { (sv, deps, hr: String) =>
if(hr == "cdh4"){
Seq("org.apache.pig" % "pig" % "0.10.0-cdh4.2.0")
}else{
val hadoopDeps = coreHadoopMap.getOrElse(hr, sys.error("Hadoop Release '%s' is an invalid/unsupported release. Valid entries are in %s".format(hr, coreHadoopMap.keySet)))
hadoopDeps._4()
}
}
)
val hiveSettings = dependentSettings ++ assemblySettings ++ Seq(
excludedJars in assembly <<= (fullClasspath in assembly) map ( cp =>
cp filterNot { x =>
x.data.getName.startsWith("mongo-hadoop-core") || x.data.getName.startsWith("mongo-java-driver") || x.data.getName.startsWith("mongo-hadoop-hive")
}
),
excludedFiles in assembly := { (bases: Seq[File]) => bases flatMap { base =>
((base * "*").get collect {
case f if f.getName.toLowerCase == "git-hash" => f
case f if f.getName.toLowerCase == "license" => f
}) ++
((base / "META-INF" * "*").get collect {
case f if f.getName.toLowerCase == "license" => f
case f if f.getName.toLowerCase == "manifest.mf" => f
})
} },
libraryDependencies ++= Seq(Dependencies.hiveSerDe, Dependencies.hiveExec),
resolvers ++= Seq(Resolvers.rawsonApache), /** Seems to have thrift deps I need*/
libraryDependencies <++= (scalaVersion, libraryDependencies, hadoopRelease) { (sv, deps, hr: String) =>
if(hr == "cdh4"){
Seq("org.apache.hive" % "hive-serde" % "0.10.0-cdh4.2.0")
}else{
val hadoopDeps = coreHadoopMap.getOrElse(hr, sys.error("Hadoop Release '%s' is an invalid/unsupported release. Valid entries are in %s".format(hr, coreHadoopMap.keySet)))
hadoopDeps._4()
}
}
)
val coreSettings = dependentSettings ++ Seq(
libraryDependencies ++= Seq(Dependencies.mongoJavaDriver, Dependencies.junit),
libraryDependencies <++= (scalaVersion, libraryDependencies, hadoopRelease) { (sv, deps, hr: String) =>
val hadoopDeps = coreHadoopMap.getOrElse(hr, sys.error("Hadoop Release '%s' is an invalid/unsupported release. Valid entries are in %s".format(hr, coreHadoopMap.keySet)))
hadoopDeps._2()
},
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
val versionMap = Map("2.8.1" -> ("specs2_2.8.1", "1.5"),
"2.9.0" -> ("specs2_2.9.0", "1.7.1"),
"2.9.0-1" -> ("specs2_2.9.0", "1.7.1"),
"2.9.1" -> ("specs2_2.9.1", "1.7.1"),
"2.9.2" -> ("specs2_2.9.2", "1.10"))
val tuple = versionMap.getOrElse(sv, sys.error("Unsupported Scala version '%s' for Specs2".format(sv)))
deps :+ ("org.specs2" % tuple._1 % tuple._2 % "test")
},
autoCompilerPlugins := true,
parallelExecution in Test := true,
testFrameworks += TestFrameworks.Specs2
)
val loadSampleDataTask = loadSampleData := {
println("Loading Sample data ...")
"mongoimport -d mongo_hadoop -c yield_historical.in --drop examples/treasury_yield/src/main/resources/yield_historical_in.json" !
"mongoimport -d mongo_hadoop -c ufo_sightings.in --drop examples/ufo_sightings/src/main/resources/ufo_awesome.json" !
println("********")
println("*** Loading the Enron, Word Count and Twitter sample data requires manual intervention. Please see the respective documentation")
println("********")
}
def hadoopDependencies(hadoopVersion: String, useStreaming: Boolean, pigVersion: String, hiveVersion: String, altStreamingVer: Option[String] = None, nextGen: Boolean = false): (Option[() => Seq[ModuleID]], () => Seq[ModuleID], String, () => Seq[ModuleID], () => Seq[ModuleID]) = {
(if (useStreaming) Some(streamingDependency(altStreamingVer.getOrElse(hadoopVersion))) else None, () => {
println("*** Adding Hadoop Dependencies for Hadoop '%s'".format(altStreamingVer.getOrElse(hadoopVersion)))
val deps = if (altStreamingVer.isDefined || nextGen)
Seq("org.apache.hadoop" % "hadoop-common" % altStreamingVer.getOrElse(hadoopVersion))
else
Seq("org.apache.hadoop" % "hadoop-core" % hadoopVersion/*,
("org.apache.hadoop" % "hadoop-hdfs" % hadoopVersion notTransitive()).exclude("commons-daemon", "commons-daemon")*/)
if (nextGen) {
def mrDep(mod: String) = "org.apache.hadoop" % "hadoop-mapreduce-client-%s".format(mod) % altStreamingVer.getOrElse(hadoopVersion) notTransitive() exclude("org.apache.hadoop", "hdfs")
if (hadoopVersion.startsWith("0.22")) {
deps ++ Seq("org.apache.hadoop" % "hadoop-mapred" % altStreamingVer.getOrElse(hadoopVersion))
} else if (hadoopVersion.startsWith("0.23") || hadoopVersion.startsWith("2.0.0")) {
deps ++ Seq(mrDep("core"), mrDep("common"), mrDep("shuffle"),
mrDep("shuffle"), mrDep("app"), mrDep("jobclient"))
} else {
sys.error("Don't know how to do any special mapping for Hadoop Version " + hadoopVersion)
}
}
else
deps
}, hadoopVersion, pigDependency(pigVersion), hiveDependency(hiveVersion))
}
def pigDependency(pigVersion: String): () => Seq[ModuleID] = {
() => {
println("*** Adding Pig Dependency for Version '%s'".format(pigVersion))
Seq(
"org.apache.pig" % "pig" % pigVersion,
"org.antlr" % "antlr" % "3.4"
)
}
}
def hiveDependency(hiveVersion: String): () => Seq[ModuleID] = {
() => {
if (hiveVersion == "") {
println("*** Sorry, no Hive support for cdh3")
Seq()
} else {
println("*** Adding Hive Dependency for Version '%s'".format(hiveVersion))
Seq(
"org.apache.hive" % "hive-serde" % hiveVersion,
"org.apache.hive" % "hive-exec" % hiveVersion
)
}
}
}
def streamingDependency(hadoopVersion: String): () => Seq[ModuleID] = {
() => {
println("Enabling build of Hadoop Streaming.")
Seq("org.apache.hadoop" % "hadoop-streaming" % hadoopVersion)
}
}
}
object Resolvers {
val scalaToolsSnapshots = "snapshots" at "http://scala-tools.org/repo-snapshots"
val scalaToolsReleases = "releases" at "http://scala-tools.org/repo-releases"
val sonatypeSnaps = "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
val sonatypeRels = "releases" at "https://oss.sonatype.org/content/repositories/releases"
val clouderaRepo = "Cloudera Repository" at "https://repository.cloudera.com/artifactory/cloudera-repos/"
val mitSimileRepo = "Simile Repo at MIT" at "http://simile.mit.edu/maven"
val mavenOrgRepo = "Maven.Org Repository" at "http://repo1.maven.org/maven2/"
/** Seems to have thrift deps I need*/
val rawsonApache = "rawsonApache" at "http://people.apache.org/~rawson/repo/"
val nictaScoobi = "Nicta Scoobi" at "http://nicta.github.com/scoobi/releases/"
}
object Dependencies {
val mongoJavaDriver = "org.mongodb" % "mongo-java-driver" % "2.10.1"
val hiveSerDe = "org.apache.hive" % "hive-serde" % "0.10.0"
val hiveExec = "org.apache.hive" % "hive-exec" % "0.10.0"
val junit = "junit" % "junit" % "4.10" % "test"
val flume = "com.cloudera" % "flume-core" % "0.9.4-cdh3u3"
val casbah = "org.mongodb" %% "casbah" % "2.3.0"
val scoobi = "com.nicta" %% "scoobi" % "0.4.0" % "provided"
}
// vim: set ts=2 sw=2 sts=2 et: