[rhq] modules/enterprise
by Libor Zoubek
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/EventHandlerBean.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
New commits:
commit 92933d7ad54d9002f294fb575bb4f299fd6078bb
Author: Libor Zoubek <lzoubek(a)redhat.com>
Date: Wed Feb 5 14:05:58 2014 +0100
REST: respect order of submitted events
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/EventHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/EventHandlerBean.java
index 1ccef83..23455d4 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/EventHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/EventHandlerBean.java
@@ -20,7 +20,7 @@ package org.rhq.enterprise.server.rest;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -333,13 +333,14 @@ public class EventHandlerBean extends AbstractRestBean {
@POST
@Path("/source/{id}/events")
- @ApiOperation("Submit multiple events for one given event source; the event source in the passed Events is ignored.")
+ @ApiOperation("Submit multiple events for one given event source; the event source in the passed Events is ignored. "+
+ "Make sure your events are ordered by timestamp to get alerts fired correctly.")
public Response addEventsToSource(@ApiParam("Id of the source to add data to") @PathParam("id") int sourceId,
List<EventRest> eventRest) {
EventSource source = findEventSourceById(sourceId);
Map<EventSource,Set<Event>> eventMap = new HashMap<EventSource, Set<Event>>();
- Set<Event> events = new HashSet<Event>(eventRest.size());
+ Set<Event> events = new LinkedHashSet<Event>(eventRest.size());
for (EventRest eRest : eventRest) {
EventSeverity eventSeverity = EventSeverity.valueOf(eRest.getSeverity());
Event event = new Event(eRest.getTimestamp(),eventSeverity,source,eRest.getDetail());
10 years, 4 months
[rhq] modules/core modules/plugins
by Thomas Segismont
modules/core/plugin-container/src/main/java/org/rhq/core/pc/ContainerService.java | 62 --
modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java | 221 +++-------
modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java | 11
modules/core/plugin-container/src/main/java/org/rhq/core/pc/agent/AgentService.java | 129 +----
modules/core/plugin-container/src/main/java/org/rhq/core/pc/availability/AvailabilityContextImpl.java | 23 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java | 69 ---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java | 30 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java | 43 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManagerInitializer.java | 41 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentContextImpl.java | 56 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java | 44 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/CreateContentRunner.java | 65 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java | 49 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java | 98 +---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java | 48 --
modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventManager.java | 45 --
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AutoDiscoveryExecutor.java | 41 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java | 27 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java | 38 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java | 151 +++---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java | 40 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java | 10
modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java | 16
modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java | 111 ++---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationContextImpl.java | 55 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java | 26 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationThreadPoolGateway.java | 49 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginComponentFactory.java | 87 +--
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginLifecycleListenerManagerImpl.java | 30 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java | 110 ++--
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginValidator.java | 23 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java | 20
modules/core/plugin-container/src/main/java/org/rhq/core/pc/upgrade/ResourceUpgradeDelegate.java | 19
modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java | 17
modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java | 33 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/BundleManagerTest.java | 91 ++--
modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/MockAgentServiceStreamRemoter.java | 41 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java | 54 +-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationManagerTest.java | 25 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java | 21
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java | 35 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/OperationManagerTest.java | 27 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/ParallelOperationsTest.java | 27 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/plugin/PluginManagerTest.java | 63 +-
modules/core/plugin-container/src/test/java/org/rhq/test/pc/PluginContainerTest.java | 17
modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java | 6
modules/plugins/cassandra/src/test/java/org/rhq/plugins/cassandra/itest/DiscoveryAndConfigurationTest.java | 14
modules/plugins/database/src/test/java/org/rhq/plugins/database/ComponentTest.java | 14
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/domain/SecurityModuleOptionsTest.java | 1
modules/plugins/mysql/src/test/java/org/rhq/plugins/mysql/ComponentTest.java | 6
modules/plugins/oracle/src/test/java/org/rhq/plugins/oracle/ComponentTest.java | 16
modules/plugins/snmptrapd/src/test/java/org/rhq/plugins/snmptrapd/ComponentTest.java | 30 +
52 files changed, 1041 insertions(+), 1384 deletions(-)
New commits:
commit 79a09a0a5a5402539f7a54668813f60ba274ce5a
Author: Elias Ross <genman(a)noderunner.net>
Date: Thu Nov 21 15:45:20 2013 +0100
Bug 991149 - Refactor Plugin Container Services initialization
Since there have been other race conditions in the past (as documented in the
code in a few spots), it feels there is an overall design issue at fault:
Objects are initialized in arbitrary order, enforced by the use of 'listeners',
but this was done as a reaction to what bugs were found.
The solution employed here is to use constructors and immutability when
possible. Handles to other components should be done using object fields, not
an object registry/singleton pattern. I tried to eliminate the use of
PluginContainer.getInstance().getXXX(), since in many cases references could be
null depending on the order of how objects are initialized. It also makes clear
what objects really depend on what objects. The use of 'PC.getInstance()'
should probably be entirely removed, since it's bug-prone, but I'll leave the
rest of the cleanup for later.
Testability is generally improved, as test/mock instances can simply be
'injected' using the constructor, not by having to create methods
that get overridden.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ContainerService.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ContainerService.java
index 20f84f3..45450ed 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ContainerService.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ContainerService.java
@@ -1,53 +1,35 @@
- /*
- * 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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc;
/**
- * An interface that all plugin container services and managers will implement. It mainly is to support the lifecycle of
- * the container services so the {@link PluginContainer} can start and stop them when it, itself, starts and stops.
+ * An interface that all plugin container services and managers will implement.
+ * Hook so container service can stop these components.
*
* @author Greg Hinkle
* @author John Mazzitelli
*/
public interface ContainerService {
- /**
- * Initializes the container service which will effectively tell the service to start doing its work.
- * Implementations of this interface can be assured that prior to this method being called, a non-<code>null</code>
- * configuration will be set via a call to {@link #setConfiguration(PluginContainerConfiguration)}.
- */
- void initialize();
/**
* Stops the container service which effectively releases all runtime resources such as running threads.
*/
void shutdown();
-
- /**
- * Informs the container service how it should be configured by providing the full plugin container configuration.
- * The plugin container will ensure it passes in a non-<code>null</code> configuration object so implementations of
- * this interface should never have to worry about a <code>null</code> <code>configuration</code> parameter value.
- *
- * @param configuration
- */
- void setConfiguration(PluginContainerConfiguration configuration);
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java
index a6ff34a..fe64a46 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java
@@ -1,34 +1,29 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc;
import java.beans.Introspector;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
@@ -55,8 +50,9 @@ import org.rhq.core.pc.agent.AgentService;
import org.rhq.core.pc.agent.AgentServiceLifecycleListener;
import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.bundle.BundleManager;
+import org.rhq.core.pc.configuration.ConfigManagementFactory;
+import org.rhq.core.pc.configuration.ConfigManagementFactoryImpl;
import org.rhq.core.pc.configuration.ConfigurationManager;
-import org.rhq.core.pc.configuration.ConfigurationManagerInitializer;
import org.rhq.core.pc.content.ContentManager;
import org.rhq.core.pc.drift.DriftManager;
import org.rhq.core.pc.event.EventManager;
@@ -66,8 +62,12 @@ import org.rhq.core.pc.inventory.ResourceFactoryManager;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationManager;
import org.rhq.core.pc.plugin.PluginComponentFactory;
+import org.rhq.core.pc.plugin.PluginLifecycleListenerManager;
+import org.rhq.core.pc.plugin.PluginLifecycleListenerManagerImpl;
import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pc.support.SupportManager;
+import org.rhq.core.pc.util.ComponentService;
+import org.rhq.core.pc.util.ComponentServiceImpl;
import org.rhq.core.pc.util.LoggingThreadFactory;
import org.rhq.core.pluginapi.util.FileUtils;
@@ -87,7 +87,7 @@ public class PluginContainer {
private static final PluginContainer INSTANCE = new PluginContainer();
- private final Log log = LogFactory.getLog(PluginContainer.class);
+ private static final Log log = LogFactory.getLog(PluginContainer.class);
private static final class NullRebootRequestListener implements RebootRequestListener {
@Override
@@ -95,34 +95,12 @@ public class PluginContainer {
}
}
- /**
- * Invoked by the plugin container immediately after it is initialized
- */
- public static interface InitializationListener {
- /**
- * Notifies the listener that the plugin container has been initialized. This method executes in the same
- * thread in which {@link PluginContainer#initialize()} is executing.
- */
- void initialized();
- }
-
- /**
- * Invoked by the plugin container immediately after it is shutdown
- */
- public static interface ShutdownListener {
- /**
- * Notifies the listener that the plugin container has been shutdown. This method executes in the same
- * thread in which {@link PluginContainer#shutdown()} is executing.
- */
- void shutdown();
- }
-
// our management interface
private PluginContainerMBeanImpl mbean;
private PluginContainerConfiguration configuration;
private String version;
- private boolean started = false;
+ private volatile boolean started = false;
private PluginManager pluginManager;
private PluginComponentFactory pluginComponentFactory;
@@ -137,22 +115,18 @@ public class PluginContainer {
private BundleManager bundleManager;
private DriftManager driftManager;
- private Collection<AgentServiceLifecycleListener> agentServiceListeners = new LinkedHashSet<AgentServiceLifecycleListener>();
+ private final Collection<AgentServiceLifecycleListener> agentServiceListeners = new CopyOnWriteArraySet<AgentServiceLifecycleListener>();
private AgentServiceStreamRemoter agentServiceStreamRemoter = null;
private AgentRegistrar agentRegistrar = null;
private RebootRequestListener rebootListener = new NullRebootRequestListener();
// this is to prevent race conditions on startup between components from all the different managers
- private ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
- private List<InitializationListener> initListeners = new ArrayList<InitializationListener>();
- private List<ShutdownListener> shutdownListeners = new ArrayList<ShutdownListener>();
- private Object initListenersLock = new Object();
- private Object shutdownListenersLock = new Object();
- private boolean shuttingDown;
private long shutdownStartTime;
private boolean shutdownGracefully;
+ private volatile boolean shuttingDown;
/**
* Returns the singleton instance.
@@ -309,31 +283,28 @@ public class PluginContainer {
ResourceContainer.initialize(configuration);
- pluginManager = new PluginManager();
- pluginComponentFactory = new PluginComponentFactory();
- inventoryManager = new InventoryManager();
- measurementManager = new MeasurementManager();
- configurationManager = new ConfigurationManager();
- operationManager = new OperationManager();
- resourceFactoryManager = new ResourceFactoryManager();
- contentManager = new ContentManager();
+ PluginLifecycleListenerManager pluginLifecycle = new PluginLifecycleListenerManagerImpl();
+ pluginManager = new PluginManager(configuration, pluginLifecycle);
eventManager = new EventManager(configuration);
- supportManager = new SupportManager();
- bundleManager = new BundleManager();
- driftManager = new DriftManager();
-
- startContainerService(pluginManager);
- startContainerService(pluginComponentFactory);
- startContainerService(inventoryManager);
- startContainerService(measurementManager);
- startContainerService(configurationManager);
- startContainerService(operationManager);
- startContainerService(resourceFactoryManager);
- startContainerService(contentManager);
- startContainerService(eventManager);
- startContainerService(supportManager);
- startContainerService(bundleManager);
- startContainerService(driftManager);
+ inventoryManager = new InventoryManager(configuration, agentServiceStreamRemoter, pluginManager, eventManager);
+ inventoryManager.initialize();
+ measurementManager = inventoryManager.getMeasurementManager();
+ pluginComponentFactory = inventoryManager.getPluginComponentFactory();
+ ComponentService componentService = new ComponentServiceImpl(pluginManager);
+ ConfigManagementFactory factory = new ConfigManagementFactoryImpl(componentService);
+ configurationManager = new ConfigurationManager(configuration, componentService, factory, agentServiceStreamRemoter, inventoryManager);
+ operationManager = new OperationManager(configuration, agentServiceStreamRemoter);
+ resourceFactoryManager = new ResourceFactoryManager(configuration, agentServiceStreamRemoter, pluginManager);
+ contentManager = new ContentManager(configuration, agentServiceStreamRemoter, inventoryManager);
+ supportManager = new SupportManager(agentServiceStreamRemoter);
+ bundleManager = new BundleManager(configuration, agentServiceStreamRemoter, inventoryManager, measurementManager);
+ driftManager = new DriftManager(configuration, agentServiceStreamRemoter, inventoryManager);
+
+ for (AgentServiceLifecycleListener ll : agentServiceListeners) {
+ for (AgentService service : services()) {
+ ll.started(service);
+ }
+ }
started = true;
@@ -341,16 +312,22 @@ public class PluginContainer {
} finally {
releaseLock(lock);
}
+ }
- synchronized (initListenersLock) {
- if (started) {
- for (InitializationListener listener : initListeners) {
- listener.initialized();
- }
- }
- }
-
- return;
+ /**
+ * Agent services, returned in alphabetical order...
+ */
+ private AgentService[] services() {
+ return new AgentService[] {
+ bundleManager,
+ configurationManager,
+ contentManager,
+ driftManager,
+ inventoryManager,
+ measurementManager,
+ operationManager,
+ resourceFactoryManager,
+ supportManager };
}
/**
@@ -383,6 +360,12 @@ public class PluginContainer {
mbean = null;
}
+ for (AgentServiceLifecycleListener ll : agentServiceListeners) {
+ for (AgentService service : services()) {
+ ll.stopped(service);
+ }
+ }
+
if (configuration.isWaitForShutdownServiceTermination()) {
log.info("Plugin container shutdown will wait up to "
+ configuration.getShutdownServiceTerminationTimeout()
@@ -403,7 +386,6 @@ public class PluginContainer {
pluginManager.shutdown();
agentServiceListeners.clear();
- agentServiceListeners = new LinkedHashSet<AgentServiceLifecycleListener>();
agentServiceStreamRemoter = null;
agentRegistrar = null;
@@ -440,7 +422,6 @@ public class PluginContainer {
configuration = null;
started = false;
- shuttingDown = false;
log.info("Plugin container is now shutdown.");
@@ -448,18 +429,11 @@ public class PluginContainer {
if (isInsideAgent) {
cleanMemory();
}
+ shuttingDown = false;
} finally {
releaseLock(lock);
}
- synchronized (shutdownListenersLock) {
- if (!started) {
- for (ShutdownListener listener : shutdownListeners) {
- listener.shutdown();
- }
- }
- }
-
return shutdownGracefully;
}
@@ -488,35 +462,6 @@ public class PluginContainer {
}
}
- private void startContainerService(ContainerService containerService) {
- log.debug("Starting and configuring container service: " + containerService.getClass().getSimpleName());
-
- containerService.setConfiguration(configuration);
-
- AgentService agentService = null;
-
- if (containerService instanceof AgentService) {
- agentService = (AgentService) containerService;
-
- agentService.setAgentServiceStreamRemoter(agentServiceStreamRemoter);
-
- for (AgentServiceLifecycleListener agentServiceListener : agentServiceListeners) {
- agentService.addLifecycleListener(agentServiceListener);
- }
-
- if (containerService instanceof ConfigurationManager) {
- ConfigurationManagerInitializer initializer = new ConfigurationManagerInitializer();
- initializer.initialize((ConfigurationManager) containerService);
- }
- }
-
- containerService.initialize();
-
- if (agentService != null) {
- agentService.notifyLifecycleListenersOfNewState(AgentService.LifecycleState.STARTED);
- }
- }
-
private Lock obtainReadLock() {
// try to obtain the lock, but if we can't get the lock in 60 seconds,
// keep going. The PC is usually fine within seconds after its initializes,
@@ -580,6 +525,8 @@ public class PluginContainer {
public PluginComponentFactory getPluginComponentFactory() {
Lock lock = obtainReadLock();
try {
+ if (pluginComponentFactory == null)
+ throw new IllegalStateException("pcf");
return pluginComponentFactory;
} finally {
releaseLock(lock);
@@ -741,37 +688,6 @@ public class PluginContainer {
}
/**
- * Add the callback listener to notify when the plugin container is initialized. If this method is invoked and
- * the PC is already initialized, then <code>listener</code> will be invoked immediately.
- *
- * @param listener The callback object to notify. If a listener with the supplied name is registered, it
- * will be replaced with the newly supplied listner.
- */
- public void addInitializationListener(InitializationListener listener) {
- synchronized (initListenersLock) {
- initListeners.add(listener);
-
- if (started) {
- listener.initialized();
- }
- }
- }
-
- /**
- * Add the callback listener to notify when the plugin container is shutdown. Unlike
- * {@link #addInitializationListener(String, InitializationListener)} the <code>listener</code> will
- * not be invoked immediately if the PC is already shutdown. It will only be invoked on future shutdowns.
- *
- * @param listener The callback object to notify. If a listener with the supplied name is registered, it
- * will be replaced with the newly supplied listener.
- */
- public void addShutdownListener(String name, ShutdownListener listener) {
- synchronized (shutdownListenersLock) {
- shutdownListeners.add(listener);
- }
- }
-
- /**
* Initiate shutdown of the specified executor service. If the "waitForShutdownServiceTermination" plugin
* container configuration property is "true" and the "shutdownServiceTerminationTimeout" has not already expired,
* then wait for the service to terminate before returning. With the exception of test code, this method should only
@@ -781,7 +697,14 @@ public class PluginContainer {
*
* @return true if the executor service terminated, or false if it is still shutting down
*/
- public boolean shutdownExecutorService(ExecutorService executorService, boolean now) {
+ public static boolean shutdownExecutorService(ExecutorService executorService, boolean now) {
+ if (executorService == null) {
+ throw new NullPointerException("executorService is null");
+ }
+ return getInstance().shutdownExecutorService0(executorService, now);
+ }
+
+ private boolean shutdownExecutorService0(ExecutorService executorService, boolean now) {
if (now) {
executorService.shutdownNow();
} else {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 849541d..992b14b 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,9 +13,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc;
import java.io.BufferedReader;
@@ -67,6 +68,7 @@ import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
+import org.rhq.core.pc.operation.OperationManager;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
import org.rhq.core.pc.standaloneContainer.Command;
import org.rhq.core.pc.standaloneContainer.History;
@@ -407,7 +409,8 @@ public class StandaloneContainer {
return;
}
- OperationContext operationContext = new OperationContextImpl(resourceId);
+ OperationManager operationManager = PluginContainer.getInstance().getOperationManager();
+ OperationContext operationContext = new OperationContextImpl(resourceId, operationManager);
OperationServices operationServices = operationContext.getOperationServices();
opId++;
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/agent/AgentService.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/agent/AgentService.java
index 0e778a7..c777bd5 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/agent/AgentService.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/agent/AgentService.java
@@ -1,31 +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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.agent;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Collection;
-import java.util.LinkedHashSet;
/**
* Those plugin container managers that need to expose their interfaces remotely (to the JON Server for example) need to
@@ -34,9 +29,8 @@ import java.util.LinkedHashSet;
* and "unremote" its client interface).
*/
public abstract class AgentService {
- private Class clientInterface;
- private Collection<AgentServiceLifecycleListener> listeners;
- private AgentServiceStreamRemoter streamRemoter;
+ private final Class clientInterface;
+ private final AgentServiceStreamRemoter streamRemoter;
/**
* Creates a new {@link AgentService} object.
@@ -44,38 +38,15 @@ public abstract class AgentService {
* @param clientInterface the client interface that this agent service wants to make remotely accessible to external
* clients
*/
- protected AgentService(Class clientInterface) {
+ protected AgentService(Class clientInterface, AgentServiceStreamRemoter streamRemoter) {
this.clientInterface = clientInterface;
- this.listeners = new LinkedHashSet<AgentServiceLifecycleListener>();
+ this.streamRemoter = streamRemoter;
}
/**
- * This is called when the agent service changes its {@link LifecycleState state} - it will notify all listeners of
- * the changed state.
- *
- * @param newState
- */
- public void notifyLifecycleListenersOfNewState(LifecycleState newState) {
- for (AgentServiceLifecycleListener agentServiceLifecycleListener : listeners) {
- switch (newState) {
- case STARTED: {
- agentServiceLifecycleListener.started(this);
- break;
- }
-
- case STOPPED: {
- agentServiceLifecycleListener.stopped(this);
- break;
- }
- }
- }
- }
-
- /**
- * Given any input stream, this will attempt to remote it using the
- * {@link #setAgentServiceStreamRemoter(AgentServiceStreamRemoter) stream remoter}, thus providing access to
- * external clients. If there is no remoter available, the same input stream instance passed into this method is
- * returned as-is.
+ * Given any inputstream, this will attempt to remote it using the {@link AgentServiceStreamRemoter stream remoter},
+ * , thus providing access to external clients. If there is no remoter available, the same input stream instance
+ * passed into this method is returned as-is.
*
* <p>If <code>inputStream</code> is <code>null</code>, <code>null</code> is returned.</p>
*
@@ -87,15 +58,13 @@ public abstract class AgentService {
if ((inputStream == null) || (streamRemoter == null)) {
return inputStream;
}
-
return streamRemoter.prepareInputStream(inputStream);
}
/**
- * Given any output stream, this will attempt to remote it using the
- * {@link #setAgentServiceStreamRemoter(AgentServiceStreamRemoter) stream remoter}, thus providing access to
- * external clients. If there is no remoter available, the same output stream instance passed into this method is
- * returned as-is.
+ * Given any outputstream, this will attempt to remote it using the {@link AgentServiceStreamRemoter stream remoter},
+ * thus providing access to external clients. If there is no remoter available, the same output stream instance
+ * passed into this method is returned as-is.
*
* <p>If <code>outputStream</code> is <code>null</code>, <code>null</code> is returned.</p>
*
@@ -107,41 +76,10 @@ public abstract class AgentService {
if ((outputStream == null) || (streamRemoter == null)) {
return outputStream;
}
-
return streamRemoter.prepareOutputStream(outputStream);
}
/**
- * Adds the given listener to the list of listeners that will be notified when this agent service changes its state
- * (i.e. is started or stopped).
- *
- * @param listener
- */
- public void addLifecycleListener(AgentServiceLifecycleListener listener) {
- listeners.add(listener);
- }
-
- /**
- * Removes the given listener so it is no longer notified of changed states.
- *
- * @param listener
- */
- public void removeLifecycleListener(AgentServiceLifecycleListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * Sets the remoter object that is responsible for remoting streams. If <code>null</code>, the agent service will
- * not be able to remote streams to external clients, as in the case when the plugin container is not running inside
- * an agent (i.e. embedded mode).
- *
- * @param remoter
- */
- public void setAgentServiceStreamRemoter(AgentServiceStreamRemoter remoter) {
- streamRemoter = remoter;
- }
-
- /**
* Returns the interface that this agent service wants to be made remotely accessible to external clients. In other
* words, this is the interface the agent will expose as the service's remote POJO interface.
*
@@ -152,10 +90,9 @@ public abstract class AgentService {
}
/**
- * The different states agent services can be in. Listeners will be notified when agent services enter one of these
- * states.
+ * Returns the stream remoter.
*/
- public enum LifecycleState {
- STARTED, STOPPED
+ protected AgentServiceStreamRemoter getStreamRemoter() {
+ return streamRemoter;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/availability/AvailabilityContextImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/availability/AvailabilityContextImpl.java
index 2919014..ce7922b 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/availability/AvailabilityContextImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/availability/AvailabilityContextImpl.java
@@ -1,8 +1,7 @@
/*
* RHQ Management Platform
- * Copyright 2012, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright (C) 2005-2014 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 as published by
@@ -14,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.availability;
@@ -23,7 +22,7 @@ package org.rhq.core.pc.availability;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.pc.PluginContainer;
+import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pluginapi.availability.AvailabilityCollectorRunnable;
import org.rhq.core.pluginapi.availability.AvailabilityContext;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
@@ -34,10 +33,12 @@ import org.rhq.core.pluginapi.availability.AvailabilityFacet;
public class AvailabilityContextImpl implements AvailabilityContext {
private final Resource resource;
+ private final InventoryManager inventoryManager;
- public AvailabilityContextImpl(Resource resource) {
+ public AvailabilityContextImpl(Resource resource, InventoryManager inventoryManager) {
super();
this.resource = resource;
+ this.inventoryManager = inventoryManager;
}
@Override
@@ -50,23 +51,23 @@ public class AvailabilityContextImpl implements AvailabilityContext {
@Override
public void requestAvailabilityCheck() {
- PluginContainer.getInstance().getInventoryManager().requestAvailabilityCheck(resource);
+ inventoryManager.requestAvailabilityCheck(resource);
}
@Override
public AvailabilityType getLastReportedAvailability() {
- Availability avail = PluginContainer.getInstance().getInventoryManager().getAvailabilityIfKnown(resource);
+ Availability avail = inventoryManager.getAvailabilityIfKnown(resource);
return (null != avail) ? avail.getAvailabilityType() : null;
}
@Override
public void disable() {
- PluginContainer.getInstance().getInventoryManager().setResourceEnablement(resource.getId(), false);
+ inventoryManager.setResourceEnablement(resource.getId(), false);
}
@Override
public void enable() {
- PluginContainer.getInstance().getInventoryManager().setResourceEnablement(resource.getId(), true);
+ inventoryManager.setResourceEnablement(resource.getId(), true);
}
/**
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
index f136c9f..ce7b3dd 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.bundle;
import java.io.File;
@@ -56,6 +57,7 @@ import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
@@ -79,7 +81,7 @@ import org.rhq.core.util.file.FileUtil;
* @author John Mazzitelli
*/
public class BundleManager extends AgentService implements BundleAgentService, BundleManagerProvider, ContainerService {
- private final Log log = LogFactory.getLog(BundleManager.class);
+ private static final Log log = LogFactory.getLog(BundleManager.class);
private final String AUDIT_DEPLOYMENT_ENDED = "Deployment Ended";
private final String AUDIT_DEPLOYMENT_STARTED = "Deployment Started";
@@ -90,39 +92,23 @@ public class BundleManager extends AgentService implements BundleAgentService, B
private final String AUDIT_PURGE_STARTED = "Purge Started";
private final String AUDIT_PURGE_ENDED = "Purge Ended";
- private PluginContainerConfiguration configuration;
- private ExecutorService deployerThreadPool;
-
- public BundleManager() {
- super(BundleAgentService.class);
- }
+ private final PluginContainerConfiguration configuration;
+ private final ExecutorService deployerThreadPool;
+ private final InventoryManager im;
+ private final MeasurementManager mm;
- public void setConfiguration(PluginContainerConfiguration configuration) {
+ public BundleManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter, InventoryManager im, MeasurementManager mm) {
+ super(BundleAgentService.class, streamRemoter);
this.configuration = configuration;
- }
-
- public void initialize() {
- createDeployerThreadPool();
- }
-
- public void shutdown() {
- shutdownDeployerThreadPool();
- }
-
- private void createDeployerThreadPool() {
- shutdownDeployerThreadPool(); // paranoia - just in case somehow an old one is still around
LoggingThreadFactory threadFactory = new LoggingThreadFactory("BundleDeployment", true);
this.deployerThreadPool = Executors.newSingleThreadExecutor(threadFactory); // single-threaded so only one deployment at a time
+ this.im = im;
+ this.mm = mm;
}
- private void shutdownDeployerThreadPool() {
- if (this.deployerThreadPool != null) {
- PluginContainer pluginContainer = PluginContainer.getInstance();
- // pass false, so we don't interrupt a plugin in the middle of a bundle deployment
- pluginContainer.shutdownExecutorService(this.deployerThreadPool, false);
- this.deployerThreadPool = null;
- }
- return;
+ public void shutdown() {
+ // pass false, so we don't interrupt a plugin in the middle of a bundle deployment
+ PluginContainer.shutdownExecutorService(this.deployerThreadPool, false);
}
public List<PackageVersion> getAllBundleVersionPackageVersions(BundleVersion bundleVersion) throws Exception {
@@ -146,7 +132,6 @@ public class BundleManager extends AgentService implements BundleAgentService, B
final BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
// find the resource that will handle the bundle processing
- InventoryManager im = getInventoryManager();
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType();
ResourceType resourceType = bundleType.getResourceType();
Set<Resource> resources = im.getResourcesWithType(resourceType);
@@ -237,7 +222,6 @@ public class BundleManager extends AgentService implements BundleAgentService, B
final BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
// find the resource that will purge the bundle
- InventoryManager im = getInventoryManager();
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType();
ResourceType resourceType = bundleType.getResourceType();
Set<Resource> resources = im.getResourcesWithType(resourceType);
@@ -469,7 +453,6 @@ public class BundleManager extends AgentService implements BundleAgentService, B
}
// get the resource entity stored in our local inventory
- InventoryManager im = getInventoryManager();
Resource resource = bundleResourceDeployment.getResource();
ResourceContainer container = im.getResourceContainer(resource);
resource = container.getResource();
@@ -526,7 +509,7 @@ public class BundleManager extends AgentService implements BundleAgentService, B
break;
}
case measurementTrait: {
- baseLocation = getMeasurementManager().getTraitValue(container, destBaseDirValueName);
+ baseLocation = mm.getTraitValue(container, destBaseDirValueName);
if (baseLocation == null) {
throw new IllegalArgumentException("Cannot obtain trait [" + destBaseDirName + "] for resource ["
+ resource.getName() + "]");
@@ -581,24 +564,4 @@ public class BundleManager extends AgentService implements BundleAgentService, B
return ComponentUtil.getComponent(resourceId, BundleFacet.class, FacetLockType.READ, timeout, false, true,
false);
}
-
- /**
- * Returns the manager that can provide data on the inventory. This is a separate protected method
- * so we can extend our manger class to have a mock manager for testing.
- *
- * @return the inventory manager
- */
- protected InventoryManager getInventoryManager() {
- return PluginContainer.getInstance().getInventoryManager();
- }
-
- /**
- * Returns the manager that can provide data on the measurements/metrics. This is a separate protected method
- * so we can extend our manger class to have a mock manager for testing.
- *
- * @return the inventory manager
- */
- protected MeasurementManager getMeasurementManager() {
- return PluginContainer.getInstance().getMeasurementManager();
- }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
index a3eddb0..583a856 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.configuration;
@@ -27,22 +23,16 @@ package org.rhq.core.pc.configuration;
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.resource.composite.ResourceFacets;
-import org.rhq.core.pc.inventory.InventoryManager;
-import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.util.ComponentService;
-import org.rhq.core.pc.util.ComponentUtil;
-import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.rhq.core.pluginapi.inventory.ResourceComponent;
public class ConfigManagementFactoryImpl implements ConfigManagementFactory {
- private ComponentService componentService;
+ private final ComponentService componentService;
- private ConfigurationUtilityService configUtilityService = new ConfigurationUtilityServiceImpl();
+ private final ConfigurationUtilityService configUtilityService = new ConfigurationUtilityServiceImpl();
- public void setComponentService(ComponentService componentService) {
+ public ConfigManagementFactoryImpl(ComponentService componentService) {
this.componentService = componentService;
}
@@ -74,7 +64,7 @@ public class ConfigManagementFactoryImpl implements ConfigManagementFactory {
return new StructuredAndRawConfigManagement();
case STRUCTURED:
default:
-
+
if (componentService.fetchResourceComponent(resourceId) instanceof ResourceConfigurationFacet){
return new StructuredConfigManagement();
} else{
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
index dfb6412..517a095 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.configuration;
import java.util.LinkedList;
@@ -43,6 +44,8 @@ import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
+import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.util.ComponentService;
import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.pc.util.FacetLockType;
@@ -59,24 +62,29 @@ import org.rhq.core.util.MessageDigestGenerator;
* @author Jason Dobies
*/
public class ConfigurationManager extends AgentService implements ContainerService, ConfigurationAgentService {
- private final Log log = LogFactory.getLog(ConfigurationManager.class);
+ private static final Log log = LogFactory.getLog(ConfigurationManager.class);
private static final String SENDER_THREAD_POOL_NAME = "ConfigurationManager.threadpool";
private static final int FACET_METHOD_TIMEOUT = 60 * 1000; // 60 seconds
- private PluginContainerConfiguration pluginContainerConfiguration;
- private ScheduledExecutorService threadPool;
+ private final PluginContainerConfiguration pluginContainerConfiguration;
- private ComponentService componentService;
+ private final ComponentService componentService;
- private ConfigManagementFactory configMgmtFactory;
+ private final ConfigManagementFactory configMgmtFactory;
- public ConfigurationManager() {
- super(ConfigurationAgentService.class);
- }
+ private ScheduledExecutorService threadPool;
- public void initialize() {
+ public ConfigurationManager(PluginContainerConfiguration configuration,
+ ComponentService componentService,
+ ConfigManagementFactory factory, AgentServiceStreamRemoter streamRemoter,
+ InventoryManager inventoryManager)
+ {
+ super(ConfigurationAgentService.class, streamRemoter);
+ this.componentService = componentService;
+ configMgmtFactory = factory;
+ pluginContainerConfiguration = configuration;
LoggingThreadFactory threadFactory = new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true);
threadPool = new ScheduledThreadPoolExecutor(1, threadFactory);
@@ -92,21 +100,8 @@ public class ConfigurationManager extends AgentService implements ContainerServi
}
public void shutdown() {
- PluginContainer pluginContainer = PluginContainer.getInstance();
// pass false, so we don't interrupt a plugin in the middle of a config update
- pluginContainer.shutdownExecutorService(threadPool, false);
- }
-
- public void setConfiguration(PluginContainerConfiguration configuration) {
- pluginContainerConfiguration = configuration;
- }
-
- public void setComponentService(ComponentService componentService) {
- this.componentService = componentService;
- }
-
- public void setConfigManagementFactory(ConfigManagementFactory factory) {
- configMgmtFactory = factory;
+ PluginContainer.shutdownExecutorService(threadPool, false);
}
public void updateResourceConfiguration(ConfigurationUpdateRequest request) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManagerInitializer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManagerInitializer.java
deleted file mode 100644
index b547e94..0000000
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManagerInitializer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.pc.configuration;
-
-import org.rhq.core.pc.util.ComponentServiceImpl;
-import org.rhq.core.pc.util.ComponentService;
-
-public class ConfigurationManagerInitializer {
-
- public void initialize(ConfigurationManager manager) {
- ComponentService componentService = new ComponentServiceImpl();
-
- ConfigManagementFactoryImpl factory = new ConfigManagementFactoryImpl();
- factory.setComponentService(componentService);
-
- manager.setComponentService(componentService);
- manager.setConfigManagementFactory(factory);
- }
-
-}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentContextImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentContextImpl.java
index 7590231..7eeeb73 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentContextImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentContextImpl.java
@@ -1,25 +1,22 @@
- /*
- * 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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.content;
import org.rhq.core.pc.PluginContainer;
@@ -34,10 +31,17 @@ import org.rhq.core.pluginapi.content.ContentServices;
* @author John Mazzitelli
*/
public class ContentContextImpl implements ContentContext {
- private int resourceId;
+ private final int resourceId;
+ private final ContentServices contentServices;
- public ContentContextImpl(int resourceId) {
+ public ContentContextImpl(int resourceId, ContentServices contentServices) {
this.resourceId = resourceId;
+ this.contentServices = contentServices;
+ }
+
+ @Deprecated
+ public ContentContextImpl(int resourceId) {
+ this(resourceId, PluginContainer.getInstance().getContentManager());
}
public int getResourceId() {
@@ -45,6 +49,6 @@ public class ContentContextImpl implements ContentContext {
}
public ContentServices getContentServices() {
- return PluginContainer.getInstance().getContentManager();
+ return contentServices;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
index 464978d..925cc14 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
@@ -62,6 +62,7 @@ import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.inventory.InventoryEventListener;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
@@ -80,22 +81,22 @@ public class ContentManager extends AgentService implements ContainerService, Co
/**
* Configuration elements for the running of this manager.
*/
- private PluginContainerConfiguration configuration;
+ private final PluginContainerConfiguration configuration;
/**
* Flag indicating whether or not this instance of the manager should run automatic, scheduled discoveries.
*/
- private boolean scheduledDiscoveriesEnabled;
+ private final boolean scheduledDiscoveriesEnabled;
/**
* Executor used in running discoveries.
*/
- private ScheduledThreadPoolExecutor discoveryThreadPoolExecutor;
+ private final ScheduledThreadPoolExecutor discoveryThreadPoolExecutor;
/**
* Executor used for CRUD operations on content.
*/
- private ExecutorService crudExecutor;
+ private final ExecutorService crudExecutor;
/**
* Manages the scheduled discoveries, keeping them ordered on next execution time.
@@ -105,15 +106,16 @@ public class ContentManager extends AgentService implements ContainerService, Co
/**
* Event listener to receive notifications of changes to the inventory.
*/
- private ContentInventoryEventListener inventoryEventListener;
+ private final ContentInventoryEventListener inventoryEventListener;
+ private final InventoryManager inventoryManager;
- public ContentManager() {
- super(ContentAgentService.class);
- }
+ public ContentManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter, InventoryManager im) {
+ super(ContentAgentService.class, streamRemoter);
- public void initialize() {
LOG.info("Initializing Content Manager...");
+ this.configuration = configuration;
+ this.inventoryManager = im;
// Determine discovery mode - we only enable discovery if we are inside the agent and the period is positive non-zero
this.scheduledDiscoveriesEnabled = (configuration.getContentDiscoveryPeriod() > 0);
@@ -147,31 +149,26 @@ public class ContentManager extends AgentService implements ContainerService, Co
inventoryEventListener = new ContentInventoryEventListener();
// the inventory manager has probably already activated some resources, so let's prepopulate our schedules
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
im.notifyForAllActivatedResources(inventoryEventListener);
// now ask that the inventory manager tell us about resources that will be activated in the future
im.addInventoryEventListener(inventoryEventListener);
+ } else {
+ inventoryEventListener = null;
}
LOG.info("Content Manager initialized...");
}
public void shutdown() {
LOG.info("Shutting down Content Manager...");
- PluginContainer pluginContainer = PluginContainer.getInstance();
- pluginContainer.shutdownExecutorService(discoveryThreadPoolExecutor, true);
+ PluginContainer.shutdownExecutorService(discoveryThreadPoolExecutor, true);
// pass false, so we don't interrupt a plugin in the middle of a content update
- pluginContainer.shutdownExecutorService(crudExecutor, false);
- pluginContainer.getInventoryManager().removeInventoryEventListener(inventoryEventListener);
- }
-
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
+ PluginContainer.shutdownExecutorService(crudExecutor, false);
+ inventoryManager.removeInventoryEventListener(inventoryEventListener);
}
public Set<ResourcePackageDetails> getLastDiscoveredResourcePackages(int resourceId) {
// Get the resource component
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
// Nothing to do if the container doesn't exist or isn't running, so punch out
@@ -356,7 +353,7 @@ public class ContentManager extends AgentService implements ContainerService, Co
*/
// Make sure the resource still exists, otherwise don't bother rescheduling
- ResourceContainer resourceContainer = PluginContainer.getInstance().getInventoryManager().getResourceContainer(
+ ResourceContainer resourceContainer = inventoryManager.getResourceContainer(
discoveryInfo.getResourceId());
if (resourceContainer != null) {
@@ -502,7 +499,7 @@ public class ContentManager extends AgentService implements ContainerService, Co
* Schedules any necessary discoveries for the specified resource.
* This is called when a resource is newly activated - as when a plugin configuration change is made.
* If a schedule is already in place, it will remain.
- *
+ *
* @param resource resource for which discoveries are being scheduled
*/
private synchronized void scheduleDiscoveries(Resource resource) {
@@ -585,7 +582,6 @@ public class ContentManager extends AgentService implements ContainerService, Co
return null;
}
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
Set<ResourcePackageDetails> updatedPackageSet = new HashSet<ResourcePackageDetails>(details);
@@ -676,6 +672,10 @@ public class ContentManager extends AgentService implements ContainerService, Co
return null;
}
+ public InventoryManager getInventoryManager() {
+ return inventoryManager;
+ }
+
// Inner Classes --------------------------------------------
/**
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/CreateContentRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/CreateContentRunner.java
index dc78bc2..66531c9 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/CreateContentRunner.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/CreateContentRunner.java
@@ -1,25 +1,22 @@
- /*
- * 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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.content;
import java.util.HashSet;
@@ -29,17 +26,16 @@ import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.content.transfer.ContentResponseResult;
import org.rhq.core.clientapi.server.content.ContentServerService;
+import org.rhq.core.clientapi.server.content.DeployPackagesRequest;
+import org.rhq.core.domain.content.PackageDetailsKey;
+import org.rhq.core.domain.content.transfer.ContentResponseResult;
import org.rhq.core.domain.content.transfer.DeployIndividualPackageResponse;
import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
-import org.rhq.core.domain.content.PackageDetailsKey;
-import org.rhq.core.clientapi.server.content.DeployPackagesRequest;
-import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.resource.ResourceCategory;
-import org.rhq.core.pc.util.ComponentUtil;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.inventory.InventoryManager;
-import org.rhq.core.pc.PluginContainer;
+import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.util.exception.ThrowableUtil;
/**
@@ -48,16 +44,16 @@ import org.rhq.core.util.exception.ThrowableUtil;
* @author Jason Dobies
*/
public class CreateContentRunner implements Runnable, Callable<DeployPackagesResponse> {
- // Attributes --------------------------------------------
+ private static final Log log = LogFactory.getLog(CreateContentRunner.class);
- private final Log log = LogFactory.getLog(CreateContentRunner.class);
+ // Attributes --------------------------------------------
- private ContentManager contentManager;
+ private final ContentManager contentManager;
/**
* Request being executed by this instance.
*/
- private DeployPackagesRequest request;
+ private final DeployPackagesRequest request;
// Constructors --------------------------------------------
@@ -134,7 +130,7 @@ public class CreateContentRunner implements Runnable, Callable<DeployPackagesRes
try {
ResourceType resourceType = ComponentUtil.getResourceType(request.getResourceId());
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
+ InventoryManager inventoryManager = contentManager.getInventoryManager();
if (executeServerScan(resourceType)) {
inventoryManager.executeServerScanImmediately();
@@ -164,5 +160,4 @@ public class CreateContentRunner implements Runnable, Callable<DeployPackagesRes
return execute;
}
-
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
index dbc7a1d..919ef17 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,9 +13,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.drift;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
@@ -52,33 +53,29 @@ import org.rhq.core.util.file.FileVisitor;
/**
* Mechanism to detect and report Drift for active Drift Definitions.
- *
+ *
* @author John Sanda
*/
public class DriftDetector implements Runnable {
- private Log log = LogFactory.getLog(DriftDetector.class);
+ private static final Log log = LogFactory.getLog(DriftDetector.class);
static final String FILE_CHANGESET_FULL = "changeset.txt";
static final String FILE_CHANGESET_DELTA = "drift-changeset.txt";
static final String FILE_SNAPSHOT_PINNED = "snapshot.pinned";
- private ScheduleQueue scheduleQueue;
-
- private ChangeSetManager changeSetMgr;
+ private final ScheduleQueue scheduleQueue;
- private MessageDigestGenerator digestGenerator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
+ private final ChangeSetManager changeSetMgr;
- private DriftClient driftClient;
+ private final MessageDigestGenerator digestGenerator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
- public void setScheduleQueue(ScheduleQueue queue) {
- scheduleQueue = queue;
- }
-
- public void setChangeSetManager(ChangeSetManager changeSetManager) {
- changeSetMgr = changeSetManager;
- }
+ private final DriftClient driftClient;
- public void setDriftClient(DriftClient driftClient) {
+ public DriftDetector(ScheduleQueue scheduleQueue,
+ ChangeSetManager changeSetMgr,
+ DriftClient driftClient) {
+ this.scheduleQueue = scheduleQueue;
+ this.changeSetMgr = changeSetMgr;
this.driftClient = driftClient;
}
@@ -202,7 +199,7 @@ public class DriftDetector implements Runnable {
// get a Set of all files in the detection, consider them initially new files, and we'll knock the
// list down as we go. As we build up FileEntries in memory this Set will shrink. It's marginally
- // less memory than if we had both in memory at the same time.
+ // less memory than if we had both in memory at the same time.
final Set<File> newFiles = new HashSet<File>(1000);
// If the basedir is still valid we need to do a directory tree scan to look for newly added files
@@ -301,12 +298,12 @@ public class DriftDetector implements Runnable {
}
}
- // The new snapshot contains all changed, unchanged and added files. Not removed files.
+ // The new snapshot contains all changed, unchanged and added files. Not removed files.
final List<FileEntry> snapshotEntries = new LinkedList<FileEntry>(unchangedEntries);
snapshotEntries.addAll(changedEntries);
snapshotEntries.addAll(addedEntries);
- // The snapshot delta contains all changed, added and removed files.
+ // The snapshot delta contains all changed, added and removed files.
final List<FileEntry> deltaEntries = new LinkedList<FileEntry>(changedEntries);
deltaEntries.addAll(removedEntries);
deltaEntries.addAll(addedEntries);
@@ -363,15 +360,15 @@ public class DriftDetector implements Runnable {
/**
* File.canRead() is basically a security check and does not guarantee that the file contents can truly be read.
* Certain files, like socket files on linux, can not be processed and it's not known until actually trying to
- * construct a FileInputStream, as is done when we actually try to generate the digest. These files will generate
+ * construct a FileInputStream, as is done when we actually try to generate the digest. These files will generate
* a FileNotFoundException. This method will catch, log and suppress that issue, and return null
* indicating the file is not suitable for drift detection.
- *
+ *
* @param basedir the drift def base directory
* @param file the new file to add
* @return the new FileEntry, or null if this file is not appropriate for drift detection (typically if the
* underlying file does not support the needed File operations.
- * @throws Will throw unexpected IOExceptions, outside of the FileNotFoundException it looks for.
+ * @throws IOException if something unexpected occurs, outside of the FileNotFoundException it looks for.
*/
private FileEntry getAddedFileEntry(File basedir, File file) throws IOException {
FileEntry result = null;
@@ -426,7 +423,7 @@ public class DriftDetector implements Runnable {
/**
* Process the entries for the snapshotReader. Each entry will be placed in one of the various Lists depending
- * on what bucket it fall into.
+ * on what bucket it fall into.
* @return true if unchangedEntries (meaning no drift) had timestamp/filesize info updated, in which case the
* snapshot should be re-written to disk even if there was no drift.
* @throws IOException
@@ -799,4 +796,4 @@ public class DriftDetector implements Runnable {
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
index 762c8e1..8189376 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.drift;
@@ -57,63 +57,56 @@ import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
-import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.util.file.FileUtil;
import org.rhq.core.util.stream.StreamUtil;
public class DriftManager extends AgentService implements DriftAgentService, DriftClient, ContainerService {
- private final Log log = LogFactory.getLog(DriftManager.class);
+ private static final Log log = LogFactory.getLog(DriftManager.class);
- private PluginContainerConfiguration pluginContainerConfiguration;
+ private final PluginContainerConfiguration pluginContainerConfiguration;
- private File changeSetsDir;
+ private final File changeSetsDir;
- private ScheduledThreadPoolExecutor driftThreadPool;
+ private final ScheduledThreadPoolExecutor driftThreadPool;
- private ScheduleQueue schedulesQueue = new ScheduleQueueImpl();
+ private final ScheduleQueue schedulesQueue = new ScheduleQueueImpl();
+ /**
+ * Not final for testing.
+ */
private ChangeSetManager changeSetMgr;
- private boolean initialized;
+ private final boolean initialized;
- public DriftManager() {
- super(DriftAgentService.class);
- }
+ private final InventoryManager inventoryManager;
- @Override
- public void setConfiguration(PluginContainerConfiguration configuration) {
+ public DriftManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter, InventoryManager inventoryManager) {
+ super(DriftAgentService.class, streamRemoter);
+ this.inventoryManager = inventoryManager;
pluginContainerConfiguration = configuration;
changeSetsDir = new File(pluginContainerConfiguration.getDataDirectory(), "changesets");
- }
-
- public boolean isInitialized() {
- return initialized;
- }
- @Override
- public void initialize() {
long initStartTime = System.currentTimeMillis();
if (!changeSetsDir.isDirectory()) {
boolean success = changeSetsDir.mkdir();
if (!success) {
log.warn("Could not create change sets directory " + changeSetsDir);
initialized = false;
+ driftThreadPool = null;
+ changeSetMgr = null;
return;
}
}
changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
- DriftDetector driftDetector = new DriftDetector();
- driftDetector.setScheduleQueue(schedulesQueue);
- driftDetector.setChangeSetManager(changeSetMgr);
- driftDetector.setDriftClient(this);
+ DriftDetector driftDetector = new DriftDetector(schedulesQueue, changeSetMgr, this);
- InventoryManager inventoryMgr = PluginContainer.getInstance().getInventoryManager();
long startTime = System.currentTimeMillis();
- initSchedules(inventoryMgr.getPlatform(), inventoryMgr);
+ initSchedules(inventoryManager.getPlatform(), inventoryManager);
long endTime = System.currentTimeMillis();
if (log.isInfoEnabled()) {
@@ -141,6 +134,10 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
}
}
+ public boolean isInitialized() {
+ return initialized;
+ }
+
private void initSchedules(Resource r, InventoryManager inventoryMgr) {
if (r.getId() == 0) {
log.debug("Will not reschedule drift detection for " + r + ". It is not sync'ed yet.");
@@ -289,17 +286,11 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
@Override
public void shutdown() {
if (driftThreadPool != null) {
- PluginContainer pluginContainer = PluginContainer.getInstance();
// TODO (ips, 04/30/12): Is it safe to pass true here to interrupt executing threads?
- pluginContainer.shutdownExecutorService(driftThreadPool, false);
- driftThreadPool = null;
- }
-
- if (schedulesQueue != null) {
- schedulesQueue.clear();
- schedulesQueue = null;
+ PluginContainer.shutdownExecutorService(driftThreadPool, false);
}
+ schedulesQueue.clear();
changeSetMgr = null;
}
@@ -421,7 +412,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
if (log.isDebugEnabled()) {
log.debug(schedule + " has been added to " + schedulesQueue);
}
- ResourceContainer container = getInventoryManager().getResourceContainer(resourceId);
+ ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
if (container != null) {
container.addDriftDefinition(driftDefinition);
}
@@ -465,7 +456,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
}
});
if (schedule != null) {
- ResourceContainer container = getInventoryManager().getResourceContainer(resourceId);
+ ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
if (container != null) {
container.removeDriftDefinition(schedule.getDriftDefinition());
}
@@ -662,8 +653,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDefinition) {
// get the resource entity stored in our local inventory
- InventoryManager im = getInventoryManager();
- ResourceContainer container = im.getResourceContainer(resourceId);
+ ResourceContainer container = inventoryManager.getResourceContainer(resourceId);
if (container == null) {
log.error("Cannot determine base directory for " + driftDefinition + ". No resource container found " +
@@ -711,7 +701,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
break;
}
case measurementTrait: {
- baseLocation = getMeasurementManager().getTraitValue(container, baseDirValueName);
+ baseLocation = getTraitValue(container, baseDirValueName);
if (baseLocation == null) {
throw new IllegalArgumentException("Cannot obtain trait [" + baseDirValueName + "] for resource ["
+ resource.getName() + "]");
@@ -734,24 +724,8 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
return destDir;
}
- /**
- * Returns the manager that can provide data on the inventory. This is a separate protected method
- * so we can extend our manger class to have a mock manager for testing.
- *
- * @return the inventory manager
- */
- protected InventoryManager getInventoryManager() {
- return PluginContainer.getInstance().getInventoryManager();
- }
-
- /**
- * Returns the manager that can provide data on the measurements/metrics. This is a separate protected method
- * so we can extend our manger class to have a mock manager for testing.
- *
- * @return the inventory manager
- */
- protected MeasurementManager getMeasurementManager() {
- return PluginContainer.getInstance().getMeasurementManager();
+ private String getTraitValue(ResourceContainer container, String traitName) {
+ return inventoryManager.getMeasurementManager().getTraitValue(container, traitName);
}
private void writeSnapshotToFile(DriftSnapshot snapshot, File file, Headers headers) throws IOException {
@@ -794,7 +768,7 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
}
private static class ZipFileNameFilter implements FilenameFilter {
- private String prefix;
+ private final String prefix;
public ZipFileNameFilter(String prefix) {
this.prefix = prefix;
@@ -805,4 +779,8 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
return name.startsWith(prefix) && name.endsWith(".zip");
}
}
+
+ public InventoryManager getInventoryManager() {
+ return inventoryManager;
+ }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java
index 52f270b..483ffd6b 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventContextImpl.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.event;
import java.util.HashSet;
@@ -32,7 +29,6 @@ import org.jetbrains.annotations.Nullable;
import org.rhq.core.domain.event.Event;
import org.rhq.core.domain.event.EventDefinition;
import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pluginapi.event.EventContext;
import org.rhq.core.pluginapi.event.EventPoller;
@@ -40,17 +36,12 @@ import org.rhq.core.pluginapi.event.EventPoller;
* @author Ian Springer
*/
public class EventContextImpl implements EventContext {
- private Resource resource;
+ private final Resource resource;
+ private final EventManager eventManager;
- public EventContextImpl(@NotNull Resource resource) {
+ public EventContextImpl(@NotNull Resource resource, EventManager eventManager) {
this.resource = resource;
- }
-
- // A reference to EventManager was previously stored in a member variable named eventManager. That should *not*
- // be done because of possible concurrency issues. See https://bugzilla.redhat.com/show_bug.cgi?id=677349 for
- // details.
- private EventManager getEventManager() {
- return PluginContainer.getInstance().getEventManager();
+ this.eventManager = eventManager;
}
public void publishEvent(@NotNull Event event) {
@@ -64,7 +55,7 @@ public class EventContextImpl implements EventContext {
+ event.getType() + "'.");
Set<Event> events = new HashSet<Event>();
events.add(event);
- getEventManager().publishEvents(events, this.resource);
+ eventManager.publishEvents(events, this.resource);
}
public void registerEventPoller(@NotNull EventPoller poller, int pollingInterval) {
@@ -105,7 +96,7 @@ public class EventContextImpl implements EventContext {
@Nullable
public SigarProxy getSigar() {
- return getEventManager().getSigar();
+ return eventManager.getSigar();
}
/**
@@ -122,14 +113,7 @@ public class EventContextImpl implements EventContext {
throw new IllegalArgumentException("Poller has unknown event type - no EventDefinition exists with name '"
+ poller.getEventType() + "'.");
final int adjustedPollingInterval = Math.max(EventContext.MINIMUM_POLLING_INTERVAL, pollingInterval);
- // Registering the event poller has to be done in a callback listener to avoid a potential deadlock.
- // See https://bugzilla.redhat.com/show_bug.cgi?id=677349 for a detailed explaination.
- PluginContainer.getInstance().addInitializationListener(new PluginContainer.InitializationListener() {
- @Override
- public void initialized() {
- getEventManager().registerEventPoller(poller, adjustedPollingInterval, resource, sourceLocation);
- }
- });
+ eventManager.registerEventPoller(poller, adjustedPollingInterval, resource, sourceLocation);
}
private void unregisterEventPollerInternal(String eventType, String sourceLocation) {
@@ -137,8 +121,6 @@ public class EventContextImpl implements EventContext {
if (eventDefinition == null)
throw new IllegalArgumentException("Unknown event type - no EventDefinition exists with name '" + eventType
+ "'.");
- EventManager eventManager = getEventManager();
- if (eventManager != null)
- eventManager.unregisterEventPoller(this.resource, eventType, sourceLocation);
+ eventManager.unregisterEventPoller(this.resource, eventType, sourceLocation);
}
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventManager.java
index 64bca8b..a635fe6 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/event/EventManager.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.event;
import java.util.HashMap;
@@ -33,8 +30,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperic.sigar.SigarProxy;
import org.jetbrains.annotations.NotNull;
-
import org.jetbrains.annotations.Nullable;
+
import org.rhq.core.domain.event.Event;
import org.rhq.core.domain.event.EventDefinition;
import org.rhq.core.domain.event.EventSource;
@@ -53,7 +50,7 @@ import org.rhq.core.system.SigarAccess;
* @author Ian Springer
*/
public class EventManager implements ContainerService {
- private final Log log = LogFactory.getLog(this.getClass());
+ private static final Log log = LogFactory.getLog(EventManager.class);
private static final String SENDER_THREAD_POOL_NAME = "EventManager.sender";
private static final int SENDER_THREAD_POOL_CORE_SIZE = 2;
@@ -62,21 +59,18 @@ public class EventManager implements ContainerService {
private static final int POLLER_THREAD_POOL_CORE_SIZE = 3;
private static final int POLLER_INITIAL_DELAY_SECS = 0;
- private PluginContainerConfiguration pcConfig;
- private ScheduledThreadPoolExecutor senderThreadPool;
- private EventReport activeReport;
- private ReentrantReadWriteLock reportLock = new ReentrantReadWriteLock(true);
- private ScheduledThreadPoolExecutor pollerThreadPool;
- private Map<PollerKey, Runnable> pollerThreads;
+ private final PluginContainerConfiguration pcConfig;
+ private final ScheduledThreadPoolExecutor senderThreadPool;
+ private volatile EventReport activeReport;
+ private final ReentrantReadWriteLock reportLock = new ReentrantReadWriteLock(true);
+ private final ScheduledThreadPoolExecutor pollerThreadPool;
+ private final Map<PollerKey, Runnable> pollerThreads;
private SigarProxy sigar;
public EventManager(PluginContainerConfiguration configuration) {
this.pcConfig = configuration;
this.activeReport = new EventReport(this.pcConfig.getEventReportMaxPerSource(), this.pcConfig
.getEventReportMaxTotal());
- }
-
- public void initialize() {
// Schedule sender thread(s) to send Event reports to the Server periodically.
EventSenderRunner senderRunner = new EventSenderRunner(this);
@@ -93,21 +87,16 @@ public class EventManager implements ContainerService {
}
public void shutdown() {
- PluginContainer pluginContainer = PluginContainer.getInstance();
if (this.senderThreadPool != null) {
log.debug("Shutting down event sender thread pool...");
- pluginContainer.shutdownExecutorService(this.senderThreadPool, true);
+ PluginContainer.shutdownExecutorService(this.senderThreadPool, true);
}
if (this.pollerThreadPool != null) {
log.debug("Shutting down event poller thread pool...");
- pluginContainer.shutdownExecutorService(this.pollerThreadPool, true);
+ PluginContainer.shutdownExecutorService(this.pollerThreadPool, true);
}
}
- public void setConfiguration(PluginContainerConfiguration config) {
- // Was already passed in the constructor
- }
-
void publishEvents(@NotNull Set<Event> events, @NotNull Resource resource) {
this.reportLock.readLock().lock();
try {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AutoDiscoveryExecutor.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AutoDiscoveryExecutor.java
index 368e2b3..d51697c 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AutoDiscoveryExecutor.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AutoDiscoveryExecutor.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.inventory;
import java.io.ByteArrayOutputStream;
@@ -46,8 +43,6 @@ import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.state.discovery.AutoDiscoveryScanType;
-import org.rhq.core.pc.PluginContainer;
-import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.plugin.PluginComponentFactory;
import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pluginapi.inventory.ProcessScanResult;
@@ -64,7 +59,7 @@ import org.rhq.core.util.exception.Severity;
* Standard platform/server inventory detection execution. This looks for top level servers, typically doing
* process-based discovery. It should probably be renamed to ServerDiscoveryExecutor as "AutoDiscovery" is
* pretty much redundant and non-descriptive. This is typically called in a non-blocking fashion, and the report
- * is returned asynchronously to the server. It is available for direct execution via a Future when running in
+ * is returned asynchronously to the server. It is available for direct execution via a Future when running in
* an embedded mode. This is complemented by {@link RuntimeDiscoveryExecutor} for discovering new child resources
* in the existing inventory hierarchy.
*
@@ -73,19 +68,15 @@ import org.rhq.core.util.exception.Severity;
* @author Ian Springer
*/
public class AutoDiscoveryExecutor implements Runnable, Callable<InventoryReport> {
- private Log log = LogFactory.getLog(AutoDiscoveryExecutor.class);
-
- private AutoDiscoveryRequest autoDiscoveryRequest;
+ private static final Log log = LogFactory.getLog(AutoDiscoveryExecutor.class);
- private InventoryManager inventoryManager;
+ private final AutoDiscoveryRequest autoDiscoveryRequest;
- private PluginContainerConfiguration configuration;
+ private final InventoryManager inventoryManager;
- public AutoDiscoveryExecutor(AutoDiscoveryRequest autoDiscoveryRequest, InventoryManager inventoryManager,
- PluginContainerConfiguration configuration) {
+ public AutoDiscoveryExecutor(AutoDiscoveryRequest autoDiscoveryRequest, InventoryManager inventoryManager) {
this.autoDiscoveryRequest = autoDiscoveryRequest;
this.inventoryManager = inventoryManager;
- this.configuration = configuration;
}
public void run() {
@@ -113,7 +104,7 @@ public class AutoDiscoveryExecutor implements Runnable, Callable<InventoryReport
} else {
log.info("Discovered " + report.getAddedRoots().size() + " new server(s).");
}
-
+
if (log.isDebugEnabled()) {
log.debug("Server discovery scan took [" + (report.getEndTime() - report.getStartTime()) + "] ms.");
}
@@ -163,8 +154,8 @@ public class AutoDiscoveryExecutor implements Runnable, Callable<InventoryReport
private void pluginDiscovery(InventoryReport report, List<ProcessInfo> processInfos) {
inventoryManager.executePlatformScan();
- PluginManager pluginManager = PluginContainer.getInstance().getPluginManager();
- PluginComponentFactory factory = PluginContainer.getInstance().getPluginComponentFactory();
+ PluginManager pluginManager = inventoryManager.getPluginManager();
+ PluginComponentFactory factory = inventoryManager.getPluginComponentFactory();
Set<ResourceType> serverTypes = pluginManager.getMetadataManager().getTypesForCategory(ResourceCategory.SERVER);
ResourceContainer platformContainer = inventoryManager.getResourceContainer(inventoryManager.getPlatform());
@@ -273,4 +264,4 @@ public class AutoDiscoveryExecutor implements Runnable, Callable<InventoryReport
// can we use: parentResourceComponent.getClass().isAssignableFrom( type.getGenericDeclaration().getClass() )
return true;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
index f8a186e..0d93dc6 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
@@ -1,6 +1,6 @@
- /*
+/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,15 +16,17 @@
* 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.pc.inventory;
- import java.util.concurrent.Callable;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.clientapi.agent.inventory.CreateResourceResponse;
-import org.rhq.core.clientapi.server.discovery.InventoryReport;
import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.resource.CreateResourceStatus;
@@ -34,8 +36,6 @@ import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.util.exception.ThrowableUtil;
- import static java.util.concurrent.TimeUnit.SECONDS;
-
/**
* Runnable implementation to process Resource create requests.
*
@@ -52,27 +52,29 @@ public class CreateResourceRunner implements Callable, Runnable {
/**
* Handle to the manager that will do most of the logic.
*/
- private ResourceFactoryManager resourceFactoryManager;
+ private final ResourceFactoryManager resourceFactoryManager;
/**
* Parent resource on which the child will be created.
*/
- private int parentResourceId;
+ private final int parentResourceId;
/**
* Indicates whether or not to execute a runtime scan after the create.
*/
- private boolean runRuntimeScan;
+ private final boolean runRuntimeScan;
/**
* ID of the request being processed. This ID will be used when the response is sent back to the caller.
*/
- private int requestId;
+ private final int requestId;
/**
* Facet to use to make the call against the plugin.
*/
- private CreateChildResourceFacet facet;
+ private final CreateChildResourceFacet facet;
+
+ private final InventoryManager inventoryManager;
/**
* Report to send to the facet as part of the call.
@@ -89,6 +91,7 @@ public class CreateResourceRunner implements Callable, Runnable {
this.requestId = requestId;
this.report = report;
this.runRuntimeScan = runRuntimeScan;
+ this.inventoryManager = PluginContainer.getInstance().getInventoryManager();
}
// Runnable Implementation --------------------------------------------
@@ -200,7 +203,6 @@ public class CreateResourceRunner implements Callable, Runnable {
LOG.debug("Scheduling service scan to discover newly created [" + report.getResourceType()
+ "] managed resource with key [" + report.getResourceKey() + "]...");
}
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
Resource discoveredResource = null;
for (int retry = 1; discoveredResource == null && retry <= SERVICE_SCAN_MAX_RETRY; retry++) {
if (LOG.isDebugEnabled()) {
@@ -241,7 +243,6 @@ public class CreateResourceRunner implements Callable, Runnable {
}
private Resource getDiscoveredResource() {
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
ResourceContainer parentResourceContainer = inventoryManager.getResourceContainer(parentResourceId);
Resource parentResource = parentResourceContainer.getResource();
for (Resource childResource : parentResource.getChildResources()) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
index a97120c..f0eb88b 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.inventory;
import java.io.File;
@@ -48,19 +45,31 @@ import org.rhq.core.pc.PluginContainer;
* @author John Mazzitelli
*/
public class InventoryFile {
- private Log log = LogFactory.getLog(InventoryFile.class);
+ private static final Log log = LogFactory.getLog(InventoryFile.class);
private final File inventoryFile;
private Resource platform;
private Map<String, ResourceContainer> resourceContainers; // keyed on UUID
+ private final InventoryManager inventoryManager;
+
/**
* Constructor for {@link InventoryFile} that will read and write inventory data to the given file.
*
* @param inventoryFile the path to the inventory.dat file
*/
- public InventoryFile(File inventoryFile) {
+ public InventoryFile(File inventoryFile, InventoryManager inventoryManager) {
this.inventoryFile = inventoryFile;
+ this.inventoryManager = inventoryManager;
+ }
+
+ /**
+ * Constructor for {@link InventoryFile} that will read and write inventory data to the given file.
+ *
+ * @param inventoryFile the path to the inventory.dat file
+ */
+ public InventoryFile(File inventoryFile) {
+ this(inventoryFile, PluginContainer.getInstance().getInventoryManager());
}
public File getInventoryFile() {
@@ -138,7 +147,6 @@ public class InventoryFile {
}
private void removeIgnoredResourcesFromChildren(Resource resource, Set<String> uuidsToIgnore) {
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
Set<Resource> children = inventoryManager.getContainerChildren(resource);
if (!children.isEmpty() && !uuidsToIgnore.isEmpty()) {
Iterator<Resource> iterator = children.iterator();
@@ -164,7 +172,6 @@ public class InventoryFile {
resource.setResourceType(fullResourceType);
// now reconnect all its children's types
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
Set<Resource> children = inventoryManager.getContainerChildren(resource);
for (Resource child : children) {
connectTypes(child, uuidsToIgnore);
@@ -184,7 +191,6 @@ public class InventoryFile {
private void addAllUUIDsToList(Resource resource, Set<String> list) {
list.add(resource.getUuid());
- InventoryManager inventoryManager = PluginContainer.getInstance().getInventoryManager();
Set<Resource> children = inventoryManager.getContainerChildren(resource);
for (Resource child : children) {
addAllUUIDsToList(child, list);
@@ -219,4 +225,4 @@ public class InventoryFile {
fos.close();
}
}
-}
\ No newline at end of file
+}
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 aed76d9..5dd9826 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
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,6 @@
package org.rhq.core.pc.inventory;
-import gnu.trove.map.TIntObjectMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
@@ -48,6 +45,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import gnu.trove.map.TIntObjectMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;
@@ -91,14 +91,19 @@ import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
import org.rhq.core.pc.agent.AgentRegistrar;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.availability.AvailabilityContextImpl;
import org.rhq.core.pc.component.ComponentInvocationContextImpl;
import org.rhq.core.pc.configuration.ConfigurationCheckExecutor;
import org.rhq.core.pc.content.ContentContextImpl;
+import org.rhq.core.pc.content.ContentManager;
import org.rhq.core.pc.drift.sync.DriftSyncManager;
import org.rhq.core.pc.event.EventContextImpl;
+import org.rhq.core.pc.event.EventManager;
import org.rhq.core.pc.inventory.ResourceContainer.ResourceComponentState;
+import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.pc.operation.OperationContextImpl;
+import org.rhq.core.pc.operation.OperationManager;
import org.rhq.core.pc.plugin.BlacklistedException;
import org.rhq.core.pc.plugin.CanonicalResourceKey;
import org.rhq.core.pc.plugin.PluginComponentFactory;
@@ -165,19 +170,19 @@ public class InventoryManager extends AgentService implements ContainerService,
SYNC_BATCH_SIZE = syncBatchSize;
}
- private final Log log = LogFactory.getLog(InventoryManager.class);
+ private static final Log log = LogFactory.getLog(InventoryManager.class);
- private PluginContainerConfiguration configuration;
+ private final PluginContainerConfiguration configuration;
private ScheduledThreadPoolExecutor inventoryThreadPoolExecutor;
private ScheduledThreadPoolExecutor availabilityThreadPoolExecutor;
// The executors are Callable
- private AutoDiscoveryExecutor serverScanExecutor;
- private RuntimeDiscoveryExecutor serviceScanExecutor;
- private AvailabilityExecutor availabilityExecutor;
+ private final AutoDiscoveryExecutor serverScanExecutor;
+ private final RuntimeDiscoveryExecutor serviceScanExecutor;
+ private final AvailabilityExecutor availabilityExecutor;
- private Agent agent;
+ private final Agent agent;
/**
* Root platform resource, required to be root of entire inventory tree in this agent
@@ -190,12 +195,12 @@ public class InventoryManager extends AgentService implements ContainerService,
*/
private boolean newPlatformWasDeletedRecently = false; // value only is valid/relevant if platform.getInventoryStatus == NEW
- private ReentrantReadWriteLock inventoryLock = new ReentrantReadWriteLock(true);
+ private final ReentrantReadWriteLock inventoryLock = new ReentrantReadWriteLock(true);
/**
* Used only for the outside the agent model to # resources
*/
- private AtomicInteger temporaryKeyIndex = new AtomicInteger(-1);
+ private final AtomicInteger temporaryKeyIndex = new AtomicInteger(-1);
/**
* UUID to ResourceContainer map
@@ -214,33 +219,56 @@ public class InventoryManager extends AgentService implements ContainerService,
*/
private final Set<InventoryEventListener> inventoryEventListeners = new CopyOnWriteArraySet<InventoryEventListener>();
- private PluginManager pluginManager = PluginContainer.getInstance().getPluginManager();
+ private final PluginManager pluginManager;
- private DiscoveryComponentProxyFactory discoveryComponentProxyFactory;
+ private final DiscoveryComponentProxyFactory discoveryComponentProxyFactory;
/**
* Handles the resource upgrade during the initialization of the inventory manager.
*/
- private ResourceUpgradeDelegate resourceUpgradeDelegate = new ResourceUpgradeDelegate(this);
+ private final ResourceUpgradeDelegate resourceUpgradeDelegate = new ResourceUpgradeDelegate(this);
+ private final PluginComponentFactory pluginFactory;
+ private final EventManager eventManager;
+ private MeasurementManager measurementManager;
- public InventoryManager() {
- super(DiscoveryAgentService.class);
+ /**
+ * Constructs a new instance.
+ * Call {@link #initialize()} once constructed.
+ */
+ public InventoryManager(PluginContainerConfiguration configuration,
+ AgentServiceStreamRemoter streamRemoter, PluginManager pluginManager,
+ EventManager eventManager) {
+ super(DiscoveryAgentService.class, streamRemoter);
+ this.configuration = configuration;
+ if (pluginManager == null)
+ throw new NullPointerException("pluginManager is null");
+ this.pluginManager = pluginManager;
+ this.pluginFactory = new PluginComponentFactory(this, pluginManager);
+ this.eventManager = eventManager;
+ availabilityExecutor = new AvailabilityExecutor(this);
+ serviceScanExecutor = new RuntimeDiscoveryExecutor(this, configuration);
+ serverScanExecutor = new AutoDiscoveryExecutor(null, this);
+ discoveryComponentProxyFactory = new DiscoveryComponentProxyFactory(pluginFactory);
+ agent = new Agent(this.configuration.getContainerName(), null, 0, null, null);
}
/**
- * @see ContainerService#initialize()
+ * Loads the inventory, sets up the platform, measurement manager, and
+ * upgrades the resources, and schedules periodic tasks.
+ *
+ * Because of dependency circularity, initialization has to happen
+ * outside of the constructor.
+ *
+ * ClassLoaderManager depends on InventoryManager to return the platform resource.
+ * InventoryManager calls PluginComponentFactory which then calls ClassLoaderManager to load classes.
*/
- @Override
public void initialize() {
inventoryLock.writeLock().lock();
try {
log.info("Initializing Inventory Manager...");
- this.discoveryComponentProxyFactory = new DiscoveryComponentProxyFactory();
- this.discoveryComponentProxyFactory.initialize();
-
- this.agent = new Agent(this.configuration.getContainerName(), null, 0, null, null);
+ discoveryComponentProxyFactory.initialize();
if (configuration.isInsideAgent()) {
loadFromDisk();
@@ -249,6 +277,9 @@ public class InventoryManager extends AgentService implements ContainerService,
// Discover the platform first thing.
executePlatformScan();
+ // Initialize measurement manager
+ measurementManager = new MeasurementManager(configuration, getStreamRemoter(), this);
+
//try the resource upgrade before we have any schedulers set up
//so that we don't get any interventions from concurrently running
//discoveries.
@@ -257,13 +288,10 @@ public class InventoryManager extends AgentService implements ContainerService,
// Never run more than one avail check at a time.
availabilityThreadPoolExecutor = new ScheduledThreadPoolExecutor(AVAIL_THREAD_POOL_CORE_POOL_SIZE,
new LoggingThreadFactory(AVAIL_THREAD_POOL_NAME, true));
- availabilityExecutor = new AvailabilityExecutor(this);
// Never run more than one discovery scan at a time (service and service scans share the same pool).
inventoryThreadPoolExecutor = new ScheduledThreadPoolExecutor(1, new LoggingThreadFactory(
INVENTORY_THREAD_POOL_NAME, true));
- serverScanExecutor = new AutoDiscoveryExecutor(null, this, configuration);
- serviceScanExecutor = new RuntimeDiscoveryExecutor(this, configuration);
// Only schedule periodic discovery scans and avail checks if we are running inside the RHQ Agent (versus
// inside EmbJopr).
@@ -295,9 +323,8 @@ public class InventoryManager extends AgentService implements ContainerService,
*/
@Override
public void shutdown() {
- PluginContainer pluginContainer = PluginContainer.getInstance();
- pluginContainer.shutdownExecutorService(this.inventoryThreadPoolExecutor, true);
- pluginContainer.shutdownExecutorService(this.availabilityThreadPoolExecutor, true);
+ PluginContainer.shutdownExecutorService(this.inventoryThreadPoolExecutor, true);
+ PluginContainer.shutdownExecutorService(this.availabilityThreadPoolExecutor, true);
if (this.configuration.isInsideAgent()) {
this.persistToDisk();
}
@@ -631,11 +658,6 @@ public class InventoryManager extends AgentService implements ContainerService,
}
@Override
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
- }
-
- @Override
public void updatePluginConfiguration(int resourceId, Configuration newPluginConfiguration)
throws InvalidPluginConfigurationClientException, PluginContainerException {
ResourceContainer container = getResourceContainer(resourceId);
@@ -1496,8 +1518,7 @@ public class InventoryManager extends AgentService implements ContainerService,
parent.removeChildResource(resource);
}
- PluginContainer.getInstance().getMeasurementManager()
- .unscheduleCollection(Collections.singleton(resource.getId()));
+ measurementManager.unscheduleCollection(Collections.singleton(resource.getId()));
if (this.resourceContainersByUUID.remove(resource.getUuid()) == null) {
if (log.isDebugEnabled()) {
@@ -1792,10 +1813,9 @@ public class InventoryManager extends AgentService implements ContainerService,
}
private ClassLoader getResourceClassLoader(Resource resource) {
- PluginComponentFactory factory = PluginContainer.getInstance().getPluginComponentFactory();
ClassLoader classLoader;
try {
- classLoader = factory.getResourceClassloader(resource);
+ classLoader = pluginFactory.getResourceClassloader(resource);
} catch (PluginContainerException e) {
if (log.isTraceEnabled()) {
log.trace("Access to resource [" + resource + "] will fail due to missing classloader.", e);
@@ -1907,7 +1927,7 @@ public class InventoryManager extends AgentService implements ContainerService,
}
try {
// should not throw ResourceTypeNotEnabledException because we checked for that above - if it does, just handle it as an error
- component = PluginContainer.getInstance().getPluginComponentFactory().buildResourceComponent(resource);
+ component = pluginFactory.buildResourceComponent(resource);
} catch (Throwable e) {
throw new PluginContainerException("Could not build component for Resource [" + resource + "]", e);
}
@@ -1920,14 +1940,13 @@ public class InventoryManager extends AgentService implements ContainerService,
|| (parentResourceContainer.getResourceComponentState() == ResourceComponentState.STARTED);
if (isParentStarted) {
- PluginComponentFactory factory = PluginContainer.getInstance().getPluginComponentFactory();
ResourceType type = resource.getResourceType();
// wrap the discovery component in a proxy to allow us to timeout discovery invocations
ResourceDiscoveryComponent discoveryComponent;
try {
// should not throw ResourceTypeNotEnabledException because we checked for that above - if it does, just handle it as an error
- discoveryComponent = factory.getDiscoveryComponent(type, parentResourceContainer);
+ discoveryComponent = pluginFactory.getDiscoveryComponent(type, parentResourceContainer);
discoveryComponent = this.discoveryComponentProxyFactory.getDiscoveryComponentProxy(type,
discoveryComponent, getDiscoveryComponentTimeout(type), parentResourceContainer);
} catch (Exception e) {
@@ -2246,7 +2265,7 @@ public class InventoryManager extends AgentService implements ContainerService,
long start = System.currentTimeMillis();
log.info("Loading inventory from data file [" + file + "]...");
- InventoryFile inventoryFile = new InventoryFile(file);
+ InventoryFile inventoryFile = new InventoryFile(file, this);
inventoryFile.loadInventory();
this.platform = inventoryFile.getPlatform();
@@ -2325,7 +2344,7 @@ public class InventoryManager extends AgentService implements ContainerService,
}
}
File file = new File(dataDir, "inventory.dat");
- InventoryFile inventoryFile = new InventoryFile(file);
+ InventoryFile inventoryFile = new InventoryFile(file, this);
inventoryFile.storeInventory(this.platform, this.resourceContainersByUUID);
} catch (Exception e) {
log.error("Could not persist inventory data to disk", e);
@@ -2339,10 +2358,9 @@ public class InventoryManager extends AgentService implements ContainerService,
* @return The discovered platform (which might be a dummy in case of testing)
*/
private Resource discoverPlatform() {
- PluginComponentFactory componentFactory = PluginContainer.getInstance().getPluginComponentFactory();
SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();
- Set<ResourceType> platformTypes = this.pluginManager.getMetadataManager().getTypesForCategory(
- ResourceCategory.PLATFORM);
+ PluginMetadataManager metadataManager = pluginManager.getMetadataManager();
+ Set<ResourceType> platformTypes = metadataManager.getTypesForCategory(ResourceCategory.PLATFORM);
// This should only ever have 1 or, at most, 2 Resources
// (always the Java fallback platform, and the native platform if supported).
@@ -2359,7 +2377,7 @@ public class InventoryManager extends AgentService implements ContainerService,
// Go through all the platform types that are supported and see if they can detect our platform.
for (ResourceType platformType : platformTypes) {
try {
- ResourceDiscoveryComponent component = componentFactory.getDiscoveryComponent(platformType, null);
+ ResourceDiscoveryComponent component = pluginFactory.getDiscoveryComponent(platformType, null);
ResourceDiscoveryContext context = new ResourceDiscoveryContext(platformType, null, null,
systemInfo, Collections.EMPTY_LIST, Collections.EMPTY_LIST, configuration.getContainerName(),
this.configuration.getPluginContainerDeployment());
@@ -2570,22 +2588,7 @@ public class InventoryManager extends AgentService implements ContainerService,
}
private void installSchedules(Set<ResourceMeasurementScheduleRequest> scheduleRequests) {
- if (PluginContainer.getInstance().getMeasurementManager() != null) {
- PluginContainer.getInstance().getMeasurementManager().scheduleCollection(scheduleRequests);
- } else {
- // MeasurementManager hasn't yet been started (or is unavailable due to locking)
- // rhq-980 Adding defensive logging to report any issues installing schedules.
- log.info("MeasurementManager not available, persisting but not yet scheduling schedule requests.");
- for (ResourceMeasurementScheduleRequest resourceRequest : scheduleRequests) {
- if (log.isDebugEnabled()) {
- log.debug("MeasurementManager unavailable, resource [" + resourceRequest.getResourceId()
- + "] will have its schedules persisted but not scheduled");
- }
- ResourceContainer resourceContainer = getResourceContainer(resourceRequest.getResourceId());
- resourceContainer.setMeasurementSchedule(resourceRequest.getMeasurementSchedules());
- resourceContainer.setAvailabilitySchedule(resourceRequest.getAvailabilitySchedule());
- }
- }
+ this.measurementManager.scheduleCollection(scheduleRequests);
}
private DriftSyncManager createDriftSyncManager() {
@@ -2836,7 +2839,7 @@ public class InventoryManager extends AgentService implements ContainerService,
EventContext eventContext;
if (resource.getResourceType().getEventDefinitions() != null
&& !resource.getResourceType().getEventDefinitions().isEmpty()) {
- eventContext = new EventContextImpl(resource);
+ eventContext = new EventContextImpl(resource, eventManager);
} else {
eventContext = null;
}
@@ -2853,7 +2856,8 @@ public class InventoryManager extends AgentService implements ContainerService,
log.info("Resource ID is 0! Operation features will not work until the resource is synced with server");
}
- OperationContext operationContext = new OperationContextImpl(resource.getId());
+ OperationManager operationManager = PluginContainer.getInstance().getOperationManager();
+ OperationContext operationContext = new OperationContextImpl(resource.getId(), operationManager);
return operationContext;
}
@@ -2877,7 +2881,8 @@ public class InventoryManager extends AgentService implements ContainerService,
if (resource.getId() == 0) {
log.info("Resource ID is 0! Content features will not work until the resource is synced with server");
}
- ContentContext contentContext = new ContentContextImpl(resource.getId());
+ ContentManager contentManager = PluginContainer.getInstance().getContentManager();
+ ContentContext contentContext = new ContentContextImpl(resource.getId(), contentManager);
return contentContext;
}
@@ -2900,7 +2905,7 @@ public class InventoryManager extends AgentService implements ContainerService,
log.error("RESOURCE UUID IS NOT SET! Availability features may not work!");
}
- AvailabilityContext availabilityContext = new AvailabilityContextImpl(resource);
+ AvailabilityContext availabilityContext = new AvailabilityContextImpl(resource, this);
return availabilityContext;
}
@@ -3613,4 +3618,16 @@ public class InventoryManager extends AgentService implements ContainerService,
// nothing to do
}
}
+
+ public PluginComponentFactory getPluginComponentFactory() {
+ return this.pluginFactory;
+ }
+
+ public PluginManager getPluginManager() {
+ return pluginManager;
+ }
+
+ public MeasurementManager getMeasurementManager() {
+ return measurementManager;
+ }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
index 3dee763..e6ad17a 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.inventory;
import java.util.concurrent.Callable;
@@ -41,6 +42,8 @@ import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
+import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pc.util.LoggingThreadFactory;
@@ -55,9 +58,10 @@ import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
* @author Jason Dobies
*/
public class ResourceFactoryManager extends AgentService implements ContainerService, ResourceFactoryAgentService {
+ private static final Log log = LogFactory.getLog(ResourceFactoryManager.class);
// This used to be a single value fixed at 60 seconds. But create and delete actions can very well exceed 1 minute
- // depending on the type of resource being created, or perhaps graceful shutdown of a resource being deleted. So,
+ // depending on the type of resource being created, or perhaps graceful shutdown of a resource being deleted. So,
// allow the timeout value to be overriden by editing rhq-agent-env.sh with new -D settings. Also, create separate
// timeouts for create and delete, as their execution times really are not related. The properties are set in
// milliseconds:
@@ -92,39 +96,32 @@ public class ResourceFactoryManager extends AgentService implements ContainerSer
// Attributes --------------------------------------------
- private final Log log = LogFactory.getLog(ResourceFactoryManager.class);
-
/**
* Configuration elements for the running of this manager.
*/
- private PluginContainerConfiguration configuration;
+ private final PluginContainerConfiguration configuration;
/**
* Executor service used to perform tasks.
*/
- private ExecutorService executor;
+ private final ExecutorService executor;
/**
* Handle to the metadata manager.
*/
- private PluginMetadataManager metadataManager;
+ private final PluginMetadataManager metadataManager;
// Constructors --------------------------------------------
/**
* Creates a new <code>ResourceFactoryManager</code> and initializes it as a remoted object.
*/
- public ResourceFactoryManager() {
- super(ResourceFactoryAgentService.class);
- }
-
- // ContainerService Implementation --------------------------------------------
-
- public void initialize() {
+ public ResourceFactoryManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter, PluginManager pluginManager) {
+ super(ResourceFactoryAgentService.class, streamRemoter);
log.debug("Initializing...");
+ this.configuration = configuration;
- // Retrieve handle to metadata manager
- metadataManager = PluginContainer.getInstance().getPluginManager().getMetadataManager();
+ this.metadataManager = pluginManager.getMetadataManager();
// Initialize thread pool for executing tasks
int corePoolSize = configuration.getResourceFactoryCoreThreadPoolSize();
@@ -136,13 +133,8 @@ public class ResourceFactoryManager extends AgentService implements ContainerSer
}
public void shutdown() {
- PluginContainer pluginContainer = PluginContainer.getInstance();
// TODO (ips, 04/30/12): Is it safe to pass true here to interrupt executing threads?
- pluginContainer.shutdownExecutorService(executor, false);
- }
-
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
+ PluginContainer.shutdownExecutorService(executor, false);
}
// ResourceFactoryAgentService Implementation --------------------------------------------
@@ -275,7 +267,7 @@ public class ResourceFactoryManager extends AgentService implements ContainerSer
* Returns the component that should be used to create the resource in the given request.
*
* @param parentResourceId identifies the parent under which the new resource will be created
- * @param timeout the agent side timeout for the resource creation. if null or unusable use FACET_CREATE_TIMEOUT.
+ * @param timeout the agent side timeout for the resource creation. if null or unusable use FACET_CREATE_TIMEOUT.
*
* @return component used to create the resource
*
@@ -291,4 +283,4 @@ public class ResourceFactoryManager extends AgentService implements ContainerSer
return facet;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
index d9431d0..fa08c16 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.inventory;
import java.io.ByteArrayOutputStream;
@@ -39,7 +40,6 @@ import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.plugin.PluginComponentFactory;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
@@ -58,7 +58,7 @@ import org.rhq.core.util.exception.Severity;
* @author Ian Springer
*/
public class RuntimeDiscoveryExecutor implements Runnable, Callable<InventoryReport> {
- private Log log = LogFactory.getLog(RuntimeDiscoveryExecutor.class);
+ private static final Log log = LogFactory.getLog(RuntimeDiscoveryExecutor.class);
private final InventoryManager inventoryManager;
private final PluginContainerConfiguration pluginContainerConfiguration;
@@ -236,7 +236,7 @@ public class RuntimeDiscoveryExecutor implements Runnable, Callable<InventoryRep
return;
}
- PluginComponentFactory factory = PluginContainer.getInstance().getPluginComponentFactory();
+ PluginComponentFactory factory = inventoryManager.getPluginComponentFactory();
try {
@@ -316,4 +316,4 @@ public class RuntimeDiscoveryExecutor implements Runnable, Callable<InventoryRep
}
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
index 7aaf12a..bc731d8 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.measurement;
import java.util.ArrayDeque;
@@ -31,7 +32,6 @@ import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.util.ComponentUtil;
@@ -46,12 +46,12 @@ import org.rhq.core.util.exception.ThrowableUtil;
* @author Greg Hinkle
*/
public class MeasurementCollectorRunner implements Callable<MeasurementReport>, Runnable {
- private Log log = LogFactory.getLog(MeasurementCollectorRunner.class);
+ private static final Log log = LogFactory.getLog(MeasurementCollectorRunner.class);
- private MeasurementManager measurementManager;
+ private final MeasurementManager measurementManager;
- // this is only kept when in debug mode to help figure out which metrics are slowing things down.
- private ScheduleHistory scheduleHistory = new ScheduleHistory();
+ // this is only kept when in debug mode to help figure out which metrics are slowing things down.
+ private final ScheduleHistory scheduleHistory = new ScheduleHistory();
public MeasurementCollectorRunner(MeasurementManager measurementManager) {
this.measurementManager = measurementManager;
@@ -65,7 +65,7 @@ public class MeasurementCollectorRunner implements Callable<MeasurementReport>,
report = this.measurementManager.getActiveReport();
long start = System.currentTimeMillis();
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
+ InventoryManager im = this.measurementManager.getInventoryManager();
Set<ScheduledMeasurementInfo> requests = this.measurementManager.getNextScheduledSet();
@@ -219,4 +219,4 @@ public class MeasurementCollectorRunner implements Callable<MeasurementReport>,
super.addLast(e);
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
index 4be5b4c..5fc0804 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.measurement;
import java.lang.management.ManagementFactory;
@@ -55,6 +56,7 @@ import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.util.ComponentUtil;
@@ -85,42 +87,39 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
static final Log LOG = LogFactory.getLog(MeasurementManager.class);
- private ScheduledThreadPoolExecutor collectorThreadPool;
- private ScheduledThreadPoolExecutor senderThreadPool;
+ private final ScheduledThreadPoolExecutor collectorThreadPool;
+ private final ScheduledThreadPoolExecutor senderThreadPool;
- private MeasurementSenderRunner measurementSenderRunner;
+ private final MeasurementSenderRunner measurementSenderRunner;
MeasurementCollectorRunner measurementCollectorRunner;
- private PluginContainerConfiguration configuration;
+ private final PluginContainerConfiguration configuration;
- private PriorityQueue<ScheduledMeasurementInfo> scheduledRequests = new PriorityQueue<ScheduledMeasurementInfo>(
+ private final PriorityQueue<ScheduledMeasurementInfo> scheduledRequests = new PriorityQueue<ScheduledMeasurementInfo>(
10000);
- private InventoryManager inventoryManager;
+ private final InventoryManager inventoryManager;
- private Map<Integer, String> traitCache = new HashMap<Integer, String>();
+ private final Map<Integer, String> traitCache = new HashMap<Integer, String>();
- private Map<Integer, CachedValue> perMinuteCache = new HashMap<Integer, CachedValue>();
+ private final Map<Integer, CachedValue> perMinuteCache = new HashMap<Integer, CachedValue>();
- private MeasurementReport activeReport = new MeasurementReport();
+ private volatile MeasurementReport activeReport = new MeasurementReport();
- private ReentrantReadWriteLock measurementLock = new ReentrantReadWriteLock(true);
+ private final ReentrantReadWriteLock measurementLock = new ReentrantReadWriteLock(true);
// -- monitoring information
- private AtomicLong collectedMeasurements = new AtomicLong(0);
- private AtomicLong totalTimeCollecting = new AtomicLong(0);
- private AtomicLong sinceLastCollectedMeasurements = new AtomicLong(0);
- private AtomicLong sinceLastCollectedTime = new AtomicLong(System.currentTimeMillis());
-
- private AtomicLong lateCollections = new AtomicLong(0);
- private AtomicLong failedCollection = new AtomicLong(0);
+ private final AtomicLong collectedMeasurements = new AtomicLong(0);
+ private final AtomicLong totalTimeCollecting = new AtomicLong(0);
+ private final AtomicLong sinceLastCollectedMeasurements = new AtomicLong(0);
+ private final AtomicLong sinceLastCollectedTime = new AtomicLong(System.currentTimeMillis());
- public MeasurementManager() {
- super(MeasurementAgentService.class);
- }
+ private final AtomicLong lateCollections = new AtomicLong(0);
+ private final AtomicLong failedCollection = new AtomicLong(0);
- @Override
- public void initialize() {
+ public MeasurementManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter, InventoryManager inventoryManager) {
+ super(MeasurementAgentService.class, streamRemoter);
+ this.configuration = configuration;
LOG.info("Initializing Measurement Manager...");
if (configuration.isStartManagementBean()) {
@@ -132,7 +131,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
}
}
- this.inventoryManager = PluginContainer.getInstance().getInventoryManager();
+ this.inventoryManager = inventoryManager;
int threadPoolSize = configuration.getMeasurementCollectionThreadPoolSize();
long collectionInitialDelaySecs = configuration.getMeasurementCollectionInitialDelay();
@@ -157,9 +156,17 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
// Load persistent measurement schedules from the InventoryManager and reconstitute them.
Resource platform = this.inventoryManager.getPlatform();
+ if (platform == null)
+ throw new IllegalStateException("null platform");
reschedule(platform);
+ } else {
+ senderThreadPool = null;
+ collectorThreadPool = null;
+ measurementSenderRunner = null;
+ measurementCollectorRunner = null;
}
+
LOG.info("Measurement Manager initialized.");
}
@@ -220,10 +227,6 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
}
public MeasurementReport getActiveReport() {
- if (this.activeReport == null) {
- this.activeReport = new MeasurementReport();
- }
-
return activeReport;
}
@@ -261,7 +264,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
* Note that if the trait is not yet cached, this will return null, and the caller will
* be forced to make a live call to obtain the trait value, but at least this can help
* avoid unnecessarily calling the live resource.
- *
+ *
* @param scheduleId the schedule for the trait for a specific resource
* @return the trait's cached value, <code>null</code> if not available
*/
@@ -289,16 +292,14 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
@Override
public void shutdown() {
- PluginContainer pluginContainer = PluginContainer.getInstance();
-
if (this.collectorThreadPool != null) {
LOG.debug("Shutting down measurement collector thread pool...");
- pluginContainer.shutdownExecutorService(this.collectorThreadPool, true);
+ PluginContainer.shutdownExecutorService(this.collectorThreadPool, true);
}
if (this.senderThreadPool != null) {
LOG.debug("Shutting down measurement sender thread pool...");
- pluginContainer.shutdownExecutorService(this.senderThreadPool, true);
+ PluginContainer.shutdownExecutorService(this.senderThreadPool, true);
}
if (configuration.isStartManagementBean()) {
@@ -311,11 +312,6 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
}
}
- @Override
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
- }
-
/**
* This remoted method allows the server to schedule a bunch of resources with one call.
*
@@ -327,10 +323,8 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
*/
@Override
public synchronized void updateCollection(Set<ResourceMeasurementScheduleRequest> scheduleRequests) {
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
-
for (ResourceMeasurementScheduleRequest resourceRequest : scheduleRequests) {
- ResourceContainer resourceContainer = im.getResourceContainer(resourceRequest.getResourceId());
+ ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceRequest.getResourceId());
if (resourceContainer != null) {
// Update (not overwrite) measurement schedule data ...
resourceContainer.updateMeasurementSchedule(resourceRequest.getMeasurementSchedules());
@@ -338,7 +332,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
scheduleCollection(resourceRequest.getResourceId(), resourceRequest.getMeasurementSchedules());
if (resourceRequest.getAvailabilitySchedule() != null) {
// Set availability schedule data if present
- // This method also triggers a reschedule of availability check
+ // This method also triggers a reschedule of availability check
resourceContainer.setAvailabilitySchedule(resourceRequest.getAvailabilitySchedule());
}
} else {
@@ -368,17 +362,15 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
*/
@Override
public synchronized void scheduleCollection(Set<ResourceMeasurementScheduleRequest> scheduleRequests) {
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
-
for (ResourceMeasurementScheduleRequest resourceRequest : scheduleRequests) {
- ResourceContainer resourceContainer = im.getResourceContainer(resourceRequest.getResourceId());
+ ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceRequest.getResourceId());
if (resourceContainer != null) {
// Set measurement schedule data ...
resourceContainer.setMeasurementSchedule(resourceRequest.getMeasurementSchedules());
// ... and then reschedule collection
scheduleCollection(resourceRequest.getResourceId(), resourceRequest.getMeasurementSchedules());
// Set availability schedule data
- // This method also triggers a reschedule of availability check
+ // This method also triggers a reschedule of availability check
resourceContainer.setAvailabilitySchedule(resourceRequest.getAvailabilitySchedule());
} else {
// This will happen when the server sends down schedules to an agent with a cleaned inventory
@@ -452,17 +444,15 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
}
// spinder 12/16/11. BZ 760139. Modified to return empty sets instead of 'null' even for erroneous conditions.
- // Server side logging or erroneous runtime conditions still occurs, but callers to getRealTimeMeasurementValues
- // won't have to additionally check for null values now. This is a safe and better pattern.
- @Override
+ // Server side logging or erroneous runtime conditions still occurs, but callers to getRealTimeMeasurementValues
+ // won't have to additionally check for null values now. This is a safe and better pattern.
public Set<MeasurementData> getRealTimeMeasurementValue(int resourceId, Set<MeasurementScheduleRequest> requests) {
if (requests.size() == 0) {
// There's no need to even call getValues() on the ResourceComponent if the list of metric names is empty.
return Collections.emptySet();
}
MeasurementFacet measurementFacet;
- ResourceContainer resourceContainer = PluginContainer.getInstance().getInventoryManager()
- .getResourceContainer(resourceId);
+ ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceId);
if (resourceContainer == null) {
LOG.warn("Can not get resource container for resource with id " + resourceId);
return Collections.emptySet();
@@ -566,12 +556,12 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
* performed due to collection falling behind. The nextCollection will be set to:
* <pre>
* Now + 30s + [1..Interval]
- *
+ *
* Where [1..Interval] is some random number of seconds no lower that 1 and no higher than the standard interval
* for the measurement.
- * </pre>
+ * </pre>
*
- * @param scheduledMeasurementInfos the late schedules to reschedule
+ * @param scheduledMeasurementInfos the late schedules to reschedule
*/
synchronized void rescheduleLateCollections(Set<ScheduledMeasurementInfo> scheduledMeasurementInfos) {
@@ -585,7 +575,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
// push out 30s from the current time to at least get a minimal 30s interval
long nextCollection = now + 30000L;
- // then add a random number of seconds [1..interval]. This will spread out the next collection times to
+ // then add a random number of seconds [1..interval]. This will spread out the next collection times to
// hopefully avoid the "hot-spot" that caused us to fall behind.
long interval = scheduledMeasurement.getInterval();
int maxRandomInterval = (int) (interval / 1000L); // exclusive upper bound
@@ -663,7 +653,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
/**
* Given the name of a trait, this will find the value of that trait for the given resource.
- *
+ *
* @param container the container of the resource whose trait value is to be obtained
* @param traitName the name of the trait whose value is to be obtained
*
@@ -694,7 +684,7 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
requests.add(new MeasurementScheduleRequest(MeasurementScheduleRequest.NO_SCHEDULE_ID, traitName, 0, true,
DataType.TRAIT));
Set<MeasurementData> dataset = getRealTimeMeasurementValue(container.getResource().getId(), requests);
- if (dataset != null && dataset.size() == 1) {
+ if (dataset.size() == 1) {
Object value = dataset.iterator().next().getValue();
if (value != null) {
traitValue = value.toString();
@@ -785,4 +775,9 @@ public class MeasurementManager extends AgentService implements MeasurementAgent
long timestamp;
double value;
}
-}
\ No newline at end of file
+
+ public InventoryManager getInventoryManager() {
+ return inventoryManager;
+ }
+
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationContextImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationContextImpl.java
index 32b0ca9..5c64fd8 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationContextImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationContextImpl.java
@@ -1,25 +1,22 @@
- /*
- * 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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.operation;
import org.rhq.core.pc.PluginContainer;
@@ -33,18 +30,24 @@ import org.rhq.core.pluginapi.operation.OperationServices;
* @author Jason Dobies
*/
public class OperationContextImpl implements OperationContext {
- private int resourceId;
+ private final int resourceId;
+ private final OperationManager operationManager;
- public OperationContextImpl(int resourceId) {
+ public OperationContextImpl(int resourceId, OperationManager operationManager) {
this.resourceId = resourceId;
+ this.operationManager = operationManager;
+ }
+
+ @Deprecated
+ public OperationContextImpl(int resourceId) {
+ this(resourceId, PluginContainer.getInstance().getOperationManager());
}
public OperationServices getOperationServices() {
- OperationManager operationManager = PluginContainer.getInstance().getOperationManager();
return new OperationServicesAdapter(operationManager);
}
public int getResourceId() {
return resourceId;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
index b8a8376..be30f85 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.operation;
import java.util.EnumSet;
@@ -44,6 +45,7 @@ import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.operation.OperationInvocation.Status;
import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.pc.util.FacetLockType;
@@ -62,17 +64,15 @@ import org.rhq.core.util.exception.WrappedRemotingException;
public class OperationManager extends AgentService implements OperationAgentService, ContainerService {
private static final String SENDER_THREAD_POOL_NAME = "OperationManager.invoker";
- private final Log log = LogFactory.getLog(OperationManager.class);
-
- private PluginContainerConfiguration configuration;
- private Timer timer;
- private OperationThreadPoolGateway operationGateway;
+ private static final Log log = LogFactory.getLog(OperationManager.class);
- public OperationManager() {
- super(OperationAgentService.class);
- }
+ private final PluginContainerConfiguration configuration;
+ private final Timer timer;
+ private final OperationThreadPoolGateway operationGateway;
- public void initialize() {
+ public OperationManager(PluginContainerConfiguration configuration, AgentServiceStreamRemoter streamRemoter) {
+ super(OperationAgentService.class, streamRemoter);
+ this.configuration = configuration;
timer = new Timer(SENDER_THREAD_POOL_NAME + ".timeout-timer");
// read the javadoc on ThreadPoolExecutor and how max pool size is affected when using LinkedBlockingQueue
@@ -97,10 +97,6 @@ public class OperationManager extends AgentService implements OperationAgentServ
operationGateway.shutdown();
}
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
- }
-
public void invokeOperation(@NotNull final String jobId, final int resourceId, @NotNull final String operationName,
@Nullable final Configuration parameterConfig) throws PluginContainerException {
invokeOperation(jobId, resourceId, operationName, parameterConfig, getOperationServerService());
@@ -290,4 +286,4 @@ public class OperationManager extends AgentService implements OperationAgentServ
return null;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationThreadPoolGateway.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationThreadPoolGateway.java
index c431a93..540738a 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationThreadPoolGateway.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationThreadPoolGateway.java
@@ -1,25 +1,22 @@
- /*
- * 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.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.operation;
import java.util.ArrayList;
@@ -31,6 +28,7 @@ import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -56,7 +54,7 @@ import org.rhq.core.pc.operation.OperationInvocation.Status;
* @author John Mazzitelli
*/
public class OperationThreadPoolGateway {
- private final Log log = LogFactory.getLog(OperationThreadPoolGateway.class);
+ private static final Log log = LogFactory.getLog(OperationThreadPoolGateway.class);
/**
* Keyed on resource IDs, this contains the list of all queued up operation invocations. If an operation is
@@ -132,8 +130,7 @@ public class OperationThreadPoolGateway {
threadPoolQueueDrain = null; // help GC
log.debug("Shutting down operation invocation thread pool...");
- PluginContainer pluginContainer = PluginContainer.getInstance();
- pluginContainer.shutdownExecutorService(threadPool, true);
+ PluginContainer.shutdownExecutorService(threadPool, true);
}
for (OperationInvocation operationToCancel : doomedOperations) {
@@ -309,4 +306,4 @@ public class OperationThreadPoolGateway {
return contents;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginComponentFactory.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginComponentFactory.java
index 9f0502c..675dc08 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginComponentFactory.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginComponentFactory.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.plugin;
import java.net.URL;
@@ -36,8 +33,6 @@ import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.ContainerService;
-import org.rhq.core.pc.PluginContainer;
-import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pluginapi.inventory.ClassLoaderFacet;
@@ -56,9 +51,16 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
public class PluginComponentFactory implements ContainerService {
private static final Log log = LogFactory.getLog(PluginComponentFactory.class);
- private PluginContainerConfiguration configuration;
- private InventoryManager inventoryManager;
- private PluginManager pluginManager;
+ private final InventoryManager inventoryManager;
+ private final PluginManager pluginManager;
+
+ /**
+ * Constructs a new instance.
+ */
+ public PluginComponentFactory(InventoryManager inventoryManager, PluginManager pluginManager) {
+ this.inventoryManager = inventoryManager;
+ this.pluginManager = pluginManager;
+ }
/**
* This will create a new {@link ResourceDiscoveryComponent} instance that can be used to discover and create
@@ -83,8 +85,7 @@ public class PluginComponentFactory implements ContainerService {
return null;
}
- PluginManager pluginMgr = getPluginManager();
- PluginMetadataManager metadataManager = pluginMgr.getMetadataManager();
+ PluginMetadataManager metadataManager = pluginManager.getMetadataManager();
String className = metadataManager.getDiscoveryClass(resourceType);
String typeName = resourceType.getName();
String pluginName = resourceType.getPlugin();
@@ -116,7 +117,7 @@ public class PluginComponentFactory implements ContainerService {
ClassLoaderManager classLoaderMgr = pluginManager.getClassLoaderManager();
ClassLoader classLoader;
if (parentResourceContainer == null
- || getInventoryManager().getPlatform().equals(parentResourceContainer.getResource())) {
+ || inventoryManager.getPlatform().equals(parentResourceContainer.getResource())) {
classLoader = classLoaderMgr.obtainPluginClassLoader(pluginName);
} else {
ClassLoader parentClassLoader = parentResourceContainer.getResourceClassLoader();
@@ -156,10 +157,10 @@ public class PluginComponentFactory implements ContainerService {
public void stop() {
}
- };
+ };
}
- String className = getPluginManager().getMetadataManager().getComponentClass(resourceType);
- ResourceContainer resourceContainer = getInventoryManager().getResourceContainer(resource);
+ String className = pluginManager.getMetadataManager().getComponentClass(resourceType);
+ ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resource);
if (resourceContainer == null) {
throw new PluginContainerException("Resource container not found for " + resource + " - cannot create ResourceComponent.");
}
@@ -178,7 +179,7 @@ public class PluginComponentFactory implements ContainerService {
/**
* Given a resource, this will return the appropriate classloader for that resource.
* If no classloader has been created for it yet, one will be created by this method.
- *
+ *
* @param resource the resource whose classloader is to be returned (and possibly created if needed)
*
* @return the resource's classloader
@@ -187,9 +188,7 @@ public class PluginComponentFactory implements ContainerService {
*/
public ClassLoader getResourceClassloader(Resource resource) throws PluginContainerException {
try {
- InventoryManager inventoryMgr = getInventoryManager();
- PluginManager pluginMgr = getPluginManager();
- ClassLoaderManager classLoaderMgr = pluginMgr.getClassLoaderManager();
+ ClassLoaderManager classLoaderMgr = pluginManager.getClassLoaderManager();
ResourceType resourceType = resource.getResourceType();
@@ -203,12 +202,12 @@ public class PluginComponentFactory implements ContainerService {
ResourceContainer parentContainer;
if (parentResource != null) {
- parentContainer = inventoryMgr.getResourceContainer(parentResource);
+ parentContainer = inventoryManager.getResourceContainer(parentResource);
if (parentContainer == null) {
throw new PluginContainerException("Missing container for parent " + parentResource + " of "
+ resource + ".");
}
- } else if (resource.equals(inventoryMgr.getPlatform())) {
+ } else if (resource.equals(inventoryManager.getPlatform())) {
// the given resource is our top platform resource - just use its plugin classloader
return classLoaderMgr.obtainPluginClassLoader(resourceType.getPlugin());
} else {
@@ -256,8 +255,7 @@ public class PluginComponentFactory implements ContainerService {
ResourceDiscoveryComponent discoveryComponent = getDiscoveryComponent(resource.getResourceType(),
parentContainer);
if (discoveryComponent != null && discoveryComponent instanceof ClassLoaderFacet) {
- InventoryManager inventoryMgr = getInventoryManager();
- additionalJars = inventoryMgr.invokeDiscoveryComponentClassLoaderFacet(resource, discoveryComponent,
+ additionalJars = inventoryManager.invokeDiscoveryComponentClassLoaderFacet(resource, discoveryComponent,
parentContainer);
}
@@ -304,40 +302,11 @@ public class PluginComponentFactory implements ContainerService {
}
}
- private InventoryManager getInventoryManager() {
- if (this.inventoryManager == null) {
- this.inventoryManager = PluginContainer.getInstance().getInventoryManager();
- }
- return this.inventoryManager;
- }
-
- private PluginManager getPluginManager() {
- if (this.pluginManager == null) {
- this.pluginManager = PluginContainer.getInstance().getPluginManager();
- }
- return this.pluginManager;
- }
-
- /**
- * Creates our (initially empty) cache of discovery components.
- *
- * @see ContainerService#initialize()
- */
- public void initialize() {
- return;
- }
-
/**
* Clears our cache of discovery components.
*
* @see ContainerService#shutdown()
*/
public void shutdown() {
- this.inventoryManager = null;
- this.pluginManager = null;
- }
-
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginLifecycleListenerManagerImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginLifecycleListenerManagerImpl.java
index 3077f16..4886d67 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginLifecycleListenerManagerImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginLifecycleListenerManagerImpl.java
@@ -1,37 +1,33 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.plugin;
-import org.rhq.core.pc.PluginContainerConfiguration;
-import org.rhq.core.pluginapi.plugin.PluginLifecycleListener;
-import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
-import org.rhq.core.clientapi.agent.PluginContainerException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.Map;
-import java.util.HashMap;
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.pluginapi.plugin.PluginLifecycleListener;
public class PluginLifecycleListenerManagerImpl implements PluginLifecycleListenerManager {
@@ -45,7 +41,7 @@ public class PluginLifecycleListenerManagerImpl implements PluginLifecycleListen
public PluginLifecycleListener loadListener(PluginDescriptor pluginDescriptor, PluginEnvironment pluginEnvironment)
throws PluginContainerException {
-
+
PluginLifecycleListener listener = cache.get(pluginDescriptor.getName());
if (listener == null) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
index 483af9e..3eebbf0 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.plugin;
import java.io.File;
@@ -77,45 +74,60 @@ public class PluginManager implements ContainerService {
/**
* The map of all plugins keyed on plugin name.
*/
- private Map<String, PluginEnvironment> loadedPluginEnvironments;
+ private final Map<String, PluginEnvironment> loadedPluginEnvironments;
/**
* A list of loaded plugins in the order in which they were loaded.
*/
- private List<Plugin> loadedPlugins;
+ private final List<Plugin> loadedPlugins;
- private PluginMetadataManager metadataManager;
- private ClassLoaderManager classLoaderManager;
- private PluginContainerConfiguration configuration;
- private UpdateLoadedPlugins updateLoadedPlugins;
+ private final PluginMetadataManager metadataManager;
+ private final ClassLoaderManager classLoaderManager;
+ private final PluginContainerConfiguration pluginContainerConfiguration;
- private PluginLifecycleListenerManager pluginLifecycleListenerMgr = new PluginLifecycleListenerManagerImpl();
+ private final PluginLifecycleListenerManager pluginLifecycleListenerMgr;
+ private final UpdateLoadedPlugins updateLoadedPlugins;
/**
- * Finds all plugins using the plugin finder defined in the
- * {@link #setConfiguration(PluginContainerConfiguration) plugin container configuration} and
- * {@link #loadPlugin(java.net.URL, ClassLoader, org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor) loads} each plugin found.
- *
- * @see ContainerService#initialize()
+ * Finds all plugins using the plugin finder defined in the <code>pluginContainerConfiguration</code> and
+ * {@link #loadPlugin(java.net.URL, ClassLoader, org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor) loads}
+ * each plugin found.
*/
- public void initialize() {
+ public PluginManager(PluginContainerConfiguration pluginContainerConfiguration,
+ PluginLifecycleListenerManager pluginLifecycleListenerManager) {
+
+ if (pluginContainerConfiguration == null) {
+ throw new NullPointerException("pluginContainerConfiguration is null");
+ }
+ if (pluginLifecycleListenerManager == null) {
+ throw new NullPointerException("pluginLifecycleListenerManager is null");
+ }
+
+ this.pluginContainerConfiguration = pluginContainerConfiguration;
+ this.pluginLifecycleListenerMgr = pluginLifecycleListenerManager;
loadedPluginEnvironments = new HashMap<String, PluginEnvironment>();
loadedPlugins = new ArrayList<Plugin>();
metadataManager = new PluginMetadataManager();
- metadataManager.setDisabledResourceTypes(configuration.getDisabledResourceTypes());
+ metadataManager.setDisabledResourceTypes(pluginContainerConfiguration.getDisabledResourceTypes());
+ updateLoadedPlugins = new UpdateLoadedPlugins() {
+ PluginTransformer transformer = new PluginTransformer();
- initUpdateLoadedPluginsCallback();
+ public void execute(PluginDescriptor pluginDescriptor, URL pluginURL) {
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
+ loadedPlugins.add(plugin);
+ }
+ };
- PluginFinder finder = configuration.getPluginFinder();
- File tmpDir = configuration.getTemporaryDirectory();
- List<String> disabledPlugins = configuration.getDisabledPlugins();
+ PluginFinder finder = pluginContainerConfiguration.getPluginFinder();
+ File tmpDir = pluginContainerConfiguration.getTemporaryDirectory();
+ List<String> disabledPlugins = pluginContainerConfiguration.getDisabledPlugins();
// The root classloader for all plugins will have all classes hidden except for those configured in the regex.
// Notice this root classloader has no jar URLs - it will provide no classes except for what it will allow
// the parent to expose as dictated by the regex.
ClassLoader thisClassLoader = this.getClass().getClassLoader();
- String rootPluginClassLoaderRegex = configuration.getRootPluginClassLoaderRegex();
+ String rootPluginClassLoaderRegex = pluginContainerConfiguration.getRootPluginClassLoaderRegex();
ClassLoader rootCL = new RootPluginClassLoader(new URL[] {}, thisClassLoader, rootPluginClassLoaderRegex);
// build our empty class loader manager - we use it to create and manage our plugin's classloaders
@@ -123,7 +135,7 @@ public class PluginManager implements ContainerService {
// Save descriptors for later use, so we don't need to parse them twice.
Map<URL, PluginDescriptor> descriptors = new HashMap<URL, PluginDescriptor>();
PluginDependencyGraph graph = new PluginDependencyGraph();
- boolean createResourceCL = configuration.isCreateResourceClassloaders();
+ boolean createResourceCL = pluginContainerConfiguration.isCreateResourceClassloaders();
this.classLoaderManager = new ClassLoaderManager(pluginNamesUrls, graph, rootCL, tmpDir, createResourceCL);
if (finder == null) {
@@ -178,19 +190,6 @@ public class PluginManager implements ContainerService {
log.error("Error initializing plugin container", e);
throw new RuntimeException("Cannot initialize the plugin container", e);
}
-
- return;
- }
-
- private void initUpdateLoadedPluginsCallback() {
- updateLoadedPlugins = new UpdateLoadedPlugins() {
- PluginTransformer transformer = new PluginTransformer();
-
- public void execute(PluginDescriptor pluginDescriptor, URL pluginURL) {
- Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
- loadedPlugins.add(plugin);
- }
- };
}
/**
@@ -226,26 +225,9 @@ public class PluginManager implements ContainerService {
this.classLoaderManager.destroy();
this.loadedPluginEnvironments.clear();
- this.loadedPluginEnvironments = null;
-
this.loadedPlugins.clear();
- this.loadedPlugins = null;
pluginLifecycleListenerMgr.shutdown();
-
- this.metadataManager = null;
- this.classLoaderManager = null;
- }
-
- /**
- * @see ContainerService#setConfiguration(PluginContainerConfiguration)
- */
- public void setConfiguration(PluginContainerConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public void setPluginLifecycleListenerManager(PluginLifecycleListenerManager pluginLifecycleListenerManager) {
- this.pluginLifecycleListenerMgr = pluginLifecycleListenerManager;
}
/**
@@ -340,8 +322,6 @@ public class PluginManager implements ContainerService {
this.metadataManager.loadPlugin(pluginDescriptor);
pluginLifecycleListenerMgr.setListener(pluginDescriptor.getName(), overseer);
updateLoadedPlugins.execute(pluginDescriptor, pluginUrl);
-
- return;
}
/**
@@ -368,9 +348,9 @@ public class PluginManager implements ContainerService {
private PluginContext createPluginContext(String pluginName) {
SystemInfo sysInfo = SystemInfoFactory.createSystemInfo();
- File dataDir = new File(this.configuration.getDataDirectory(), pluginName);
- File tmpDir = this.configuration.getTemporaryDirectory();
- String pcName = this.configuration.getContainerName();
+ File dataDir = new File(pluginContainerConfiguration.getDataDirectory(), pluginName);
+ File tmpDir = pluginContainerConfiguration.getTemporaryDirectory();
+ String pcName = pluginContainerConfiguration.getContainerName();
PluginContext context = new PluginContext(pluginName, sysInfo, tmpDir, dataDir, pcName);
return context;
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginValidator.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginValidator.java
index 060390a..e54ab17 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginValidator.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginValidator.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.plugin;
import java.io.File;
@@ -108,9 +105,7 @@ public class PluginValidator {
configuration.setTemporaryDirectory(new File(System.getProperty("java.io.tmpdir")));
configuration.setDataDirectory(new File(System.getProperty("java.io.tmpdir")));
- PluginManager manager = new PluginManager();
- manager.setConfiguration(configuration);
- manager.initialize();
+ PluginManager manager = new PluginManager(configuration, new PluginLifecycleListenerManagerImpl());
boolean success = true; // assume all goes well; we'll set this to false if we hit any error
@@ -327,4 +322,4 @@ public class PluginValidator {
if (interactive)
System.out.println(warningMessage);
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
index 1c67c31..f601223 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.pc.support;
import java.io.InputStream;
@@ -23,8 +24,8 @@ import java.io.InputStream;
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.clientapi.agent.support.SupportAgentService;
import org.rhq.core.pc.ContainerService;
-import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pluginapi.support.SnapshotReportRequest;
@@ -40,24 +41,15 @@ import org.rhq.core.pluginapi.support.SupportFacet;
*/
public class SupportManager extends AgentService implements SupportAgentService, ContainerService {
- public SupportManager() {
- super(SupportAgentService.class);
- }
-
- public void setConfiguration(PluginContainerConfiguration configuration) {
- return;
- }
-
- public void initialize() {
- return;
+ public SupportManager(AgentServiceStreamRemoter streamRemoter) {
+ super(SupportAgentService.class, streamRemoter);
}
public void shutdown() {
- return;
}
public InputStream getSnapshotReport(int resourceId, String name, String description) throws Exception {
- SupportFacet facet = getSupportFacet(resourceId, 600000L); // give it enough time to zip up all the snapshot content
+ SupportFacet facet = getSupportFacet(resourceId, 600000L); // give it enough time to zip up all the snapshot content
SnapshotReportRequest request = new SnapshotReportRequest(name, description);
SnapshotReportResults results = facet.getSnapshotReport(request);
InputStream inputStream = results.getInputStream();
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/upgrade/ResourceUpgradeDelegate.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/upgrade/ResourceUpgradeDelegate.java
index 1fa5242..0e75463 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/upgrade/ResourceUpgradeDelegate.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/upgrade/ResourceUpgradeDelegate.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.upgrade;
@@ -34,7 +34,6 @@ import org.rhq.core.clientapi.agent.upgrade.ResourceUpgradeRequest;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.resource.ResourceUpgradeReport;
-import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
@@ -61,11 +60,11 @@ public class ResourceUpgradeDelegate {
private boolean enabled = true;
- private Set<ResourceUpgradeRequest> requests = new HashSet<ResourceUpgradeRequest>();
- private Set<ResourceUpgradeRequest> originalResourceData = new HashSet<ResourceUpgradeRequest>();
- private InventoryManager inventoryManager;
- private Set<Resource> failedResources = new HashSet<Resource>();
- private Map<Resource, Set<ResourceType>> failedResourceTypesPerParent = new HashMap<Resource, Set<ResourceType>>();
+ private final Set<ResourceUpgradeRequest> requests = new HashSet<ResourceUpgradeRequest>();
+ private final Set<ResourceUpgradeRequest> originalResourceData = new HashSet<ResourceUpgradeRequest>();
+ private final InventoryManager inventoryManager;
+ private final Set<Resource> failedResources = new HashSet<Resource>();
+ private final Map<Resource, Set<ResourceType>> failedResourceTypesPerParent = new HashMap<Resource, Set<ResourceType>>();
private boolean mergeFailed;
public ResourceUpgradeDelegate(InventoryManager inventoryManager) {
@@ -261,7 +260,7 @@ public class ResourceUpgradeDelegate {
ResourceDiscoveryComponent<ResourceComponent<T>> discoveryComponent;
try {
- discoveryComponent = PluginContainer.getInstance().getPluginComponentFactory()
+ discoveryComponent = inventoryManager.getPluginComponentFactory()
.getDiscoveryComponent(resource.getResourceType(), parentResourceContainer);
} catch (ResourceTypeNotEnabledException rtne) {
// no point in continuing if the resource is unmanageable because its type has been disabled
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
index bd98afd..2dcda30 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -19,14 +19,19 @@
package org.rhq.core.pc.util;
-import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.pc.PluginContainer;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
public class ComponentServiceImpl implements ComponentService {
+ private final PluginManager pluginManager;
+
+ public ComponentServiceImpl(PluginManager pluginManager) {
+ this.pluginManager = pluginManager;
+ }
+
public ResourceType getResourceType(int resourceId) throws PluginContainerException {
return ComponentUtil.getResourceType(resourceId);
}
@@ -38,12 +43,8 @@ public class ComponentServiceImpl implements ComponentService {
}
public String getAmpsVersion(int resourceId) throws PluginContainerException {
- PluginContainer pluginContainer = PluginContainer.getInstance();
- PluginManager pluginMgr = pluginContainer.getPluginManager();
-
ResourceType resourceType = getResourceType(resourceId);
-
- return pluginMgr.getAmpsVersion(resourceType.getPlugin());
+ return pluginManager.getAmpsVersion(resourceType.getPlugin());
}
public ResourceComponent fetchResourceComponent(int resourceId) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java
index dd2c443..8e9a4a3 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.util;
import java.lang.reflect.InvocationHandler;
@@ -61,11 +58,12 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
* @author Ian Springer
*/
public class DiscoveryComponentProxyFactory {
- private final Log log = LogFactory.getLog(DiscoveryComponentProxyFactory.class);
+ private static final Log log = LogFactory.getLog(DiscoveryComponentProxyFactory.class);
private static final String DAEMON_THREAD_POOL_NAME = "ResourceDiscoveryComponent.invoker.daemon";
private ExecutorService daemonThreadPool = null;
private final Set<ResourceType> blacklist = new HashSet<ResourceType>();
+ private final PluginComponentFactory pluginComponentFactory;
private static boolean blacklistDisable;
static {
try {
@@ -75,6 +73,9 @@ public class DiscoveryComponentProxyFactory {
} // always catch here, always let the class load, use a default if the sysprop is invalid
}
+ public DiscoveryComponentProxyFactory(PluginComponentFactory pluginComponentFactory) {
+ this.pluginComponentFactory = pluginComponentFactory;
+ }
/**
* Same as {@link #getDiscoveryComponentProxy(org.rhq.core.domain.resource.ResourceType, org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent, long, org.rhq.core.pc.inventory.ResourceContainer)} except
@@ -91,7 +92,6 @@ public class DiscoveryComponentProxyFactory {
}
try {
- PluginComponentFactory pluginComponentFactory = PluginContainer.getInstance().getPluginComponentFactory();
ClassLoader pluginClassLoader = pluginComponentFactory.getDiscoveryComponentClassLoader(
parentResourceContainer, type.getPlugin());
@@ -142,10 +142,9 @@ public class DiscoveryComponentProxyFactory {
public void shutdown() {
if (daemonThreadPool != null) {
- PluginContainer pluginContainer = PluginContainer.getInstance();
- pluginContainer.shutdownExecutorService(daemonThreadPool, true);
+ PluginContainer.shutdownExecutorService(daemonThreadPool, true);
+ daemonThreadPool = null;
}
- daemonThreadPool = null;
}
public HashSet<ResourceType> getResourceTypeBlacklist() {
@@ -190,7 +189,7 @@ public class DiscoveryComponentProxyFactory {
private final long timeout;
private final ResourceType resourceType;
private final ClassLoader pluginClassLoader;
- private Class<?> componentInterface;
+ private final Class<?> componentInterface;
public ResourceDiscoveryComponentInvocationHandler(ResourceType type, ResourceDiscoveryComponent component,
long timeout, ClassLoader pluginClassLoader, Class<?> componentInterface) {
@@ -286,7 +285,7 @@ public class DiscoveryComponentProxyFactory {
private final ResourceDiscoveryComponent component;
private final Method method;
private final Object[] args;
- private ClassLoader pluginClassLoader;
+ private final ClassLoader pluginClassLoader;
private Thread thread;
ComponentInvocationThread(ResourceDiscoveryComponent component, Method method, Object[] args,
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/BundleManagerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/BundleManagerTest.java
index 3b2b477..5ab112b 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/BundleManagerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/BundleManagerTest.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.bundle;
import java.io.File;
@@ -65,9 +62,13 @@ import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
+import org.rhq.core.pc.event.EventManager;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
+import org.rhq.core.pc.plugin.PluginLifecycleListenerManager;
+import org.rhq.core.pc.plugin.PluginLifecycleListenerManagerImpl;
+import org.rhq.core.pc.plugin.PluginManager;
import org.rhq.core.pluginapi.bundle.BundleDeployRequest;
import org.rhq.core.pluginapi.bundle.BundleDeployResult;
import org.rhq.core.pluginapi.bundle.BundleFacet;
@@ -78,19 +79,30 @@ import org.rhq.core.pluginapi.inventory.ResourceContext;
@Test
public class BundleManagerTest {
private MockBundleManager mockBundleManager;
+ private MockInventoryManager im;
private PluginContainerConfiguration pcConfig;
+ private PluginManager pluginManager;
+
+ private static final String BUNDLE_CONFIG_CONTEXT_VALUE_FS = getPath("/blah");
+ private static final String BUNDLE_CONFIG_LOCATION_PC = getPath("/pluginconfig/base/dir");
+ private static final String BUNDLE_CONFIG_LOCATION_RC = getPath("/resourceconfig/base/dir");
+ private static final String BUNDLE_CONFIG_LOCATION_MT = getPath("/trait/base/dir");
@BeforeMethod
public void beforeMethod() {
ServerServices serverServices = new ServerServices();
serverServices.setBundleServerService(new MockBundleServerService());
+ PluginLifecycleListenerManager pluginLifecycleListenerManager = new PluginLifecycleListenerManagerImpl();
pcConfig = new PluginContainerConfiguration();
+ pcConfig.setStartManagementBean(false);
pcConfig.setServerServices(serverServices);
+ ResourceContainer.initialize(pcConfig);
+ pluginManager = new PluginManager(pcConfig, pluginLifecycleListenerManager);
+ im = new MockInventoryManager();
+ im.initialize();
mockBundleManager = new MockBundleManager();
- mockBundleManager.setConfiguration(pcConfig);
- mockBundleManager.initialize();
// clear any past interrupted state
Thread.interrupted();
@@ -99,11 +111,13 @@ public class BundleManagerTest {
@AfterMethod
public void afterMethod() {
mockBundleManager.shutdown();
+ im.shutdown();
+ im.getMeasurementManager().shutdown();
+ ResourceContainer.shutdown();
pcConfig = null;
}
public void testNonPlatformBundleDeploy_FileSystem_AbsolutePath() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
@@ -128,8 +142,6 @@ public class BundleManagerTest {
}
public void testNonPlatformBundleDeploy_FileSystem_RelativePath() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
-
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
BundleVersion bundleVersion = new BundleVersion("bundleVersionName", "1.0", bundle, "");
@@ -143,7 +155,7 @@ public class BundleManagerTest {
// to test that we are really using this context value, our tests set it to something other than "/".
// That's why we prepend CONTEXT_VALUE_FS to the front of the destination's destDir
// note that we expect that relative path converted to absolute
- mockBundleManager.absolutePathToAssert = MockInventoryManager.BUNDLE_CONFIG_CONTEXT_VALUE_FS + "/relative/path";
+ mockBundleManager.absolutePathToAssert = BUNDLE_CONFIG_CONTEXT_VALUE_FS + "/relative/path";
BundleScheduleResponse response = mockBundleManager.schedule(request);
assertSuccess(response);
assertBundleDeploymentStatus(BundleDeploymentStatus.SUCCESS);
@@ -151,8 +163,6 @@ public class BundleManagerTest {
}
public void testNonPlatformBundleDeploy_PluginConfig() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
-
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
BundleVersion bundleVersion = new BundleVersion("bundleVersionName", "1.0", bundle, "");
@@ -162,7 +172,7 @@ public class BundleManagerTest {
BundleResourceDeployment resourceDeployment = new BundleResourceDeployment(bundleDeployment, im.serverPC);
BundleScheduleRequest request = new BundleScheduleRequest(resourceDeployment);
- mockBundleManager.absolutePathToAssert = MockInventoryManager.BUNDLE_CONFIG_LOCATION_PC + "/relative/path/pc";
+ mockBundleManager.absolutePathToAssert = BUNDLE_CONFIG_LOCATION_PC + "/relative/path/pc";
BundleScheduleResponse response = mockBundleManager.schedule(request);
assertSuccess(response);
assertBundleDeploymentStatus(BundleDeploymentStatus.SUCCESS);
@@ -170,8 +180,6 @@ public class BundleManagerTest {
}
public void testNonPlatformBundleDeploy_ResourceConfig() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
-
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
BundleVersion bundleVersion = new BundleVersion("bundleVersionName", "1.0", bundle, "");
@@ -181,7 +189,7 @@ public class BundleManagerTest {
BundleResourceDeployment resourceDeployment = new BundleResourceDeployment(bundleDeployment, im.serverRC);
BundleScheduleRequest request = new BundleScheduleRequest(resourceDeployment);
- mockBundleManager.absolutePathToAssert = MockInventoryManager.BUNDLE_CONFIG_LOCATION_RC + "/relative/path/rc";
+ mockBundleManager.absolutePathToAssert = BUNDLE_CONFIG_LOCATION_RC + "/relative/path/rc";
BundleScheduleResponse response = mockBundleManager.schedule(request);
assertSuccess(response);
assertBundleDeploymentStatus(BundleDeploymentStatus.SUCCESS);
@@ -189,8 +197,6 @@ public class BundleManagerTest {
}
public void testNonPlatformBundleDeploy_Trait() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
-
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
BundleVersion bundleVersion = new BundleVersion("bundleVersionName", "1.0", bundle, "");
@@ -200,7 +206,7 @@ public class BundleManagerTest {
BundleResourceDeployment resourceDeployment = new BundleResourceDeployment(bundleDeployment, im.serverMT);
BundleScheduleRequest request = new BundleScheduleRequest(resourceDeployment);
- mockBundleManager.absolutePathToAssert = MockInventoryManager.BUNDLE_CONFIG_LOCATION_MT + "/relative/path/mt";
+ mockBundleManager.absolutePathToAssert = BUNDLE_CONFIG_LOCATION_MT + "/relative/path/mt";
BundleScheduleResponse response = mockBundleManager.schedule(request);
assertSuccess(response);
assertBundleDeploymentStatus(BundleDeploymentStatus.SUCCESS);
@@ -208,8 +214,6 @@ public class BundleManagerTest {
}
public void testNonPlatformBundleDeploy_FileSystem_Failure() throws Exception {
- MockInventoryManager im = (MockInventoryManager) mockBundleManager.getInventoryManager();
-
BundleType bundleType = new BundleType("bundleTypeName", im.bundleHandlerType);
Bundle bundle = new Bundle("bundleName", bundleType, null, null);
BundleVersion bundleVersion = new BundleVersion("bundleVersionName", "1.0", bundle, "");
@@ -239,17 +243,13 @@ public class BundleManagerTest {
}
private class MockBundleManager extends BundleManager {
- public String absolutePathToAssert;
- @Override
- protected InventoryManager getInventoryManager() {
- return new MockInventoryManager();
+ public MockBundleManager() {
+ super(pcConfig, new MockAgentServiceStreamRemoter(), im,
+ new MockMeasurementManager(pcConfig));
}
- @Override
- protected MeasurementManager getMeasurementManager() {
- return new MockMeasurementManager();
- }
+ public String absolutePathToAssert;
@Override
protected BundleFacet getBundleFacet(int resourceId, long timeout) throws PluginContainerException {
@@ -313,21 +313,17 @@ public class BundleManagerTest {
}
}
- private static class MockInventoryManager extends InventoryManager {
+ private class MockInventoryManager extends InventoryManager {
private static final String BUNDLE_CONFIG_NAME_FS = "fsBaseDirLocation";
- private static final String BUNDLE_CONFIG_CONTEXT_VALUE_FS = getPath("/blah");
private static final String BUNDLE_CONFIG_NAME_PC = "pcBaseDirLocation";
private static final String BUNDLE_CONFIG_CONTEXT_VALUE_PC = "pcPropBundle";
- private static final String BUNDLE_CONFIG_LOCATION_PC = getPath("/pluginconfig/base/dir");
private static final String BUNDLE_CONFIG_NAME_RC = "rcBaseDirLocation";
private static final String BUNDLE_CONFIG_CONTEXT_VALUE_RC = "rcPropBundle";
- private static final String BUNDLE_CONFIG_LOCATION_RC = getPath("/resourceconfig/base/dir");
private static final String BUNDLE_CONFIG_NAME_MT = "mtBaseDirLocation";
private static final String BUNDLE_CONFIG_CONTEXT_VALUE_MT = "traitBundle";
- private static final String BUNDLE_CONFIG_LOCATION_MT = getPath("/trait/base/dir");
// mocking the following:
// - one platform type and a platform resource to be used as the root parent
@@ -349,10 +345,11 @@ public class BundleManagerTest {
public Resource serverPC;
public Resource serverRC;
public Resource serverMT;
- public HashMap<ResourceType, Resource> typeResourceMap = new HashMap<ResourceType, Resource>();
- public HashMap<Integer, ResourceContainer> idResourceContainerMap = new HashMap<Integer, ResourceContainer>();
+ public final HashMap<ResourceType, Resource> typeResourceMap = new HashMap<ResourceType, Resource>();
+ public final HashMap<Integer, ResourceContainer> idResourceContainerMap = new HashMap<Integer, ResourceContainer>();
public MockInventoryManager() {
+ super(pcConfig, null, pluginManager, new EventManager(pcConfig));
platformType = new ResourceType("platformResourceTypeName", "pluginName", ResourceCategory.PLATFORM, null);
bundleHandlerType = new ResourceType("bhRTypeName", "pluginName", ResourceCategory.SERVER, platformType);
serverTypeFS = new ResourceType("typeName-fileSystem", "pluginName", ResourceCategory.SERVER, platformType);
@@ -461,17 +458,23 @@ public class BundleManagerTest {
@Override
public ResourceContainer getResourceContainer(Resource resource) {
+ if (idResourceContainerMap == null)
+ return null;
return idResourceContainerMap.get(resource.getId());
}
}
private class MockMeasurementManager extends MeasurementManager {
+ public MockMeasurementManager(PluginContainerConfiguration configuration) {
+ super(configuration, null, im);
+ }
+
@Override
public Set<MeasurementData> getRealTimeMeasurementValue(int resourceId, Set<MeasurementScheduleRequest> requests) {
// anytime this method gets called, it means our tests are asking for the test trait value. It will
// always be the same value for all tests.
MeasurementDataTrait data = new MeasurementDataTrait(requests.iterator().next(),
- MockInventoryManager.BUNDLE_CONFIG_LOCATION_MT);
+ BUNDLE_CONFIG_LOCATION_MT);
Set<MeasurementData> values = new HashSet<MeasurementData>();
values.add(data);
return values;
@@ -484,4 +487,4 @@ public class BundleManagerTest {
super(resource, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/MockAgentServiceStreamRemoter.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/MockAgentServiceStreamRemoter.java
new file mode 100644
index 0000000..08ea0a7
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/bundle/MockAgentServiceStreamRemoter.java
@@ -0,0 +1,41 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.pc.bundle;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.rhq.core.pc.agent.AgentServiceStreamRemoter;
+
+public class MockAgentServiceStreamRemoter implements AgentServiceStreamRemoter {
+
+ @Override
+ public InputStream prepareInputStream(InputStream stream) {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+
+ @Override
+ public OutputStream prepareOutputStream(OutputStream stream) {
+ return new ByteArrayOutputStream();
+ }
+
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
index c8443e9..ab90af6 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
@@ -1,48 +1,43 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.configuration;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertNotNull;
import java.util.Set;
-import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.rhq.core.pluginapi.inventory.ResourceComponent;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
-
-import org.testng.annotations.Test;
+import org.jmock.Expectations;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
-import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.RawConfiguration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
-import org.jmock.Expectations;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pc.util.FacetLockType;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
@@ -58,8 +53,7 @@ public class ConfigManagementFactoryImplTest extends ConfigManagementTest {
@BeforeMethod
public void setup() {
- factory = new ConfigManagementFactoryImpl();
- factory.setComponentService(componentService);
+ factory = new ConfigManagementFactoryImpl(componentService);
}
@Test
@@ -102,7 +96,7 @@ public class ConfigManagementFactoryImplTest extends ConfigManagementTest {
allowing(componentService).fetchResourceComponent(resourceId);
will(returnValue(new MockResourceConfigurationFacetForLegacy()));
-
+
}
});
@@ -125,7 +119,7 @@ public class ConfigManagementFactoryImplTest extends ConfigManagementTest {
allowing(componentService).getResourceType(resourceId);
will(returnValue(createResourceTypeThatSupportsStructured()));
-
+
allowing(componentService).fetchResourceComponent(resourceId);
will(returnValue(new MockResourceConfigurationFacet()));
}
@@ -150,7 +144,7 @@ public class ConfigManagementFactoryImplTest extends ConfigManagementTest {
allowing(componentService).getResourceType(resourceId);
will(returnValue(createResourceTypeThatSupportsStructured()));
-
+
allowing(componentService).fetchResourceComponent(resourceId);
will(returnValue(new MockResourceConfigurationFacet()));
@@ -246,7 +240,7 @@ public class ConfigManagementFactoryImplTest extends ConfigManagementTest {
allowing(componentService).getResourceType(resourceId);
will(returnValue(createResourceTypeThatSupportsStructured()));
-
+
allowing(componentService).fetchResourceComponent(resourceId);
will(returnValue(new MockResourceConfigurationFacet()));
}
@@ -303,12 +297,12 @@ class MockResourceConfigurationFacetForLegacy implements ResourceComponent{
public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception {
// TODO Auto-generated method stub
-
+
}
public void stop() {
// TODO Auto-generated method stub
-
+
}
public AvailabilityType getAvailability() {
@@ -374,5 +368,3 @@ class MockResourceConfigurationFacet implements ResourceComponent, ResourceConfi
return null;
}
};
-
-
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationManagerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationManagerTest.java
index 9a08bae..22b9b41 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationManagerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationManagerTest.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.configuration;
@@ -65,10 +61,8 @@ public class ConfigurationManagerTest extends ConfigManagementTest {
@BeforeMethod
public void setup() {
configMgmtFactory = context.mock(ConfigManagementFactory.class);
-
- configurationMgr = new ConfigurationManager();
- configurationMgr.setConfigManagementFactory(configMgmtFactory);
- configurationMgr.setComponentService(componentService);
+ PluginContainerConfiguration containerConfig = new PluginContainerConfiguration();
+ configurationMgr = new ConfigurationManager(containerConfig, componentService, configMgmtFactory, null, null);
}
@Test
@@ -399,12 +393,9 @@ public class ConfigurationManagerTest extends ConfigManagementTest {
final ConfigurationServerService configServerService = context.mock(ConfigurationServerService.class);
- PluginContainerConfiguration containerConfig = new PluginContainerConfiguration();
ServerServices serverServices = new ServerServices();
serverServices.setConfigurationServerService(configServerService);
- configurationMgr.setConfiguration(containerConfig);
-
final UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(
configServerService, resourceType, configMgmt, request);
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
index 0f2d30a..006d0c3 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.drift;
@@ -73,10 +73,7 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue = new ScheduleQueueImpl();
- detector = new DriftDetector();
- detector.setDriftClient(driftClient);
- detector.setChangeSetManager(changeSetMgr);
- detector.setScheduleQueue(scheduleQueue);
+ detector = new DriftDetector(scheduleQueue, changeSetMgr, driftClient);
}
@Test
@@ -230,7 +227,7 @@ public class DriftDetectorTest extends DriftTest {
@Test
public void skipDetectionForScheduledThatIsDisabled() throws Exception {
- detector.setDriftClient(new DriftClientTestStub() {
+ DriftClientTestStub driftClient = new DriftClientTestStub() {
{
setBaseDir(resourceDir);
}
@@ -239,7 +236,7 @@ public class DriftDetectorTest extends DriftTest {
public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
fail("Should not invoke drift client when drift definition is disabled");
}
- });
+ };
DriftDefinition def = driftDefinition("disabled-config-test", resourceDir.getAbsolutePath());
def.setEnabled(false);
@@ -252,6 +249,7 @@ public class DriftDetectorTest extends DriftTest {
touch(server1Conf);
scheduleQueue.addSchedule(schedule);
+ detector = new DriftDetector(scheduleQueue, changeSetMgr, driftClient);
detector.run();
// make sure that the next scan time is not updated
@@ -886,7 +884,7 @@ public class DriftDetectorTest extends DriftTest {
// was previously detected. It should not however, produce a new current snapshot
// since there are no changes on the file system.
final AtomicBoolean repeatChangeSetCalled = new AtomicBoolean(false);
- detector.setDriftClient(new DriftClientTestStub() {
+ DriftClientTestStub driftClient = new DriftClientTestStub() {
{
setBaseDir(resourceDir);
}
@@ -904,9 +902,10 @@ public class DriftDetectorTest extends DriftTest {
+ "is wrong");
assertEquals(version, 1, "The snapshot version should not have changed since no new drift was detected");
}
- });
+ };
schedule.resetSchedule();
+ detector = new DriftDetector(scheduleQueue, changeSetMgr, driftClient);
detector.run();
// verify that the current snapshot file has not changed
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
index 93832bf..a2d49ba 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.pc.drift;
@@ -49,8 +49,11 @@ import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
+import org.rhq.core.pc.event.EventManager;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
+import org.rhq.core.pc.plugin.PluginLifecycleListenerManagerImpl;
+import org.rhq.core.pc.plugin.PluginManager;
public class DriftManagerTest extends DriftTest {
@@ -60,6 +63,8 @@ public class DriftManagerTest extends DriftTest {
private PluginContainerConfiguration pcConfig;
+ private PluginManager pluginManager;
+
private TestDriftManager driftMgr;
@BeforeMethod
@@ -67,6 +72,7 @@ public class DriftManagerTest extends DriftTest {
tmpDir = mkdir(basedir(), "tmp");
pcConfig = new PluginContainerConfiguration();
+ pluginManager = new PluginManager(pcConfig, new PluginLifecycleListenerManagerImpl());
ServerServices serverServices = new ServerServices();
driftServerService = new TestDriftServerService();
serverServices.setDriftServerService(driftServerService);
@@ -74,8 +80,7 @@ public class DriftManagerTest extends DriftTest {
pcConfig.setDataDirectory(basedir());
pcConfig.setTemporaryDirectory(tmpDir);
- driftMgr = new TestDriftManager();
- driftMgr.setConfiguration(pcConfig);
+ driftMgr = new TestDriftManager(pcConfig);
driftMgr.setChangeSetMgr(changeSetMgr);
}
@@ -379,18 +384,22 @@ public class DriftManagerTest extends DriftTest {
void execute();
}
- private static class TestDriftManager extends DriftManager {
-
- FakeInventoryManager inventoryMgr = new FakeInventoryManager();
+ private class TestDriftManager extends DriftManager {
- @Override
- public InventoryManager getInventoryManager() {
- return inventoryMgr;
+ public TestDriftManager(PluginContainerConfiguration configuration) {
+ super(configuration, null, new FakeInventoryManager(configuration));
}
+
}
- private static class FakeInventoryManager extends InventoryManager {
- private Map<Integer, ResourceContainer> resourceContainers = new HashMap<Integer, ResourceContainer>();
+ private class FakeInventoryManager extends InventoryManager {
+
+ private final Map<Integer, ResourceContainer> resourceContainers = new HashMap<Integer, ResourceContainer>();
+
+ public FakeInventoryManager(PluginContainerConfiguration configuration) {
+ super(configuration, null, pluginManager, new EventManager(configuration));
+ initialize();
+ }
@Override
public ResourceContainer getResourceContainer(int resourceId) {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/OperationManagerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/OperationManagerTest.java
index e215fd7..0abaa2b 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/OperationManagerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/OperationManagerTest.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.operation;
import java.text.SimpleDateFormat;
@@ -69,9 +66,7 @@ public class OperationManagerTest {
pcConfig.setOperationInvocationTimeout(5);
pcConfig.setServerServices(serverServices);
- manager = new MockOperationManager();
- manager.setConfiguration(pcConfig);
- manager.initialize();
+ manager = new MockOperationManager(pcConfig);
}
@AfterMethod
@@ -532,6 +527,10 @@ public class OperationManagerTest {
private class MockOperationManager extends OperationManager {
+ public MockOperationManager(PluginContainerConfiguration configuration) {
+ super(configuration, null);
+ }
+
@Override
protected OperationFacet getOperationFacet(int resourceId, long facetMethodTimeout)
throws PluginContainerException {
@@ -612,4 +611,4 @@ public class OperationManagerTest {
private static String formatTime(long date) {
return new SimpleDateFormat("HH:mm:ss.S").format(new Date(date));
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/ParallelOperationsTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/ParallelOperationsTest.java
index a1713d7..0ffd899 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/ParallelOperationsTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/operation/ParallelOperationsTest.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.operation;
import java.text.SimpleDateFormat;
@@ -71,9 +68,7 @@ public class ParallelOperationsTest {
pcConfig.setOperationInvocationTimeout(OPERATION_TIMEOUT_MILLIS / 1000L);
pcConfig.setServerServices(serverServices);
- manager = new MockOperationManager();
- manager.setConfiguration(pcConfig);
- manager.initialize();
+ manager = new MockOperationManager(pcConfig);
println("Starting new test method...");
}
@@ -159,6 +154,10 @@ public class ParallelOperationsTest {
private class MockOperationManager extends OperationManager {
+ public MockOperationManager(PluginContainerConfiguration configuration) {
+ super(configuration, null);
+ }
+
@Override
protected OperationFacet getOperationFacet(int resourceId, long facetMethodTimeout)
throws PluginContainerException {
@@ -246,4 +245,4 @@ public class ParallelOperationsTest {
private static String formatTime(long date) {
return new SimpleDateFormat("HH:mm:ss.S").format(new Date(date));
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/plugin/PluginManagerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/plugin/PluginManagerTest.java
index 4a72afb..244f32e 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/plugin/PluginManagerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/plugin/PluginManagerTest.java
@@ -1,37 +1,27 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2014 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.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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.
+ * GNU 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.
+ * 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.pc.plugin;
-import org.apache.commons.io.FileUtils;
-import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
-import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
-import org.rhq.core.pc.PluginContainerConfiguration;
-import org.rhq.core.pluginapi.plugin.PluginContext;
-import org.rhq.core.pluginapi.plugin.PluginLifecycleListener;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import java.io.File;
import java.net.URL;
@@ -42,9 +32,16 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
+import org.apache.commons.io.FileUtils;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.pc.PluginContainerConfiguration;
+import org.rhq.core.pluginapi.plugin.PluginContext;
+import org.rhq.core.pluginapi.plugin.PluginLifecycleListener;
public class PluginManagerTest {
@@ -89,11 +86,8 @@ public class PluginManagerTest {
@Test
public void initializeShouldLoadDiscoveredPlugins() throws Exception {
PluginContainerConfiguration configuration = createConfiguration();
-
- PluginManager pluginMgr = new PluginManager();
- pluginMgr.setConfiguration(configuration);
- pluginMgr.initialize();
-
+ FakePluginLifecycleListenerManager mgr = new FakePluginLifecycleListenerManager();
+ PluginManager pluginMgr = new PluginManager(configuration, mgr);
verifyThatPluginsAreLoaded(pluginMgr);
}
@@ -103,10 +97,7 @@ public class PluginManagerTest {
FakePluginLifecycleListenerManager pluginLifecycleListenerMgr = new FakePluginLifecycleListenerManager();
- PluginManager pluginMgr = new PluginManager();
- pluginMgr.setConfiguration(configuration);
- pluginMgr.setPluginLifecycleListenerManager(pluginLifecycleListenerMgr);
- pluginMgr.initialize();
+ PluginManager pluginMgr = new PluginManager(configuration, pluginLifecycleListenerMgr);
verifyPluginsLoadedInCorrectOrder(pluginLifecycleListenerMgr);
}
@@ -117,11 +108,7 @@ public class PluginManagerTest {
FakePluginLifecycleListenerManager pluginLifecycleListenerMgr = new FakePluginLifecycleListenerManager();
- PluginManager pluginMgr = new PluginManager();
- pluginMgr.setConfiguration(configuration);
- pluginMgr.setPluginLifecycleListenerManager(pluginLifecycleListenerMgr);
- pluginMgr.initialize();
-
+ PluginManager pluginMgr = new PluginManager(configuration, pluginLifecycleListenerMgr);
pluginMgr.shutdown();
verifyPluginsShutdownInCorrectOrder(pluginLifecycleListenerMgr);
@@ -239,9 +226,9 @@ public class PluginManagerTest {
* tests.
*/
static class PluginLifecycleTracker {
- private List<String> initializedPlugins = new LinkedList<String>();
+ private final List<String> initializedPlugins = new LinkedList<String>();
- private List<String> shutdownPlugins = new LinkedList<String>();
+ private final List<String> shutdownPlugins = new LinkedList<String>();
public void initialize(String plugin) {
initializedPlugins.add(plugin);
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/test/pc/PluginContainerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/test/pc/PluginContainerTest.java
index 5beb7a5..0b31066 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/test/pc/PluginContainerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/test/pc/PluginContainerTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2011 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.test.pc;
@@ -178,17 +178,8 @@ public class PluginContainerTest extends JMockTest {
*/
public static void startConfiguredPluginContainer() {
PluginContainer.getInstance().setConfiguration(getCurrentPluginContainerConfiguration());
-
PluginContainer.getInstance().initialize();
- try {
- while (!PluginContainer.getInstance().isStarted()) {
- Thread.sleep(100);
- }
- } catch (InterruptedException e) {
- throw new IllegalStateException("Thread interrupted while waiting for plugin container to start.", e);
- }
-
InventoryManager im = PluginContainer.getInstance().getInventoryManager();
for (int i = 0; i < CURRENT_SETUP.get().numberOfInitialDiscoveries(); ++i) {
im.executeServerScanImmediately();
@@ -409,6 +400,8 @@ public class PluginContainerTest extends JMockTest {
if ("classpath".equals(pluginUri.getScheme())) {
String path = pluginUri.getPath();
pluginUrl = testObject.getClass().getResource(path);
+ if (pluginUrl == null)
+ throw new IOException("could not find " + pluginUri);
} else {
pluginUrl = pluginUri.toURL();
}
diff --git a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
index e904c56..ac35380 100644
--- a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
+++ b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.plugin.testutil;
import static org.testng.Assert.assertEquals;
@@ -101,7 +102,7 @@ import org.rhq.test.shrinkwrap.RhqAgentPluginArchive;
*/
public abstract class AbstractAgentPluginTest extends Arquillian {
- private Log log = LogFactory.getLog(this.getClass());
+ private static final Log log = LogFactory.getLog(AbstractAgentPluginTest.class);
@ArquillianResource
protected MockingServerServices serverServices;
@@ -705,7 +706,6 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
ignoredResources = (ignoredResources == null) ? new ArrayList<String>() : ignoredResources;
ConfigurationManager configManager = this.pluginContainer.getConfigurationManager();
- configManager.initialize();
Thread.sleep(10 * 1000L);
Queue<Resource> unparsedResources = new LinkedList<Resource>();
diff --git a/modules/plugins/cassandra/src/test/java/org/rhq/plugins/cassandra/itest/DiscoveryAndConfigurationTest.java b/modules/plugins/cassandra/src/test/java/org/rhq/plugins/cassandra/itest/DiscoveryAndConfigurationTest.java
index 19f7cc5..09c9005 100644
--- a/modules/plugins/cassandra/src/test/java/org/rhq/plugins/cassandra/itest/DiscoveryAndConfigurationTest.java
+++ b/modules/plugins/cassandra/src/test/java/org/rhq/plugins/cassandra/itest/DiscoveryAndConfigurationTest.java
@@ -1,8 +1,7 @@
/*
* RHQ Management Platform
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright (C) 2005-2014 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 as published by
@@ -14,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.plugins.cassandra.itest;
@@ -60,13 +59,13 @@ import org.rhq.core.pluginapi.operation.OperationResult;
*/
@Test(groups = { "integration" }, singleThreaded = true, enabled = DiscoveryAndConfigurationTest.ENABLED)
public class DiscoveryAndConfigurationTest {
+ private static final Log log = LogFactory.getLog(DiscoveryAndConfigurationTest.class);
public static final boolean ENABLED = false;
private static final int TYPE_HIERARCHY_DEPTH = 6;
protected static final String PLUGIN_NAME = "Cassandra";
- private Log log = LogFactory.getLog(this.getClass());
private ConfigurationManager configManager;
@@ -95,7 +94,6 @@ public class DiscoveryAndConfigurationTest {
}
configManager = PluginContainer.getInstance().getConfigurationManager();
- configManager.initialize();
Thread.sleep(10 * 1000L);
} catch (Exception e) {
@@ -272,4 +270,4 @@ public class DiscoveryAndConfigurationTest {
return foundResources;
}
-}
\ No newline at end of file
+}
diff --git a/modules/plugins/database/src/test/java/org/rhq/plugins/database/ComponentTest.java b/modules/plugins/database/src/test/java/org/rhq/plugins/database/ComponentTest.java
index 8e869e4..c01b3f3 100644
--- a/modules/plugins/database/src/test/java/org/rhq/plugins/database/ComponentTest.java
+++ b/modules/plugins/database/src/test/java/org/rhq/plugins/database/ComponentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -136,9 +136,9 @@ public abstract class ComponentTest {
*/
private EventManager eventManager;
- private PluginContainer pluginContainer = PluginContainer.getInstance();
+ private final PluginContainer pluginContainer = PluginContainer.getInstance();
- private SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();
+ private final SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();
/**
* Scan all processes before starting; false will disable this feature.
@@ -152,8 +152,8 @@ public abstract class ComponentTest {
private final File temporaryDirectory = temp;
private final File dataDirectory = temp;
private final String pluginContainerName = "rhq";
- private final OperationContext operationContext = new OperationContextImpl(0);
- private final ContentContext contentContext = new ContentContextImpl(0);
+ private final OperationContext operationContext = new OperationContextImpl(0, null);
+ private final ContentContext contentContext = new ContentContextImpl(0, null);
private PluginContainerDeployment pluginContainerDeployment = null;
private Resource platform;
private ResourceContainer platformContainer;
@@ -296,10 +296,10 @@ public abstract class ComponentTest {
String rclassname = pmm.getComponentClass(type);
ResourceComponent component = (ResourceComponent) Class.forName(rclassname).newInstance();
- availabilityContext = new AvailabilityContextImpl(cresource);
+ availabilityContext = new AvailabilityContextImpl(cresource, pluginContainer.getInventoryManager());
inventoryContext = new InventoryContextImpl(cresource);
- EventContext eventContext = new EventContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
ResourceContext context = new ResourceContext(cresource, parentComponent,
null, rdc, systemInfo, temporaryDirectory, dataDirectory,
pluginContainerName, eventContext, operationContext, contentContext,
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/domain/SecurityModuleOptionsTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/domain/SecurityModuleOptionsTest.java
index c8544c1..bd3ad3a 100644
--- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/domain/SecurityModuleOptionsTest.java
+++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/domain/SecurityModuleOptionsTest.java
@@ -267,7 +267,6 @@ public class SecurityModuleOptionsTest extends AbstractJBossAS7PluginTest {
if (testConfigurationManager == null) {
testConfigurationManager = this.pluginContainer.getConfigurationManager();
testConfigurationManager = pluginContainer.getConfigurationManager();
- testConfigurationManager.initialize();
Thread.sleep(20 * 1000L);
}
//iterate through list of nodes and make sure they've all been discovered
diff --git a/modules/plugins/mysql/src/test/java/org/rhq/plugins/mysql/ComponentTest.java b/modules/plugins/mysql/src/test/java/org/rhq/plugins/mysql/ComponentTest.java
index fdcce4a..1b54245 100644
--- a/modules/plugins/mysql/src/test/java/org/rhq/plugins/mysql/ComponentTest.java
+++ b/modules/plugins/mysql/src/test/java/org/rhq/plugins/mysql/ComponentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -293,10 +293,10 @@ public abstract class ComponentTest {
String rclassname = pmm.getComponentClass(type);
ResourceComponent component = (ResourceComponent) Class.forName(rclassname).newInstance();
- AvailabilityContext availContext = new AvailabilityContextImpl(cresource);
+ AvailabilityContext availContext = new AvailabilityContextImpl(cresource, pluginContainer.getInventoryManager());
InventoryContext inventoryContext = new InventoryContextImpl(cresource);
- EventContext eventContext = new EventContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
ResourceContext context = new ResourceContext(cresource, parentComponent,
null, rdc, systemInfo, temporaryDirectory, dataDirectory,
pluginContainerName, eventContext, operationContext, contentContext,
diff --git a/modules/plugins/oracle/src/test/java/org/rhq/plugins/oracle/ComponentTest.java b/modules/plugins/oracle/src/test/java/org/rhq/plugins/oracle/ComponentTest.java
index 346565b..6762b0b 100644
--- a/modules/plugins/oracle/src/test/java/org/rhq/plugins/oracle/ComponentTest.java
+++ b/modules/plugins/oracle/src/test/java/org/rhq/plugins/oracle/ComponentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -151,8 +151,8 @@ public abstract class ComponentTest {
resource.setParentResource(pluginContainer.getInventoryManager().getPlatform());
ResourceDiscoveryComponent resourceDiscoveryComponent = new NothingDiscoveringDiscoveryComponent();
- EventContext eventContext = new EventContextImpl(resource);
- AvailabilityContext availContext = new AvailabilityContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
+ AvailabilityContext availContext = new AvailabilityContextImpl(resource, pluginContainer.getInventoryManager());
InventoryContext inventoryContext = new InventoryContextImpl(resource);
ResourceContext context = new ResourceContext(resource, parentResourceComponent, parentResourceContext,
resourceDiscoveryComponent, systemInfo, temporaryDirectory, dataDirectory, pluginContainerName,
@@ -189,8 +189,8 @@ public abstract class ComponentTest {
ResourceDiscoveryComponent rdc = (ResourceDiscoveryComponent) Class.forName(s).newInstance();
log.debug("rdc=" + rdc);
- EventContext eventContext = new EventContextImpl(resource);
- AvailabilityContext availContext = new AvailabilityContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
+ AvailabilityContext availContext = new AvailabilityContextImpl(resource, pluginContainer.getInventoryManager());
InventoryContext inventoryContext = new InventoryContextImpl(resource);
ResourceContext context = new ResourceContext(resource, component, parentContext, resourceDiscoveryComponent,
systemInfo, temporaryDirectory, dataDirectory, pluginContainerName, eventContext, operationContext,
@@ -221,8 +221,8 @@ public abstract class ComponentTest {
String rclassname = pmm.getComponentClass(type);
ResourceComponent component = (ResourceComponent) Class.forName(rclassname).newInstance();
- EventContext eventContext = new EventContextImpl(resource);
- AvailabilityContext availContext = new AvailabilityContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
+ AvailabilityContext availContext = new AvailabilityContextImpl(resource, pluginContainer.getInventoryManager());
InventoryContext inventoryContext = new InventoryContextImpl(resource);
ResourceContext context = new ResourceContext(cresource, parentComponent, parentContext,
resourceDiscoveryComponent, systemInfo, temporaryDirectory, dataDirectory, pluginContainerName,
@@ -234,7 +234,7 @@ public abstract class ComponentTest {
/**
* Called before the configuration is processed; override to set specific plugin parameters.
- * @see #configuration
+ * @see Configuration
*/
protected void setConfiguration(Configuration configuration, ResourceType resourceType) {
}
diff --git a/modules/plugins/snmptrapd/src/test/java/org/rhq/plugins/snmptrapd/ComponentTest.java b/modules/plugins/snmptrapd/src/test/java/org/rhq/plugins/snmptrapd/ComponentTest.java
index 24b6d9f..166dbb3 100644
--- a/modules/plugins/snmptrapd/src/test/java/org/rhq/plugins/snmptrapd/ComponentTest.java
+++ b/modules/plugins/snmptrapd/src/test/java/org/rhq/plugins/snmptrapd/ComponentTest.java
@@ -1,3 +1,22 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2014 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.plugins.snmptrapd;
import java.io.File;
@@ -77,9 +96,10 @@ public abstract class ComponentTest {
pcc.setEventSenderInitialDelay(1);
pcc.setEventSenderPeriod(1);
- PluginContainer.getInstance().setConfiguration(pcc);
- PluginContainer.getInstance().initialize();
- eventManager = PluginContainer.getInstance().getEventManager();
+ PluginContainer pluginContainer = PluginContainer.getInstance();
+ pluginContainer.setConfiguration(pcc);
+ pluginContainer.initialize();
+ eventManager = pluginContainer.getEventManager();
Resource resource = new Resource();
resource.setResourceType(resourceType);
@@ -93,11 +113,11 @@ public abstract class ComponentTest {
File temporaryDirectory = temp;
File dataDirectory = temp;
String pluginContainerName = "rhq";
- EventContext eventContext = new EventContextImpl(resource);
+ EventContext eventContext = new EventContextImpl(resource, eventManager);
OperationContext operationContext = new OperationContextImpl(0);
ContentContext contentContext = new ContentContextImpl(0);
PluginContainerDeployment pluginContainerDeployment = null;
- AvailabilityContext availContext = new AvailabilityContextImpl(resource);
+ AvailabilityContext availContext = new AvailabilityContextImpl(resource, pluginContainer.getInventoryManager());
InventoryContext inventoryContext = new InventoryContextImpl(resource);
ResourceContext context = new ResourceContext(resource, parentResourceComponent, parentResourceContext,
resourceDiscoveryComponent, systemInfo, temporaryDirectory, dataDirectory, pluginContainerName,
10 years, 4 months
[rhq] 2 commits - modules/core modules/plugins
by Heiko W. Rupp
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementScheduleRequest.java | 9 ++++++
modules/plugins/perftest/README | 10 ++++++-
modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestComponent.java | 12 +++++++++
modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/resource/SimpleResourceFactory.java | 13 ++++++++++
4 files changed, 43 insertions(+), 1 deletion(-)
New commits:
commit e10fd1db708b230e43474b9c5f440edfa946ca46
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Feb 5 10:23:41 2014 +0100
Add some explanation.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementScheduleRequest.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementScheduleRequest.java
index fe73f2c..795a400 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementScheduleRequest.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementScheduleRequest.java
@@ -44,6 +44,7 @@ public class MeasurementScheduleRequest implements Serializable {
private String name;
private int interval;
private boolean enabled;
+ /** encoded data type and numeric byte to safe space. See #toDataNumType for details */
byte dataNumType;
public MeasurementScheduleRequest(MeasurementSchedule schedule) {
@@ -173,6 +174,14 @@ public class MeasurementScheduleRequest implements Serializable {
return true;
}
+ /**
+ * Encode the data type and numeric byte in one byte instead of two enum pointers,
+ * thus reducing memory consumption from 24(?) bytes down to 1.
+ * High nibble is the data type, low nibble the numeric type
+ * @param dataType DataType to encode
+ * @param numericType NumericType to encode
+ * @return
+ */
private byte toDataNumType(DataType dataType, NumericType numericType) {
byte dTmp = (byte) (dataType != null ? dataType.ordinal() + 1 : 0);
byte nTmp = (byte) (numericType != null ? numericType.ordinal() + 1 : 0);
commit 944c8124eb3c6a357a1a7086587c650e1292e0a2
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Mon Feb 3 10:45:38 2014 +0100
Allow to delay discovery and getValues() to better mimic reality.
diff --git a/modules/plugins/perftest/README b/modules/plugins/perftest/README
index bb31981..3d702f6 100644
--- a/modules/plugins/perftest/README
+++ b/modules/plugins/perftest/README
@@ -9,4 +9,12 @@ Usage
"-Drhq.perftest.scenario=high-servers-1000"
- Some scenarios may be configurable and require other system properties to dictate their behavior. Check the
- scenario XML files for more details.
\ No newline at end of file
+ scenario XML files for more details.
+
+Two properties allow to control the time it takes for discovery and getValues(). This allows to better mimic real
+life, where a target server never returns data in 0ms.
+
+- rhq.perftest.getvaluesdelayms -- delay for getValues() in ms
+- rhq.perftest.discoverydelayms -- delay for discovery of one individual resource
+
+If the values are 0 or not given, no delay happens.
\ No newline at end of file
diff --git a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestComponent.java b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestComponent.java
index c93c7a4..04f1e6e 100644
--- a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestComponent.java
+++ b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestComponent.java
@@ -76,6 +76,7 @@ public class PerfTestComponent implements ResourceComponent, MeasurementFacet, C
private ResourceContext resourceContext;
private EventPoller eventPoller;
private Configuration resourceConfiguration;
+ private long getValuesDelay = 0L;
// ResourceComponent Implementation --------------------------------------------
@@ -87,6 +88,10 @@ public class PerfTestComponent implements ResourceComponent, MeasurementFacet, C
if (!scenarioManager.isEnabled())
log.warn("[" + this.resourceContext.getResourceType().getName()
+ "] perftest Resources exist in inventory, but no Perf test scenario is enabled.");
+
+ String tmp = System.getProperty("rhq.perftest.getvaluesdelayms","0");
+ getValuesDelay = Long.parseLong(tmp);
+
}
public void stop() {
@@ -141,6 +146,13 @@ public class PerfTestComponent implements ResourceComponent, MeasurementFacet, C
case COMPLEX:
log.error("DataType " + metric.getDataType() + " not yet supported");
}
+ if (getValuesDelay>0) {
+ try {
+ Thread.sleep(getValuesDelay);
+ } catch (Exception e ) {
+ ; // ignored
+ }
+ }
}
}
diff --git a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/resource/SimpleResourceFactory.java b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/resource/SimpleResourceFactory.java
index 587a1ff..2a1c08f 100644
--- a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/resource/SimpleResourceFactory.java
+++ b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/resource/SimpleResourceFactory.java
@@ -45,10 +45,15 @@ public class SimpleResourceFactory implements ResourceFactory {
private final Log log = LogFactory.getLog(this.getClass());
+ private long discoveryDelay = 0L;
+
// Constructors --------------------------------------------
public SimpleResourceFactory(SimpleResourceGenerator generator) {
this.generator = generator;
+ String tmp = System.getProperty("rhq.perftest.discoverydelayms","0");
+ discoveryDelay = Long.parseLong(tmp);
+
}
// ResourceFactory Implementation --------------------------------------------
@@ -69,6 +74,14 @@ public class SimpleResourceFactory implements ResourceFactory {
resourceVersion, resourceDescription, pluginConfiguration, null);
discoveredResources.add(details);
+
+ if (discoveryDelay>0) {
+ try {
+ Thread.sleep(discoveryDelay);
+ } catch (InterruptedException e) {
+ ; // ignored
+ }
+ }
}
return discoveredResources;
10 years, 4 months
[rhq] modules/enterprise
by mike thompson
modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/AvailabilityOverUnderGraphType.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/StackedBarMetricGraphImpl.java | 69 ++++++----
2 files changed, 50 insertions(+), 23 deletions(-)
New commits:
commit c118c27222ab96a7f7d5f639843de7ad01011c72
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Tue Feb 4 15:28:37 2014 -0800
[BZ 1014571] UX on selecting graph subselection via dragging. Add the drag selection to the x-axis.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/AvailabilityOverUnderGraphType.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/AvailabilityOverUnderGraphType.java
index b546776..dd7e8cb 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/AvailabilityOverUnderGraphType.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/AvailabilityOverUnderGraphType.java
@@ -326,8 +326,8 @@ public class AvailabilityOverUnderGraphType implements AvailabilityGraphType {
svg.append("text")
.attr("class", "availabilityLabel")
- .attr("x", -40)
- .attr("y", 10)
+ .attr("x", 0)
+ .attr("y", 15)
.style("font-size", "12px")
.style("font-family", "Arial, Verdana, sans-serif;")
.style("font-weight", "bold")
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/StackedBarMetricGraphImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/StackedBarMetricGraphImpl.java
index 17eeec3..806a1b8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/StackedBarMetricGraphImpl.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/coregui/client/inventory/common/graph/graphtype/StackedBarMetricGraphImpl.java
@@ -82,9 +82,9 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
// Define the Stacked Bar Graph function using the module pattern
var metricStackedBarGraph = function () {
- "use strict";
// privates
var margin = {top: 10, right: 5, bottom: 5, left: 40},
+ margin2 = {top: 150, right: 5, bottom: 5, left: 0},
width = 750 - margin.left - margin.right,
adjustedChartHeight = chartContext.chartHeight - 50,
height = adjustedChartHeight - margin.top - margin.bottom,
@@ -102,10 +102,14 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
highBound,
calcBarWidth,
yScale,
- yAxis,
timeScale,
+ yAxis,
xAxis,
+ brush,
+ brushGroup,
+ timeScaleForBrush,
chart,
+ context,
svg;
// adjust the min scale so blue low line is not in axis
@@ -205,6 +209,12 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
return d.x;
}));
+ timeScaleForBrush = $wnd.d3.time.scale()
+ .range([0, width])
+ .domain($wnd.d3.extent(chartData, function (d) {
+ return d.x;
+ }));
+
xAxis = $wnd.d3.svg.axis()
.scale(timeScale)
.ticks(xTicks)
@@ -220,9 +230,15 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
.attr("height", height + margin.top - titleHeight - titleSpace + margin.bottom)
.attr("transform", "translate(" + margin.left + "," + (+titleHeight + titleSpace + margin.top) + ")");
+ context = svg.append("g")
+ .attr("class", "context")
+ .attr("width", width + margin.left + margin.right)
+ .attr("height", 150)
+ .attr("transform", "translate(" + margin2.left + "," + (+titleHeight + titleSpace + margin.top + 90) + ")");
+
legendUnDefined = (chartContext.chartAverage === "");
if ((!chartContext.hideLegend && !useSmallCharts() && !legendUnDefined )) {
- createMinAvgPeakSidePanel(chartContext.minChartTitle, chartContext.chartMin, chartContext.avgChartTitle, chartContext.chartAverage, chartContext.peakChartTitle, chartContext.chartMax, chartContext.yAxisUnits);
+ createMinAvgPeakSidePanel(chartContext.minChartTitle, chartContext.chartMin, chartContext.avgChartTitle, chartContext.chartAverage, chartContext.peakChartTitle, chartContext.chartMax );
}
}
@@ -298,7 +314,7 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
function createHeader(titleName) {
var title = chart.append("g").append("rect")
.attr("class", "title")
- .attr("x", 10)
+ .attr("x", 30)
.attr("y", margin.top)
.attr("height", titleHeight)
.attr("width", width + 30 + margin.left)
@@ -615,15 +631,24 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
}
function createXandYAxes() {
+ var xAxisGroup;
xAxis.tickFormat($wnd.rhqCommon.getD3CustomTimeFormat(chartContext.chartXaxisTimeFormatHours, chartContext.chartXaxisTimeFormatHoursMinutes));
// create x-axis
- svg.append("g")
+ xAxisGroup = svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
+ if(!chartContext.isPortalGraph){
+ xAxisGroup.append("g")
+ .attr("class", "x brush")
+ .call(brush)
+ .selectAll("rect")
+ .attr("y", -6)
+ .attr("height", 30);
+ }
// create y-axis
svg.append("g")
@@ -712,32 +737,33 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
}
- function createBrush(){
+ function createXAxisBrush(){
+
+ brush = $wnd.d3.svg.brush()
+ .x(timeScaleForBrush)
+ .on("brushstart", brushStart)
+ .on("brush", brushMove)
+ .on("brushend", brushEnd);
- var brush = $wnd.d3.svg.brush()
- .x(timeScale)
- .on("brushstart", brushstart)
- .on("brush", brushmove)
- .on("brushend", brushend),
- brushg = svg.append("g")
- .attr("class", "brush")
- .call(brush);
+ brushGroup = svg.append("g")
+ .attr("class", "brush")
+ .call(brush);
- brushg.selectAll(".resize").append("path");
+ brushGroup.selectAll(".resize").append("path");
- brushg.selectAll("rect")
- .attr("height", height);
+ brushGroup.selectAll("rect")
+ .attr("height", height);
- function brushstart() {
+ function brushStart() {
svg.classed("selecting", true);
}
- function brushmove() {
+ function brushMove() {
var s = brush.extent();
updateDateRangeDisplay($wnd.moment(s[0]), $wnd.moment(s[1]));
}
- function brushend() {
+ function brushEnd() {
var s = brush.extent();
var startTime = Math.round(s[0].getTime());
var endTime = Math.round(s[1].getTime() );
@@ -757,6 +783,7 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
}
+
return {
// Public API
draw: function (chartContext) {
@@ -769,7 +796,7 @@ public class StackedBarMetricGraphImpl extends AbstractMetricGraph {
createYAxisGridLines();
if(!chartContext.isPortalGraph){
- createBrush();
+ createXAxisBrush();
}
createStackedBars();
createXandYAxes();
10 years, 4 months
[rhq] Branch 'release/jon3.2.x' - modules/plugins
by Jay Shaughnessy
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 7 ++-
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java | 13 ++----
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/AbstractServerComponentTest.java | 19 +++++-----
3 files changed, 19 insertions(+), 20 deletions(-)
New commits:
commit e3e8c936433ae9406bff0a6beb9735c476fce818
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Thu Jan 30 06:30:48 2014 -0500
Bug 1025050 - EAP 6 plug-in should not require start script environment variables to be set
Conflicts:
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
Cherry-pick master 6785f80b99a4def0128939113fd5af7d3b4ebee5
Signed-off-by: Jay Shaughnessy <jshaughn(a)redhat.com>
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index a6043c4..a89e9b8 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.modules.plugins.jbossas7;
import java.io.OutputStream;
@@ -354,7 +355,9 @@ public class BaseComponent<T extends ResourceComponent<?>> implements AS7Compone
@Override
public void deleteResource() throws Exception {
- log.info("Removing AS7 resource [" + path + "]...");
+ if (log.isDebugEnabled()) {
+ log.debug("Removing AS7 resource [" + path + "]...");
+ }
if (context.getResourceType().getName().equals(MANAGED_SERVER)) {
// We need to do two steps because of AS7-4032
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
index 1e84c06..cd94280 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -159,7 +159,9 @@ public abstract class BaseServerComponent<T extends ResourceComponent<?>> extend
try {
if ((availabilityType == AvailabilityType.UP) && (previousAvailabilityType != AvailabilityType.UP)) {
validateServerAttributes();
- log.info(getResourceDescription() + " has just come UP.");
+ if (log.isDebugEnabled()) {
+ log.debug(getResourceDescription() + " has just come UP.");
+ }
}
} finally {
previousAvailabilityType = availabilityType;
@@ -457,13 +459,6 @@ public abstract class BaseServerComponent<T extends ResourceComponent<?>> extend
}
}
- Map<String, String> startScriptEnv = startScriptConfig.getStartScriptEnv();
- if (startScriptEnv.isEmpty()) {
- errors.add("No start script environment variables are set. At a minimum, PATH should be set "
- + "(on UNIX, it should contain at least /bin and /usr/bin). It is recommended that "
- + "JAVA_HOME also be set, otherwise the PATH will be used to find java.");
- }
-
return errors;
}
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/AbstractServerComponentTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/AbstractServerComponentTest.java
index 6ff3d06..0703835 100644
--- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/AbstractServerComponentTest.java
+++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/AbstractServerComponentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2013 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -16,6 +16,7 @@
* 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.modules.plugins.jbossas7.itest;
import static org.testng.Assert.assertEquals;
@@ -199,17 +200,17 @@ public abstract class AbstractServerComponentTest extends AbstractJBossAS7Plugin
}
protected void validateStartScriptEnv(Map<String, String> env) {
- Assert.assertTrue(env.size() <= 4, env.toString());
-
String javaHome = env.get("JAVA_HOME");
- Assert.assertNotNull(javaHome);
- Assert.assertTrue(new File(javaHome).isDirectory());
+ if (javaHome != null) {
+ Assert.assertTrue(new File(javaHome).isDirectory());
+ }
String path = env.get("PATH");
- Assert.assertNotNull(path);
- String[] pathElements = path.split(File.pathSeparator);
- Assert.assertTrue(pathElements.length >= 1);
- Assert.assertTrue(new File(pathElements[0]).isDirectory());
+ if (path != null) {
+ String[] pathElements = path.split(File.pathSeparator);
+ Assert.assertTrue(pathElements.length >= 1);
+ Assert.assertTrue(new File(pathElements[0]).isDirectory());
+ }
}
protected abstract String getBindAddressSystemPropertyName();
10 years, 4 months
[rhq] 2 commits - modules/helpers
by snegrea
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatedMetricsServer.java | 40 +++
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/Simulator.java | 105 ++++++++--
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatorCLI.java | 6
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/WaitForRawInserts.java | 67 ++++++
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlan.java | 30 ++
modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlanner.java | 9
modules/helpers/metrics-simulator/src/main/resources/sample.json | 25 ++
modules/helpers/metrics-simulator/src/test/java/org/rhq/metrics/simulator/SimulatorTest.java | 6
8 files changed, 267 insertions(+), 21 deletions(-)
New commits:
commit 18b0c7e2036a7e40f99fbcdfcca0f948b68978ac
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Feb 4 15:04:46 2014 -0600
Sample configuration JSON for the metrics simulator. JSON comments were enabled in the code prior to this.
diff --git a/modules/helpers/metrics-simulator/src/main/resources/sample.json b/modules/helpers/metrics-simulator/src/main/resources/sample.json
new file mode 100644
index 0000000..83feae7
--- /dev/null
+++ b/modules/helpers/metrics-simulator/src/main/resources/sample.json
@@ -0,0 +1,25 @@
+{
+ //[threaded, sequential]
+ //threaded = multi threaded simulation
+ //sequential = single threaded simulation
+ "simulationType": "threaded",
+
+ //for threaded = total simulation time in minutes
+ //for sequential = total number of days
+ "simulationTime": 1,
+
+ //[seconds, minutes, hours]
+ //not used in sequential simulations
+ "intervalType": "seconds",
+
+ //num of collectors * batch size = total num of metrics
+ "numMeasurementCollectors": 1,
+ "batchSize": 1,
+
+ "nodes": ["127.0.0.1"],
+
+ "cqlPort": 9142,
+
+ //[async,sync]
+ "aggregationType": "sync"
+}
commit b9d84ecb79ecb6b58689c6babd2b92088197c26d
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Feb 4 15:01:43 2014 -0600
Update the metrics simulator to run single threaded simulations that guarantees order and completion of events.
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatedMetricsServer.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatedMetricsServer.java
new file mode 100644
index 0000000..85edf7a
--- /dev/null
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatedMetricsServer.java
@@ -0,0 +1,40 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.metrics.simulator;
+
+import org.joda.time.DateTime;
+
+import org.rhq.server.metrics.MetricsServer;
+
+class SimulatedMetricsServer extends MetricsServer {
+ private DateTime currentHour;
+
+ public void setCurrentHour(DateTime currentHour) {
+ this.currentHour = currentHour;
+ }
+
+ @Override
+ protected DateTime currentHour() {
+ if (currentHour == null) {
+ return super.currentHour();
+ }
+ return currentHour;
+ }
+
+}
\ No newline at end of file
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/Simulator.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/Simulator.java
index a3d1eed..91453ff 100644
--- a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/Simulator.java
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/Simulator.java
@@ -23,6 +23,9 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -38,11 +41,14 @@ import com.datastax.driver.core.exceptions.NoHostAvailableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.joda.time.DateTime;
import org.joda.time.Minutes;
import org.rhq.cassandra.schema.SchemaManager;
import org.rhq.cassandra.util.ClusterBuilder;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.metrics.simulator.plan.SimulationPlan;
+import org.rhq.metrics.simulator.plan.SimulationPlan.SimulationType;
import org.rhq.server.metrics.MetricsDAO;
import org.rhq.server.metrics.MetricsServer;
import org.rhq.server.metrics.StorageSession;
@@ -56,30 +62,97 @@ public class Simulator implements ShutdownManager {
private boolean shutdown = false;
- public void run(SimulationPlan plan) {
- final ScheduledExecutorService aggregators = Executors.newScheduledThreadPool(1, new SimulatorThreadFactory());
- final ScheduledExecutorService collectors = Executors.newScheduledThreadPool(
- plan.getNumMeasurementCollectors(), new SimulatorThreadFactory());
- final ExecutorService aggregationQueue = Executors.newSingleThreadExecutor(new SimulatorThreadFactory());
- final ScheduledExecutorService readers = Executors.newScheduledThreadPool(plan.getReaderThreadPoolSize(),
- new SimulatorThreadFactory());
-
- Metrics metrics = new Metrics();
- final ConsoleReporter consoleReporter = createConsoleReporter(metrics, plan.getMetricsReportInterval());
+ private Metrics metrics;
+ private Session session;
+ private StorageSession storageSession;
+ private MetricsDAO metricsDAO;
+ private MetricsServer metricsServer;
+
+ public void run(SimulationPlan plan) throws Throwable {
+ if (SimulationType.THREADED.equals(plan.getSimulationType())) {
+ this.runThreadedSimulation(plan);
+ } else if (SimulationType.SEQUENTIAL.equals(plan.getSimulationType())) {
+ this.runSequentialSimulation(plan);
+ } else {
+ throw new UnsupportedOperationException("Simulation type " + plan.getSimulationType() + " not implemented.");
+ }
+ }
+ private void initializeMetricsServer(SimulationPlan plan) {
+ metrics = new Metrics();
createSchema(plan.getNodes(), plan.getCqlPort());
+ session = createSession(plan.getNodes(), plan.getCqlPort());
+ storageSession = new StorageSession(session);
+ metricsDAO = new MetricsDAO(storageSession, plan.getMetricsServerConfiguration());
- Session session = createSession(plan.getNodes(), plan.getCqlPort());
- StorageSession storageSession = new StorageSession(session);
-
- MetricsDAO metricsDAO = new MetricsDAO(storageSession, plan.getMetricsServerConfiguration());
- final MetricsServer metricsServer = new MetricsServer();
+ metricsServer = new SimulatedMetricsServer();
metricsServer.setDAO(metricsDAO);
metricsServer.setConfiguration(plan.getMetricsServerConfiguration());
metricsServer.setAggregationBatchSize(plan.getAggregationBatchSize());
metricsServer.setUseAsyncAggregation(plan.getAggregationType() == SimulationPlan.AggregationType.ASYNC);
-
metricsServer.setDateTimeService(plan.getDateTimeService());
+ }
+
+ /**
+ * Run a sequential simulation where metrics insertion and aggregation run
+ * in a single thread in sequence. The progression of time
+ * is managed by the simulation. This guarantees that
+ * the number of insertions and sequence of events takes
+ * place in order irrespective of host limitations.
+ */
+ private void runSequentialSimulation(SimulationPlan plan) throws Throwable {
+ this.initializeMetricsServer(plan);
+
+ SimulatedMetricsServer test = (SimulatedMetricsServer) metricsServer;
+ Random random = new Random();
+ long timestamp = plan.getDateTimeService().nowInMillis();
+ long endOfSimulation = timestamp + 24L * 60 * 60 * 1000 * plan.getSimulationTime();
+ long numberOfMetrics = plan.getBatchSize() * plan.getNumMeasurementCollectors();
+
+ Set<MeasurementDataNumeric> data = new HashSet<MeasurementDataNumeric>(plan.getBatchSize());
+
+ int lastAggregationHour = new DateTime(timestamp).getHourOfDay();
+
+ for (; timestamp < endOfSimulation; timestamp += 30 * 1000) {
+ DateTime currentTime = new DateTime(timestamp);
+
+ data.clear();
+ for (int i = 0; i < numberOfMetrics; ++i) {
+ data.add(new MeasurementDataNumeric(timestamp, i, random.nextDouble()));
+ }
+
+ WaitForRawInserts waitForRawInserts = new WaitForRawInserts(data.size());
+ metricsServer.addNumericData(data, waitForRawInserts);
+ waitForRawInserts.await("Failed to insert raw data at time: " + timestamp);
+
+ test.setCurrentHour(new DateTime(timestamp));
+ if (currentTime.getHourOfDay() != lastAggregationHour) {
+ lastAggregationHour = currentTime.getHourOfDay();
+ test.calculateAggregates();
+ }
+ }
+
+ metricsServer.shutdown();
+ log.info("Simulation has completed. Initiating shutdown...");
+ shutdown(0);
+ }
+
+ /**
+ * Run a multi-threaded simulation where multiple threads
+ * collect metrics and run aggregation.
+ * The scheduling is done based on intervalType please review the
+ * simulation plan for the timing.
+ */
+ private void runThreadedSimulation(SimulationPlan plan) {
+ this.initializeMetricsServer(plan);
+ final ConsoleReporter consoleReporter = createConsoleReporter(metrics, plan.getMetricsReportInterval());
+
+ final ScheduledExecutorService aggregators = Executors.newScheduledThreadPool(1, new SimulatorThreadFactory());
+ final ScheduledExecutorService collectors = Executors.newScheduledThreadPool(
+ plan.getNumMeasurementCollectors(), new SimulatorThreadFactory());
+ final ExecutorService aggregationQueue = Executors.newSingleThreadExecutor(new SimulatorThreadFactory());
+ final ScheduledExecutorService readers = Executors.newScheduledThreadPool(plan.getReaderThreadPoolSize(),
+ new SimulatorThreadFactory());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatorCLI.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatorCLI.java
index b026752..6b09355 100644
--- a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatorCLI.java
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/SimulatorCLI.java
@@ -108,7 +108,11 @@ public class SimulatorCLI {
}
Simulator simulator = new Simulator();
- simulator.run(plan);
+ try {
+ simulator.run(plan);
+ } catch (Throwable t) {
+ System.out.println(t);
+ }
}
public static void main(String[] args) {
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/WaitForRawInserts.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/WaitForRawInserts.java
new file mode 100644
index 0000000..3cdf586
--- /dev/null
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/WaitForRawInserts.java
@@ -0,0 +1,67 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.metrics.simulator;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.server.metrics.RawDataInsertedCallback;
+
+/**
+* @author John Sanda
+*/
+class WaitForRawInserts implements RawDataInsertedCallback {
+
+ private final Log log = LogFactory.getLog(WaitForRawInserts.class);
+
+ private CountDownLatch latch;
+
+ private Throwable throwable;
+
+ public WaitForRawInserts(int numInserts) {
+ latch = new CountDownLatch(numInserts);
+ }
+
+ @Override
+ public void onFinish() {
+ }
+
+ @Override
+ public void onSuccess(MeasurementDataNumeric measurementDataNumeric) {
+ latch.countDown();
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ latch.countDown();
+ this.throwable = throwable;
+ log.error("An async operation failed", throwable);
+ }
+
+ public void await(String errorMsg) throws Throwable {
+ latch.await();
+ if (throwable != null) {
+ throw throwable;
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlan.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlan.java
index c2dbf19..5e0a46a 100644
--- a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlan.java
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlan.java
@@ -76,6 +76,26 @@ public class SimulationPlan {
}
}
+ public static enum SimulationType {
+ THREADED("threaded"), SEQUENTIAL("sequential");
+
+ private final String text;
+
+ SimulationType(String text) {
+ this.text = text;
+ }
+
+ public static SimulationType fromText(String text) {
+ if (text.equals("threaded") || text.equals("thread")) {
+ return THREADED;
+ }
+ if (text.equals("sequential") || text.equals("seq")) {
+ return SEQUENTIAL;
+ }
+ throw new IllegalArgumentException(text + " is not a valid simulation type");
+ }
+ }
+
private long collectionInterval;
private long aggregationInterval;
@@ -110,6 +130,8 @@ public class SimulationPlan {
private AggregationType aggregationType;
+ private SimulationType simulationType;
+
private int readerThreadPoolSize = 1;
public int getReaderThreadPoolSize() {
@@ -248,6 +270,14 @@ public class SimulationPlan {
this.aggregationType = aggregationType;
}
+ public SimulationType getSimulationType() {
+ return simulationType;
+ }
+
+ public void setSimulationType(SimulationType simulationType) {
+ this.simulationType = simulationType;
+ }
+
public boolean isAggregationEnabled() {
return aggregationEnabled;
}
diff --git a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlanner.java b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlanner.java
index 02c29e8..292e1ac 100644
--- a/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlanner.java
+++ b/modules/helpers/metrics-simulator/src/main/java/org/rhq/metrics/simulator/plan/SimulationPlanner.java
@@ -28,6 +28,8 @@ package org.rhq.metrics.simulator.plan;
import java.io.File;
import java.net.InetAddress;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -45,7 +47,9 @@ import org.rhq.server.metrics.MetricsConfiguration;
public class SimulationPlanner {
public SimulationPlan create(File jsonFile) throws Exception {
- ObjectMapper mapper = new ObjectMapper();
+ JsonFactory jsonFactory = new JsonFactory();
+ jsonFactory.enable(Feature.ALLOW_COMMENTS);
+ ObjectMapper mapper = new ObjectMapper(jsonFactory);
JsonNode root = mapper.readTree(jsonFile);
SimulationPlan simulation = new SimulationPlan();
@@ -105,6 +109,9 @@ public class SimulationPlanner {
"sync")));
simulation.setAggregationEnabled(getBoolean(root.get("aggregationEnabled"), true));
+ simulation.setSimulationType(SimulationPlan.SimulationType.fromText(getString(root.get("simulationType"),
+ "threaded")));
+
return simulation;
}
diff --git a/modules/helpers/metrics-simulator/src/test/java/org/rhq/metrics/simulator/SimulatorTest.java b/modules/helpers/metrics-simulator/src/test/java/org/rhq/metrics/simulator/SimulatorTest.java
index f01051d..c4ba74d 100644
--- a/modules/helpers/metrics-simulator/src/test/java/org/rhq/metrics/simulator/SimulatorTest.java
+++ b/modules/helpers/metrics-simulator/src/test/java/org/rhq/metrics/simulator/SimulatorTest.java
@@ -27,6 +27,7 @@ import java.io.File;
import org.testng.annotations.Test;
+import org.rhq.metrics.simulator.Simulator;
import org.rhq.metrics.simulator.plan.SimulationPlan;
import org.rhq.metrics.simulator.plan.SimulationPlanner;
@@ -36,12 +37,11 @@ import org.rhq.metrics.simulator.plan.SimulationPlanner;
public class SimulatorTest {
@Test
- public void runSimulator() throws Exception {
+ public void runSimulator() throws Throwable {
File jsonFile = new File(getClass().getResource("test-simulator.json").toURI());
SimulationPlanner planner = new SimulationPlanner();
SimulationPlan plan = planner.create(jsonFile);
Simulator simulator = new Simulator();
simulator.run(plan);
}
-
-}
+}
\ No newline at end of file
10 years, 4 months
[rhq] Branch 'hotfix/jon3.1.2' - modules/enterprise
by Larry O'Leary
modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 7dddc95e4ced8fa682cab1f556f719c5c33fcc8f
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Jan 6 17:32:47 2014 -0500
[1020064 parentName alert operation tokens resolving to parentId value instead of parentName]
Fixed what looks like cut+paste issue.
(cherry picked from 3.1.x commit a8d9a2ac71b57f70236a23cba7b7b0da64e14ec1)
diff --git a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
index cdf03ac..da8be8b 100644
--- a/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
+++ b/modules/enterprise/server/plugins/alert-operations/src/main/java/org/rhq/enterprise/server/plugins/alertOperations/AlertTokenReplacer.java
@@ -201,9 +201,9 @@ public class AlertTokenReplacer {
case RESOURCE_PARENT_NAME:
parent = mgr.getParentResource(resource.getId());
if (parent == null)
- return "0";
+ return "N/A";
else
- return String.valueOf(parent.getId());
+ return parent.getName();
case RESOURCE_TYPE_ID:
return String.valueOf(resource.getResourceType().getId());
case RESOURCE_TYPE_NAME:
10 years, 4 months
[rhq] Branch 'feature/embeddedagent' - 2 commits - modules/enterprise
by mazz
modules/enterprise/pom.xml | 2
modules/enterprise/server/embeddedagent/src/main/java/org/rhq/embeddedagent/extension/AgentService.java | 21 ++++++++++
modules/enterprise/server/pom.xml | 1
3 files changed, 24 insertions(+)
New commits:
commit d972365f13f9af973f769d4491348d92ef87c79b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Feb 4 15:07:38 2014 -0500
put the embedded agent in the mvn reactor so it builds with everything else
diff --git a/modules/enterprise/pom.xml b/modules/enterprise/pom.xml
index 0105ca8..2dbde1f 100644
--- a/modules/enterprise/pom.xml
+++ b/modules/enterprise/pom.xml
@@ -40,6 +40,7 @@
<module>server/startup-subsystem</module>
<module>server/installer</module>
<module>server/server-control</module>
+ <module>server/embeddedagent</module>
<module>binding</module>
<module>scripting</module>
<module>server/client-api</module>
@@ -72,6 +73,7 @@
<module>server/startup-subsystem</module>
<module>server/installer</module>
<module>server/server-control</module>
+ <module>server/embeddedagent</module>
<module>server/appserver</module>
<module>server/client-api</module>
<module>server/itests-2</module>
diff --git a/modules/enterprise/server/pom.xml b/modules/enterprise/server/pom.xml
index c820eb4..d31861a 100644
--- a/modules/enterprise/server/pom.xml
+++ b/modules/enterprise/server/pom.xml
@@ -35,6 +35,7 @@
<module>server-control</module>
<module>safe-invoker</module>
<module>client-api</module>
+ <module>embeddedagent</module>
<module>itests-2</module>
</modules>
</profile>
commit 9cdd3f8c2b9bd091105ba55a3a7d2c3001031900
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Feb 4 15:05:51 2014 -0500
have embedded agent now use the new "enabled plugins" preference in the agent.
diff --git a/modules/enterprise/server/embeddedagent/src/main/java/org/rhq/embeddedagent/extension/AgentService.java b/modules/enterprise/server/embeddedagent/src/main/java/org/rhq/embeddedagent/extension/AgentService.java
index 651f557..a9d5000 100644
--- a/modules/enterprise/server/embeddedagent/src/main/java/org/rhq/embeddedagent/extension/AgentService.java
+++ b/modules/enterprise/server/embeddedagent/src/main/java/org/rhq/embeddedagent/extension/AgentService.java
@@ -18,6 +18,7 @@ import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
+import org.rhq.enterprise.agent.AgentConfigurationConstants;
import org.rhq.enterprise.agent.AgentMain;
import org.rhq.enterprise.communications.ServiceContainerConfigurationConstants;
@@ -145,6 +146,26 @@ public class AgentService implements Service<AgentService> {
configOverrides.put(ServiceContainerConfigurationConstants.CONNECTOR_BIND_ADDRESS, agentBindAddress);
configOverrides.put(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, agentBindPort);
+ // if the agent was told to explicitly enable some plugins, add them to the "enabledPlugins" preference.
+ // if the agent was told to explicitly disnable some plugins, add them to the "disabledPlugins" preference.
+ StringBuilder enabledPlugins = new StringBuilder();
+ StringBuilder disabledPlugins = new StringBuilder();
+ for (Map.Entry<String, Boolean> entry : plugins.entrySet()) {
+ String pluginName = entry.getKey();
+ Boolean enabled = entry.getValue();
+ if (enabled) {
+ enabledPlugins.append((enabledPlugins.length() > 0) ? "," : "").append(pluginName);
+ } else {
+ disabledPlugins.append((disabledPlugins.length() > 0) ? "," : "").append(pluginName);
+ }
+ }
+ if (enabledPlugins.length() > 0) {
+ configOverrides.put(AgentConfigurationConstants.PLUGINS_ENABLED, enabledPlugins.toString());
+ }
+ if (disabledPlugins.length() > 0) {
+ configOverrides.put(AgentConfigurationConstants.PLUGINS_DISABLED, disabledPlugins.toString());
+ }
+
ServerEnvironment env = envServiceValue.getValue();
boolean resetConfigurationAtStartup = true;
AgentConfigurationSetup configSetup = new AgentConfigurationSetup(
10 years, 4 months
[rhq] Branch 'feature/embeddedagent' - modules/core modules/enterprise modules/plugins
by mazz
modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java | 36 ++++++++++
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java | 9 ++
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java | 8 ++
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java | 36 +++++++++-
modules/enterprise/agent/src/main/resources/agent-configuration.xml | 35 +++++++++
modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml | 1
6 files changed, 123 insertions(+), 2 deletions(-)
New commits:
commit 0ee69bc811c165449d73448542bd6db75b279f4e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Feb 4 12:16:21 2014 -0500
add new feature to the agent that lets you tell the agent explicitly what plugins you want enabled. All others will be disabled.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
index 36ba906..469a0db 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
@@ -46,6 +46,7 @@ public class PluginContainerConfiguration {
private static final String CONTAINER_NAME_PROP = PROP_PREFIX + "container-name";
private static final String DATA_DIRECTORY_PROP = PROP_PREFIX + "data-directory";
private static final String TEMP_DIRECTORY_PROP = PROP_PREFIX + "temp-directory";
+ private static final String ENABLED_PLUGINS = PROP_PREFIX + "enabled-plugins";
private static final String DISABLED_PLUGINS = PROP_PREFIX + "disabled-plugins";
private static final String DISABLED_RESOURCE_TYPES = PROP_PREFIX + "disabled-resource-types";
private static final String ROOT_PLUGIN_CLASSLOADER_REGEX_PROP = PROP_PREFIX + "root-plugin-classloader-regex";
@@ -231,6 +232,7 @@ public class PluginContainerConfiguration {
* is the name found in the plugin .xml descriptor in the plugin root element.
*
* @param disabledPlugins
+ * @see #setEnabledPlugins(List)
*/
public void setDisabledPlugins(List<String> disabledPlugins) {
if (disabledPlugins != null) {
@@ -241,6 +243,40 @@ public class PluginContainerConfiguration {
}
/**
+ * See {@link #setEnabledPlugins(List)} for a description of this.
+ *
+ * @return list of plugin names identifying plugins to be enabled
+ */
+ @SuppressWarnings("unchecked")
+ public List<String> getEnabledPlugins() {
+ List<String> list = (List<String>) configuration.get(ENABLED_PLUGINS);
+ if (list == null) {
+ return new ArrayList<String>(0);
+ } else {
+ return new ArrayList<String>(list);
+ }
+ }
+
+ /**
+ * If only a specific set of plugins are to be loaded by the plugin container, the given
+ * list should be the names of the plugins to be enabled. All other plugins will be
+ * disabled by default. If a plugin name is listed in both this enabled list and the
+ * {@link #setDisabledPlugins(List)} list, the plugin will be disabled (in other words,
+ * the disabled list takes precedence). Note that the plugin name is the name found in
+ * the plugin .xml descriptor in the plugin root element.
+ *
+ * @param enabledPlugins
+ * @see #setDisabledPlugins(List)
+ */
+ public void setEnabledPlugins(List<String> enabledPlugins) {
+ if (enabledPlugins != null) {
+ configuration.put(ENABLED_PLUGINS, enabledPlugins);
+ } else {
+ configuration.remove(ENABLED_PLUGINS);
+ }
+ }
+
+ /**
* If any resource types are to be disabled, the resource types names will be returned
* in a list.
* Each type is listed as "plugin name>parent type>child type".
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java
index 34f669b..f46a02c 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java
@@ -1214,6 +1214,14 @@ public class AgentConfiguration {
tmp_directory.mkdir();
}
+ // determine what, if any, plugins are to be enabled
+ String enabled_pref = m_preferences.get(AgentConfigurationConstants.PLUGINS_ENABLED, null);
+ List<String> enabled_plugins = null;
+ if (enabled_pref != null) {
+ String[] array = enabled_pref.split(",");
+ enabled_plugins = new ArrayList<String>(Arrays.asList(array));
+ }
+
// determine what, if any, plugins are to be disabled
String disabled_pref = m_preferences.get(AgentConfigurationConstants.PLUGINS_DISABLED, null);
List<String> disabled_plugins = null;
@@ -1246,6 +1254,7 @@ public class AgentConfiguration {
config.setDataDirectory(data_directory);
config.setTemporaryDirectory(tmp_directory);
config.setDisabledPlugins(disabled_plugins);
+ config.setEnabledPlugins(enabled_plugins);
config.setDisabledResourceTypes(disabled_types);
config.setRootPluginClassLoaderRegex(clRegex);
config.setServerDiscoveryInitialDelay(server_discovery_initial_delay);
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java
index 96a71a9..379d7b7 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java
@@ -546,6 +546,14 @@ public interface AgentConfigurationConstants {
String PLUGINS_ROOT_PLUGIN_CLASSLOADER_REGEX = PROPERTY_NAME_PREFIX + "plugins.root-plugin-classloader-regex";
/**
+ * The comma separated list of names of plugins that are to be explicitly enabled at startup.
+ * Only those plugins in this preference will be enabled, all others will be disabled.
+ * The disabled plugins setting takes precendence, however. If a plugin is specified in both
+ * the plugins.enabled and plugins.disabled preferences, the plugin will be disabled.
+ */
+ String PLUGINS_ENABLED = PROPERTY_NAME_PREFIX + "plugins.enabled";
+
+ /**
* The comma separated list of names of plugins that are to be disabled at startup
*/
String PLUGINS_DISABLED = PROPERTY_NAME_PREFIX + "plugins.disabled";
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
index 8b7f622..1f5f987 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
@@ -114,8 +114,6 @@ public class PluginUpdate {
}
try {
- List<String> disabled_plugin_names = this.config.getDisabledPlugins();
-
// find out what plugins we already have locally
Map<String, Plugin> current_plugins = getCurrentPlugins();
@@ -133,6 +131,40 @@ public class PluginUpdate {
Map<String, Plugin> latest_plugins_map = new HashMap<String, Plugin>(latest_plugins.size());
+ // Get the list of plugins this agent was told to explicitly disable or enable.
+ // If there was a non-empty list of enabled plugins, those are the only plugins to be enabled, any other
+ // plugins not listed in the enabled plugins list will be disabled.
+ // If there was a non-empty list of disabled plugins, those plugins to be explicitly disabled, but any
+ // other plugins available from the server will be enabled by default.
+ // If there were both disabled and enabled plugins explicitly set, we have to choose what takes precendence.
+ // If a plugin was listed as both "enabled" and "disabled", the plugin will be disabled (that is, the
+ // disabled list takes precendence).
+ // For example, suppose our latest plugins on the server are named A, B, C, and D.
+ // If the following (E)nabled and (D)isabled plugins are the following,
+ // then you can see what plugins are to be (U)sed:
+ // (E)=<empty>, (D)=<empty>, (U)=A,B,C,D
+ // (E)=<empty>, (D)=B,C (U)=A,D
+ // (E)=A,B (D)=<empty>, (U)=A,B
+ // (E)=A,B (D)=B,C (U)=A [notice B was listed in both (E) and (D) - it is therefore disabled]
+ //
+ // What we do is we make sure we set disabled_plugin_names with all the names of the plugins to be disabled.
+ // This is just the disabled plugins list unless enabled plugins was also defined, in which case
+ // we have to make sure we figure out the real list of disabled plugins.
+
+ List<String> disabled_plugin_names = this.config.getDisabledPlugins();
+ List<String> enabled_plugin_names = this.config.getEnabledPlugins();
+ if (!enabled_plugin_names.isEmpty()) {
+ // start with all of the names of the plugins that the server has
+ List<String> plugin_names = new ArrayList<String>(latest_plugins.size());
+ for (Plugin latest_plugin : latest_plugins) {
+ plugin_names.add(latest_plugin.getName());
+ }
+ // remove the explicitly enabled plugins from that list
+ plugin_names.removeAll(enabled_plugin_names);
+ // what is left are all the plugins to be disabled, so add those to the disabled plugins list
+ disabled_plugin_names.addAll(plugin_names);
+ }
+
// determine if we need to upgrade any of our current plugins to the latest versions
for (Plugin latest_plugin : latest_plugins) {
String plugin_filename = latest_plugin.getPath();
diff --git a/modules/enterprise/agent/src/main/resources/agent-configuration.xml b/modules/enterprise/agent/src/main/resources/agent-configuration.xml
index ce27dde..8d67b3d 100644
--- a/modules/enterprise/agent/src/main/resources/agent-configuration.xml
+++ b/modules/enterprise/agent/src/main/resources/agent-configuration.xml
@@ -842,6 +842,10 @@ commands named "config", "setconfig" and "setup" and the command line options
its local plugins directory, but that plugin is disabled
via this preference, that local plugin jar file will be
deleted and the plugin will not be loaded.
+
+ Note that if a plugin is listed in both this preference and
+ the rhq.agent.plugins.enabled preference, the plugin will
+ be disabled (that is, this disabled setting takes precedence).
-->
<!--
<entry key="rhq.agent.plugins.disabled" value=""/>
@@ -849,6 +853,37 @@ commands named "config", "setconfig" and "setup" and the command line options
<!--
_______________________________________________________________
+ rhq.agent.plugins.enabled
+
+ Defines the names of the plugins that are to be enabled.
+ This is a comma-separated list of plugin names, where a
+ plugin name is found in the name attribute in the root XML
+ element in the plugin descriptor. If this setting is set,
+ any plugin not in this enabled list will be disabled and thus
+ simply not loaded in the plugin container.
+
+ By default, all plugins are enabled. If a plugin was marked
+ as disabled by the server, the agent will not download it and
+ will not load it, regardless of the value of this preference.
+ If a plugin is enabled on the server, this
+ preference will override that enable setting (in other words,
+ if the agent did not have a plugin in this enabled setting,
+ the plugin will not be enabled, effectively overriding
+ the server setting). If the agent already has a plugin jar in
+ its local plugins directory, but that plugin is not enabled
+ via this preference, that local plugin jar file will be
+ deleted and the plugin will not be loaded.
+
+ Note that if a plugin is listed in both this preference and
+ the rhq.agent.plugins.disabled preference, the plugin will
+ be disabled (that is, the disabled setting takes precedence).
+ -->
+ <!--
+ <entry key="rhq.agent.plugins.enabled" value=""/>
+ -->
+
+ <!--
+ _______________________________________________________________
rhq.agent.plugins.disabled-resource-types
Defines the names of the resource types to be disabled.
diff --git a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
index 641fbee..c9820cf 100644
--- a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
@@ -331,6 +331,7 @@
<c:simple-property name="rhq.agent.plugins.event-sender.period-secs" type="integer" units="seconds" activationPolicy="restart" required="false" default="30" displayName="Event Sender Period" description="Defines how often event reports get sent to the server (in seconds)" />
<c:simple-property name="rhq.agent.plugins.event-report.max-per-source" type="integer" activationPolicy="restart" required="false" default="200" displayName="Event Report Max Per Source" description="Defines the maximum number of events for any given event source that can be placed in a single event report that is sent up to the server. If this number is larger than the max-total setting, then this setting is ignored" />
<c:simple-property name="rhq.agent.plugins.event-report.max-total" type="integer" activationPolicy="restart" required="false" default="400" displayName="Event Report Max Total" description="Defines the total maximum number of events that can be placed in a single event report that is sent up to the server" />
+ <c:simple-property name="rhq.agent.plugins.enabled" type="string" activationPolicy="restart" required="false" default="" displayName="Enabled Plugins" description="Defines the plugins that should be enabled by the plugin container. Those plugins not listed will not be loaded. This is a comma-separated list of plugin names." />
<c:simple-property name="rhq.agent.plugins.disabled" type="string" activationPolicy="restart" required="false" default="" displayName="Disabled Plugins" description="Defines the plugins that should be disabled and not loaded by the plugin container. This is a comma-separated list of plugin names." />
<c:simple-property name="rhq.agent.plugins.disabled-resource-types" type="string" activationPolicy="restart" required="false" default="" displayName="Disabled Resource Types" description="Defines the resource types that should be disabled and not used by the plugin container. This is a |-separated list of type names in the form of 'plugin name>parent type>child type'." />
</c:group>
10 years, 4 months