AdventNet Web NMS 4 API Specification

com.adventnet.management.config
Class TaskGenerator

java.lang.Object
  |
  +--com.adventnet.management.config.TaskGenerator
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SnmpTaskGenerator

public class TaskGenerator
extends java.lang.Object
implements java.io.Serializable


This class provides methods to define or generate configuration information in XML format. The XML thus got is referred to as a taskXML or task. Tasks can then be submitted to the ConfigServer using DeviceConfigurationAPI or ConfigClientAPI for configuring devices.

A task's reusablility can further be increased by defining it as a template. Such a template based task is created by adding attributes containing standard place holders as values. ConfigServer supports the following placeholders,
$InventoryInput$<ID>, $NEInput<ID>, $UserInput$<ID> and $DataSourceParam$<ID>

A PlaceHolder has its own way of getting the data.
InventoryInput - Takes values from DB or files. By default ConfigServer takes values from NMS Database for InventoryInputs.
NEInput - Takes values from Network Element present in the Network.
UserInput - Values provided by the User.
DataSourceParam - Input Values for the DataSource given at the time of executing the Template.

Thus a template based attribute can be created in steps as explained below.

First, the attribute is defined.

SnmpAttribute snmpAttr = new SnmpAttribute("1.6.0", "sysLocation", (byte)4, "$UserInput$location");
The PlaceHolders need values and these values are provided by DataSources. So DataSources are needed to be associated for executing template based tasks. They can be generated by using DataSourceGenerator. The corresponding DataSource for the above attribute will be
<DataSource>
<UserInput id="location" name="NELocation" value="$DataSourceParam$location"/>
</DataSource>
Value of $DataSourceParam$location can be given at the time of executing the template task and this value will be substituted for the Attribute's value on executing the task.

TaskGenerator taskGen = new TaskGenerator();
taskGen.setTaskName("demoTask");

//Name of the protocol as given in <Web NMS Home>/conf/configprovider.xml
taskGen.setProtocol("snmp");
taskGen.setNewTask(true);

//Devices will be executed in sequential order.
taskGen.setSequential(true);
SnmpDevice device = new SnmpDevice("localhost", "161");
taskGen.setDevices( new SnmpDevice[]{device});
SnmpAttribute snmpAttr = new SnmpAttribute("1.6.0", "sysLocation", (byte)4, "AdventNet");
snmpAttr.setAttribute("MOName", "<Name of the ManagedObject that should be updated in NMS>");
taskGen.addAttribute(snmpAttr);
String taskXML = taskGen.getTask();
Refer <Web NMS Home>/configtasks/root for some default tasks and <Web NMS Home>/configtasks/root/datasource for the associated dataSources.

For generating SNMP specific tasks, use com.adventnet.management.config.snmp.SnmpTaskGenerator

Since:
Web NMS 2.3
See Also:
ConfigClientAPI, DeviceConfigurationAPI, DeviceList, Device, Attribute, DataSourceGenerator, Serialized Form

Field Summary
protected  java.util.Vector attributes
          Holds attributes defined for this task.
protected  java.lang.StringBuffer buff
          Stores the Configuration Information.
protected  org.w3c.dom.Document document
          Represents the Task XML document.
 
Constructor Summary
TaskGenerator()
          Creates an empty Attribute Vector for adding attributes.
 
Method Summary
 void addAttribute(Attribute attribute)
          Method which adds an attribute to the Configuration Task.
 void addGroupAttribute(Attribute[] taskAttributes, java.util.Properties userProps)
          Method which adds a group of config attributes and its user properties to the task.
 void addProtocolAttribute(java.lang.String name, java.lang.String value)
          Adds protocol specific attribute to a task, like mibsToBeLoaded in SNMP.
