This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new d22ef30 MBean to dump config information at a path (#4280)
d22ef30 is described below
commit d22ef30fe613d60d84a5310a6b89cdbe2c495995
Author: Chetan Mehrotra <chetanm@apache.org>
AuthorDate: Fri Feb 15 07:26:45 2019 +0530
MBean to dump config information at a path (#4280)
---
.../org/apache/openwhisk/common/ConfigMXBean.scala | 55 ++++++++++++++++++++++
.../openwhisk/core/controller/Controller.scala | 3 +-
.../apache/openwhisk/core/invoker/Invoker.scala | 1 +
.../openwhisk/common/ConfigMXBeanTests.scala | 39 +++++++++++++++
4 files changed, 97 insertions(+), 1 deletion(-)
diff --git a/common/scala/src/main/scala/org/apache/openwhisk/common/ConfigMXBean.scala b/common/scala/src/main/scala/org/apache/openwhisk/common/ConfigMXBean.scala
new file mode 100644
index 0000000..8551ac7
--- /dev/null
+++ b/common/scala/src/main/scala/org/apache/openwhisk/common/ConfigMXBean.scala
@@ -0,0 +1,55 @@
+/*
+ * 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.openwhisk.common
+import java.lang.management.ManagementFactory
+
+import com.typesafe.config.{ConfigFactory, ConfigRenderOptions}
+import javax.management.ObjectName
+
+trait ConfigMXBean {
+
+ /**
+ * Renders the config value to a string
+ *
+ * @param path root of subtree which needs to be rendered. Pass `.` for getting whole subtree
rendered
+ * @param originComment {@link ConfigValue#origin} of that setting's value. For example
these
+ * comments might tell you which file a setting comes from.
+ * @return rendered config
+ */
+ def getConfig(path: String, originComment: Boolean): String
+}
+
+object ConfigMXBean extends ConfigMXBean {
+ val name = new ObjectName("org.apache.openwhisk:name=config")
+ private val renderOptions =
+ ConfigRenderOptions.defaults().setComments(false).setOriginComments(true).setFormatted(true).setJson(false)
+
+ override def getConfig(path: String, originComment: Boolean): String = {
+ val config = ConfigFactory.load()
+ val co = if (path == ".") config.root() else config.getConfig(path).root()
+ co.render(renderOptions.setOriginComments(originComment))
+ }
+
+ def register(): Unit = {
+ ManagementFactory.getPlatformMBeanServer.registerMBean(ConfigMXBean, name)
+ }
+
+ def unregister(): Unit = {
+ ManagementFactory.getPlatformMBeanServer.unregisterMBean(name)
+ }
+}
diff --git a/core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala
b/core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala
index 5136a66..44a7099 100644
--- a/core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala
+++ b/core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala
@@ -29,7 +29,7 @@ import pureconfig.loadConfigOrThrow
import spray.json.DefaultJsonProtocol._
import spray.json._
import org.apache.openwhisk.common.Https.HttpsConfig
-import org.apache.openwhisk.common.{AkkaLogging, Logging, LoggingMarkers, TransactionId}
+import org.apache.openwhisk.common.{AkkaLogging, ConfigMXBean, Logging, LoggingMarkers, TransactionId}
import org.apache.openwhisk.core.WhiskConfig
import org.apache.openwhisk.core.connector.MessagingProvider
import org.apache.openwhisk.core.containerpool.logging.LogStoreProvider
@@ -207,6 +207,7 @@ object Controller {
"runtimes" -> runtimes.toJson)
def main(args: Array[String]): Unit = {
+ ConfigMXBean.register()
Kamon.loadReportersFromConfig()
implicit val actorSystem = ActorSystem("controller-actor-system")
implicit val logger = new AkkaLogging(akka.event.Logging.getLogger(actorSystem, this))
diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala
index 2f35afb..5f42040 100644
--- a/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala
+++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/Invoker.scala
@@ -64,6 +64,7 @@ object Invoker {
}
def main(args: Array[String]): Unit = {
+ ConfigMXBean.register()
Kamon.loadReportersFromConfig()
implicit val ec = ExecutionContextFactory.makeCachedThreadPoolExecutionContext()
implicit val actorSystem: ActorSystem =
diff --git a/tests/src/test/scala/org/apache/openwhisk/common/ConfigMXBeanTests.scala b/tests/src/test/scala/org/apache/openwhisk/common/ConfigMXBeanTests.scala
new file mode 100644
index 0000000..c47e5e0
--- /dev/null
+++ b/tests/src/test/scala/org/apache/openwhisk/common/ConfigMXBeanTests.scala
@@ -0,0 +1,39 @@
+/*
+ * 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.openwhisk.common
+import java.lang.management.ManagementFactory
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.{FlatSpec, Matchers}
+
+@RunWith(classOf[JUnitRunner])
+class ConfigMXBeanTests extends FlatSpec with Matchers {
+ behavior of "ConfigMBean"
+
+ it should "return config at path" in {
+ ConfigMXBean.register()
+ val config = ManagementFactory.getPlatformMBeanServer.invoke(
+ ConfigMXBean.name,
+ "getConfig",
+ Array("whisk.spi", java.lang.Boolean.FALSE),
+ Array("java.lang.String", "boolean"))
+ config.asInstanceOf[String] should include("ArtifactStoreProvider")
+ ConfigMXBean.unregister()
+ }
+}
|