8 NMS Notification Listener Sample Application Reference

This chapter provides information about the example code for the NMS Notification Listener Sample Application.

Configuring the NMS Notification Listener Sample Application to Receive Notifications

To enable the Notification Listener Sample Application to connect to the NMS Server and receive notification events, configure the Sample Application by doing the following:

  1. Getting the ORB Object

  2. Getting the EMS Session Object

  3. Getting the Event Channel Object from the EMS Session Object

  4. Getting the Consumer Admin Object from the Event Channel Object

  5. Connecting to the StructuredProxyPullSupplier from the Consumer Admin Object

  6. Pulling the Notification Events from StructuredProxyPullSupplier

  7. Saving the Generated Notification Events in XML Files

The following subsections show example Java code for the notification listener, which connects to the EMS or NMS servers and receives notifications. You can extend the example Java code based on the EMS or NMS you are using. The EMS or NMS saves its notification events in the StructuredProxyPullSupplier object.

Getting the ORB Object

String nameService = "NameService="+corbaUrl;
String[] orbArgs =  new String[] {"-ORBInitRef", nameService};
ORB orb = ORB.init(orbArgs, null );

Getting the EMS Session Object

EmsSession_I emsSession =  null;
NamingContextExt ncRef = null;
try {
                  ncRef NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
} catch (InvalidName e) {
    e.printStackTrace();
    throw e;
}
NameComponent tmfClass = new NameComponent(nmsDetails.getClazz(), "Class");
NameComponent tmfVendor = new NameComponent(nmsDetails.getVendor(), "Vendor");
NameComponent tmfEmsInstance = new NameComponent(nmsDetails.getEmsInstance(),"EmsInstance");
NameComponent tmfVersion = new NameComponent(nmsDetails.getVersion(), "Version");
NameComponent tmfEntity = new NameComponent(nmsDetails.getEmsSessionFactory(),"EmsSessionFactory_I");
NameComponent[] name = {tmfClass, tmfVendor, tmfEmsInstance, tmfVersion, tmfEntity};
EmsSessionFactory_I sessionFactory = null;
try {
    sessionFactory = EmsSessionFactory_IHelper.narrow(ncRef.resolve(name));
} catch (NotFound e) {
    throw e;
} catch (CannotProceed e) {
    throw e;
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
    throw e;
}
POA rootpoa = null;
try {
    rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
} catch (InvalidName e) {
    throw e;
}
try {
    rootpoa.the_POAManager().activate();
} catch (AdapterInactive e) {
    throw e;
}
NmsSessionImpl nmsSessionImpl = new NmsSessionImpl(orb);
org.omg.CORBA.Object corbaObj = null;
try {
    corbaObj = rootpoa.servant_to_reference(nmsSessionImpl);
} catch (ServantNotActive e) {
    throw e;
} catch (WrongPolicy e) {
    throw e;
}
NmsSession_I nmsSession = NmsSession_IHelper.narrow(corbaObj);
EmsSession_IHolder sessionHolder = new EmsSession_IHolder();
// Read the NMS User credentials from the console.
Console console = System.console();
String username = console.readLine(sub_nl +" ["+ nmsDetails.getEmsInstance() + "] Login as: ");
char[] password = console.readPassword(sub_nl +" ["+ nmsDetails.getEmsInstance() +"] password: ");
String passwd = new String(password);
try {
    sessionFactory.getEmsSession(username, passwd, nmsSession, sessionHolder);
} catch (ProcessingFailureException e) {
    throw e;
}
emsSession =  sessionHolder.value;

Getting the Event Channel Object from the EMS Session Object

EventChannelHolder eventChannelHolder = new EventChannelHolder();
try {
emsSession.getEventChannel(eventChannelHolder);
} catch (ProcessingFailureException e) {
    throw e;
}
EventChannel eventChannel = eventChannelHolder.value;

Getting the Consumer Admin Object from the Event Channel Object

// In  NMS Notification Service, if only one Customer Admin Object is configured,
// obtain the ConsumerAdmin Object by calling default_consumer_admin().
ConsumerAdmin consumerAdmin = eventChannel.default_consumer_admin();
// otherwise
// int consumerAdminId = 0; // Get the consumer Admin Id from NMS Notification
// configuration details.
    //try {
    //     return eventChannel.get_consumeradmin(consumerAdminId);
    //} catch (AdminNotFound e) {
    //     e.printStackTrace();
//}

Connecting to the StructuredProxyPullSupplier from the Consumer Admin Object