protected  void generateAttributes(Attribute[] attributes, org.w3c.dom.Element node)
          Called by the generator for generating the attribute specific information.
 Attribute[] getAttributeArray()
          Returns the assigned attributes for this task.
 java.util.Vector getAttributes()
          Returns the assigned attributes for this task.
 java.lang.String getDataSourceName()
          Returns the name of the DataSource asscoiated for this template.
 java.lang.String getDescription()
          Returns the description of a task.
 java.lang.String[] getDeviceList()
          Returns the assigned DeviceList names for this task.
 Device[] getDevices()
          Returns devices that are assigned for configuration.
 java.lang.String getProtocol()
          Returns the protocol of the task.
 java.lang.String getRollbackDocument()
          Returns the rollback document name that has been set.
 int getRollbackType()
          Returns the rollback type which has been set for a task.
 java.util.Vector getSubDeviceList()
          Returns DeviceList names as a Vector of String array in a CombinedTask.
 java.util.Vector getSubDevices()
          Returns subDevices as a Vector of Device Array in a CombinedTask.
 java.util.Vector getSubTasks()
          Returns the subTaskNames as a Vector of Strings in a CombinedTask.
 java.lang.String getTask()
          Returns configuration data in XML Format.
 java.lang.String getTaskName()
          Returns the name assigned for this configuration data.
 java.lang.String getVersion()
          Returns the version of the task XML.
 boolean isNewTask()
          Returns whether the task is an existing one or to be created from this XML.
 boolean isOverwrite()
          Says whether the task should be overwritten or not.
 boolean isPersistence()
          Says whether the task is to be stored in Database or not.
 boolean isRollbackNeeded()
          Returns whether rollback is needed or not for this task.
 boolean isSequential()
          Says whether the devices assigned to this task should be executed in a sequential or parallel manner.
 boolean isTemplate()
          Says whether the Task is a template based one or not.
 void saveTask(java.lang.String fileName)
          Saves the configuration XML in the specified file.
 void setAttributeList(Attribute[] attributeList)
          Sets the list of attributes for this task.
 void setDataSourceName(java.lang.String dataSourceName)
          Sets the DataSource name for this template.
 void setDescription(java.lang.String description)
          Sets the description for this task.
 void setDeviceLevelResult(boolean enableDeviceResult)
          Enables the device level result propagation of ConfigServer.
 void setDeviceList(java.lang.String[] deviceListNames)
          Sets the devicelists for which configuration should be done.
 void setDeviceList(java.util.Vector subTaskNames, java.util.Vector deviceList)
          Sets the deviceLists for the subTasks for CombinedTask Configuration.
 void setDevices(Device[] devices)
          Sets the devices for which the configuration should be done.
 void setDevices(java.util.Vector subTaskNames, java.util.Vector subDevices)
          Sets the devices for the sub tasks for CombinedTask Configuration.
 void setInterPacketDelay(int timeDelay)
          Specifies the delay between successive requests to various agents.
 void setNewTask(boolean newTask)
          Sets whether the task is a new or an existing task.
 void setOverwrite(boolean overwrite)
          Specifies whether the task should be overwritten or not.
 void setPersistence(boolean persistence)
          Specifies whether task should be stored in Database or not.
 void setProtocol(java.lang.String protocol)
          Sets the protocol for this task.
 void setRollback(boolean isRollbackNeeded)
          Sets the rollback for the task.
 void setRollbackDocument(java.lang.String taskName)
          Sets the rollback document for this task.
 void setRollbackType(int type)
          Specifies the rollback type for this task.
 void setSequential(boolean sequential)
          Specifies whether the devices should be configured in a sequential or parallel manner.
 void setSubTaskNames(java.util.Vector subTaskNames)
          Sets the subTasks for Combined Task Configuration.
Combined task is the collection of tasks which has already been created .These tasks can belong to different protocols.
 void setTaskName(java.lang.String taskName)
          Sets the task name for the configuraton information.
 void setTemplate(boolean template)
          Sets the task to be a template.
 void setVersion(java.lang.String version)
          Sets the version for the task XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected java.util.Vector attributes
Holds attributes defined for this task.

document

protected org.w3c.dom.Document document
Represents the Task XML document.

buff

protected java.lang.StringBuffer buff
Stores the Configuration Information.
Constructor Detail

TaskGenerator

public TaskGenerator()
Creates an empty Attribute Vector for adding attributes.
Method Detail

setDeviceLevelResult

