Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Documentation + Cleanup
  • Loading branch information
Markus von Rüden committed Jul 29, 2014
1 parent a2481b6 commit e2b5859
Show file tree
Hide file tree
Showing 28 changed files with 745 additions and 271 deletions.
@@ -1,9 +1,54 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx;

import org.opennms.netmgt.jmx.connection.JmxServerConnectionException;

/**
* The JmxCollector is responsible to collect the configured data at the configured ip address.
*/
public interface JmxCollector {


/**
* Implements the logic for the jmx data collection.
* <p/>
* Therefore it should somehow:
* 1. establish the connection to the configured ip address.
* 2. collect the configured data.
* 3. inform the {@link org.opennms.netmgt.jmx.JmxSampleProcessor} about the collected data.
* <p/>
* The {@link org.opennms.netmgt.jmx.JmxSampleProcessor} is a callback for each sample collected.
* Therefore each sample can be transformed to another data structure (e.g. collectd).
*
* @param config The configuration to use for the collection.
* @param sampleProcessor The callback to process each sample.
* @throws JmxServerConnectionException If the connection to the jmx server could not be established (whatever the reason).
*/
void collect(JmxCollectorConfig config, JmxSampleProcessor sampleProcessor) throws JmxServerConnectionException;
}
@@ -1,3 +1,31 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx;

import org.opennms.netmgt.config.collectd.jmx.JmxCollection;
Expand All @@ -13,6 +41,7 @@ public class JmxCollectorConfig {
private int retries;

private Map<String, String> serviceProperties;

private JmxCollection jmxCollection;

public String getAgentAddress() {
Expand Down
@@ -1,9 +1,51 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx;

import org.opennms.netmgt.jmx.samples.JmxAttributeSample;
import org.opennms.netmgt.jmx.samples.JmxCompositeSample;

/**
* Processes collected JMX Samples.
*/
public interface JmxSampleProcessor {
/**
* Callback method for each collected MBean Attribute.
*
* @param attributeSample The collected sample.
*/
void process(JmxAttributeSample attributeSample);

/**
* Callback method for each collected Composite Member.
*
* @param compositeSample The collected sample.
*/
void process(JmxCompositeSample compositeSample);
}
31 changes: 29 additions & 2 deletions core/jmx/api/src/main/java/org/opennms/netmgt/jmx/JmxUtils.java
@@ -1,14 +1,41 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

// TODO mvr document and add license text
public final class JmxUtils {

/**
* Converts, so that we only have Strings, all non String value parameters will be removed.
* Converts the map, so that it only contains String values. All non String values will be removed (null values included).
* <p/>
* The returned map is not modifiable.
* <p/>
Expand Down
@@ -1,11 +1,70 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx.connection;

import java.util.Map;

/**
* The connection manager is responsible to create a
* {@link org.opennms.netmgt.jmx.connection.JmxServerConnector}
* implementation according to the connectionName and establish a connection using that server connector.
* <p/>
* If no {@link org.opennms.netmgt.jmx.connection.JmxServerConnector} could be used for a given
* connectionName the error handling is up to the implementation.
* <p/>
* If a connection to a JMX Server could not be established the {@link JmxConnectionManager} may try again.
* If a connection manager supports retries is up to the implementation.
*/
public interface JmxConnectionManager {

/**
* Connects to the given <code>ipAddress</code> using the
* {@link org.opennms.netmgt.jmx.connection.JmxServerConnector} registered with <code>connectionString</code>.
* <p/>
* If the connection to the server could not be established (e.g. no retries left) a JmxServerConnectionException is thrown.
*
* @param connectionName The {@link org.opennms.netmgt.jmx.connection.JmxConnectors} name of the connection. May be null.
* @param ipAddress the address to connecto to
* @param connectionProperties properties for the connection (e.g. port, user, etc.)
* @param retryCallback A callback, which should be called BEFORE creating the connection. May be null.
* @return A JmxServerConnectionWrapper for the MBeanServerConnection.
* @throws JmxServerConnectionException if the connection to the given ipAddress using the registered JmxServerConnector could not be established.
*/
JmxServerConnectionWrapper connect(String connectionName, String ipAddress, Map<String, String> connectionProperties, RetryCallback retryCallback) throws JmxServerConnectionException;

/**
* This callback should always be invoked BEFORE invoking
* the {@link org.opennms.netmgt.jmx.connection.JmxServerConnector#createConnection(String, java.util.Map)}
* method.
* <p/>
* It may contain additional logic when a retry is made (e.g. reset a timer)
*/
interface RetryCallback {
void onRetry();
}
Expand Down
@@ -1,6 +1,36 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx.connection;

// TODO name
/**
* All available connectors.
*/
public final class JmxConnectors {

public static final String JSR160 = "jsr160";
Expand Down
@@ -1,7 +1,43 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx.connection;

import java.io.IOException;

/**
* Is used to indicate that a connection to a JMX Server (MBeanServer) could not be established.
* The reason may be that the server is not reachable, or credentials are invalid or
* there is no {@link org.opennms.netmgt.jmx.connection.JmxServerConnector} registered
* for the {@link org.opennms.netmgt.jmx.connection.JmxConnectors}.
* <p/>
* The exception's <code>errorMessage</code> should provide details about the concrete error.
*/
public class JmxServerConnectionException extends Exception {
private static final long serialVersionUID = 1L;

Expand Down
@@ -1,8 +1,42 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.netmgt.jmx.connection;

import javax.management.MBeanServerConnection;
import java.io.Closeable;

/**
* Wraps the established {@link javax.management.MBeanServerConnection}.
* <p/>
* Basically this makes closing an established connection easier, du to the
* <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html">try-resource java 7 language feature</a>.
*/
public interface JmxServerConnectionWrapper extends Closeable {

MBeanServerConnection getMBeanServerConnection();
Expand Down

0 comments on commit e2b5859

Please sign in to comment.