Skip to content

Commit

Permalink
add extra changes needed to get akka cluster support
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored and mdedetrich committed Jan 26, 2024
1 parent 27b4032 commit 4b78adf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
54 changes: 54 additions & 0 deletions cluster/src/main/scala/org/apache/pekko/cluster/ConfigUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.cluster

import com.typesafe.config.{ Config, ConfigValue, ConfigValueFactory, ConfigValueType }

import scala.annotation.nowarn

private[cluster] object ConfigUtil {

@nowarn("msg=deprecated")
def addAkkaConfig(cfg: Config, akkaVersion: String): Config = {
import scala.collection.JavaConverters._
val innerSet = cfg.entrySet().asScala
.filter(e => e.getKey.startsWith("pekko.") && e.getValue.valueType() != ConfigValueType.OBJECT)
.map { entry =>
entry.getKey.replace("pekko", "akka") -> adjustPackageNameIfNecessary(entry.getValue)
}
var newConfig = cfg
innerSet.foreach { case (key, value) =>
newConfig = newConfig.withValue(key, value)
}
newConfig.withValue("akka.version", ConfigValueFactory.fromAnyRef(akkaVersion))
}

private def adjustPackageNameIfNecessary(cv: ConfigValue): ConfigValue = {
if (cv.valueType() == ConfigValueType.STRING) {
val str = cv.unwrapped().toString
if (str.startsWith("org.apache.pekko")) {
ConfigValueFactory.fromAnyRef(str.replace("org.apache.pekko", "akka"))
} else {
cv
}
} else {
cv
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ private[cluster] abstract class SeedNodeProcess(joinConfigCompatChecker: JoinCon
"Note that disabling it will allow the formation of a cluster with nodes having incompatible configuration settings. " +
"This node will be shutdown!"

private lazy val needsAkkaConfig: Boolean = {
context.system.settings.config
.getStringList("pekko.remote.accept-protocol-names")
.contains("akka")
}

private lazy val akkaVersion: String = {
val cfg = context.system.settings.config
if (cfg.hasPath("akka.version")) {
cfg.getString("akka.version")
} else {
cfg.getString("pekko.cluster.akka.version")
}
}

private def stopOrBecome(behavior: Option[Actor.Receive]): Unit =
behavior match {
case Some(done) => context.become(done) // JoinSeedNodeProcess
Expand All @@ -65,8 +80,12 @@ private[cluster] abstract class SeedNodeProcess(joinConfigCompatChecker: JoinCon
val configToValidate =
JoinConfigCompatChecker.filterWithKeys(requiredNonSensitiveKeys, context.system.settings.config)

val adjustedConfig = if (needsAkkaConfig)
ConfigUtil.addAkkaConfig(configToValidate, akkaVersion)
else configToValidate

seedNodes.foreach { a =>
context.actorSelection(context.parent.path.toStringWithAddress(a)) ! InitJoin(configToValidate)
context.actorSelection(context.parent.path.toStringWithAddress(a)) ! InitJoin(adjustedConfig)
}
}

Expand Down

0 comments on commit 4b78adf

Please sign in to comment.