Skip to content

Commit

Permalink
Merge pull request #591 from dataswift/she-config-test
Browse files Browse the repository at this point in the history
She config test
  • Loading branch information
dataswifty authored Apr 25, 2022
2 parents 5415cb5 + 85ed949 commit e112fce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ lazy val hat = project
DsLib.SilhouettePersistence,
DsLib.SlickPostgresDriver,
Lib.AwsV1Sdk,
Lib.AwsV2SdkLambda,
Lib.AwsV2SdkSts,
Lib.AwsV2SdkAuth,
Lib.BouncyCastle,
Lib.Ficus,
Lib.Guard,
Expand All @@ -39,7 +42,6 @@ lazy val hat = project
Lib.PlayTest,
Lib.PrometheusFilter,
Lib.ScalaGuice,
LocalThirdParty.AlpakkaAwsLambda,
LocalThirdParty.CirceConfig,
LocalThirdParty.PrettyTime,
DsLib.IntegrationTestCommon % Test,
Expand Down
42 changes: 36 additions & 6 deletions hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
package org.hatdex.hat.she.models

import akka.actor.ActorSystem
import akka.stream.alpakka.awslambda.scaladsl.AwsLambdaFlow
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.{ ActorMaterializer, Materializer }
import io.dataswift.models.hat.EndpointDataBundle
import io.dataswift.models.hat.applications.Version
Expand All @@ -35,11 +33,11 @@ import org.hatdex.hat.api.service.RemoteExecutionContext
import org.joda.time.DateTime
import play.api.libs.json.{ Format, Json }
import play.api.{ Configuration, Logger }
import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider
import software.amazon.awssdk.core.SdkBytes
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.lambda.LambdaAsyncClient
import software.amazon.awssdk.services.lambda.model.{ InvokeRequest, InvokeResponse }
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider

import javax.inject.Inject
import scala.concurrent.{ ExecutionContext, Future }
Expand Down Expand Up @@ -166,7 +164,7 @@ class AwsLambdaExecutor @Inject() (
LambdaAsyncClient
.builder()
.region(Region.of(configuration.get[String]("she.aws.region")))
.credentialsProvider(ContainerCredentialsProvider.builder().build())
.credentialsProvider(DefaultCredentialsProvider.create())
.build()

actorSystem.registerOnTermination(lambdaClient.close())
Expand All @@ -175,7 +173,38 @@ class AwsLambdaExecutor @Inject() (
request: InvokeRequest
)(implicit jsonFormatter: Format[T]): Future[T] =
if (mock) Future.successful(null.asInstanceOf[T])
else
else {
lambdaClient.invoke{request}.get match {
case r: InvokeResponse if r.functionError() == null =>
logger.debug(s"""Function responded with:
| Status: ${r.statusCode()}
| Body: ${r.payload().asUtf8String()}
| Logs: ${Option(r.logResult()).map(log => java.util.Base64.getDecoder.decode(log))}
""".stripMargin)
val jsResponse =
Json.parse(r.payload().asUtf8String()).validate[T] recover {
case e =>
val message = s"Error parsing lambda response: $e"
logger.error(message)
logger.error(s"Unable to parse: ${r.payload().asUtf8String()}")
throw DataFormatException(message)
}
Future(jsResponse.get)
case r: InvokeResponse if r.functionError() != null =>
val message =
s"Retrieving SHE function Response Error: ${r.functionError()}"
logger.error(message)
throw new ApiException(message)
case r =>
val message =
s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}"
logger.error(message)
throw new ApiException(message)
}
}


/*
Source
.single(request)
.via(AwsLambdaFlow(1)(lambdaClient))
Expand All @@ -200,5 +229,6 @@ class AwsLambdaExecutor @Inject() (
s"Retrieving SHE function configuration failed: $r, ${r.payload().asUtf8String()}"
logger.error(message)
throw new ApiException(message)
}
}*/

}
9 changes: 0 additions & 9 deletions hat/conf/she.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ she {
endpoint = "insights/busy-time"
experimental = true
}
{
id = "common-locations"
version = "1.0.0"
baseUrl = "common-locations-dev"
baseUrl = ${?COMMON_LOCATION_URL}
namespace = "she"
endpoint = "insights/common-locations"
experimental = true
}
{
id = "covid19-score"
version = "1.0.0"
Expand Down
6 changes: 6 additions & 0 deletions project/BasicSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ object BasicSettings extends AutoPlugin {
// and https://github.com/travis-ci/travis-ci/issues/3775
javaOptions += "-Xmx1G"
)

object autoImport {
// Do Nothing
// Added by Terry 20220422
// Not sure why this block is missing and how you got HAT to compile in the first place?
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resolvers += "HAT Library Artifacts Releases" at "https://s3-eu-west-1.amazonaws
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4")
addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.12")
addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.22")
addSbtPlugin("org.hatdex" % "sbt-slick-postgres-generator" % "0.1.2")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")
Expand Down

0 comments on commit e112fce

Please sign in to comment.