org.omg.CORBA.IntHolder proxyId = new org.omg.CORBA.IntHolder();
ProxySupplier proxySupplier = null;
try {
proxySupplier = consumerAdmin.obtain_notification_pull_supplier(ClientType.STRUCTURED_EVENT, proxyId); // In cases where different 
// ClientType is configured on NMS, change the ClientType to obtain
// appropriateProxyPullSupplier.
    }
catch ( org.omg.CosNotifyChannelAdmin.AdminLimitExceeded ex ) {
    ex.printStackTrace( System.err );
    System.exit(-1);
}
StructuredProxyPullSupplier s_proxy_pull_supplier = null;
try {
    s_proxy_pull_supplier = StructuredProxyPullSupplierHelper.narrow(proxySupplier);
}
catch ( org.omg.CORBA.BAD_PARAM ex ) {
    ex.printStackTrace( System.err );
    System.exit(-1);
}
try {
    s_proxy_pull_supplier.connect_structured_pull_consumer( null );
}

Pulling the Notification Events from StructuredProxyPullSupplier

/**
     * This method pulls the Notification Events from NMS StructuredProxyPullSupplier.
     */
    public void startPullEvents() {
        System.out.println("Pulling the events..." );
        EventPersister persister = new EventPersister(eventQueue);
        persister.start();
        if(proxyPullSupplier != null) {
            while ( true ) {
                try {
                    StructuredEvent event proxyPullSupplier.pull_structured_event();
                    if(event != null){
                         eventQueue.add(event);
                    }
                }
                catch ( org.omg.CosEventComm.Disconnected ex ) {
                    ex.printStackTrace( System.err );
                    return;
                }
            }
        }
    }

Saving the Generated Notification Events in XML Files

The NMS Notification Listener Sample Application creates the following XML files to store details for each of the following types of entities:

  1. Create the EMS_Name.me file (where EMS_Name is the name of the EMS) to contain the list of details about managed elements (MEs) on the EMS or NMS.

  2. Create the EMS_Name.tl file to contain the list of details about topological links (TLs) on the EMS or NMS.

  3. Create the EMS_Name.snc file to contain the list of details about subnetwork connections (SNCs) on the EMS or NMS.

  4. Create the EMS_Name.deted_tl file to contain the list of deleted TLs on the EMS or NMS.

/**
* The persister saves the last modified information about the MEs, SNCs, and TLs in XML files.
*/
class EventPersister extends Thread {
    private Queue<StructuredEvent> eventQueue;
    public EventPersister(Queue<StructuredEvent> eventQueue){
           this.eventQueue = eventQueue;
    }
    public void run(){
    while(true){
    if(!eventQueue.isEmpty()){
    while(!eventQueue.isEmpty()){
       // TODO: record the notifications into files based on ObjectType.
try {
                  StructuredEvent event = eventQueue.poll();
Property[] properties = event.filterable_data;
// Get the Object Name on which the notification is generated.
NameAndStringValue_T[] objectName = NVSList_THelper.extract(properties[1].value);
// Get the Object Type on which the notification is generated.
ObjectType_T objectType = ObjectType_THelper.extract(properties[2].value);
// Get the EMS Time at which the notification is generated.
// Formatted in yyyyMMddHHmmss
String emsTime = properties[3].value.toString();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String emsName = objectName[0].value;
String meName = null;
String sncName = null;
String topologicalLinkName = null;
System.out.println("EMS ["+emsName+"]");
if(objectType == ObjectType_T.OT_MANAGED_ELEMENT || objectType == ObjectType_T.OT_EQUIPMENT ||
objectType == ObjectType_T.OT_EQUIPMENT_HOLDER || objectType == ObjectType_T.OT_PHYSICAL_TERMINATION_POINT) {
meName = objectName[1].value;
System.out.println("ME ["+meName+"] LastModified: ["+dateFormat.parse(emsTime)+"]");
} else if(objectType == ObjectType_T.OT_TOPOLOGICAL_LINK){
    topologicalLinkName = objectName[1].value;
    System.out.println("TL ["+topologicalLinkName+"] LastModified: ["+dateFormat.parse(emsTime)+"]");
} else if(objectType == ObjectType_T.OT_SUBNETWORK_CONNECTION){
    sncName = objectName[2].value;
    System.out.println("SNC ["+sncName+"] LastModified: ["+dateFormat.parse(emsTime)+"]");
}
} catch(Exception ex){
ex.printStackTrace();
}
    }
    }
    }
}
   
 
/* Sample Notification Generated on Adding New EquipmentHolder.
           ****************************************************
           START OF NT_OBJECT_CREATION
           *****************************************************
           name: notificationId value:29
           name: objectName value:
                           name: EMS value:ECI/LightSoft_1
                           name: ManagedElement value:LSN/EMS_XDM_121/1064
                           name: EquipmentHolder value:/rack=1/shelf=1/slot=1/sub_slot=4
           name: objectType value:OT_EQUIPMENT_HOLDER
           name: emsTime value:20140302141559.0
           name: neTime value:
           name: edgePointRelated value:FALSE
           name: remainder_of_body  value:
                   Name: attributeList value:
                           name: EMS value:ECI/LightSoft_1
 
                           name: ManagedElement value:LSN/EMS_XDM_121/1064
                           name: EquipmentHolder value:/rack=1/shelf=1/slot=1/sub_slot=4
 
                   name: userLabel value:I1 OTR1 4
                   name: nativeEMSName value:I1 OTR1 4
                   name: owner value:
                   name: alarmReportingIndicator value:TRUE
                   name: holderType value:sub_slot
                   name: expectedOrInstalledEquipment value:
                           name: EMS value:LSN/EMS_XDM_121
 
                           name: ManagedElement value:1064
                           name: EquipmentHolder value:/rack=1/shelf=1/slot=1/sub_slot=4
 
                           name: Equipment value:1
                   name: EquipmentObjectTypeList value:
                           NONE
                           ETR1
                           OTR1
                   name: holderState value:EXPECTED_AND_NOT_INSTALLED
                   name: additionalInfo value:
                           name: LSNExt_TimestampSignature value:20140302141559.8
 
           *************************************************************
           END OF NT_OBJECT_CREATION
           *************************************************************
           */
    }