public void setDeviceLevelResult(boolean enableDeviceResult)
Enables the device level result propagation of ConfigServer. i.e ConfigServer sends the configuration result once it finishes the configuration of each device associated with the task.
Parameters:
enableDeviceResult - true if device level results are needed, else false.

setInterPacketDelay

public void setInterPacketDelay(int timeDelay)
Specifies the delay between successive requests to various agents. This feature of delaying successive requests has been enabled for SNMP Requests only.
Parameters:
timeDelay - delay time that is to be set in milliseconds

setPersistence

public void setPersistence(boolean persistence)
Specifies whether task should be stored in Database or not. This attribute is not applicable for CombinedTasks.
Parameters:
persistence - true if the task is to be stored in Database otherwise false.

isPersistence

public boolean isPersistence()
Says whether the task is to be stored in Database or not.
Returns:
true if the task is stored in Database otherwise false

setRollback

public void setRollback(boolean isRollbackNeeded)
Sets the rollback for the task. If rollback attribute is set to true, then ConfigServer attempts to maintain the consistency across the devices by applying the previous configuration or rollback document assigned for this task.Rollback will be applied only for those devices which are succeeded or failed during configuration.
Parameters:
isRollbackNeeded - true if rollback need to be done for the successfully configured devices, otherwise false.
See Also:
setRollbackType(int), setRollbackDocument(String)

isRollbackNeeded

public boolean isRollbackNeeded()
Returns whether rollback is needed or not for this task.
Returns:
true if rollback has been set for the task otherwise false

setRollbackType

public void setRollbackType(int type)
Specifies the rollback type for this task. Rollback Type can be either ConfigConstants.CURRENT_CONFIG or ConfigConstants.DOCUMENT.If type is CURRENT_CONFIG, ConfigServer keeps the configuration of the device before applying the task and if the execution fails for this device, ConfigServer applies the previous configuration for the device. If the type is DOCUMENT, ConfigServer just applies this document for these devices. By default, rollback type is set to CURRENT_CONFIG.
Parameters:
type - the rollback type to be set for the task.
See Also:
ConfigConstants.DOCUMENT, ConfigConstants.CURRENT_CONFIG, setRollback(boolean), setRollbackDocument(String), getRollbackType()

getRollbackType

public int getRollbackType()
Returns the rollback type which has been set for a task.
Returns:
rollback type
See Also:
ConfigConstants.DOCUMENT, ConfigConstants.CURRENT_CONFIG, setRollbackType(int)

setRollbackDocument

public void setRollbackDocument(java.lang.String taskName)
Sets the rollback document for this task. Rollback Document is an already existing task which will be applied for the devices if rollback is enabled and rollback document is assigned for the task.
Parameters:
taskName - the name of the existing task.
See Also:
getRollbackDocument()

getRollbackDocument

public java.lang.String getRollbackDocument()
Returns the rollback document name that has been set.
Returns:
rollback document name.
See Also:
setRollbackDocument(String)

setDescription

public void setDescription(java.lang.String description)
Sets the description for this task.
Parameters:
description - description of the task.
See Also:
getDescription()

getDescription

public java.lang.String getDescription()
Returns the description of a task.
Returns:
the description of the task
See Also:
setDescription(String)

getAttributes

public java.util.Vector getAttributes()
Returns the assigned attributes for this task.
Returns:
a Vector of attributes.

getAttributeArray

public Attribute[] getAttributeArray()
Returns the assigned attributes for this task.
Returns:
the Attribute array

setOverwrite

public void setOverwrite(boolean overwrite)
Specifies whether the task should be overwritten or not. If this parameter is set to false, ConfigServer throws TaskExistsException if one tries to overwrite the existing task if present. By default, the task will not be overwritten. Also ConfigServer throws ConcurrentModificationException if the task to be overwritten is currently under execution.
Parameters:
overwrite - should be set to true if the task should be overwritten otherwise false

isOverwrite

public boolean isOverwrite()
Says whether the task should be overwritten or not.
Returns:
true if the task is to be overwritten ,otherwise false.

setSequential

public void setSequential(boolean sequential)
Specifies whether the devices should be configured in a sequential or parallel manner.
Parameters:
sequential - true if the devices are to be configured sequentially otherwise false

isSequential

