2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.vpnservice.fcapsapp.alarm;
11 import org.opendaylight.vpnservice.fcapsappjmx.ControlPathFailureAlarm;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 import javax.management.MBeanServer;
16 import javax.management.MalformedObjectNameException;
17 import javax.management.ObjectName;
18 import java.lang.management.ManagementFactory;
20 public class AlarmAgent {
21 static Logger s_logger = LoggerFactory.getLogger(AlarmAgent.class);
22 private MBeanServer mbs = null;
23 private ObjectName alarmName = null;
24 private static final String BEANNAME = "SDNC.FM:name=ControlPathFailureAlarmBean";
25 private static ControlPathFailureAlarm alarmBean = new ControlPathFailureAlarm();
28 * constructor get the instance of platform MBeanServer
31 mbs = ManagementFactory.getPlatformMBeanServer();
33 alarmName = new ObjectName(BEANNAME);
34 } catch (MalformedObjectNameException e) {
35 s_logger.error("ObjectName instance creation failed for BEANAME {} : {}",BEANNAME, e);
40 * Method registers alarm mbean in platform MbeanServer
42 public void registerAlarmMbean() {
44 if (!mbs.isRegistered(alarmName)) {
45 mbs.registerMBean(alarmBean, alarmName);
46 s_logger.info("Registered Mbean {} successfully", alarmName);
48 } catch (Exception e) {
49 s_logger.error("Registeration failed for Mbean {} :{}", alarmName,e);
54 * Method invoke raise alarm JMX API in platform MbeanServer with alarm details
58 * Additional details describing about the alarm on which dpnId and hostname
60 * Source of the alarm ex: dpnId=openflow:1
61 * the source node that caused this alarm
63 public void invokeFMraisemethod(String alarmId,String text,String src) {
65 mbs.invoke(alarmName, "raiseAlarm", new Object[]{alarmId, text, src},
66 new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
67 s_logger.debug("Invoked raiseAlarm function for Mbean {} with source {}", BEANNAME, src);
68 } catch (Exception e) {
69 s_logger.error("Invoking raiseAlarm method failed for Mbean {} :{}", alarmName,e);
74 * Method invoke clear alarm JMX API in platform MbeanServer with alarm details
78 * Additional details describing about the alarm on which dpnId and hostname
80 * Source of the alarm ex: dpn=openflow:1
81 * the source node that caused this alarm
83 public void invokeFMclearmethod(String alarmId,String text,String src) {
85 mbs.invoke(alarmName, "clearAlarm", new Object[]{alarmId, text, src},
86 new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
87 s_logger.debug("Invoked clearAlarm function for Mbean {} with source {}",BEANNAME,src);
88 } catch (Exception e) {
89 s_logger.error("Invoking clearAlarm method failed for Mbean {} :{}", alarmName,e);
94 * Method gets the alarm details to be raised and construct the alarm objects
96 * Source of the alarm dpnId
100 public void raiseControlPathAlarm(String nodeId,String host) {
101 StringBuilder alarmText = new StringBuilder();
102 StringBuilder source = new StringBuilder();
106 alarmText.append("OF Switch ").append(nodeId).append(" lost heart beat communication with controller ")
108 source.append("Dpn=").append(nodeId);
110 s_logger.debug("Raising ControlPathConnectionFailure alarm... alarmText {} source {} ", alarmText, source);
111 //Invokes JMX raiseAlarm method
112 invokeFMraisemethod("ControlPathConnectionFailure", alarmText.toString(), source.toString());
113 } catch (Exception e) {
114 s_logger.error("Exception before invoking raise method in jmx {}", e);
117 s_logger.error("Received hostname is null");
122 * Method gets the alarm details to be cleared and construct the alarm objects
124 * Source of the alarm dpnId
126 public void clearControlPathAlarm(String nodeId) {
127 StringBuilder source = new StringBuilder();
130 source.append("Dpn=").append(nodeId);
131 s_logger.debug("Clearing ControlPathConnectionFailure alarm of source {} ", source);
132 //Invokes JMX clearAlarm method
133 invokeFMclearmethod("ControlPathConnectionFailure", "OF Switch gained communication with controller",
135 } catch (Exception e) {
136 s_logger.error("Exception before invoking clear method jmx {}", e);