Extending the NMS Notification Listener Sample Application to Filter Notifications

To receive notification messages, you must configure the EMS or NMS to generate different types of notification events, such as SYSLOG, ALARMS, and so on. The NMS Notification Listener Sample Application does not have any filters that restrict notifications from the EMS or NMS and hence it receives all types of notification messages. You can extend the Sample Application to filter notifications based on your business requirements. You add notification filters by extending the StructuredPushConsumer interface that is part of the Sample Application.

You can filter events on both the supplier and consumer side. In particular, filters may be applied to the supplier and consumer admins and to supplier and consumer proxies.

To apply a filter to the supplier admin or proxy, extend the StructuredPushConsumer interface by doing the following:

  1. Obtaining a Reference to the Filter Factory

  2. Creating a Filter

  3. Adding the Filter to an Admin or Proxy

The following subsections show example Java code, which you can extend to filter different types of notifications events.

Obtaining a Reference to the Filter Factory

Applying a filter means obtaining a reference to the Default Filter Factory. Note that every object of type CosNotifyChannelAdmin:: EventChannel includes a reference to the DefaultFilterFactory.

FilterFactory filterFactory = eventChannel.default_filter_factory();

Creating a Filter

Do the following to create a simple filter, as implemented by the FilteredConsumer class:

Create Constraints

final int numberofConstraints = 4;
String[] constraintStrings =
{

”$domain_name == Telecom”,
”$type_name == CommunicationsAlarm”,
”$type_name == Notification”,
”$severity != 4”

};

ConstraintExp[] constraints =  new ConstraintExp[numberofConstraints];

for(int i = 0 ; i < numberofConstraints ; ++i)
{
EventType eventType = new EventType();
eventType.domain_name = "*";
eventType.type_name = "*";

EventType[] eventTypes = new EventType[1];
eventTypes[0] = eventType;

ConstraintExp constraint = new ConstraintExp();
constraint.event_types = eventTypes;
constraint.constraint_expr = constraintStrings[i];

constraints[i] = constraint;
}

Create a Filter

Call the create_filter() method on the FilterFactory to create a filter.

filter = filterFactory.create_filter("EXTENDED_TCL");

where:

EXTENDED_TCL is the default grammar supported by all compliant notification services.

Add Constraints to the Filter

Add the constraints you created to the filter by calling the add_constraints() method.

ConstraintInfo[] info = filter.add_constraints(constraints);

Adding the Filter to an Admin or Proxy

The following interfaces are inherited from the FilterAdmin interface and can have filter objects added to them:

ProxyConsumer
ProxySupplier
ConsumerAdmin
SupplierAdmin

For example, the following line adds a filter to a supplier proxy:

proxySupplier.add_filter(filter);