Skip to content
Merged
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ lazy val utilDependencies = Seq(
"org.slf4j" % "slf4j-api" % "1.7.25",
"org.apache.commons" % "commons-compress" % "1.15",
"org.tensorflow" % "tensorflow" % "1.8.0",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.313"
"com.amazonaws" % "aws-java-sdk" % "1.7.4"
)

lazy val root = (project in file("."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ case class SearchTrie


object SearchTrie {
def apply(phrases: Array[Array[String]], caseSensitive: Boolean): SearchTrie = {
def apply(phrases: Array[Array[String]], caseSensitive: Boolean = false): SearchTrie = {

// Have only root at the beginning
val vocab = mutable.Map[String, Int]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import java.sql.Timestamp
import java.util.Calendar
import java.util.zip.ZipInputStream

import org.apache.hadoop.fs.Path
import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.{AWSCredentials, AWSStaticCredentialsProvider}
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.regions.RegionUtils
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.GetObjectRequest
import com.amazonaws.{AmazonServiceException, ClientConfiguration}
import com.johnsnowlabs.util.ConfigHelper
import org.apache.hadoop.fs.Path

import scala.collection.mutable

Expand All @@ -33,20 +34,23 @@ class S3ResourceDownloader(bucket: String,
}

lazy val client = {
val regionObj = RegionUtils.getRegion(region)

val builder = AmazonS3ClientBuilder.standard()
if (credentials.isDefined)
builder.setCredentials(new AWSStaticCredentialsProvider(credentials.get))

builder.setRegion(region)
val config = new ClientConfiguration()
val timeout = ConfigHelper.getConfigValue(ConfigHelper.s3SocketTimeout).map(_.toInt).getOrElse(0)
config.setSocketTimeout(timeout)
builder.setClientConfiguration(config)

builder.build()
}
val s3Client = {
if (credentials.isDefined) {
new AmazonS3Client(credentials.get, config)
} else {
new AmazonS3Client(config)
}
}

s3Client.setRegion(regionObj)
s3Client
}

private def downloadMetadataIfNeed(folder: String): List[ResourceMetadata] = {
val lastState = repoFolder2Metadata.get(folder)
Expand Down Expand Up @@ -171,4 +175,17 @@ class S3ResourceDownloader(bucket: String,
.filter(part => part.nonEmpty)
.mkString("/")
}

implicit class S3ClientWrapper(client: AmazonS3Client) {

def doesObjectExist(bucket: String, key: String): Boolean = {
try {
client.getObjectMetadata(bucket, key)
true
} catch {
case e: AmazonServiceException => if (e.getStatusCode == 404) return false else throw e
}
}
}

}