2 Replies Latest reply on Dec 3, 2015 6:40 PM by tiago.matias

    How to define the PID for a bundle ?

    tiago.matias

      Hello,

       

      I'm trying to configure a feature repository with included configuration entries. The idea is to have a base feature with my two bundles and then a Quality and Production features that inherit the base feature and specify the properties for the services. Here's my starting point:

       

      <features name="foo-hub-features">

          <feature name="foo-hub-base-feature" version="${project.version}" description="Base bundles" resolver="(obr)">

              <bundle>mvn:pt.foo.hub/mysql-service/${project.version}</bundle>

              <bundle>mvn:pt.foo.hub/tele-underwriting-service/${project.version}</bundle>

          </feature>

       

          <feature name="foo-hub-qa-feature" version="${project.version}"

              description="QA configuration for the base feature" resolver="(obr)">

              <feature>foo-hub-base-feature</feature>

              <config name="pt.foo.hub.tuw-service">

                  tuw_service_endpoint=http://localhost:9090/b2b/foo/tuw

              </config>

       

              <!-- Specific configuration for the mysql service

              <config name="pt.foo.hub.mysql-service">

                  hostName=192.168.1.10

                  database=qaDatabase

              </config>

          </feature>

       

          <feature name="foo-hub-prod-feature " version="${project.version}"

              description="Production configuration for the base future" resolver="(obr)">

              <feature>foo-hub-base-feature</feature>

              <config name="pt.foo.hub.mysql-service">

                  hostName=192.168.1.99

                  database=superDatabase

              </config>

          </feature>

       

      </features>

       

      This installs perfectly on fuse 6.2. I created two profiles (QA+PROD) and assigned each feature to a particular profile. The profles are then assigned to a container.  However the services cannot find the configuration properties.

       

      This is the bundle-context.xml for one of the services (mysql service):

       

      <!-- namespaces removed for clarity -->

      <beans>

          <osgix:cm-properties id="cmProps" persistent-id="pt.foo.hub.mysql-service">

              <prop key="hostName">127.0.0.1</prop>

              <prop key="database">dummyDb</prop>

          </osgix:cm-properties>

          <ctx:property-placeholder properties-ref="cmProps" />

          <osgi:service auto-export="all-classes" ref="mysqlService" />

      </beans>

       

      And the bundle-context-osgi.xml:

       

      <!-- namespaces removed for clarity -->

        <bean id="mysqlService" class="pt.foo.hub.mysql_service.MysqlService">

          <property name="hostname" value="${hostName}"/>

          <property name="database" value="${database}"/>

        </bean>

      </beans>

      Howver the service fails because It cannot find those properties. Checking the console I got this:

       

      Pid:            service.f3840d63-aca7-46ae-b8ee-5ef0f70566db

      FactoryPid:     service

      BundleLocation: null

      Properties:

         database= qaDatabase

         hostFH = 192.168.1.10

         org.apache.karaf.features.configKey = pt.foo.hub.mysql-service

         service.factoryPid = service

         service.pid = service.f3840d63-aca7-46ae-b8ee-5ef0f70566db

       

      Obviously something is missing because the FactoryPid is set to "service" when it should be something like: "pt.foo.hub.mysql-service". Actually both my two bundles have the same FactoryPID.

       

      What am I missing? I feel that it must be something terribly simple and obvious!

       

      By the way, my POM is (simplified):

       

      <?xml version="1.0" encoding="UTF-8"?>

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

       

          <parent>

              <groupId>pt.foo.configs</groupId>

              <artifactId>foo-configs</artifactId>

              <version>2.0-SNAPSHOT</version>

              <relativePath>../configs/pom.xml</relativePath>

          </parent>

       

          <modelVersion>4.0.0</modelVersion>

          <groupId>pt.foo.hub</groupId>

          <artifactId>mysql-service</artifactId>

          <packaging>bundle</packaging>

          <name>Mysql Service</name>

       

          <dependencies>

              <dependency>

                  <groupId>mysql</groupId>

                  <artifactId>mysql-connector-java</artifactId>

                  <version>${mysql.version}</version>

              </dependency>

              <dependency>

                  <groupId>commons-dbcp</groupId>

                  <artifactId>commons-dbcp</artifactId>

                  <version>1.4</version>

              </dependency>

          </dependencies>

       

       

          <build>

              <resources>

                  <resource>

                      <directory>src/main/resources</directory>

                  </resource>

                  <resource>

                      <directory>src/main/java</directory>

                      <includes>

                          <include>plugin.xml</include>

                          <include>META-INF/*</include>

                      </includes>

                  </resource>

              </resources>

       

              <plugins>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-compiler-plugin</artifactId>

                      <version>${maven-compiler-plugin.version}</version>

                      <configuration>

                          <encoding>${project.build.sourceEncoding}</encoding>

                          <source>${java.version}</source>

                          <target>${java.version}</target>

                      </configuration>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-resources-plugin</artifactId>

                      <version>${maven-resources-plugin.version}</version>

                  </plugin>

       

                  <plugin>

                      <groupId>org.apache.felix</groupId>

                      <artifactId>maven-bundle-plugin</artifactId>

                      <version>${maven-bundle-plugin.version}</version>

                      <extensions>true</extensions>

                      <configuration>

                          <obrRepository>NONE</obrRepository>

                          <manifestLocation>META-INF</manifestLocation>

                          <instructions>

                              <Export-Package>

                                  !pt.foo.hub.mysql_service.internal,

                                  pt.foo.hub.mysql_service*,

                                  org.apache.commons.dbcp.*

                              </Export-Package>

                              <Import-Package>

                                  !org.apache.commons.jocl*,

                                  !org.apache.commons.dbcp*,

                                  !pt.foo.hub.mysql_service*,

                                  *

                              </Import-Package>

                              <Include-Resource>src/main/resources</Include-Resource>

                              <DynamicImport-Package>*</DynamicImport-Package>

                          </instructions>

                      </configuration>

                  </plugin>

              </plugins>

          </build>

      </project>

       

      Thanks for any help

        • 1. Re: How to define the PID for a bundle ?
          tiago.matias

          By the way, I forgot to mention that the feature appears correct:

           

          JBossFuse:admin@root> features:info  foo-hub-qa-feature
          Description of foo-hub-qa-feature 2.0-SNAPSHOT feature
          QA configuration for the base feature
          ----------------------------------------------------------------
          Feature configuration:
            pt.foo.hub.tuw-service
            pt.foo.hub.mysql-service
          Feature has no configuration files
          Feature depends on:
            foo-hub-base-feature 0.0.0
          Feature has no bundles.
          Feature has no conditionals.
          
          • 2. Re: How to define the PID for a bundle ?
            tiago.matias

            I managed to solve this problem. Turns out, that '-' character in the PID is invalid (pt.foo.hub.mysql-service).