Skip to content

Commit

Permalink
#446 Fix job creation when cases are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 29, 2018
1 parent 10c53bb commit b676b4c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions thehive-cortex/app/connectors/cortex/services/CortexSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ case class CortexConfig(instances: Seq[CortexClient]) {
class JobReplicateActor @Inject() (
cortexSrv: CortexSrv,
eventSrv: EventSrv,
implicit val ec: ExecutionContext,
implicit val mat: Materializer) extends Actor {

private lazy val logger = Logger(getClass)

override def preStart(): Unit = {
eventSrv.subscribe(self, classOf[MergeArtifact])
super.preStart()
Expand All @@ -82,11 +85,14 @@ class JobReplicateActor @Inject() (

override def receive: Receive = {
case MergeArtifact(newArtifact, artifacts, authContext)
logger.info(s"Merging jobs from artifacts ${artifacts.map(_.id)} into artifact ${newArtifact.id}")
import org.elastic4play.services.QueryDSL._
cortexSrv.find(and(parent("case_artifact", withId(artifacts.map(_.id): _*)), "status" ~= JobStatus.Success), Some("all"), Nil)._1
.mapAsyncUnordered(5) { job
val baseFields = Fields(job.attributes - "_id" - "_routing" - "_parent" - "_type" - "createdBy" - "createdAt" - "updatedBy" - "updatedAt" - "user")
cortexSrv.create(newArtifact, baseFields)(authContext)
val baseFields = Fields(job.attributes - "_id" - "_routing" - "_parent" - "_type" - "_version" - "createdBy" - "createdAt" - "updatedBy" - "updatedAt" - "user")
val createdJob = cortexSrv.create(newArtifact, baseFields)(authContext)
createdJob.failed.foreach(error => logger.error(s"Fail to create job under artifact ${newArtifact.id}\n\tjob attributes: $baseFields", error))
createdJob
}
.runWith(Sink.ignore)
case RemoveJobsOf(artifactId)
Expand Down

0 comments on commit b676b4c

Please sign in to comment.