modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
| 19 +
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
| 57 ++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
| 132 ++++++++++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
| 7
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
| 30 ++
6 files changed, 240 insertions(+), 9 deletions(-)
New commits:
commit 7122b59f83eab6785068f46224f4d601373f26ef
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 12:24:46 2011 +0200
Start support for adding and removal of server instances.
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 470722d..bd0b458 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
@@ -210,11 +210,19 @@ public class ASConnection {
br.close();
}
}
- String outcome = builder.toString();
+ String outcome;
+ JsonNode operationResult=null;
+ if (builder!=null) {
+ outcome= builder.toString();
+ operationResult = mapper.readTree(outcome);
+ }
+ else {
+ outcome="- no response from server -";
+ }
System.out.println("==> " + outcome);
- JsonNode operationResult = mapper.readTree(outcome);
return operationResult;
+
} catch (IOException e) {
e.printStackTrace(); // TODO: Customise this generated block
}
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 460aebf..b53dd74 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
@@ -20,7 +20,9 @@ package org.rhq.modules.plugins.jbossas7;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.codehaus.jackson.JsonNode;
@@ -87,12 +89,27 @@ public class DomainComponent extends BaseComponent implements
OperationFacet{
} else if (what.equals("server")) {
List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>();
- String host = conf.getSimpleValue("domainHost","local");
-
- address.add(new PROPERTY_VALUE("host",host));
- address.add(new PROPERTY_VALUE("server-config",myServerName));
+ if (context.getResourceType().getName().equals("JBossAS-Managed"))
{
+ String host =
conf.getSimpleValue("domainHost","local");
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+ operation = new Operation(op,address);
+ }
+ else if (context.getResourceType().getName().equals("Host")) {
+ address.addAll(pathToAddress(getPath()));
+ String serverName = parameters.getSimpleValue("name",null);
+ address.add(new PROPERTY_VALUE("server-config",serverName));
+ Map<String,String> props = new HashMap<String, String>();
+ String serverGroup = parameters.getSimpleValue("group",null);
+ props.put("name",serverName);
+ props.put("group",serverGroup);
+// boolean autoStart =
parameters.getSimple("auto-start").getBooleanValue();
+// props.put("auto-start",String.valueOf(autoStart));
+ // TODO put more properties in
+
+ operation = new Operation(op,address,props);
+ }
- operation = new Operation(op,address);
}
OperationResult operationResult = new OperationResult();
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 9994339..e77a2ca 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
@@ -120,7 +120,6 @@
</parameters>
</operation>
-
<server name="Profile"
description="One profile in a domain"
discovery="SubsystemDiscovery"
@@ -147,12 +146,31 @@
<server name="Host"
description="Host involved in this domain"
discovery="SubsystemDiscovery"
- class="BaseComponent"
+ class="DomainComponent"
<plugin-configuration>
<c:simple-property name="path" default="/host/*"
readOnly="true"/>
</plugin-configuration>
+ <operation name="server:add" displayName="Create
server" description="Add a new server to this host.">
+ <parameters>
+ <c:simple-property name="name" description="Name of
this new server" required="true"/>
+ <c:simple-property name="group" displayName="Server
Group" description="Server group to put this sever in" default=""
required="false"/>
+ <c:simple-property name="auto-start"
displayName="Autostart" description="Should this server start at
boot?" type="boolean" default="false"
required="false"/>
+ </parameters>
+ <results>
+ <c:simple-property name="result"
description="Outcome of the create server operation"/>
+ </results>
+ </operation>
+ <operation name="server:remove" displayName="Delete
server" description="Deletes a server on this host.">
+ <parameters>
+ <c:simple-property name="name" description="Name of
this new server" required="true"/>
+ </parameters>
+ <results>
+ <c:simple-property name="result"
description="Outcome of the delete server operation"/>
+ </results>
+ </operation>
+
<resource-configuration>
<c:list-property name="server-config" />
</resource-configuration>
@@ -210,9 +228,10 @@
<process-scan name="ManagedAS"
query="process|basename|match=^java.*,arg|org.jboss.as.server|match=.*"/>
- <operation name="server:start" description="Start this server
instance."/>
- <operation name="server:stop" description="Stop this server
instance."/>
- <operation name="server:restart" description="Restart this
server instance."/>
+ <operation name="server:start" description="Start this server
instance." displayName="Start"/>
+ <operation name="server:stop" description="Stop this server
instance." displayName="Stop"/>
+ <operation name="server:restart" description="Restart this
server instance." displayName="Restart"/>
+
</server>
commit f2aa9b3dfbe8d6c2cc7b8239a753fe1f7023142a
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Mar 31 08:30:04 2011 +0200
Get availability for a managed server from the domain.
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 bfed04a..460aebf 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
@@ -25,6 +25,7 @@ import java.util.List;
import org.codehaus.jackson.JsonNode;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.modules.plugins.jbossas7.json.Operation;
@@ -38,6 +39,29 @@ import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
public class DomainComponent extends BaseComponent implements OperationFacet{
@Override
+ public AvailabilityType getAvailability() {
+
+ if (context.getResourceType().getName().equals("JBossAS-Managed")) {
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>(2);
+ String host = conf.getSimpleValue("domainHost","local");
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+ Operation getStatus = new
Operation("read-attribute",address,"name","status");
+ JsonNode result = connection.execute(getStatus);
+ if (connection.isErrorReply(result))
+ return AvailabilityType.DOWN;
+
+ String msg = connection.getSuccessDescription(result);
+ if (msg.contains("STARTED"))
+ return AvailabilityType.UP;
+ else
+ return AvailabilityType.DOWN;
+ }
+
+ return super.getAvailability(); // TODO: Customise this generated block
+ }
+
+ @Override
public OperationResult invokeOperation(String name,
Configuration parameters) throws
InterruptedException, Exception {
commit 397d5539988b798e49d2dc6e3f896c125274e0bc
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Mar 30 21:42:40 2011 +0200
Support start/stop/restart of servers.
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 401887b..470722d 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
@@ -199,7 +199,6 @@ public class ASConnection {
in.close();
}
else {
- System.out.println(conn.getResponseCode());
InputStream errorStream = conn.getErrorStream();
if (errorStream!=null) {
BufferedReader br = new BufferedReader(new
InputStreamReader(errorStream));
@@ -254,6 +253,12 @@ public class ASConnection {
if (node==null)
node = jsonNode.findValue("domain-failure-description"); // TODO
JBAS-9182
return node.getValueAsText();
+ }
+ public String getSuccessDescription(JsonNode jsonNode) {
+ if (jsonNode==null)
+ return "No message found";
+ JsonNode node = jsonNode.findValue("result");
+ return node.getValueAsText();
}
}
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 3b025f3..5dbd0b3 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
@@ -291,7 +291,7 @@ public class BaseComponent implements ResourceComponent,
MeasurementFacet, Confi
return ret;
}
- private String getResultingPath() {
+ protected String getResultingPath() {
ResourceComponent parentResourceComponent =
context.getParentResourceComponent();
String parentPath =null;
String myPath;
@@ -328,7 +328,7 @@ public class BaseComponent implements ResourceComponent,
MeasurementFacet, Confi
}
- private List<PROPERTY_VALUE> pathToAddress(String path) {
+ protected List<PROPERTY_VALUE> pathToAddress(String path) {
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/BaseProcessDiscovery.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseProcessDiscovery.java
index c38e297..5ea4bd7 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,12 +1,19 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
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.mc4j.ems.connection.support.metadata.LocalVMTypeDescriptor;
+import org.w3c.dom.Document;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyList;
@@ -17,6 +24,7 @@ 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;
import org.rhq.plugins.jmx.JMXDiscoveryComponent;
@@ -29,6 +37,7 @@ public class BaseProcessDiscovery 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=";
private final Log log = LogFactory.getLog(this.getClass());
/**
@@ -69,6 +78,10 @@ public class BaseProcessDiscovery implements
ResourceDiscoveryComponent
tmp = tmp.substring( i + 8);
tmp = tmp.substring(0,tmp.indexOf("/"));
serverNameFull = tmp;
+
+ String host = findHost(psr.getProcessInfo(),true);
+ config.put(new PropertySimple("domainHost",host));
+
}
serverName =
serverNameFull.substring(serverNameFull.lastIndexOf("/")+1);
if (serverName.isEmpty())
@@ -114,7 +127,49 @@ public class BaseProcessDiscovery implements
ResourceDiscoveryComponent
}
- String getBaseDirFromCommandLine(String[] commandLine) {
+ private String findHost(ProcessInfo processInfo,boolean isDomain) {
+ String hostXmlFile = getHostXmlFileLocation(processInfo, isDomain);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ String hostName = null;
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputStream is = new FileInputStream(hostXmlFile);
+ Document document = builder.parse(is); // TODO keep this around
+ hostName = document.getDocumentElement().getAttribute("name");
+ is.close();
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: Customise this generated block
+ }
+ if (hostName==null)
+ hostName="local"; // Fallback to the installation default
+ return hostName;
+ }
+
+ /**
+ * 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
+ * @param isDomain Are we looking for host.xml (=isDomain) or not
+ * @return The path to the definition file.
+ */
+ private String getHostXmlFileLocation(ProcessInfo processInfo, boolean isDomain) {
+
+ String home = processInfo.getEnvironmentVariable("jboss.home.dir");
+ StringBuilder builder = new StringBuilder(home);
+ if (isDomain)
+ builder.append("/domain");
+ else
+ builder.append("/standalone");
+ builder.append("/configuration");
+ if (isDomain)
+ builder.append("/host.xml");
+ else
+ builder.append("/standalone.xml");
+ return builder.toString();
+
+ }
+
+ String getBaseDirFromCommandLine(String[] commandLine) {
for (String line: commandLine) {
if (line.startsWith(DJBOSS_SERVER_BASE_DIR))
return line.substring(DJBOSS_SERVER_BASE_DIR.length());
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
new file mode 100644
index 0000000..bfed04a
--- /dev/null
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DomainComponent.java
@@ -0,0 +1,91 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.codehaus.jackson.JsonNode;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
+
+/**
+ * Common stuff for the Domain
+ * @author Heiko W. Rupp
+ */
+@SuppressWarnings("unused")
+public class DomainComponent extends BaseComponent implements OperationFacet{
+
+ @Override
+ public OperationResult invokeOperation(String name,
+ Configuration parameters) throws
InterruptedException, Exception {
+
+ if (!name.contains(":")) {
+ OperationResult badName = new OperationResult("Operation name did not
contain a ':'");
+ badName.setErrorMessage("Operation name did not contain a
':'");
+ return badName;
+ }
+
+ int colonPos = name.indexOf(':');
+ String what = name.substring(0, colonPos);
+ String op = name.substring(colonPos+1);
+ Operation operation=null;
+
+ if (what.equals("server-group")) {
+ String groupName = parameters.getSimpleValue("name",null);
+ String profile =
parameters.getSimpleValue("profile","default");
+
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>(1);
+ address.add(new PROPERTY_VALUE("server-group",groupName));
+
+ operation = new Operation(op,address,"profile",profile);
+ } else if (what.equals("server")) {
+ List<PROPERTY_VALUE> address = new ArrayList<PROPERTY_VALUE>();
+
+ String host = conf.getSimpleValue("domainHost","local");
+
+ address.add(new PROPERTY_VALUE("host",host));
+ address.add(new PROPERTY_VALUE("server-config",myServerName));
+
+ operation = new Operation(op,address);
+ }
+
+ OperationResult operationResult = new OperationResult();
+ if (operation!=null) {
+ JsonNode result = connection.execute(operation);
+
+ if (connection.isErrorReply(result)) {
+
operationResult.setErrorMessage(connection.getFailureDescription(result));
+ }
+ else {
+
operationResult.setSimpleResult(connection.getSuccessDescription(result));
+ }
+ }
+ else {
+ operationResult.setErrorMessage("No valid operation was given");
+ }
+ // TODO throw an exception if the operation failed?
+ return operationResult;
+ }
+}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
index 898f176..92abbae 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/json/Operation.java
@@ -64,6 +64,13 @@ public class Operation {
}
+ public Operation(String operation, List<PROPERTY_VALUE> address) {
+ this.operation = operation;
+ this.address = address;
+ additionalProperties = Collections.emptyMap();
+
+ }
+
public Operation() {
// needed for Jackson
}
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 6af7de6..9994339 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
@@ -199,7 +199,7 @@
<server name="JBossAS-Managed"
discovery="BaseProcessDiscovery"
- class="BaseComponent"
+ class="DomainComponent"
<plugin-configuration>
<c:simple-property name="hostname" default="localhost"
required="true"/>
@@ -210,6 +210,11 @@
<process-scan name="ManagedAS"
query="process|basename|match=^java.*,arg|org.jboss.as.server|match=.*"/>
+ <operation name="server:start" description="Start this server
instance."/>
+ <operation name="server:stop" description="Stop this server
instance."/>
+ <operation name="server:restart" description="Restart this
server instance."/>
+
+
</server>