This repository was archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Mongo import #13
Open
gclaramunt
wants to merge
15
commits into
master
Choose a base branch
from
MongoImport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mongo import #13
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
086bb69
add one-jar plugin
53b2c98
Fix bug in Json building
e012009
add database name to precog ingest path
8c91a27
Merge branch 'JdbcImport' into MongoImport
8c1b3bb
create common package
86516b9
fix premature closing of connection
f46d934
add assembly task and update build config
6f73835
handle different "sorting" columns
671bf26
add common package
587c59b
fixed sbt dependencies, update importers to new ingest api
gclaramunt 6867bf9
composite project files
gclaramunt e4c4413
Merge branch 'JdbcImport' of github.com:reportgrid/client-libraries i…
gclaramunt b04f1b9
Changes for code review comments
gclaramunt 3f11d34
Merge branch 'master' of github.com:reportgrid/client-libraries into …
gclaramunt 15bc2d6
lot of changes from code review comments
gclaramunt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name := "import-tools" | ||
|
|
||
| organization := "org.precog" | ||
|
|
||
| version := "0.1" | ||
|
|
||
| scalaVersion := "2.9.2" | ||
|
|
||
|
|
||
| scalacOptions ++= Seq("-unchecked", "-deprecation") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name := "import-common" | ||
|
|
||
| organization := "org.precog" | ||
|
|
||
| version := "0.1" | ||
|
|
||
| scalaVersion := "2.9.2" | ||
|
|
||
| resolvers ++= Seq( | ||
| "ReportGrid (public)" at "http://nexus.reportgrid.com/content/repositories/public-releases" | ||
| ) | ||
|
|
||
| libraryDependencies ++= Seq( | ||
| "com.reportgrid" %% "blueeyes-core" % "1.0.0-M8.1", | ||
| "com.reportgrid" %% "blueeyes-json" % "1.0.0-M8.1" | ||
| ) | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import sbt._ | ||
| object CommonProj extends Build | ||
| { | ||
| lazy val root = Project("import-common", file(".")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.7") |
62 changes: 62 additions & 0 deletions
62
tools/import/common/src/main/scala/com/precog/tools/importers/common/ConsoleUtils.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.precog.tools.importers.common | ||
|
|
||
| import annotation.tailrec | ||
|
|
||
| /** | ||
| * User: gabriel | ||
| * Date: 1/25/13 | ||
| */ | ||
| object ConsoleUtils { | ||
|
|
||
| @tailrec | ||
| def selectSet[T](label:String, available: Seq[T], selected: Seq[T]=List()): Seq[T] = | ||
| if (available.isEmpty) selected | ||
| else { | ||
|
|
||
| println("Available %ss:".format(label)) | ||
| println(present(available)) | ||
|
|
||
| println("Selected %ss:".format(label)) | ||
| println(present(selected)) | ||
|
|
||
| println("Select %ss by entering its number or name, 0 to select all, enter to continue: ".format(label)) | ||
|
|
||
| val selIdx = readLine() | ||
| selIdx match { | ||
| case "" => selected | ||
| case ParseInt(0) => available | ||
| case ParseInt(x) if x<=available.size => { | ||
| val elem:T = available(x - 1) | ||
| selectSet(label,available.filterNot(_==elem), selected:+elem) | ||
| } | ||
| case s:String if (available.exists(_.toString == s)) => { | ||
| val elem:T =available.find(_.toString == s).get | ||
| selectSet(label,available.filterNot(_==elem), selected:+elem) | ||
| } | ||
| case _ => selectSet(label,available, selected) | ||
| } | ||
| } | ||
|
|
||
| @tailrec | ||
| def selectOne[T](label:String, available: Seq[T]): T ={ | ||
|
|
||
| println("Available %ss:".format(label)) | ||
| println(present(available)) | ||
|
|
||
| println("Select one %s by entering its number or name: ".format(label)) | ||
|
|
||
| val selIdx = readLine() | ||
| selIdx match { | ||
| case ParseInt(x) if x<=available.size => available(x - 1) | ||
| case s:String => available.find(_.toString == s) match { | ||
| case Some(t) => t | ||
| case None => selectOne(label,available) | ||
| } | ||
| case _ => selectOne(label,available) | ||
| } | ||
| } | ||
|
|
||
| def present[T](arr:Seq[T])= arr.zipWithIndex.map({ case (a, b) => (b+1) + ":" + a }).mkString(", ") | ||
|
|
||
|
|
||
| } |
61 changes: 61 additions & 0 deletions
61
tools/import/common/src/main/scala/com/precog/tools/importers/common/Ingest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.precog.tools.importers.common | ||
|
|
||
| import akka.dispatch._ | ||
| import akka.dispatch.Future | ||
| import scalaz.Monad | ||
|
|
||
| import blueeyes.json._ | ||
| import blueeyes.core.data.DefaultBijections._ | ||
| import blueeyes.core.service._ | ||
| import blueeyes.core.service.engines.HttpClientXLightWeb | ||
| import blueeyes.bkka.FutureMonad | ||
| import scalaz.StreamT | ||
| import java.nio.ByteBuffer | ||
| import blueeyes.core.http.HttpResponse | ||
| import blueeyes.core.data.ByteChunk | ||
| import scala.Right | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| /** | ||
| * User: gabriel | ||
| * Date: 3/21/13 | ||
| */ | ||
| object Ingest { | ||
|
|
||
| private lazy val logger = LoggerFactory.getLogger("com.precog.tools.importers.jdbc.Ingest") | ||
|
|
||
| def sendToPrecog(host:String, path:String, apiKey:String, dataStream:StreamT[Future,ByteBuffer], streaming:Boolean = true)(implicit executor:ExecutionContext): Future[HttpResponse[ByteChunk]] = { | ||
| implicit val M = new FutureMonad(executor) | ||
| val httpClient = new HttpClientXLightWeb()(executor) | ||
|
|
||
| dataStream.isEmpty.flatMap( isEmpty => | ||
| if (isEmpty) { | ||
| logger.info("No need to send empty data stream") | ||
| Future(HttpResponse.empty) | ||
| } else { | ||
| val byteChunks: ByteChunk = Right(dataStream) | ||
| //val fullPath = "%s/ingest/v1/fs%s".format(host, path) | ||
| val fullPath = "%s/fs%s".format(host, path) //local test only | ||
| val ingestParams = ('apiKey -> apiKey)::( if (streaming) List('mode -> "streaming") else List('mode -> "batch", 'receipt -> "true")) | ||
| logger.info("Ingesting to %s".format(path)) | ||
| httpClient.parameters(ingestParams:_*).header("Content-Type","application/json").post(fullPath)(byteChunks) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| def callSucceded(response:HttpResponse[ByteChunk]){ | ||
| response match { | ||
| case HttpResponse(_ ,_,Some(Left(buffer)),_) => logger.info("Result: %s".format(new String(buffer.array(), "UTF-8"))) | ||
| case _ => logger.error("Unexpected stream in %s".format(response)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| def toByteStream(dataStream: StreamT[Future, JValue])(implicit m:Monad[Future]): StreamT[Future, ByteBuffer] = { | ||
| dataStream.map(jv => ByteBuffer.wrap({ | ||
| val js = "%s\n".format(jv.renderCompact) | ||
| logger.trace("to bytes = %s".format(js.replace('\n',' '))) | ||
| js | ||
| }.getBytes("UTF-8"))) | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
tools/import/common/src/main/scala/com/precog/tools/importers/common/package.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.precog.tools.importers | ||
|
|
||
| /** | ||
| * User: gabriel | ||
| * Date: 1/25/13 | ||
| */ | ||
| package object common { | ||
|
|
||
| object ParseInt{ | ||
| def unapply(s : String) : Option[Int] = try { | ||
| Some(s.toInt) | ||
| } catch { | ||
| case _ : java.lang.NumberFormatException => None | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import sbt._ | ||
| object JdbcImportProj extends Build | ||
| { | ||
| lazy val root = | ||
| Project("import-jdbc", file(".")) dependsOn(common) | ||
| lazy val common = | ||
| ProjectRef(uri("../common/"), "import-common") | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.7") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| blueeyes-async { | ||
| name = "DefaultActorPool" | ||
| keep-alive-time = 5s | ||
| core-pool-size-factor = 1.0 | ||
| core-pool-size-max = 8 | ||
| max-pool-size-factor = 1.0 | ||
| max-pool-size-max = 8 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wtf, as seen on #precog-internals. :-)