Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Add S3 support. #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import DatasourceModal from '../datasource-modal.class.js';


const HDFS_REGEX = /(hdfs):\/\/([\w\-_]+)+([\w\-\\.,@?^=%&:/~\\+#]*[\w\-\\@?^=%&/~\\+#])?/;
const HDFS_REGEX = /(hdfs|s3|s3a|s3n):\/\/([\w\-_]+)+([\w\-\\.,@?^=%&:/~\\+#]*[\w\-\\@?^=%&/~\\+#])?/;
const HDFS_PREFIX = 'hdfs://';


Expand All @@ -40,7 +40,7 @@ class HdfsModalController extends DatasourceModal {
if (editedDatasource) {
this.originalDatasource = editedDatasource;
this.datasourceParams = editedDatasource.params;
this.hdfsPathBuffer = this.datasourceParams.hdfsParams.hdfsPath.replace(HDFS_PREFIX, '');
this.hdfsPathBuffer = this.datasourceParams.hdfsParams.hdfsPath;
this.validateHdfsPath();
} else {
this.datasourceParams = {
Expand All @@ -66,10 +66,9 @@ class HdfsModalController extends DatasourceModal {
}, true);
}


canAddDatasource() {
const isCsvSeparatorValid = this.isCsvSeparatorValid(this.datasourceParams.hdfsParams);
const isSourceValid = this.datasourceParams.hdfsParams.hdfsPath !== 'hdfs://';
const isSourceValid = this.datasourceParams.hdfsParams.hdfsPath !== HDFS_PREFIX;

return super.canAddDatasource() &&
isCsvSeparatorValid &&
Expand All @@ -78,19 +77,12 @@ class HdfsModalController extends DatasourceModal {


onChangeHandler() {
this.hideHdfsPrefix();
this.datasourceParams.hdfsParams.hdfsPath = this.hdfsPathBuffer;
this.validateHdfsPath();
}


hideHdfsPrefix() {
this.hdfsPathBuffer = this.hdfsPathBuffer.replace(HDFS_PREFIX, '');
this.datasourceParams.hdfsParams.hdfsPath = `${HDFS_PREFIX}${this.hdfsPathBuffer}`;
}


validateHdfsPath() {
this.isHdfsPathValid = this.datasourceParams.hdfsParams.hdfsPath !== '' &&
this.isHdfsPathValid = this.datasourceParams.hdfsParams.hdfsPath !== HDFS_PREFIX &&
this.datasourceParams.hdfsParams.hdfsPath.match(HDFS_REGEX);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<div class="datasources-modal" ng-form="datasourceForm">
<div class="datasources-modal__header">
<div class="modal-title">HDFS</div>
<div class="modal-title">HDFS & S3</div>
</div>

<div class="datasources-modal__body">
<div class="datasources-modal__body-row">
<label class="title">HDFS path</label>
<label class="title">path</label>
<div class="icon-input">
<div class="hdfs-prefix">hdfs://</div>
<input
ng-disabled="$ctrl.previewMode"
ng-model="$ctrl.hdfsPathBuffer"
Expand Down
6 changes: 5 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ object Library {

val spark = (name: String) => "org.apache.spark" %% s"spark-$name" % Version.spark excludeScalatest

val hadoop = (name: String) => "org.apache.hadoop" % s"hadoop-$name" % (Version.hadoop + ".+")

val spray = (name: String) => "io.spray" %% s"spray-$name" % Version.spray excludeAkkaActor

val akkaActor = akka("actor")
Expand Down Expand Up @@ -114,7 +116,9 @@ object Dependencies {
object Spark {
val components = Seq(
sparkCore,
sparkMLLib)
sparkMLLib,
hadoop("aws")
)
// val provided = components.map(_ % Provided)
val provided = components
val test = components.map(_ % s"$Test,it")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ object FileScheme {
case object HDFS extends FileScheme("hdfs")
case object File extends FileScheme("file")
case object Library extends FileScheme("library")
case object S3 extends FileScheme("s3")
case object S3A extends FileScheme("s3a")
case object S3N extends FileScheme("s3n")

// TODO Autoderive values. There is macro-library for extracting sealed case objects.
val values = Seq(HTTP, HTTPS, FTP, HDFS, File, Library)
val values = Seq(HTTP, HTTPS, FTP, HDFS, File, Library, S3, S3A, S3N)

val supportedByParquet = Seq(HDFS)
val supportedByParquet = Seq(HDFS, S3, S3A, S3N)

def fromPath(path: String): FileScheme = {
val matchingFileSchema = values.find(schema => path.startsWith(schema.pathPrefix))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ object DataFrameFromFileReader {

private def readUsingProvidedFileScheme
(path: FilePath, fileFormat: InputFileFormatChoice)
(implicit context: ExecutionContext): DataFrame =
(implicit context: ExecutionContext): DataFrame = {
import FileScheme._
path.fileScheme match {
case FileScheme.Library =>
case Library =>
val filePath = FilePathFromLibraryPath(path)
readUsingProvidedFileScheme(filePath, fileFormat)
case FileScheme.File => DriverFiles.read(path.pathWithoutScheme, fileFormat)
case FileScheme.HTTP | FileScheme.HTTPS | FileScheme.FTP =>
case HTTP | HTTPS | FTP =>
val downloadedPath = FileDownloader.downloadFile(path.fullPath)
readUsingProvidedFileScheme(downloadedPath, fileFormat)
case FileScheme.HDFS => ClusterFiles.read(path, fileFormat)
case HDFS | S3 | S3A | S3N => ClusterFiles.read(path, fileFormat)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object DataFrameToFileWriter {
new java.io.File(libraryPath).getParentFile.mkdirs()
writeUsingProvidedFileScheme(fileChoice, dataFrame, filePath, saveMode)
case FileScheme.File => DriverFiles.write(dataFrame, path, fileChoice.getFileFormat(), saveMode)
case HDFS => ClusterFiles.write(dataFrame, path, fileChoice.getFileFormat(), saveMode)
case HDFS | S3 | S3A | S3N => ClusterFiles.write(dataFrame, path, fileChoice.getFileFormat(), saveMode)
case HTTP | HTTPS | FTP => throw NotSupportedScheme(path.fileScheme)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ trait ToDatasourceConverters {
case FileScheme.File |
FileScheme.FTP |
FileScheme.HTTP |
FileScheme.HTTPS =>
FileScheme.HTTPS |
FileScheme.S3 |
FileScheme.S3A |
FileScheme.S3N =>
params.setExternalFileParams(fileType)
params.setDatasourceType(DatasourceType.EXTERNALFILE)
case FileScheme.HDFS =>
Expand Down Expand Up @@ -147,7 +150,10 @@ trait ToDatasourceConverters {
case FileScheme.File |
FileScheme.FTP |
FileScheme.HTTP |
FileScheme.HTTPS =>
FileScheme.HTTPS |
FileScheme.S3 |
FileScheme.S3A |
FileScheme.S3N =>
params.setExternalFileParams(fileType)
params.setDatasourceType(DatasourceType.EXTERNALFILE)
case FileScheme.HDFS =>
Expand Down
6 changes: 3 additions & 3 deletions seahorse-workflow-executor/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Version {
case "2.0.0" | "2.0.1" | "2.0.2" => ("2.11.8", "1.8", "2.7.1", "2.4.9", "3.3.+")
}

val amazonS3 = "1.10.16"
val amazonSDK = "1.7.4"
val googleApi = "1.22.0"
val mockito = "1.10.19"
val nsscalaTime = "1.8.0"
Expand Down Expand Up @@ -53,7 +53,7 @@ object Library {

val akkaActor = akka("actor")
val akkaTestkit = akka("testkit")
val amazonS3 = "com.amazonaws" % "aws-java-sdk-s3" % Version.amazonS3 excludeJackson
val amazonSDK = "com.amazonaws" % "aws-java-sdk" % Version.amazonSDK excludeJackson
val apacheCommonsLang3 = "org.apache.commons" % "commons-lang3" % Version.apacheCommons
val apacheCommonsCsv = "org.apache.commons" % "commons-csv" % "1.1" // Also used by spark-csv
val config = "com.typesafe" % "config" % "1.3.1"
Expand Down Expand Up @@ -171,7 +171,7 @@ object Dependencies {
akkaActor,
sprayClient,
apacheCommonsLang3,
amazonS3,
amazonSDK,
nscalaTime,
scalaReflect,
apacheCommonsCsv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object SeahorseSparkLauncher {
val extraClassPath = s"${sparkLauncherConfig.weJarPath}:${jars.mkString(":")}"

jars.toList.foldLeft(sparkLauncher) { (acc, jar) => acc.addJar(jar) }
.addHadoopAwsJars()
.setConf("spark.driver.extraClassPath", extraClassPath)
.setConfOpt("spark.executor.memory", clusterConfig.executorMemory)
.setConfOpt("spark.driver.memory", clusterConfig.driverMemory)
Expand All @@ -74,6 +75,12 @@ object SeahorseSparkLauncher {
}

implicit class RichSparkLauncher(self: SparkLauncher) {

def addHadoopAwsJars(): SparkLauncher = {
self.addJar("/opt/docker/app/lib/com.amazonaws.aws-java-sdk-1.7.4.jar")
.addJar("/opt/docker/app/lib/org.apache.hadoop.hadoop-aws-2.7.6.jar")
}

def setConfOpt(key: String, valueOpt: Option[String]): SparkLauncher = {
valueOpt match {
case Some(value) => self.setConf(key, value)
Expand Down