Scheduling in ODI using SDK

Scheduling in ODI using SDK:

After a long time am gonna write something about ODI SDK. I got a request from Kane in otn forum about scheduling in ODI without taking the help of ODI Studio. Well that’s obvious, requirement may come in different ways. So initially I was digging around the package provided by Oracle ( oracle.odi.domain.runtime.scheduling ). I tried to see my odi-core.jar file and didn’t find this package. Thats strange !! Right ? I spent around 2 hours and just left it because of some other work.

But today I found the problem and it was with the wrong version of jar file. I was using the odi-core.jar that belongs to  version 11.1.1.5  and the above package was added in 11.1.1.6.  So I just copied the jar file to ODI 11.1.1.5  \oracledi.sdk\lib directory and bounced the agent.

Then I found an unexpected result and ended up with below message.

Exception in thread “main” java.lang.NoSuchMethodError: org.eclipse.persistence.mappings.OneToManyMapping.setMustDeleteReferenceObjectsOneByOne(Ljava/lang/Boolean;)V

Okay it seems that it is something related to the version mismatch. Probably its the time to  install 11.1.1.6 version. After installing I started the agent and this time the agent was successful. 🙂  Fine, lets get to the issue on our hand. Following is the code snippet that I have wrote on my eclipse. This will create the scheduling for a specified time. Note that your agent should be up.

Scenario name is : PKG_ROUTER , Agent name is : ODIAgent1  and Context is : GLOBAL

package com.bhabani.OdiTool;

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.config.WorkRepositoryDbInfo;
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.runtime.scenario.OdiScenario;
import oracle.odi.domain.runtime.scenario.OdiScenarioSchedule;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder;
import oracle.odi.domain.runtime.scheduling.*;
import oracle.odi.domain.runtime.scheduling.RecurrenceAttributes.DayOfMonth;
import oracle.odi.domain.runtime.scheduling.RecurrenceAttributes.TimeOfDay;
import oracle.odi.runtime.agent.invocation.RemoteRuntimeAgentInvoker;

public class ScenSchedule {
public static void main(String[] args) {
String Url = "jdbc:oracle:thin:@localhost:1521:xe";
String Driver="oracle.jdbc.OracleDriver";
String Master_User="ODI_MASTER2";
String Master_Pass="odimaster2";
String WorkRep="WORKREP91";
String Odi_User="SUPERVISOR";
String Odi_Pass="SUNOPSIS";

MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes());
WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(WorkRep, new PoolingAttributes());
OdiInstance odiInstance=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo));
Authentication auth = odiInstance.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray());
odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth);
ITransactionStatus trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition());

RemoteRuntimeAgentInvoker agent = new RemoteRuntimeAgentInvoker("http://localhost:20910/oraclediagent", "SUPERVISOR", "SUNOPSIS".toCharArray());

OdiScenario odiscen= ((IOdiScenarioFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiScenario.class)).findLatestByName("PKG_ROUTER");

OdiSchedule schedule = new OdiScenarioSchedule(odiscen, "GLOBAL", "ODIAgent1");
Recurrence monthlyRecurrence = Recurrence.createMonthlyRecurrence(new DayOfMonth(12), new TimeOfDay(21,25,00));
Period repetitionInterval = new Period(2, TimeUnit.MINUTE);
Repetition repetition = new Repetition(2, null, repetitionInterval);
schedule.setRecurrence(monthlyRecurrence);
schedule.setRepetition(repetition);
odiInstance.getTransactionalEntityManager().persist(schedule);
odiInstance.getTransactionManager().commit(trans);
try{
agent.invokeUpdateSchedules();
}
catch(Exception e){
System.out.println(e.getMessage());
}
odiInstance.close();
}
}

When you will run this program you will see below message in the console palette.

Now lets verify the same in ODI Studio.  Do  quick refresh and you can see the schedule information.

odisdk_schedule1
What about update agent? Lets click on view schedule.
odisdk_schedule2
Yes there it is :D. This will now run in the specified time as long as the agent is up.

 

Thats all. Thanks everybody for your support.

Best Regards
Bhabani

0

About the author

Bhabani(http://dwteam.in) - Currently Bhabani is working as Sr Development Engineer at Harman International. He has good expertise on Oracle, Oracle Data Integrator, Pervasive Data Integrator, MSBI, Talend and Java. He is also contributing in ODI-OTN forum for last 5 years. He is from India. If you want to reach him then please visit contact us 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.

Similar Posts

3 comments

Can you please let me know if I have to set variables for this scheduler, how this can be achieved.

Great Bhabani. Is there any way I can get the existing schedules of a Scenario and set to INACTIVE.

Hi Bhabani,

Liked your post. I am new to ODI SDK , i am currently trying to generate the ODI scenario using ODI SDK. i have placed all required jar from oracledi.sdk folder to the eclipse Java path. but still i am getting below error :

The Jar odi-core.jar has no source attachment.

have used Java code to generate the scenario :

OdiProject project=new OdiProject(“TEST”,”TEST”);
OdiFolder folder=new OdiFolder(project,”First Folder”);
OdiContext context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode(“GLOBAL”);
OdiPackage pPackage=new OdiPackage(folder,”TEST”);

OdiInterface intf=new OdiInterface(folder,”OdiInterface”,context);
OdiScenario newScen = gene.generateScenario(intf, “MYSCENERIO”, “001”);

if you have any idea about the above issue, kindly provide your input. it will be really helpful.

Leave a reply

required*

Are you a human? *