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;
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);
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
Thanks for the article.
I want to read more.
Hope to learn from you all.
Welcome to ODI World Lin. Have fun
where i put this code
Hi Bhabani,
i want to fetch model and project mapping and run that , in java code like i have a UI there i will select models and select project and run from the UI , can you help me out how i will do that from , i am developing ODI plugins ,
Thanks
Saroj
Email – Gpkumar9437@gmail.com