Playing with ODI and Groovy – Part 4 – Exporting/Importing ODI Scenarios with SDK

Hi all, I’m back with the continuation of this Groovy and ODI series. Last post we saw how to find the different scenarios between two environments. Today we will look on how we may export those different scenarios from our source repository and how to import them in our target repository. We will do a two-step operation: first we will export the different ODI objects from our source repository as XML files into a folder and then we will import those xml files into our target repository.
Our code is very similar to the one that we did for post 3, but we will need to enhance it a little bit. First thing that we will have to change in our code is the function that creates the list of objects. In the previous post, we were just adding the name of the scenarios to the list. Now we will need to store the object itself in the list, since we will need to have the ODI object (scenario) to have it exported.

Also, we will need to create a variable that will indicate the path where the objects will be temporarily exported.

exportPath = "C:\\Odi"

One import thing that we will need to change is how to compare the objects. In the previous post, we were simply comparing them, as they were strings, which was ok for our propose there. However, now we cannot simple compare the java objects because they will be different even if they represent the same scenario name/version. They are considered “different” because they came from different environments and logically, they represent different ODI entities.

I’m basically doing three tests to see if the source scenario will be migrated or not: first I compare its name, than its version and finally if its name starts with TEST (this last step does not need to be done if you want to get the complete scenario list). Next step I just print the scenarios names and versions that will be exported/imported:

Export objects in ODI SDK is very straight forward: you need to inform which scenarios you want to export (in our case, all objects that were stored in diffScenarios array), the path where the object will be exported and the encode option that will be used. In this case, I just went ahead with the default encode options.

Importing objects is also easy, but similarly to a database, you need to explicitly commit your actions to make it effective in the target repository. Also, for the sake of simplicity, we will import all new scenarios under “root”, but we could explicitly say under which ODI objects we would want to have it imported to:

Can you help me with the code where i can export the scenarios separately and put them all on a location and a another groovy script which import all the scenarios placed on that location . i need these two scripts separately. email id:rajeshsaini47@gmail.com

If I use the option to import UPDATE I get the error “ODI-10035: SNP_SCEN:” XXXX 001 “(with internal id: 10178101) violates the alternative key constraint AK_SNP_SCEN (SCEN_NAME, SCEN_VERSION) for the values ​​…”

My solution is to go one by one, right click on the stage and “import replacement/substituition”

Got it. I dont know if this option exists in the SDK, I would need to do some research. Just to confirm, you are trying to update one ODI scenario with the same version number correct? In other words, you already have ODI scenario 001 and you want to import/replace the same 001 in the other environment, correct? I had so many issues with those kind of imports in the past that right now I’m a very big fan of increasing version numbers. In all my projects I increase the version number anytime that I need to migrate something (like 1_00_00, 1_00_01 and so on), so I never run on this AK constraints situations.

I never used, but I checked the documentation and it says three input parameters. Please be aware that it is not strings. It is a OdiScenario object, a String and a Boolean. Maybe you are trying to pass only the String instead of the OdiScenario object.