modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
| 10 +
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
| 3
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
| 69 ++++------
3 files changed, 41 insertions(+), 41 deletions(-)
New commits:
commit db608e3eeb24f87078e5008f563ce1f334c99457
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Thu Mar 29 11:03:12 2012 -0400
bugfix: homeDir was being used in a couple places where baseDir should have been used;
use the PropertiesFileUpdate utility to update the mgmt users props file; minor: add a
constant for the char encoding in PropertiesFileUpdate
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
b/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
index 2389268..595fda2 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/PropertiesFileUpdate.java
@@ -47,6 +47,9 @@ import java.util.Properties;
* @author John Mazzitelli
*/
public class PropertiesFileUpdate {
+
+ private static final String CHAR_ENCODING_8859_1 = "8859_1";
+
private File file;
/**
@@ -80,7 +83,7 @@ public class PropertiesFileUpdate {
if (!existingProps.containsKey(key)) {
FileOutputStream fos = new FileOutputStream(file, true);
try {
- PrintStream ps = new PrintStream(fos, true, "8859_1");
+ PrintStream ps = new PrintStream(fos, true, CHAR_ENCODING_8859_1);
try {
ps.println(key + "=" + value);
} finally {
@@ -127,8 +130,8 @@ public class PropertiesFileUpdate {
// Now go line-by-line in the properties file, updating property values as we go
along.
// When we get to the end of the existing file, append any new props that
didn't exist before.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream out = new PrintStream(baos, true, "8859_1");
- InputStreamReader isr = new InputStreamReader(new FileInputStream(file),
"8859_1");
+ PrintStream out = new PrintStream(baos, true, CHAR_ENCODING_8859_1);
+ InputStreamReader isr = new InputStreamReader(new FileInputStream(file),
CHAR_ENCODING_8859_1);
BufferedReader in = new BufferedReader(isr);
for (String line = in.readLine(); line != null; line = in.readLine()) {
@@ -210,4 +213,5 @@ public class PropertiesFileUpdate {
return ((start > 0) || (end < str.length())) ? str.substring(start, end) :
str;
}
+
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index 67f70cd..4b421c4 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
@@ -117,7 +117,7 @@ public abstract class BaseProcessDiscovery extends
AbstractBaseDiscovery
pluginConfig.put(new PropertySimple("configDir", configDir));
pluginConfig.put(new PropertySimple("startScript",
getMode().getStartScript()));
pluginConfig.put(new PropertySimple("domainHost",
findHost(getHostXmlFile(process, configDir))));
- fillUserPassFromFile(pluginConfig, getMode(), homeDir);
+ fillUserPassFromFile(pluginConfig, getMode(), baseDir);
File logFile = getLogFile(getLogDir(process, baseDir));
initLogEventSourcesConfigProp(logFile.getPath(), pluginConfig);
HostPort managementHostPort = getManagementPortFromHostXml(commandLine);
@@ -317,7 +317,6 @@ public abstract class BaseProcessDiscovery extends
AbstractBaseDiscovery
}
private void fillUserPassFromFile(Configuration config, AS7Mode mode, File baseDir)
{
- // String configDir = baseDir + File.separator + mode + File.separator +
"configuration";
String realm = getManagementSecurityRealmFromHostXml();
String fileName = getSecurityPropertyFileFromHostXml(baseDir, mode, realm);
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
index bdf8a66..68a78c0 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
@@ -19,11 +19,7 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.net.ConnectException;
-import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
@@ -47,6 +43,7 @@ import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.ProcessExecutionUtility;
import org.rhq.core.system.ProcessExecution;
import org.rhq.core.system.ProcessExecutionResults;
+import org.rhq.core.util.PropertiesFileUpdate;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
import org.rhq.modules.plugins.jbossas7.json.Operation;
@@ -74,7 +71,7 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
* @throws Exception If anything goes wrong
*/
protected OperationResult restartServer(Configuration parameters, AS7Mode mode)
throws Exception {
- OperationResult tmp = invokeOperation("shutdown",parameters);
+ OperationResult tmp = invokeOperation("shutdown", parameters);
if (tmp.getErrorMessage()!=null) {
tmp.setErrorMessage("Restart failed while failing to shut down: " +
tmp.getErrorMessage());
@@ -116,12 +113,12 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
protected OperationResult startServer(AS7Mode mode) {
OperationResult operationResult = new OperationResult();
String startScript = pluginConfiguration.getSimpleValue("startScript",
mode.getStartScript());
- String baseDir =
pluginConfiguration.getSimpleValue("baseDir","");
- if (baseDir.isEmpty()) {
- operationResult.setErrorMessage("No base directory provided");
+ String homeDir = pluginConfiguration.getSimpleValue("homeDir",
"");
+ if (homeDir.isEmpty()) {
+ operationResult.setErrorMessage("No home directory provided.");
return operationResult;
}
- String script = baseDir + File.separator + startScript;
+ String script = homeDir + File.separator + startScript;
ProcessExecution processExecution;
processExecution = ProcessExecutionUtility.createProcessExecution(new
File("/bin/sh"));
@@ -148,7 +145,7 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
}
}
- processExecution.setWorkingDirectory(baseDir);
+ processExecution.setWorkingDirectory(homeDir);
processExecution.setCaptureOutput(true);
processExecution.setWaitForCompletion(15000L); // 15 seconds // TODO: Should we
wait longer than 15 seconds?
processExecution.setKillOnTimeout(false);
@@ -274,12 +271,12 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
return result;
}
- String homeDirString = pluginConfig.getSimpleValue("homeDir",
"");
- if (homeDirString.isEmpty()) {
- result.setErrorMessage("No homeDir found - cannot continue.");
+ String baseDirString = pluginConfig.getSimpleValue("baseDir",
"");
+ if (baseDirString.isEmpty()) {
+ result.setErrorMessage("No baseDir found - cannot continue.");
return result;
}
- File homeDir = new File(homeDirString);
+ File baseDir = new File(baseDirString);
String configFile;
BaseProcessDiscovery processDiscovery;
@@ -298,30 +295,31 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
processDiscovery.readStandaloneOrHostXmlFromFile(configFile);
String realm = pluginConfig.getSimpleValue("realm",
"ManagementRealm");
- String propertiesFilePath =
processDiscovery.getSecurityPropertyFileFromHostXml(homeDir, mode, realm);
+ String propertiesFilePath =
processDiscovery.getSecurityPropertyFileFromHostXml(baseDir, mode, realm);
- Properties p = new Properties();
+ String encryptedPassword;
try {
- UsernamePasswordHashUtil util = new UsernamePasswordHashUtil();
- String value = util.generateHashedHexURP(user, realm,
password.toCharArray());
-
- FileInputStream fis = new FileInputStream(propertiesFilePath);
- p.load(fis);
- fis.close();
- p.setProperty(user,value);
- FileOutputStream fos = new FileOutputStream(propertiesFilePath);
- p.store(fos,null);
- fos.flush();
- fos.close();
- } catch (IOException e) {
- log.error(e.getMessage());
- result.setErrorMessage(e.getMessage());
- } catch (NoSuchAlgorithmException nsae) {
- log.error(nsae.getMessage());
- result.setErrorMessage(nsae.getMessage());
+ UsernamePasswordHashUtil hashUtil = new UsernamePasswordHashUtil();
+ encryptedPassword = hashUtil.generateHashedHexURP(user, realm,
password.toCharArray());
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to encrypt password.", e);
}
- result.setSimpleResult("Management user [" + user + "] added or
updated.");
- log.info("Added or updated management user [" + user +
"].");
+
+ boolean userAlreadyExisted;
+ try {
+ PropertiesFileUpdate propsFileUpdate = new
PropertiesFileUpdate(propertiesFilePath);
+ Properties existingProps = propsFileUpdate.loadExistingProperties();
+ userAlreadyExisted = existingProps.containsKey(user);
+ propsFileUpdate.update(user, encryptedPassword);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to update management users properties
file [" + propertiesFilePath
+ + "].", e);
+ }
+
+ String verb = (userAlreadyExisted) ? "updated" : "added";
+ result.setSimpleResult("Management user [" + user + "] " +
verb + ".");
+ log.info("Management user [" + user + "] " + verb + "
for " + context.getResourceType().getName()
+ + " server with key [" + context.getResourceKey() +
"].");
context.getAvailabilityContext().requestAvailabilityCheck();
@@ -329,7 +327,6 @@ public class BaseServerComponent extends BaseComponent implements
MeasurementFac
}
public void getValues(MeasurementReport report, Set metrics) throws Exception {
-
Set<MeasurementScheduleRequest> requests = metrics;
Set<MeasurementScheduleRequest> leftovers = new
HashSet<MeasurementScheduleRequest>(requests.size());