-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
atk-pipeline/src/main/scala/io/gearpump/examples/atk_pipeline/PipeLine.scala
This file contains 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,137 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.gearpump.examples.atk_pipeline | ||
|
||
import akka.actor.ActorSystem | ||
import io.gearpump.cluster.UserConfig | ||
import io.gearpump.cluster.client.ClientContext | ||
import io.gearpump.cluster.main.{ArgumentsParser, CLIOption, ParseResult} | ||
import io.gearpump.streaming.dsl.{TypedDataSource, CollectionDataSource} | ||
import io.gearpump.streaming.dsl.plan.OpTranslator.{HandlerTask, SourceTask} | ||
import io.gearpump.streaming.source.DataSource | ||
import io.gearpump.streaming.{Processor, StreamApplication} | ||
import io.gearpump.util.Graph._ | ||
import io.gearpump.util.{AkkaApp, Graph, LogUtil} | ||
import org.slf4j.Logger | ||
|
||
trait Scoring extends java.io.Serializable { | ||
protected val LOG: Logger = LogUtil.getLogger(getClass) | ||
val tar: String = "" | ||
val archiveName: String = null | ||
val modelName: String = null | ||
val ModelBytesFileName: String = null | ||
|
||
def load: Unit = { | ||
//TODO | ||
// This will replaced by ATK utility object that loads a tar from HDFS and returns a Model. | ||
LOG.info(s"KMeansDataProcessor load") | ||
|
||
/* | ||
Try({ | ||
val pt = new Path(tar) | ||
val uri = new URI(tar) | ||
val hdfsFileSystem: org.apache.hadoop.fs.FileSystem = org.apache.hadoop.fs.FileSystem.get(uri, new Configuration()) | ||
val tempFilePath = "/tmp/kmeans.tar" | ||
val local = new Path(tempFilePath) | ||
hdfsFileSystem.copyToLocalFile(false, pt, local) | ||
val tmpPath = "/tmp/" | ||
val myTarFile: TarArchiveInputStream = new TarArchiveInputStream(new FileInputStream(new File(tempFilePath))) | ||
var entry: TarArchiveEntry = null | ||
entry = myTarFile.getNextTarEntry | ||
while (entry != null) { | ||
// Get the name of the file | ||
val individualFile: String = entry.getName | ||
// Get Size of the file and create a byte array for the size | ||
val content: Array[Byte] = new Array[Byte](entry.getSize.toInt) | ||
myTarFile.read(content, 0, content.length) | ||
val outputFile = new FileOutputStream(new File(tmpPath + individualFile)) | ||
IOUtils.write(content, outputFile) | ||
outputFile.close() | ||
if (individualFile.contains(".jar")) { | ||
archiveName = individualFile.substring(0, individualFile.indexOf(".jar")) | ||
} | ||
else if (individualFile.contains("modelname")) { | ||
val s = new String(content) | ||
modelName = s.replaceAll("\n", "") | ||
} | ||
else { | ||
ModelBytesFileName = tmpPath + individualFile | ||
} | ||
entry = myTarFile.getNextTarEntry | ||
} | ||
myTarFile.close() | ||
}) match { | ||
case Success(a) => | ||
case Failure(throwable) => | ||
LOG.error(s"Error: $throwable") | ||
} | ||
*/ | ||
|
||
|
||
} | ||
|
||
def score(vector: Array[String]): Unit | ||
|
||
} | ||
|
||
class KMeans(override val tar: String) extends Scoring { | ||
|
||
def score(vector: Array[String]): Unit = { | ||
LOG.info("KMeansDataProcessor next") | ||
} | ||
|
||
} | ||
|
||
object PipeLine extends AkkaApp with ArgumentsParser { | ||
private val LOG: Logger = LogUtil.getLogger(getClass) | ||
|
||
override val options: Array[(String, CLIOption[Any])] = Array( | ||
"tar"-> CLIOption[String]("<tar file location in hdfs>", required = false, defaultValue = Some("/user/gearpump/atk/kmeans.tar")) | ||
) | ||
|
||
def application(config: ParseResult, system: ActorSystem): StreamApplication = { | ||
val TAR = "trustedanalytics.scoring-engine.archive-tar" | ||
import ATKTask._ | ||
import SourceTask._ | ||
implicit val actorSystem = system | ||
val tar = config.getString("tar") | ||
val appConfig = UserConfig.empty.withString(TAR, tar) | ||
val source = new CollectionDataSource[String](Seq("one","two","three")) | ||
val sourceProcessor = Processor[HandlerTask,DataSource](source, 1, "Source", UserConfig.empty) | ||
val kmeans = new KMeans(tar) | ||
val kmeansProcessor = Processor[HandlerTask,Scoring](kmeans, 1, "ATK", appConfig) | ||
val app = StreamApplication("ATKPipeline", Graph( | ||
sourceProcessor ~> kmeansProcessor | ||
), appConfig) | ||
app | ||
} | ||
|
||
override def main(akkaConf: Config, args: Array[String]): Unit = { | ||
val config = parse(args) | ||
val context = ClientContext(akkaConf) | ||
val appId = context.submit(application(config, context.system)) | ||
context.close() | ||
} | ||
|
||
} | ||
|
This file contains 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 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 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