modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASUploadConnection.java
| 144 ++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
| 4
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
| 27
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
| 7
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
| 289 ++++++++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ServerGroupComponent.java
| 113 +++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/SubsystemDiscovery.java
| 51 +
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/PROPERTY_VALUE.java
| 7
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/ReadChildrenNames.java
| 37 +
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
| 99 ++-
10 files changed, 738 insertions(+), 40 deletions(-)
New commits:
commit 7bda199733e460362365e15793cc607b25acff48
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Apr 6 21:49:39 2011 +0200
Improve detection of child resources
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index 5dbd0b3..644fc24 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -52,6 +52,7 @@ import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -329,6 +330,9 @@ public class BaseComponent implements ResourceComponent,
MeasurementFacet, Confi
}
protected List<PROPERTY_VALUE> pathToAddress(String path) {
+ if (path==null || path.isEmpty())
+ return Collections.emptyList();
+
if (path.endsWith("/"))
path = path.substring(0,path.length()-1);
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
index a06a296..21005a9 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
@@ -114,8 +114,11 @@ public class DomainComponent extends BaseComponent implements
OperationFacet{
} else if (what.equals("destination")) {
address.addAll(pathToAddress(getPath()));
String newName = parameters.getSimpleValue("name","");
- String type =
parameters.getSimpleValue("type","Queue").toLowerCase();
- address.add(new PROPERTY_VALUE(type,newName));
+// String type =
parameters.getSimpleValue("type","Queue").toLowerCase();
+// address.add(new PROPERTY_VALUE(type,newName));
+ String queueName =
parameters.getSimpleValue("queue-address","");
+ Map<String,Object> props = new HashMap<String, Object>();
+ props.put("queue-address",queueName);
operation = new Operation(op,address);
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/SubsystemDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/SubsystemDiscovery.java
index 1c498d1..9aea097 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/SubsystemDiscovery.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/SubsystemDiscovery.java
@@ -23,11 +23,13 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-import org.rhq.modules.plugins.jbossas7.json.Subsystem;
+import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
+import org.rhq.modules.plugins.jbossas7.json.ReadChildrenNames;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -35,7 +37,6 @@ import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
/**
* Discover subsystems
@@ -83,47 +84,63 @@ public class SubsystemDiscovery implements
ResourceDiscoveryComponent<BaseCompon
System.out.println("total path: [" + path + "]");
- JsonNode json = connection.getLevelData(path,recursive, false);
+ JsonNode json ;
+ if (!recursive)
+ json = connection.getLevelData(path,recursive, false);
+ else {
+ List<PROPERTY_VALUE> addr ;
+ addr = parentComponent.pathToAddress(parentPath);
+ String childType = cpath.substring(0, cpath.length() - 2);
+ if (childType.startsWith("/"))
+ childType = childType.substring(1);
+ json = connection.execute(new ReadChildrenNames(addr, childType));
+ }
if (!connection.isErrorReply(json)) {
if (recursive) {
int i = path.lastIndexOf("/");
String subPath = path.substring(i+1);
- JsonNode subNode = json.findPath(subPath);
+ JsonNode subNode = json.findPath("result");
if (subNode==null || subNode.isNull())
subNode = json.get(subPath); // TODO clean this up. to get the
'key' in a path from the AS we need to use get()
- Map<String,Subsystem> subsystemMap = mapper.readValue(subNode,new
TypeReference<Map<String,Subsystem>>() {});
+// Map<String,Subsystem> subsystemMap = mapper.readValue(subNode,new
TypeReference<Map<String,Subsystem>>() {});
+ if (subNode.isArray()) {
- if (subsystemMap==null) {
- log.warn("SubsystemMap was null for path [" + path +
"] and subPath ["+ subPath + "] and subNode [" + subNode +
"]");
- return Collections.emptySet();
- }
+ Iterator<JsonNode> iter = subNode.getElements();
+// if (subsystemMap==null) {
+// log.warn("SubsystemMap was null for path [" + path +
"] and subPath ["+ subPath + "] and subNode [" + subNode +
"]");
+// return Collections.emptySet();
+// }
+ while (iter.hasNext()) {
+ JsonNode node = iter.next();
+ String val = node.getTextValue();
- for (Map.Entry<String,Subsystem> entry: subsystemMap.entrySet()) {
- String key = entry.getKey();
- Subsystem subsystem = entry.getValue();
- String newPath = cpath.replaceAll("\\*",key);
+ String newPath = cpath.replaceAll("\\*",val);
Configuration config2 = context.getDefaultPluginConfiguration();
PropertySimple pathProp = new
PropertySimple("path",newPath);
config2.put(pathProp);
- String resKey = context.getParentResourceContext().getResourceKey() +
"/" + key;
+ String resKey = context.getParentResourceContext().getResourceKey() +
"/" + val;
String name = resKey.substring(resKey.lastIndexOf("/") +
1);
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
context.getResourceType(), // DataType
- path + "/" + key, // Key
+ path + "/" + val, // Key
name, // Name
null, // Version
- subsystem.description, // Description
+ "TODO", // subsystem.description, // Description
config2,
null);
details.add(detail);
}
+ }
+ else {
+ System.out.println("subnode was no array");
+ }
}
else {
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/PROPERTY_VALUE.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/PROPERTY_VALUE.java
index b2c8223..efe389b 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/PROPERTY_VALUE.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/PROPERTY_VALUE.java
@@ -59,4 +59,11 @@ public class PROPERTY_VALUE implements Serializable{
this.value = value;
}
+ @Override
+ public String toString() {
+ return "PROPERTY_VALUE{" +
+ "key='" + key + '\'' +
+ ", value='" + value + '\'' +
+ '}';
+ }
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/ReadChildrenNames.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/ReadChildrenNames.java
new file mode 100644
index 0000000..8c5b37c
--- /dev/null
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/ReadChildrenNames.java
@@ -0,0 +1,37 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.modules.plugins.jbossas7.json;
+
+import java.util.List;
+
+/**
+ * Operation that reads children of a given type from an address
+ * @author Heiko W. Rupp
+ */
+public class ReadChildrenNames extends Operation {
+
+ /**
+ * Reas children names of a given type below a given address
+ * @param address Address to look at e.g. /profile/default/subsystem/messaging
+ * @param childType e.g. queue
+ */
+ public ReadChildrenNames(List<PROPERTY_VALUE> address, String childType) {
+ super("read-children-names",address,"child-type",childType);
+ }
+}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 6741bb3..258da2c 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -51,7 +51,7 @@
version="4.0.0-SNAPSHOT"
- <depends plugin="JMX" useClasses="true"/>
+<!-- <depends plugin="JMX" useClasses="true"/> -->
<!-- TODO I think we should introduce an abstract AS7 plugin that contains some
base functionality and then
@@ -284,6 +284,7 @@
<server name="Messaging"
discovery="SubsystemDiscovery"
class="DomainComponent"
+ description="The underlying HornetQ based messaging subsystem"
singleton="true"
<runs-inside>
@@ -298,12 +299,15 @@
<operation name="destination:add" displayName="Add
destination" description="Add a Queue or Topic">
<parameters>
<c:simple-property name="name" description="Name of the
Destination" required="true"/>
+ <c:simple-property name="queue-address"
description="The queue address defines what address is used for routing
messages." required="true"/>
<c:simple-property name="type" description="Type of
Destination to create" default="Queue">
<c:property-options>
<c:option value="Queue"/>
<c:option value="Topic"/>
</c:property-options>
</c:simple-property>
+ <c:simple-property name="filter" description="The queue
message filter definition."/>
+ <c:simple-property name="durable" description="Defines
whether the queue is durable." type="boolean"
default="false"/>
</parameters>
<results>
<c:simple-property name="operationResult"/>
@@ -329,7 +333,7 @@
class="BaseComponent"
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/acceptor"/>
+ <c:simple-property name="path" readOnly="true"
default="acceptor"/>
</plugin-configuration>
</service>
<service name="MessagingConnector"
@@ -337,17 +341,65 @@
class="BaseComponent"
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/connector"/>
+ <c:simple-property name="path" readOnly="true"
default="connector"/>
</plugin-configuration>
</service>
- <service name="Queue"
+ <service name="HQueue"
discovery="SubsystemDiscovery"
class="BaseComponent"
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/queue/*"/>
+ <c:simple-property name="path" readOnly="true"
default="queue/*"/>
+ </plugin-configuration>
+ <resource-configuration>
+ <c:simple-property name="queue-address"
required="true"/>
+ <c:simple-property name="filter" />
+ <c:simple-property name="durable"
type="boolean"/>
+ </resource-configuration>
+
+ </service>
+ </server>
+
+ <server name="JMS"
+ discovery="SubsystemDiscovery"
+ class="DomainComponent"
+ description="The JMS messaging subsystem"
+ singleton="true"
+
+ <runs-inside>
+ <parent-resource-type name="Profile"
plugin="jboss-as-7"/>
+ <parent-resource-type name="JBossAS7-Standalone"
plugin="jboss-as-7"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="path" readOnly="true"
default="/subsystem/jms"/>
+ </plugin-configuration>
+
+ <service name="Queue"
+ discovery="SubsystemDiscovery"
+ class="BaseComponent"
+
+ <plugin-configuration>
+ <c:simple-property name="path" readOnly="true"
default="queue/*"/>
</plugin-configuration>
</service>
+ <service name="Topic"
+ discovery="SubsystemDiscovery"
+ class="BaseComponent"
+
+ <plugin-configuration>
+ <c:simple-property name="path" readOnly="true"
default="topic/*"/>
+ </plugin-configuration>
+ </service>
+ <service name="Connection-Factory"
+ discovery="SubsystemDiscovery"
+ class="BaseComponent"
+
+ <plugin-configuration>
+ <c:simple-property name="path" readOnly="true"
default="connection-factory/*"/>
+ </plugin-configuration>
+ </service>
+
</server>
<server name="JBossWeb"
@@ -377,9 +429,9 @@
<metric property="bytesSent"
measurementType="trendsup"/>
<metric property="bytesReceived"
measurementType="trendsup"/>
<metric property="processingTime"
measurementType="trendsup"/>
- <metric property="errorCount"
measurementType="trendsup"/>
+ <metric property="errorCount"
measurementType="trendsup" displayType="summary"/>
<metric property="maxTime" />
- <metric property="requestCount"
measurementType="trendsup"/>
+ <metric property="requestCount"
measurementType="trendsup" displayType="summary"/>
<resource-configuration>
<c:simple-property name="protocol"
required="false" description="The web connector protocol."/>
@@ -431,7 +483,7 @@
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/data-source/*"/>
+ <c:simple-property name="path" readOnly="true"
default="data-source/*"/>
</plugin-configuration>
</service>
@@ -442,7 +494,7 @@
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/xa-data-source/*"/>
+ <c:simple-property name="path" readOnly="true"
default="xa-data-source/*"/>
</plugin-configuration>
</service>
@@ -453,7 +505,7 @@
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/jdbc-driver/*"/>
+ <c:simple-property name="path" readOnly="true"
default="jdbc-driver/*"/>
</plugin-configuration>
</service>
commit f2dc89709b73b7506403f04ff36dc894a44232f5
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Apr 6 12:28:18 2011 +0200
Detect Managed AS through hosts.xml , start with deployments.
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASUploadConnection.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASUploadConnection.java
new file mode 100644
index 0000000..f3e9ee0
--- /dev/null
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASUploadConnection.java
@@ -0,0 +1,144 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.modules.plugins.jbossas7;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.jackson.JsonNode;
+
+/**
+ * Connection for uploading of content.
+ * Partially taken from
https://github.com/jbossas/jboss-as/blob/master/testsuite/smoke/src/test/...
+ *
+ * @author Jonathan Pearlin (of the original code)
+ * @author Heiko W. Rupp
+ */
+public class ASUploadConnection {
+
+ private static final String BOUNDARY =
"-----------------------------261773107125236";
+
+ private static final String CRLF = "\r\n";
+
+ private static final String POST_REQUEST_METHOD = "POST";
+
+ private static final String UPLOAD_URL =
"http://localhost:9990/domain-api/add-content";
+
+ private final Log log = LogFactory.getLog(ASUploadConnection.class);
+
+ BufferedOutputStream os = null;
+ BufferedInputStream is = null;
+ private HttpURLConnection connection;
+
+ public OutputStream getOutputStream(String fileName) {
+ try {
+ // Create the HTTP connection to the upload URL
+ connection = (HttpURLConnection) new URL(UPLOAD_URL).openConnection();
+ connection.setDoInput(true);
+ connection.setDoOutput(true);
+ connection.setRequestMethod(POST_REQUEST_METHOD);
+
+ // Grab the test WAR file and get a stream to its contents to be included in
the POST.
+ os = new BufferedOutputStream(connection.getOutputStream());
+ os.write(buildPostRequestHeader(fileName));
+
+ return os;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public JsonNode finishUpload() {
+ try {
+ os.write(buildPostRequestFooter());
+ os.flush();
+
+ is = new BufferedInputStream(connection.getInputStream());
+ // TODO read from IN
+
+ } catch (IOException e) {
+ e.printStackTrace(); // TODO: Customise this generated block
+ }
+ finally {
+ closeQuietly(is);
+ closeQuietly(os);
+ }
+
+ return null;
+ }
+
+
+ private byte[] buildPostRequestHeader(String fileName) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(buildPostRequestHeaderSection("form-data;
name=\"test1\"", "", "test1"));
+ builder.append(buildPostRequestHeaderSection("form-data;
name=\"test2\"", "", "test2"));
+ builder.append(buildPostRequestHeaderSection("form-data;
name=\"file\"; filename=\""+fileName+"\"",
"application/octet-stream", ""));
+ return builder.toString().getBytes();
+ }
+
+ private String buildPostRequestHeaderSection(final String contentDisposition, final
String contentType, final String content) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(BOUNDARY);
+ builder.append(CRLF);
+ if(contentDisposition != null && contentDisposition.length() > 0) {
+ builder.append(String.format("Content-Disposition: %s",
contentDisposition));
+ }
+ builder.append(CRLF);
+ if(contentType != null && contentType.length() > 0) {
+ builder.append(String.format("Content-Type: %s", contentType));
+ }
+ builder.append(CRLF);
+ if(content != null && content.length() > 0) {
+ builder.append(content);
+ }
+ builder.append(CRLF);
+ return builder.toString();
+ }
+
+ private byte[] buildPostRequestFooter() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(CRLF);
+ builder.append(BOUNDARY);
+ builder.append("--");
+ builder.append(CRLF);
+ return builder.toString().getBytes();
+ }
+
+
+ private void closeQuietly(final Closeable closeable) {
+ if(closeable != null) {
+ try {
+ closeable.close();
+ } catch (final IOException e) {}
+ }
+ }
+}
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 5ea4bd7..8597d8f 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
@@ -1,3 +1,21 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
@@ -58,12 +76,9 @@ public class BaseProcessDiscovery implements
ResourceDiscoveryComponent
String serverNameFull;
String serverName;
String psName = psr.getProcessScan().getName();
- if (psName.equals("ProcessManager")) {
- serverNameFull = "ProcessManager";
- serverName = "ProcessManager";
- } else if (psName.equals("ASManager")) {
- serverName = "ASManager";
- serverNameFull = "ASManager";
+ if (psName.equals("ProcessController")) {
+ serverNameFull = "ProcessController";
+ serverName = "ProcessController";
} else if (psName.equals("HostController")) {
serverName = "HostController";
serverNameFull = "HostController";
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
new file mode 100644
index 0000000..86e3b99
--- /dev/null
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ManagedASDiscovery.java
@@ -0,0 +1,289 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.modules.plugins.jbossas7;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+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.core.system.ProcessInfo;
+
+/**
+ * Discovery class for managed AS 7 instances.
+ *
+ * @author Heiko W. Rupp
+ */
+public class ManagedASDiscovery implements ResourceDiscoveryComponent
+
+{
+
+ static final String DJBOSS_SERVER_BASE_DIR = "-Djboss.server.base.dir=";
+ static final String DORG_JBOSS_BOOT_LOG_FILE =
"-Dorg.jboss.boot.log.file=";
+ static final String DLOGGING_CONFIGURATION = "-Dlogging.configuration=";
+ static final int DEFAULT_MGMT_PORT = 9990;
+ private final Log log = LogFactory.getLog(this.getClass());
+ private Document hostXml;
+ private static final String DJBOSS_SERVER_HOME_DIR = "-Djboss.home.dir";
+
+ /**
+ * Run the auto-discovery
+ */
+ public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext discoveryContext) throws Exception {
+ Set<DiscoveredResourceDetails> discoveredResources = new
HashSet<DiscoveredResourceDetails>();
+
+
+ List<ProcessScanResult> scans =
discoveryContext.getAutoDiscoveredProcesses();
+
+ for (ProcessScanResult psr : scans) {
+
+ // get the HostController, as this is an indicator for managed AS
+ String psName = psr.getProcessScan().getName();
+ if (!psName.equals("HostController"))
+ continue;
+
+ // Now we have the host controller, lets get the host.xml file
+ // and obtain the servers from there.
+ ProcessInfo processInfo = psr.getProcessInfo();
+ readHostXml(processInfo);
+ String hostName = findHostName();
+ int port = getManagementPortFromHostXml();
+
+
+ List<ServerInfo> serverNames = getServersFromHostXml();
+ for (ServerInfo serverInfo : serverNames) {
+
+ Configuration config = discoveryContext.getDefaultPluginConfiguration();
+ config.put(new PropertySimple("domainHost",hostName));
+ config.put(new PropertySimple("group",serverInfo.group));
+ config.put(new PropertySimple("port",port));
+
+ // TODO this fails for the downed servers.
+ // get from the domain or other place as soon as the domain provides it.
+ initLogFile(scans, serverInfo.name, config,
getHomeDirFromCommandLine(processInfo.getCommandLine()));
+
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
+ discoveryContext.getResourceType(), // ResourceType
+ hostName + "/" + serverInfo.name, // key
+ serverInfo.name, // Name
+ null, // TODO real version - get from Domain as soon as it is
provided
+ "Managed AS 7 instance", // Description
+ config,
+ null
+ );
+
+ // Add to return values
+ discoveredResources.add(detail);
+ log.info("Discovered new ... " +
discoveryContext.getResourceType() + ", " + serverInfo);
+ }
+ }
+ return discoveredResources;
+ }
+
+ /**
+ * Loop through the Process scans for ManagedAS and if found extract the logfile
path.
+ * @param scans process scan results
+ * @param name server name to look for
+ * @param config config to put the info in
+ * @param basePath
+ */
+ private void initLogFile(List<ProcessScanResult> scans, String name,
Configuration config, String basePath) {
+
+ for (ProcessScanResult psr : scans) {
+ if (!psr.getProcessScan().getName().equals("ManagedAS"))
+ continue;
+
+ String[] commandLine = psr.getProcessInfo().getCommandLine();
+
+ String logFile = basePath + File.separator +
getLogFileFromCommandLine(commandLine);
+
+ if (logFile.contains(name))
+ initLogEventSourcesConfigProp(logFile,config);
+ }
+ }
+
+ private int getManagementPortFromHostXml() {
+ Element host = hostXml.getDocumentElement();
+ NodeList interfaceParent =
host.getElementsByTagName("management-interfaces");
+ if (interfaceParent ==null || interfaceParent.getLength()==0) {
+ log.warn("No <management-interfaces> found in host.xml");
+ return DEFAULT_MGMT_PORT;
+ }
+ NodeList mgmtInterfaces = interfaceParent.item(0).getChildNodes();
+ if (mgmtInterfaces==null || mgmtInterfaces.getLength()==0) {
+ log.warn("No <*-interface> found in host.xml");
+ return DEFAULT_MGMT_PORT;
+ }
+ for (int i = 0 ; i < mgmtInterfaces.getLength(); i++) {
+ if (!(mgmtInterfaces.item(i) instanceof Element))
+ continue;
+
+ Element mgmtInterface = (Element) mgmtInterfaces.item(i);
+ if (mgmtInterface.getNodeName().equals("http-interface")) {
+ String tmp = mgmtInterface.getAttribute("port");
+ int port = Integer.valueOf(tmp);
+ return port;
+ }
+ }
+ return DEFAULT_MGMT_PORT;
+ }
+
+ private List<ServerInfo> getServersFromHostXml() {
+
+ Element host = hostXml.getDocumentElement();
+ NodeList serversElement = host.getElementsByTagName("servers");
+ if (serversElement ==null || serversElement.getLength()==0) {
+ log.warn("No <servers> found in host.xml");
+ return Collections.emptyList();
+ }
+ NodeList servers = serversElement.item(0).getChildNodes();
+ if (servers==null || servers.getLength()==0) {
+ log.warn("No <server> found in host.xml");
+ return Collections.emptyList();
+ }
+ List<ServerInfo> result = new ArrayList<ServerInfo>();
+ for (int i = 0 ; i < servers.getLength(); i++) {
+ if (!(servers.item(i) instanceof Element))
+ continue;
+
+ ServerInfo info = new ServerInfo();
+ Element server = (Element) servers.item(i);
+ info.name = server.getAttribute("name");
+ info.group = server.getAttribute("group");
+ String autoStart = server.getAttribute("autoStart");
+ if (autoStart==null || autoStart.isEmpty())
+ autoStart = "false";
+ info.autoStart = Boolean.getBoolean(autoStart);
+
+ result.add(info);
+ }
+
+ return result;
+ }
+
+
+ private String findHostName() {
+ String hostName = hostXml.getDocumentElement().getAttribute("name");
+ return hostName;
+ }
+
+ private void readHostXml(ProcessInfo processInfo) {
+ String hostXmlFile = getHostXmlFileLocation(processInfo);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputStream is = new FileInputStream(hostXmlFile);
+ hostXml = builder.parse(is);
+ is.close();
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: Customise this generated block
+ }
+ }
+
+ /**
+ * Get the location of the host definition file (host.xml in domain mode,
standalone.xml
+ * in standalone mode.
+ *
+ * @param processInfo ProcessInfo structure containing the ENV variables
+ * @return The path to the definition file.
+ */
+ private String getHostXmlFileLocation(ProcessInfo processInfo) {
+
+ String home = getHomeDirFromCommandLine(processInfo.getCommandLine());
+ StringBuilder builder = new StringBuilder(home);
+ builder.append("/domain");
+ builder.append("/configuration");
+ builder.append("/host.xml");
+ return builder.toString();
+
+ }
+
+
+
+ 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 "";
+ }
+
+//-Dorg.jboss.boot.log.file=/devel/jbas7/jboss-as/build/target/jboss-7.0.0.Alpha2/domain/log/server-manager/boot.log
+//-Dlogging.configuration=file:/devel/jbas7/jboss-as/build/target/jboss-7.0.0.Alpha2/domain/configuration/logging.properties
+
+ String getLogFileFromCommandLine(String[] commandLine) {
+
+ for (String line: commandLine) {
+ if (line.startsWith(DORG_JBOSS_BOOT_LOG_FILE))
+ return line.substring(DORG_JBOSS_BOOT_LOG_FILE.length());
+ }
+ return "";
+ }
+
+ private void initLogEventSourcesConfigProp(String fileName, Configuration
pluginConfiguration) {
+
+ PropertyList logEventSources = pluginConfiguration
+ .getList(LogFileEventResourceComponentHelper.LOG_EVENT_SOURCES_CONFIG_PROP);
+
+ if (logEventSources==null)
+ return;
+
+ File serverLogFile = new File(fileName);
+
+ if (serverLogFile.exists() && !serverLogFile.isDirectory()) {
+ PropertyMap serverLogEventSource = new
PropertyMap("logEventSource");
+ serverLogEventSource.put(new PropertySimple(
+
LogFileEventResourceComponentHelper.LogEventSourcePropertyNames.LOG_FILE_PATH,
serverLogFile));
+ serverLogEventSource.put(new PropertySimple(
+ LogFileEventResourceComponentHelper.LogEventSourcePropertyNames.ENABLED,
Boolean.FALSE));
+ logEventSources.add(serverLogEventSource);
+ }
+ }
+
+ private class ServerInfo {
+ String name;
+ String group;
+ boolean autoStart;
+
+
+ }
+
+}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ServerGroupComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ServerGroupComponent.java
new file mode 100644
index 0000000..9650731
--- /dev/null
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ServerGroupComponent.java
@@ -0,0 +1,113 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.modules.plugins.jbossas7;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.jackson.JsonNode;
+
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.transfer.DeployPackageStep;
+import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
+import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
+import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
+import org.rhq.core.domain.resource.CreateResourceStatus;
+import org.rhq.core.pluginapi.content.ContentContext;
+import org.rhq.core.pluginapi.content.ContentFacet;
+import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+
+/**
+ * Component dealing with server group specific things
+ * @author Heiko W. Rupp
+ */
+public class ServerGroupComponent extends DomainComponent implements ContentFacet,
CreateChildResourceFacet {
+
+ private final Log log = LogFactory.getLog(ServerGroupComponent.class);
+
+ @Override
+ public List<DeployPackageStep> generateInstallationSteps(ResourcePackageDetails
packageDetails) {
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public DeployPackagesResponse deployPackages(Set<ResourcePackageDetails>
packages,
+ ContentServices contentServices) {
+
+ ContentContext cctx = context.getContentContext();
+
+ String uploadUrl = "http://localhost:9990/domain-api/add-content";
+
+ for (ResourcePackageDetails details : packages) {
+ ASUploadConnection uploadConnection = new ASUploadConnection();
+ OutputStream out = uploadConnection.getOutputStream(details.getFileName());
+ contentServices.downloadPackageBits(cctx, details.getKey(), out, false);
+ JsonNode result = uploadConnection.finishUpload();
+ }
+
+
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public RemovePackagesResponse removePackages(Set<ResourcePackageDetails>
packages) {
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type)
{
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public CreateResourceReport createResource(CreateResourceReport report) {
+
+
+ ResourcePackageDetails details = report.getPackageDetails();
+
+ ContentContext cctx = context.getContentContext();
+ ContentServices contentServices = cctx.getContentServices();
+ String resourceTypeName = report.getResourceType().getName();
+
+ ASUploadConnection connection = new ASUploadConnection();
+ OutputStream out = connection.getOutputStream(details.getFileName());
+// contentServices.downloadPackageBits(cctx,details.getKey(),out,false);
+ contentServices.downloadPackageBitsForChildResource(cctx, resourceTypeName,
details.getKey(), out);
+
+ JsonNode result = connection.finishUpload();
+ System.out.println(result);
+
+
+ report.setStatus(CreateResourceStatus.SUCCESS) ;
+
+ return report;
+
+ }
+}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 02b4bf8..6741bb3 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -71,7 +71,7 @@
&logSources;
</plugin-configuration>
- <process-scan name="ProcessManager"
query="process|basename|match=^java.*,arg|org.jboss.as.process-controller|match=.*"/>
+ <process-scan name="ProcessController"
query="process|basename|match=^java.*,arg|org.jboss.as.process-controller|match=.*"/>
<operation name="dummyOperation">
@@ -93,7 +93,7 @@
&logSources;
</plugin-configuration>
- <process-scan name="ProcessManager"
query="process|basename|match=^java.*,arg|org.jboss.as.host-controller|match=.*"/>
+ <process-scan name="HostController"
query="process|basename|match=^java.*,arg|org.jboss.as.host-controller|match=.*"/>
<operation name="dummyOperation">
@@ -132,16 +132,25 @@
<server name="ServerGroup"
description="Server groups on this domain"
discovery="SubsystemDiscovery"
- class="ServerGroupComponent">
+ class="ServerGroupComponent"
+
+ <!-- TODO move
operation to createDeletePolicy="create-only" -->
+
<plugin-configuration>
<c:simple-property name="path"
default="/server-group/*" readOnly="true"/>
</plugin-configuration>
+
+
+ <content name="deployment" category="deployable"
isCreationType="true" description="Deployments on this domain">
+ </content>
+
<resource-configuration>
<c:simple-property name="profile" />
<c:simple-property name="socket-binding-group"/>
<c:simple-property name="jvm"/>
<c:simple-property name="deployment"
required="false"/> <!-- TODO change structure. Or put below as resource?
-->
</resource-configuration>
+ <service name="Deployment" class="BaseComponent"
discovery="SubsystemDiscovery" createDeletePolicy="create-only"/>
</server>
<server name="Host"
description="Host involved in this domain"
@@ -171,9 +180,11 @@
</results>
</operation>
+<!--
<resource-configuration>
<c:list-property name="server-config" />
</resource-configuration>
+-->
</server>
@@ -216,16 +227,20 @@
</server>
<server name="JBossAS-Managed"
- discovery="BaseProcessDiscovery"
+ discovery="ManagedASDiscovery"
class="DomainComponent"
<plugin-configuration>
<c:simple-property name="hostname" default="localhost"
required="true"/>
<c:simple-property name="port" default="9990"
type="integer" required="true"/>
+ <c:simple-property name="domainHost" readOnly="true"
description="Hostname in the domain"/>
+ <c:simple-property name="group" readOnly="true"
displayName="Server Group" description="Server Group this instance belongs
to."/>
&logSources;
</plugin-configuration>
+ <!-- Scan for host controller is intentional -->
+ <process-scan name="HostController"
query="process|basename|match=^java.*,arg|org.jboss.as.host-controller|match=.*"/>
<process-scan name="ManagedAS"
query="process|basename|match=^java.*,arg|org.jboss.as.server|match=.*"/>
<operation name="server:start" description="Start this server
instance." displayName="Start">
@@ -330,7 +345,7 @@
class="BaseComponent"
<plugin-configuration>
- <c:simple-property name="path" readOnly="true"
default="/queue/"/>
+ <c:simple-property name="path" readOnly="true"
default="/queue/*"/>
</plugin-configuration>
</service>
</server>
@@ -383,7 +398,9 @@
<resource-configuration>
<c:simple-property name="access-log"/>
- <c:list-property name="alias" description="The virtual
server aliases"/>
+ <c:list-property name="alias" description="The virtual
server aliases">
+ <c:simple-property name="alias"/>
+ </c:list-property>
<c:simple-property name="rewrite"/>
</resource-configuration>