Working with Import Rule Sets
You can use Import Rule Sets to customize Object imports.
Creating an Import Rule Set
To create an Import Rule Set:
- Navigate to Configure > Deploy > Import Rule Sets.
-
Click New.
-
Choose a Partition and enter a Name.
- If you want to rename Partitions during import, click the Partition Renames tab and add some Partition renaming rules.
-
If you want the Rule Set to contain one or more import rules, click the Import Rules tab. Click Add to add an import rule, then choose an option from the Object Type dropdown list. The controls below this field change depending on which type of Object you select. See below for details.
-
To specify pre-import, post-import, and post-persist rules, click the Import Action tab.
- Fill in the details and choose the Import Rules Tab.
- Click Save & Close.
Using Import Rule Sets
To use an Import Rule Set during an import:
- Navigate to Configure > Deploy > Imports.
-
Click New.
-
On the Select CAR file screen, select the CAR file you want to import or enter its URL.
-
On the Import Rule Set screen, select the Import Rule Set you want to use.
-
On the Import Details screen, select the import options you want to use.
-
Click Run.
Importing Tables
If you try to import tables that exist in the target system but have different contents (except for the special System_Values table), the import will fail. If you import the System_Values table, rows that are not found in the target system will be appended, but existing rows not be modified during import.
Import Rule Set Parameters
Import Rule Sets accept Parameters that can be set in the following ways:
- In the The properties of the Import Rule Set (
ImportRuleSetProperties
) parameter of System_Import_Archive. - Embedded in the CAR file in
META-INF/ImportRuleSet-parameters.properties
. - On the command line using api-tool.jar.
The Parameters can be retrieved in the Import Rule Set action using the jcsImportRuleSet.getProperty(<name>)
method, where <name>
is the name of the property for which you want to retrieve a value.
Using Embedded Import Rule Sets
You can embed and Import Rule Set in a CAR file by exporting the Import Rule Set and then extracting it out of the CAR file. Set the Name to ImportRuleSet
, the Partition to GLOBAL
, and the Library to GLOBAL.None
. The resulting XML file can be copied into the target CAR file at the following path: META-INF/ImportRuleSet.xml
.
A properties file can also be embedded in the car file and will be used in combination with the Import Rule Set, provided it is located in the CAR file under META-INF/ImportRuleSet-parameters.properties
.
Partition Renaming in Embedded Import Rule Sets
Import Rule Sets embedded in CAR files can specify a Partition variable that can be set in the Import Rule Set action using the ${TargetPartition}
variable. You can specify a default value using the ${TargetPartition}:<default_value>
syntax. If no default value is specified in the Export Rule Set, the parameter is mandatory and must be set (for example) on the command line.
The following excerpt from an Import Rule Set specifies a Partition rename with a default value. When no TragetPartition
variable is set for the Import Rule Set, all Objects will be imported into the DEFAULT_PARTITION
Partition.
<ImportRuleSetPartitionRename>
<ProcessOrder>0</ProcessOrder>
<OldPartition>GLOBAL</OldPartition>
<NewPartition>${TargetPartition:DEFAULT_PARTITION}</NewPartition>
</ImportRuleSetPartitionRename>
Examples
Pre-Import: Hold a Queue Prior to Import
Assume that you want to prepare the environment for the Objects to be imported, and that requires you to hold a Queue (in this example, the Queue named "MSLN_Queue"). To make this happen:
- Navigate to Configure > Automate > Folders.
-
Click New.
- Select the
GLOBAL
Partition. - Enter
Example
into the Name field. - Click Save & Close.
- Navigate to Configure > Deploy > Import Rule Sets.
-
Click New.
- Enter a name.
- Click the Import Action tab.
- Click Pre Import enter fill the code below into the Source field.
- Click Save & Close.
{
Partition p = jcsSession.getPartitionByName("REDWOOD");
Queue q = jcsSession.getQueueByName(p, "MSLN_Queue");
q.hold();
}
Post-Import: Using Import Rules to Change Objects During Import
Assume you want to import a CAR archive containing multiple Job Definitions, and these Job Definitions all have a Parameter named SAP_SYSTEMS
that needs to be assigned a new default value. Assume further that the default value in the CAR file is Q2A, and you want to replace that with PR2 to match the new system. The Parameter CLIENT
also needs to change from 200 to 800. To accomplish this:
- Navigate to Configure > Deploy > Import Rule Sets.
-
Click New.
- Select the
GLOBAL
Partition. - Enter a name.
- Click the Import Rules tab.
- Click Add to create a new import rule.
- Enter
Q2A_TO_PR2
in the Name field and choose Job Definition from the Object Type dropdown list. - In the Matching area, click New next to Parameter and enter the Name
SAP_SYSTEMS
and the Default ExpressionQ2A
. - In the Replaces area, click New next to Parameter and enter the Name
SAP_SYSTEMS
and the Default ExpressionPR2
. - Add an additional import rule.
- Enter
200_TO_800
in the Name field and choose Job Definition from the Object Type dropdown list. - In the Matching area, click New next to Parameter and enter the Name
CLIENT
and the Default Expression200
. - In the Replaces area, click New next to Parameter and enter the Name
CLIENT
and the Default Expression800
. - Click Save & Close.
Post -Import: Using RedwoodScript to Change Objects on Import
The following procedure creates an Import Rule Set that assigns the Example
application to all Objects in an import.
- Navigate to Configure > Automate > Folders.
-
Click New.
- Select the
GLOBAL
Partition. - Enter
Example
into the Name field. - Click Save & Close.
- Navigate to Configure > Deploy > Import Rule Sets
-
Click New.
- Enter a name.
- Click the Import Action tab.
- Click Post Import and enter the code below into the Source field.
- Click Save & Close.
{
Partition part = jcsSession.getPartitionByName("GLOBAL");
Application application = jcsSession.getApplicationByName(part, "Example");
for (Object o : jcsImportRuleSet.getObjects())
{
if (o instanceof ApplicationObject)
{
((ApplicationObject) o).setParentApplication(application);
}
}
}
Post Import: Using RedwoodScript to Repair Missing References
All referenced Objects that are not in the CAR file must be in the target system. If, for example, an application referenced by Objects in the CAR file is neither in the CAR file nor in the target system, that creates an unresolved reference. Unresolved references must be updated via the UnresolvedObjects Map.
- Navigate to Configure > Automate > Folders.
- Create a Folder named
Example
in theGLOBAL
Partition. - Create a Folder named
MSLN_Temporary
in theGLOBAL
Partition. - Navigate to Configure > Deploy > Import Rule Sets.
- Create a new Import Rule Set and click its Import Action tab.
- Click Post Import and enter the code below into the Source field.
- Click Save & Close.
- Create a Job Definition of type RedwoodScript named
RS_MSLN_TestImport
, with{}
as the Source and MSLN_Temporary as the application. - Navigate to Configure > Automate > Job Definitions and export the
RS_MSLN_TestImport
Job Definition (without its related Objects). - Delete the
RS_MSLN_TestImport
Job Definition. - Submit the System_ProcessKeepClauses Job Definition to run Now.
- Navigate to Configure > Automate > Folders and delete the application named
MSLN_Temporary
. - Submit an import with the Import Rule Set and select the exported CAR file.
- Navigate to Configure > Automate > Job Definitions and locate the Job Definition named
RS_MSLN_TestImport
. Note that its application is set toExample
.
//@pragma:Unresolved
import com.redwood.scheduler.api.model.Application;
import com.redwood.scheduler.api.scripting.variables.ImportActionUnresolvedObject;
import java.util.Map;
{
Map<Long,ImportActionUnresolvedObject> unresolved = jcsImportRuleSet.getUnresolvedObjects();
Partition part = jcsSession.getPartitionByName("GLOBAL");
Application exampleApp = jcsSession.getApplicationByName(part, "Example");
unresolved.forEach((k, v)->
{
jcsOutLog.info("type: " + v.getObjectType());
jcsOutLog.info("path: " + v.getPath());
if (exampleApp != null
&& Application.OBJECT_TYPE.equals(v.getObjectType())
&& "GLOBAL.MSLN_Temporary.$2".equals(v.getPath())) //Check the application path in the source system, ensure you specify the correct path here
{
v.replaceWith(exampleApp);
}
});
}
Tip: If your import action does not replace all unresolved Objects, a RuntimeException
will be thrown with the number of unresolved references. Run the import without the import action to get a list of unresolved references.
Post Persist: Release a Queue
To release the Queue named MSLN_Queue after the imported Objects have been persisted to the database:
- Navigate to Configure > Deploy > Import Rule Sets.
- Click New.
-
Select the
GLOBAL
Partition. -
Enter
Example
into the Name field. - Click the Import Action tab.
- Click Post Persist and fill the code below into the Source field.
- Click Save & Close.
{
Partition p = jcsSession.getPartitionByName("REDWOOD");
Queue q = jcsSession.getQueueByName(p, "MSLN_Queue");
q.release();
}
Post-Persist - Submit a Job after Import
Assume you want to submit the Job Definition named MSLN_Installer
after import to cleanup or prepare the environment for the newly imported Objects.
Note: The Job Definition can have been imported in the import where this runs.
- Navigate to Configure > Deploy > Import Rule Sets.
- Click New.
- Enter a name and then click the Import Action tab.
- Click Post Persist and enter the code below into the Source field.
- Click Save & Close.
//Get imported process Definition
Partition p = jcsSession.getPartitionByName("REDWOOD");
JobDefinition jd = jcsSession.getJobDefinitionByName(p, "MSLN_Installer");
Job j = jd.prepare();