[ 
https://issues.apache.org/jira/browse/CAMEL-12980?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16740200#comment-16740200
 ] 

Grzegorz Grzybek commented on CAMEL-12980:
------------------------------------------

OK, Here's what I did. With sample blueprint.xml with *two* contexts (one bad, 
one correct):
{code:xml}
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";> 
    <camelContext xmlns="http://camel.apache.org/schema/blueprint";> 
        <route id="r1"> 
            <from 
uri="timer://simpleTimer?period=1000&amp;repeatCount=0&amp;funnyopt=1" /> 
            <setBody> <simple>Hello World 1</simple> </setBody> 
            <to uri="log:test" />
        </route> 
    </camelContext> 
    <camelContext xmlns="http://camel.apache.org/schema/blueprint";> 
        <route id="r2"> 
            <from uri="timer://simpleTimer?period=1000&amp;repeatCount=0" /> 
            <setBody> <simple>Hello World 2</simple> </setBody> 
            <to uri="log:test" />
        </route> 
    </camelContext> 
</blueprint> 
{code}

I've installed it using {{install -s blueprint:file:///data/tmp/blueprint.xml}} 
and saw:

# working and visible context 2:
{noformat}
karaf@root()> context-list
 Context        Status              Total #       Failed #     Inflight #   
Uptime         
 -------        ------              -------       --------     ----------   
------         
 camel-4        Started                   7              0              0   
7.662 seconds  
karaf@root()> route-list
 Context        Route          Status              Total #       Failed #     
Inflight #   Uptime         
 -------        -----          ------              -------       --------     
----------   ------         
 camel-4        r2             Started                   9              0       
       0   9.213 seconds  
{noformat}

Correct state for a bundle:
{noformat}
karaf@root()> la -l|grep blueprint.xml
65 │ Failure  │  80 │ 0.0.0           │ blueprint:file:///data/tmp/blueprint.xml
{noformat}

Additional diagnostic information:
{noformat}
karaf@root()> bundle:diag 65
Bundle 65
---------
Status: Failure
Camel Blueprint
Camel context "camel-3"
Exception: Failed to create route r1: 
Route(r1)[[From[timer://simpleTimer?period=1000&repeatCount=... because of 
Failed to resolve endpoint: 
timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due to: Failed to 
resolve endpoint: timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due 
to: There are 1 parameters that couldn't be set on the endpoint. Check the uri 
if the parameters are spelt correctly and that they are properties of the 
endpoint. Unknown parameters=[{funnyopt=1}]
org.apache.camel.FailedToCreateRouteException: Failed to create route r1: 
Route(r1)[[From[timer://simpleTimer?period=1000&repeatCount=... because of 
Failed to resolve endpoint: 
timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due to: Failed to 
resolve endpoint: timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due 
to: There are 1 parameters that couldn't be set on the endpoint. Check the uri 
if the parameters are spelt correctly and that they are properties of the 
endpoint. Unknown parameters=[{funnyopt=1}]
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:217)
        at 
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1140)
        at 
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3735)
        at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3440)
        at 
org.apache.camel.impl.DefaultCamelContext$4.call(DefaultCamelContext.java:3248)
        at 
org.apache.camel.impl.DefaultCamelContext$4.call(DefaultCamelContext.java:3244)
        at 
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3267)
        at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3244)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:72)
        at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3160)
        at 
org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:254)
        at 
org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:296)
        at 
org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:187)
        at 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190)
        at 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve 
endpoint: timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due to: 
Failed to resolve endpoint: 
timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due to: There are 1 
parameters that couldn't be set on the endpoint. Check the uri if the 
parameters are spelt correctly and that they are properties of the endpoint. 
Unknown parameters=[{funnyopt=1}]
        at 
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:753)
        at 
org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80)
        at 
org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:227)
        at 
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
        at 
org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:122)
        at 
org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:75)
        at 
org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:98)
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1332)
        at 
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:212)
        ... 24 more
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve 
endpoint: timer://simpleTimer?funnyopt=1&period=1000&repeatCount=0 due to: 
There are 1 parameters that couldn't be set on the endpoint. Check the uri if 
the parameters are spelt correctly and that they are properties of the 
endpoint. Unknown parameters=[{funnyopt=1}]
        at 
