From c165260e94e49e252913d4a318b494778df35464 Mon Sep 17 00:00:00 2001 From: To-om Date: Wed, 7 Dec 2016 17:49:29 +0100 Subject: [PATCH] #53 Fix atMost parameter in cortex waitreport call --- thehive-cortex/app/connectors/cortex/models/Job.scala | 2 +- .../app/connectors/cortex/services/CortexSrv.scala | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/thehive-cortex/app/connectors/cortex/models/Job.scala b/thehive-cortex/app/connectors/cortex/models/Job.scala index 704e4e74ab..501b0bd57c 100644 --- a/thehive-cortex/app/connectors/cortex/models/Job.scala +++ b/thehive-cortex/app/connectors/cortex/models/Job.scala @@ -41,7 +41,7 @@ class JobModel @Inject() (artifactModel: ArtifactModel) extends ChildModelDef[Jo } } class Job(model: JobModel, attributes: JsObject) extends EntityDef[JobModel, Job](model, attributes) with JobAttributes { - override def toJson = super.toJson + ("report" → report().fold[JsValue](JsObject(Nil))(r ⇒ Json.parse(r))) + override def toJson = super.toJson + ("report" → report().fold[JsValue](JsObject(Nil))(r ⇒ Json.parse(r))) // FIXME is parse fails (invalid report) } case class CortexJob(id: String, analyzerId: String, artifact: CortexArtifact, date: Date, status: JobStatus.Type, cortexIds: List[String] = Nil) extends CortexModel[CortexJob] { diff --git a/thehive-cortex/app/connectors/cortex/services/CortexSrv.scala b/thehive-cortex/app/connectors/cortex/services/CortexSrv.scala index d3d8f7d08d..8da0bae5dd 100644 --- a/thehive-cortex/app/connectors/cortex/services/CortexSrv.scala +++ b/thehive-cortex/app/connectors/cortex/services/CortexSrv.scala @@ -5,7 +5,7 @@ import java.nio.file.{ Path, Paths } import javax.inject.{ Inject, Singleton } import scala.concurrent.{ ExecutionContext, Future } -import scala.concurrent.duration.Duration +import scala.concurrent.duration.DurationInt import scala.language.implicitConversions import scala.util.{ Failure, Success } import scala.util.control.NonFatal @@ -140,12 +140,15 @@ class CortexSrv @Inject() ( def updateJobWithCortex(jobId: String, cortexJobId: String, cortex: CortexClient)(implicit authContext: AuthContext): Unit = { log.debug(s"Requesting status of job $cortexJobId in cortex ${cortex.name} in order to update job ${jobId}") - cortex.waitReport(cortexJobId, Duration.Inf) andThen { + cortex.waitReport(cortexJobId, 1.minute) andThen { case Success(j) ⇒ val status = (j \ "status").asOpt[JobStatus.Type].getOrElse(JobStatus.Failure) - val report = (j \ "report").as[JsObject] + val report = (j \ "report").asOpt[JsObject].getOrElse(JsObject(Nil)).toString log.debug(s"Job $cortexJobId in cortex ${cortex.name} has finished with status $status, updating job ${jobId}") - update(jobId, Fields.empty.set("status", status.toString).set("report", report)) + update(jobId, Fields.empty.set("status", status.toString).set("report", report)).onComplete { + case Failure(e) ⇒ log.error(s"Update job fails", e) + case _ ⇒ + } case Failure(e) ⇒ log.debug(s"Request of status of job $cortexJobId in cortex ${cortex.name} fails, restarting ...") updateJobWithCortex(jobId, cortexJobId, cortex)