public boolean isSequential()
Says whether the devices assigned to this task should be executed in a sequential or parallel manner.
Returns:
true if the sequential option for the task is set to true otherwise false

setProtocol

public void setProtocol(java.lang.String protocol)
Sets the protocol for this task. This protcol is used by ConfigServer to get the corresponding ConfigProvider from <Web NMS Home>/conf/configprovider.xml. The protocol value should match with the TYPE value in the provider file.
Parameters:
protocol - protocol of the task.
See Also:
getProtocol()

getProtocol

public java.lang.String getProtocol()
Returns the protocol of the task.
Returns:
the protocol that has been set for the task / subtask in the case of a Combined Task.
See Also:
setProtocol(String)

setVersion

public void setVersion(java.lang.String version)
Sets the version for the task XML. Default value is 1.0.ConfigServer uses the version of task XML to support backward comptability in future.
Parameters:
version - of the task XML.
See Also:
getVersion()

getVersion

public java.lang.String getVersion()
Returns the version of the task XML.
Returns:
the version of the task that is being created/executed.
See Also:
setVersion(String)

setDevices

public void setDevices(Device[] devices)
Sets the devices for which the configuration should be done. If both Devices and DeviceLists associated for the Task, ConfigServer executes the Devices first and then the devices from the DeviceList will be executed, i.e preferenece will be given to the Devices rather than DeviceLists.
Parameters:
devices - an array of devices that need to be associated with the task.
See Also:
Device, setDeviceList(String[])

setDeviceList

public void setDeviceList(java.lang.String[] deviceListNames)
Sets the devicelists for which configuration should be done. A DeviceList is a set of devices which can be stored like a Task in ConfigServer. DeviceList can be stored using ConfigClientAPI.saveDeviceList(String).
Parameters:
deviceListNames - a String array containing name of deviceLists.
See Also:
DeviceList, ConfigClientAPI.saveDeviceList(String), setDevices(Device[]), getDeviceList()

setDevices

public void setDevices(java.util.Vector subTaskNames,
                       java.util.Vector subDevices)
Sets the devices for the sub tasks for CombinedTask Configuration. A CombinedTask is a set of subtasks which are already created and these tasks can be grouped and executed at a stretch.A combined task can have subtasks of different protocol. Also a set of devicelists can also be associated for the subtasks. If both devices and devicelists are associated for the same subtask, priority will be given to the devices rather devices present in a DeviceList.Used for creating CombinedTasks.
Parameters:
subTaskNames - Vector of subTask names.
subDevices - Vector of Device array.
See Also:
setDeviceList(Vector,Vector), getDevices()

setDeviceList

public void setDeviceList(java.util.Vector subTaskNames,
                          java.util.Vector deviceList)
Sets the deviceLists for the subTasks for CombinedTask Configuration. Used for creating CombinedTasks.
Parameters:
subTaskNames - Vector of subTaskNames.
deviceList - Vector of String array containing deviceListNames.
See Also:
DeviceList, setDevices(Vector,Vector), getDeviceList()

setSubTaskNames

public void setSubTaskNames(java.util.Vector subTaskNames)
Sets the subTasks for Combined Task Configuration.
Combined task is the collection of tasks which has already been created .These tasks can belong to different protocols. This is intended for storing the CombinedTask in DataBase. Used for creating CombinedTasks.
Parameters:
subTaskNames - the names of the subtasks to be included in the Combined Task

getSubTasks

public java.util.Vector getSubTasks()
Returns the subTaskNames as a Vector of Strings in a CombinedTask.
Returns:
Vector containing name of the subTasks

getSubDevices

public java.util.Vector getSubDevices()
Returns subDevices as a Vector of Device Array in a CombinedTask.
Returns:
Vector of Device array
See Also:
Device

getSubDeviceList

public java.util.Vector getSubDeviceList()
Returns DeviceList names as a Vector of String array in a CombinedTask.
Returns:
Vector of String array.
See Also:
DeviceList

getDevices

public Device[] getDevices()
Returns devices that are assigned for configuration.
Returns:
a Device Array.
See Also:
setDevices(Device[]), setDevices(Vector, Vector)

