Skip to content

Commit

Permalink
Merge pull request #603 from dataswift/dev
Browse files Browse the repository at this point in the history
Dependency Inject issues resolved
  • Loading branch information
mudspot authored May 6, 2022
2 parents a3f5d88 + 6e4d41d commit 10ac44e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 52 deletions.
4 changes: 3 additions & 1 deletion hat/app/org/hatdex/hat/api/controllers/SystemStatus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SystemStatus @Inject() (
configuration.get[Long]("resourceManagement.hatFileStorageAllowance")
private val hatSharedSecret: String =
configuration.get[String]("resourceManagement.hatSharedSecret")
private val hatVersion: String =
configuration.get[String]("hat.version")

private val logger = Logger(this.getClass)

Expand All @@ -87,7 +89,7 @@ class SystemStatus @Inject() (

def version(): Action[AnyContent] = {
Action.async {
Future.successful(Ok(Json.toJson(Map[String, String]("Version" -> configuration.get[String]("hat.version")))))
Future.successful(Ok(Json.toJson(Map[String, String]("Version" -> hatVersion))))
}
}

Expand Down
59 changes: 36 additions & 23 deletions hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ import play.api.{ Configuration, Logger }
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.services.lambda.model.{ InvokeRequest, InvokeResponse, ResourceNotFoundException}
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider

import javax.inject.Inject
import scala.concurrent.{ ExecutionContext, Future }
import java.util.concurrent.CompletableFuture

class LambdaFunctionExecutable(
id: String,
Expand Down Expand Up @@ -174,31 +175,43 @@ class AwsLambdaExecutor @Inject() (
)(implicit jsonFormatter: Format[T]): Future[T] =
if (mock) Future.successful(null.asInstanceOf[T])
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 =>
try {
val invokeRequestF: CompletableFuture[InvokeResponse] = lambdaClient.invoke{request}
invokeRequestF.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)
}
} catch {
case e: ResourceNotFoundException =>
val message =
s"Retrieving SHE function Response Error: ${r.functionError()}"
s"Retrieving SHE function Response ResourceNotFoundException: $e, ${request.toString()}"
logger.error(message)
logger.error(r.payload().asUtf8String())
throw new ApiException(message)
case r =>
val message =
s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}"
case e: Exception =>
val message = s"Retrieving SHE function Response Unknown Exception: $e, ${request.toString()}"
logger.error(message)
throw new ApiException(message)
}
Expand Down
2 changes: 1 addition & 1 deletion hat/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ silhouette {
}

hat {
version = "v2.8.15-show-version"
version = "v2.8.15"
version = ${?HAT_VERSION}
tls = false
schemaMigrations = ["evolutions/hat-database-schema/13_liveEvolutions.sql", "evolutions/hat-database-schema/14_newHat.sql"]
Expand Down
27 changes: 0 additions & 27 deletions hat/conf/she.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ she {
endpoint = "insights/emotions"
experimental = false
}
{
id = "twitter-word-cloud"
version = "1.0.0"
baseUrl = "drops-word-cloud-dev"
baseUrl = ${?DROPS_SHE_BASE_URL}
namespace = "drops"
endpoint = "insights/twitter/word-cloud"
experimental = true
}
{
id = "sentiment-history"
version = "1.0.0"
Expand Down Expand Up @@ -69,23 +60,5 @@ she {
endpoint = "healthsurveyscores"
experimental = true
}
{
id = "weizmann-score"
version = "0.1.0"
baseUrl = "weizmann-score-dev"
baseUrl = ${?DROPS_SHE_BASE_URL}
namespace = "emitto"
endpoint = "healthsurveyscores"
experimental = false
}
{
id = "howmi-weizmann-score"
version = "1.0.0"
baseUrl = "howmi-weizmann-score-dev"
baseUrl = ${?DROPS_SHE_BASE_URL}
namespace = "howmi"
endpoint = "healthsurveyscores"
experimental = true
}
]
}

0 comments on commit 10ac44e

Please sign in to comment.