diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/build.sbt b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/build.sbt index b8f3d02..b7e02a2 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/build.sbt +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/build.sbt @@ -1,6 +1,5 @@ -val akkaV = "2.4.3" - -resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/") +val akkaVersion = "2.5.13" +val akkaHttpVersion = "10.1.3" val Frontend = config("frontend") extend(Compile) val Backend = config("backend") extend(Compile) @@ -12,31 +11,26 @@ def customAssemblySettings = inTask(assembly)(mainClass := Some("sample.cluster.factorial.FactorialBackend")) ++ inTask(assembly)(assemblyJarName := "akka-sample-backend.jar")) -val project = Project( - id = "akka-sample-cluster-scala", - base = file("."), - settings = customAssemblySettings ++ Defaults.coreDefaultSettings ++ Seq( - name := """akka-sample-cluster""", - scalaVersion := "2.11.8", - // scalaVersion := provided by Typesafe Reactive Platform - scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"), - javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-Xlint:deprecation"), + +lazy val `akka-sample-cluster-scala` = project + .in(file(".")) + .settings( + customAssemblySettings, + name := "akka-sample-cluster", + scalaVersion := "2.12.6", + scalacOptions in Compile ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"), + javacOptions in Compile ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"), + javaOptions in run ++= Seq("-Xms128m", "-Xmx1024m"), libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-cluster" % akkaV, - "com.typesafe.akka" %% "akka-multi-node-testkit" % akkaV, - "com.typesafe.akka" %% "akka-http-experimental" % akkaV, - "com.typesafe.akka" %% "akka-http-spray-json-experimental" % akkaV, - "com.typesafe.akka" %% "akka-contrib" % akkaV, - "org.scalaj" %% "scalaj-http" % "2.3.0", - "com.typesafe.play" %% "play-json" % "2.3.4", - "org.scalatest" %% "scalatest" % "2.2.1" % "test"//, - /*"org.fusesource" % "sigar" % "1.6.4"*/), - javaOptions in run ++= Seq( - //"-Djava.library.path=./sigar", - "-Xms128m", "-Xmx1024m"), - Keys.fork in run := true, - mainClass in (Compile, run) := Some("sample.cluster.simple.SimpleClusterApp"), + "com.typesafe.akka" %% "akka-actor" % akkaVersion, + "com.typesafe.akka" %% "akka-remote" % akkaVersion, + "com.typesafe.akka" %% "akka-cluster" % akkaVersion, + "com.typesafe.akka" %% "akka-http" % akkaHttpVersion, + "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion, + "org.scalatest" %% "scalatest" % "3.0.1" % Test), + fork in run := true, + mainClass in (Compile, run) := Some("sample.cluster.factorial.FactorialApp"), parallelExecution in Test := false, - mainClass in assembly := Some("sample.cluster.factorial.FactorialApp") + mainClass in assembly := Some("sample.cluster.factorial.FactorialApp"), + licenses := Seq(("CC0", url("http://creativecommons.org/publicdomain/zero/1.0"))) ) -) diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/libexec/activator-launch-1.3.10.jar b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/libexec/activator-launch-1.3.10.jar deleted file mode 100644 index 69050e7..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/libexec/activator-launch-1.3.10.jar and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/assembly.sbt b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/assembly.sbt index 1741de9..d95475f 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/assembly.sbt +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/assembly.sbt @@ -1 +1 @@ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3") \ No newline at end of file +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7") diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/build.properties b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/build.properties index 3685577..d6e3507 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/build.properties +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/build.properties @@ -1,4 +1 @@ -#Activator-generated Properties -#Fri Aug 26 13:05:39 EDT 2016 -template.uuid=472c6099-8b2b-4aee-a669-dbaab0c53138 -sbt.version=0.13.7 +sbt.version=1.1.6 diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/plugins.sbt b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/plugins.sbt index 04a8320..8b13789 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/plugins.sbt +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/project/plugins.sbt @@ -1,5 +1 @@ -resolvers += Classpaths.typesafeReleases - -addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.8") - diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-freebsd-6.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-freebsd-6.so deleted file mode 100644 index 3e94f0d..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-freebsd-6.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-linux.so deleted file mode 100644 index 5a2e4c2..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-solaris.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-solaris.so deleted file mode 100644 index 6396482..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-amd64-solaris.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-hpux-11.sl b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-hpux-11.sl deleted file mode 100644 index d92ea4a..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-hpux-11.sl and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-linux.so deleted file mode 100644 index 2bd2fc8..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ia64-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-pa-hpux-11.sl b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-pa-hpux-11.sl deleted file mode 100644 index 0dfd8a1..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-pa-hpux-11.sl and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-aix-5.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-aix-5.so deleted file mode 100644 index 7d4b519..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-aix-5.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-linux.so deleted file mode 100644 index 4394b1b..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-aix-5.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-aix-5.so deleted file mode 100644 index 35fd828..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-aix-5.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-linux.so deleted file mode 100644 index a1ba252..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-ppc64-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-s390x-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-s390x-linux.so deleted file mode 100644 index c275f4a..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-s390x-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc-solaris.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc-solaris.so deleted file mode 100644 index aa847d2..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc-solaris.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc64-solaris.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc64-solaris.so deleted file mode 100644 index 6c4fe80..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-sparc64-solaris.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal-macosx.dylib b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal-macosx.dylib deleted file mode 100644 index 27ab107..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal-macosx.dylib and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal64-macosx.dylib b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal64-macosx.dylib deleted file mode 100644 index 0c721fe..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-universal64-macosx.dylib and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-5.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-5.so deleted file mode 100644 index 8c50c61..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-5.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-6.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-6.so deleted file mode 100644 index f080027..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-freebsd-6.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-linux.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-linux.so deleted file mode 100644 index a0b64ed..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-linux.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-solaris.so b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-solaris.so deleted file mode 100644 index c6452e5..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/libsigar-x86-solaris.so and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-amd64-winnt.dll b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-amd64-winnt.dll deleted file mode 100644 index 1ec8a03..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-amd64-winnt.dll and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.dll b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.dll deleted file mode 100644 index 6afdc01..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.dll and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.lib b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.lib deleted file mode 100644 index 04924a1..0000000 Binary files a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/sigar/sigar-x86-winnt.lib and /dev/null differ diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/application.conf b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/application.conf index 0b87d9a..ffec373 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/application.conf +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/application.conf @@ -17,19 +17,34 @@ clustering { akka { actor { - provider = "akka.cluster.ClusterActorRefProvider" + provider = cluster } + coordinated-shutdown.exit-jvm = on remote { - log-remote-lifecycle-events = off netty.tcp { hostname = ${clustering.ip} port = ${clustering.port} + bind-hostname=0.0.0.0 + } + artery { + # enabled = on + transport = tcp + canonical.hostname = ${clustering.ip} + canonical.port = ${clustering.port} + bind.hostname=0.0.0.0 } } cluster { + # change 'akka.tcp' to 'akka' if artery is enabled seed-nodes = [ "akka.tcp://"${clustering.name}"@"${clustering.seed-host}":"${clustering.seed-port}] + + # auto downing is NOT safe for production deployments. + # you may want to use it during development, read more about it in the docs. auto-down-unreachable-after = 10s } + } + + diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/factorial.conf b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/factorial.conf index dc8018f..d5e17c8 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/factorial.conf +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/factorial.conf @@ -1,25 +1,15 @@ include "application" -# //#min-nr-of-members akka.cluster.min-nr-of-members = 2 -# //#min-nr-of-members -# //#role-min-nr-of-members akka.cluster.role { frontend.min-nr-of-members = 1 backend.min-nr-of-members = 1 } -# //#role-min-nr-of-members -# //#adaptive-router akka.actor.deployment { /factorialFrontend/factorialBackendRouter = { - router = round-robin-group # adaptive-group - # metrics-selector = heap - # metrics-selector = load - # metrics-selector = cpu - # metrics-selector = mix - nr-of-instances = 4 + router = round-robin-group routees.paths = ["/user/factorialBackend"] cluster { enabled = on @@ -28,4 +18,3 @@ akka.actor.deployment { } } } -# //#adaptive-router diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats1.conf b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats1.conf deleted file mode 100644 index 9f376ac..0000000 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats1.conf +++ /dev/null @@ -1,16 +0,0 @@ -include "application" - -# //#config-router-lookup -akka.actor.deployment { - /statsService/workerRouter { - router = consistent-hashing-group - nr-of-instances = 100 - routees.paths = ["/user/statsWorker"] - cluster { - enabled = on - allow-local-routees = on - use-role = compute - } - } -} -# //#config-router-lookup diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats2.conf b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats2.conf deleted file mode 100644 index 1eee48f..0000000 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/resources/stats2.conf +++ /dev/null @@ -1,17 +0,0 @@ -include "application" - -# //#config-router-deploy -akka.actor.deployment { - /singleton/statsService/workerRouter { - router = consistent-hashing-pool - nr-of-instances = 100 - cluster { - enabled = on - max-nr-of-instances-per-node = 3 - allow-local-routees = on - use-role = compute - } - } -} -# //#config-router-deploy - diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/Extra.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/Extra.scala deleted file mode 100644 index 24149b0..0000000 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/Extra.scala +++ /dev/null @@ -1,38 +0,0 @@ -package sample.cluster.factorial - -import akka.actor.Props -import akka.actor.Actor - -// not used, only for documentation -abstract class FactorialFrontend2 extends Actor { - //#router-lookup-in-code - import akka.cluster.routing.ClusterRouterGroup - import akka.cluster.routing.ClusterRouterGroupSettings - import akka.cluster.routing.AdaptiveLoadBalancingGroup - import akka.cluster.routing.HeapMetricsSelector - - val backend = context.actorOf( - ClusterRouterGroup(AdaptiveLoadBalancingGroup(HeapMetricsSelector), - ClusterRouterGroupSettings( - totalInstances = 100, routeesPaths = List("/user/factorialBackend"), - allowLocalRoutees = true, useRole = Some("backend"))).props(), - name = "factorialBackendRouter2") - //#router-lookup-in-code -} - -// not used, only for documentation -abstract class FactorialFrontend3 extends Actor { - //#router-deploy-in-code - import akka.cluster.routing.ClusterRouterPool - import akka.cluster.routing.ClusterRouterPoolSettings - import akka.cluster.routing.AdaptiveLoadBalancingPool - import akka.cluster.routing.SystemLoadAverageMetricsSelector - - val backend = context.actorOf( - ClusterRouterPool(AdaptiveLoadBalancingPool( - SystemLoadAverageMetricsSelector), ClusterRouterPoolSettings( - totalInstances = 100, maxInstancesPerNode = 3, - allowLocalRoutees = false, useRole = Some("backend"))).props(Props[FactorialBackend]), - name = "factorialBackendRouter3") - //#router-deploy-in-code -} \ No newline at end of file diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialApp.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialApp.scala index 69fb39c..9cdcc6c 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialApp.scala +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialApp.scala @@ -5,7 +5,7 @@ object FactorialApp { // starting 3 backend nodes and 1 frontend node FactorialBackend.main(Seq("2551").toArray) FactorialBackend.main(Seq("2552").toArray) - FactorialBackend.main(Array.empty) + FactorialBackend.main(Seq("2553").toArray) FactorialFrontend.main(Array.empty) } -} \ No newline at end of file +} diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialBackend.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialBackend.scala index b4cdc84..cbc7c09 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialBackend.scala +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialBackend.scala @@ -7,16 +7,14 @@ import akka.actor.Actor import akka.actor.ActorLogging import akka.actor.ActorSystem import akka.actor.Props -import akka.http.scaladsl.Http import akka.pattern.pipe -//#backend class FactorialBackend extends Actor with ActorLogging { import context.dispatcher def receive = { - case (n: Int) => + case n: Int => Future(factorial(n)) map { result => (n, result) } pipeTo sender() } @@ -29,7 +27,6 @@ class FactorialBackend extends Actor with ActorLogging { } } -//#backend object FactorialBackend { @@ -50,12 +47,22 @@ object FactorialBackend { val internalSeedPort = appConfig.getString("clustering.seed-port") - val config = ConfigFactory.parseString("akka.cluster.roles = [backend]"). - withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.hostname=$internalIp")). - withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port")). - withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.bind-hostname=0.0.0.0")). - withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort)). - withFallback(appConfig) + val config = ConfigFactory.parseString(s""" + akka.cluster.roles = [backend] + akka.remote { + netty.tcp { + hostname=$internalIp + port=$port + } + } + + akka.remote.artery { + canonical.hostname=$internalIp + canonical.port=$port + } + """) + .withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort)) + .withFallback(appConfig) val system = ActorSystem(clusterName, config) system.actorOf(Props[FactorialBackend], name = "factorialBackend") diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialFrontend.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialFrontend.scala index a3e2487..d9967f1 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialFrontend.scala +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/FactorialFrontend.scala @@ -17,7 +17,6 @@ import scala.concurrent.duration._ case object GetInfo case class Info(completed: Long, n: Int, factorial: BigInt) -//#frontend class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLogging { val backend = context.actorOf(FromConfig.props(), @@ -56,7 +55,6 @@ class FactorialFrontend(upToN: Int, repeat: Boolean) extends Actor with ActorLog 1 to upToN foreach { backend ! _ } } } -//#frontend object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol { @@ -107,7 +105,6 @@ object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol { val minMembers = appConfig.getNumber("akka.cluster.min-nr-of-members") val config = ConfigFactory.parseString("akka.cluster.roles = [frontend]"). - withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-hostname=0.0.0.0")). withFallback(NetworkConfig.seedsConfig(clusterName, internalSeedHostname, internalSeedPort)). withFallback(appConfig) @@ -116,24 +113,12 @@ object FactorialFrontend extends SprayJsonSupport with DefaultJsonProtocol { implicit val timeout = Timeout(5.seconds) implicit val executor = system.dispatcher system.log.info(s"Factorials will start when $minMembers backend members in the cluster.") - //#registerOnUp + Cluster(system) registerOnMemberUp { val frontend = system.actorOf(Props(classOf[FactorialFrontend], upToN, repeat), name = "factorialFrontend") Http().bindAndHandle(routes(system, frontend, timeout), serverHost, serverPort) } - //#registerOnUp - - //#registerOnRemoved - Cluster(system).registerOnMemberRemoved { - // exit JVM when ActorSystem has been terminated - system.registerOnTermination(System.exit(-1)) - // in case ActorSystem shutdown takes longer than 10 seconds, - // exit the JVM forcefully anyway - system.scheduler.scheduleOnce(10.seconds)(System.exit(-1))(system.dispatcher) - // shut down ActorSystem - system.terminate() - } - //#registerOnRemoved + } } diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/MetricsListener.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/MetricsListener.scala deleted file mode 100644 index 3d6a2a8..0000000 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/MetricsListener.scala +++ /dev/null @@ -1,47 +0,0 @@ -package sample.cluster.factorial - -import akka.actor.ActorLogging -import akka.actor.Actor - -//#metrics-listener -import akka.cluster.Cluster -import akka.cluster.ClusterEvent.ClusterMetricsChanged -import akka.cluster.ClusterEvent.CurrentClusterState -import akka.cluster.NodeMetrics -import akka.cluster.StandardMetrics.HeapMemory -import akka.cluster.StandardMetrics.Cpu - -class MetricsListener extends Actor with ActorLogging { - val selfAddress = Cluster(context.system).selfAddress - - // subscribe to ClusterMetricsChanged - // re-subscribe when restart - override def preStart(): Unit = - Cluster(context.system).subscribe(self, classOf[ClusterMetricsChanged]) - override def postStop(): Unit = - Cluster(context.system).unsubscribe(self) - - def receive = { - case ClusterMetricsChanged(clusterMetrics) => - clusterMetrics.filter(_.address == selfAddress) foreach { nodeMetrics => - logHeap(nodeMetrics) - logCpu(nodeMetrics) - } - case state: CurrentClusterState => // ignore - } - - def logHeap(nodeMetrics: NodeMetrics): Unit = nodeMetrics match { - case HeapMemory(address, timestamp, used, committed, max) => - log.info("Used heap: {} MB", used.doubleValue / 1024 / 1024) - case _ => // no heap info - } - - def logCpu(nodeMetrics: NodeMetrics): Unit = nodeMetrics match { - case Cpu(address, timestamp, Some(systemLoadAverage), cpuCombined, processors) => - log.info("Load: {} ({} processors)", systemLoadAverage, processors) - case _ => // no cpu info - } -} - -//#metrics-listener - diff --git a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/NetworkConfig.scala b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/NetworkConfig.scala index 66dcb1b..6259267 100644 --- a/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/NetworkConfig.scala +++ b/akka-sample-cluster-on-cloudfoundry/akka-sample-cluster/src/main/scala/sample/cluster/factorial/NetworkConfig.scala @@ -1,20 +1,21 @@ package sample.cluster.factorial -import java.net.{InetAddress, NetworkInterface, URLEncoder} +import java.net.InetAddress -import scala.collection.JavaConversions._ -import com.typesafe.config.{Config, ConfigFactory, ConfigValueFactory} -import play.api.libs.json.Json +import scala.collection.JavaConverters._ -import scala.concurrent.{ExecutionContext, Future} -import scalaj.http.{Http, HttpOptions, HttpResponse} +import com.typesafe.config.Config +import com.typesafe.config.ConfigFactory +import com.typesafe.config.ConfigValueFactory -/** - * Created by Admin on 2016-08-31. - */ object NetworkConfig { - def hostLocalAddress: String = System.getenv("CF_INSTANCE_INTERNAL_IP") + def hostLocalAddress: String = { + System.getenv("CF_INSTANCE_INTERNAL_IP") match { + case null => "127.0.0.1" // for local testing + case ip => ip + } + } def seedsConfig( clusterName: String, @@ -22,7 +23,9 @@ object NetworkConfig { internalSeedPort: String): Config = { ConfigFactory.empty().withValue("akka.cluster.seed-nodes", ConfigValueFactory.fromIterable( - InetAddress.getAllByName(internalSeedHostname).map(_.getHostAddress).toSeq. - map{ case(ip) => s"akka.tcp://$clusterName@$ip:$internalSeedPort"})) + InetAddress.getAllByName(internalSeedHostname).toVector.map { address => + s"akka.tcp://$clusterName@${address.getHostAddress}:$internalSeedPort" + }.asJava)) + // change 'akka.tcp' to 'akka' if artery is enabled } }