You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/01 07:48:56 UTC

[camel] branch master updated (7312e3c -> 58fb94f)

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

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 7312e3c  CAMEL-13036: Allow advice with to turn off logging routes before/after as XML
     new cf93fec  CAMEL-13810: Always log ERROR if failed to start CamelContext
     new 58fb94f  CAMEL-13094: Ensure service is stopped if it fails to start as it did in Camel 2.x. This can also lead to JMX MBeans not being unregistered from the JVM. Thanks to Thomas Diesler for the unit test.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/support/service/ServiceSupport.java      | 11 +++
 .../camel/impl/engine/AbstractCamelContext.java    |  1 +
 .../RouteStartupFailShouldStopAlsoIssueTest.java   | 11 +--
 .../camel/management/ManagedStartupFailedTest.java | 82 ++++++++++++++++++++++
 4 files changed, 97 insertions(+), 8 deletions(-)
 create mode 100644 core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java


[camel] 01/02: CAMEL-13810: Always log ERROR if failed to start CamelContext

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cf93fecc9f8d36eebd6faad896d89909ed9578c6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 1 09:26:17 2019 +0200

    CAMEL-13810: Always log ERROR if failed to start CamelContext
---
 .../src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 11b6e3e..4c3b7a6 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2291,6 +2291,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
                         return;
                     }
                 } else {
+                    log.error("Error starting CamelContext (" + getName() + ") due to exception thrown: " + e.getMessage(), e);
                     throw RuntimeCamelException.wrapRuntimeException(e);
                 }
             }


[camel] 02/02: CAMEL-13094: Ensure service is stopped if it fails to start as it did in Camel 2.x. This can also lead to JMX MBeans not being unregistered from the JVM. Thanks to Thomas Diesler for the unit test.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 58fb94fc865db636b5cda224d87f537807787dc5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 1 09:27:34 2019 +0200

    CAMEL-13094: Ensure service is stopped if it fails to start as it did in Camel 2.x. This can also lead to JMX MBeans not being unregistered from the JVM. Thanks to Thomas Diesler for the unit test.
---
 .../camel/support/service/ServiceSupport.java      | 11 +++
 .../RouteStartupFailShouldStopAlsoIssueTest.java   | 11 +--
 .../camel/management/ManagedStartupFailedTest.java | 82 ++++++++++++++++++++++
 3 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/support/service/ServiceSupport.java b/core/camel-api/src/main/java/org/apache/camel/support/service/ServiceSupport.java
index 1fbbe85..c62a998 100644
--- a/core/camel-api/src/main/java/org/apache/camel/support/service/ServiceSupport.java
+++ b/core/camel-api/src/main/java/org/apache/camel/support/service/ServiceSupport.java
@@ -98,6 +98,13 @@ public abstract class ServiceSupport implements StatefulService {
                 status = STARTED;
                 log.trace("Service started: {}", this);
             } catch (Exception e) {
+                // need to stop as some resources may have been started during startup
+                try {
+                    stop();
+                } catch (Exception e2) {
+                    // ignore
+                    log.trace("Error while stopping service after it failed to start: " + this + ". This exception is ignored", e);
+                }
                 status = FAILED;
                 log.trace("Error while starting service: " + this, e);
                 throw RuntimeCamelException.wrapRuntimeException(e);
@@ -113,6 +120,10 @@ public abstract class ServiceSupport implements StatefulService {
      */
     public void stop() {
         synchronized (lock) {
+            if (status == FAILED) {
+                log.trace("Service: {} failed and regarded as already stopped", this);
+                return;
+            }
             if (status == STOPPED || status == SHUTTINGDOWN || status == SHUTDOWN) {
                 log.trace("Service: {} already stopped", this);
                 return;
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/RouteStartupFailShouldStopAlsoIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/RouteStartupFailShouldStopAlsoIssueTest.java
index 219c1e3..b7f9490 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/RouteStartupFailShouldStopAlsoIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/RouteStartupFailShouldStopAlsoIssueTest.java
@@ -67,17 +67,12 @@ public class RouteStartupFailShouldStopAlsoIssueTest extends ContextTestSupport
         assertTrue(context.getRouteController().getRouteStatus("foo").isStopped());
         assertFalse(context.getRouteController().getRouteStatus("foo").isStarted());
 
-        assertFalse(context.getRouteController().getRouteStatus("bar").isStopped());
-        assertTrue(context.getRouteController().getRouteStatus("bar").isStarted());
-
-        context.stop();
-
-        assertTrue(context.getRouteController().getRouteStatus("foo").isStopped());
-        assertFalse(context.getRouteController().getRouteStatus("foo").isStarted());
-
         assertTrue(context.getRouteController().getRouteStatus("bar").isStopped());
         assertFalse(context.getRouteController().getRouteStatus("bar").isStarted());
 
+        assertFalse(context.getStatus().isStarted());
+        assertTrue(context.getStatus().isStopped());
+
         assertEquals(3, EVENTS.size());
         assertEquals("constructor", EVENTS.get(0));
         assertEquals("doStart", EVENTS.get(1));
diff --git a/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java
new file mode 100644
index 0000000..54c1c37
--- /dev/null
+++ b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java
@@ -0,0 +1,82 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.camel.management;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ManagedStartupFailedTest extends ManagementTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testAllGood() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").transform(body().prepend("Hello "));
+            }
+        });
+
+        context.start();
+
+        MBeanServer server = getMBeanServer();
+        try {
+            Set<ObjectName> onames = server.queryNames(new ObjectName("org.apache.camel:*"), null);
+            assertTrue(onames.size() > 0);
+
+            ProducerTemplate producer = context.createProducerTemplate();
+            String result = producer.requestBody("direct:start", "Kermit", String.class);
+            assertEquals("Hello Kermit", result);
+        } finally {
+            context.stop();
+        }
+
+        Set<ObjectName> onames = server.queryNames(new ObjectName("org.apache.camel:*"), null);
+        assertEquals(Collections.emptySet(), onames);
+    }
+
+    @Test
+    public void testStartupFailure() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("invalid:start");
+            }
+        });
+
+        try {
+            context.start();
+            fail("Startup failure expected");
+        } catch (Exception ex) {
+            // expected
+        }
+
+        MBeanServer server = getMBeanServer();
+        Set<ObjectName> onames = server.queryNames(new ObjectName("org.apache.camel:*"), null);
+        assertEquals(Collections.emptySet(), onames);
+    }
+}