5 Replies Latest reply on Oct 30, 2012 12:58 PM by plord_plord

    Deploying features using <config> to set different property values for each

    plord_plord

      I am trying to deploy a bundle which contains a camel route which currently just listens on a vm endpoint. Each feature has the same  bundle and overrides the name of the endpoint using config admin.

      This is being done to validate the deployment mechanism.

       

      Here are the two features:

       

            

       

      I can install both features, and the bundle is activated and started as seen in the output of the list command: (It only shows up once)

       

      features:list output

      jms-sr-comp1                          fuse-poc                          

      jms-sr-comp2                          fuse-poc   

       

      osgi:list output

      com.foo.poc.fuse.fuse-dyna-route (1.0.0.SNAPSHOT)

       

      It appears that the route in the first feature installed is actually started. The second one is not running.

       

      I can also see the config using config:list, but only from the first feature loaded.

       

      I know this works if I use FMC, Fabric and Profiles. How do I get this to work using features directly?

        • 1. Re: Deploying features using <config> to set different property values for each
          ffang

          Hi,

           

          I don't think you can have multiple instance of  exact same bundle in one OSGi container, so there's only one mvn:com.foo.poc.fuse/fuse-dyna-route/1.0.0-SNAPSHOT get installed and only one property could get picked up.

           

          Freeman

          • 2. Re: Deploying features using <config> to set different property values for each
            plord_plord

            But you can do this using the Profile mechanism from fabric.  I was under the assumption that you could therefore use the feature mechanism without fabric to do the same thing.

            • 3. Re: Deploying features using <config> to set different property values for each
              jrawlings1980

              I don't think you can do this using a single Fabric profile.  You would need to create two profiles with different config admin properties for your configurable endpoints and assign to different containers.

               

              The way we have done this is by using d-osgi and the ESB registry. 

               

              We have multiple instances of the same version bundle but in different lightweight containers.  These bundles expose a service using the same interface with a service property to identify each  implementation.  This property is set using Fabric profiles.

               

              The calling service looks up the required bundle from the registry using d-osgi and a service filter which corresponds to the service property.

               

              This provides loosely coupled services which can be dynamically added and registered within each OSGi registry and in turn the Zookeeper registry.  This also provides a good scalable option as the calling service can randomly use one of a list of services returned by Zookeeper.

               

              I have added some code snippets to hopefully add clarity:

               

              Service Implementation bundle uses Config admin service to set a service property and the different endpoint.

               

              <cm:property-placeholder persistent-id="com.company ">
                   <cm:default-properties>
                        <cm:property name="identifier.key" value="0"></cm:property>
                        <cm:property name="endpoint" value="activemq:somewhere"></cm:property>
                   </cm:default-properties>
              </cm:property-placeholder>
              
              <service ref="myService" auto-export="interfaces">
                   <service-properties>
                        <entry key="service.exported.interfaces" value="*"></entry>
                        <entry key="identifier.key" value="${identifier.key}"></entry>
                   </service-properties>
              </service>
              
              <endpoint uri="{{endpoint}}" id="myEndpoint"></endpoint>
              
              <route id="myRoute">
              <from uri="somewhere"></from>
              <to ref="myEndpoint"></to>
              </route>

               

              Calling service in Java DSL so we can dynamically lookup multiple instances matching the same filter and load balance between them.  Not sure if this is possible in XML DSL.

               

              String indentifyingKey = request.getIdentifyingKey();
              String filter = "(identifier.key=" + indentifyingKey + ")";
              BundleContext bundleContext = FrameworkUtil.getBundle(MyServiceCaller.class).getBundleContext();
              
              Collection<ServiceReference<MyService>> serviceReferences =
                   bundleContext.getServiceReferences(MyService.class, filter);
              
              LOGGER.debug("Found ["+ serviceReferences.size() +"]  my service(s) for: " + indentifyingKey);
              
              ServiceReference<MyService> serviceReference = (ServiceReference<MyService>) getRandomService(serviceReferences.toArray());
              
              MyService myService = bundleContext.getService(serviceReference);

               

               

              Example fabric profiles...

               

               

              fabric:profile-create --parents mq-base --parents default --parents dosgi --parents camel my-profile
              fabric:profile-edit -r mvn:org.fusesource.esb/fuse-esb/7.0.2.fuse-097/xml/features my-profile
              fabric:profile-edit -r mvn:com.company/my-features/1.0-SNAPSHOT/xml/features my-profile
              fabric:profile-edit --features jms-sr-comp1 my-profile
              fabric:profile-edit --pid com.company/identifier.key=1 my-profile
              fabric:profile-edit --pid com.company/endpoint=jms-sr-comp1 my-profile
              fabric:container-create --parent root --profile my-profile my-server-1
              
              fabric:profile-create --parents mq-base --parents default --parents dosgi --parents camel my-profile
              fabric:profile-edit -r mvn:org.fusesource.esb/fuse-esb/7.0.2.fuse-097/xml/features my-profile
              fabric:profile-edit -r mvn:com.company/my-features/1.0-SNAPSHOT/xml/features my-profile
              fabric:profile-edit --features jms-sr-comp1 my-profile
              fabric:profile-edit --pid com.company/identifier.key=2 my-profile
              fabric:profile-edit --pid com.company/endpoint=jms-sr-comp2 my-profile
              fabric:container-create --parent root --profile my-profile my-server-2

               

              I would appreciate peoples thoughts on this.

               

              Thanks, James.

              • 4. Re: Deploying features using <config> to set different property values for each
                ffang

                Hi,

                 

                Yeah, leverage fabric to deploy it on different container is the way to go, that said, same bundle with different configuration is possible on different containers.

                 

                Freeman

                • 5. Re: Deploying features using <config> to set different property values for each
                  plord_plord

                  After much testing I have come to the conclusion that the profile mechanism to deploy the same bundle to the same container with a different config is not possible. In order to do this, the  bundle name needs to be changed.

                   

                  Of course deploying the same bundle to different containers is always possible.