Skip to content

Commit 10ac44e

Browse files
authored
Merge pull request #603 from dataswift/dev
Dependency Inject issues resolved
2 parents a3f5d88 + 6e4d41d commit 10ac44e

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

hat/app/org/hatdex/hat/api/controllers/SystemStatus.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class SystemStatus @Inject() (
6262
configuration.get[Long]("resourceManagement.hatFileStorageAllowance")
6363
private val hatSharedSecret: String =
6464
configuration.get[String]("resourceManagement.hatSharedSecret")
65+
private val hatVersion: String =
66+
configuration.get[String]("hat.version")
6567

6668
private val logger = Logger(this.getClass)
6769

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

8890
def version(): Action[AnyContent] = {
8991
Action.async {
90-
Future.successful(Ok(Json.toJson(Map[String, String]("Version" -> configuration.get[String]("hat.version")))))
92+
Future.successful(Ok(Json.toJson(Map[String, String]("Version" -> hatVersion))))
9193
}
9294
}
9395

hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ import play.api.{ Configuration, Logger }
3636
import software.amazon.awssdk.core.SdkBytes
3737
import software.amazon.awssdk.regions.Region
3838
import software.amazon.awssdk.services.lambda.LambdaAsyncClient
39-
import software.amazon.awssdk.services.lambda.model.{ InvokeRequest, InvokeResponse }
39+
import software.amazon.awssdk.services.lambda.model.{ InvokeRequest, InvokeResponse, ResourceNotFoundException}
4040
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
4141

4242
import javax.inject.Inject
4343
import scala.concurrent.{ ExecutionContext, Future }
44+
import java.util.concurrent.CompletableFuture
4445

4546
class LambdaFunctionExecutable(
4647
id: String,
@@ -174,31 +175,43 @@ class AwsLambdaExecutor @Inject() (
174175
)(implicit jsonFormatter: Format[T]): Future[T] =
175176
if (mock) Future.successful(null.asInstanceOf[T])
176177
else {
177-
lambdaClient.invoke{request}.get match {
178-
case r: InvokeResponse if r.functionError() == null =>
179-
logger.debug(s"""Function responded with:
180-
| Status: ${r.statusCode()}
181-
| Body: ${r.payload().asUtf8String()}
182-
| Logs: ${Option(r.logResult()).map(log => java.util.Base64.getDecoder.decode(log))}
183-
""".stripMargin)
184-
val jsResponse =
185-
Json.parse(r.payload().asUtf8String()).validate[T] recover {
186-
case e =>
187-
val message = s"Error parsing lambda response: $e"
188-
logger.error(message)
189-
logger.error(s"Unable to parse: ${r.payload().asUtf8String()}")
190-
throw DataFormatException(message)
191-
}
192-
Future(jsResponse.get)
193-
case r: InvokeResponse if r.functionError() != null =>
178+
try {
179+
val invokeRequestF: CompletableFuture[InvokeResponse] = lambdaClient.invoke{request}
180+
invokeRequestF.get match {
181+
case r: InvokeResponse if r.functionError() == null =>
182+
logger.debug(s"""Function responded with:
183+
| Status: ${r.statusCode()}
184+
| Body: ${r.payload().asUtf8String()}
185+
| Logs: ${Option(r.logResult()).map(log => java.util.Base64.getDecoder.decode(log))}
186+
""".stripMargin)
187+
val jsResponse =
188+
Json.parse(r.payload().asUtf8String()).validate[T] recover {
189+
case e =>
190+
val message = s"Error parsing lambda response: $e"
191+
logger.error(message)
192+
logger.error(s"Unable to parse: ${r.payload().asUtf8String()}")
193+
throw DataFormatException(message)
194+
}
195+
Future(jsResponse.get)
196+
case r: InvokeResponse if r.functionError() != null =>
197+
val message =
198+
s"Retrieving SHE function Response Error: ${r.functionError()}"
199+
logger.error(message)
200+
throw new ApiException(message)
201+
case r =>
202+
val message =
203+
s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}"
204+
logger.error(message)
205+
throw new ApiException(message)
206+
}
207+
} catch {
208+
case e: ResourceNotFoundException =>
194209
val message =
195-
s"Retrieving SHE function Response Error: ${r.functionError()}"
210+
s"Retrieving SHE function Response ResourceNotFoundException: $e, ${request.toString()}"
196211
logger.error(message)
197-
logger.error(r.payload().asUtf8String())
198212
throw new ApiException(message)
199-
case r =>
200-
val message =
201-
s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}"
213+
case e: Exception =>
214+
val message = s"Retrieving SHE function Response Unknown Exception: $e, ${request.toString()}"
202215
logger.error(message)
203216
throw new ApiException(message)
204217
}

hat/conf/application.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ silhouette {
8080
}
8181

8282
hat {
83-
version = "v2.8.15-show-version"
83+
version = "v2.8.15"
8484
version = ${?HAT_VERSION}
8585
tls = false
8686
schemaMigrations = ["evolutions/hat-database-schema/13_liveEvolutions.sql", "evolutions/hat-database-schema/14_newHat.sql"]

hat/conf/she.conf

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ she {
3333
endpoint = "insights/emotions"
3434
experimental = false
3535
}
36-
{
37-
id = "twitter-word-cloud"
38-
version = "1.0.0"
39-
baseUrl = "drops-word-cloud-dev"
40-
baseUrl = ${?DROPS_SHE_BASE_URL}
41-
namespace = "drops"
42-
endpoint = "insights/twitter/word-cloud"
43-
experimental = true
44-
}
4536
{
4637
id = "sentiment-history"
4738
version = "1.0.0"
@@ -69,23 +60,5 @@ she {
6960
endpoint = "healthsurveyscores"
7061
experimental = true
7162
}
72-
{
73-
id = "weizmann-score"
74-
version = "0.1.0"
75-
baseUrl = "weizmann-score-dev"
76-
baseUrl = ${?DROPS_SHE_BASE_URL}
77-
namespace = "emitto"
78-
endpoint = "healthsurveyscores"
79-
experimental = false
80-
}
81-
{
82-
id = "howmi-weizmann-score"
83-
version = "1.0.0"
84-
baseUrl = "howmi-weizmann-score-dev"
85-
baseUrl = ${?DROPS_SHE_BASE_URL}
86-
namespace = "howmi"
87-
endpoint = "healthsurveyscores"
88-
experimental = true
89-
}
9063
]
9164
}

0 commit comments

Comments
 (0)