modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
| 138 ++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
| 129 +---
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
| 8
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HostControllerComponent.java
| 36 -
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
| 64 +-
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AbstractConfigurationHandlingTest.java
| 35 -
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationLoadingTest.java
| 300 ++++------
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/OperationJsonTest.java
| 194 +++---
8 files changed, 490 insertions(+), 414 deletions(-)
New commits:
commit 94cc4206c8525ca9b69469947dc5deab4633a13e
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Mon Feb 27 18:19:28 2012 -0500
fix unit test failures for as7 configuration.
- needed to overload the execute behavior just for these tests.
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AbstractConfigurationHandlingTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AbstractConfigurationHandlingTest.java
index 1af2f2f..72166d5 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AbstractConfigurationHandlingTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AbstractConfigurationHandlingTest.java
@@ -19,6 +19,7 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
@@ -31,6 +32,8 @@ import javax.xml.bind.util.ValidationEventCollector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
@@ -42,6 +45,7 @@ import org.rhq.core.clientapi.descriptor.plugin.ServerDescriptor;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.modules.plugins.jbossas7.json.Result;
/**
* Base class for configuration handling tests
@@ -53,7 +57,6 @@ public class AbstractConfigurationHandlingTest {
private Log log = LogFactory.getLog(getClass());
private PluginDescriptor pluginDescriptor;
-
void loadPluginDescriptor() throws Exception {
try {
URL descriptorUrl =
this.getClass().getClassLoader().getResource(DESCRIPTOR_FILENAME);
@@ -102,8 +105,7 @@ public class AbstractConfigurationHandlingTest {
builder.append(line);
}
return builder.toString();
- }
- finally {
+ } finally {
reader.close();
}
}
@@ -114,6 +116,23 @@ public class AbstractConfigurationHandlingTest {
*
*/
protected class FakeConnection extends ASConnection {
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Override
+ public Result execute(Operation op) {
+ JsonNode json = executeRaw(op);
+ Result result = null;
+ try {
+ result = mapper.readValue(json, Result.class);
+ } catch (JsonParseException e) {
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
JsonNode content;
@@ -127,11 +146,11 @@ public class AbstractConfigurationHandlingTest {
@Override
public JsonNode executeRaw(Operation operation) {
- if (content==null)
+ if (content == null)
throw new IllegalStateException("Content not yet set");
Address address = operation.getAddress();
- if (address!=null && !address.isEmpty()) {
+ if (address != null && !address.isEmpty()) {
// we need to clone the content and then for the result find the right
sub-content to put into result and
// return this one.
@@ -139,17 +158,17 @@ public class AbstractConfigurationHandlingTest {
String[] parts = address.getPath().split("=");
String key = parts[0];
String val = parts[1];
- JsonNode result = content.get("result");
+ JsonNode result = content.get("result");
JsonNode keyNode = result.get(key);
JsonNode valNode = keyNode.get(val);
// clone the original content
ObjectMapper tmpMapper = new ObjectMapper();
JsonNode tmp = tmpMapper.createObjectNode();
- ((ObjectNode)tmp).putAll(((ObjectNode)content));
+ ((ObjectNode) tmp).putAll(((ObjectNode) content));
// replace the result with the sub-content
- ((ObjectNode)tmp).put("result",valNode);
+ ((ObjectNode) tmp).put("result", valNode);
return tmp;
}
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationLoadingTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationLoadingTest.java
index 8e3704b..db086f6 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationLoadingTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationLoadingTest.java
@@ -18,14 +18,10 @@
*/
package org.rhq.modules.plugins.jbossas7;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.testng.annotations.BeforeSuite;
@@ -58,208 +54,172 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
}
public void test1() throws Exception {
- FakeConnection connection = new FakeConnection();
- ConfigurationDefinition definition = new
ConfigurationDefinition("foo","Test1");
+ //create a fake connection so that we control the execute behavior
+ FakeConnection connection = new FakeConnection();
+ //create/mock a configuration definition. Remember definition shared between N
configurations.
+ ConfigurationDefinition definition = new ConfigurationDefinition("foo",
"Test1");
+ //?
definition.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
- definition.put(new PropertyDefinitionSimple("access-log",
"Access-Log", false,
- PropertySimpleType.STRING));
- definition.put(new PropertyDefinitionSimple("rewrite",
"Rewrite", false,
- PropertySimpleType.BOOLEAN));
- definition.put(new PropertyDefinitionSimple("notThere",
"NotThere", false,
- PropertySimpleType.STRING));
- definition.put(new PropertyDefinitionList("alias", "Alias",
true, new PropertyDefinitionSimple(
- "alias", "alias", true, PropertySimpleType.STRING)));
+ //Add a few properties that we will be testing/exercising
+ definition.put(new PropertyDefinitionSimple("access-log",
"Access-Log", false, PropertySimpleType.STRING));
+ definition.put(new PropertyDefinitionSimple("rewrite",
"Rewrite", false, PropertySimpleType.BOOLEAN));
+ definition.put(new PropertyDefinitionSimple("notThere",
"NotThere", false, PropertySimpleType.STRING));
+ definition.put(new PropertyDefinitionList("alias", "Alias",
true, new PropertyDefinitionSimple("alias",
+ "alias", true, PropertySimpleType.STRING)));
-
- String resultString = " {\"outcome\" : \"success\",
\"result\" : {\"alias\" :
[\"example.com\",\"example2.com\"],"+
- " \"access-log\" : \"my.log\",
\"rewrite\" : true}}";
+ //Construct the result string that we would expect back.
+ String resultString = " {\"outcome\" : \"success\",
\"result\" : {\"alias\" :
[\"example.com\",\"example2.com\"],"
+ + " \"access-log\" : \"my.log\",
\"rewrite\" : true}}";
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ //deserialize string to ComplexResult.
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
+
+ //create json tree from result.
JsonNode json = mapper.valueToTree(result);
+ //add the created content to the fake connection so that we set the results to be
returned.
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ //We pass in null here so that the fake connection will return the value passed
into setContent().
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
- assert config.get("alias")!=null;
+ assert config.get("alias") != null;
assert config.get("alias") instanceof PropertyList;
PropertyList aliases = (PropertyList) config.get("alias");
List<Property> list = aliases.getList();
- assert list.size()==2;
- int count=2;
- for (Property p: list) {
+ assert list.size() == 2;
+ int count = 2;
+ for (Property p : list) {
PropertySimple ps = (PropertySimple) p;
if (ps.getStringValue().equals("example.com"))
count--;
if (ps.getStringValue().equals("example2.com"))
count--;
}
- assert count==0 : "Did not find all needed aliases";
+ assert count == 0 : "Did not find all needed aliases";
Property notThere = config.get("notThere");
- assert notThere !=null;
- assert ((PropertySimple)notThere).getStringValue()==null;
+ assert notThere != null;
+ assert ((PropertySimple) notThere).getStringValue() == null;
PropertySimple property = (PropertySimple) config.get("rewrite");
- assert property!=null;
+ assert property != null;
assert property.getBooleanValue();
property = (PropertySimple) config.get("access-log");
- assert property!=null && property.getStringValue()!=null;
+ assert property != null && property.getStringValue() != null;
assert property.getStringValue().equals("my.log");
}
public void test2() throws Exception {
- String resultString = "{\n" +
- " \"outcome\" : \"success\",\n" +
- " \"result\" : {\n" +
- " \"autoflush\" : true,\n" +
- " \"encoding\" : null,\n" +
- " \"formatter\" : \"%d{HH:mm:ss,SSS} %-5p [%c]
(%t) %s%E%n\",\n" +
- " \"level\" : \"INFO\",\n" +
- " \"file\" : {\n" +
- " \"path\" : \"server.log\",\n" +
- " \"relative-to\" :
\"jboss.server.log.dir\"\n" +
- " },\n" +
- " \"suffix\" : \".yyyy-MM-dd\"\n" +
- " },\n" +
- " \"response-headers\" : null\n" +
- "}";
+ String resultString = "{\n" + " \"outcome\" :
\"success\",\n" + " \"result\" : {\n"
+ + " \"autoflush\" : true,\n" + "
\"encoding\" : null,\n"
+ + " \"formatter\" : \"%d{HH:mm:ss,SSS} %-5p [%c] (%t)
%s%E%n\",\n" + " \"level\" : \"INFO\",\n"
+ + " \"file\" : {\n" + " \"path\" :
\"server.log\",\n"
+ + " \"relative-to\" :
\"jboss.server.log.dir\"\n" + " },\n" + "
\"suffix\" : \".yyyy-MM-dd\"\n"
+ + " },\n" + " \"response-headers\" : null\n"
+ "}";
FakeConnection connection = new FakeConnection();
- ConfigurationDefinition definition = new
ConfigurationDefinition("foo","Test1");
+ ConfigurationDefinition definition = new ConfigurationDefinition("foo",
"Test1");
PropertyDefinitionSimple propertyDefinition = new
PropertyDefinitionSimple("autoflush", "Autoflush", false,
- PropertySimpleType.BOOLEAN);
+ PropertySimpleType.BOOLEAN);
propertyDefinition.setDefaultValue("true");
definition.put(propertyDefinition);
- propertyDefinition = new PropertyDefinitionSimple("encoding",
"Encoding", false,
- PropertySimpleType.STRING);
+ propertyDefinition = new PropertyDefinitionSimple("encoding",
"Encoding", false, PropertySimpleType.STRING);
propertyDefinition.setDefaultValue("HelloWorld");
definition.put(propertyDefinition);
- PropertyDefinitionSimple pathProperty = new
PropertyDefinitionSimple("path","File
path",true,PropertySimpleType.STRING);
- PropertyDefinitionSimple relativeToProperty = new
PropertyDefinitionSimple("relative-to","Relative-To",true,PropertySimpleType.STRING);
- PropertyDefinitionMap fileMapDef = new
PropertyDefinitionMap("file","Log
file",true,pathProperty,relativeToProperty);
+ PropertyDefinitionSimple pathProperty = new
PropertyDefinitionSimple("path", "File path", true,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple relativeToProperty = new
PropertyDefinitionSimple("relative-to", "Relative-To", true,
+ PropertySimpleType.STRING);
+ PropertyDefinitionMap fileMapDef = new PropertyDefinitionMap("file",
"Log file", true, pathProperty,
+ relativeToProperty);
definition.put(fileMapDef);
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
- assert config!=null;
- assert config.get("autoflush")!=null : "Autoflush was null";
+ assert config != null;
+ assert config.get("autoflush") != null : "Autoflush was
null";
assert config.getSimple("autoflush").getBooleanValue() :
"Autoflush was false";
PropertyMap fileMap = (PropertyMap) config.get("file");
- assert fileMap!=null : "File Map was null";
+ assert fileMap != null : "File Map was null";
PropertySimple path = (PropertySimple) fileMap.get("path");
- assert path!=null : "File->path was null";
+ assert path != null : "File->path was null";
assert path.getStringValue().equals("server.log") : "File->path
wrong";
-
}
-
public void test3() throws Exception {
- String resultString = "{\n" +
- " \"outcome\" : \"success\",\n" +
- " \"result\" : {\n" +
- " \"name\" : \"standard-sockets\",\n" +
- " \"default-interface\" :
\"default\",\n" +
- " \"port-offset\" : \"0\",\n" +
- " \"socket-binding\" : {\n" +
- " \"jndi\" : {\n" +
- " \"name\" : \"jndi\",\n" +
- " \"interface\" : null,\n" +
- " \"port\" : 1099,\n" +
- " \"fixed-port\" : null,\n" +
- " \"multicast-address\" : null,\n" +
- " \"multicast-port\" : null\n" +
- " },\n" +
- " \"jmx-connector-registry\" : {\n" +
- " \"name\" :
\"jmx-connector-registry\",\n" +
- " \"interface\" : null,\n" +
- " \"port\" : 1090,\n" +
- " \"fixed-port\" : null,\n" +
- " \"multicast-address\" : null,\n" +
- " \"multicast-port\" : null\n" +
- " },\n" +
- " \"jmx-connector-server\" : {\n" +
- " \"name\" :
\"jmx-connector-server\",\n" +
- " \"interface\" : null,\n" +
- " \"port\" : 1091,\n" +
- " \"fixed-port\" : null,\n" +
- " \"multicast-address\" : null,\n" +
- " \"multicast-port\" : null\n" +
- " },\n" +
- " \"http\" : {\n" +
- " \"name\" : \"http\",\n" +
- " \"interface\" : null,\n" +
- " \"port\" : 8080,\n" +
- " \"fixed-port\" : null,\n" +
- " \"multicast-address\" : null,\n" +
- " \"multicast-port\" : null\n" +
- " },\n" +
- " \"https\" : {\n" +
- " \"name\" : \"https\",\n" +
- " \"interface\" : null,\n" +
- " \"port\" : 8447,\n" +
- " \"fixed-port\" : null,\n" +
- " \"multicast-address\" :
\"224.1.2.3\",\n" +
- " \"multicast-port\" : 18447\n" +
- " }"+
- " }\n" +
- " }\n" +
- "}";
+ String resultString = "{\n" + " \"outcome\" :
\"success\",\n" + " \"result\" : {\n"
+ + " \"name\" : \"standard-sockets\",\n" +
" \"default-interface\" : \"default\",\n"
+ + " \"port-offset\" : \"0\",\n" + "
\"socket-binding\" : {\n" + " \"jndi\" : {\n"
+ + " \"name\" : \"jndi\",\n" + "
\"interface\" : null,\n" + " \"port\" :
1099,\n"
+ + " \"fixed-port\" : null,\n" + "
\"multicast-address\" : null,\n"
+ + " \"multicast-port\" : null\n" + "
},\n" + " \"jmx-connector-registry\" : {\n"
+ + " \"name\" :
\"jmx-connector-registry\",\n" + " \"interface\" :
null,\n"
+ + " \"port\" : 1090,\n" + "
\"fixed-port\" : null,\n"
+ + " \"multicast-address\" : null,\n" + "
\"multicast-port\" : null\n" + " },\n"
+ + " \"jmx-connector-server\" : {\n" + "
\"name\" : \"jmx-connector-server\",\n"
+ + " \"interface\" : null,\n" + "
\"port\" : 1091,\n" + " \"fixed-port\" :
null,\n"
+ + " \"multicast-address\" : null,\n" + "
\"multicast-port\" : null\n" + " },\n"
+ + " \"http\" : {\n" + "
\"name\" : \"http\",\n" + " \"interface\" :
null,\n"
+ + " \"port\" : 8080,\n" + "
\"fixed-port\" : null,\n"
+ + " \"multicast-address\" : null,\n" + "
\"multicast-port\" : null\n" + " },\n"
+ + " \"https\" : {\n" + "
\"name\" : \"https\",\n" + " \"interface\"
: null,\n"
+ + " \"port\" : 8447,\n" + "
\"fixed-port\" : null,\n"
+ + " \"multicast-address\" :
\"224.1.2.3\",\n" + " \"multicast-port\" :
18447\n" + " }"
+ + " }\n" + " }\n" + "}";
ConfigurationDefinition definition = loadDescriptor("socketBinding");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
-
assert config != null;
PropertyList propertyList = (PropertyList)
config.get("socket-binding");
- assert propertyList!=null;
+ assert propertyList != null;
List<Property> list = propertyList.getList();
- assert list.size()==5;
+ assert list.size() == 5;
for (Property prop : list) {
PropertyMap propMap2 = (PropertyMap) prop;
- Map<String,Property> map2 = propMap2.getMap();
- assert map2.size()==6;
+ Map<String, Property> map2 = propMap2.getMap();
+ assert map2.size() == 6;
assert map2.containsKey("port");
assert map2.containsKey("multicast-port");
assert map2.containsKey("multicast-address");
- if
(((PropertySimple)map2.get("name")).getStringValue().equals("https"))
{
- assert
((PropertySimple)map2.get("port")).getIntegerValue()==8447;
- assert
((PropertySimple)map2.get("multicast-port")).getIntegerValue()==18447;
+ if (((PropertySimple)
map2.get("name")).getStringValue().equals("https")) {
+ assert ((PropertySimple) map2.get("port")).getIntegerValue() ==
8447;
+ assert ((PropertySimple)
map2.get("multicast-port")).getIntegerValue() == 18447;
}
}
}
-
public void test4() throws Exception {
String resultString = loadJsonFromFile("extensions.json");
@@ -267,31 +227,30 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test4");
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
assert config != null;
PropertyList extensions = (PropertyList) config.get("extension");
- assert extensions !=null;
+ assert extensions != null;
List<Property> extensionList = extensions.getList();
- assert extensionList.size()==22 : "Expected 22 extensions, got " +
extensionList.size();
+ assert extensionList.size() == 22 : "Expected 22 extensions, got " +
extensionList.size();
PropertyMap propertyMap = (PropertyMap) extensionList.get(0);
assert propertyMap != null;
PropertyMap starMap = (PropertyMap) propertyMap.get("*");
- assert starMap!=null;
+ assert starMap != null;
PropertySimple module = (PropertySimple) starMap.get("module");
- assert module!=null : "Module was null, but should not";
+ assert module != null : "Module was null, but should not";
String stringValue = module.getStringValue();
- assert stringValue!=null : "module property has no value";
+ assert stringValue != null : "module property has no value";
assert stringValue.equals("org.jboss.as.arquillian.service");
-
}
public void test5() throws Exception {
@@ -301,27 +260,27 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test5");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
assert config != null;
PropertyList locations = (PropertyList)
config.get("schema-locations");
- assert locations!=null;
+ assert locations != null;
List<Property> list = locations.getList();
- assert list.size()==21 : "List does not contain 21 entries, but " +
list.size();
+ assert list.size() == 21 : "List does not contain 21 entries, but " +
list.size();
PropertyMap propertyMap = (PropertyMap) list.get(0);
- assert propertyMap !=null;
- Map<String,Property> map = propertyMap.getMap();
- assert map.size()==1;
+ assert propertyMap != null;
+ Map<String, Property> map = propertyMap.getMap();
+ assert map.size() == 1;
PropertySimple urnProp = (PropertySimple) map.get("*");
String stringValue = urnProp.getStringValue();
- assert stringValue!=null : "Location property has no value";
+ assert stringValue != null : "Location property has no value";
assert stringValue.endsWith(".xsd");
}
@@ -333,27 +292,27 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test6and7");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
assert config != null;
PropertySimple nameProperty = (PropertySimple) config.get("name");
- assert nameProperty !=null;
+ assert nameProperty != null;
String stringValue = nameProperty.getStringValue();
- assert stringValue!=null;
+ assert stringValue != null;
assert stringValue.equals("default");
Property criteria = config.get("criteria");
- assert criteria !=null;
+ assert criteria != null;
PropertySimple critProp = (PropertySimple) criteria;
stringValue = critProp.getStringValue();
- assert stringValue!=null;
+ assert stringValue != null;
}
@@ -364,27 +323,27 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test6and7");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
assert config != null;
PropertySimple nameProperty = (PropertySimple) config.get("name");
- assert nameProperty !=null;
+ assert nameProperty != null;
String stringValue = nameProperty.getStringValue();
- assert stringValue!=null;
+ assert stringValue != null;
assert stringValue.equals("public");
Property criteria = config.get("criteria");
- assert criteria !=null;
+ assert criteria != null;
PropertySimple critProp = (PropertySimple) criteria;
stringValue = critProp.getStringValue();
- assert stringValue!=null;
+ assert stringValue != null;
assert stringValue.equals("any-ipv4-address");
}
@@ -396,24 +355,25 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test8");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
- assert config!=null;
- assert config.getAllProperties().size()==8 : "Did not find 8 properties, but
" + config.getAllProperties().size();
+ assert config != null;
+ assert config.getAllProperties().size() == 8 : "Did not find 8 properties,
but "
+ + config.getAllProperties().size();
Property prop = config.get("bean-validation-enabled");
assert prop != null;
PropertySimple ps = (PropertySimple) prop;
assert ps.getBooleanValue();
prop = config.get("cached-connection-manager-error");
- assert prop!=null;
+ assert prop != null;
ps = (PropertySimple) prop;
- assert ps.getBooleanValue()==false;
+ assert ps.getBooleanValue() == false;
}
@@ -422,45 +382,43 @@ public class ConfigurationLoadingTest extends
AbstractConfigurationHandlingTest
ConfigurationDefinition definition = loadDescriptor("test9");
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
JsonNode json = mapper.valueToTree(result);
FakeConnection connection = new FakeConnection();
connection.setContent(json);
- ConfigurationLoadDelegate delegate = new
ConfigurationLoadDelegate(definition,connection,null);
+ ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(definition,
connection, null);
Configuration config = delegate.loadResourceConfiguration();
- assert config!=null;
+ assert config != null;
Collection<Property> properties = config.getProperties();
- assert properties.size()==6 : "Got " + properties.size() + " props
instead of 6: " + properties.toString();
+ assert properties.size() == 6 : "Got " + properties.size() + "
props instead of 6: " + properties.toString();
PropertySimple simple = config.getSimple("check-interval");
- assert simple !=null;
+ assert simple != null;
Integer integerValue = simple.getIntegerValue();
- assert integerValue !=null : "check-interval was null";
- assert integerValue ==17 : "check-interval was not 17 but " +
integerValue;
+ assert integerValue != null : "check-interval was null";
+ assert integerValue == 17 : "check-interval was not 17 but " +
integerValue;
PropertySimple disabled = config.getSimple("disabled");
- assert disabled !=null : "disabled was null";
+ assert disabled != null : "disabled was null";
Boolean booleanValue = disabled.getBooleanValue();
- assert booleanValue !=null;
+ assert booleanValue != null;
assert booleanValue;
PropertySimple listings = config.getSimple("listings");
- assert listings !=null;
+ assert listings != null;
Boolean booleanValue1 = listings.getBooleanValue();
- assert booleanValue1 !=null;
+ assert booleanValue1 != null;
assert !booleanValue1;
PropertySimple simple1 = config.getSimple("max-depth");
- assert simple1 !=null;
+ assert simple1 != null;
Integer integerValue1 = simple1.getIntegerValue();
- assert integerValue1 !=null;
- assert integerValue1 ==3;
+ assert integerValue1 != null;
+ assert integerValue1 == 3;
PropertySimple simple2 = config.getSimple("default-virtual-server");
- assert simple2 !=null;
+ assert simple2 != null;
String stringValue = simple2.getStringValue();
- assert stringValue !=null;
+ assert stringValue != null;
assert stringValue.equals("default-host");
-
-
}
}
commit 80562eaf03271de823632c9c63439271126b13df
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Mon Feb 27 17:19:23 2012 -0500
Fix copy paste mistake.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 7722312..ef4506c 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -134,7 +134,7 @@ public class ASConnection {
if ((json_to_send.indexOf(JSON_SERVER_CONFIG + EAP_PREFIX) > -1)
|| (json_to_send.indexOf(JSON_SERVER_CONFIG + EDG_PREFIX) > -1)
|| (json_to_send.indexOf(JSON_NAME + EAP_PREFIX) > -1)
- || (json_to_send.indexOf(JSON_NAME + EAP_PREFIX) > -1)) {
+ || (json_to_send.indexOf(JSON_NAME + EDG_PREFIX) > -1)) {
//delve into Operation and remove prefixes
Operation purgedOperation = purgeOperation(operation);
commit 8b2e5871114d8c08545befc8b9486129f82b2d34
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 16:17:07 2012 -0500
adding more context for unparsable json change.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 76a630a..7722312 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -382,6 +382,8 @@ public class ASConnection {
return failure;
}
//spinder 2/22/12: if unparsable JSON detected remove it. TODO: see if fixed
with later version of jackson
+ //This needs to be in place until i)Jackson version where this is fixed or
+ // ii) fix for
https://issues.jboss.org/browse/JBPAPP-8233
if (as7ResultSerialization.indexOf(UNPARSABLE_JSON) > -1) {
if (verbose) {
log.warn("------ Detected unparsable JSON <" +
as7ResultSerialization + ">.");
commit c70a38dd3de2d8d4a1c25634ff3ceb83bd1a36bb
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 15:06:34 2012 -0500
Return failure Result for unexpected errors instead of null.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 00f61d2..76a630a 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -403,7 +403,15 @@ public class ASConnection {
return res;
} catch (IOException e) {
log.error(e.getMessage());
- return null;
+ if (verbose) {
+ log.error("----------- Operation execution unparsable. Request
" + ":[" + op + "] Response:<" + node
+ + ">");
+ }
+ Result failure = new Result();
+ failure.setFailureDescription("Operation <" + op + ">
returned unparsable JSON, <" + node + ">.");
+ return failure;
+ //don't return null.
+ //return null;
}
}
commit cf0c1af06a5d552413bdd404b320d01bfb5c1635
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 15:03:00 2012 -0500
Modifying connection class to handle 'failure-description' responses from AS7
as we were currently detecting as invalid json.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 812c5ff..00f61d2 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -57,6 +57,7 @@ public class ASConnection {
Authenticator passwordAuthenticator;
private String host;
private int port;
+ private String FAILURE_DESCRIPTION = "\"failure-description\"";
private String UNPARSABLE_JSON = ",\"server-groups\":null";
private static String EAP_PREFIX = AbstractBaseDiscovery.EAP_PREFIX;
private static String EDG_PREFIX = AbstractBaseDiscovery.EDG_PREFIX;
@@ -364,8 +365,22 @@ public class ASConnection {
Result res;
try {
+ //check for failure-description indicator, otherwise ObjectMapper will try to
deserialize as json. Ex.
+ //
{"outcome":"failed","failure-description":"JBAS014792:
Unknown attribute number-of-timed-out-transactions","rolled-back":true}
String as7ResultSerialization = node.toString();
+ if (as7ResultSerialization.indexOf(FAILURE_DESCRIPTION) > -1) {
+ if (verbose) {
+ log.warn("------ Detected 'failure-description' when
communicating with server."
+ + as7ResultSerialization);
+ }
+ Result failure = new Result();
+ int failIndex = as7ResultSerialization.indexOf(FAILURE_DESCRIPTION);
+ String failMessage = "";
+ failMessage = as7ResultSerialization.substring(failIndex +
FAILURE_DESCRIPTION.length() + 1);
+ failure.setFailureDescription("Operation <" + op +
"> returned <" + failMessage + ">");
+ return failure;
+ }
//spinder 2/22/12: if unparsable JSON detected remove it. TODO: see if fixed
with later version of jackson
if (as7ResultSerialization.indexOf(UNPARSABLE_JSON) > -1) {
if (verbose) {
commit 1bf2f81404a399f823d3f1bf7b6b8b74144ac7fb
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 14:57:36 2012 -0500
Removing extra JSON segment returned with some results from AS7.
- Jackson libraries confused by extra JSON segment returned even though the returned
string is valid JSON.
- We need to check out whether this is still a problem with later jackson versions.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 6249bbc..812c5ff 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -57,6 +57,7 @@ public class ASConnection {
Authenticator passwordAuthenticator;
private String host;
private int port;
+ private String UNPARSABLE_JSON = ",\"server-groups\":null";
private static String EAP_PREFIX = AbstractBaseDiscovery.EAP_PREFIX;
private static String EDG_PREFIX = AbstractBaseDiscovery.EDG_PREFIX;
private static String NAME = "name";
@@ -362,6 +363,23 @@ public class ASConnection {
}
Result res;
try {
+
+ String as7ResultSerialization = node.toString();
+
+ //spinder 2/22/12: if unparsable JSON detected remove it. TODO: see if fixed
with later version of jackson
+ if (as7ResultSerialization.indexOf(UNPARSABLE_JSON) > -1) {
+ if (verbose) {
+ log.warn("------ Detected unparsable JSON <" +
as7ResultSerialization + ">.");
+ }
+ String trimExtraJson = "";
+ int index = as7ResultSerialization.indexOf(UNPARSABLE_JSON);
+ trimExtraJson = as7ResultSerialization.substring(0, index)
+ + as7ResultSerialization.substring(index +
UNPARSABLE_JSON.length());
+ res = (isComplex) ? mapper.readValue(trimExtraJson, ComplexResult.class)
: mapper.readValue(
+ trimExtraJson, Result.class);
+ return res;
+ }
+
if (isComplex) {
res = mapper.readValue(node, ComplexResult.class);
} else {
commit 3869977299956619d02c36e0bbd179c50fe97e86
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 14:53:44 2012 -0500
[BZ 785128] unable to remove managed server. Have to remove EAP/EDG
prefixes when carrying out operations on the server now since we're
prepending EAP/EDG depending on EAP server used.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
index 6a7523f..6249bbc 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
@@ -28,6 +28,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -36,6 +37,7 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.Result;
@@ -55,6 +57,12 @@ public class ASConnection {
Authenticator passwordAuthenticator;
private String host;
private int port;
+ private static String EAP_PREFIX = AbstractBaseDiscovery.EAP_PREFIX;
+ private static String EDG_PREFIX = AbstractBaseDiscovery.EDG_PREFIX;
+ private static String NAME = "name";
+ private static String OPERATION_SERVER_CONFIG = "server-config=";
+ private static String JSON_SERVER_CONFIG =
"{\"server-config\":\"";
+ private static String JSON_NAME = "\"name\":\"";
/**
* Construct an ASConnection object. The real "physical" connection is done
in
@@ -119,9 +127,26 @@ public class ASConnection {
OutputStream out = conn.getOutputStream();
String json_to_send = mapper.writeValueAsString(operation);
+ //BZ:785128. removing artificial prefix for messages going back to the
server.
+ //check for prefixed names
+ if ((json_to_send.indexOf(JSON_SERVER_CONFIG + EAP_PREFIX) > -1)
+ || (json_to_send.indexOf(JSON_SERVER_CONFIG + EDG_PREFIX) > -1)
+ || (json_to_send.indexOf(JSON_NAME + EAP_PREFIX) > -1)
+ || (json_to_send.indexOf(JSON_NAME + EAP_PREFIX) > -1)) {
+
+ //delve into Operation and remove prefixes
+ Operation purgedOperation = purgeOperation(operation);
+ if (verbose) {
+ log.warn("---------------- Purging EAP/EDG prefixes detected.
Was <" + operation + "> but now <"
+ + purgedOperation + ">.");
+ }
+ operation = purgedOperation;
+ }
+
if (verbose) {
log.info("Json to send: " + json_to_send);
}
+
mapper.writeValue(out, operation);
out.flush();
@@ -236,6 +261,67 @@ public class ASConnection {
return null;
}
+ /** This operation purges the Operation passed in of EAP/EDG prefixes in the
+ * Address portion and in the AdditionalProperties section. The returned
+ * operation should be identical in every other way and should be used
+ * instead of the unpurged operation which will cause unrecognized property
+ * errors.
+ *
+ * @param operation to be purged.
+ * @return The same operation minus the prefixes.
+ */
+ private Operation purgeOperation(Operation operation) {
+ //purge prefixes from name
+ if (operation != null) {
+ boolean prefixLocated = false;
+
+ //Ex.
+ //Operation{operation='remove', address=Address{path:
host=master,server-config=EAP server-six},
+ //additionalProperties={socket-binding-port-offset=0, name=EAP server-six,
auto-start=false, group=,
+ //socket-binding-group=}}
+
+ //ADDRESS parsing
+ String path = operation.getAddress().getPath();
+ if (path.indexOf(OPERATION_SERVER_CONFIG + EAP_PREFIX) > -1
+ || path.indexOf(OPERATION_SERVER_CONFIG + EDG_PREFIX) > -1) {
+ int index = -1;
+ prefixLocated = true;
+ if ((index = path.indexOf(OPERATION_SERVER_CONFIG + EAP_PREFIX)) > -1)
{
+ path = path.substring(0, index + OPERATION_SERVER_CONFIG.length())
+ + path.substring(index + OPERATION_SERVER_CONFIG.length() +
EAP_PREFIX.length());
+ }
+ if ((index = path.indexOf(OPERATION_SERVER_CONFIG + EDG_PREFIX)) > -1)
{
+ path = path.substring(0, index + OPERATION_SERVER_CONFIG.length())
+ + path.substring(index + OPERATION_SERVER_CONFIG.length() +
EDG_PREFIX.length());
+ }
+ }
+
+ //ADDITIONAL-PROPERTIES parsing
+ Map<String, Object> additionalProperties =
operation.getAdditionalProperties();
+ if ((additionalProperties != null) &&
!additionalProperties.isEmpty()
+ && additionalProperties.containsKey(NAME)) {
+ String contents = (String) additionalProperties.get(NAME);
+ if (contents.startsWith(EAP_PREFIX) || contents.startsWith(EDG_PREFIX))
{
+ prefixLocated = true;
+ if (contents.startsWith(EAP_PREFIX)) {
+ contents = contents.substring(EAP_PREFIX.length());
+ } else if (contents.startsWith(EDG_PREFIX)) {
+ contents = contents.substring(EDG_PREFIX.length());
+ }
+ additionalProperties.put(NAME, contents);
+ }
+ }
+
+ if (prefixLocated) {
+ //create new Operation to return.
+ Operation newOperation = new Operation(operation.getOperation(), new
Address(path),
+ additionalProperties);
+ return newOperation;
+ }
+ }
+ return operation;
+ }
+
/**
* Execute the passed Operation and return its Result. This is a shortcut of
* #execute(Operation, false)
@@ -274,12 +360,13 @@ public class ASConnection {
failure.setFailureDescription("Operation [" + op + "] returned
null");
return failure;
}
+ Result res;
try {
- Result res;
- if (isComplex)
+ if (isComplex) {
res = mapper.readValue(node, ComplexResult.class);
- else
+ } else {
res = mapper.readValue(node, Result.class);
+ }
return res;
} catch (IOException e) {
log.error(e.getMessage());
commit e3b17d4977e91bda9bf8362817bc68290f557683
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 14:30:06 2012 -0500
Use constants where possible for EAP/EDG identifiers.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
index dca0b8c..54ef7d4 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
@@ -50,6 +50,10 @@ public class AbstractBaseDiscovery {
protected Document hostXml;
protected final Log log = LogFactory.getLog(this.getClass());
private static final String JBOSS_EAP_PREFIX = "jboss-eap-";
+ public static final String EAP = "EAP";
+ public static final String EDG = "EDG";
+ public static final String EAP_PREFIX = EAP + " ";
+ public static final String EDG_PREFIX = EDG + " ";
private XPathFactory factory;
protected AbstractBaseDiscovery() {
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 a0faeaa..f136483 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
@@ -178,11 +178,11 @@ public class BaseProcessDiscovery extends AbstractBaseDiscovery
implements Resou
}
if (isEAP) {
- serverName = "EAP " + serverName;
- version = "EAP " + version;
+ serverName = EAP_PREFIX + serverName;
+ version = EAP_PREFIX + version;
} else if (isEDG) {
- serverName = "EDG " + serverName;
- version = "EDG " + version;
+ serverName = EDG_PREFIX + serverName;
+ version = EDG_PREFIX + version;
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
index 3d937c0..5feaab2 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
@@ -102,12 +102,12 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
String resourceName = serverInfo.name;
- if (hostInfo.productName.equalsIgnoreCase("eap")) {
- version = "EAP " + hostInfo.productVersion;
+ if (hostInfo.productName.equalsIgnoreCase(EAP)) {
+ version = EAP_PREFIX + hostInfo.productVersion;
resourceDescription = "Managed JBoss Enterprise Application
Platform 6 server";
- resourceName = "EAP " + resourceName;
- } else if (hostInfo.productName.equalsIgnoreCase("EDG")) {
- version = "EDG " + hostInfo.productVersion;
+ resourceName = EAP_PREFIX + resourceName;
+ } else if (hostInfo.productName.equalsIgnoreCase(EDG)) {
+ version = EDG_PREFIX + hostInfo.productVersion;
resourceDescription = "Managed JBoss Enterprise Data Grid 6
server";
} else {
resourceDescription = "Managed AS7 server";
commit ce4b1a63105f7d67bf94a19445d731ab10bfc52e
Author: Simeon Pinder <spinder(a)redhat.com>
Date: Sat Feb 25 14:09:03 2012 -0500
- ignore this diff. No functional changes just ide formatting.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
index c464e4b..dca0b8c 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AbstractBaseDiscovery.java
@@ -41,7 +41,7 @@ import org.rhq.core.system.ProcessInfo;
* in the area of processes and host.xml
* @author Heiko W. Rupp
*/
-public class AbstractBaseDiscovery {
+public class AbstractBaseDiscovery {
static final String DORG_JBOSS_BOOT_LOG_FILE =
"-Dorg.jboss.boot.log.file=";
private static final String DJBOSS_SERVER_HOME_DIR = "-Djboss.home.dir";
static final int DEFAULT_MGMT_PORT = 9990;
@@ -52,8 +52,6 @@ public class AbstractBaseDiscovery {
private static final String JBOSS_EAP_PREFIX = "jboss-eap-";
private XPathFactory factory;
-
-
protected AbstractBaseDiscovery() {
synchronized (this) {
factory = XPathFactory.newInstance();
@@ -68,7 +66,7 @@ public class AbstractBaseDiscovery {
* @param isDomainMode Indiates if host.xml should be read (true) or standalone.xml
(false)
*/
protected void readStandaloneOrHostXml(ProcessInfo processInfo, boolean isDomainMode)
{
- String hostXmlFile = getHostXmlFileLocation(processInfo,isDomainMode);
+ String hostXmlFile = getHostXmlFileLocation(processInfo, isDomainMode);
readStandaloneOrHostXmlFromFile(hostXmlFile);
}
@@ -93,11 +91,11 @@ public class AbstractBaseDiscovery {
* @return The home dir if found or empty string otherwise
*/
String getHomeDirFromCommandLine(String[] commandLine) {
- for (String line: commandLine) {
- if (line.startsWith(DJBOSS_SERVER_HOME_DIR))
- return line.substring(DJBOSS_SERVER_HOME_DIR.length()+1);
- }
- return "";
+ for (String line : commandLine) {
+ if (line.startsWith(DJBOSS_SERVER_HOME_DIR))
+ return line.substring(DJBOSS_SERVER_HOME_DIR.length() + 1);
+ }
+ return "";
}
/**
@@ -107,7 +105,7 @@ public class AbstractBaseDiscovery {
*/
String getLogFileFromCommandLine(String[] commandLine) {
- for (String line: commandLine) {
+ for (String line : commandLine) {
if (line.startsWith(DORG_JBOSS_BOOT_LOG_FILE))
return line.substring(DORG_JBOSS_BOOT_LOG_FILE.length());
}
@@ -121,7 +119,7 @@ public class AbstractBaseDiscovery {
* @param commandLine Command line arguments of the process to
*/
protected HostPort getManagementPortFromHostXml(String[] commandLine) {
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
String portString;
@@ -129,35 +127,29 @@ public class AbstractBaseDiscovery {
String socketBindingName;
- socketBindingName = obtainXmlPropertyViaXPath(
-
"//management/management-interfaces/http-interface/socket-binding/@http");
- String socketInterface = obtainXmlPropertyViaXPath(
-
"//management/management-interfaces/http-interface/socket/@interface");
+ socketBindingName =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/socket-binding/@http");
+ String socketInterface =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/socket/@interface");
if (!socketInterface.isEmpty()) {
- interfaceExpession = obtainXmlPropertyViaXPath(
- "//interfaces/interface[@name='" +
socketInterface + "']/inet-address/@value");
- portString = obtainXmlPropertyViaXPath(
-
"//management/management-interfaces/http-interface/socket/@port");
- }
- else if (socketBindingName.isEmpty()) {
+ interfaceExpession =
obtainXmlPropertyViaXPath("//interfaces/interface[@name='" +
socketInterface
+ + "']/inet-address/@value");
+ portString =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/socket/@port");
+ } else if (socketBindingName.isEmpty()) {
// old AS7.0, early 7.1 style
portString =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/@port");
- String interfaceName = obtainXmlPropertyViaXPath(
-
"//management/management-interfaces/http-interface/@interface");
- interfaceExpession = obtainXmlPropertyViaXPath(
- "/server/interfaces/interface[@name='" + interfaceName
+ "']/inet-address/@value");
- }
- else {
+ String interfaceName =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/@interface");
+ interfaceExpession =
obtainXmlPropertyViaXPath("/server/interfaces/interface[@name='" +
interfaceName
+ + "']/inet-address/@value");
+ } else {
// later AS7.1 and EAP6 standalone.xml
- portString = obtainXmlPropertyViaXPath(
- "/server/socket-binding-group/socket-binding[@name='" +
socketBindingName + "']/@port");
- String interfaceName = obtainXmlPropertyViaXPath(
- "/server/socket-binding-group/socket-binding[@name='" +
socketBindingName + "']/@interface");
+ portString =
obtainXmlPropertyViaXPath("/server/socket-binding-group/socket-binding[@name='"
+ + socketBindingName + "']/@port");
+ String interfaceName =
obtainXmlPropertyViaXPath("/server/socket-binding-group/socket-binding[@name='"
+ + socketBindingName + "']/@interface");
// TODO the next may also be expressed differently
- interfaceExpession = obtainXmlPropertyViaXPath(
- "/server/interfaces/interface[@name='" + interfaceName
+ "']/inet-address/@value");
+ interfaceExpession =
obtainXmlPropertyViaXPath("/server/interfaces/interface[@name='" +
interfaceName
+ + "']/inet-address/@value");
}
HostPort hp = new HostPort();
@@ -167,17 +159,14 @@ public class AbstractBaseDiscovery {
else
hp.host = "localhost"; // Fallback
-
- if (portString!=null && !portString.isEmpty()) {
- String tmp = replaceDollarExpression(portString,commandLine,
"9990");
+ if (portString != null && !portString.isEmpty()) {
+ String tmp = replaceDollarExpression(portString, commandLine,
"9990");
hp.port = Integer.valueOf(tmp);
- }
- else
+ } else
hp.port = 9990; // Fallback to default
return hp;
}
-
/**
* Check if the passed value has an expression in the form of ${var} or
${var:default},
* try to resolve it. Resolution is done by looking at the command line to see if
@@ -194,15 +183,14 @@ public class AbstractBaseDiscovery {
return value;
// remove ${ }
- value = value.substring(2,value.length()-1);
+ value = value.substring(2, value.length() - 1);
String fallback = lastResort;
String expression;
if (value.contains(":")) {
int i = value.indexOf(":");
- expression = value.substring(0,i);
- fallback = value.substring(i+1);
- }
- else {
+ expression = value.substring(0, i);
+ fallback = value.substring(i + 1);
+ } else {
expression = value;
}
/*
@@ -214,7 +202,7 @@ public class AbstractBaseDiscovery {
* to find the management addresss
*/
- String ret=null;
+ String ret = null;
for (int i = 0, commandLineLength = commandLine.length; i < commandLineLength;
i++) {
String line = commandLine[i];
if (expression.contains("address")) {
@@ -222,7 +210,7 @@ public class AbstractBaseDiscovery {
if (line.contains("="))
ret = line.substring(line.indexOf("=") + 1); //
-bmanagement=1.2.3.4
else
- ret = commandLine[i+1]; // -bmanagement 1.2.3.4
+ ret = commandLine[i + 1]; // -bmanagement 1.2.3.4
break;
}
} else if (expression.contains("port")) {
@@ -233,7 +221,7 @@ public class AbstractBaseDiscovery {
}
}
- if (ret==null)
+ if (ret == null)
ret = fallback;
return ret;
@@ -246,7 +234,7 @@ public class AbstractBaseDiscovery {
* @return server name
*/
protected String findHostName() {
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
String hostName = hostXml.getDocumentElement().getAttribute("name");
@@ -258,10 +246,9 @@ public class AbstractBaseDiscovery {
* @return host and port of the domain controller
*/
protected HostPort getDomainControllerFromHostXml() {
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
-
// first check remote, as we can't distinguish between a missing local
element or
// and empty one which is the default
String remoteHost =
obtainXmlPropertyViaXPath("/host/domain-controller/remote/@host");
@@ -272,8 +259,7 @@ public class AbstractBaseDiscovery {
hp = new HostPort(false);
hp.host = remoteHost;
hp.port = Integer.parseInt(portString);
- }
- else {
+ } else {
hp = new HostPort(true);
hp.port = 9999;
}
@@ -283,7 +269,7 @@ public class AbstractBaseDiscovery {
}
String getManagementSecurtiyRealmFromHostXml() {
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
String realm =
obtainXmlPropertyViaXPath("//management/management-interfaces/http-interface/@security-realm");
@@ -292,21 +278,24 @@ public class AbstractBaseDiscovery {
}
String getSecurityPropertyFileFromHostXml(String baseDir, AS7Mode mode, String realm)
{
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
- String fileName =
obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" + realm
+ "']/authentication/properties/@path");
- String relDir =
obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" + realm
+ "']/authentication/properties/@relative-to");
+ String fileName =
obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" +
realm
+ + "']/authentication/properties/@path");
+ String relDir =
obtainXmlPropertyViaXPath("//security-realms/security-realm[@name='" +
realm
+ + "']/authentication/properties/@relative-to");
String dmode;
- if (mode==AS7Mode.STANDALONE)
- dmode="server";
+ if (mode == AS7Mode.STANDALONE)
+ dmode = "server";
else
- dmode="domain";
+ dmode = "domain";
- String fullName ;
+ String fullName;
if (relDir.equals("jboss." + dmode + ".config.dir"))
- fullName = baseDir + File.separator + mode.getBaseDir() + File.separator +
"configuration" + File.separator + fileName;
+ fullName = baseDir + File.separator + mode.getBaseDir() + File.separator +
"configuration" + File.separator
+ + fileName;
else
fullName = relDir + File.separator + fileName;
@@ -323,7 +312,7 @@ public class AbstractBaseDiscovery {
protected String getHostXmlFileLocation(ProcessInfo processInfo, boolean isDomain) {
String home = processInfo.getEnvironmentVariable("jboss.home.dir");
- if (home==null)
+ if (home == null)
home = getHomeDirFromCommandLine(processInfo.getCommandLine());
StringBuilder builder = new StringBuilder(home);
if (isDomain)
@@ -341,7 +330,7 @@ public class AbstractBaseDiscovery {
protected String determineServerVersionFromHomeDir(String homeDir) {
String version;
- String tmp = homeDir.substring(homeDir.lastIndexOf("/")+1);
+ String tmp = homeDir.substring(homeDir.lastIndexOf("/") + 1);
if (tmp.startsWith(JBOSS_AS_PREFIX)) {
version = tmp.substring(JBOSS_AS_PREFIX.length());
} else if (tmp.startsWith(JBOSS_EAP_PREFIX)) {
@@ -362,10 +351,9 @@ public class AbstractBaseDiscovery {
*
*/
protected String obtainXmlPropertyViaXPath(String xpathExpression) {
- if (hostXml==null)
+ if (hostXml == null)
throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);
-
XPath xpath = factory.newXPath();
try {
XPathExpression expr = xpath.compile(xpathExpression);
@@ -379,7 +367,6 @@ public class AbstractBaseDiscovery {
}
}
-
/**
* Helper class that holds information about the host,port tuple
*/
@@ -401,11 +388,7 @@ public class AbstractBaseDiscovery {
@Override
public String toString() {
- return "HostPort{" +
- "host='" + host + '\'' +
- ", port=" + port +
- ", isLocal=" + isLocal +
- '}';
+ return "HostPort{" + "host='" + host +
'\'' + ", port=" + port + ", isLocal=" + isLocal +
'}';
}
}
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HostControllerComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HostControllerComponent.java
index b46b108..6212650 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HostControllerComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HostControllerComponent.java
@@ -44,8 +44,8 @@ public class HostControllerComponent extends BaseServerComponent
implements Oper
}
@Override
- public OperationResult invokeOperation(String name,
- Configuration parameters) throws
InterruptedException, Exception {
+ public OperationResult invokeOperation(String name, Configuration parameters) throws
InterruptedException,
+ Exception {
if (name.equals("start")) {
return startServer(AS7Mode.DOMAIN);
@@ -54,58 +54,55 @@ public class HostControllerComponent extends BaseServerComponent
implements Oper
} else if (name.equals("shutdown")) {
// This is a bit trickier, as it needs to be executed on the level on
/host=xx
- String domainHost =
pluginConfiguration.getSimpleValue("domainHost","");
+ String domainHost =
pluginConfiguration.getSimpleValue("domainHost", "");
if (domainHost.isEmpty()) {
OperationResult result = new OperationResult();
result.setErrorMessage("No domain host found - can not
continue");
return result;
}
- Operation op = new
Operation("shutdown","host",domainHost);
+ Operation op = new Operation("shutdown", "host",
domainHost);
Result res = getASConnection().execute(op);
- return postProcessResult(name,res);
- }
- else if (name.equals("installRhqUser")) {
+ return postProcessResult(name, res);
+ } else if (name.equals("installRhqUser")) {
return installManagementUser(parameters, pluginConfiguration, AS7Mode.HOST);
}
-
// Defer other stuff to the base component for now
return super.invokeOperation(name, parameters);
}
-
@Override
public CreateResourceReport createResource(CreateResourceReport report) {
// If Content is to be deployed, call the deployContent method
- if (report.getPackageDetails()!=null)
+ if (report.getPackageDetails() != null)
return super.deployContent(report);
// TODO check for types of children -- this is server group only at the moment.
String name = report.getUserSpecifiedResourceName();
Address address = new Address(path);
- address.add("server-group",name);
- Operation op = new Operation("add",address);
+ address.add("server-group", name);
+ Operation op = new Operation("add", address);
Configuration rc = report.getResourceConfiguration();
- String profile = rc.getSimpleValue("profile","");
+ String profile = rc.getSimpleValue("profile", "");
if (profile.isEmpty()) {
report.setErrorMessage("No profile given");
report.setStatus(CreateResourceStatus.FAILURE);
return report;
}
- op.addAdditionalProperty("profile",profile);
- String socketBindingGroup =
rc.getSimpleValue("socket-binding-group","");
+ op.addAdditionalProperty("profile", profile);
+ String socketBindingGroup = rc.getSimpleValue("socket-binding-group",
"");
if (socketBindingGroup.isEmpty()) {
report.setErrorMessage("No socket-binding-group given");
report.setStatus(CreateResourceStatus.FAILURE);
return report;
}
- op.addAdditionalProperty("socket-binding-group",socketBindingGroup);
+ op.addAdditionalProperty("socket-binding-group", socketBindingGroup);
PropertySimple offset = rc.getSimple("socket-binding-port-offset");
- if (offset!=null && offset.getStringValue()!=null)
-
op.addAdditionalProperty("socket-binding-port-offset",offset.getIntegerValue());
+ if (offset != null && offset.getStringValue() != null)
+ op.addAdditionalProperty("socket-binding-port-offset",
offset.getIntegerValue());
// TODO add jvm info
Result res = getASConnection().execute(op);
@@ -113,8 +110,7 @@ public class HostControllerComponent extends BaseServerComponent
implements Oper
report.setResourceKey(address.getPath());
report.setResourceName(name);
report.setStatus(CreateResourceStatus.SUCCESS);
- }
- else {
+ } else {
report.setErrorMessage(res.getFailureDescription());
report.setStatus(CreateResourceStatus.FAILURE);
report.setException(res.getRhqThrowable());
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
index 5890ca2..3d937c0 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
@@ -31,7 +31,6 @@ import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.event.log.LogFileEventResourceComponentHelper;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
-import org.rhq.core.pluginapi.inventory.ProcessScanResult;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.modules.plugins.jbossas7.json.Address;
@@ -64,10 +63,9 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
String hostName = hcConfig.getSimpleValue("domainHost",
"master"); // TODO good default?
HostInfo hostInfo = getHostInfo(hostName);
- if (hostInfo==null)
+ if (hostInfo == null)
return discoveredResources;
-
try {
// get the HostController, as this is an indicator for managed AS
@@ -85,7 +83,7 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery implements
Resourc
config.put(new PropertySimple("socket-binding-group",
serverInfo.bindingGroup));
} else {
String group = resolveSocketBindingGroup(serverInfo.group);
- config.put(new
PropertySimple("socket-binding-group",group));
+ config.put(new PropertySimple("socket-binding-group",
group));
}
config.put(new PropertySimple("socket-binding-port-offset",
serverInfo.portOffset));
@@ -95,8 +93,9 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery implements
Resourc
// get from the domain or other place as soon as the domain provides it.
//XXX hardcoded separators?
- String serverLog =
hcConfig.getSimpleValue("baseDir","/tmp")+File.separator+"domain/servers/"+serverInfo.name+"/log/server.log";
- initLogEventSourcesConfigProp(serverLog,config);
+ String serverLog = hcConfig.getSimpleValue("baseDir",
"/tmp") + File.separator + "domain/servers/"
+ + serverInfo.name + "/log/server.log";
+ initLogEventSourcesConfigProp(serverLog, config);
String version;
String resourceDescription;
@@ -107,43 +106,42 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
version = "EAP " + hostInfo.productVersion;
resourceDescription = "Managed JBoss Enterprise Application
Platform 6 server";
resourceName = "EAP " + resourceName;
- }
- else if (hostInfo.productName.equalsIgnoreCase("EDG")) {
+ } else if (hostInfo.productName.equalsIgnoreCase("EDG")) {
version = "EDG " + hostInfo.productVersion;
resourceDescription = "Managed JBoss Enterprise Data Grid 6
server";
- }
- else {
+ } else {
resourceDescription = "Managed AS7 server";
version = hostInfo.releaseVersion;
}
DiscoveredResourceDetails detail = new
DiscoveredResourceDetails(discoveryContext.getResourceType(), // ResourceType
- hostName + "/" + serverInfo.name, // key
- resourceName, // Name
- version, // TODO get from Domain as soon as it is provided
- resourceDescription, // Description
- config, null);
+ hostName + "/" + serverInfo.name, // key
+ resourceName, // Name
+ version, // TODO get from Domain as soon as it is provided
+ resourceDescription, // Description
+ config, null);
// Add to return values
discoveredResources.add(detail);
log.info("Discovered new ... " +
discoveryContext.getResourceType() + ", " + serverInfo);
}
} catch (Exception e) {
- log.warn("Discovery for a " + discoveryContext.getResourceType() +
" failed for process " + " :" + e.getMessage());
+ log.warn("Discovery for a " + discoveryContext.getResourceType() +
" failed for process " + " :"
+ + e.getMessage());
}
return discoveredResources;
}
private String resolveSocketBindingGroup(String serverGroup) {
- Address address = new Address("server-group",serverGroup);
- Operation operation = new
ReadAttribute(address,"socket-binding-group");
+ Address address = new Address("server-group", serverGroup);
+ Operation operation = new ReadAttribute(address,
"socket-binding-group");
Result result = parentComponent.getASConnection().execute(operation);
return (String) result.getResult();
}
private List<ServerInfo> getManagedServers(String domainHost) {
- Address address = new Address("host",domainHost);
- Operation operation = new ReadChildrenNames(address,"server-config");
+ Address address = new Address("host", domainHost);
+ Operation operation = new ReadChildrenNames(address, "server-config");
ASConnection connection = parentComponent.getASConnection();
Result res = connection.execute(operation);
List<String> servers = (List<String>) res.getResult();
@@ -153,15 +151,15 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
info.name = server;
ret.add(info);
- address= new Address("host",domainHost);
- address.add("server-config",server);
+ address = new Address("host", domainHost);
+ address.add("server-config", server);
operation = new ReadResource(address);
ComplexResult cres = connection.executeComplex(operation);
- Map<String,Object> map = cres.getResult();
+ Map<String, Object> map = cres.getResult();
info.group = (String) map.get("group");
- info.autoStart = (Boolean)map.get("auto-start");
+ info.autoStart = (Boolean) map.get("auto-start");
Integer offset = (Integer) map.get("socket-binding-port-offset");
- if (offset!=null)
+ if (offset != null)
info.portOffset = offset;
info.bindingGroup = (String) map.get("socket-binding-group");
}
@@ -170,7 +168,7 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
}
private HostInfo getHostInfo(String domainHost) {
- Address address = new Address("host",domainHost);
+ Address address = new Address("host", domainHost);
Operation operation = new ReadResource(address);
HostInfo info = new HostInfo();
@@ -178,11 +176,11 @@ public class ManagedASDiscovery extends AbstractBaseDiscovery
implements Resourc
if (!cres.isSuccess())
return null;
- Map<String,Object> map = cres.getResult();
+ Map<String, Object> map = cres.getResult();
info.releaseCodeName = (String) map.get("release-codename");
- info.releaseVersion = (String)map.get("release-version");
+ info.releaseVersion = (String) map.get("release-version");
info.productName = (String) map.get("product-name");
- info.productVersion = (String)map.get("product-version");
+ info.productVersion = (String) map.get("product-version");
return info;
}
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/OperationJsonTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/OperationJsonTest.java
index 2dcd49f..aefd5ee 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/OperationJsonTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/OperationJsonTest.java
@@ -18,21 +18,18 @@
*/
package org.rhq.modules.plugins.jbossas7;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.annotate.JsonAnyGetter;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.testng.annotations.Test;
import org.rhq.modules.plugins.jbossas7.json.Address;
import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
-import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
import org.rhq.modules.plugins.jbossas7.json.Result;
import org.rhq.modules.plugins.jbossas7.json.WriteAttribute;
@@ -42,28 +39,26 @@ import org.rhq.modules.plugins.jbossas7.json.WriteAttribute;
@Test
public class OperationJsonTest {
+ public void operationSerDeserTest() throws Exception {
- public void operationSerDeserTest() throws Exception{
-
- Address address= new Address();
- address.add("subsystem","web");
- address.add("connector","http");
-
- Operation operation = new
WriteAttribute(address,"socket-binding","jndi");
+ Address address = new Address();
+ address.add("subsystem", "web");
+ address.add("connector", "http");
+ Operation operation = new WriteAttribute(address, "socket-binding",
"jndi");
ObjectMapper mapper = new ObjectMapper();
String result = mapper.writeValueAsString(operation);
- Operation op = mapper.readValue(result,Operation.class);
- assert op!=null;
- assert op.getOperation()!=null : "op.operation was null!";
+ Operation op = mapper.readValue(result, Operation.class);
+ assert op != null;
+ assert op.getOperation() != null : "op.operation was null!";
assert op.getOperation().equals(operation.getOperation()) : "Operation is
" + op.getOperation();
- assert op.getName()!=null : "op.getName is null";
- assert op.getName().equals("socket-binding") : "attribute name is
" + op.getName() + " and not 'socket-binding'";
+ assert op.getName() != null : "op.getName is null";
+ assert op.getName().equals("socket-binding") : "attribute name is
" + op.getName()
+ + " and not 'socket-binding'";
assert op.getValue().equals("jndi") : "attribute value is "
+ op.getValue();
- assert op.getAddress().size()==2 : "Address did not contain 2 parts, but
" + op.getAddress().size();
-
+ assert op.getAddress().size() == 2 : "Address did not contain 2 parts, but
" + op.getAddress().size();
}
@@ -72,23 +67,23 @@ public class OperationJsonTest {
String json = "{\"myKey\":\"myValue\"}";
ObjectMapper mapper = new ObjectMapper();
- PROPERTY_VALUE pv = mapper.readValue(json,PROPERTY_VALUE.class);
+ PROPERTY_VALUE pv = mapper.readValue(json, PROPERTY_VALUE.class);
assert pv.getKey().equals("myKey") : "Key is " +
pv.getKey();
- assert pv.getValue().equals("myValue"): "Value is " +
pv.getValue();
+ assert pv.getValue().equals("myValue") : "Value is " +
pv.getValue();
}
public void anyPayloadTest() throws Exception {
- Address address= new Address();
- address.add("/server-group","newOne");
+ Address address = new Address();
+ address.add("/server-group", "newOne");
- Map<String,Object> props = new HashMap<String, Object>();
- props.put("profile","default");
- props.put("someBool",true);
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("profile", "default");
+ props.put("someBool", true);
- Operation operation = new Operation("add",address,props);
- operation.addAdditionalProperty("foo","bar");
+ Operation operation = new Operation("add", address, props);
+ operation.addAdditionalProperty("foo", "bar");
ObjectMapper mapper = new ObjectMapper();
@@ -98,7 +93,7 @@ public class OperationJsonTest {
assert !result.contains("name") : "Result contains a name property
but should not : " + result;
assert !result.contains("null") : "Result contains null values but
should not : " + result;
- Operation op = mapper.readValue(result,Operation.class);
+ Operation op = mapper.readValue(result, Operation.class);
assert op.getOperation().equals(operation.getOperation()) : "Operation is
" + op.getOperation();
assert op.getAdditionalProperties().containsKey("someBool") : "Key
someBool not found ";
Object someBool = op.getAdditionalProperties().get("someBool");
@@ -107,11 +102,11 @@ public class OperationJsonTest {
}
public void addPropsTest() throws Exception {
- Address address= new Address();
- address.add("/server-group","newOne");
+ Address address = new Address();
+ address.add("/server-group", "newOne");
- Operation operation = new Operation("add",address);
- operation.addAdditionalProperty("foo","bar");
+ Operation operation = new Operation("add", address);
+ operation.addAdditionalProperty("foo", "bar");
ObjectMapper mapper = new ObjectMapper();
@@ -125,7 +120,7 @@ public class OperationJsonTest {
String resultString = "{\"outcome\" : \"success\",
\"result\" : \"no metrics available\"}";
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
assert result != null;
assert result.getOutcome().equals("success");
@@ -137,18 +132,19 @@ public class OperationJsonTest {
String resultString = "{\"outcome\" : \"success\",
\"result\" : \"DISABLED\"}";
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
assert result != null;
assert result.getOutcome().equals("success");
assert result.isSuccess();
}
+
public void simpleResultWithFailure() throws Exception {
String resultString = "{\"outcome\" : \"failed\",
\"failure-description\" : [{ \"java.util.NoSuchElementException\" :
\"No child 'profile' exists\" }]}";
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
assert result != null;
assert result.getOutcome().equals("failed");
@@ -156,7 +152,7 @@ public class OperationJsonTest {
assert result.getResult() == null;
assert result.getFailureDescription() != null;
-// assert result.getFailureDescription().size() == 1;
+ // assert result.getFailureDescription().size() == 1;
}
public void complexResult1() throws Exception {
@@ -164,18 +160,18 @@ public class OperationJsonTest {
String resultString = " {\"outcome\" : \"success\",
\"result\" : {\"alias\" : [\"example.com\"],
\"access-log\" : null, \"rewrite\" : null}}";
ObjectMapper mapper = new ObjectMapper();
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
assert result != null;
assert result.getOutcome().equals("success");
assert result.isSuccess();
- assert result.getResult().size()==3;
+ assert result.getResult().size() == 3;
String rewrite = (String) result.getResult().get("rewrite");
assert rewrite == null;
List<String> aliases = (List<String>)
result.getResult().get("alias");
assert aliases != null;
- assert aliases.size()==1;
+ assert aliases.size() == 1;
assert aliases.get(0).equals("example.com");
}
@@ -184,13 +180,13 @@ public class OperationJsonTest {
String resultString =
"{\"outcome\":\"success\",\"result\":[\"standard-sockets\",\"messaging-sockets\"],\"response-headers\":null,
\"rolled-back\" : false}";
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
assert result != null;
assert result.getOutcome().equals("success");
assert result.isSuccess();
List<String> stringList = (List<String>) result.getResult();
- assert stringList.size()==2;
+ assert stringList.size() == 2;
assert stringList.get(0).equals("standard-sockets");
assert stringList.get(1).equals("messaging-sockets");
assert !result.isRolledBack();
@@ -202,7 +198,7 @@ public class OperationJsonTest {
String resultString = "{\"outcome\":\"failed\",
\"rolled-back\" : true}";
ObjectMapper mapper = new ObjectMapper();
- Result result = mapper.readValue(resultString,Result.class);
+ Result result = mapper.readValue(resultString, Result.class);
assert result != null;
assert result.getOutcome().equals("failed");
@@ -211,77 +207,69 @@ public class OperationJsonTest {
}
-
public void complexResult2() throws Exception {
-
- String resultString =
- "{\n" +
- " \"outcome\" : \"failed\",\n" +
- " \"result\" : {\n" +
- " \"server-groups\" : {\n" +
- " \"main-server-group\" : {\n" +
- " \"server-one\" : {\n" +
- " \"host\" : \"local\",\n"
+
- " \"response\" : {\n" +
- " \"outcome\" :
\"success\",\n" +
- " \"result\" : null,\n" +
- " \"compensating-operation\" :
{\n" +
- " \"operation\" :
\"add\",\n" +
- " \"address\" : [ {\n" +
- " \"subsystem\" :
\"jms\"\n" +
- " }, {\n" +
- " \"queue\" :
\"flubbr\"\n" +
- " } ],\n" +
- " \"durable\" :
\"true\",\n" +
- " \"entries\" : [
\"PropertySimple[id=0, name=entries, value=flubbr, override=null]\" ]\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"server-two\" : {\n" +
- " \"host\" : \"local\",\n"
+
- " \"response\" : {\n" +
- " \"outcome\" :
\"success\",\n" +
- " \"result\" : null,\n" +
- " \"compensating-operation\" :
{\n" +
- " \"operation\" :
\"add\",\n" +
- " \"address\" : [ {\n" +
- " \"subsystem\" :
\"jms\"\n" +
- " }, {\n" +
- " \"queue\" :
\"flubbr\"\n" +
- " } ],\n" +
- " \"durable\" :
\"true\",\n" +
- " \"entries\" : [
\"PropertySimple[id=0, name=entries, value=flubbr, override=null]\" ]\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"server-demo\" : {\n" +
- " \"host\" : \"local\",\n"
+
- " \"response\" : {\n" +
- " \"outcome\" :
\"failed\",\n" +
- " \"failure-description\" : \"No
handler for add at address [\\n (\\\"host\\\" =>
\\\"local\\\"),\\n (\\\"server\\\" =>
\\\"server-demo\\\"),\\n (\\\"subsystem\\\" =>
\\\"jms\\\"),\\n (\\\"queue\\\" =>
\\\"flubbr\\\")\\n]\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " },\n" +
- " \"failure-description\" : \"Operation was
not applied successfully to any servers\"\n" +
- "}";
+ String resultString = "{\n"
+ + " \"outcome\" : \"failed\",\n"
+ + " \"result\" : {\n"
+ + " \"server-groups\" : {\n"
+ + " \"main-server-group\" : {\n"
+ + " \"server-one\" : {\n"
+ + " \"host\" : \"local\",\n"
+ + " \"response\" : {\n"
+ + " \"outcome\" : \"success\",\n"
+ + " \"result\" : null,\n"
+ + " \"compensating-operation\" : {\n"
+ + " \"operation\" : \"add\",\n"
+ + " \"address\" : [ {\n"
+ + " \"subsystem\" : \"jms\"\n"
+ + " }, {\n"
+ + " \"queue\" : \"flubbr\"\n"
+ + " } ],\n"
+ + " \"durable\" : \"true\",\n"
+ + " \"entries\" : [ \"PropertySimple[id=0,
name=entries, value=flubbr, override=null]\" ]\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"server-two\" : {\n"
+ + " \"host\" : \"local\",\n"
+ + " \"response\" : {\n"
+ + " \"outcome\" : \"success\",\n"
+ + " \"result\" : null,\n"
+ + " \"compensating-operation\" : {\n"
+ + " \"operation\" : \"add\",\n"
+ + " \"address\" : [ {\n"
+ + " \"subsystem\" : \"jms\"\n"
+ + " }, {\n"
+ + " \"queue\" : \"flubbr\"\n"
+ + " } ],\n"
+ + " \"durable\" : \"true\",\n"
+ + " \"entries\" : [ \"PropertySimple[id=0,
name=entries, value=flubbr, override=null]\" ]\n"
+ + " }\n"
+ + " }\n"
+ + " },\n"
+ + " \"server-demo\" : {\n"
+ + " \"host\" : \"local\",\n"
+ + " \"response\" : {\n"
+ + " \"outcome\" : \"failed\",\n"
+ + " \"failure-description\" : \"No handler for
add at address [\\n (\\\"host\\\" => \\\"local\\\"),\\n
(\\\"server\\\" => \\\"server-demo\\\"),\\n
(\\\"subsystem\\\" => \\\"jms\\\"),\\n (\\\"queue\\\"
=> \\\"flubbr\\\")\\n]\"\n"
+ + " }\n" + " }\n" + " }\n"
+ " }\n" + " },\n"
+ + " \"failure-description\" : \"Operation was not
applied successfully to any servers\"\n" + "}";
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
- ComplexResult result = mapper.readValue(resultString,ComplexResult.class);
+ ComplexResult result = mapper.readValue(resultString, ComplexResult.class);
assert !result.isSuccess() : "Result should be 'failed', but was
not";
assert result.getFailureDescription().startsWith("Operation was not applied
successfully to any servers");
assert result.getResult().containsKey("server-groups");
- Map<String,Object> sgs = (Map<String, Object>)
result.getResult().get("server-groups");
+ Map<String, Object> sgs = (Map<String, Object>)
result.getResult().get("server-groups");
assert sgs.containsKey("main-server-group");
- Map<String,Object> mainSg = (Map<String, Object>)
sgs.get("main-server-group");
- assert mainSg.size()==3 : "Main server group does not have 3 servers, but
" + mainSg.size();
- Map<String,Object> s3 = (Map<String, Object>)
mainSg.get("server-demo");
- Map<String,Object> response = (Map<String, Object>)
s3.get("response");
- assert response!=null;
+ Map<String, Object> mainSg = (Map<String, Object>)
sgs.get("main-server-group");
+ assert mainSg.size() == 3 : "Main server group does not have 3 servers, but
" + mainSg.size();
+ Map<String, Object> s3 = (Map<String, Object>)
mainSg.get("server-demo");
+ Map<String, Object> response = (Map<String, Object>)
s3.get("response");
+ assert response != null;
}