org.apache.camel.impl.DefaultComponent.validateParameters(DefaultComponent.java:215)
        at 
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:139)
        at 
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:706)
        ... 32 more

{noformat}

After stopping the bundle, the status is correct and contexts are gone:
{noformat}
karaf@root()> context-list
karaf@root()> bundle:diag 65
karaf@root()> la -l|grep blueprint.xml
65 │ Resolved │  80 │ 0.0.0           │ blueprint:file:///data/tmp/blueprint.xml
{noformat}

There's single instance of new {{BundleStateService}} exposed from blueprint 
bundle (regardles of number of contexts it exposes):
{noformat}
karaf@root()> bundle:services  -p 65                                            
                                  

Bundle 65 provides:
-------------------
objectClass = [org.apache.karaf.bundle.core.BundleStateService]
service.bundleid = 65
service.id = 156
service.scope = singleton
...
{noformat}

This new service is used by 
{{org.apache.camel.blueprint.BlueprintCamelContext#start()}} to track state of 
the bundle and context.

After fixing first camel context we see the state changed and diagnostic info 
removed:
{noformat}
karaf@root()> context-list
 Context        Status              Total #       Failed #     Inflight #   
Uptime         
 -------        ------              -------       --------     ----------   
------         
 camel-7        Started                   6              0              0   
6.989 seconds  
 camel-8        Started                   6              0              0   
6.963 seconds  
karaf@root()> bundle:diag 65
karaf@root()> la -l|grep blueprint.xml
65 │ Active   │  80 │ 0.0.0           │ blueprint:file:///data/tmp/blueprint.xml
{noformat}

And blueprint bundle exposes 6 services:
{noformat}
karaf@root()> bundle:services 65

Bundle 65 provides:
-------------------
[org.apache.karaf.bundle.core.BundleStateService]
[org.osgi.service.blueprint.container.BlueprintListener]
[org.osgi.service.blueprint.container.BlueprintListener]
[org.osgi.service.blueprint.container.BlueprintContainer]
[org.apache.camel.CamelContext]
[org.apache.camel.CamelContext]
{noformat}

camel-blueprint bundle imports additional package (optionally):
{noformat}
org.apache.karaf.bundle.core;resolution:=optional;version="[4,5)"
{noformat}

If (somehow), this package is not available (wrong Karaf version or no Karaf at 
all), everything works fine, but bundle is Active (again, with one correct and 
one broken context):
{noformat}
karaf@root()> bundle:diag 65
karaf@root()> la -l|grep blueprint.xml
65 │ Active   │  80 │ 0.0.0           │ blueprint:file:///data/tmp/blueprint.xml
karaf@root()> context-list
 Context        Status              Total #       Failed #     Inflight #   
Uptime          
 -------        ------              -------       --------     ----------   
------          
 camel-4        Started                  18              0              0   
18.667 seconds  
{noformat}


> Bundle in 'Active' State but Camel Context not initialized
> ----------------------------------------------------------
>
>                 Key: CAMEL-12980
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12980
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-blueprint
>    Affects Versions: 2.20.1, 2.21.1
>            Reporter: Xilai Dai
>            Assignee: Grzegorz Grzybek
>            Priority: Critical
>             Fix For: 3.0.0, 2.24.0
>
>         Attachments: blueprint.xml
>
>
> The camel context can't get initialized when validation of the 
> RouteDefinition failed (e.g. typo in Uri or add an unsupported option in 
> Uri), but when deploy the blueprint, the CamelContext startup and then 
> shutdown, but the bundle status is still 'Active', only a 
> FailedToCreateRouteException ERROR is logged.
> 318 │ Active  │  80 │ 0.0.0                 │ blueprint.xml
> Attached the simple blueprint.xml for reproduce it.
> The expected behaviour is the bundle is in the 'Failure' status in this case.
> The fix proposal from my side is, move the call of "this.maybeStart()" from 
> blueprintEvent() method to the constructor of the BlueprintCamelContext 
> class. then this kind of Route definition error can be processed during the 
> Blueprint "CREATING" phase. Currently, the start() is invoked after Blueprint 
> in "CREATED" phase. (I tested this fix locally and have the expected 
> 'Failure' bundle status) 
> (This issue is found in Camel 2.20.x, 2.21.x, but it may affects also on 
> master branch)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to