Skip to content

Commit ae1d2c6

Browse files
committed
Start turning example into something useful.
1 parent 3215c56 commit ae1d2c6

File tree

21 files changed

+49
-1412
lines changed

21 files changed

+49
-1412
lines changed

bin/ivory

100755100644
File mode changed.

ivory-cli/src/main/resources/mainclasses.json

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"service-name" : "generate-dictionary",
4848
"class-name" : "com.ambiata.ivory.cli.generateDictionary"
4949
},
50+
{
51+
"service-name" : "generate-facts",
52+
"class-name" : "com.ambiata.ivory.cli.generateFacts"
53+
},
5054
{
5155
"service-name" : "cat-facts",
5256
"class-name" : "com.ambiata.ivory.cli.catFacts"

ivory-generate/src/main/scala/com/ambiata/ivory/generate/GenerateFactsCli.scala ivory-cli/src/main/scala/com/ambiata/ivory/cli/generateFacts.scala

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ambiata.ivory.generate
1+
package com.ambiata.ivory.cli
22

33
import com.nicta.scoobi.Scoobi._
44
import scalaz.{DList => _, _}, Scalaz._, effect._
@@ -10,13 +10,14 @@ import com.ambiata.mundane.control._
1010
import com.ambiata.mundane.io._
1111

1212
import com.ambiata.ivory.core._
13+
import com.ambiata.ivory.generate._
1314
import com.ambiata.ivory.alien.hdfs._
1415

15-
object GenerateFactsCli extends ScoobiApp {
16+
object generateFacts extends IvoryApp {
1617

1718
case class CliArguments(dictionary: String, flags: String, entities: Int, start: LocalDate, end: LocalDate, output: String)
1819

19-
val parser = new scopt.OptionParser[CliArguments]("GenerateDictionaryCli"){
20+
val parser = new scopt.OptionParser[CliArguments]("generate-facts"){
2021
head("""
2122
|Random Fact Generator.
2223
|
@@ -32,12 +33,9 @@ object GenerateFactsCli extends ScoobiApp {
3233
opt[String]('o', "output") action { (x, c) => c.copy(output = x) } required() text s"Hdfs path to write facts to."
3334
}
3435

35-
def run() {
36-
parser.parse(args, CliArguments("", "", 0, LocalDate.now(), LocalDate.now(), "")).map(c =>
37-
GenerateFacts.onHdfs(c.entities, new Path(c.dictionary), new Path(c.flags), c.start, c.end, new Path(c.output))(configuration).run(configuration).run.unsafePerformIO() match {
38-
case Ok(v) => println(s"Dictionary successfully written to ${c.output}.")
39-
case Error(e) => println(s"Failed to generate dictionary: ${Result.asString(e)}")
40-
}
41-
)
42-
}
36+
val cmd = IvoryCmd[CliArguments](parser, CliArguments("", "", 0, LocalDate.now(), LocalDate.now(), ""), ScoobiCmd { configuration => c =>
37+
GenerateFacts.onHdfs(c.entities, new Path(c.dictionary), new Path(c.flags), c.start, c.end, new Path(c.output))(configuration).run(configuration).
38+
mapError(e => { println(s"Failed to generate dictionary: ${Result.asString(e)}"); e }).
39+
map(v => List(s"Dictionary successfully written to ${c.output}."))
40+
})
4341
}

ivory-cli/src/main/scala/com/ambiata/ivory/cli/main.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object main {
1919
createRepository,
2020
factDiff,
2121
generateDictionary,
22+
generateFacts,
2223
importFacts,
2324
importFeatureStore,
2425
ingest,
@@ -80,7 +81,7 @@ case class IvoryCmd[A](parser: scopt.OptionParser[A], initial: A, runner: IvoryR
8081
* Represents the different types of runners in an Ivory program,
8182
* so that any required setup can be handled in a single place
8283
*/
83-
sealed trait IvoryRunner[A]
84+
sealed trait IvoryRunner[A]
8485
case class ActionCmd[A](f: A => IOAction[Unit]) extends IvoryRunner[A]
8586
case class HadoopCmd[A](f: Configuration => A => ResultTIO[List[String]]) extends IvoryRunner[A]
8687
case class ScoobiCmd[A](f: ScoobiConfiguration => A => ResultTIO[List[String]]) extends IvoryRunner[A]

ivory-example/bin/build

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh -eu
2+
3+
IVORY=$(dirname $0)/../..
4+
EXAMPLE=$IVORY/ivory-example
5+
TARGET=${1:-$OJ_ARTEFACT_ROOT}
6+
7+
mkdir -p ${TARGET}/bin
8+
cp ${EXAMPLE}/bin/run ${EXAMPLE}/bin/ivory ${TARGET}/bin
9+
10+
(
11+
cd $IVORY
12+
./sbt ";project cli; clean; assembly"
13+
cp $IVORY/ivory-cli/target/scala-2.10/ivory-cli-assembly-*.jar ${TARGET}/bin/ivory.jar
14+
) || exit $?

ivory-example/bin/extract-latest-fatrepo

-12
This file was deleted.

ivory-example/bin/import-fatrepo

-16
This file was deleted.

ivory-example/bin/ivory

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh -eu
2+
3+
JAR="$(dirname $0)/ivory.jar"
4+
5+
hadoop jar $JAR com.ambiata.ivory.cli.main "$@"

ivory-example/bin/run

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh -eu
2+
3+
TARGET=${1:-/tmp/test-$RANDOM}
4+
IVORY=$TARGET/ivory
5+
DICT=$TARGET/dictionary
6+
FACTS=$TARGET/facts
7+
FLAGS=$TARGET/flags
8+
9+
PATH=$(dirname $0):$PATH; export PATH
10+
11+
ivory generate-dictionary -n 5 -f 100 -o $TARGET
12+
ivory generate-facts -d $DICT -f $FLAGS -n 1000 -s 2012-01-01 -e 2012-02-01 -o $FACTS

ivory-example/src/main/resources/dictionary.psv

-5
This file was deleted.

ivory-example/src/main/resources/facts.psv

-20
This file was deleted.

ivory-example/src/main/resources/facts2.psv

-20
This file was deleted.

0 commit comments

Comments
 (0)