diff options
Diffstat (limited to 'integrity-monitor/src/main/java/org/onap/policy/common/im/jmx')
4 files changed, 51 insertions, 39 deletions
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java index a18b1434..eb1d9f8b 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.onap.policy.common.im.IntegrityMonitor; +import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.im.StateManagement; /** @@ -187,7 +188,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void test() throws Exception { + public void test() throws IntegrityMonitorException { // Call evaluateSanity on IntegrityMonitor to run the test logger.debug("test() called..."); if (integrityMonitor != null) { @@ -201,7 +202,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void lock() throws Exception { + public void lock() throws IntegrityMonitorException { logger.debug("lock() called..."); if (stateManager != null) { stateManager.lock(); @@ -213,7 +214,7 @@ public class ComponentAdmin implements ComponentAdminMBean { } @Override - public void unlock() throws Exception { + public void unlock() throws IntegrityMonitorException { logger.debug("unlock() called..."); if (stateManager != null) { stateManager.unlock(); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java index e98288eb..5ada6da0 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminException.java @@ -20,7 +20,9 @@ package org.onap.policy.common.im.jmx; -public class ComponentAdminException extends Exception { +import org.onap.policy.common.im.IntegrityMonitorException; + +public class ComponentAdminException extends IntegrityMonitorException { private static final long serialVersionUID = 1L; public ComponentAdminException() { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java index d61add59..2c011935 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdminMBean.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ package org.onap.policy.common.im.jmx; +import org.onap.policy.common.im.IntegrityMonitorException; + /** * Provides operations to test health, lock and unlock components. */ @@ -27,24 +29,24 @@ public interface ComponentAdminMBean { /** * Test health of component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component fails the health check */ - void test() throws Exception; + void test() throws IntegrityMonitorException; /** * Administratively lock component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component lock fails */ - void lock() throws Exception; + void lock() throws IntegrityMonitorException; /** * Administratively unlock component. * - * @throws Exception + * @throws IntegrityMonitorException * if the component unlock fails */ - void unlock() throws Exception; + void unlock() throws IntegrityMonitorException; } diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java index d15fc5e7..c9a2ce80 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/JmxAgentConnection.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; +import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -86,35 +87,41 @@ public final class JmxAgentConnection { /** * Get a connection to the jmxAgent MBeanServer. * @return the connection - * @throws Exception on error + * @throws IntegrityMonitorException on error */ - public MBeanServerConnection getMBeanConnection() throws Exception { - JMXServiceURL url; - if (jmxUrl == null) { - url = new JMXServiceURL(jmxAgentUrl(host, port)); - } - else { - url = new JMXServiceURL(jmxUrl); - } - Map<String, Object> env = new HashMap<>(); - - connector = JMXConnectorFactory.newJMXConnector(url, env); - connector.connect(); - connector.addConnectionNotificationListener( - new NotificationListener() { + public MBeanServerConnection getMBeanConnection() throws IntegrityMonitorException { - @Override - public void handleNotification( - Notification notification, Object handback) { - if (notification.getType().equals( - JMXConnectionNotification.FAILED)) { - // handle disconnect - disconnect(); - } - } - }, null, null); + try { + JMXServiceURL url; + if (jmxUrl == null) { + url = new JMXServiceURL(jmxAgentUrl(host, port)); + } + else { + url = new JMXServiceURL(jmxUrl); + } + Map<String, Object> env = new HashMap<>(); + + connector = JMXConnectorFactory.newJMXConnector(url, env); + connector.connect(); + connector.addConnectionNotificationListener( + new NotificationListener() { - return connector.getMBeanServerConnection(); + @Override + public void handleNotification( + Notification notification, Object handback) { + if (notification.getType().equals( + JMXConnectionNotification.FAILED)) { + // handle disconnect + disconnect(); + } + } + }, null, null); + + return connector.getMBeanServerConnection(); + + } catch (IOException e) { + throw new IntegrityMonitorException(e); + } } /** |