Sie sind auf Seite 1von 5

8/8/2015 Create Agent in ODI using SDKDW Team

Welcome to DWTeam  
Sat, 08 Aug 2015   

Home
ODI
Java
Open Discussion
Contact Me

Today's Popular Articles and Posts:

How to set jdk path in windows 7
Lookup in ODI 11g
OpenTool in ODI using Java

Configure ODI 11g Local Agent
Rename All Files in a Directory
Transaction Control in ODI

Search

Home  »  ODI  »  Create Agent in ODI using SDK

Create Agent in ODI using SDK:

Tuesday, January 22, 2013, 9:26
ODI  [3 comments]

Create Agent in ODI using SDK:

More on SDK !!  Here is the code to create physical agent as well as logical agent in ODI . Thanks to Oracle for giving such flexibility. One thing which
i want to share with you is, whenever i do anything in ODI Studio, I always think of making in ODI SDK. Yes its quite interesting and you should have
time to research on this.

import oracle.odi.core.OdiInstance;
import oracle.odi.core.config.MasterRepositoryDbInfo;
import oracle.odi.core.config.OdiInstanceConfig;
import oracle.odi.core.config.PoolingAttributes;

http://dwteam.in/create­agent­in­odi­using­sdk/ 1/5
8/8/2015 Create Agent in ODI using SDKDW Team
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
import oracle.odi.core.security.Authentication;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.OdiContextualAgentMapping;
import oracle.odi.domain.topology.OdiLogicalAgent;
import oracle.odi.domain.topology.OdiPhysicalAgent;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.domain.topology.finder.IOdiLogicalAgentFinder;
import oracle.odi.domain.topology.finder.IOdiPhysicalAgentFinder;

public abstract class CreateAgentSample
{
public static void main(String[] args)
{
String masterJdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
String masterDriver = "oracle.jdbc.OracleDriver";
String masterUserName = "odi_master2";
String masterPassword = "odimaster2";
String odiUserName = "SUPERVISOR";
String odiPassword = "SUNOPSIS";
String host="localhost";
int hostport=20912;
String protocol="HTTP";
String physicalAgentName="OracleDIAgent1";
String logicalAgentName="OracleDIAgent1";
String applicationContext="oraclediagent";
boolean status=false;

MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(masterJdbcUrl, masterDriver, masterUserName, masterPassword.toCharArray(), new
PoolingAttributes());
OdiInstanceConfig config = new OdiInstanceConfig(masterInfo, null, 0);
OdiInstance odiInstance = OdiInstance.createInstance(config);
Authentication auth = odiInstance.getSecurityManager().createAuthentication(odiUserName, odiPassword.toCharArray());
odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth);
ITransactionStatus trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition());

IOdiLogicalAgentFinder logicalAgentFinder = (IOdiLogicalAgentFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiLogicalAgent.class);
OdiLogicalAgent logicalAgentExist = logicalAgentFinder.findByName(logicalAgentName);

if (logicalAgentExist != null) {
System.out.println("agent already exists");
status=true;
}
IOdiPhysicalAgentFinder physicalAgentFinder = (IOdiPhysicalAgentFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiPhysicalAgent.class);
OdiPhysicalAgent physicalAgentExist = physicalAgentFinder.findByName(physicalAgentName);

if (physicalAgentExist != null){
System.out.println("agent already exists");
status=true;
}
if(!status){
try {
OdiPhysicalAgent physicalAgent = new OdiPhysicalAgent(physicalAgentName);
physicalAgent.setApplicationName(applicationContext);
physicalAgent.setHostName(host);
physicalAgent.setHostPort(hostport);
physicalAgent.setProtocol(protocol);
OdiLogicalAgent logicalAgent = new OdiLogicalAgent(logicalAgentName);

http://dwteam.in/create­agent­in­odi­using­sdk/ 2/5
8/8/2015 Create Agent in ODI using SDKDW Team
OdiContext defaultContext= ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findDefaultContext();
OdiContextualAgentMapping mapping = new OdiContextualAgentMapping(defaultContext, logicalAgent, physicalAgent);

odiInstance.getTransactionalEntityManager().persist(physicalAgent);
odiInstance.getTransactionalEntityManager().persist(logicalAgent);
odiInstance.getTransactionalEntityManager().persist(mapping);
odiInstance.getTransactionManager().commit(trans);
System.out.println("Agent creation successful");
}
finally
{
if (odiInstance != null)
{
odiInstance.getSecurityManager().clearCurrentThreadAuthentication();

if (auth != null) {
auth.close();
}
odiInstance.close();
}
}
}
}
}

Output in Console:

Jan 22, 2013 2:48:13 PM org.eclipse.persistence.default
INFO: EclipseLink, version: Eclipse Persistence Services – 2.3.1.v20111018­r10243
Jan 22, 2013 2:48:13 PM org.eclipse.persistence.default
INFO: master­session login successful
Jan 22, 2013 2:48:13 PM org.eclipse.persistence.default
INFO: login successful
Jan 22, 2013 2:48:15 PM org.eclipse.persistence.default
INFO: master­session logout successful
Agent creation successful

Thank You
Bhabani

About the Author

Bhabani has written 61 stories on this site.

http://dwteam.in/create­agent­in­odi­using­sdk/ 3/5
8/8/2015 Create Agent in ODI using SDKDW Team

Currently Bhabani is working as a Consultant at Oracle. He has good expertise on Oracle, Oracle Data Integrator, Pervasive Data Integrator,
SSAS,SSRS and SSIS. He is also contributing in ODI­OTN forum for last 4 years. He is from India. If you want to reach him then please visit contact
me page. If you have any doubts or concerns on the above article, please put your question here. Dw Team will try to respond it as soon as possible.
Also dont forget to provide your comments / suggestions / feedback for further improvement. Thanks for your time.

3 Responses to Create Agent in ODI using SDK

1.   lin says:
July 19, 2013 at 1:35 am

Thanks for the article.
I want to read more.
Hope to learn from you all.

Reply

 Bhabani says:
July 20, 2013 at 3:40 am

Welcome to ODI World Lin. Have fun

Reply

2.   Naila imdad says:
October 3, 2014 at 12:58 pm

where i put this code

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Name * 

Email * 

Website

http://dwteam.in/create­agent­in­odi­using­sdk/ 4/5
8/8/2015 Create Agent in ODI using SDKDW Team

Are you a human?
four −   = 1

Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr
title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code>
<del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Comment

« Create ODI repository using SDK Invoke ODI Scenario using OdiInvokeWebService »
© dwteam.in

Powered by XenataSolutions

http://dwteam.in/create­agent­in­odi­using­sdk/ 5/5

Das könnte Ihnen auch gefallen