Skip to content

Commit

Permalink
Initialise single node cluster if there are configured seed nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 22, 2020
1 parent 2f4a618 commit 34ccc6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.thp.thehive.connector.misp.services

import scala.concurrent.Future
import scala.util.{Failure, Success, Try}

import play.api.Logger

import akka.actor.{Actor, ActorRef, ActorSystem, Cancellable}
import akka.cluster.Cluster
import akka.cluster.singleton.{ClusterSingletonProxy, ClusterSingletonProxySettings}
import javax.inject.{Inject, Named, Provider}
import org.thp.scalligraph.auth.UserSrv
import play.api.Logger

import scala.concurrent.Future
import scala.util.{Failure, Success, Try}

object MispActor {
case object Synchro
Expand Down Expand Up @@ -61,17 +59,11 @@ class MispActor @Inject() (
}

class MispActorProvider @Inject() (system: ActorSystem, @Named("misp-actor-singleton") mispActorSingleton: ActorRef) extends Provider[ActorRef] {
lazy val logger: Logger = Logger(getClass)
override def get(): ActorRef = {
val cluster = Cluster(system)
logger.info("Initialising cluster")
cluster.join(mispActorSingleton.path.address)
logger.info(s"cluster members are ${cluster.state.members}")
override def get(): ActorRef =
system.actorOf(
ClusterSingletonProxy.props(
singletonManagerPath = mispActorSingleton.path.toStringWithoutAddress,
settings = ClusterSingletonProxySettings(system)
)
)
}
}
14 changes: 13 additions & 1 deletion thehive/app/org/thp/thehive/ClusterSetup.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
package org.thp.thehive class ClusterSetup {
package org.thp.thehive

import akka.actor.ActorSystem
import akka.cluster.Cluster
import javax.inject.Inject
import play.api.{Configuration, Logger}

class ClusterSetup @Inject() (configuration: Configuration, system: ActorSystem) {
lazy val logger: Logger = Logger(getClass)
if (configuration.get[Seq[String]]("akka.cluster.seed-nodes").isEmpty) {
val cluster = Cluster(system)
logger.info("Initialising cluster")
cluster.join(cluster.system.provider.getDefaultAddress)
}
}
1 change: 1 addition & 0 deletions thehive/app/org/thp/thehive/TheHiveModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TheHiveModule(environment: Environment, configuration: Configuration) exte
bindActor[NotificationActor]("notification-actor")

bind[SchemaUpdater].asEagerSingleton()
bind[ClusterSetup].asEagerSingleton()
()
}
}

0 comments on commit 34ccc6d

Please sign in to comment.