|
Overview
This topic explains the Provisioning example using Provisioning API. You can get the handle of Provisioning API using RMI/TCP/JMS. After that you can carryout provisioning using the (XML) template.
Description
When you want to carry out provisioning using Provisioning API, you have to handle the following:
Get the Provisioning server properties to form the server URL.
Get the handle of Provisioning API using any of the communication modes RMI/TCP/JMS.
Execute Provisioning by fetching the template, populate the user values, pass it on to the Provisioning module.
In the case of UI based provisioning, you have to handle all the three above mentioned actions. But the client side code takes care of fetching the user input values from the UI and populates the values in template.
Code Snippet using RMI
Get the Provisioning server properties to form the server URL and get the handle of Provisioning API using RMI.
|
package test.prov; import java.net.MalformedURLException; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.util.Properties; import java.util.*; import com.adventnet.management.config.xml.InvalidTemplateException; import com.adventnet.management.config.xml.UserInput; import com.adventnet.nms.provisioning.OperationFailedException; import com.adventnet.nms.provisioning.ProvisioningAPI; import com.adventnet.nms.provisioning.ui.ProvClientUtils; import com.adventnet.nms.provisioning.xml.Form; import com.adventnet.nms.provisioning.xml.PopulateTemplateParams; import com.adventnet.nms.provisioning.xml.StageResult; import com.adventnet.nms.provisioning.xml.Template; import com.adventnet.nms.provisioning.xml.TemplateResult; import com.adventnet.nms.util.CommonUtilCarrier; import com.adventnet.nms.util.NmsCommonUtilClientImpl;
public class RMITestSlerreServiceVlan { public static void main(String[] args) {
Properties serverProps = new Properties();
serverProps.put("MODE", "RMI");//Mode of communication with Web NMS serverProps.put("USERNAME", "root");//Username of the operator who wants to execute provisioning serverProps.put("PASSWORD", "public");//Operator password serverProps.put("SERVERNAME", args[0]);//Server name serverProps.put("SERVERPORT", "1099");//RMI Port ProvisioningAPI PROV; try { PROV = ProvClientUtils.getProvisioningAPI(serverProps); //Get Provisioning handle. CommonUtilCarrier.setInstance(new NmsCommonUtilClientImpl()); executeProvisioning(PROV); } catch (MalformedURLException e) { logMessage("MALFORMED URL"); e.printStackTrace(); } catch (RemoteException e) { logMessage("REMOTE EXCEPTION"); e.printStackTrace(); } catch (NotBoundException e) { logMessage("NOT BOUND EXCEPTION"); e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
Execute Provisioning by fetching the template, populate the user values, pass it on to the Provisioning module.
|
private static void executeProvisioning(ProvisioningAPI PROV) { String templateString = null; Template template = null; try { templateString = PROV.getTemplate("SlerreServiceVlanSimple"); template = new Template(templateString); //Get the Form object and subsquently UserInput object Vector forms=template.getForms(); Form form =(Form) forms.elementAt(0); Vector uInputs =form.getUserInputs(); Properties provProps = setupTemplatemeters();
//Set All UserInput Values for(Enumeration en=uInputs.elements();en.hasMoreElements();) { UserInput uInput=(UserInput)en.nextElement(); String id=uInput.getID(); uInput.setValue(provProps.getProperty("$UserInput$"+id)); }
System.out.println(" Modified Template \n"+ template.toString());
Template tempObj = PopulateTemplateParams.substituteParams(template, provProps); logMessage(PROV.provision(template.toString())); } catch (InvalidTemplateException e) { logMessage("Invalid Template Exception"); logError(e); } catch (OperationFailedException e) { logMessage("Provisioning Operation Failed"); logError(e); } } |
The attached template is used along with above code snippet.
|
|
Note: You have to handle, populating the values of user input, in the code as given in the above snippet. |
|
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Template SYSTEM "Template.dtd"> <Template name="SlerreServiceVlanSimple" owner="root" finish="OK" close="Close" description="This template creates Ethernet Service" > <Stage label="Input">
<Initialization> <Context contextType="sql" handleName="SierreServiceVlanHandle" URL="jdbc:postgresql://localhost/WebNmsDB" driverName="org.postgresql.Driver" userName="root" /> </Initialization> <Form id="Input" title="Input Parameters" description="This Template collects parameters for a VLAN service."> <UserInput id="1#" label="Subscription ID" required="true" editable="true" default="X_1234_0001"/> <UserInput id="2#" label="Subscription ID" required="true" editable="true" default="X_1234_0002"/> </Form>
<Script> System.out.println("End of INPUT"); System.out.println("UserInput1 = $UserInput$1#"); System.out.println("UserInput2 = $UserInput$2#"); </Script> <GoTo label="Validation" /> </Stage> <Stage label="Validation">
<InventoryInput> <SQLInput id="a_class#" contextHandleName="SierreServiceVlanHandle" default="null" sqlCommand="select CLASSNAME from ManagedObject where NAME like '$UserInput$1#'" /> <SQLInput id="b_class#" contextHandleName="SierreServiceVlanHandle" default="null" sqlCommand="select CLASSNAME from ManagedObject where NAME like '$UserInput$2#'" /> </InventoryInput> <Script> System.out.println("Inventory Output: 1 = $InventoryInput$a_class#"); System.out.println("Inventory Output: 2 = $InventoryInput$b_class#"); </Script> </Stage> </Template> |
|