Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to add external data source when I develop my plugin?

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Hi all,

Where, I put my external data source when I develop my plugin.

11 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2014

Hi all,

Thanks for your responses.

I have resolved it like this:

I have changed the jira connexion database in the dbconfig.xml with an external data base and I have used the data base existing in the file context.xml located in this directory my_plugin_home\target\container\tomcat6x\cargo-jira-home\conf.

0 votes
Kul August 12, 2015

I agree with Boris, You can create jndi external datasource as described here using the confluence sdk.

https://developer.atlassian.com/docs/developer-tools/declaring-jndi-datasources-in-amps

Just add in your pom.xml like i did for SDK version 5.8.6.

    <build>
        <plugins>
            <plugin>
               
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-amps-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <instanceId>instanceId1</instanceId>
                    <products>
                        <product>
                            <id>confluence</id>
                            <instanceId>instanceId1</instanceId>
                            <version>${confluence.version}</version>
                            <dataPath>src/main/resources/empty-home</dataPath>
                            <dataSources>
                                <dataSource>
                                    <jndi>jdbc/DefaultDS</jndi>
                                    <url>jdbc:postgresql://localhost:5432/confluence</url>
                                    <username>confluence</username>
                                    <password>confluence</password>
                                    <driver>org.postgresql.Driver</driver>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>postgresql</groupId>
                                            <artifactId>postgresql</artifactId>
                                            <version>9.1-901-1.jdbc4</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </dataSource>
                                <dataSource>
                                    <jndi>jdbc/externalDataSource</jndi>
                                    <url>jdbc:oracle:thin:@host:1525:dbname</url>
                                    <username>SCHEMA</username>
                                    <password>PASSWORD</password>
                                    <driver>oracle.jdbc.OracleDriver</driver>
                                    <libArtifacts>
                                        <libArtifact>
                                            <groupId>com.oracle</groupId>
                                            <artifactId>ojdbc6</artifactId>
                                            <version>11.2.0</version>
                                        </libArtifact>
                                    </libArtifacts>
                                </dataSource>
                            </dataSources>
                        </product>
                    </products>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-confluence-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>

                <configuration>
                    <productVersion>${confluence.version}</productVersion>
                    <productDataVersion>${confluence.data.version}</productDataVersion>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <confluence.version>5.8.6</confluence.version>
        <confluence.data.version>5.8.6</confluence.data.version>
        <amps.version>5.0.13</amps.version>
        <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
    </properties>

 

You might need to clean up your m2 if you are playing with versions. altas-clean and then atlas-run will run the same for you. Hope it will help.

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

You can declare datasource in the pom.xml as described here https://developer.atlassian.com/display/DOCS/Declaring+JNDI+Datasources+in+AMPS

0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Then configure context.xml as explained here http://confluence.kepler-rominfo.com/display/DBCF/Data+Source+Configuration

(don't forget the jdbc driver)

And use the sample code here when the plugin needs the connection:

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Oracle_8i,_9i_&_10g

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Hi thanks for reponse,

I have seen this before asked this question (liked it) and I have did this ClassLoader origCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ComponentManager.class.getClassLoader());
//::TODO:: do lookup here
} finally {
Thread.currentThread().setContextClassLoader(origCL);

}

(I develop a rest plugin) and it work fine when I execute this

InitialContext iContext = new InitialContext();

Context context = (Context) iContext.Lookup("java:com/emp");

DataSource dataSource = (DataSource) context.lookup("jdbc/JiraDS");

System.out.println(dataSource.toString()) return this : org.apache.tomcat.dbcp.BasicDataSource@16e5841.

but when I put in context.lookup("jdbc/MyExternalDataBase") it return an exception

I think that I have not asked question correctly .

So my problem :

Where I put my data source to browse It (file) when I develop my plugin ?

I have tried to put It in this file

Myplugin_home\target\container\tomcat6x\cargo-jira-home\conf\context.xml and It's produced an error



RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

@Alexalready mentioned in his comment to this question, you ned to configure JNDI in server.xm/context.xml as follows

&lt;Resource name="jdbc/MyExternalDataBase" auth="Container" type="javax.sql.DataSource"
	 maxActive="15" maxIdle="100" maxWait="90000"
	removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
	username="username" password="password" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
	url="jdbc:sqlserver://;serverName=severname.com;databaseName=test"/&gt;

don't forgot to change username, password and server name, after this changes you need to restart server

then you can access jndi on your plugin as you specified above

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

@rambanam prasad

in which directory, I do this changes?

MY_Plugin_Home\Target\...

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

you need to add above code in jira server not in plugin code!

go to the conf folder in jira installation directory(../JIRA/conf/server.xml)

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

@rambanam prasad

My need is to connect my plugin when I develop It to do some tests not after installation or It's not possible?

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

then you need to use JDBC to connect external DB, you can get sample code here

http://www.tutorialspoint.com/jdbc/jdbc-sample-code.htm

Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2014

This is not exactly my need, but I accept this answer because it allowed me to review the use of JDBC.

0 votes
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Hi, @Alex Perez

Yes, That's what I want.

0 votes
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Thanks for yours answers

Just I explain you more:

I would to find my data source in context.xml when Iuse It in production.

0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Well,

you can define the DS in context.xml, but then the plugin must call jndi to locate it.

Note that if you use context.xml tomcat will manage the DS pool and the driver must be deployed to lib/ folder instead of packed with the driver.

0 votes
rambabu patina
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014
0 votes
Alex Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Hi zezeto,

Ive recently developed a plugin that uses a external mysql db :)

The plugin loads the datasource configuration from a properties, located in the JIRA_HOME folder. From the plugin code, the datasource access to the properties with:

try {
		log.debug("loading driver");
		Class.forName("com.mysql.jdbc.Driver");
		log.debug("loading properties in JIRA_HOME ...");
		Properties connectionProps = new Properties();
		File jiraHome = ComponentAccessor.getComponent(JiraHome.class).getHome();
		File propertyFile = new File(jiraHome, "CMDB.properties");
		FileInputStream stream = new FileInputStream(propertyFile);
		connectionProps.load(stream);
		log.debug("getting connection ...");
		this.conn = DriverManager.getConnection(connectionProps.getProperty("url"), connectionProps);
} catch (Exception e) {
		log.debug("error connecting to CMDB: " + e.getMessage());
}
log.debug("connection initialized.");

Driver is included in pom.xml as dependency, so is embeded in the resulting plugin jarfile.

HTH

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events