Applying a native command set to a device
The applying a native command set to a device example shows how to apply a set of device commands in a Native Command Set that do not modify the configuration of a device. For example, the set of device commands might be the "show" commands on a CISCO router.
This type of native command set is known as an “interrogative” native command set, and is intended specifically to only fetch data from the device. The device's configuration is not synchronized back into Netcool Configuration Manager - Base after executing an interrogative native command set. To make configuration changes to a device with a native command set, you must use a “configuration change” type of native command set. Configuration change native command sets result in the device's configuration being synchronized back into Netcool Configuration Manager - Base if the command set is successfully applied, so that Netcool Configuration Manager - Base will be in sync with the changed configuration on the device. Note that for interrogative native command sets the response data from the device is stored in Netcool Configuration Manager - Base along with the UOW data as “interrogation results” and can be retrieved using the API. For configuration change native command sets the response data from the device is not captured and stored, except parts of detected error strings in UOW logs.
In a previous example, you learned how to submit a Unit Of Work that is scheduled. This example shows how to execute the command synchronously (blocking until the UOW completes or a timeout value is exceeded).
Command Sets and Native Command Sets may contain parameters that must be resolved (parameter values applied) before submitting them and the example shows how to do that as well.
ResourceManager rMgr;
WorkflowManager wMgr;
Properties params; //the parameters (keys) and data (values)
NetworkResourceKey nrKey;
NativeCommmandSet ncs;
.
.
.
//it is assumed the session has been established
rMgr = session.resourceManager();
wMgr = session.workflowManager();
.
.
.
//it is assumed that the NetworkResourceKey has been populated
// and an interrorgative NativeCommandSet has been fetched
try {
//it is assumed that params has been populated
//skip this if you don't have any parameters
ncs.applyParameters(params);
//instantiate and populate a command
NativeCommandSetCommand cmd = rMgr.dataFactory().newNativeCommandSetCommand();
//this command operates on a Collection of NetworkResourceKeys,
//even though you may only have one of them
//it is assumed the key has been established
ArrayList nrKeys = new ArrayList();
nrKeys.add(nrKey);
cmd.setKeys(nrKeys);
cmd.addCommandSet(ncs);
cmd.setComment("Apply NCS");
cmd.setContinueOnError(true);
cmd.validate();
//now execute the commands, assuming a timeout condition will not occur
NativeCommandSetCommand resultCmd =
(NativeCommandSetCommand)wMgr.executeCommandBlocking(cmd, 922337203685477L, true);
Collection<InterrogationResult> iResults = resultCmd.getInterrogationResults();
for(InterrogationResult iResult : iResults) {
String resultStr = iResult.getInterrogationResult();
//now examine the command output
System.out.println("NCS interrogation result: " + resultStr);
}
}catch (IcosException ie) {
System.out.println(ie.getNestedExceptionStackTrace());
}