getDeviceList

public java.lang.String[] getDeviceList()
Returns the assigned DeviceList names for this task.
Returns:
an array of DeviceList names
See Also:
DeviceList, setDeviceList(String[]), setDeviceList(Vector, Vector)

setTaskName

public void setTaskName(java.lang.String taskName)
Sets the task name for the configuraton information. Default value is Task1.
Parameters:
taskName - the name that you want to set for the task.
See Also:
getTaskName()

getTaskName

public java.lang.String getTaskName()
Returns the name assigned for this configuration data.
Returns:
the task's name if set, else returns "Task1", the default value.
See Also:
setTaskName(String)

setNewTask

public void setNewTask(boolean newTask)
Sets whether the task is a new or an existing task. This attribute is used by ConfigServer to determine whether the task should be taken from DB or from the assigned attributes. If this attribute is true, ConfigServer stores the submitted task in DB before executing the task over a set of assigned Devices and DeviceLists. If the attribute is assigned to false, ConfigServer restores the task from the DB ( it neglects the attributes ,if any assigned )and executes over the assigned Devices and DeviceLists.
Parameters:
newTask - true if the task has to take the attributes during execution time, false if the task is to be taken from storage.

isNewTask

public boolean isNewTask()
Returns whether the task is an existing one or to be created from this XML.
Returns:
true if the task doesn't exist, else false.

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Sets the DataSource name for this template.
Parameters:
dataSourceName - name of the existing DataSource.
See Also:
DataSourceGenerator, DataSource, getDataSourceName()

getDataSourceName

public java.lang.String getDataSourceName()
Returns the name of the DataSource asscoiated for this template.
Returns:
DataSource name.
See Also:
DataSource, setDataSourceName(String)

isTemplate

public boolean isTemplate()
Says whether the Task is a template based one or not.
Returns:
true if the task is a template, else false.

setTemplate

public void setTemplate(boolean template)
Sets the task to be a template. If the task is a template, then it's Attribute values can be dynamically changed before doing the configuration. DataSource defines various ways of getting the Attribute's value.
Parameters:
template - boolean value which decides whether the task is to be a template or not.
See Also:
DataSource

getTask

public java.lang.String getTask()
Returns configuration data in XML Format. See DeviceConfigurationAPI, ConfigClientAPI for executing the created task XML.
Returns:
the task in the XML form if present, else returns null.
See Also:
DeviceConfigurationAPI, ConfigClientAPI

saveTask

public void saveTask(java.lang.String fileName)
Saves the configuration XML in the specified file.
Parameters:
fileName - name of the file for storing the configuration information.

generateAttributes

protected void generateAttributes(Attribute[] attributes,
                                  org.w3c.dom.Element node)
Called by the generator for generating the attribute specific information. This method is used to generate task XML.
Parameters:
attributes - array of Attributes.
node - parent node for these attributes.
See Also:
Attribute

addAttribute

public void addAttribute(Attribute attribute)
Method which adds an attribute to the Configuration Task.
Parameters:
attribute - an com.adventnet.management.config.xml.Attribute value
See Also:
setNewTask(boolean)

addGroupAttribute

public void addGroupAttribute(Attribute[] taskAttributes,
                              java.util.Properties userProps)
Method which adds a group of config attributes and its user properties to the task. Attributes that are present in a group will be send in a single packet for configuring the devices.Here parameter userProps can be null.
Parameters:
taskAttributes - an array of attributes.
userProps - userSpecificProperties.
See Also:
setNewTask(boolean)

setAttributeList

public void setAttributeList(Attribute[] attributeList)
Sets the list of attributes for this task. If the newTask attribute is false, ConfigServer discards all these attributes and takes attributes only from the saved task.
Parameters:
attributeList - an array of attributes.
See Also:
setNewTask(boolean)

addProtocolAttribute

public void addProtocolAttribute(java.lang.String name,
                                 java.lang.String value)
Adds protocol specific attribute to a task, like mibsToBeLoaded in SNMP.
Parameters:
name - protocol specific property like mibsToBeLoaded in SNMP.
value - value to be substituted for this specific property.

AdventNet Web NMS 4 API Specification