Set IT Resource Instance parameters from Ant build script
ImportItResourceInstanceParameters.java
import java.util.Hashtable;
import java.util.Properties;
import Thor.API.Operations.tcITResourceInstanceOperationsIntf;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import com.thortech.xl.util.config.ConfigurationClient;
/**
* Sets an IT Resource Instance parameters from the command-line. Xellerate
* Deployment Manager 9.0 doesn't export/import the parameter values.
*
* I use this class from an Ant build file. If the parameter value has (space)
* characters, they will need to be escaped using the http url '%20'
* (percent-sign two zero).
*
* Other special characters such as * (star), ' (quote), " (double-quote), ?
* (question mark), etc. are not supported. But they can be easily escaped using
* method above.
*
* @date 08/22/2006
* @author Vinh-An Trinh (vinhant@zerointech.com)
*/
public class ImportItResourceInstanceParameters
{
/**
* arg[0] : Xellerate username (eg xelsysadm) arg[1] : Xellerate password
* arg[2] : "IT Resource Type Definition" name arg[3] : "IT Resource
* instance" name arg[4..n] : key=value
*/
public static void main(String args[])
{
if (args.length < 3)
{
System.out.println("");
return;
}
try
{
Properties jndi = ConfigurationClient.getComplexSettingByPath(
"Discovery.CoreServer").getAllSettings();
tcUtilityFactory tcutilityfactory = new tcUtilityFactory(jndi,
args[0], args[1]);
tcITResourceInstanceOperationsIntf itResInstIntf =
(tcITResourceInstanceOperationsIntf) tcutilityfactory.getUtility(
"Thor.API.Operations.tcITResourceInstanceOperationsIntf");
// Kludge : replace %20 with space
// Makes it easier to run this from an Ant build file
String serverType = args[2].replaceAll("%20", " ");
String serverName = args[3].replaceAll("%20", " ");
// Find IT resource instance key
Hashtable filter = new Hashtable();
filter.put("IT Resources Type Definition.Server Type", serverType);
tcResultSet servers = itResInstIntf.findITResourceInstances(filter);
if (servers.getRowCount() == 0)
{
System.out.println("IT Resource Type not found: " + serverType);
return;
}
long resourceKey = 0;
for (int i = 0; i < servers.getRowCount(); i++)
{
servers.goToRow(i);
String name = servers.getStringValue("IT Resources.Name");
if (name.equalsIgnoreCase(serverName))
{
resourceKey = servers.getLongValue("IT Resources.Key");
break;
}
}
if (resourceKey == 0)
{
System.out.println("IT Resource Instance name not found: "
+ serverName);
return;
}
// Build new parameters
Hashtable params = new Hashtable();
for (int i = 0; i < args.length - 4; i++)
{
int idx = args[4 + i].indexOf('=');
if (idx == -1)
{
System.out.println("Parsing error (equal sign not found): "
+ args[4 + i]);
return;
}
// Kludge : replace %20 with space
// Makes it easier to run this from an Ant build file
String key = args[4 + i].substring(0, idx).replaceAll("%20",
" ");
String value = args[4 + i].substring(idx + 1).replaceAll("%20",
" ");
params.put(key, value);
}
System.out.println("Importing :" + "\n " + serverType + "\n "
+ serverName + "\n " + params);
itResInstIntf.updateITResourceInstanceParameters(resourceKey,
params);
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
System.exit(0);
}
}
}
Sample Ant script
<project name="setup-it-resource-instance-parameters" default="all">
<property name="xl.home" value="C:\xellerate9\xellerate"/>
<!-- Set these values when invoking ant -->
<property name="dom01.password" value=""/>
<property name="webhome.password" value=""/>
<property name="oracleapps.password" value=""/>
<target name="all" depends="hrRecon, exc01, dom01, webhome, email, oracleApps">
</target>
<!-- NOTE : copy the folder 'config' of the xellerate design console client -->
<!-- in the current directory -->
<target name="run">
<java classname="ImportItResourceInstanceParameters" fork="true">
<classpath>
<pathelement path="."/>
<fileset dir="${xl.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${xl.home}/ext">
<include name="**/*.jar"/>
</fileset>
</classpath>
<sysproperty key="java.security.auth.login.config"
value="${xl.home}/config/auth.conf"/>
<sysproperty key="XL.RedirectSysOutErrToFile" value="false"/>
<arg line="xelsysadm xelsysadm ${args}" />
</java>
</target>
<target name="hrRecon">
<antcall target="run">
<param name="args" value="Oracle%20HR%20Recon Oracle%20HR%20Recon
reconLastRunTime=0"/>
</antcall>
</target>
<target name="exc01">
<antcall target="run">
<param name="args" value="Exchange%20Server EXC01
Server%20Name=EXC01
Last%20Modified%20Time%20Stamp=0
Store%20Name=MAILBOX%20STORE%20(EXC01)"/>
</antcall>
</target>
<target name="dom01">
<antcall target="run">
<param name="args" value="AD%20Server DOM01
Root%20Context=dc=foobar,dc=com
Admin%20FQDN=xellerate@foobar.com
Admin%20Password=${dom01.password}
Use%20SSL=true
SSL%20Port%20Number=636
Admin%20Login=xellerate
AtMap%20ADUser=AtMap.AD
AtMap%20Group=AtMap.ADGroup
Last%20Modified%20Time%20Stamp=0
Last%20Modified%20Time%20Stamp%20Group=0
ADGroup%20LookUp%20Definition=Lookup.ADReconliation.GroupLookup
Server%20Address=dom01
NTLM%20Domain=foobar"/>
</antcall>
</target>
<target name="webhome">
<antcall target="run">
<param name="args" value="Database WEBHOME
DatabaseName=WEBHOME
Driver=oracle.jdbc.driver.OracleDriver
URL=jdbc:oracle:thin:@webhome:1526:webhome
UserID=webhome
Password=${webhome.password}
DataBaseType=Oracle"/>
</antcall>
</target>
<target name="email">
<antcall target="run">
<param name="args" value="Mail%20Server Email%20Server
Server%20Name=smtp.foobar.com
Authentication=false"/>
</antcall>
</target>
<target name="oracleApps">
<antcall target="run">
<param name="args" value="Oracle Oracle%20Apps%20Server
IsDebug=No
Host=apps
Port=1526
SID=apps
Admin=apps
AdminCredentials=${oracleapps.password}
TimeStamp=none"/>
</antcall>
</target>
</project>