1
votes

I have a basic ESB Fuse test project set up with the following modules:

simple-datasource simple-model simple-service

The datasource is configured through blueprint and the datasource attached to jndi:

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

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="simpleDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=xyz))(ADDRESS=(PROTOCOL=TCP)(HOST=xx.xx.xx.xx)(PORT=1521)))" />
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean>

<!--bean id="simpleDataSource" class="oracle.jdbc.driver.OracleDriver">     
    <property name="URL" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=devd))(ADDRESS=(PROTOCOL=TCP)(HOST=10.75.192.195)(PORT=1521)))"/>
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean-->

<service ref="simpleDataSource" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/simpleDataSource" />
    </service-properties>
</service>

The model defines a persistent unit inside persistence.xml file and references the datasource through jndi (notice the long and short jndi lookup defined here, both which I have tried):

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">

<persistence-unit name="simple-service-persistence-unit" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <!--jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/simpleDataSource)</jta-data-source-->
    <jta-data-source>osgi.jndi.service.name=jdbc/simpleDataSource</jta-data-source>
    <!-- list of the persistance classes -->
    <class>com.model.SimpleRow</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>

The SimpleRow class uses JPA annotations:

package com.model;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table;

@Entity @Table(name = "SIMPLE") public class SimpleRow {

@Column(name = "simple_id")
private Long simpleId;

@Column(name = "simple_text", length =100)
private String simpleText;

public Long getSimpleId() {
    return simpleId;
}

public void setSimpleId(Long simpleId) {
    this.simpleId = simpleId;
}

public String getSimpleText() {
    return simpleText;
}

public void setSimpleText(String simpleText) {
    this.simpleText = simpleText;
}

}

I then attempt to inject the EntityManager into a service, again using blueprint and a reference to the simple-service-persistence-unit:

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

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/xmlns/jpa/v1.1.0 http://aries.apache.org/schemas/jpa/jpa_110.xsd">

<bean id="simpleService" class="com.service.SimpleServiceImpl">
    <jpa:context property="entityManager" unitname="simple-service-persistence-unit" />
    <tx:transaction method="*" value="Required" />
</bean>

<service ref="simpleService" interface="com.service.SimpleService" />

Now when I install these modules into the fuse OSGi container the simple-datasource and simple-module both appear to install correctly. Listing these modules gives:

[ 274] [Active     ] [            ] [       ] [   60] Simple Model (1.0.0)
[ 275] [Active     ] [Created     ] [       ] [   60] Simple Datasource (1.0.0)

I created a test jdbc module which used an injected DataSource and this confirmed that the DataSource is working correctly e.g.

public class DbExample {
DataSource dataSource;

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void test() throws Exception {
    Connection con = dataSource.getConnection();
    Statement stmt = null;
    DatabaseMetaData dbMeta = con.getMetaData();
    ....
 }

Now, when I try and start the simple-service, it enters into a grace-period state and the following message is printed to the log file:

2013-07-02 11:05:33,772 | INFO  | e-1.0.0-thread-1 | BlueprintContainerImpl           | ?                                   ? | 8 - org.apache.aries.blueprint.core - 1.0.1.fuse-71-047 | Bundle simple-service is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=simple-service-persistence-unit))(objectClass=javax.persistence.EntityManagerFactory))]

Listing the module state shows it to be in the grace-period state:

[ 277] [Active     ] [GracePeriod ] [       ] [   60] Simple Service Bundle (1.0.0)

It eventually times out and moves into a failure state.

Now my initial thinking was that it could be a broken datasource, but the jdbc module proves that it's working fine. My subsequent thoughts are that the jndi lookup isn't working correctly, although I'm not sure how to check this. Is there any way of viewing the jndi registry? Any other suggestions welcomed.

1
what does ls 275 show?vikingsteve

1 Answers

1
votes

Your bundle is waiting for a service to show up, this might either be an issue because you're referencing a service that isn't available (turn DEBUG logging on and you'll see the details in the log) or what sometimes happens (depending on the underlying version of Karaf/Aries) that you need to switch blueprint to use the synchronized deployment cause sometimes a waiting bundle doesn't catch the later started service. For doing this you need to flip the org.apache.aries.blueprint.synchronous=true in the etc/config.properties file.