You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2018/02/23 15:58:33 UTC

qpid-broker-j git commit: QPID-8110: [Broker-J] Add ability to check ERRORED state of entire configured object hierarchy

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 0a26d40f3 -> b720d7d1e


QPID-8110: [Broker-J] Add ability to check ERRORED state of entire configured object hierarchy

This closes #4
https://github.com/apache/qpid-broker-j/pull/4


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/b720d7d1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/b720d7d1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/b720d7d1

Branch: refs/heads/master
Commit: b720d7d1e81324441b8fbc2850ef19ca0fdf9bda
Parents: 0a26d40
Author: Alex Rudyy <or...@apache.org>
Authored: Fri Feb 23 15:58:12 2018 +0000
Committer: Alex Rudyy <or...@apache.org>
Committed: Fri Feb 23 15:58:12 2018 +0000

----------------------------------------------------------------------
 .../org/apache/qpid/server/model/Broker.java    |  4 +
 .../apache/qpid/server/model/BrokerImpl.java    | 85 +++++++++++++++-----
 .../qpid/server/model/DescendantType.java       | 26 ++++++
 3 files changed, 93 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b720d7d1/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java b/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
index 6f7b74c..3bb26d4 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
@@ -54,6 +54,7 @@ public interface Broker<X extends Broker<X>> extends ConfiguredObject<X>, EventL
     String CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT = "channel.flowControlEnforcementTimeout";
     String BROKER_FLOW_TO_DISK_THRESHOLD = "broker.flowToDiskThreshold";
     String BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD = "broker.failStartupWithErroredChild";
+    String BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE = "broker.failStartupWithErroredChildScope";
 
     String BROKER_MSG_AUTH = "qpid.broker_msg_auth";
 
@@ -99,6 +100,9 @@ public interface Broker<X extends Broker<X>> extends ConfiguredObject<X>, EventL
     @ManagedContextDefault(name = BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD)
     boolean DEFAULT_BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD = false;
 
+    @ManagedContextDefault(name = BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE)
+    DescendantType DEFAULT_BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE = DescendantType.IMMEDIATE;
+
     @ManagedContextDefault(name = BROKER_MSG_AUTH)
     boolean DEFAULT_BROKER_MSG_AUTH = false;
 

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b720d7d1/broker-core/src/main/java/org/apache/qpid/server/model/BrokerImpl.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerImpl.java b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerImpl.java
index 7119d00..62c71b9 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/BrokerImpl.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/BrokerImpl.java
@@ -27,6 +27,7 @@ import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -273,6 +274,28 @@ public class BrokerImpl extends AbstractContainer<BrokerImpl> implements Broker<
         {
             throw new IllegalConfigurationException("Cannot change the model version");
         }
+
+        if (changedAttributes.contains(CONTEXT))
+        {
+            @SuppressWarnings("unchecked")
+            Map<String, String> context = (Map<String, String>) proxyForValidation.getAttribute(CONTEXT);
+            if (context.containsKey(BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE))
+            {
+                String value = context.get(BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE);
+                try
+                {
+                    DescendantType.valueOf(value);
+                }
+                catch (Exception e)
+                {
+                    throw new IllegalConfigurationException(String.format(
+                            "Unsupported value '%s' is specified for context variable '%s'. Please, change it to any of supported : %s",
+                            value,
+                            BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE,
+                            EnumSet.allOf(DescendantType.class)));
+                }
+            }
+        }
     }
 
     @Override
@@ -362,38 +385,32 @@ public class BrokerImpl extends AbstractContainer<BrokerImpl> implements Broker<
 
     private void performActivation()
     {
-        boolean hasBrokerAnyErroredChildren = false;
+        final DescendantType descendantScope = getContextValue(DescendantType.class,
+                                                               BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE);
+        List<ConfiguredObject<?>> failedChildren = getChildrenInState(this, State.ERRORED, descendantScope);
 
-        List<ConfiguredObject<?>> failedChildren = new ArrayList<>();
-        for (final Class<? extends ConfiguredObject> childClass : getModel().getChildTypes(getCategoryClass()))
+        if (!failedChildren.isEmpty())
         {
-            final Collection<? extends ConfiguredObject> children = getChildren(childClass);
-            if (children != null) {
-                for (final ConfiguredObject<?> child : children)
-                {
-                    if (child.getState() == State.ERRORED )
-                    {
-                        hasBrokerAnyErroredChildren = true;
-                        LOGGER.warn("Broker child object '{}' of type '{}' is {}",
-                                child.getName(), childClass.getSimpleName(), State.ERRORED);
-                        failedChildren.add(child);
-                    }
-                }
+            for (ConfiguredObject<?> o : failedChildren)
+            {
+                LOGGER.warn("{} child object '{}' of type '{}' is {}",
+                            o.getParent().getCategoryClass().getSimpleName(),
+                            o.getName(),
+                            o.getClass().getSimpleName(),
+                            State.ERRORED);
             }
-        }
-
-        if(!failedChildren.isEmpty())
-        {
             getEventLogger().message(BrokerMessages.FAILED_CHILDREN(failedChildren.toString()));
         }
 
         _documentationUrl = getContextValue(String.class, QPID_DOCUMENTATION_URL);
         final boolean brokerShutdownOnErroredChild = getContextValue(Boolean.class,
                                                                      BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD);
-        if (!_parent.isManagementMode() && brokerShutdownOnErroredChild && hasBrokerAnyErroredChildren)
+        if (!_parent.isManagementMode() && brokerShutdownOnErroredChild && !failedChildren.isEmpty())
         {
-            throw new IllegalStateException(String.format("Broker context variable %s is set and the broker has %s children",
-                    BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD, State.ERRORED));
+            throw new IllegalStateException(String.format(
+                    "Broker context variable %s is set and the broker has %s children",
+                    BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD,
+                    State.ERRORED));
         }
         updateAccessControl();
 
@@ -422,6 +439,30 @@ public class BrokerImpl extends AbstractContainer<BrokerImpl> implements Broker<
         setState(State.ACTIVE);
     }
 
+    private List<ConfiguredObject<?>> getChildrenInState(final ConfiguredObject<?> configuredObject,
+                                                         final State state,
+                                                         final DescendantType descendantScope)
+    {
+        List<ConfiguredObject<?>> foundChildren = new ArrayList<>();
+        Class<? extends ConfiguredObject> categoryClass = configuredObject.getCategoryClass();
+        for (final Class<? extends ConfiguredObject> childClass : getModel().getChildTypes(categoryClass))
+        {
+            final Collection<? extends ConfiguredObject> children = configuredObject.getChildren(childClass);
+            for (final ConfiguredObject<?> child : children)
+            {
+                if (child.getState() == state)
+                {
+                    foundChildren.add(child);
+                }
+                if (descendantScope == DescendantType.ALL)
+                {
+                    foundChildren.addAll(getChildrenInState(child, state, descendantScope));
+                }
+            }
+        }
+        return foundChildren;
+    }
+
     private void checkDirectMemoryUsage()
     {
         if (_compactMemoryThreshold >= 0

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b720d7d1/broker-core/src/main/java/org/apache/qpid/server/model/DescendantType.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/DescendantType.java b/broker-core/src/main/java/org/apache/qpid/server/model/DescendantType.java
new file mode 100644
index 0000000..66d296a
--- /dev/null
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/DescendantType.java
@@ -0,0 +1,26 @@
+package org.apache.qpid.server.model;/*
+ *
+ * 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.
+ *
+ */
+
+public enum DescendantType
+{
+    IMMEDIATE,
+    ALL
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org