modules/core/plugin-api/pom.xml | 101 ++++ modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ChildResourceTypeDiscoveryFacet.java | 40 + modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java | 111 +++++ modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java | 19 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/AddResourceTypePromptCommand.java | 23 + modules/enterprise/gui/portal-war/src/main/webapp/admin/test/ResourceTypeCreator.jsp | 62 --- modules/plugins/hadoop/pom.xml | 6 modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java | 94 ++-- modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorDiscovery.java | 81 +-- modules/plugins/perftest/pom.xml | 142 ++++++ modules/plugins/pom.xml | 205 ++++++++++ 11 files changed, 729 insertions(+), 155 deletions(-)
New commits: commit 65d71aac8eef3e6fa0ec01205f26c89fe7a2514c Author: Alexander Kiefer alexander.kiefer@dillinger.biz Date: Thu Jul 22 16:13:07 2010 +0200
Several changes necessary to create new ResourceTypes within the NagiosPlugin and make them work in Agent and Server
diff --git a/modules/core/plugin-api/pom.xml b/modules/core/plugin-api/pom.xml new file mode 100644 index 0000000..9def010 --- /dev/null +++ b/modules/core/plugin-api/pom.xml @@ -0,0 +1,101 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.rhq</groupId> + <artifactId>rhq-core-parent</artifactId> + <version>3.0.0.B04</version> + </parent> + + <groupId>org.rhq</groupId> + <artifactId>rhq-core-plugin-api</artifactId> + <packaging>jar</packaging> + + <name>RHQ Plugin API</name> + <description>RHQ Plugin API used to write custom plugins</description> + + <scm> + <connection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/core/plugin-api</connection> + <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/core/plugin-api</developerConnection> + </scm> + + <properties> + <scm.module.path>modules/core/plugin-api/</scm.module.path> + </properties> + + <dependencies> + + <!-- Internal Deps --> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-domain</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-native-system</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- 3rd Party Deps --> + + <!-- TODO: This is a fix for the Javac bug requiring annotations to be + available when compiling dependent classes. It is fixed in JDK 6 --> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + <version>1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>jboss.jboss-embeddable-ejb3</groupId> + <artifactId>hibernate-all</artifactId> + <version>1.0.0.Alpha9</version> + <scope>provided</scope> <!-- by ON Container --> + <!-- needed for referenced domain entities that use Hibernate annotations --> + </dependency> + + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <!-- NOTE: The version is defined in the root POM's dependencyManagement section. --> + </dependency> + + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <!-- NOTE: The version is defined in the root POM's dependencyManagement section. --> + <!--<scope>test</scope> not sure about this --> + </dependency> + + </dependencies> + + <pluginRepositories> + <pluginRepository> + <id>java.net</id> + <name>java.net Maven Repository</name> + <url>http://download.java.net/maven/1/</url> + <layout>legacy</layout> + <snapshots> + <enabled>false</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + + <repositories> + <repository> + <id>java.net</id> + <name>java.net Maven Repository</name> + <url>http://download.java.net/maven/1/</url> + <layout>legacy</layout> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + +</project> diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ChildResourceTypeDiscoveryFacet.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ChildResourceTypeDiscoveryFacet.java new file mode 100644 index 0000000..cf88165 --- /dev/null +++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ChildResourceTypeDiscoveryFacet.java @@ -0,0 +1,40 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program 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 and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.rhq.core.pluginapi.inventory; + +import java.util.Set; + +import org.rhq.core.domain.resource.ResourceType; + +/** + * Interface defines method to discover ChildResourceTypes of existing parentType + * + * @author Alexander Kiefer + * @param <ResourceType> + */ +public interface ChildResourceTypeDiscoveryFacet { + + //ParentResourceType will be given within start method of each Plugin from the context + Set<ResourceType> discoverChildResourceTypes(); +} diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java new file mode 100644 index 0000000..792a97a --- /dev/null +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java @@ -0,0 +1,111 @@ +package org.rhq.core.pc.inventory; + +import java.util.Set; +import java.util.concurrent.Callable; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.rhq.core.domain.measurement.AvailabilityType; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.core.pc.PluginContainer; +import org.rhq.core.pc.util.ComponentUtil; +import org.rhq.core.pc.util.FacetLockType; +import org.rhq.core.pluginapi.inventory.ChildResourceTypeDiscoveryFacet; +import org.rhq.core.util.exception.ThrowableUtil; + +public class ChildResourceTypeDiscoveryRunner implements Callable<Set<ResourceType>>, Runnable { + + private Log log = LogFactory.getLog(ChildResourceTypeDiscoveryRunner.class); + //private MeasurementManager measurementManager; + private int resourceId; + + //TODO: maybe to be implemented for later usage + // public ChildResourceTypeDiscoveryRunner(MeasurementManager measurementManager) { + // + // } + + public ChildResourceTypeDiscoveryRunner(int resourceId) { + this.resourceId = resourceId; + } + + public void run() { + try { + call(); + } catch (Exception e) { + log.error("Could not get measurement report.", e); + } + } + + public Set<ResourceType> call() { + + Set<ResourceType> resourceTypes = null; + + try { + //TODO: + //this.measurementManager.getLock().readLock().lock(); + //report = this.measurementManager.getActiveReport(); + + long start = System.currentTimeMillis(); + + InventoryManager im = PluginContainer.getInstance().getInventoryManager(); + + //Set<ScheduledMeasurementInfo> requests = this.measurementManager.getNextScheduledSet(); + // if (requests != null) { + // if ((System.currentTimeMillis() - 30000L) > requests.iterator().next().getNextCollection()) { + // this.measurementManager.incrementLateCollections(requests.size()); + // log.debug("Measurement collection is falling behind... Missed requested time by [" + // + (System.currentTimeMillis() - requests.iterator().next().getNextCollection()) + "ms]"); + // + // this.measurementManager.reschedule(requests); + // return report; + // } + //Integer resourceId = requests.iterator().next().getResourceId(); + + ResourceContainer container = im.getResourceContainer(this.resourceId); + + if (container.getResourceComponentState() != ResourceContainer.ResourceComponentState.STARTED + || container.getAvailability() == null + || container.getAvailability().getAvailabilityType() == AvailabilityType.DOWN) { + // Don't collect metrics for resources that are down + if (log.isDebugEnabled()) { + log.debug("ChildType not discoverd for inactive resource component: " + container.getResource()); + } + } else { + ChildResourceTypeDiscoveryFacet discoveryComponent = ComponentUtil.getComponent(resourceId, + ChildResourceTypeDiscoveryFacet.class, FacetLockType.READ, 30 * 1000, true, true); + + resourceTypes = discoverChildResourceTypes(discoveryComponent); + } + + } catch (Throwable t) { + log.error("Failed to run ChildType discovery", t); + } + return resourceTypes; + } + + /** + * + * @param discoveryComponent + * @return + */ + private Set<ResourceType> discoverChildResourceTypes(ChildResourceTypeDiscoveryFacet discoveryComponent) { + + Set<ResourceType> resourceTypes = null; + try { + long start = System.currentTimeMillis(); + resourceTypes = discoveryComponent.discoverChildResourceTypes(); + long duration = (System.currentTimeMillis() - start); + + if (duration > 2000) { + log.info("[PERF] Discovery of childResourceTypes for [" + discoveryComponent + "] took [" + duration + + "ms]"); + } + } catch (Throwable t) { + + log.warn("Failure to discover childResourceType data - cause: " + ThrowableUtil.getAllMessages(t)); + } + + return resourceTypes; + } +} diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java index 222d5a5..ea9a4e4 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java @@ -997,6 +997,25 @@ public class InventoryManager extends AgentService implements ContainerService, } catch (Exception e) { throw new RuntimeException("Error submitting service scan", e); } + + /** + * Usage of new implemented ChildResourceTypeDiscoveryRunner + */ + ChildResourceTypeDiscoveryRunner childDiscoveryRunner = new ChildResourceTypeDiscoveryRunner(resourceId); + try { + //get Set<ResourceType> + Set<ResourceType> resourceTypes = inventoryThreadPoolExecutor.submit( + (Callable<Set<ResourceType>>) childDiscoveryRunner).get(); + + //Iterate over all the ResourceTypes contained in the Set + for (ResourceType type : resourceTypes) { + //Create a new ResourceType in the DB for the selected type + this.createNewResourceType(type.getName(), type.getName() + "Metric"); + } + + } catch (Exception e) { + throw new RuntimeException("Error submitting service scan", e); + } }
@Nullable diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/AddResourceTypePromptCommand.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/AddResourceTypePromptCommand.java index 774e7f8..89a22ba 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/AddResourceTypePromptCommand.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/AddResourceTypePromptCommand.java @@ -1,3 +1,26 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program 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 and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package org.rhq.enterprise.agent.promptcmd;
import java.io.PrintWriter; diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/ResourceTypeCreator.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/ResourceTypeCreator.jsp index 218c66d..24f96fe 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/ResourceTypeCreator.jsp +++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/ResourceTypeCreator.jsp @@ -15,7 +15,8 @@ <%@page import="org.rhq.enterprise.server.resource.ResourceTypeManagerBean"%> <%@page import="org.apache.commons.logging.*"%>
-<%@page import="org.rhq.enterprise.server.util.LookupUtil"%><html> +<%@page import="org.rhq.enterprise.server.util.LookupUtil"%> +<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>ResourceTypeCreator</title> @@ -55,65 +56,6 @@ out.println("Please insert the name of the new ResourceType"); } %> - -</body> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> -<%@page import="javax.naming.*"%> -<%@page import="javax.ejb.*"%> -<%@page import="java.rmi.*"%> -<%@page import="java.util.*"%> -<%@page import="org.rhq.enterprise.server.resource.metadata.*"%> -<%@page import="org.rhq.core.domain.plugin.*"%> - -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> - -<%@page import="org.rhq.core.domain.resource.ResourceType"%> -<%@page import="org.rhq.core.domain.resource.ResourceCategory"%> -<%@page import="javax.persistence.NoResultException"%> -<%@page import="org.rhq.enterprise.server.resource.ResourceTypeManagerLocal"%> -<%@page import="org.rhq.enterprise.server.resource.ResourceTypeManagerBean"%> -<%@page import="org.apache.commons.logging.*"%> - -<%@page import="org.rhq.enterprise.server.util.LookupUtil"%><html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> -<title>ResourceTypeCreator</title> -</head> -<body> - <h1>ResourceTypeCreator JSP Page</h1> - - <form action="ResourceTypeCreator.jsp" method="post"> - - Enter the name of the new RessourceType: - <input type="text" name="resourceTypeName" width="150px" height="35px"><br> - <!-- Enter the name of first metric: - <input type="text" name="resourceTypeMetric1Input" width="150px" height="35px"><br> - Enter the name of second metric: - <input type="text" name="resourceTypeMetric2Input" width="150px" height="35px"><br> - Enter the name third metric: - <input type="text" name="resourceTypeMetric3Input" width="150px" height="35px"><br> - --> - - <input type="submit" value="Create new ResourceType"> - - </form> - - <% - /** Creation of parameters for the new ResourceType */ - String resourceTypeName = request.getParameter("resourceTypeName"); - if( resourceTypeName != null ) - { - //After name of new resourceType has been given - out.println("Input:" + resourceTypeName); - - LookupUtil.getResourceMetadataManager().addNewResourceType(resourceTypeName); - } - else - { - out.println("Please insert the name of the new ResourceType"); - } - %> - </body> </html> diff --git a/modules/plugins/hadoop/pom.xml b/modules/plugins/hadoop/pom.xml index f5bfd9a..4065ead 100644 --- a/modules/plugins/hadoop/pom.xml +++ b/modules/plugins/hadoop/pom.xml @@ -9,7 +9,7 @@ <parent> <groupId>org.rhq</groupId> <artifactId>rhq-plugins-parent</artifactId> - <version>3.0.0-SNAPSHOT</version><!-- TODO adjust RHQ version --> + <version>3.0.0.B04</version><!-- TODO adjust RHQ version --> </parent>
<groupId>org.rhq</groupId> @@ -21,7 +21,7 @@
<properties> <scm.module.path>TODO</scm.module.path> - <rhq.version>3.0.0-SNAPSHOT</rhq.version> <!-- TODO adjust, see above too --> + <rhq.version>3.0.0.B04</rhq.version> <!-- TODO adjust, see above too --> </properties>
<build> @@ -182,4 +182,4 @@ <!-- TODO add your dependencies here -->
</dependencies> -</project> \ No newline at end of file +</project> diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java index f3f6d54..e5b67b4 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java @@ -1,4 +1,5 @@ package org.rhq.plugins.nagios; + /* * RHQ Management Platform * Copyright (C) 2005-2008 Red Hat, Inc. @@ -18,6 +19,7 @@ package org.rhq.plugins.nagios; * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -25,19 +27,22 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.measurement.DataType; -import org.rhq.plugins.nagios.controller.NagiosManagementInterface; -import org.rhq.plugins.nagios.data.NagiosSystemData; import org.rhq.core.domain.configuration.Configuration; -import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException; import org.rhq.core.domain.measurement.AvailabilityType; +import org.rhq.core.domain.measurement.DataType; import org.rhq.core.domain.measurement.MeasurementDataNumeric; import org.rhq.core.domain.measurement.MeasurementDataTrait; import org.rhq.core.domain.measurement.MeasurementReport; import org.rhq.core.domain.measurement.MeasurementScheduleRequest; +import org.rhq.core.domain.resource.ResourceCategory; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.core.pluginapi.inventory.ChildResourceTypeDiscoveryFacet; +import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException; import org.rhq.core.pluginapi.inventory.ResourceComponent; import org.rhq.core.pluginapi.inventory.ResourceContext; import org.rhq.core.pluginapi.measurement.MeasurementFacet; +import org.rhq.plugins.nagios.controller.NagiosManagementInterface; +import org.rhq.plugins.nagios.data.NagiosSystemData; import org.rhq.plugins.nagios.error.NagiosException;
/** @@ -48,9 +53,8 @@ import org.rhq.plugins.nagios.error.NagiosException; * * @author Alexander Kiefer */ -public class NagiosMonitorComponent implements ResourceComponent, MeasurementFacet -{ - private final Log log = LogFactory.getLog(this.getClass()); +public class NagiosMonitorComponent implements ResourceComponent, MeasurementFacet, ChildResourceTypeDiscoveryFacet { + private final Log log = LogFactory.getLog(this.getClass());
public static final String DEFAULT_NAGIOSIP = "127.0.0.1"; public static final String DEFAULT_NAGIOSPORT = "6557"; @@ -64,13 +68,12 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac * Return availability of this resource * @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability() */ - public AvailabilityType getAvailability() - { + public AvailabilityType getAvailability() { if (context.getParentResourceComponent() instanceof NagiosMonitorComponent) { return AvailabilityType.UP; // TODO get from parent? } else { boolean available = false; - if (nagiosManagementInterface!=null) + if (nagiosManagementInterface != null) available = nagiosManagementInterface.pingNagios();
if (available) @@ -83,14 +86,14 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac * Start the resource connection * @see org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext) */ - public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception - { - //get context of this component instance - this.context = context; + public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception { + //get context of this component instance + this.context = context;
- //get config + //get config if (context.getParentResourceComponent() instanceof NagiosMonitorComponent) { NagiosMonitorComponent parent = (NagiosMonitorComponent) context.getParentResourceComponent(); + nagiosHost = parent.getNagiosHost(); nagiosPort = parent.getNagiosPort(); } else { @@ -103,16 +106,14 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac //Interface class to the nagios system nagiosManagementInterface = new NagiosManagementInterface(nagiosHost, nagiosPort);
- //log.info("nagios Plugin started"); + //log.info("nagios Plugin started"); }
- /** * Tear down the rescource connection * @see org.rhq.core.pluginapi.inventory.ResourceComponent#stop() */ - public void stop() - { + public void stop() {
}
@@ -120,32 +121,26 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac * Gather measurement data * @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set) */ - public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) - { + public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) { NagiosSystemData nagiosSystemData = null; String serviceName = this.context.getResourceType().getName(); log.info("getValues() of ResourceType: " + serviceName);
- try - { + try { //Getting all Nagios system information - nagiosSystemData = nagiosManagementInterface.createNagiosSystemData(); - } - catch (Exception e) - { + nagiosSystemData = nagiosManagementInterface.createNagiosSystemData(); + } catch (Exception e) { log.warn(" Can not get information from Nagios: ", e); return; }
//iterating over the metrics - for (MeasurementScheduleRequest req : metrics) - { - try - { // Don't let one bad egg spoil the cake + for (MeasurementScheduleRequest req : metrics) { + try { // Don't let one bad egg spoil the cake
- String[] splitter = req.getName().split("\|"); - String property = splitter[1]; - String pattern = splitter[2]; + String[] splitter = req.getName().split("\|"); + String property = splitter[1]; + String pattern = splitter[2];
if (log.isDebugEnabled()) { log.debug("Name of Metric: " + property); @@ -153,7 +148,8 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac }
// Get "raw" data from nagios data structures - we need to pick our value below - String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost").getValue(); // TODO use 'real' host + String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost") + .getValue(); // TODO use 'real' host
Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(value); @@ -164,20 +160,16 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac if (req.getDataType() == DataType.MEASUREMENT) { MeasurementDataNumeric res = new MeasurementDataNumeric(req, Double.valueOf(val)); report.addData(res); - } - else if(req.getDataType() == DataType.TRAIT) { + } else if (req.getDataType() == DataType.TRAIT) { MeasurementDataTrait res = new MeasurementDataTrait(req, val); report.addData(res); - } - else + } else log.error("Unknown DataType for request " + req); + } else { + log.warn("Pattern >>" + pattern + "<< did not match for input >>" + value + "<< and request: >>" + + req.getName()); } - else { - log.warn("Pattern >>" + pattern + "<< did not match for input >>" + value + "<< and request: >>" + req.getName()); - } - } - catch (NagiosException e) - { + } catch (NagiosException e) { log.error(e); } } @@ -190,4 +182,16 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac public int getNagiosPort() { return nagiosPort; } + + public Set<ResourceType> discoverChildResourceTypes() { + + ResourceType parentType = this.context.getResourceType(); + ResourceType resourceType = new ResourceType("NewChild", parentType.getPlugin(), ResourceCategory.SERVICE, + parentType); + + Set<ResourceType> resourceTypes = new HashSet<ResourceType>(); + resourceTypes.add(resourceType); + + return resourceTypes; + } } \ No newline at end of file diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorDiscovery.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorDiscovery.java index 8f0a879..fd79f3b 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorDiscovery.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorDiscovery.java @@ -1,4 +1,5 @@ package org.rhq.plugins.nagios; + /* * RHQ Management Platform * Copyright (C) 2005-2008 Red Hat, Inc. @@ -20,6 +21,7 @@ package org.rhq.plugins.nagios;
import java.util.HashSet; import java.util.Set; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
@@ -31,18 +33,17 @@ import org.rhq.core.pluginapi.inventory.ManualAddFacet; import org.rhq.core.pluginapi.inventory.ResourceComponent; import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent; import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext; +import org.rhq.plugins.nagios.NagiosMonitorComponent; import org.rhq.plugins.nagios.network.NetworkConnection; import org.rhq.plugins.nagios.reply.LqlReply; import org.rhq.plugins.nagios.request.LqlResourceTypeRequest;
- /** * Discovery class * *@author Alexander Kiefer */ -public class NagiosMonitorDiscovery implements ResourceDiscoveryComponent, ManualAddFacet -{ +public class NagiosMonitorDiscovery implements ResourceDiscoveryComponent, ManualAddFacet { private final Log log = LogFactory.getLog(this.getClass());
/** @@ -52,20 +53,15 @@ public class NagiosMonitorDiscovery implements ResourceDiscoveryComponent, Manua * @return Our server type * @throws org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException */ - public DiscoveredResourceDetails discoverResource(Configuration configuration, ResourceDiscoveryContext resourceDiscoveryContext) throws InvalidPluginConfigurationException { - - String nagiosHost = configuration.getSimpleValue("nagiosHost",NagiosMonitorComponent.DEFAULT_NAGIOSIP); - String nagiosPort = configuration.getSimpleValue("nagiosPort",NagiosMonitorComponent.DEFAULT_NAGIOSPORT); - - DiscoveredResourceDetails detail = new DiscoveredResourceDetails ( - resourceDiscoveryContext.getResourceType(), - "nagios@"+nagiosHost+":"+nagiosPort, - "Nagios@"+nagiosHost+":"+nagiosPort, - null, - "Nagios server @ " + nagiosHost + ":" + nagiosPort, - configuration, - null - ); + public DiscoveredResourceDetails discoverResource(Configuration configuration, + ResourceDiscoveryContext resourceDiscoveryContext) throws InvalidPluginConfigurationException { + + String nagiosHost = configuration.getSimpleValue("nagiosHost", NagiosMonitorComponent.DEFAULT_NAGIOSIP); + String nagiosPort = configuration.getSimpleValue("nagiosPort", NagiosMonitorComponent.DEFAULT_NAGIOSPORT); + + DiscoveredResourceDetails detail = new DiscoveredResourceDetails(resourceDiscoveryContext.getResourceType(), + "nagios@" + nagiosHost + ":" + nagiosPort, "Nagios@" + nagiosHost + ":" + nagiosPort, null, + "Nagios server @ " + nagiosHost + ":" + nagiosPort, configuration, null); log.info("Adding NagiosMonitor " + detail);
return detail; @@ -79,7 +75,7 @@ public class NagiosMonitorDiscovery implements ResourceDiscoveryComponent, Manua
// If we have no parent, it means the NagioMonitoring server type is not yet up. ResourceComponent tmpComponent = discoveryContext.getParentResourceComponent(); - if (tmpComponent ==null || !(tmpComponent instanceof NagiosMonitorComponent)) + if (tmpComponent == null || !(tmpComponent instanceof NagiosMonitorComponent)) return discoveredResources;
NagiosMonitorComponent parentComponent = (NagiosMonitorComponent) tmpComponent; @@ -91,50 +87,41 @@ public class NagiosMonitorDiscovery implements ResourceDiscoveryComponent, Manua
// the resource type we are interested in this invocation ResourceType wanted = discoveryContext.getResourceType(); - //for each available service - for(int i = 0; i < resourceTypeReply.getLqlReply().size(); i++) - { + //for each available service + for (int i = 0; i < resourceTypeReply.getLqlReply().size(); i++) {
String nagiosType = resourceTypeReply.getLqlReply().get(i); if (!nagiosType.equals(wanted.getName())) - continue; + continue;
//create new DiscoveredResourceDetails instance - DiscoveredResourceDetails detail = new DiscoveredResourceDetails - ( - //new ResourceType instance per service - wanted, - "nagiosKey@" + "Nr:" + i + ":" + resourceTypeReply.getLqlReply().get(i), - "Nagios@" + "Nr:" + i + ":" + resourceTypeReply.getLqlReply().get(i), - null, - "NagiosService: " + resourceTypeReply.getLqlReply().get(i), - null, - null - ); - - //add DiscoveredResourceDetails instance to Set - discoveredResources.add(detail); + DiscoveredResourceDetails detail = new DiscoveredResourceDetails( + //new ResourceType instance per service + wanted, "nagiosKey@" + "Nr:" + i + ":" + resourceTypeReply.getLqlReply().get(i), "Nagios@" + "Nr:" + i + + ":" + resourceTypeReply.getLqlReply().get(i), null, "NagiosService: " + + resourceTypeReply.getLqlReply().get(i), null, null); + + //add DiscoveredResourceDetails instance to Set + discoveredResources.add(detail); log.info("Discovered a nagios service: " + detail); - } + }
- return discoveredResources; - } + return discoveredResources; + }
/** * Don't run the auto-discovery of this "nagios" server type, * as we probably won't have one on each platform. Rather have the admin * explicitly add it to one platform. */ + private LqlReply getResourceTypeInformation(String nagiosIp, int nagiosPort) { + LqlResourceTypeRequest resourceTypeRequest = new LqlResourceTypeRequest(); + LqlReply resourceTypeReply;
- private LqlReply getResourceTypeInformation(String nagiosIp, int nagiosPort) - { - LqlResourceTypeRequest resourceTypeRequest = new LqlResourceTypeRequest(); - LqlReply resourceTypeReply; - - NetworkConnection connection = new NetworkConnection(nagiosIp, nagiosPort); - resourceTypeReply = connection.sendAndReceive(resourceTypeRequest); + NetworkConnection connection = new NetworkConnection(nagiosIp, nagiosPort); + resourceTypeReply = connection.sendAndReceive(resourceTypeRequest);
- return resourceTypeReply; + return resourceTypeReply; }
} \ No newline at end of file diff --git a/modules/plugins/perftest/pom.xml b/modules/plugins/perftest/pom.xml new file mode 100644 index 0000000..7e6310b --- /dev/null +++ b/modules/plugins/perftest/pom.xml @@ -0,0 +1,142 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.rhq</groupId> + <artifactId>rhq-plugins-parent</artifactId> + <version>3.0.0.B04</version> + </parent> + + <groupId>org.rhq</groupId> + <artifactId>rhq-perftest-plugin</artifactId> + <packaging>jar</packaging> + + <name>RHQ Performance Test Plugin</name> + <description>a plugin for performance testing</description> + + <scm> + <connection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/plugins/perftest</connection> + <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/plugins/perftest</developerConnection> + </scm> + + <properties> + <scm.module.path>modules/plugins/perftest/</scm.module.path> + </properties> + + <dependencies> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <!-- NOTE: The version is defined in the root POM's dependencyManagement section. --> + </dependency> + + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <!-- NOTE: The version is defined in the root POM's dependencyManagement section. --> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>com.sun.tools.xjc.maven2</groupId> + <artifactId>maven-jaxb-plugin</artifactId> + <version>1.1</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <configuration> + <generatePackage>org.rhq.plugins.perftest.scenario</generatePackage> + <generateDirectory>${basedir}/target/generated-sources/xjc</generateDirectory> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <version>2.0</version> + <executions> + <execution> + <id>copy-jaxb-deps</id> + <phase>process-resources</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + </artifactItem> + <artifactItem> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + </artifactItem> + </artifactItems> + <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + <executions> + <execution> + <id>surefire-it</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>${maven.test.skip}</skip> + <excludedGroups>${rhq.testng.excludedGroups}</excludedGroups> + <useSystemClassLoader>false</useSystemClassLoader> + <argLine>-Djava.library.path=${basedir}/target/itest/lib</argLine> + <!-- + <argLine>-Djava.library.path=${basedir}/target/itest/lib -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</argLine> + --> + + <systemProperties> + <property> + <name>project.artifactId</name> + <value>${project.artifactId}</value> + </property> + <property> + <name>project.version</name> + <value>${project.version}</value> + </property> + </systemProperties> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <pluginRepositories> + <pluginRepository> + <id>java.net</id> + <name>java.net Maven Repository</name> + <url>http://download.java.net/maven/1/</url> + <layout>legacy</layout> + </pluginRepository> + </pluginRepositories> + +</project> diff --git a/modules/plugins/pom.xml b/modules/plugins/pom.xml new file mode 100644 index 0000000..204c00c --- /dev/null +++ b/modules/plugins/pom.xml @@ -0,0 +1,205 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.rhq</groupId> + <artifactId>rhq-parent</artifactId> + <version>3.0.0.B04</version> + </parent> + + <groupId>org.rhq</groupId> + <artifactId>rhq-plugins-parent</artifactId> + <packaging>pom</packaging> + + <name>RHQ Plugins</name> + <description>parent POM for all RHQ plugins</description> + + <scm> + <connection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/plugins</connection> + <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/plugins</developerConnection> + </scm> + + <properties> + <scm.module.path>modules/plugins/</scm.module.path> + </properties> + + <dependencies> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-domain</artifactId> + <version>${project.version}</version> + <scope>provided</scope> <!-- by PC --> + </dependency> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-plugin-api</artifactId> + <version>${project.version}</version> + <scope>provided</scope> <!-- by PC --> + </dependency> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-native-system</artifactId> + <version>${project.version}</version> + <scope>provided</scope> <!-- by PC --> + </dependency> + + <dependency> + <groupId>${rhq.groupId}</groupId> + <artifactId>rhq-core-plugin-container</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <!-- + TODO: This is a fix for the Javac bug requiring annotations to be available when compiling dependent classes. + It is fixed in JDK 6. + --> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + <version>1.0</version> + <scope>provided</scope> <!-- by RHQ container --> + </dependency> + + <!-- + TODO: This is a fix for the Javac bug requiring annotations to be available when compiling dependent classes; + it is fixed in JDK 6. + --> + <dependency> + <groupId>jboss.jboss-embeddable-ejb3</groupId> + <artifactId>hibernate-all</artifactId> + <version>1.0.0.Alpha9</version> + <scope>provided</scope> <!-- by RHQ container --> + </dependency> + + </dependencies> + + <!-- !!! --> + <!-- These profile groupings need to also be mirrored in server/ear/pom.xml --> + <!-- !!! --> + + <modules> + <!-- core plugins --> + <module>platform</module> + <module>rhq-agent</module> + <module>jmx</module> + <module>nagios</module> + </modules> + + <profiles> + + <profile> + <id>jboss-plugins</id> + <activation> + <property> + <name>java.home</name> + </property> + </activation> + + <modules> + <!-- NOTE: Order is important. --> + <module>augeas</module> + <module>apache</module> + <module>tomcat</module> + <module>jboss-as</module> + <module>hibernate</module> + <module>rhq-server</module> + <module>jboss-cache</module> + <module>jboss-as-5</module> + <module>jboss-cache-v3</module> + <!-- was not in Jopr build at merge time <module>jbossOSGi</module> --> + </modules> + </profile> + + <profile> + <id>bundle-plugins</id> + <activation> + <property> + <name>java.home</name> + </property> + </activation> + + <modules> + <module>filetemplate-bundle</module> + <module>ant-bundle</module> + </modules> + </profile> + + <profile> + <id>linux-plugins</id> + <activation> + <property> + <name>java.home</name> + </property> + </activation> + + <modules> + <module>augeas</module> + <module>cron</module> + <module>script</module> + <module>grub</module> + <!-- not behaving <module>hardware</module> --> + <module>hosts</module> + <module>cobbler</module> + <module>sudoers</module> + <module>netservices</module> + <module>samba</module> + <module>postfix</module> + <module>aliases</module> + <module>sshd</module> + </modules> + </profile> + + + <profile> + <id>misc-plugins</id> + <activation> + <property> + <name>java.home</name> + </property> + </activation> + + <modules> + <module>byteman</module> + + <module>iis</module> + <module>database</module> + <module>postgres</module> + <module>hadoop</module> + <module>hudson</module> + <!-- error in code generation (see RHQ-1225) <module>jira</module> --> + <module>mysql</module> + <!-- non-public dependency <module>onewire</module> --> + <module>oracle</module> + <module>perftest</module> + <module>script2</module> + <module>snmptrapd</module> + <!--<module>twitter</module>--> + <module>virt</module> + <module>kickstart</module> + + </modules> + </profile> + + <profile> + <id>validate-plugins</id> + <activation> + <property> + <name>java.home</name> + </property> + </activation> + + <modules> + <!-- make this the last - it will validate all the plugins --> + <module>validate-all-plugins</module> + </modules> + </profile> + + </profiles> + +</project> +
rhq-commits@lists.fedorahosted.org