in app/prism/Prism.scala [23:63]
def findAllInstances(): Future[Seq[Instance]] =
findAll[Instance]("/instances")
def findAllLaunchConfigurations(): Future[Seq[LaunchConfiguration]] =
findAll[LaunchConfiguration]("/launch-configurations")
def findAllLaunchTemplates(): Future[Seq[LaunchTemplate]] =
findAll[LaunchTemplate]("/active-launch-template-versions")
def findCopiedImages(): Future[Seq[Image]] =
findAll[Image]("/images?tags.CopiedFromAMI!=")
private def findAll[T](
path: String
)(implicit r: Reads[Seq[T]]): Future[Seq[T]] = {
val url = s"$baseUrl$path"
ws.url(url).get().flatMap { resp =>
val prismResponse = for {
stale <- (resp.json \ "stale").validate[JsBoolean].map(_.value)
data <- r.reads(resp.json)
} yield (stale, data)
prismResponse.fold(
error => {
val message =
s"Failed to parse Prism response for GET $url. Status code = ${resp.status}, Error = $error"
log.warn(message)
Future.failed(new IllegalStateException(message))
},
{
case (true, _) =>
Future.failed(
new IllegalStateException(
s"Prism response indicated it was stale on $url"
)
)
case (false, t) => Future.successful(t)
}
)
}
}