You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/09/21 15:49:37 UTC

[activemq-artemis] branch main updated: ARTEMIS-4007 - expose status attribute on configuration that can hold version or error state and reflect modifications via refresh

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 2d662a07f3 ARTEMIS-4007 - expose status attribute on configuration that can hold version or error state and reflect modifications via refresh
     new 9c851f9605 This closes #4228
2d662a07f3 is described below

commit 2d662a07f3d74002d866d828519cfdaab2fceb14
Author: Gary Tully <ga...@gmail.com>
AuthorDate: Wed Sep 21 12:48:06 2022 +0100

    ARTEMIS-4007 - expose status attribute on configuration that can hold version or error state and reflect modifications via refresh
---
 .../java/org/apache/activemq/artemis/logs/AuditLogger.java    |  8 ++++++++
 .../artemis/api/core/management/ActiveMQServerControl.java    |  3 +++
 .../apache/activemq/artemis/core/config/Configuration.java    |  7 +++++++
 .../activemq/artemis/core/config/impl/ConfigurationImpl.java  | 11 +++++++++++
 .../core/management/impl/ActiveMQServerControlImpl.java       | 10 ++++++++++
 .../apache/activemq/artemis/core/server/ActiveMQServer.java   |  4 ++++
 .../management/ActiveMQServerControlUsingCoreTest.java        |  5 +++++
 .../artemis/tests/integration/server/ConfigurationTest.java   |  5 +++++
 8 files changed, 53 insertions(+)

diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java
index 990b6ebd3f..f4ca51030b 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java
@@ -2984,4 +2984,12 @@ public interface AuditLogger extends BasicLogger {
    @LogMessage(level = Logger.Level.INFO)
    @Message(id = 601764, value = "User {0} is calling deliverScheduledMessage on queue: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
    void deliverScheduledMessage(String user, Object source, Object... args);
+
+   static void getStatus(Object source, Object... args) {
+      BASE_LOGGER.getStatus(getCaller(), source);
+   }
+
+   @LogMessage(level = Logger.Level.INFO)
+   @Message(id = 601765, value = "User {0} is getting status on target resource: {1}", format = Message.Format.MESSAGE_FORMAT)
+   void getStatus(String user, Object source);
 }
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java
index ad88409819..2889ecbe1d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java
@@ -521,6 +521,9 @@ public interface ActiveMQServerControl {
    @Attribute(desc = "The runtime size of the authorization cache")
    long getAuthorizationCacheSize();
 
+   @Attribute(desc = "The current status in JSON format")
+   String getStatus();
+
    // Operations ----------------------------------------------------
    @Operation(desc = "Isolate the broker", impact = MBeanOperationInfo.ACTION)
    boolean freezeReplication();
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
index ad2a5c9f26..cfd2c71f59 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
@@ -1430,4 +1430,11 @@ public interface Configuration {
    default String resolvePropertiesSources(String propertiesFileUrl) {
       return System.getProperty(ActiveMQDefaultConfiguration.BROKER_PROPERTIES_SYSTEM_PROPERTY_NAME, propertiesFileUrl);
    }
+
+   String getStatus();
+
+   /** This value can reflect a desired state (revision) of config. Useful when configurationFileRefreshPeriod > 0
+       Eventually with some coordination we can update it from various server components. */
+   // Inspired by https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#:~:text=The%20status%20describes%20the%20current,the%20desired%20state%20you%20supplied
+   void setStatus(String status);
 }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index 62a13627ad..a528fc9715 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -401,6 +401,7 @@ public class ConfigurationImpl implements Configuration, Serializable {
     * Parent folder for all data folders.
     */
    private File artemisInstance;
+   private String status;
 
    @Override
    public String getJournalRetentionDirectory() {
@@ -2848,6 +2849,16 @@ public class ConfigurationImpl implements Configuration, Serializable {
       return this;
    }
 
+   @Override
+   public String getStatus() {
+      return status;
+   }
+
+   @Override
+   public void setStatus(String status) {
+      this.status = status;
+   }
+
    // extend property utils with ability to auto-fill and locate from collections
    // collection entries are identified by the name() property
    private static class CollectionAutoFillPropertiesUtil extends PropertyUtilsBean {
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
index a395757701..ada081c798 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java
@@ -4490,6 +4490,16 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
       }
    }
 
+   @Override
+   public String getStatus() {
+      if (AuditLogger.isBaseLoggingEnabled()) {
+         AuditLogger.getStatus(this.server);
+      }
+      checkStarted();
+
+      return server.getConfiguration().getStatus();
+   }
+
    @Override
    public void resetUser(String username, String password, String roles, boolean plaintext) throws Exception {
       if (AuditLogger.isBaseLoggingEnabled()) {
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
index 5a88dd08d2..bbc32eb727 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
@@ -964,4 +964,8 @@ public interface ActiveMQServer extends ServiceComponent {
 
    default void setProperties(String fileUrltoBrokerProperties) {
    }
+
+   default String getStatus() {
+      return "";
+   }
 }
\ No newline at end of file
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
index a28ee4e633..2ffef62bb2 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java
@@ -838,6 +838,11 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
             return (Long) proxy.retrieveAttributeValue("AuthorizationCacheSize", Long.class);
          }
 
+         @Override
+         public String getStatus() {
+            return (String) proxy.retrieveAttributeValue("Status", String.class);
+         }
+
          @Override
          public double getDiskStoreUsage() {
             try {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ConfigurationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ConfigurationTest.java
index 269dc53c94..b3457f641a 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ConfigurationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ConfigurationTest.java
@@ -87,6 +87,7 @@ public class ConfigurationTest extends ActiveMQTestBase {
 
       config.put("addressConfigurations.mytopic_3.queueConfigs.\"queue.B3\".address", "mytopic_3");
       config.put("addressConfigurations.mytopic_3.queueConfigs.\"queue.B3\".routingType", "MULTICAST");
+      config.put("status","{\"generation\": \"1\"}");
 
       try (FileOutputStream outStream = new FileOutputStream(propsFile)) {
          config.store(outStream, null);
@@ -112,6 +113,7 @@ public class ConfigurationTest extends ActiveMQTestBase {
 
          // add new binding from props update
          config.put("addressConfigurations.mytopic_3.queueConfigs.\"queue.C3\".address", "mytopic_3");
+         config.put("status","{\"generation\": \"2\"}");
 
          try (FileOutputStream outStream = new FileOutputStream(propsFile)) {
             config.store(outStream, null);
@@ -122,6 +124,9 @@ public class ConfigurationTest extends ActiveMQTestBase {
             return mytopic_31.getBindings().size() == 3;
          });
 
+         // verify round trip apply
+         Assert.assertTrue(server.getActiveMQServerControl().getStatus().contains("2"));
+
       } finally {
          try {
             server.stop();