NMC-RX 7.3.x User Guide, Vol. 2 > Sample Client Program
> NMS Client Java Program Sample
NMS Client Java Program Sample
import org.tmforum.mtnm.globaldefs.*;
import org.tmforum.mtnm.common.*;
import org.tmforum.mtnm.session.*;
import org.tmforum.mtnm.emsSession.*;
import org.tmforum.mtnm.nmsSession.*;
import org.tmforum.mtnm.emsSessionFactory.*;
import org.omg.CORBA.*;
import com.redstonecom.services.corbaevents.CorbaApi;
import
com.redstonecom.services.provisioningservice.unspcorbabridge.tmf814.nmsSession.Tmf814NmsSessionImpl;
import com.redstonecom.services.provisioningservice.unspcorbabridge.nmcrx.unspRXDeviceMgr.*;
import com.redstonecom.services.provisioningservice.unspcorbabridge.nmcrx.unspRXCustomerMgr.*;
import java.util.*;
import java.lang.*;
import java.text.SimpleDateFormat;
import java.io.*;
class NmcrxPSSampleClient
{
private CorbaApi corbaApi = CorbaApi.getInstance();
private String[] cmd_line_args;
private java.util.Properties properties;
EmsSession_I emsSession_I;
EmsSessionFactory_I emsSessionFactory_I;
static public void main( String[] args )
{
NmcrxPSSampleClient client = new NmcrxPSSampleClient( args, null );
client.start();
if ( client.emsSessionFactory_I != null )
{
client.initialRequests();
System.exit(0);
}
}
private NmcrxPSSampleClient( String[] args, java.util.Properties properties )
{
this.cmd_line_args = args;
this.properties = properties;
}
private void start()
{
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
corbaApi.connectToORB( cmd_line_args, properties );
corbaApi.connectToPOA();
try
{
// Get the Name Service object:
// Connecting to Name Service
corbaApi.connectToNameServiceByIORFile("JuniperERXNameService.ior");
// getEmsSessionFactoryServer
emsSessionFactory_I = getEmsSessionFactoryServer();
}
catch ( Exception e )
{
System.out.println(
"Connecting to Name Service failed : " + e.getMessage());
}
}
private EmsSessionFactory_I getEmsSessionFactoryServer()
{
try
{
org.omg.CORBA.Object Obj = corbaApi.findObjectForName(
"JUNIPER_NMCRX_TMF814_EMSSESSIONFACTORY_8384" );
return EmsSessionFactory_IHelper.narrow( Obj );
}
catch ( Exception e )
{
System.out.println( "EmsSessionFactory Server will not be available." );
return null;
}
}
private void initialRequests()
{
try{
// Create NmsSession client_nms to pass to EmsSession
org.omg.CORBA.Object Obj;
Tmf814NmsSessionImpl tmf814NmsSessionServer =
new Tmf814NmsSessionImpl(cmd_line_args);
// Export NmsSession
Obj = tmf814NmsSessionServer.export(
"TMF814_NMSSESSION", false );
NmsSession_I client_nms = NmsSession_IHelper.narrow( Obj );
// Try to get emaSession by call getEmsSession of EmsSessionFactory
EmsSession_IHolder emsSession_IHolder = new EmsSession_IHolder();
emsSessionFactory_I.getEmsSession(
"admin", "nmc-rxadmin", client_nms, emsSession_IHolder);
// set EmsSession in NmsSession, this is not standard method, but only use it at local
tmf814NmsSessionServer.setAssociatedSession(emsSession_IHolder.value);
emsSession_I = EmsSession_IHelper.narrow(emsSession_IHolder.value);
Common_IHolder common_IHolder = new Common_IHolder();
// Try to get Device Manager
emsSession_I.getManager("UNSPRXDEVICEMGR", common_IHolder );
UnspRXDeviceMgr_I deviceMgr =
UnspRXDeviceMgr_IHelper.narrow(common_IHolder.value);
// Try to get Customer Manager
emsSession_I.getManager("UNSPRXCUSTOMERMGR", common_IHolder );
UnspRXCustomerMgr_I customerMgr =
UnspRXCustomerMgr_IHelper.narrow(common_IHolder.value);
// ping EMS Corba Server
emsSession_I.ping();
String IP = "65.194.140.194";
String ptp = "5/0";
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[3];
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
objectPath[1] = new NameAndStringValue_T("ManagedElement", IP);
objectPath[2] = new NameAndStringValue_T("PTP", ptp);
this.testListAllByDeviceMgr(deviceMgr, IP, ptp, "8", "2.0");
this.testListAllByCustomerMgr(customerMgr, "ABC1's");
deviceMgr = null;
emsSession_I.endSession();
emsSession_I = null;
emsSessionFactory_I = null;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
catch(Exception e)
{
System.out.println("testEmsSessionFactory failed: " + e.getMessage());
}
}
private void testListAllByDeviceMgr(UnspRXDeviceMgr_I deviceMgr, String IP, String ptp, String
index, String name)
{
this.ListAllNode(deviceMgr);
this.ListAllATM(deviceMgr, IP, ptp);
this.ListAllATMSUB(deviceMgr, IP, ptp);
this.ListAllPVC(deviceMgr, IP, ptp, index);
}
private void ListAllNode(UnspRXDeviceMgr_I deviceMgr)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[1];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
try{
deviceMgr.listAll( objectPath,
UnspRXDeviceMgrObjectType.ManagedElement,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}
private void ListAllATM(UnspRXDeviceMgr_I deviceMgr, String IP, String ptp)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[3];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
objectPath[1] = new NameAndStringValue_T("ManagedElement", IP);
objectPath[2] = new NameAndStringValue_T("PTP", ptp);
try{
deviceMgr.listAll( objectPath,
UnspRXDeviceMgrObjectType.AtmInterface,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
org.tmforum.mtnm.globaldefs.NamingAttributesIterator_I nai =
namingAttributesIterator_IHolder.value;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}
private void ListAllATMSUB(UnspRXDeviceMgr_I deviceMgr, String IP, String ptp)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[4];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
objectPath[1] = new NameAndStringValue_T("ManagedElement", IP);
objectPath[2] = new NameAndStringValue_T("PTP", ptp);
objectPath[3] = new NameAndStringValue_T("AtmInterface", "ATM" + ptp);
try{
deviceMgr.listAll( objectPath,
UnspRXDeviceMgrObjectType.AtmSubInterface,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
org.tmforum.mtnm.globaldefs.NamingAttributesIterator_I nai =
namingAttributesIterator_IHolder.value;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}
private void ListAllPVC(UnspRXDeviceMgr_I deviceMgr, String IP, String ptp, String Index)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[5];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
objectPath[1] = new NameAndStringValue_T("ManagedElement", IP);
objectPath[2] = new NameAndStringValue_T("PTP", ptp);
objectPath[3] = new NameAndStringValue_T("AtmInterface", "ATM" + ptp);
objectPath[4] = new NameAndStringValue_T("AtmSubInterface", "ATM" + ptp + "." + Index);
try{
deviceMgr.listAll( objectPath,
UnspRXDeviceMgrObjectType.AtmPvc,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
org.tmforum.mtnm.globaldefs.NamingAttributesIterator_I nai =
namingAttributesIterator_IHolder.value;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}
private void testListAllByCustomerMgr(UnspRXCustomerMgr_I customerMgr, String name)
{
this.ListAllCustomerByCustomer(customerMgr);
this.ListAllCustSiteByCustomer(customerMgr, name);
}
private void ListAllCustomerByCustomer(UnspRXCustomerMgr_I customerMgr)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[1];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
try{
customerMgr.listAll( objectPath,
UnspRXCustomerMgrObjectType.Customer,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
org.tmforum.mtnm.globaldefs.NamingAttributesIterator_I nai =
namingAttributesIterator_IHolder.value;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}
private void ListAllCustSiteByCustomer(UnspRXCustomerMgr_I customerMgr, String customerName)
{
NameAndStringValue_T[] objectPath = new NameAndStringValue_T[2];
NamingAttributesList_THolder namingAttributesList_THolder =
new NamingAttributesList_THolder();
NamingAttributesIterator_IHolder namingAttributesIterator_IHolder =
new NamingAttributesIterator_IHolder();
objectPath[0] = new NameAndStringValue_T("EMS", "JUNIPER_NMCRX");
objectPath[1] = new NameAndStringValue_T("Customer", customerName );
try{
customerMgr.listAll( objectPath,
UnspRXCustomerMgrObjectType.CustSite,
10,
namingAttributesList_THolder,
namingAttributesIterator_IHolder);
org.tmforum.mtnm.globaldefs.NamingAttributesIterator_I nai =
namingAttributesIterator_IHolder.value;
}
catch(ProcessingFailureException e)
{
System.out.println("ProcessingFailureException: " + e.errorReason );
}
}