GoldenGate and Oracle Data Integrator - A Perfect Match in 12c... Part 3: Setup Journalizing
After a short vacation, some exciting news, and a busy few weeks (including KScope14 in Seattle, WA), it's time to get the "GoldenGate and Oracle Data Integrator - A Perfect Match in 12c" blog series rolling again. Hopefully readers can find some time between World Cup matches to try integrating ODI and GoldenGate on their own!
To recap my previous two posts on this subject, I first started by showing the latest Information Management Reference Architecture at a high-level (described in further detail by Mark Rittman) and worked through the JAgent configuration, necessary for communication between ODI and GoldenGate. In the second post, I walked through the changes made to the GoldenGate JKM in ODI 12c and laid out the necessary edits for loading the Foundation layer at a high-level. Now, it's time to make the edits to the JKM and set up the ODI metadata.
Before I jump into the JKM customization, let's go through a brief review of the foundation layer and its purpose. The foundation schema contains tables that are essentially duplicates of the source table structure, but with the addition of the foundation audit columns, described below, that allow for the storage of all transactional history in the tables.
FND_SCN (System Change Number)
FND_COMMIT_DATE (when the change was committed)
FND_DML_TYPE (DML type for the transaction: insert, update, delete)
The GoldenGate replicat parameter file must be setup to map the source transactions into the foundation tables using the INSERTALLRECORDS option. This is the same option that the replicat uses to load the J$ tables, allowing only inserts and no updates or deletes. A few changes to the JKM will allow us to choose whether or not we want to load the Foundation schema tables via GoldenGate.
Edit the Journalizing Knowledge Module
To start, make a copy of the "JKM Oracle to Oracle Consistent (OGG Online)" so we don't modify the original. Now we're ready to make our changes.
Add New Options
A couple of new Options will need to be added to enable the additional feature of loading the foundation schema, while still maintaining the original JKM code. Option values are set during the configuration of the JKM on the Model, but can also have a default in the JKM.
APPLY_FOUNDATION
This option, when true, will enable this step during the Start Journal process, allowing it to generate the source-to-foundation mapping statement in the Replicat (apply) parameter file.
FND_LSCHEMA
This option will be set with Logical Schema name for the Foundation layer, and will be used to find the physical database schema name when output in the GoldenGate replicat parameter file.
Add a New Task
With the options created, we can now add the additional task to the JKM that will create the source to foundation table mappings in the GoldenGate replicat parameter file. The quickest way to add the task is to duplicate a current task. Open the JKM to the Tasks tab and scroll down to the "Create apply prm (3)" step. Right click the task and select Duplicate. A copy of the task will be created and in the order that we want, just after the step we duplicated.
Rename the step to “Create apply prm (4) RM”, adding the additional RM tag so it's easily identifiable as a custom step. From the properties, open the Edit Expression dialog for the Target Command. The map statement, just below the OdiOutFile line, will need to be modified. First, remove the IF statement code, as the execution of this step will be driven by the APPLY_FOUNDATION option being set to true.
Here's a look at the final code after editing.
map <%= odiRef.getObjectName("L", odiRef.getJrnInfo("TABLE_NAME"), odiRef.getOggModelInfo("SRC_LSCHEMA"), "D") %>, TARGET <%= odiRef.getSchemaName("" + odiRef.getOption("FND_LSCHEMA") + "","D") %>.<%= odiRef.getJrnInfo("TABLE_NAME") %>, KEYCOLS (<%= odiRef.getColList("", "[COL_NAME]", ", ", "", "PK") %>, FND_SCN)<%if (!odiRef.getOption("NB_APPLY_PROCESS").equals("1")) {%>, FILTER (@RANGE(#ODI_APPLY_NUMBER,<%= nbApplyProcesses %>,<%= odiRef.getColList("", "[COL_NAME]", ", ", "", "PK") %>))<% } %> INSERTALLRECORDS, COLMAP ( USEDEFAULTS, FND_COMMIT_DATE = @GETENV('GGHEADER' , 'COMMITTIMESTAMP'), FND_SCN = @GETENV('TRANSACTION' , 'CSN'), FND_DML_TYPE = @GETENV('GGHEADER' , 'OPTYPE') );
The output of this step is going to be a mapping for each source-to-foundation table in the GoldenGate replicat parameter file, similar to this:
map PM_SRC.SRC_CITY, TARGET EDW_FND.SRC_CITY, KEYCOLS (CITY_ID, FND_SCN) INSERTALLRECORDS, COLMAP ( USEDEFAULTS, FND_COMMIT_DATE = @GETENV('GGHEADER' , 'COMMITTIMESTAMP'), FND_SCN = @GETENV('TRANSACTION' , 'CSN'), FND_DML_TYPE = @GETENV('GGHEADER' , 'OPTYPE') );
The column mappings (COLMAP clause) are hard-coded into the JKM, with the parameter USEDEFAULTS mapping each column one-to-one. We also hard-code each foundation audit column mapping to the appropriate environment variable from the GoldenGate trail file. Learn more about the GETENV GoldenGate function here.
The bulk of the editing on this step is done to the MAP statement. The out-of-the-box JKM is setup to apply transactional changes to both the J$, or change table, and fully replicated table. Now we need to add the mapping to the foundation table. In order to do so, we first need to identify the foundation schema and table name for the target table using the ODI Substitution API.
map ... TARGET <%= odiRef.getSchemaName("" + odiRef.getOption("FND_LSCHEMA") + "", "D") %> ...
The nested Substitution API call allows us to get the physical database schema name based on the ODI Logical Schema that we will set in the option FND_LSCHEMA, during setup of the JKM on the ODI Model. Then, we concatenate the target table name with a dot (.) in between to get the fully qualified table name (e.g. EDW_FND.SRC_CITY).
... KEYCOLS (<%= odiRef.getColList("", "[COL_NAME]", ", ", "", "PK") %>, FND_SCN) ...
We also added the FND_SCN to the KEYCOLS clause, forcing the uniqueness of each row in the foundation tables. Because we only insert records into this table, the natural key will most likely be duplicated numerous times should a record be updated or deleted on the source.
Set Options
The previously created task, “Create apply prm (4) RM”, should be set to execute only when the APPLY_FOUNDATION option is "true". On this step, go to the Properties window and choose the Options tab. Deselect all options except APPLY_FOUNDATION, and when Start Journal is run, this step will be skipped unless APPLY_FOUNDATION is true.
Edit Task
Finally, we need to make a simple change to the “Execute apply commands online” task. First, add the custom step indicator (in my example, RM) to the end of the task name. In the target command expression, comment out the “start replicat …” command by using a double-dash.
--start replicat ...
This prevents GoldenGate from starting the replicat process automatically, as we’ll first need to complete an initial load of the source data to the target before we can begin replication of new transactions.
Additional Setup
The GoldenGate Manager and JAgent are ready to go, as is the customized "JKM Oracle to Oracle Consistent (OGG Online)" Journalizing Knowledge Module. Now we need to setup the Topology for both GoldenGate and the data sources.
Setup GoldenGate Topology - Data Servers
In order to properly use the "online" integration between GoldenGate and Oracle Data Integrator, a connection must be setup for the GoldenGate source and target. These will be created as ODI Data Servers, just as you would create an Oracle database connection. But, rather than provide a JDBC url, we will enter connection information for the JAgent that we configured in the initial post in the series.
First, open up the Physical Architecture under the Topology navigator and find the Oracle GoldenGate technology. Right-click and create a new Data Server.
Fill out the information regarding the GoldenGate JAgent and Manager. To find the JAgent port, browse to the GG_HOME/cfg directory and open "Config.properties" in a text viewer. Down towards the bottom, the "jagent.rmi.port", which is used when OEM is enabled, can be found.
#################################################################### ## jagent.rmi.port ### ## RMI Port which EM Agent will use to connect to JAgent ### ## RMI Port will only be used if agent.type.enabled=OEM ### #################################################################### jagent.rmi.port=5572
The rest of the connection information can be recalled from the JAgent setup.
Once completed, test the connection to ensure all of the parameters are correct. Be sure to setup a Data Server for both the source and target, as each will have its own JAgent connection information.
Setup GoldenGate Topology - Schemas
Now that the connection is set, the Physical Schema for both the GoldenGate source and target must be created. These schemas tie directly to the GoldenGate process groups and will be the name of the generated parameter files. Under the source Data Server, create a new Physical Schema. Choose the process type of "Capture", provide a name (8 characters or less due to GoldenGate restrictions), and enter the trail file paths for the source and target trail files.
Create the Logical Schema just as you would with any other ODI Technology, and the extract process group schema is set.
For the target, or replicat, process group, perform the same actions on the GoldenGate target Data Server. This time, we just need to specify the target trail file directory, the discard directory (where GoldenGate reporting and discarded records will be stored), and the source definitions directory. The source definitions file is a GoldenGate representation of the source table structure, used when the source and target table structures do not match. The Online JKM will create and place this file in the source definitions directory.
Again, setup the Logical Schema as usual and the connections and process group schemas are ready to go!
The final piece of the puzzle is to setup the source and target data warehouse Data Servers, Physical Schemas, and Logical Schemas. Use the standard best practices for this setup, and then it's time to create ODI Models and start journalizing. In the next post, Part 4 of the series, we'll walk through applying the JKM to the source Model and start journalizing using the Online approach to GoldenGate and ODI integration.