modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/BackupAndReplaceFileActionHandler.java
| 8
modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
| 16
modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/HandlerUtils.java
| 9
modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
| 6
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
| 53 +-
modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/ExtensionModelTest.java
| 5
modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
| 2
modules/core/dbutils/src/main/java/org/rhq/core/db/ant/dbupgrade/DBUpgrader.java
| 24
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
| 13
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryFile.java
| 10
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
| 12
modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
| 1
modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
| 16
modules/core/util/src/test/java/org/rhq/core/util/ZipUtilTest.java
| 4
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java
| 8
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
| 6
modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
| 10
modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
| 8
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
| 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
| 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/SearchBar.java
| 31 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleFileUploadServlet.java
| 13
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PackageVersionFileUploadServlet.java
| 16
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
| 14
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
| 6
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
| 42 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
| 63 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CustomJaasDeploymentService.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
| 63 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
| 14
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
| 13
modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
| 76 +-
modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
| 4
modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java
| 2
modules/plugins/byteman/src/main/java/org/rhq/plugins/byteman/BytemanRuleComponent.java
| 2
modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableComponent.java
| 16
modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
| 6
modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISServerDiscoveryComponent.java
| 4
modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostComponent.java
| 4
modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostDiscoveryComponent.java
| 4
modules/plugins/jboss-cache/src/main/java/org/rhq/plugins/jbosscache/JBossCacheComponent.java
| 6
modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
| 46 -
modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
| 3
modules/plugins/netservices/src/main/java/org/rhq/plugins/netservices/HTTPNetServiceComponent.java
| 4
modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleDiscoveryComponent.java
| 7
modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java
| 4
modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java
| 1
modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/YumServer.java
| 21
modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
| 48 -
modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java
| 3
modules/plugins/rhq-agent/src/main/java/org/rhq/plugins/agent/AgentSnapshotReport.java
| 9
modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
| 49 +
modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
| 8
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDiscoveryComponent.java
| 9
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatGroupComponent.java
| 3
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatUserComponent.java
| 3
modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
| 3
modules/plugins/virt/src/main/java/org/rhq/plugins/virt/LibVirtConnection.java
| 264 ++++++----
modules/plugins/virt/src/main/java/org/rhq/plugins/virt/VirtualizationDomainComponent.java
| 5
modules/test-utils/src/main/java/org/rhq/test/JPAUtils.java
| 16
61 files changed, 723 insertions(+), 412 deletions(-)
New commits:
commit ec88d4be0152d195ef769de97f43cdd289d77aeb
Merge: b38642e c4a82bc
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Aug 1 08:41:55 2011 +0200
Merge branch 'code-smell' into master
commit b38642e2f6dc7ea6ada5781440c7580336b38af6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 23:47:32 2011 -0400
[coverity] fix NPE
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
index 60d6b0f..a57c686 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
@@ -20,7 +20,6 @@ package org.rhq.enterprise.server.alert;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -307,24 +306,26 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
public boolean finalizeNotifications(Subject subject, List<AlertNotification>
notifications) {
boolean hasErrors = false;
-
+
AlertSenderPluginManager pluginManager = alertManager.getAlertPluginManager();
-
- for(AlertNotification notification : notifications) {
+
+ for (AlertNotification notification : notifications) {
AlertSender<?> sender =
pluginManager.getAlertSenderForNotification(notification);
-
- AlertSenderValidationResults validation =
sender.validateAndFinalizeConfiguration(subject);
-
- notification.setConfiguration(validation.getAlertParameters());
- notification.setExtraConfiguration(validation.getExtraParameters());
-
- hasErrors = hasErrors || hasErrors(validation.getAlertParameters()) ||
- hasErrors(validation.getExtraParameters());
- }
-
+
+ if (sender != null) {
+ AlertSenderValidationResults validation =
sender.validateAndFinalizeConfiguration(subject);
+
+ notification.setConfiguration(validation.getAlertParameters());
+ notification.setExtraConfiguration(validation.getExtraParameters());
+
+ hasErrors = hasErrors || hasErrors(validation.getAlertParameters())
+ || hasErrors(validation.getExtraParameters());
+ }
+ }
+
return !hasErrors;
}
-
+
public int cleanseAlertNotificationBySubject(int subjectId) {
return cleanseParameterValueForAlertSender("System Users",
"subjectId", String.valueOf(subjectId));
}
@@ -335,17 +336,17 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
public void massReconfigure(List<Integer> alertNotificationIds, Map<String,
String> newConfigurationValues) {
Query query =
entityManager.createNamedQuery(AlertNotification.QUERY_UPDATE_PARAMETER_FOR_NOTIFICATIONS);
-
+
query.setParameter("alertNotificationIds", alertNotificationIds);
-
- for(Map.Entry<String, String> entry : newConfigurationValues.entrySet()) {
+
+ for (Map.Entry<String, String> entry : newConfigurationValues.entrySet())
{
query.setParameter("propertyName", entry.getKey());
query.setParameter("propertyValue", entry.getValue());
-
+
query.executeUpdate();
}
}
-
+
private int cleanseParameterValueForAlertSender(String senderName, String
propertyName, String valueToCleanse) {
Query query =
entityManager.createNamedQuery(AlertNotification.QUERY_CLEANSE_PARAMETER_VALUE_FOR_ALERT_SENDER);
query.setParameter("senderName", senderName);
@@ -357,43 +358,43 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
private boolean hasErrors(AbstractPropertyMap configuration) {
if (configuration instanceof PropertyMap) {
- if (((PropertyMap)configuration).getErrorMessage() != null) {
+ if (((PropertyMap) configuration).getErrorMessage() != null) {
return true;
}
}
-
- for(Map.Entry<String, Property> entry : configuration.getMap().entrySet())
{
+
+ for (Map.Entry<String, Property> entry : configuration.getMap().entrySet())
{
if (hasErrors(entry.getValue())) {
return true;
}
}
-
+
return false;
}
-
+
private boolean hasErrors(PropertyList list) {
if (list.getErrorMessage() != null) {
return true;
}
-
- for(Property p : list.getList()) {
+
+ for (Property p : list.getList()) {
if (hasErrors(p)) {
return true;
}
}
-
+
return false;
}
-
+
private boolean hasErrors(Property property) {
if (property instanceof PropertySimple) {
return property.getErrorMessage() != null;
} else if (property instanceof PropertyList) {
return hasErrors((PropertyList) property);
} else if (property instanceof PropertyMap) {
- return hasErrors((AbstractPropertyMap)property);
+ return hasErrors((AbstractPropertyMap) property);
} else {
return false;
}
- }
+ }
}
commit 9537fe73100bcef9054098b2fa0f41f43b108e9d
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 23:44:09 2011 -0400
[coverity] fix NPE
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 3db9170..3f07f8b 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
@@ -661,6 +661,13 @@ public class AgentConfiguration {
long[] ret_params = isClientSenderCommandSpoolFileParamsValueValid(value);
+ // If the config was invalid, immediately fall back to our default just so we
don't bomb out with a NPE later.
+ // We are guaranteed not to get a null returned if we pass in the hardcoded
default params.
+ // The above method will have already logged a warning for us.
+ if (ret_params == null) {
+ ret_params =
isClientSenderCommandSpoolFileParamsValueValid(AgentConfigurationConstants.DEFAULT_CLIENT_SENDER_COMMAND_SPOOL_FILE_PARAMS);
+ }
+
return ret_params;
}
@@ -1229,7 +1236,6 @@ public class AgentConfiguration {
return config;
}
-
/**
* This returns the agent's security token that it needs to send with its
commands to the server. If <code>
* null</code>, it means the agent has not yet been registered with the
server.
commit 7fd8a41c6bf1f3327e968611c5fb0452e6f455a4
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 23:29:58 2011 -0400
[coverity] fix NPE
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
index 85f5e92..5860fb6 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/CoreGUI.java
@@ -53,8 +53,8 @@ import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceT
import org.rhq.enterprise.gui.coregui.client.menu.MenuBarView;
import org.rhq.enterprise.gui.coregui.client.report.ReportTopView;
import org.rhq.enterprise.gui.coregui.client.report.tag.TaggedView;
-import org.rhq.enterprise.gui.coregui.client.test.TestRemoteServiceStatisticsView;
import org.rhq.enterprise.gui.coregui.client.test.TestDataSourceResponseStatisticsView;
+import org.rhq.enterprise.gui.coregui.client.test.TestRemoteServiceStatisticsView;
import org.rhq.enterprise.gui.coregui.client.test.TestTopView;
import org.rhq.enterprise.gui.coregui.client.util.ErrorHandler;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
@@ -524,10 +524,12 @@ public class CoreGUI implements EntryPoint,
ValueChangeHandler<String>, Event.Na
}
}.run(); // fire the timer immediately
} else {
- if (this.currentCanvas instanceof BookmarkableView) {
- ((BookmarkableView)
this.currentCanvas).renderView(viewPath.next());
- } else {
- this.currentCanvas.markForRedraw();
+ if (this.currentCanvas != null) {
+ if (this.currentCanvas instanceof BookmarkableView) {
+ ((BookmarkableView)
this.currentCanvas).renderView(viewPath.next());
+ } else {
+ this.currentCanvas.markForRedraw();
+ }
}
}
}
commit 47dad6a1bae981765565df5f6b25e0e2aacbc7a3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 23:06:00 2011 -0400
[coverity] close initial contexts
diff --git a/modules/test-utils/src/main/java/org/rhq/test/JPAUtils.java
b/modules/test-utils/src/main/java/org/rhq/test/JPAUtils.java
index b385473..cff3343 100644
--- a/modules/test-utils/src/main/java/org/rhq/test/JPAUtils.java
+++ b/modules/test-utils/src/main/java/org/rhq/test/JPAUtils.java
@@ -24,8 +24,13 @@ public class JPAUtils {
public static EntityManager lookupEntityManager() {
try {
- return ((EntityManagerFactory)
getInitialContext().lookup("java:/RHQEntityManagerFactory"))
- .createEntityManager();
+ InitialContext initialContext = getInitialContext();
+ try {
+ return ((EntityManagerFactory)
initialContext.lookup("java:/RHQEntityManagerFactory"))
+ .createEntityManager();
+ } finally {
+ initialContext.close();
+ }
} catch (NamingException e) {
throw new RuntimeException("Failed to load entity manager", e);
}
@@ -33,7 +38,12 @@ public class JPAUtils {
public static TransactionManager lookupTransactionManager() {
try {
- return (TransactionManager)
getInitialContext().lookup("java:/TransactionManager");
+ InitialContext initialContext = getInitialContext();
+ try {
+ return (TransactionManager)
initialContext.lookup("java:/TransactionManager");
+ } finally {
+ initialContext.close();
+ }
} catch (NamingException e) {
throw new RuntimeException("Failed to load transaction manager",
e);
}
commit a0dcfe490b595b9c950eff69a1d4efa9410482d9
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 23:04:17 2011 -0400
[coverity] fix NPE
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
index 38d0fa5..2321fd3 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupTreeView.java
@@ -591,8 +591,8 @@ public class ResourceGroupTreeView extends LocatableVLayout implements
Bookmarka
public void renderView(ViewPath viewPath) {
currentViewId = viewPath.getCurrent();
- String currentViewIdPath = currentViewId.getPath();
if (this.currentViewId != null) {
+ String currentViewIdPath = currentViewId.getPath();
if ("AutoCluster".equals(currentViewIdPath)) {
// Move the currentViewId to the ID portion to play better with other
code
currentViewId = viewPath.getNext();
commit 5cd3024ccd2ef2712864f1331a7500d5b7abe1d8
Merge: ed7aad1 da99d5b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 22:55:15 2011 -0400
Merge commit 'origin/master' into code-smell
Conflicts:
modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
commit ed7aad1f40f87b6d484897d72eb2075836f7ae29
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:43:23 2011 -0400
[coverity] close initial contexts
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
index e9ff990..5cd937b 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
@@ -233,6 +233,7 @@ public final class LookupUtil {
try {
InitialContext context = new InitialContext();
DataSource ds = (DataSource)
context.lookup(RHQConstants.DATASOURCE_JNDI_NAME);
+ context.close();
return ds;
} catch (Exception e) {
throw new RuntimeException("Failed to get the data source", e);
@@ -249,6 +250,7 @@ public final class LookupUtil {
try {
InitialContext context = new InitialContext();
TransactionManager tm = (TransactionManager)
context.lookup(RHQConstants.TRANSACTION_MANAGER_JNDI_NAME);
+ context.close();
return tm;
} catch (Exception e) {
throw new RuntimeException("Failed to get the transaction manager",
e);
@@ -678,7 +680,12 @@ public final class LookupUtil {
* @throws NamingException when resource not found
*/
private static Object lookup(String name) throws NamingException {
- return new InitialContext().lookup(name);
+ InitialContext initialContext = new InitialContext();
+ try {
+ return initialContext.lookup(name);
+ } finally {
+ initialContext.close();
+ }
}
public static DataAccessManagerLocal getDataAccessManager() {
commit 199940ca403f4123a2a6a753b196a12f975e207a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:24:39 2011 -0400
[coverity] close jar file
diff --git
a/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
b/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
index fc43008..704b48d 100644
---
a/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
+++
b/modules/enterprise/agentupdate/src/main/java/org/rhq/enterprise/agent/update/AgentUpdate.java
@@ -272,9 +272,13 @@ public class AgentUpdate {
private byte[] getJarFileContent(String filename) throws Exception {
JarFile jarFile = new JarFile(getJarFilename()); // use the jar file because user
might have used --jar
- JarEntry jarFileEntry = jarFile.getJarEntry(filename);
- InputStream jarFileEntryStream = jarFile.getInputStream(jarFileEntry);
- return slurp(jarFileEntryStream);
+ try {
+ JarEntry jarFileEntry = jarFile.getJarEntry(filename);
+ InputStream jarFileEntryStream = jarFile.getInputStream(jarFileEntry);
+ return slurp(jarFileEntryStream);
+ } finally {
+ jarFile.close();
+ }
}
private void printSyntax() {
commit 9cabd191fd42b89a86d1fa6bd2290bc5ea7a16c3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:22:35 2011 -0400
[coverity] close reader
diff --git
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
index 693885f..9a071b7 100644
---
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
+++
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
@@ -58,7 +58,7 @@ public class ScriptCommand implements ClientCommand {
private ScriptEngine jsEngine;
private StandardBindings bindings;
-
+
private final Log log = LogFactory.getLog(ScriptCommand.class);
private StringBuilder script = new StringBuilder();
@@ -85,7 +85,15 @@ public class ScriptCommand implements ClientCommand {
bindScriptArgs(scriptCmdLine);
executeUtilScripts();
- return executeScriptFile(new
FileReader(scriptCmdLine.getScriptFileName()), client);
+ FileReader reader = new FileReader(scriptCmdLine.getScriptFileName());
+ try {
+ return executeScriptFile(reader, client);
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException ignore) {
+ }
+ }
} catch (FileNotFoundException e) {
client.getPrintWriter().println(e.getMessage());
if (log.isDebugEnabled()) {
@@ -97,8 +105,7 @@ public class ScriptCommand implements ClientCommand {
if (log.isDebugEnabled()) {
log.debug("A parse error occurred.", e);
}
- }
- else {
+ } else {
throw new CLIScriptException(e);
}
}
@@ -143,8 +150,8 @@ public class ScriptCommand implements ClientCommand {
} catch (ScriptException e) {
String message = e.getCause() != null ? e.getCause().getMessage() :
e.getMessage();
- message =
message.replace("sun.org.mozilla.javascript.internal.EcmaError:
","");
- message = message.replace("(<Unknown source>#1) in <Unknown
source> at line number 1","");
+ message =
message.replace("sun.org.mozilla.javascript.internal.EcmaError: ",
"");
+ message = message.replace("(<Unknown source>#1) in <Unknown
source> at line number 1", "");
client.getPrintWriter().println(message);
client.getPrintWriter().println(script);
@@ -162,9 +169,10 @@ public class ScriptCommand implements ClientCommand {
public void initBindings(ClientMain client) {
if (jsEngine == null) {
bindings = new StandardBindings(client.getPrintWriter(),
client.getRemoteClient());
-
+
try {
- jsEngine = ScriptEngineFactory.getScriptEngine("JavaScript",
new PackageFinder(Arrays.asList(getLibDir())), bindings);
+ jsEngine = ScriptEngineFactory.getScriptEngine("JavaScript",
new PackageFinder(Arrays
+ .asList(getLibDir())), bindings);
jsEngine.eval("1+1");
} catch (ScriptException e) {
e.printStackTrace();
@@ -172,19 +180,20 @@ public class ScriptCommand implements ClientCommand {
e.printStackTrace();
}
}
-
+
bindings.getSubject().setValue(client.getSubject());
bindings.getPretty().getValue().setWidth(client.getConsoleWidth());
bindings.getProxyFactory().setValue(new EditableResourceClientFactory(client));
-
+
//non-standard bindings
bindings.put("configurationEditor", new ConfigurationEditor(client));
bindings.put("rhq", new Controller(client));
ScriptEngineFactory.injectStandardBindings(jsEngine, bindings, false);
-
- ScriptEngineFactory.bindIndirectionMethods(jsEngine,
"configurationEditor", bindings.get("configurationEditor"));
- ScriptEngineFactory.bindIndirectionMethods(jsEngine, "rhq",
bindings.get("rhq"));
+
+ ScriptEngineFactory
+ .bindIndirectionMethods(jsEngine, "configurationEditor",
bindings.get("configurationEditor"));
+ ScriptEngineFactory.bindIndirectionMethods(jsEngine, "rhq",
bindings.get("rhq"));
}
private void executeUtilScripts() {
@@ -253,8 +262,7 @@ public class ScriptCommand implements ClientCommand {
if (client.isInteractiveMode()) {
client.getPrintWriter().println(e.getMessage());
client.getPrintWriter().println("^");
- }
- else {
+ } else {
throw new CLIScriptException(e);
}
}
@@ -270,8 +278,8 @@ public class ScriptCommand implements ClientCommand {
}
public String getDetailedHelp() {
- return "Execute a statement or a script. The following services managers are
available: " +
- RhqManagers.values();
+ return "Execute a statement or a script. The following services managers are
available: "
+ + RhqManagers.values();
}
public ScriptContext getContext() {
commit 19c89919315d3a13f2894f9da829f1384e710053
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:20:31 2011 -0400
close streams (didn't see a coverity alert on this - I just came across it)
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
index 89280d9..e7f63a4 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/Version.java
@@ -184,7 +184,11 @@ public class Version {
Properties newProps = new Properties();
try {
- newProps.load(stream);
+ try {
+ newProps.load(stream);
+ } finally {
+ stream.close();
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}
commit b7a146b5eae72b2545ceead0a45c79420355be7a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:18:49 2011 -0400
[coverity] close stream
diff --git
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
index 84e9ec0..0150a9c 100644
---
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
+++
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/Version.java
@@ -190,7 +190,11 @@ public class Version {
try {
URL jarUrl =
Version.class.getProtectionDomain().getCodeSource().getLocation();
JarFile jarFile = new JarFile(new File(jarUrl.toURI()));
- manifest = jarFile.getManifest();
+ try {
+ manifest = jarFile.getManifest();
+ } finally {
+ jarFile.close();
+ }
} catch (Exception e) {
return new Properties();
}
commit 2a8e27ee809f2d812b72b15fcbb5ee8a0485c653
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:15:31 2011 -0400
[converity] close stream
diff --git
a/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
b/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
index 8bb9865..4d5848f 100644
---
a/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
+++
b/modules/enterprise/comm/src/main/java/org/rhq/enterprise/communications/util/DumpBytes.java
@@ -167,9 +167,13 @@ public class DumpBytes {
int num_bytes;
try {
- fis = new FileInputStream(file);
file_contents = new byte[(int) file.length()];
- num_bytes = fis.read(file_contents);
+ fis = new FileInputStream(file);
+ try {
+ num_bytes = fis.read(file_contents);
+ } finally {
+ fis.close();
+ }
if (num_bytes != file_contents.length) {
throw new IllegalStateException(num_bytes + "!=" +
file_contents.length);
commit 0fac1e88882631275804d98d47c910b005f1050e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 16:11:15 2011 -0400
[coverity] close input streams
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
index 052bf11..db04c59 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
@@ -92,7 +92,12 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl
implements Syst
File file = agentManager.getAgentUpdateVersionFile();
Properties props = new Properties();
- props.load(new FileInputStream(file));
+ FileInputStream inStream = new FileInputStream(file);
+ try {
+ props.load(inStream);
+ } finally {
+ inStream.close();
+ }
return convertFromProperties(props);
} catch (Throwable t) {
@@ -143,7 +148,12 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl
implements Syst
File versionFile = new File(getClientDownloadDir(),
"rhq-client-version.properties");
try {
Properties p = new Properties();
- p.load(new FileInputStream(versionFile));
+ FileInputStream inStream = new FileInputStream(versionFile);
+ try {
+ p.load(inStream);
+ } finally {
+ inStream.close();
+ }
return convertFromProperties(p);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t, "Unable to retrieve client version
info.");
commit 2e3d2af81ea989a9dad7d9ccc5c6e551a085d879
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:53:19 2011 -0400
[coverity] close input streams
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
index 3bdafda..b339190 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/RetrieveContentBitsRunner.java
@@ -86,7 +86,12 @@ public class RetrieveContentBitsRunner implements Runnable {
InputStream is;
try {
is = contentManager.performGetPackageBits(request.getResourceId(),
request.getPackageDetails());
- pkgDetails.setSHA256(new
MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(is));
+ try {
+ pkgDetails.setSHA256(new
MessageDigestGenerator(MessageDigestGenerator.SHA_256)
+ .calcDigestString(is));
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace();
}
@@ -95,7 +100,11 @@ public class RetrieveContentBitsRunner implements Runnable {
InputStream is;
try {
is = contentManager.performGetPackageBits(request.getResourceId(),
request.getPackageDetails());
- pkgDetails.setMD5((new
MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(is)));
+ try {
+ pkgDetails.setMD5((new
MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(is)));
+ } finally {
+ is.close();
+ }
} catch (Exception e) {
e.printStackTrace();
}
commit 302b7ee7c388f0db5f7cf926308034b5041de7ad
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:44:49 2011 -0400
[coverity] be nice and close the context. don't worry about doing it
in a try-finally - if the lookup fails, we have more important things
to worry about then not closing the context - such as we don't
have a hibernate entity manager available!
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
index b399741..e9ff990 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/LookupUtil.java
@@ -266,6 +266,7 @@ public final class LookupUtil {
try {
InitialContext context = new InitialContext();
EntityManagerFactory factory = (EntityManagerFactory)
context.lookup(RHQConstants.ENTITY_MANAGER_JNDI_NAME);
+ context.close();
return factory.createEntityManager();
} catch (Exception e) {
throw new RuntimeException("Failed to create an entity manager",
e);
@@ -653,7 +654,8 @@ public final class LookupUtil {
localJNDIName = getLocalJNDIName(type);
return (T) lookup(localJNDIName);
} catch (NamingException e) {
- throw new RuntimeException("Failed to lookup local interface to EJB
" + type + ", localJNDI=[" + localJNDIName + "]", e);
+ throw new RuntimeException("Failed to lookup local interface to EJB
" + type + ", localJNDI=["
+ + localJNDIName + "]", e);
}
}
commit 796ac12453e260f24228add540934d9a128804bf
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:40:00 2011 -0400
[coverity] close the initial context
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
index 85fb5b8..a2bdaa9 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
@@ -109,12 +109,20 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
}
public EntityManager getEntityManager() {
+ InitialContext initialContext = null;
try {
- return ((EntityManagerFactory)
getInitialContext().lookup("java:/RHQEntityManagerFactory"))
+ initialContext = getInitialContext();
+ return ((EntityManagerFactory)
initialContext.lookup("java:/RHQEntityManagerFactory"))
.createEntityManager();
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load entity manager", e);
+ } finally {
+ try {
+ initialContext.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to close the initial context -
why did this happen?", e);
+ }
}
}
commit a07dc82e8347ce2f1e7e42f9520fb3d4d5f7f3b6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:33:05 2011 -0400
[coverity] closing the initial context explicitly
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
index 57ec318..85fb5b8 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
@@ -35,15 +35,13 @@ import javax.transaction.TransactionManager;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterGroups;
-import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.BeforeSuite;
import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
public abstract class AbstractEJB3Test extends AssertJUnit {
-// @BeforeSuite(groups = "integration.ejb3")
+ // @BeforeSuite(groups = "integration.ejb3")
@BeforeGroups(groups = "integration.ejb3")
public static void startupEmbeddedJboss() {
System.out.println("Starting ejb3...");
@@ -84,7 +82,7 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
}
}
-// @AfterSuite
+ // @AfterSuite
@AfterGroups(groups = "integration.ejb3")
public static void shutdownEmbeddedJboss() {
EJB3StandaloneBootstrap.shutdown();
@@ -93,12 +91,20 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
private TransactionManager tm;
public TransactionManager getTransactionManager() {
+ InitialContext initialContext = null;
try {
- tm = (TransactionManager)
getInitialContext().lookup("java:/TransactionManager");
+ initialContext = getInitialContext();
+ tm = (TransactionManager)
initialContext.lookup("java:/TransactionManager");
return tm;
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load transaction manager",
e);
+ } finally {
+ try {
+ initialContext.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to close the initial context -
why did this happen?", e);
+ }
}
}
commit e0bb9de07efb271a80e98f53a4c09e75c9b1d73e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:23:01 2011 -0400
[coverity] close the jar file for the test
diff --git
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
index 2e3374f..714d9b5 100644
---
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
+++
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
@@ -311,7 +311,7 @@ public class PluginTransformerTest {
JarFile jarFile = new JarFile(pluginJarFile);
Manifest manifest = jarFile.getManifest();
Attributes attributes = manifest.getMainAttributes();
-
+ jarFile.close();
return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
commit 59a739e6a77f05d48ede89e5dc416ea670ad478c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:13:36 2011 -0400
[coverity] this isn't used anywhere, but we may revive it later. close the input
stream properly.
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
index 93a9c56..3c9d64f 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/i18n/PropertiesGenerator.java
@@ -1,25 +1,25 @@
- /*
- * 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-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.clientapi.agent.metadata.i18n;
import java.io.File;
@@ -34,9 +34,11 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -106,7 +108,12 @@ public class PropertiesGenerator {
if (update) {
// First load into properties we can check for existence
previousProperties = new Properties();
- previousProperties.load(new FileInputStream(propertiesFile));
+ FileInputStream is = new FileInputStream(propertiesFile);
+ try {
+ previousProperties.load(is);
+ } finally {
+ is.close();
+ }
this.contentWriter.println("\n\n# Contents added " + new Date()
+ "\n\n");
}
commit 2300051a18838bb45b6f33ca4a15ffba8f076c2a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:08:43 2011 -0400
[coverity] make sure we close the jar file
diff --git
a/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
b/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
index c24fb54..529f317 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/file/JarContentFileInfo.java
@@ -168,6 +168,7 @@ public class JarContentFileInfo extends ContentFileInfo {
JarFile jarFile = new JarFile(file);
if (null != jarFile) {
manifest = jarFile.getManifest();
+ jarFile.close();
}
} else {
File manifestFile = new File(file, "/META-INF/MANIFEST.MF");
commit f816103dfd72e5108772459d4673eb6226cf0a19
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 14:56:55 2011 -0400
[coverity] close the pid file
diff --git a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
index e4d7575..325ed20 100644
--- a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
+++ b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
@@ -18,18 +18,6 @@
*/
package org.rhq.plugins.mysql;
-import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.measurement.DataType;
-import org.rhq.core.domain.measurement.MeasurementDataNumeric;
-import org.rhq.core.domain.measurement.MeasurementReport;
-import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.rhq.core.pluginapi.inventory.ResourceComponent;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
-import org.rhq.core.pluginapi.measurement.MeasurementFacet;
-import org.rhq.core.util.jdbc.JDBCUtil;
-import org.rhq.plugins.database.DatabaseComponent;
-
import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
@@ -43,8 +31,19 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.system.AggregateProcessInfo;
import org.rhq.core.system.ProcessInfo;
+import org.rhq.plugins.database.DatabaseComponent;
import org.rhq.plugins.database.DatabaseQueryUtility;
/**
@@ -129,7 +128,7 @@ public class MySqlComponent implements DatabaseComponent,
ResourceComponent, Mea
} else if ("Process.aggregateMemory.size".equals(requestName))
{
long value = aggregateProcessInfo.getAggregateMemory().getSize();
report.addData(new MeasurementDataNumeric(request, new
Double((double) value)));
- }else if
("Process.aggregateMemory.pageFaults".equals(requestName)) {
+ } else if
("Process.aggregateMemory.pageFaults".equals(requestName)) {
long value =
aggregateProcessInfo.getAggregateMemory().getPageFaults();
report.addData(new MeasurementDataNumeric(request, new
Double((double) value)));
} else if ("Process.aggregateCpu.user".equals(requestName)) {
@@ -141,12 +140,12 @@ public class MySqlComponent implements DatabaseComponent,
ResourceComponent, Mea
} else if ("Process.aggregateCpu.percent".equals(requestName))
{
double value = aggregateProcessInfo.getAggregateCpu().getPercent();
report.addData(new MeasurementDataNumeric(request, new
Double(value)));
- } else if ("Process.aggregateCpu.total".equals(requestName))
{
+ } else if ("Process.aggregateCpu.total".equals(requestName)) {
long value = aggregateProcessInfo.getAggregateCpu().getTotal();
- report.addData(new MeasurementDataNumeric(request, new
Double((double)value)));
- }else if
("Process.aggregateFileDescriptor.total".equals(requestName)) {
+ report.addData(new MeasurementDataNumeric(request, new
Double((double) value)));
+ } else if
("Process.aggregateFileDescriptor.total".equals(requestName)) {
long value =
aggregateProcessInfo.getAggregateFileDescriptor().getTotal();
- report.addData(new MeasurementDataNumeric(request, new
Double((double)value)));
+ report.addData(new MeasurementDataNumeric(request, new
Double((double) value)));
}
} else {
if (request.getDataType() == DataType.MEASUREMENT) {
@@ -202,11 +201,15 @@ public class MySqlComponent implements DatabaseComponent,
ResourceComponent, Mea
if (file.canRead()) {
try {
FileReader pidFileReader = new FileReader(file);
- char pidData[] = new char[(int)file.length()];
- pidFileReader.read(pidData);
- String pidString = new String(pidData);
- pidString = pidString.trim();
- result = Long.valueOf(pidString);
+ try {
+ char pidData[] = new char[(int) file.length()];
+ pidFileReader.read(pidData);
+ String pidString = new String(pidData);
+ pidString = pidString.trim();
+ result = Long.valueOf(pidString);
+ } finally {
+ pidFileReader.close();
+ }
} catch (Exception ex) {
log.warn("Unable to read MySQL pid file " + pidFile);
}
commit bd2129db2d7f4e76efc938986674d24beebd1b4f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 14:28:47 2011 -0400
[coverity] not really necessary I don't think - seems like Bundle Manager Bean
closes the stream for us. but just in case...
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleFileUploadServlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleFileUploadServlet.java
index 71ff5f4..3081883 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleFileUploadServlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleFileUploadServlet.java
@@ -58,11 +58,14 @@ public class BundleFileUploadServlet extends FileUploadServlet {
String version = getFormField(formFields, "version",
Integer.toString(bundleVersionId));
Architecture architecture = new Architecture(getFormField(formFields,
"arch", "noarch"));
InputStream fileStream = new FileInputStream(file);
-
- BundleManagerLocal bundleManager = LookupUtil.getBundleManager();
- BundleFile bundleFile = bundleManager.addBundleFile(subject, bundleVersionId,
name, version, architecture,
- fileStream);
- successMsg = "success [" + bundleFile.getId() + "]";
+ try {
+ BundleManagerLocal bundleManager = LookupUtil.getBundleManager();
+ BundleFile bundleFile = bundleManager.addBundleFile(subject,
bundleVersionId, name, version,
+ architecture, fileStream);
+ successMsg = "success [" + bundleFile.getId() + "]";
+ } finally {
+ fileStream.close(); // I don't think this is necessary (seems
BundleManager closes it for us) but do it anyway just in case
+ }
} catch (Exception e) {
writeExceptionResponse(response, "Failed to upload bundle file",
e); // clients will look for this string!
return;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PackageVersionFileUploadServlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PackageVersionFileUploadServlet.java
index 9aed016..0795914 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PackageVersionFileUploadServlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PackageVersionFileUploadServlet.java
@@ -32,7 +32,6 @@ import javax.servlet.http.HttpServletResponse;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.enterprise.server.content.ContentManagerLocal;
-import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
/**
@@ -73,8 +72,6 @@ public class PackageVersionFileUploadServlet extends FileUploadServlet
{
if (repoIdS != null) {
repoId = Integer.parseInt(repoIdS);
}
-
- InputStream fileStream = new FileInputStream(file);
//use getUploadedPackageVersion instead of createPackageVersion here
//because createPackageVersion successfully returns an already existing
@@ -84,10 +81,15 @@ public class PackageVersionFileUploadServlet extends FileUploadServlet
{
Map<String, String> metaData = new HashMap<String, String>();
metaData.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
Long.toString(file.lastModified()));
metaData.put(ContentManagerLocal.UPLOAD_FILE_NAME, packageName);
- PackageVersion packageVersion =
contentManager.getUploadedPackageVersion(subject, packageName,
- packageTypeId, version, architectureId, fileStream, metaData, repoId);
-
- successMsg = "success [packageVersionId=" + packageVersion.getId()
+ ",packageId=" + packageVersion.getGeneralPackage().getId() + "]";
+ InputStream fileStream = new FileInputStream(file);
+ try {
+ PackageVersion packageVersion =
contentManager.getUploadedPackageVersion(subject, packageName,
+ packageTypeId, version, architectureId, fileStream, metaData,
repoId);
+ successMsg = "success [packageVersionId=" +
packageVersion.getId() + ",packageId="
+ + packageVersion.getGeneralPackage().getId() + "]";
+ } finally {
+ fileStream.close();
+ }
} catch (Exception e) {
writeExceptionResponse(response, "Failed to upload file", e); //
clients will look for this string!
return;
commit c59a821e4bc8ee18d19262f4c5887af6545eb5de
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 14:19:06 2011 -0400
[coverity] make sure we close the input stream
diff --git
a/modules/core/dbutils/src/main/java/org/rhq/core/db/ant/dbupgrade/DBUpgrader.java
b/modules/core/dbutils/src/main/java/org/rhq/core/db/ant/dbupgrade/DBUpgrader.java
index d4c055f..9a0c91b 100644
--- a/modules/core/dbutils/src/main/java/org/rhq/core/db/ant/dbupgrade/DBUpgrader.java
+++ b/modules/core/dbutils/src/main/java/org/rhq/core/db/ant/dbupgrade/DBUpgrader.java
@@ -20,6 +20,7 @@ package org.rhq.core.db.ant.dbupgrade;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -28,9 +29,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+
import mazz.i18n.Msg;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+
import org.rhq.core.db.DatabaseType;
import org.rhq.core.db.DatabaseTypeFactory;
import org.rhq.core.db.DbUtil;
@@ -70,16 +74,16 @@ public class DBUpgrader extends Task {
private Connection connection;
private boolean doCloseConnection;
-
+
public DBUpgrader() {
doCloseConnection = true;
}
-
+
public DBUpgrader(Connection connection) {
this.connection = connection;
doCloseConnection = false;
}
-
+
/**
* The URL to the database that is to be upgraded.
*
@@ -339,12 +343,20 @@ public class DBUpgrader extends Task {
if (typeMapFile == null) {
typeMaps = TypeMap.loadKnownTypeMaps();
} else {
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(typeMapFile);
+ fis = new FileInputStream(typeMapFile);
typeMaps = TypeMap.loadTypeMapsFromStream(fis);
} catch (Exception e) {
throw new
BuildException(MSG.getMsg(DbAntI18NResourceKeys.DBUPGRADE_TYPE_MAP_FILE_ERROR,
typeMapFile
.getAbsolutePath(), e), e);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ }
+ }
}
}
@@ -461,7 +473,7 @@ public class DBUpgrader extends Task {
if (connection == null) {
connection = DbUtil.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
}
- return connection;
+ return connection;
}
/**
@@ -474,7 +486,7 @@ public class DBUpgrader extends Task {
this.connection = connection;
doCloseConnection = connection == null;
}
-
+
/**
* Returns the type of database that is being upgraded.
*
commit fb8f4905912ba0bbc63d1aabc8dae84e10619b32
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 14:12:13 2011 -0400
[coverity] just a test class, but it should still close the stream to be a good
citizen
diff --git a/modules/core/util/src/test/java/org/rhq/core/util/ZipUtilTest.java
b/modules/core/util/src/test/java/org/rhq/core/util/ZipUtilTest.java
index 4bada6d..8ddcf1e 100644
--- a/modules/core/util/src/test/java/org/rhq/core/util/ZipUtilTest.java
+++ b/modules/core/util/src/test/java/org/rhq/core/util/ZipUtilTest.java
@@ -74,7 +74,9 @@ public class ZipUtilTest {
destFile.mkdirs();
} else {
destFile.getParentFile().mkdirs();
- StreamUtil.copy(stream, new FileOutputStream(destFile), false);
+ FileOutputStream fos = new FileOutputStream(destFile);
+ StreamUtil.copy(stream, fos, false);
+ fos.close();
}
return true;
}
commit 7db43fdbd624ec1227a1d7745b67b59f39a9fe1e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 14:07:38 2011 -0400
[coverity] paranoia - just make sure we always close the file stream, avoiding the
possibility that Buffered stream constructor bombs would leave the file stream open
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
index 25be7de..a9b07f2 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginClassLoader.java
@@ -205,21 +205,24 @@ public class PluginClassLoader extends URLClassLoader {
}
}
- BufferedOutputStream outputStream;
+ FileOutputStream fileOutputStream;
try {
- outputStream = new BufferedOutputStream(new
FileOutputStream(file));
+ fileOutputStream = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
if (file.exists() && (file.length() > 0)) {
// e.g. on win32, agent running w/ dll loaded
PluginDumper cannot overwrite file inuse.
continue;
}
-
throw ex;
}
+ BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
try {
file.deleteOnExit();
+ // do NOT close this inputStream since it is buffering the
ZipInputStream
+ // and we are going to still process that input stream later.
We close
+ // this ZipInputStream down below in the outer most
try-finally block.
BufferedInputStream inputStream = new
BufferedInputStream(zis);
int count;
@@ -229,13 +232,12 @@ public class PluginClassLoader extends URLClassLoader {
}
} finally {
outputStream.flush();
- outputStream.close();
+ outputStream.close(); // this also closes the
fileOutputStream
}
} catch (IOException ioe) {
if (file != null) {
file.delete();
}
-
throw ioe;
}
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
index fa26970..90e2117 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginClassLoader.java
@@ -133,37 +133,39 @@ public class ServerPluginClassLoader extends URLClassLoader {
}
}
- BufferedOutputStream outputStream;
+ FileOutputStream fileOutputStream;
try {
- outputStream = new BufferedOutputStream(new
FileOutputStream(file));
+ fileOutputStream = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
if (file.exists() && (file.length() > 0)) {
// e.g. on win32, agent running w/ dll loaded
PluginDumper cannot overwrite file inuse.
continue;
}
-
throw ex;
}
+ BufferedOutputStream outputStream = new
BufferedOutputStream(fileOutputStream);
try {
file.deleteOnExit();
+ // do NOT close this inputStream since it is buffering the
ZipInputStream
+ // and we are going to still process that input stream later.
We close
+ // this ZipInputStream down below in the outer most
try-finally block.
BufferedInputStream inputStream = new
BufferedInputStream(zis);
- int count = 0;
+ int count;
byte[] b = new byte[8192];
while ((count = inputStream.read(b)) > -1) {
outputStream.write(b, 0, count);
}
} finally {
outputStream.flush();
- outputStream.close();
+ outputStream.close(); // this also closes the
fileOutputStream
}
} catch (IOException ioe) {
if (file != null) {
file.delete();
}
-
throw ioe;
}
}
commit 2f53d69eccc94ffa068ed1483ca3d7d6db9d776e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 13:00:09 2011 -0400
opps, fix comment
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
index e2fc414..5697374 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
@@ -939,7 +939,7 @@ public class ServerCommunicationsService implements
ServerCommunicationsServiceM
return server_configuration;
} finally {
- // we know this isn't non-null; if it was, we would have thrown the
IOException earlier.
+ // we know this is not null; if it was, we would have thrown the IOException
earlier.
config_file_input_stream.close();
}
}
commit b09ab768bc1d84ab27476536237f28e09506387f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 12:58:59 2011 -0400
[coverity] close the config file input stream
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
index 29116d8..e2fc414 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/comm/ServerCommunicationsService.java
@@ -439,12 +439,12 @@ public class ServerCommunicationsService implements
ServerCommunicationsServiceM
try {
ClientCommandSenderConfiguration sender_config =
getSenderConfiguration(agent);
if (sender_config.commandSpoolFileName != null) {
- spool_file = new File(sender_config.dataDirectory,
sender_config.commandSpoolFileName);
- if (spool_file.exists()) {
- // first truncate it, in case Windows is locking it; then try to
delete
- new FileOutputStream(spool_file, false).close();
- spool_file.delete();
- }
+ spool_file = new File(sender_config.dataDirectory,
sender_config.commandSpoolFileName);
+ if (spool_file.exists()) {
+ // first truncate it, in case Windows is locking it; then try to
delete
+ new FileOutputStream(spool_file, false).close();
+ spool_file.delete();
+ }
}
} catch (Exception e) {
LOG.warn("Failed to truncate/delete spool for deleted agent ["
+ agent + "]"
@@ -907,36 +907,41 @@ public class ServerCommunicationsService implements
ServerCommunicationsServiceM
// But first we need to backup these original preferences in case the config file
fails to load -
// we'll restore the original values in that case.
- Preferences preferences_node = getPreferencesNode();
- ByteArrayOutputStream backup = new ByteArrayOutputStream();
- preferences_node.exportSubtree(backup);
- preferences_node.clear();
-
- // now load in the preferences
try {
- Preferences.importPreferences(config_file_input_stream);
+ Preferences preferences_node = getPreferencesNode();
+ ByteArrayOutputStream backup = new ByteArrayOutputStream();
+ preferences_node.exportSubtree(backup);
+ preferences_node.clear();
- if (new ServerConfiguration(preferences_node).getServerConfigurationVersion()
== 0) {
- throw new IllegalArgumentException(LOG.getMsgString(
- ServerI18NResourceKeys.BAD_NODE_NAME_IN_CONFIG_FILE, file_name,
preferences_node_name));
- }
- } catch (Exception e) {
- // a problem occurred importing the config file; let's restore our
original values
+ // now load in the preferences
try {
- Preferences.importPreferences(new
ByteArrayInputStream(backup.toByteArray()));
- } catch (Exception e1) {
- // its conceivable the same problem occurred here as with the original
exception (backing store problem?)
- // let's throw the original exception, not this one
- }
+ Preferences.importPreferences(config_file_input_stream);
- throw e;
- }
+ if (new
ServerConfiguration(preferences_node).getServerConfigurationVersion() == 0) {
+ throw new IllegalArgumentException(LOG.getMsgString(
+ ServerI18NResourceKeys.BAD_NODE_NAME_IN_CONFIG_FILE, file_name,
preferences_node_name));
+ }
+ } catch (Exception e) {
+ // a problem occurred importing the config file; let's restore our
original values
+ try {
+ Preferences.importPreferences(new
ByteArrayInputStream(backup.toByteArray()));
+ } catch (Exception e1) {
+ // its conceivable the same problem occurred here as with the
original exception (backing store problem?)
+ // let's throw the original exception, not this one
+ }
- ServerConfiguration server_configuration = new
ServerConfiguration(preferences_node);
+ throw e;
+ }
- LOG.debug(ServerI18NResourceKeys.LOADED_CONFIG_FILE, file_name);
+ ServerConfiguration server_configuration = new
ServerConfiguration(preferences_node);
- return server_configuration;
+ LOG.debug(ServerI18NResourceKeys.LOADED_CONFIG_FILE, file_name);
+
+ return server_configuration;
+ } finally {
+ // we know this isn't non-null; if it was, we would have thrown the
IOException earlier.
+ config_file_input_stream.close();
+ }
}
/**
commit 4b3e3a6e01e2f599af8a21a14c37debc92060cc1
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 12:37:04 2011 -0400
[coverity] close the context - no need to keep it open since we just create it to see
that no exceptions occurred.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CustomJaasDeploymentService.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CustomJaasDeploymentService.java
index be7a0ab..a4124ca 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CustomJaasDeploymentService.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CustomJaasDeploymentService.java
@@ -209,7 +209,7 @@ public class CustomJaasDeploymentService implements
CustomJaasDeploymentServiceM
}
log.debug("Validating LDAP with environment=" + env);
- new InitialLdapContext(env, null);
+ new InitialLdapContext(env, null).close();
return;
}
commit 0329aa66eaea0e3a53b4c7682e9e49d3a28d0750
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 12:17:21 2011 -0400
[coverity] make sure to close the file
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 7a8e1e5..ea5e7fd 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
@@ -103,8 +103,9 @@ public class InventoryFile {
* inventory
*/
public void loadInventory() throws PluginContainerException {
+ FileInputStream fis = null;
try {
- FileInputStream fis = new FileInputStream(inventoryFile);
+ fis = new FileInputStream(inventoryFile);
ObjectInputStream ois = new ObjectInputStream(fis);
// this list will contain UUIDs of resources that we should ignore usually
due to disabled plugins
@@ -126,6 +127,13 @@ public class InventoryFile {
return;
} catch (Exception e) {
throw new PluginContainerException("Cannot load inventory file: " +
inventoryFile, e);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ }
}
}
commit 203bb4b9b7d4107d7332754709b6bc9ec5851771
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 12:12:05 2011 -0400
[coverity] make sure we close the printwriter in finally block
diff --git
a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/YumServer.java
b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/YumServer.java
index dc92a61..3524b9b 100644
---
a/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/YumServer.java
+++
b/modules/plugins/platform/src/main/java/org/rhq/plugins/platform/content/yum/YumServer.java
@@ -178,15 +178,18 @@ public class YumServer {
File file = new File(yumconf);
try {
PrintWriter writer = new PrintWriter(file);
- writer.println("[rhq]");
- writer.println("name=RHQ");
- writer.printf("baseurl=%s\n", context.baseurl());
- writer.printf("metadata_expire=%d\n",
context.getMetadataCacheTimeout());
- writer.println("enabled=1");
- writer.println("gpgcheck=0");
- writer.println("keepalive=0");
- writer.println("timeout=90");
- writer.close();
+ try {
+ writer.println("[rhq]");
+ writer.println("name=RHQ");
+ writer.printf("baseurl=%s\n", context.baseurl());
+ writer.printf("metadata_expire=%d\n",
context.getMetadataCacheTimeout());
+ writer.println("enabled=1");
+ writer.println("gpgcheck=0");
+ writer.println("keepalive=0");
+ writer.println("timeout=90");
+ } finally {
+ writer.close();
+ }
} catch (Exception e) {
String msg = "The yum repo configuration file '" + file +
"' could not be created/updated!";
log.error(msg, e);
commit 3a558fe5559b55707cb861e72a3d307a6a24b2a6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 11:42:07 2011 -0400
[coverity] this should have been an assert - and if it was, this unit test would have
failed only because the casting was incorrect.
the code it was testing actually worked. I'm fixing the test so this actually
asserts the correct thing.
diff --git
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/ExtensionModelTest.java
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/ExtensionModelTest.java
index 3d9fb10..06fc087 100644
---
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/ExtensionModelTest.java
+++
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/ExtensionModelTest.java
@@ -37,6 +37,7 @@ import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
import org.rhq.core.clientapi.descriptor.DescriptorPackages;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
@@ -130,7 +131,9 @@ public class ExtensionModelTest {
assert !def1.isRequired();
assert def1 instanceof PropertyDefinitionSimple;
assert ((PropertyDefinitionSimple)
def1).getType().equals(PropertySimpleType.BOOLEAN);
-
def1.getConfigurationDefinition().getDefaultTemplate().getConfiguration().get("force").equals("false");
+ PropertySimple prop = (PropertySimple)
def1.getConfigurationDefinition().getDefaultTemplate()
+ .getConfiguration().get("force");
+ assert prop.getBooleanValue().booleanValue() == false;
assert stopOp.getResultsConfigurationDefinition() != null;
ConfigurationDefinition results = stopOp.getResultsConfigurationDefinition();
commit d85516841d7bead784f587535c1364d47185b7a9
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 11:23:34 2011 -0400
[coverity] the if-stmt looks bad, but anyway, this handler doesn't do anything
anyway, the main code inside it was commented out.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/SearchBar.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/SearchBar.java
index cce560c..007f908 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/SearchBar.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/search/SearchBar.java
@@ -38,9 +38,6 @@ import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.Event.NativePreviewEvent;
-import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
@@ -129,17 +126,23 @@ public class SearchBar extends AbstractSearchBar {
String searchButtonId =
searchBarElement.getAttribute("searchButtonId");
searchButton = DOM.getElementById(searchButtonId);
- Event.addNativePreviewHandler(new NativePreviewHandler() {
- public void onPreviewNativeEvent(NativePreviewEvent event) {
- if (event.getNativeEvent() != null &&
event.getNativeEvent().getEventTarget() != null) {
-
- if (event.getNativeEvent().getEventTarget().equals(searchButton)
- && event.getTypeInt() == Event.ONMOUSEDOWN) {
- //prepareSearchExecution();
- }
- }
- }
- });
+ // Don't know what this originally was going to be used for, but if you
notice,
+ // after all the if-stmts are evaluated true, the only piece of code to be
invoked
+ // (prepareSearchExecution()) has been commented out. So this is a no-op. In
addition
+ // the second if-stmt (getEventTarget().equals(searchButton) doesn't look
correct and
+ // may not ever evaluate to true anyway. Commenting this out, in case something
like this
+ // is needed in the future, but we'll havee to probably fix that if-stmt
first.
+
+ // Event.addNativePreviewHandler(new NativePreviewHandler() {
+ // public void onPreviewNativeEvent(NativePreviewEvent event) {
+ // if (event.getNativeEvent() != null &&
event.getNativeEvent().getEventTarget() != null) {
+ // if
(event.getNativeEvent().getEventTarget().equals(searchButton)
+ // && event.getTypeInt() == Event.ONMOUSEDOWN) {
+ // //prepareSearchExecution();
+ // }
+ // }
+ // }
+ // });
String searchSubsystem =
searchBarElement.getAttribute("searchSubsystem");
setSearchSubsystem(SearchSubsystem.valueOf(searchSubsystem.toUpperCase()));
commit e7bcd08184a293f0fa745e4fe8a1167dd552bb68
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 11:15:21 2011 -0400
[coverity] fix NPE
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
index 71f5ec5..047f5af 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/AbstractTwoLevelTabSetView.java
@@ -296,7 +296,8 @@ public abstract class AbstractTwoLevelTabSetView<T, U extends
Layout> extends Lo
SubTab subTab = tab.getDefaultSubTab();
if (subTab == null || tab.getLayout().isSubTabDisabled(subTab)) {
-
CoreGUI.getErrorHandler().handleError(MSG.view_tabs_invalidSubTab(subTab.getName()));
+ CoreGUI.getErrorHandler().handleError(
+ MSG.view_tabs_invalidSubTab((subTab != null ? subTab.getName() :
"null")));
subTab = tab.getLayout().getDefaultSubTab();
}
commit 4120c6b83a25a6b52c44e8e5a6fa528989f8c4a5
Merge: 447cd29 c8dc1d8
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Jul 14 11:46:34 2011 +0200
Merge branch 'master' into code-smell
diff --cc modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
index e84d7d4,be0446b..d21ab62
--- a/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
@@@ -23,9 -23,10 +23,11 @@@
package org.rhq.core.util.stream;
import java.io.BufferedInputStream;
+ import java.io.BufferedReader;
+ import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
commit 447cd29b3c4d39c80fabc990096807353544d258
Merge: f7aa5f5 32b8223
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Dec 2 10:54:48 2010 +0100
Merge branch 'master' into code-smell
diff --cc modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
index 3eb1c6b,b57c65b..e4d7575
--- a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
+++ b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
@@@ -30,16 -27,16 +27,17 @@@ import org.rhq.core.pluginapi.inventory
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.plugins.database.DatabaseComponent;
+ import java.io.File;
+ import java.io.FileReader;
import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+ import java.sql.Statement;
import java.util.HashMap;
+ import java.util.List;
import java.util.Map;
import java.util.Set;
diff --cc
modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
index 2ada67b,30b65f2..c4ada90
---
a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
+++
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
@@@ -28,10 -28,8 +28,9 @@@ import org.rhq.core.pluginapi.inventory
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.core.pluginapi.inventory.ManualAddFacet;
import org.rhq.core.system.ProcessInfo;
+import org.rhq.core.util.jdbc.JDBCUtil;
import java.sql.Connection;
- import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.LinkedHashSet;
import java.util.List;
@@@ -82,59 -79,53 +80,53 @@@ public class MySqlDiscoveryComponent im
}
protected static DiscoveredResourceDetails
createResourceDetails(ResourceDiscoveryContext discoveryContext,
- Configuration pluginConfiguration, ProcessInfo processInfo) {
-
- String key = buildUrl(pluginConfiguration);
- String db =
pluginConfiguration.getSimple(DB_CONFIGURATION_PROPERTY).getStringValue();
- String name = "MySql [" + db + "]";
- try {
- String version = getVersion(pluginConfiguration);
- return new DiscoveredResourceDetails(discoveryContext.getResourceType(),
key, name, version,
- DEFAULT_RESOURCE_DESCRIPTION, pluginConfiguration, processInfo);
- } catch (Exception e) {
- log.warn("Getting details failed: " + e.getMessage());
- if (e.getCause()!=null) {
- log.warn(" caused by: " + e.getCause().getMessage());
- }
- }
- return null;
- }
+ Configuration pluginConfiguration,
+ ProcessInfo processInfo) throws InvalidPluginConfigurationException {
- protected static String buildUrl(Configuration config) {
- String host = config.getSimple(HOST_CONFIGURATION_PROPERTY).getStringValue();
- String port = config.getSimple(PORT_CONFIGURATION_PROPERTY).getStringValue();
- String user =
config.getSimple(PRINCIPAL_CONFIGURATION_PROPERTY).getStringValue();
- String pass =
config.getSimple(CREDENTIALS_CONFIGURATION_PROPERTY).getStringValue();
- String url = "jdbc:mysql://" + host + "?user=" + user +
"&password=" + pass;
- return url;
- }
-
- protected static String getVersion(Configuration config) {
- String version = null;
- Connection conn = null;
+ MySqlConnectionInfo ci = buildConnectionInfo(pluginConfiguration);
+ Connection conn;
+ String version = "";
try {
- conn = buildConnection(config);
+ conn = MySqlConnectionManager.getConnectionManager().getConnection(ci);
version = conn.getMetaData().getDatabaseProductVersion();
- } catch (SQLException e) {
- // TODO GH: How to put this back to the server while inventorying this
resource in an unconfigured state
- log.info("Exception detecting mysql instance version" +
e.getMessage());
- } finally {
- JDBCUtil.safeClose(conn);
+ } catch (SQLException ex) {
+ // ignore so we can still add to the inventory even though we can't
currently connect
}
- return version;
- }
+ String key = new StringBuilder().append("MySql:")
+ .append(ci.getDb())
+ .append(":")
+ .append(ci.getHost())
+ .append(":")
+ .append(ci.getPort())
+ .append("-")
+ .append(ci.getUser()).toString();
+ String name = new StringBuilder().append("MySql [")
+ .append(ci.getDb())
+ .append("]").toString();
+
+ DiscoveredResourceDetails result = new DiscoveredResourceDetails(
+ discoveryContext.getResourceType(),
+ key,
+ name,
+ version,
+ "MySql Server",
+ pluginConfiguration,
+ processInfo);
- public static Connection buildConnection(Configuration configuration) throws
SQLException {
- String driverClass =
configuration.getSimple(DRIVER_CONFIGURATION_PROPERTY).getStringValue();
- try {
- Class.forName(driverClass);
- } catch (ClassNotFoundException e) {
- throw new InvalidPluginConfigurationException("Specified JDBC driver
class (" + driverClass
- + ") not found.");
+ if (log.isDebugEnabled()) {
+ log.debug("Discovered Database Server for MySQL Database " +
ci.buildURL());
}
+ return result;
- String url = buildUrl(configuration);
-
- return DriverManager.getConnection(url);
}
+
+ static MySqlConnectionInfo buildConnectionInfo(Configuration configuration) {
+ // build the Discovered Resource from the configuration
+ String host =
configuration.getSimple(HOST_CONFIGURATION_PROPERTY).getStringValue();
+ String port =
configuration.getSimple(PORT_CONFIGURATION_PROPERTY).getStringValue();
+ String user =
configuration.getSimple(PRINCIPAL_CONFIGURATION_PROPERTY).getStringValue();
+ String pass =
configuration.getSimple(CREDENTIALS_CONFIGURATION_PROPERTY).getStringValue();
+ String db =
configuration.getSimple(DB_CONFIGURATION_PROPERTY).getStringValue();
+ return new MySqlConnectionInfo(host, port, db, user, pass);
+ }
-}
+}
commit f7aa5f57e02fb94389c33ac5b22bcef222488bc7
Merge: 077dd3d 08566cc
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Oct 13 11:16:45 2010 +0200
Merge branch 'master' into code-smell
diff --cc modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
index 4034184,bc1fc64..484d591
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
@@@ -87,10 -87,12 +87,12 @@@ public class Props
private Set<Template> templates = new HashSet<Template>();
- private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();;
+ private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();
- private Set<OperationProps> operations = new
LinkedHashSet<OperationProps>();;
+ private Set<OperationProps> operations = new
LinkedHashSet<OperationProps>();
+ private Set<TypeKey> runsInsides = new LinkedHashSet<TypeKey>();;
+
private String pluginName;
private String pluginDescription;
commit 077dd3d75a5782dd4c775b47a64e80b0cfd38311
Merge: 8970684 e5fac0a
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Sep 14 18:08:59 2010 +0200
Merge branch 'master' into code-smell
commit 89706849030f5d35d65189b7cc6e8fd75da403d2
Merge: 271474d fb4f6c2
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Sep 3 11:02:19 2010 +0200
Merge branch 'master' into code-smell
commit 271474dd691b04cc01106d83baee292cfd6689a2
Merge: 4d5b070 66234db
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 24 18:10:33 2010 +0200
Merge branch 'master' into code-smell
diff --cc
modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
index ba0ea81,4f1045e..2ada67b
---
a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
+++
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
@@@ -106,9 -115,7 +117,9 @@@ public class MySqlDiscoveryComponent im
version = conn.getMetaData().getDatabaseProductVersion();
} catch (SQLException e) {
// TODO GH: How to put this back to the server while inventorying this
resource in an unconfigured state
- log.info("Exception detecting mysql instance version", e);
+ log.info("Exception detecting mysql instance version" +
e.getMessage());
+ } finally {
+ JDBCUtil.safeClose(conn);
}
return version;
}
@@@ -126,4 -133,4 +137,4 @@@
return DriverManager.getConnection(url);
}
--}
++}
commit 4d5b070e7e77d53f32d93ee9788e52e1ff5b509f
Merge: 88faac6 462e15f
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 20 12:46:56 2010 +0200
Merge branch 'master' into code-smell
commit 88faac6a30c0282e08d2b0d7d19d6d019a0504c3
Merge: 2c7c7fc 1c5c441
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Aug 16 12:19:04 2010 +0200
Merge branch 'master' into code-smell
commit 2c7c7fc3aa949bbfebdefaaa4a0688a95bbeede8
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 15:21:25 2010 +0200
Be defensive about the existence of HTTP Date header.
diff --git
a/modules/plugins/netservices/src/main/java/org/rhq/plugins/netservices/HTTPNetServiceComponent.java
b/modules/plugins/netservices/src/main/java/org/rhq/plugins/netservices/HTTPNetServiceComponent.java
index 85b19ad..54d9256 100644
---
a/modules/plugins/netservices/src/main/java/org/rhq/plugins/netservices/HTTPNetServiceComponent.java
+++
b/modules/plugins/netservices/src/main/java/org/rhq/plugins/netservices/HTTPNetServiceComponent.java
@@ -24,6 +24,7 @@ import java.util.Date;
import java.util.Locale;
import java.util.Set;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.logging.Log;
@@ -114,7 +115,8 @@ public class HTTPNetServiceComponent implements ResourceComponent,
MeasurementFa
// TODO: may need to allow plugin to configure the locale, but for this fixed
string, make sure we
// ignore default locale, this works for english.
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss
zzz", Locale.ENGLISH);
- Date contentDate =
sdf.parse(method.getResponseHeader("Date").getValue());
+ Header dateHeader = method.getResponseHeader("Date");
+ Date contentDate = dateHeader == null ? new Date(System.currentTimeMillis())
: sdf.parse(dateHeader.getValue());
// System.out.println("Success: " + success);
// System.out.println("Response: " + responseCode);
commit c033ec0a86a394f0caeda7081ed9c3fbd77ac524
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 15:16:53 2010 +0200
Fail gracefully if we cannot determine the deployment descriptor file of the mbean
during the resource configuration update.
diff --git
a/modules/plugins/jboss-cache/src/main/java/org/rhq/plugins/jbosscache/JBossCacheComponent.java
b/modules/plugins/jboss-cache/src/main/java/org/rhq/plugins/jbosscache/JBossCacheComponent.java
index 34c3ffc..daa7cdb 100644
---
a/modules/plugins/jboss-cache/src/main/java/org/rhq/plugins/jbosscache/JBossCacheComponent.java
+++
b/modules/plugins/jboss-cache/src/main/java/org/rhq/plugins/jbosscache/JBossCacheComponent.java
@@ -281,6 +281,12 @@ public class JBossCacheComponent implements
ResourceComponent<JMXComponent>, Mea
String mbeanName = context.getResourceKey();
File file = DeploymentUtility.getDescriptorFile(parentServer.getEmsConnection(),
mbeanName);
+ if (file == null) {
+ report.setStatus(ConfigurationUpdateStatus.FAILURE);
+ report.setErrorMessage("Failed to determine the deployment descriptor
file for mbean '" + mbeanName + "'.");
+ return;
+ }
+
CacheConfigurationHelper helper = new CacheConfigurationHelper();
try {
helper.writeConfig(file, newOne, mbeanName, true);
commit 6334d8b4fbb3e77b3ce607cd3191406ad85cc348
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 15:06:07 2010 +0200
Paranoidly prevent NPE if a set of rules changed between avail checks of the parent
BytemanScriptComponent.
diff --git
a/modules/plugins/byteman/src/main/java/org/rhq/plugins/byteman/BytemanRuleComponent.java
b/modules/plugins/byteman/src/main/java/org/rhq/plugins/byteman/BytemanRuleComponent.java
index 09f7213..189eb47 100644
---
a/modules/plugins/byteman/src/main/java/org/rhq/plugins/byteman/BytemanRuleComponent.java
+++
b/modules/plugins/byteman/src/main/java/org/rhq/plugins/byteman/BytemanRuleComponent.java
@@ -36,7 +36,7 @@ public class BytemanRuleComponent implements
ResourceComponent<BytemanScriptComp
List<String> rules =
this.resourceContext.getParentResourceComponent().getRules();
for (String rule : rules) {
String ruleName = client.determineRuleName(rule);
- if (ruleName.equals(ourKey)) {
+ if (ourKey.equals(ruleName)) {
return AvailabilityType.UP;
}
}
commit ac1418991c901faed1397c7a9016d226316855a0
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 15:00:54 2010 +0200
Make sure to close the stream (this will paranoidly close the buffered output stream
instead just the file output stream that is wrapped by it).
diff --git
a/modules/plugins/rhq-agent/src/main/java/org/rhq/plugins/agent/AgentSnapshotReport.java
b/modules/plugins/rhq-agent/src/main/java/org/rhq/plugins/agent/AgentSnapshotReport.java
index f2fb4b3..cd92575 100644
---
a/modules/plugins/rhq-agent/src/main/java/org/rhq/plugins/agent/AgentSnapshotReport.java
+++
b/modules/plugins/rhq-agent/src/main/java/org/rhq/plugins/agent/AgentSnapshotReport.java
@@ -21,6 +21,7 @@ package org.rhq.plugins.agent;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.OutputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
@@ -29,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.util.SnapshotReport;
+import org.rhq.core.util.stream.StreamUtil;
/**
* Performs some slight customizations of the snapshot report utility such as taking a
snapshot of the live
@@ -82,11 +84,12 @@ public class AgentSnapshotReport extends SnapshotReport {
try {
File configDir = new File(this.agentInstallDir, "conf");
File liveConfigFile = new File(configDir,
"live-agent-configuration.properties");
- FileOutputStream fos = new FileOutputStream(liveConfigFile);
+ OutputStream fos = null;
try {
- this.agentConfiguration.store(new BufferedOutputStream(fos), null);
+ fos = new BufferedOutputStream(new FileOutputStream(liveConfigFile));
+ this.agentConfiguration.store(fos, null);
} finally {
- fos.close();
+ StreamUtil.safeClose(fos);
}
return liveConfigFile;
} catch (Exception e) {
commit 8869c018b39935049b924b1d7273fcb15663b7b9
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:54:40 2010 +0200
Prevent an NPE if all aliases would be removed from a tomcat vhost.
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
index e8d6e8b..2746c5b 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatVHostComponent.java
@@ -159,11 +159,10 @@ public class TomcatVHostComponent extends
MBeanResourceComponent<TomcatServerCom
String currentValsLongString = currentVals.getStringValue();
String newValsLongString = newVals.getStringValue();
StringTokenizer tokenizer = null;
- Configuration opConfig = null;
+ Configuration opConfig = new Configuration();
if (null != newValsLongString) {
tokenizer = new StringTokenizer(newValsLongString, "\n");
- opConfig = new Configuration();
while (tokenizer.hasMoreTokens()) {
String newVal = tokenizer.nextToken().trim();
if ((null == currentValsLongString) ||
!currentValsLongString.contains(newVal)) {
commit f270fe5702392360cc2ab6710f2e4f528f6ab4b3
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:53:00 2010 +0200
Prevent an NPE when the user was removed from all groups or roles during resource
configuration update.
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatUserComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatUserComponent.java
index 52efaac..24936cd 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatUserComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatUserComponent.java
@@ -162,11 +162,10 @@ public class TomcatUserComponent extends
MBeanResourceComponent<TomcatUserDataba
String currentValsLongString = currentVals.getStringValue();
String newValsLongString = newVals.getStringValue();
StringTokenizer tokenizer = null;
- Configuration opConfig = null;
+ Configuration opConfig = new Configuration();
if (null != newValsLongString) {
tokenizer = new StringTokenizer(newValsLongString, "\n");
- opConfig = new Configuration();
while (tokenizer.hasMoreTokens()) {
String newVal = tokenizer.nextToken().trim();
if ((null == currentValsLongString) ||
!currentValsLongString.contains(newVal)) {
commit d6a394514a81cab7a2912d5f0d183b7b958d84ea
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:50:40 2010 +0200
Prevent an NPE in case all the roles were removed from the tomcat group.
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatGroupComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatGroupComponent.java
index 89b2ce2..1d667a7 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatGroupComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatGroupComponent.java
@@ -141,11 +141,10 @@ public class TomcatGroupComponent extends
MBeanResourceComponent<TomcatUserDatab
String currentValsLongString = currentVals.getStringValue();
String newValsLongString = newVals.getStringValue();
StringTokenizer tokenizer = null;
- Configuration opConfig = null;
+ Configuration opConfig = new Configuration();
if (null != newValsLongString) {
tokenizer = new StringTokenizer(newValsLongString, "\n");
- opConfig = new Configuration();
while (tokenizer.hasMoreTokens()) {
String newVal = tokenizer.nextToken().trim();
if ((null == currentValsLongString) ||
!currentValsLongString.contains(newVal)) {
commit 48f7788fa29d437b791f28625c233e87c5e2b811
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:48:16 2010 +0200
Be paranoid about File.getParentFile()
diff --git
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDiscoveryComponent.java
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDiscoveryComponent.java
index 3007520..fc0e681 100644
---
a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDiscoveryComponent.java
+++
b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDiscoveryComponent.java
@@ -341,8 +341,17 @@ public class TomcatDiscoveryComponent implements
ResourceDiscoveryComponent, Man
private String determineCatalinaHomeOnWindows(ProcessInfo processInfo) {
File exePath = new File(processInfo.getName());
+
File parentDir = exePath.getParentFile();
+ if (parentDir == null) { //paranoia
+ return null;
+ }
+
File ewsDir = parentDir.getParentFile();
+ if (ewsDir == null) { //paranoia
+ return null;
+ }
+
File tomcatDir = new File(ewsDir, "share/apache-tomcat-6.0.24");
if (tomcatDir.exists()) {
commit dd633d1e56712671a496952dd6f04fae21bada07
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:36:32 2010 +0200
Throw a specific exception if failed to parse virt domain xml.
diff --git
a/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/VirtualizationDomainComponent.java
b/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/VirtualizationDomainComponent.java
index a67d5c3..adc75a6 100644
---
a/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/VirtualizationDomainComponent.java
+++
b/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/VirtualizationDomainComponent.java
@@ -159,6 +159,11 @@ public class VirtualizationDomainComponent implements
ResourceComponent<Virtuali
String xml = virt.getDomainXML(this.domainName);
Configuration oldConfig = loadResourceConfiguration();
+
+ if (oldConfig == null) {
+ throw new IllegalStateException("Failed to parse the XML
specification for domain '" + domainName + "'.");
+ }
+
Configuration newConfig = report.getConfiguration();
String newXml = XMLEditor.updateDomainXML(report.getConfiguration(), xml);
commit 8ad726302d19649136d25783b23555431de16db2
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 14:07:50 2010 +0200
Be paranoid about free()ing the libvirt objects, throw IllegalArgumentException if
domain/network of some name cannot be found instead of just blindly throwing an NPE later
in the workflow.
diff --git
a/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/LibVirtConnection.java
b/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/LibVirtConnection.java
index 6b16328..b1f578e 100644
--- a/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/LibVirtConnection.java
+++ b/modules/plugins/virt/src/main/java/org/rhq/plugins/virt/LibVirtConnection.java
@@ -114,15 +114,17 @@ public class LibVirtConnection {
public DomainInfo getDomainInfo(String domainName) throws LibvirtException {
try {
- Domain domain = connection.domainLookupByName(domainName);
-
- DomainInfo info = new DomainInfo();
- info.domainInfo = domain.getInfo();
- info.name = domainName;
- info.uuid = domain.getUUIDString();
- domain.free();
-
- return info;
+ Domain domain = getDomain(domainName);
+ try {
+ DomainInfo info = new DomainInfo();
+ info.domainInfo = domain.getInfo();
+ info.name = domainName;
+ info.uuid = domain.getUUIDString();
+
+ return info;
+ } finally {
+ domain.free();
+ }
} catch (LibvirtException e) {
log.error("Error looking up domain with name " + domainName, e);
throw e;
@@ -132,14 +134,19 @@ public class LibVirtConnection {
public DomainInfo getDomainInfo(int id) throws LibvirtException {
try {
Domain domain = connection.domainLookupByID(id);
-
- DomainInfo info = new DomainInfo();
- info.domainInfo = domain.getInfo();
- info.name = domain.getName();
- info.uuid = domain.getUUIDString();
- domain.free();
-
- return info;
+ if (domain == null) {
+ throw new IllegalArgumentException("No domain found with ID: "
+ id);
+ }
+ try {
+ DomainInfo info = new DomainInfo();
+ info.domainInfo = domain.getInfo();
+ info.name = domain.getName();
+ info.uuid = domain.getUUIDString();
+
+ return info;
+ } finally {
+ domain.free();
+ }
} catch (LibvirtException e) {
log.error("Error looking up domain with id " + id, e);
throw e;
@@ -147,18 +154,22 @@ public class LibVirtConnection {
}
public String getDomainXML(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- String returnValue = domain.getXMLDesc(0);
- domain.free();
-
- return returnValue;
+ Domain domain = getDomain(domainName);
+ try {
+ return domain.getXMLDesc(0);
+ } finally {
+ domain.free();
+ }
}
public int domainReboot(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.reboot(0);
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.reboot(0);
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainRestore(String toPath) throws LibvirtException {
@@ -167,57 +178,79 @@ public class LibVirtConnection {
}
public int domainDestroy(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.destroy();
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.destroy();
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainDelete(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- DomainState state = domain.getInfo().state;
-
- if ((state != DomainState.VIR_DOMAIN_SHUTDOWN) && (state !=
DomainState.VIR_DOMAIN_SHUTOFF)) {
- domain.destroy();
+ Domain domain = getDomain(domainName);
+ try {
+ DomainState state = domain.getInfo().state;
+
+ if ((state != DomainState.VIR_DOMAIN_SHUTDOWN) && (state !=
DomainState.VIR_DOMAIN_SHUTOFF)) {
+ domain.destroy();
+ }
+ domain.undefine();
+
+ return SUCCESS;
+ } finally {
+ domain.free();
}
- domain.undefine();
- domain.free();
- return SUCCESS;
}
public int domainSave(String domainName, String toPath) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.save(toPath);
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.save(toPath);
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainResume(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.resume();
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.resume();
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainShutdown(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.shutdown();
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.shutdown();
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainSuspend(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.suspend();
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.suspend();
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public int domainCreate(String domainName) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.create();
- domain.free();
- return SUCCESS;
+ Domain domain = getDomain(domainName);
+ try {
+ domain.create();
+ return SUCCESS;
+ } finally {
+ domain.free();
+ }
}
public boolean defineDomain(String xml) throws LibvirtException {
@@ -230,35 +263,48 @@ public class LibVirtConnection {
}
public void setMaxMemory(String domainName, long size) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.setMaxMemory(size);
- domain.free();
+ Domain domain = getDomain(domainName);
+ try {
+ domain.setMaxMemory(size);
+ } finally {
+ domain.free();
+ }
}
public void setMemory(String domainName, long size) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.setMemory(size);
- domain.free();
+ Domain domain = getDomain(domainName);
+ try {
+ domain.setMemory(size);
+ } finally {
+ domain.free();
+ }
}
public void setVcpus(String domainName, int count) throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- domain.setVcpus(count);
- domain.free();
+ Domain domain = getDomain(domainName);
+ try {
+ domain.setVcpus(count);
+ } finally {
+ domain.free();
+ }
}
public DomainInterfaceStats getDomainInterfaceStats(String domainName, String path)
throws LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- DomainInterfaceStats returnValue = domain.interfaceStats(path);
- domain.free();
- return returnValue;
+ Domain domain = getDomain(domainName);
+ try {
+ return domain.interfaceStats(path);
+ } finally {
+ domain.free();
+ }
}
public DomainBlockStats getDomainBlockStats(String domainName, String path) throws
LibvirtException {
- Domain domain = connection.domainLookupByName(domainName);
- DomainBlockStats returnValue = domain.blockStats(path);
- domain.free();
- return returnValue;
+ Domain domain = getDomain(domainName);
+ try {
+ return domain.blockStats(path);
+ } finally {
+ domain.free();
+ }
}
public int close() throws LibvirtException {
@@ -275,7 +321,10 @@ public class LibVirtConnection {
double usedMemory = 0;
for (int id : connection.listDomains()) {
Domain domain = connection.domainLookupByID(id);
- usedMemory += domain.getInfo().memory;
+ if (domain != null) {
+ usedMemory += domain.getInfo().memory;
+ domain.free();
+ }
}
return usedMemory / memory;
}
@@ -284,8 +333,10 @@ public class LibVirtConnection {
long cpuTime = 0;
for (int id : connection.listDomains()) {
Domain domain = connection.domainLookupByID(id);
- cpuTime += domain.getInfo().cpuTime;
- domain.free();
+ if (domain != null) {
+ cpuTime += domain.getInfo().cpuTime;
+ domain.free();
+ }
}
return cpuTime;
}
@@ -321,28 +372,37 @@ public class LibVirtConnection {
return getNetworks().contains(name);
}
- //TODO NEED TO ADD A NETWORK OBJECT AND FREE THE LIBVIRT ONE
public NetworkInfo getNetwork(String name) throws LibvirtException {
- NetworkInfo info = new NetworkInfo();
- Network net = connection.networkLookupByName(name);
- info.name = net.getName();
- info.autostart = net.getAutostart();
- info.bridgeName = net.getBridgeName();
- return info;
+ Network net = getLibVirtNetwork(name);
+
+ try {
+ NetworkInfo info = new NetworkInfo();
+ info.name = net.getName();
+ info.autostart = net.getAutostart();
+ info.bridgeName = net.getBridgeName();
+ return info;
+ } finally {
+ net.free();
+ }
}
public String getNetworkXML(String name) throws LibvirtException {
- Network network = connection.networkLookupByName(name);
- String returnValue = network.getXMLDesc(0);
- network.free();
- return returnValue;
+ Network network = getLibVirtNetwork(name);
+ try {
+ return network.getXMLDesc(0);
+ } finally {
+ network.free();
+ }
}
public void updateNetwork(String name, String xml, boolean autostart) throws
LibvirtException {
connection.networkDefineXML(xml);
- Network network = connection.networkLookupByName(name);
- network.setAutostart(autostart);
- network.free();
+ Network network = getLibVirtNetwork(name);
+ try {
+ network.setAutostart(autostart);
+ } finally {
+ network.free();
+ }
}
public static class DomainInfo {
@@ -385,10 +445,26 @@ public class LibVirtConnection {
System.out.println(conn.connection.domainLookupByName(foo).getXMLDesc(0));
}
}
+
+ private Domain getDomain(String domainName) throws LibvirtException,
IllegalArgumentException {
+ Domain ret = connection.domainLookupByName(domainName);
+ if (ret == null) {
+ throw new IllegalArgumentException("Could not find a domain called
'" + domainName + "'.");
+ }
+
+ return ret;
+ }
+
+ private Network getLibVirtNetwork(String networkName) throws LibvirtException,
IllegalArgumentException {
+ Network ret = connection.networkLookupByName(networkName);
+ if (ret == null) {
+ throw new IllegalArgumentException("Could not find a netword called
'" + networkName + "'.");
+ }
+
+ return ret;
+ }
}
-//TODO Put the callbacks in
-/* Comment this out untilt he callbacks get in*/
class Logger extends org.libvirt.ErrorCallback {
// Make this static so the callback will always have an object
commit 1a666b2c5cd1e942d8f568c041ac2f678421050b
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Aug 13 12:20:05 2010 +0200
Removed needless null check.
diff --git
a/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
b/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
index 475195a..38f1b02 100644
---
a/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
+++
b/modules/plugins/script/src/main/java/org/rhq/plugins/script/ScriptServerComponent.java
@@ -336,12 +336,8 @@ public class ScriptServerComponent implements ResourceComponent,
MeasurementFace
ProcessExecutionResults results = executeExecutable(sysInfo, pluginConfig, args,
wait, captureOutput);
if (log.isDebugEnabled()) {
- if (results != null) {
- logDebug("CLI results: exitcode=[" + results.getExitCode() +
"]; error=[" + results.getError()
- + "]; output=" +
truncateString(results.getCapturedOutput()));
- } else {
- logDebug("CLI has null results");
- }
+ logDebug("CLI results: exitcode=[" + results.getExitCode() +
"]; error=[" + results.getError()
+ + "]; output=" + truncateString(results.getCapturedOutput()));
}
return results;
commit b9f07c09436a548434acfd6855662d54d33bf866
Merge: c8fb8b3 910702a
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Aug 12 15:30:40 2010 +0200
Merge branch 'master' into code-smell
commit c8fb8b3652d6b32e880b52913dd2280ab157eb57
Merge: 2638f27 f1365e5
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Aug 12 15:18:05 2010 +0200
Merge branch 'code-smell' of
ssh://git.fedorahosted.org/git/rhq/rhq into
code-smell
commit f1365e541a2ba19357abfa063333dc9901f6d786
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Aug 12 12:24:08 2010 +0200
12644 prevent NPE
diff --git
a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java
b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java
index 6830f5f..16d6c89 100644
---
a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java
+++
b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/PerfTestDiscoveryComponent.java
@@ -18,6 +18,7 @@
*/
package org.rhq.plugins.perftest;
+import java.util.Collections;
import java.util.Set;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.resource.ResourceType;
@@ -44,6 +45,9 @@ public class PerfTestDiscoveryComponent implements
ResourceDiscoveryComponent {
Set<DiscoveredResourceDetails> resourceDetails = null;
if (manager.isEnabled()) {
ResourceFactory resourceFactory =
manager.getResourceFactory(resourceType.getName());
+ if (resourceFactory==null)
+ return Collections.emptySet();
+
resourceDetails = resourceFactory.discoverResources(context);
// If there is a plugin configuration factory defined, run it on each
resource
diff --git
a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java
b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java
index d9aabf9..1eb831d 100644
---
a/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java
+++
b/modules/plugins/perftest/src/main/java/org/rhq/plugins/perftest/ScenarioManager.java
@@ -310,6 +310,7 @@ public class ScenarioManager {
return new SimpleResourceFactory((SimpleResourceGenerator) generator);
}
+ log.warn("No factory for generator " + generator.toString() + "
specified");
return null;
}
commit 391f9be4637842049cc01e90d7bce1b4ce54e86f
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Aug 12 12:02:58 2010 +0200
Fix some potential NPE and resource leakage
diff --git
a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
index 69587d0..17a6818 100644
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/PluginGen.java
@@ -61,37 +61,49 @@ public class PluginGen {
public void run() throws Exception {
+ Props props = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ try {
- Props props = askQuestions(br, new Props());
- if (props == null) {
- // abort by user
- return;
- }
+ props = askQuestions(br, new Props());
+ if (props == null) {
+ // abort by user
+ return;
+ }
+
+ boolean done = false;
+ do {
- boolean done = false;
- do {
-
- System.out.println();
- System.out.print("Do you want to add a child to " + props.getName()
+ "? (y/N) ");
- String answer = br.readLine();
- answer = answer.toLowerCase(Locale.getDefault());
- if (answer.startsWith("n") || answer.length() == 0)
- done = true;
- else {
- Props child = askQuestions(br, props);
- if (child == null) {
- // abort by user
- return;
+ System.out.println();
+ System.out.print("Do you want to add a child to " +
props.getName() + "? (y/N) ");
+ String answer = br.readLine();
+ if (answer==null) {
+ break;
+ }
+ answer = answer.toLowerCase(Locale.getDefault());
+ if (answer.startsWith("n") || answer.length() == 0)
+ done = true;
+ else {
+ Props child = askQuestions(br, props);
+ if (child == null) {
+ // abort by user
+ return;
+ }
+ props.getChildren().add(child);
}
- props.getChildren().add(child);
- }
- } while (!done);
+ } while (!done);
+ } catch (IOException ioe) {
+ System.err.println("Internal error happended: " +
ioe.getMessage());
+ } finally {
+ br.close();
+ }
- log.info("\nYou have choosen:\n" + props.toString());
- postprocess(props);
- generate(props);
+ if (props!=null) {
+ log.info("\nYou have chosen:\n" + props.toString());
+ postprocess(props);
+ generate(props);
+ }
System.out.println("Don't forget to ");
System.out.println(" - add your plugin to the parent pom.xml if
needed");
@@ -345,11 +357,15 @@ public class PluginGen {
Template templ = config.getTemplate(template + ".ftl");
Writer out = new BufferedWriter(new FileWriter(new File(directory,
fileName)));
- Map<String, Props> root = new HashMap<String, Props>();
- root.put("props", props);
- templ.process(root, out);
- out.flush();
- out.close();
+ try {
+ Map<String, Props> root = new HashMap<String, Props>();
+ root.put("props", props);
+ templ.process(root, out);
+ }
+ finally {
+ out.flush();
+ out.close();
+ }
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (TemplateException te) {
diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
index a657f42..4034184 100644
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
@@ -87,9 +87,9 @@ public class Props {
private Set<Template> templates = new HashSet<Template>();
- private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();;
+ private Set<MetricProps> metrics = new LinkedHashSet<MetricProps>();
- private Set<OperationProps> operations = new
LinkedHashSet<OperationProps>();;
+ private Set<OperationProps> operations = new
LinkedHashSet<OperationProps>();
private String pluginName;
private String pluginDescription;
diff --git
a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java
b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java
index 566af60..911ed41 100644
---
a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java
+++
b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/ResourceCategory.java
@@ -77,7 +77,7 @@ public enum ResourceCategory {
public static ResourceCategory getByAbbrv(char abbrev) {
EnumSet<ResourceCategory> set = EnumSet.allOf(ResourceCategory.class);
for (ResourceCategory cat : set) {
- if (cat.getAbbrev()==abbrev)
+ if (cat.abbrevLetter ==abbrev)
return cat;
}
return null;
commit 2638f279d22aebb3e5ebcad5f7bd17c3d873b33b
Merge: aef5cf2 a13c17d
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Aug 11 15:02:32 2010 +0200
Merge branch 'master' into code-smell
commit aef5cf286fc08b16273a54022ecb0f48f19d9b44
Merge: ac90dbd a5187a8
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 18:11:10 2010 +0200
Merge branch 'master' into code-smell
commit ac90dbd66d849db6dc7d4d82e595cf44cf58b5c0
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 18:02:45 2010 +0200
Trivial - code formatting.
diff --git
a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
index 1821eed..b805ea9 100644
---
a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
+++
b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
@@ -37,27 +37,29 @@ import org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent;
public class SambaServerDiscoveryComponent extends AugeasConfigurationDiscoveryComponent
{
- private static final Pattern netBiosNamePattern =
Pattern.compile("[\\s]*netbios[\\s]*name[\\s]*=[\\s]*(.*)[\\s]*");
-
- public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext)
throws InvalidPluginConfigurationException, Exception {
+ private static final Pattern NET_BIOS_NAME_PATTERN = Pattern
+ .compile("[\\s]*netbios[\\s]*name[\\s]*=[\\s]*(.*)[\\s]*");
+
+ public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
Set<DiscoveredResourceDetails> resources =
super.discoverResources(resourceDiscoveryContext);
- for (DiscoveredResourceDetails detail : resources){
+ for (DiscoveredResourceDetails detail : resources) {
Configuration config = detail.getPluginConfiguration();
PropertySimple property = (PropertySimple)
config.get(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
String configFilePath = property.getStringValue();
String resourceName;
-
+
try {
- resourceName = findNetBiosName(configFilePath);
- }catch(Exception e){
- resourceName =
resourceDiscoveryContext.getSystemInformation().getHostname();
+ resourceName = findNetBiosName(configFilePath);
+ } catch (Exception e) {
+ resourceName =
resourceDiscoveryContext.getSystemInformation().getHostname();
}
detail.setResourceName(resourceName);
}
return resources;
}
-
- private String findNetBiosName(String includeFile) throws Exception{
+
+ private String findNetBiosName(String includeFile) throws Exception {
try {
File file = new File(includeFile);
if (file.exists()) {
@@ -66,21 +68,20 @@ public class SambaServerDiscoveryComponent extends
AugeasConfigurationDiscoveryC
try {
String strLine;
while ((strLine = br.readLine()) != null) {
- Matcher m = netBiosNamePattern.matcher(strLine);
+ Matcher m = NET_BIOS_NAME_PATTERN.matcher(strLine);
if (m.matches()) {
String glob = m.group(1);
-
- return glob;
- }
+
+ return glob;
+ }
}
} finally {
StreamUtil.safeClose(br);
}
}
- }
- catch (Exception e) {
- throw new Exception("NetBios name was not found in configuration file
"+ includeFile + " cause:",e);
+ } catch (Exception e) {
+ throw new Exception("NetBios name was not found in configuration file
" + includeFile + " cause:", e);
}
- throw new Exception("NetBios name was not found in configuration file
"+ includeFile);
+ throw new Exception("NetBios name was not found in configuration file "
+ includeFile);
}
}
commit 892927807a251621668c91bbf18e07e05c8037bd
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 18:00:39 2010 +0200
Close the stream.
diff --git
a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
index b53c006..1821eed 100644
---
a/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
+++
b/modules/plugins/samba/src/main/java/org/rhq/plugins/samba/SambaServerDiscoveryComponent.java
@@ -31,6 +31,7 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.core.util.stream.StreamUtil;
import org.rhq.plugins.augeas.AugeasConfigurationComponent;
import org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent;
@@ -62,16 +63,19 @@ public class SambaServerDiscoveryComponent extends
AugeasConfigurationDiscoveryC
if (file.exists()) {
FileInputStream fstream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- while ((strLine = br.readLine()) != null) {
- Matcher m = netBiosNamePattern.matcher(strLine);
- if (m.matches()) {
- String glob = m.group(1);
-
- return glob;
- }
+ try {
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ Matcher m = netBiosNamePattern.matcher(strLine);
+ if (m.matches()) {
+ String glob = m.group(1);
+
+ return glob;
+ }
+ }
+ } finally {
+ StreamUtil.safeClose(br);
}
- br.close();
}
}
catch (Exception e) {
commit e6e41cf77ad3cd48cb50abb74b56952c289fa49c
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 17:57:09 2010 +0200
Unnecessarily getting a value twice.
diff --git
a/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java
b/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java
index af3280a..6312c4d 100644
---
a/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java
+++
b/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java
@@ -151,7 +151,8 @@ public class PostgresUserComponent implements
DatabaseComponent<PostgresServerCo
+ " ";
if (type != UpdateType.DROP) {
- if (config.getSimpleValue("password",null) != null &&
config.getSimpleValue("password",null).length() != 0) {
+ String password = config.getSimpleValue("password",null);
+ if (password != null && password.length() != 0) {
sql += " WITH PASSWORD '" +
config.getSimpleValue("password",null) + "' ";
}
commit 75e16e1459f6e2d7f1725189be63f2439a91ec3a
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 17:56:14 2010 +0200
Make sure to close the JDBC connection.
diff --git
a/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresDiscoveryComponent.java
b/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresDiscoveryComponent.java
index b02d764..b03327d 100644
---
a/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresDiscoveryComponent.java
+++
b/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresDiscoveryComponent.java
@@ -298,7 +298,12 @@ public class PostgresDiscoveryComponent implements
ResourceDiscoveryComponent, M
}
public static List<String> getDatabases(Configuration pluginConfiguration) {
- return getDatabaseNames(pluginConfiguration,
getConnection(pluginConfiguration));
+ Connection conn = getConnection(pluginConfiguration);
+ try {
+ return getDatabaseNames(pluginConfiguration, conn);
+ } finally {
+ JDBCUtil.safeClose(conn);
+ }
}
private static List<String> getDatabaseNames(Configuration config, Connection
conn) {
commit dfa063dcb426f7ba05cfd3923c603b9d33e4dbf4
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 17:46:45 2010 +0200
Trivial - code formatting.
diff --git
a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
index 49172bd..91490c0 100644
---
a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
+++
b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
@@ -37,27 +37,28 @@ import java.util.regex.Pattern;
public class PostfixServerDiscoveryComponent extends
AugeasConfigurationDiscoveryComponent {
- private static final Pattern hostNamePattern =
Pattern.compile("[\\s]*myhostname[\\s]*=[\\s]*([^$].*)[\\s]*");
-
- public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext)
throws InvalidPluginConfigurationException, Exception {
+ private static final Pattern HOSTNAME_PATTERN =
Pattern.compile("[\\s]*myhostname[\\s]*=[\\s]*([^$].*)[\\s]*");
+
+ public Set discoverResources(ResourceDiscoveryContext resourceDiscoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
Set<DiscoveredResourceDetails> resources =
super.discoverResources(resourceDiscoveryContext);
- for (DiscoveredResourceDetails detail : resources){
+ for (DiscoveredResourceDetails detail : resources) {
Configuration config = detail.getPluginConfiguration();
PropertySimple property = (PropertySimple)
config.get(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
String configFilePath = property.getStringValue();
String resourceName;
-
+
try {
- resourceName = findHostName(configFilePath);
- }catch(Exception e){
- resourceName =
resourceDiscoveryContext.getSystemInformation().getHostname();
+ resourceName = findHostName(configFilePath);
+ } catch (Exception e) {
+ resourceName =
resourceDiscoveryContext.getSystemInformation().getHostname();
}
detail.setResourceName(resourceName);
}
return resources;
}
-
- private String findHostName(String includeFile) throws Exception{
+
+ private String findHostName(String includeFile) throws Exception {
try {
File file = new File(includeFile);
if (file.exists()) {
@@ -66,21 +67,20 @@ public class PostfixServerDiscoveryComponent extends
AugeasConfigurationDiscover
try {
String strLine;
while ((strLine = br.readLine()) != null) {
- Matcher m = hostNamePattern.matcher(strLine);
+ Matcher m = HOSTNAME_PATTERN.matcher(strLine);
if (m.matches()) {
String glob = m.group(1);
-
- return glob;
- }
+
+ return glob;
+ }
}
} finally {
StreamUtil.safeClose(br);
}
}
- }
- catch (Exception e) {
- throw new Exception("NetBios name was not found in configuration file
"+ includeFile + " cause:",e);
+ } catch (Exception e) {
+ throw new Exception("NetBios name was not found in configuration file
" + includeFile + " cause:", e);
}
- throw new Exception("NetBios name was not found in configuration file
"+ includeFile);
+ throw new Exception("NetBios name was not found in configuration file "
+ includeFile);
}
}
commit e13bce0c0d7a0d84a6afbfc5c7c04586f306329a
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 17:37:40 2010 +0200
Close the stream.
diff --git
a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
index 8f26ee0..49172bd 100644
---
a/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
+++
b/modules/plugins/postfix/src/main/java/org/rhq/plugins/postfix/PostfixServerDiscoveryComponent.java
@@ -23,6 +23,7 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.core.util.stream.StreamUtil;
import org.rhq.plugins.augeas.AugeasConfigurationComponent;
import org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent;
@@ -62,16 +63,19 @@ public class PostfixServerDiscoveryComponent extends
AugeasConfigurationDiscover
if (file.exists()) {
FileInputStream fstream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- while ((strLine = br.readLine()) != null) {
- Matcher m = hostNamePattern.matcher(strLine);
- if (m.matches()) {
- String glob = m.group(1);
-
- return glob;
- }
+ try {
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ Matcher m = hostNamePattern.matcher(strLine);
+ if (m.matches()) {
+ String glob = m.group(1);
+
+ return glob;
+ }
+ }
+ } finally {
+ StreamUtil.safeClose(br);
}
- br.close();
}
}
catch (Exception e) {
commit 86b070e80ddf96df954e976613464d7af120a977
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 16:42:19 2010 +0200
Make sure to not fail when close() method of a stream throws an exception.
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
index 08303c8..6bee4b2 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
@@ -26,6 +26,7 @@ import java.io.FileInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import org.jbpm.graph.exe.ExecutionContext;
+import org.rhq.core.util.stream.StreamUtil;
/**
* @author Jason Dobies
@@ -115,9 +116,7 @@ public class CompareDigestActionHandler extends BaseHandler {
while (in.read(buffer) != -1) {
}
} finally {
- if (in != null) {
- in.close();
- }
+ StreamUtil.safeClose(in);
}
String digest = HandlerUtils.encode(messageDigest.digest());
commit 41a3463a600a4014ed650d96c9fbd604dd4e8ba5
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 16:38:49 2010 +0200
Adding a utility method for safely closing streams.
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
b/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
index e970b83..e84d7d4 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/stream/StreamUtil.java
@@ -25,6 +25,7 @@ package org.rhq.core.util.stream;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@@ -245,4 +246,19 @@ public class StreamUtil {
return retObject;
}
+
+ /**
+ * Can be used to safely close a stream. No-op if the stream is null.
+ *
+ * @param stream the stream to close or null
+ */
+ public static void safeClose(Closeable stream) {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ LOG.error("Failed to close a stream.", e);
+ }
+ }
+ }
}
\ No newline at end of file
commit fe93c191577091c0f45b11e80d5aba28084f7fb5
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 16:27:43 2010 +0200
Added missing import (how come I missed this?)
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
index 7f6dbae..a3f1963 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
@@ -22,6 +22,7 @@
*/
package com.jboss.jbossnetwork.product.jbpm.handlers;
+import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
commit 0597c8e2ddafd88f7c0c9d2c25f81f1f461739f4
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 15:34:10 2010 +0200
Close the connections in the test code and in the discovery.
diff --git a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
index e3da0aa..f89344a 100644
--- a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
+++ b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlComponent.java
@@ -28,6 +28,7 @@ import
org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.plugins.database.DatabaseComponent;
import java.sql.Connection;
@@ -116,10 +117,11 @@ public class MySqlComponent implements DatabaseComponent,
ResourceComponent, Mea
public static void main(String[] args) throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
+ Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection conn =
+ conn =
DriverManager.getConnection("jdbc:mysql://192.168.1.5?user=rhqadmin&password=rhqadmin");
DatabaseMetaData dmd = conn.getMetaData();
@@ -149,6 +151,8 @@ public class MySqlComponent implements DatabaseComponent,
ResourceComponent, Mea
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
+ } finally {
+ JDBCUtil.safeClose(conn);
}
}
}
diff --git
a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
index f50fbc0..ba0ea81 100644
---
a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
+++
b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java
@@ -28,6 +28,7 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.core.pluginapi.inventory.ManualAddFacet;
import org.rhq.core.system.ProcessInfo;
+import org.rhq.core.util.jdbc.JDBCUtil;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -99,12 +100,15 @@ public class MySqlDiscoveryComponent implements
ResourceDiscoveryComponent, Manu
protected static String getVersion(Configuration config) {
String version = null;
+ Connection conn = null;
try {
- Connection conn = buildConnection(config);
+ conn = buildConnection(config);
version = conn.getMetaData().getDatabaseProductVersion();
} catch (SQLException e) {
// TODO GH: How to put this back to the server while inventorying this
resource in an unconfigured state
log.info("Exception detecting mysql instance version", e);
+ } finally {
+ JDBCUtil.safeClose(conn);
}
return version;
}
commit 20460165a99b1f2e92cc6033e7fb3dc158984ef4
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 15:27:11 2010 +0200
Close the connection when done with it during the discovery.
diff --git
a/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleDiscoveryComponent.java
b/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleDiscoveryComponent.java
index 2340f0b..79d67fd 100644
---
a/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleDiscoveryComponent.java
+++
b/modules/plugins/oracle/src/main/java/org/rhq/plugins/oracle/OracleDiscoveryComponent.java
@@ -35,6 +35,7 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.core.pluginapi.inventory.ManualAddFacet;
import org.rhq.core.system.ProcessInfo;
+import org.rhq.core.util.jdbc.JDBCUtil;
/**
@@ -75,8 +76,10 @@ public class OracleDiscoveryComponent implements
ResourceDiscoveryComponent, Man
public DiscoveredResourceDetails discoverResource(Configuration pluginConfig,
ResourceDiscoveryContext
resourceDiscoveryContext)
throws InvalidPluginConfigurationException {
+
+ Connection connection = null;
try {
- Connection connection = OracleServerComponent.buildConnection(pluginConfig);
+ connection = OracleServerComponent.buildConnection(pluginConfig);
DatabaseMetaData dbmd = connection.getMetaData();
String version = dbmd.getDatabaseMajorVersion() + "." +
dbmd.getDatabaseMinorVersion();
DiscoveredResourceDetails details =
createResourceDetails(resourceDiscoveryContext, pluginConfig,
@@ -85,6 +88,8 @@ public class OracleDiscoveryComponent implements
ResourceDiscoveryComponent, Man
} catch (Exception e) {
log.warn("Could not connect to oracle with supplied configuration",
e);
throw new InvalidPluginConfigurationException("Unable to connect to
Oracle",e);
+ } finally {
+ JDBCUtil.safeClose(connection);
}
}
commit cb19eacae48d2e2c0d47b761191dd11ef103c2cd
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 14:52:23 2010 +0200
Removing unused obsolete testing code.
diff --git
a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISServerDiscoveryComponent.java
b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISServerDiscoveryComponent.java
index f4cbceb..4e276a3 100644
---
a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISServerDiscoveryComponent.java
+++
b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISServerDiscoveryComponent.java
@@ -83,8 +83,4 @@ public class IISServerDiscoveryComponent implements
ResourceDiscoveryComponent {
return Collections.singleton(details);
}
-
- public static void main(String[] args) throws Exception {
- new IISServerDiscoveryComponent().discoverResources(null);
- }
}
diff --git
a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostDiscoveryComponent.java
b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostDiscoveryComponent.java
index a6fc8a1..0cd5cd8 100644
---
a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostDiscoveryComponent.java
+++
b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostDiscoveryComponent.java
@@ -93,8 +93,4 @@ public class IISVHostDiscoveryComponent implements
ResourceDiscoveryComponent<II
return hostDetails;
}
-
- public static void main(String[] args) throws Exception {
- new IISVHostDiscoveryComponent().discoverResources(null);
- }
}
commit be16929be8cdd15b30d9e2ac98ee6efa2a68cbe0
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 14:51:52 2010 +0200
Preventing NPE in case of invalid plugin configuration.
diff --git a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostComponent.java
b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostComponent.java
index 692dbb8..9d264b9 100644
--- a/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostComponent.java
+++ b/modules/plugins/iis/src/main/java/org/rhq/plugins/iis/IISVHostComponent.java
@@ -56,6 +56,10 @@ public class IISVHostComponent implements
ResourceComponent<IISServerComponent>,
String logFormat = getResponseTimeLogFormat();
ResponseTimeConfiguration responseTimeConfiguration =
getResponseTimeConfiguration();
+ if (logFormat == null) {
+ throw new InvalidPluginConfigurationException("The
'responseTimeLogFormat' property must be specified.");
+ }
+
responseTimeDelegate = new IISResponseTimeDelegate(logDirectory, logFormat,
responseTimeConfiguration
/*,collectionTZ.equals("true")*/);
}
commit 4ea9b298ddf1e5bf36567265e040c894d074fa92
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 14:05:31 2010 +0200
Avoid an NPE when the component is not properly configured.
diff --git
a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableComponent.java
b/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableComponent.java
index 0c7a5a5..f8ddcd8 100644
---
a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableComponent.java
+++
b/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableComponent.java
@@ -23,10 +23,14 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
@@ -40,6 +44,8 @@ import org.rhq.core.util.jdbc.JDBCUtil;
public class CustomTableComponent implements DatabaseComponent<DatabaseComponent>,
MeasurementFacet {
private ResourceContext<DatabaseComponent> context;
+ private static final Log log = LogFactory.getLog(CustomTableComponent.class);
+
public void start(ResourceContext<DatabaseComponent> resourceContext) throws
InvalidPluginConfigurationException,
Exception {
this.context = resourceContext;
@@ -67,7 +73,15 @@ public class CustomTableComponent implements
DatabaseComponent<DatabaseComponent
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest>
metrics) throws Exception {
String query =
this.context.getPluginConfiguration().getSimpleValue("metricQuery", null);
-
+
+ if (query == null) {
+ ResourceType type = this.context.getResourceType();
+ String resourceKey = this.context.getResourceKey();
+ log.info("Resource " + resourceKey + " (" +
type.getName() + ", plugin " + type.getPlugin()
+ + "): The plugin configuration doesn't specify
'metricQuery' property. Ignoring the measurement request.");
+ return;
+ }
+
query = CustomTableRowDiscoveryComponent.formatMessage(query,
this.context.getPluginConfiguration().getSimpleValue("key",null));
Map<String, Double> values =
DatabaseQueryUtility.getNumericQueryValues(this, query);
commit 029f0c7abe2743f33460a4be96e1fc1814cce917
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 12:35:22 2010 +0200
Making sure resource name is specified in the plugin config and that null description
doesn't blow up the discovery.
diff --git
a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
b/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
index aaf2e67..4b40d86 100644
---
a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
+++
b/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
@@ -53,8 +53,12 @@ public class CustomTableRowDiscoveryComponent implements
ResourceDiscoveryCompon
String table = config.getSimpleValue("table", null);
String keyColumn = config.getSimpleValue("keyColumn", null);
String resourceName = config.getSimpleValue("name", null);
- String resourceDescription = config.getSimpleValue("description",
null);
+ String resourceDescription = config.getSimpleValue("description",
"");
+ if (resourceName == null) {
+ throw new InvalidPluginConfigurationException("The 'name'
connection property has to be specified.");
+ }
+
statement = conn.createStatement();
resultSet = statement.executeQuery("SELECT * FROM " + table);
commit cc86e651f9c850356dbfa82a42ee821948440ab8
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 11:54:25 2010 +0200
Make sure to close the stream.
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
index 1f6d9c5..08303c8 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/CompareDigestActionHandler.java
@@ -107,12 +107,19 @@ public class CompareDigestActionHandler extends BaseHandler {
private String calculateDigest() throws Exception {
MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
- DigestInputStream in = new DigestInputStream(new
FileInputStream(fileToBeCheckedLocation), messageDigest);
-
- byte[] buffer = new byte[4096];
- while (in.read(buffer) != -1) {
+ DigestInputStream in = null;
+
+ try {
+ in = new DigestInputStream(new FileInputStream(fileToBeCheckedLocation),
messageDigest);
+ byte[] buffer = new byte[4096];
+ while (in.read(buffer) != -1) {
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
}
-
+
String digest = HandlerUtils.encode(messageDigest.digest());
return digest;
}
commit 8a9fd618e4f6a47a97da77a23e30437093861610
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 11:40:31 2010 +0200
Fix possible null dereference.
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
index 48a2674..7f6dbae 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/SetProcessStatusActionHandler.java
@@ -37,7 +37,10 @@ public class SetProcessStatusActionHandler implements ActionHandler {
private Boolean status;
public void execute(ExecutionContext executionContext) {
- executionContext.getContextInstance().setVariable("processStatus",
status);
+ ContextInstance instance = executionContext.getContextInstance();
+ if (instance != null) {
+ instance.setVariable("processStatus", status);
+ }
}
public Boolean getStatus() {
commit bff8c9db80f86d9696f8ddc57756ee9782d2a8e2
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Aug 10 11:09:49 2010 +0200
Fixing possible null parent path dereference.
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/BackupAndReplaceFileActionHandler.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/BackupAndReplaceFileActionHandler.java
index 00d6a65..da5b5b2 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/BackupAndReplaceFileActionHandler.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/BackupAndReplaceFileActionHandler.java
@@ -155,9 +155,11 @@ public class BackupAndReplaceFileActionHandler extends BaseHandler {
if (!replacementFilename.equalsIgnoreCase(originalFilename)) {
// This file name can't be relative since we need its parent in the next
step
HandlerUtils.checkFilenameIsAbsolute(originalFileLocation);
-
- File destinationFile = new File(originalFile.getParentFile().getPath() +
File.separator
- + replacementFilename);
+
+ //check that there is a parent
+ File parent = HandlerUtils.checkAndReturnParent(originalFileLocation);
+
+ File destinationFile = new File(parent, replacementFilename);
setDestinationFileLocation(destinationFile.getPath());
// Make sure the newly generated file name isn't going to clash with an
existing file
diff --git
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/HandlerUtils.java
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/HandlerUtils.java
index ae5293b..50d802c 100644
---
a/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/HandlerUtils.java
+++
b/modules/common/jboss-as/src/main/java/com/jboss/jbossnetwork/product/jbpm/handlers/HandlerUtils.java
@@ -142,6 +142,15 @@ public class HandlerUtils {
}
}
+ public static File checkAndReturnParent(String filename) throws
ActionHandlerException {
+ File parent = getFile(filename).getParentFile();
+ if (parent == null) {
+ throw new ActionHandlerException("Cannot access parent directory of
[" + formatPath(filename) + "].");
+ }
+
+ return parent;
+ }
+
private static File getFile(String filename) throws ActionHandlerException {
return new File(filename);
}