modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
| 77 +++++-----
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
| 8 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/SnapshotGenerator.java
| 17 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
| 21 ++
4 files changed, 69 insertions(+), 54 deletions(-)
New commits:
commit ea1f3b883340dd4db2724f01e80484a497c4f048
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 3 12:29:48 2014 -0500
[1059932] PC classes must use data directory configured in PC, not just use
"data"
Change things around to us the proper data directory, as configured for the
plugin container (via InventoryManager)
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
index da70b18..666281f 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
@@ -39,6 +39,7 @@ import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
+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.FacetLockType;
@@ -52,13 +53,10 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
private static final Log log = LogFactory.getLog(ConfigurationCheckExecutor.class);
private ConfigurationServerService configurationServerService;
- private InventoryManager inventoryManager;
private static final long CONFIGURATION_CHECK_TIMEOUT = 30000L;
- public ConfigurationCheckExecutor(ConfigurationServerService
configurationServerService,
- InventoryManager inventoryManager) {
+ public ConfigurationCheckExecutor(ConfigurationServerService
configurationServerService) {
this.configurationServerService = configurationServerService;
- this.inventoryManager = inventoryManager;
}
public void run() {
@@ -70,14 +68,16 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
long start = System.currentTimeMillis();
CountTime countTime;
- countTime = checkConfigurations(this.inventoryManager.getPlatform(), true);
- log.info("Configuration update check for [" + countTime.count + "]
resources completed in " +
- (System.currentTimeMillis() - start)/1000 + "s wall time, " +
countTime.time + "ms check time");
+ InventoryManager inventoryManager =
PluginContainer.getInstance().getInventoryManager();
+ Resource platform = inventoryManager.getPlatform();
+ countTime = checkConfigurations(inventoryManager, platform, true);
+ log.info("Configuration update check for [" + countTime.count + "]
resources completed in "
+ + (System.currentTimeMillis() - start) / 1000 + "s wall time, " +
countTime.time + "ms check time");
return null;
}
- public CountTime checkConfigurations(Resource resource, boolean checkChildren) {
- ResourceContainer resourceContainer =
this.inventoryManager.getResourceContainer(resource.getId());
+ public CountTime checkConfigurations(InventoryManager inventoryManager, Resource
resource, boolean checkChildren) {
+ ResourceContainer resourceContainer =
inventoryManager.getResourceContainer(resource.getId());
ConfigurationFacet resourceComponent = null;
ResourceType resourceType = resource.getResourceType();
@@ -93,7 +93,7 @@ public class ConfigurationCheckExecutor implements Runnable, Callable {
FacetLockType.NONE, CONFIGURATION_CHECK_TIMEOUT, true, false,
true);
} catch (PluginContainerException e) {
// Expecting when the resource does not support configuration
management
- // Should never happen after above check
+ // Should never happen after above check
}
}
@@ -104,7 +104,6 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
long t1 = System.currentTimeMillis();
-
if (debugEnabled) {
log.debug("Checking for updated Resource configuration for
" + resource + "...");
}
@@ -117,7 +116,8 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
.getResourceConfigurationDefinition();
// Normalize and validate the config.
-
ConfigurationUtility.normalizeConfiguration(liveConfiguration,
configurationDefinition,true,true);
+
ConfigurationUtility.normalizeConfiguration(liveConfiguration, configurationDefinition,
+ true, true);
List<String> errorMessages =
ConfigurationUtility.validateConfiguration(liveConfiguration,
configurationDefinition);
for (String errorMessage : errorMessages) {
@@ -126,10 +126,10 @@ public class ConfigurationCheckExecutor implements Runnable,
Callable {
+ errorMessage);
}
- Configuration original = getResourceConfiguration(resource);
+ Configuration original =
getResourceConfiguration(inventoryManager, resource);
- if (original==null) {
- original = loadConfigurationFromFile(resource.getId());
+ if (original == null) {
+ original = loadConfigurationFromFile(inventoryManager,
resource.getId());
}
if (!liveConfiguration.equals(original)) {
@@ -138,8 +138,9 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
}
this.configurationServerService.persistUpdatedResourceConfiguration(resource.getId(),
liveConfiguration);
-// resource.setResourceConfiguration(liveConfiguration);
- boolean persisted =
persistConfigurationToFile(resource.getId(),liveConfiguration, log);
+ //
resource.setResourceConfiguration(liveConfiguration);
+ boolean persisted =
persistConfigurationToFile(inventoryManager, resource.getId(),
+ liveConfiguration, log);
if (persisted) {
resource.setResourceConfiguration(null);
}
@@ -151,22 +152,22 @@ public class ConfigurationCheckExecutor implements Runnable,
Callable {
}
long now = System.currentTimeMillis();
- countTime.add(1,(now-t1));
+ countTime.add(1, (now - t1));
// Give the agent some time to breathe
try {
Thread.sleep(750);
} catch (InterruptedException e) {
; // We don't care
+ }
}
}
- }
if (checkChildren) {
- for (Resource child :
this.inventoryManager.getContainerChildren(resource, resourceContainer)) {
+ for (Resource child : inventoryManager.getContainerChildren(resource,
resourceContainer)) {
try {
- CountTime inner = checkConfigurations(child, true);
- countTime.add(inner.count,inner.time);
+ CountTime inner = checkConfigurations(inventoryManager, child,
true);
+ countTime.add(inner.count, inner.time);
} catch (Exception e) {
log.error("Failed to check Resource configuration for "
+ child + ".", e);
}
@@ -176,20 +177,22 @@ public class ConfigurationCheckExecutor implements Runnable,
Callable {
return countTime;
}
- public static Configuration getResourceConfiguration(Resource resource) {
+ static public Configuration getResourceConfiguration(InventoryManager
inventoryManager, Resource resource) {
Configuration result = resource.getResourceConfiguration();
if (null == result) {
- result = loadConfigurationFromFile(resource.getId());
+ result = loadConfigurationFromFile(inventoryManager, resource.getId());
}
return result;
}
- public static boolean persistConfigurationToFile(int resourceId, Configuration
liveConfiguration, Log log) {
+ static public boolean persistConfigurationToFile(InventoryManager inventoryManager,
int resourceId,
+ Configuration liveConfiguration, Log log) {
boolean success = true;
try {
- String pathname = "data/rc/" + String.valueOf(resourceId/1000); //
Don't put too many files into one data dir
- File dataDir = new File(pathname);
+ File baseDataDir = inventoryManager.getDataDirectory();
+ String pathname = "rc/" + String.valueOf(resourceId / 1000); //
Don't put too many files into one data dir
+ File dataDir = new File(baseDataDir, pathname);
if (!dataDir.exists()) {
success = dataDir.mkdirs();
if (!success) {
@@ -213,9 +216,10 @@ public class ConfigurationCheckExecutor implements Runnable, Callable
{
}
- static private Configuration loadConfigurationFromFile(int resourceId) {
- String pathname = "data/rc/" + String.valueOf(resourceId/1000); //
Don't put too many files into one data dir
- File dataDir = new File(pathname);
+ static private Configuration loadConfigurationFromFile(InventoryManager
inventoryManager, int resourceId) {
+ File baseDataDir = inventoryManager.getDataDirectory();
+ String pathname = "rc/" + String.valueOf(resourceId / 1000); //
Don't put too many files into one data dir
+ File dataDir = new File(baseDataDir, pathname);
File file = new File(dataDir, String.valueOf(resourceId));
if (!file.exists()) {
log.error("File " + file.getAbsolutePath() + " does not
exist");
@@ -239,21 +243,18 @@ public class ConfigurationCheckExecutor implements Runnable,
Callable {
}
private static class CountTime {
- private long count=0;
- private long time=0;
+ private long count = 0L;
+ private long time = 0L;
private void add(long count, long time) {
- this.count +=count;
- this.time +=time;
+ this.count += count;
+ this.time += time;
}
@Override
public String toString() {
- return "CountTime{" +
- "count=" + count +
- ", time=" + time +
- '}';
+ return "CountTime{" + "count=" + count + ",
time=" + time + '}';
}
}
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 393d392..dfb6412 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
@@ -81,13 +81,13 @@ public class ConfigurationManager extends AgentService implements
ContainerServi
threadPool = new ScheduledThreadPoolExecutor(1, threadFactory);
ConfigurationCheckExecutor configurationChecker = new
ConfigurationCheckExecutor(
- getConfigurationServerService(),
PluginContainer.getInstance().getInventoryManager());
+ getConfigurationServerService());
if (pluginContainerConfiguration.getConfigurationDiscoveryPeriod() > 0
&& pluginContainerConfiguration.isInsideAgent()) {
- threadPool.scheduleAtFixedRate(configurationChecker,
pluginContainerConfiguration
- .getConfigurationDiscoveryInitialDelay(), pluginContainerConfiguration
- .getConfigurationDiscoveryPeriod(), TimeUnit.SECONDS);
+ threadPool.scheduleAtFixedRate(configurationChecker,
+ pluginContainerConfiguration.getConfigurationDiscoveryInitialDelay(),
+ pluginContainerConfiguration.getConfigurationDiscoveryPeriod(),
TimeUnit.SECONDS);
}
}
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 ca940cb..aed76d9 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
@@ -1864,6 +1864,10 @@ public class InventoryManager extends AgentService implements
ContainerService,
+ "] as it is already in the process of starting.");
return false;
+ default:
+ log.error("Unexpected state [" + state.name() + "],
returning false...");
+
+ return false;
}
} else {
if (log.isTraceEnabled()) {
@@ -2038,6 +2042,13 @@ public class InventoryManager extends AgentService implements
ContainerService,
}
}
+ /**
+ * @return The location for [plugins] to write data files
+ */
+ public File getDataDirectory() {
+ return this.configuration.getDataDirectory();
+ }
+
private <T extends ResourceComponent<?>> ResourceContext<T>
createResourceContext(Resource resource,
T parentComponent, ResourceContext<?> parentResourceContext,
ResourceDiscoveryComponent<T> discoveryComponent) {
@@ -2047,7 +2058,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
discoveryComponent, // the discovery component (this is actually the proxy to
it)
SystemInfoFactory.createSystemInfo(), // for native access
this.configuration.getTemporaryDirectory(), // location for plugin to write
temp files
- this.configuration.getDataDirectory(), // location for plugin to write data
files
+ this.configuration.getDataDirectory(), // base location for plugin to write
data files
this.configuration.getContainerName(), // the name of the agent/PC
getEventContext(resource), // for event access
getOperationContext(resource), // for operation manager access
@@ -3073,7 +3084,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
if (resourceConfiguration != null) {
resourceConfiguration.cleanoutRawConfiguration();
- boolean persisted =
ConfigurationCheckExecutor.persistConfigurationToFile(resource.getId(),
+ boolean persisted =
ConfigurationCheckExecutor.persistConfigurationToFile(this, resource.getId(),
resourceConfiguration, log);
if (persisted) {
resource.setResourceConfiguration(null);
@@ -3082,7 +3093,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
}
public static Configuration getResourceConfiguration(Resource agentSideResource) {
- return ConfigurationCheckExecutor.getResourceConfiguration(agentSideResource);
+ return
ConfigurationCheckExecutor.getResourceConfiguration(PluginContainer.getInstance().getInventoryManager(),
+ agentSideResource);
}
private void compactConfiguration(Configuration config) {
@@ -3487,6 +3499,9 @@ public class InventoryManager extends AgentService implements
ContainerService,
}
break;
}
+ default:
+ // nothing to do for other states
+ break;
}
container.setSynchronizationState(ResourceContainer.SynchronizationState.SYNCHRONIZED);
commit 5bd9673b5d08f51e933438132e63d7620354de9c
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Feb 3 12:00:11 2014 -0500
Fix: was logging as the wrong class.
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/SnapshotGenerator.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/SnapshotGenerator.java
index e6c4d07..bdc84f4 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/SnapshotGenerator.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/SnapshotGenerator.java
@@ -1,10 +1,6 @@
package org.rhq.core.pc.drift;
-import org.apache.commons.io.DirectoryWalker;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import static java.io.File.separator;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -21,14 +17,17 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import org.rhq.core.pc.configuration.ConfigurationCheckExecutor;
-import org.rhq.core.util.MessageDigestGenerator;
+import org.apache.commons.io.DirectoryWalker;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
-import static java.io.File.separator;
+import org.rhq.core.util.MessageDigestGenerator;
public class SnapshotGenerator extends DirectoryWalker {
- private final Log log = LogFactory.getLog(ConfigurationCheckExecutor.class);
+ private final Log log = LogFactory.getLog(SnapshotGenerator.class);
private MessageDigestGenerator digestGenerator = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256);