modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASConnection.java
| 10
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ASUploadConnection.java
| 11
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
| 18 -
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DeploymentComponent.java
| 149 +++++++++-
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
| 8
5 files changed, 180 insertions(+), 16 deletions(-)
New commits:
commit 04cd6df03ec0dd2bdd6093c313c55a4ff3cb3110
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Jan 26 21:56:13 2012 +0100
First cut at content-based (re-)deployment
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 6fa678b..9651be2 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
@@ -51,6 +51,8 @@ public class ASConnection {
private ObjectMapper mapper;
public static boolean verbose = false; // This is a variable on purpose, so devs can
switch it on in the debugger or in the agent
Authenticator passwordAuthenticator ;
+ private String host;
+ private int port;
/**
* Construct an ASConnection object. The real "physical" connection is done
in
@@ -61,6 +63,8 @@ public class ASConnection {
* @param password password needed for authentication
*/
public ASConnection(String host, int port, String user, String password) {
+ this.host = host;
+ this.port = port;
try {
url = new URL("http", host, port, MANAGEMENT);
@@ -258,5 +262,11 @@ public class ASConnection {
}
}
+ public String getHost() {
+ return host;
+ }
+ public int getPort() {
+ return port;
+ }
}
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
index a5b8bdd..ff5aa94 100644
---
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
@@ -66,8 +66,15 @@ public class ASUploadConnection {
public ASUploadConnection(String dcHost, int port, String user, String password) {
this.host = dcHost;
this.port = port;
- passwordAuthenticator = new AS7Authenticator(user,password);
- Authenticator.setDefault(passwordAuthenticator);
+ if (user!=null) {
+ passwordAuthenticator = new AS7Authenticator(user,password);
+ Authenticator.setDefault(passwordAuthenticator);
+ }
+ }
+
+ public ASUploadConnection(ASConnection asConnection) {
+ this.host=asConnection.getHost();
+ this.port=asConnection.getPort();
}
public OutputStream getOutputStream(String fileName) {
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 e4fa0e4..7510a8f 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
@@ -70,7 +70,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-public class BaseComponent<T extends ResourceComponent<?>> implements
ResourceComponent<T>, MeasurementFacet, ConfigurationFacet, DeleteResourceFacet,
+public class BaseComponent<T extends ResourceComponent<?>> implements
ResourceComponent<T>, MeasurementFacet, ConfigurationFacet,
+ DeleteResourceFacet,
CreateChildResourceFacet, OperationFacet
{
private static final String INTERNAL = "_internal:";
@@ -341,13 +342,18 @@ public class BaseComponent<T extends
ResourceComponent<?>> implements ResourceCo
if (fileName.startsWith("C:\\fakepath\\")) { // TODO this is a hack
as the server adds the fake path somehow
fileName=fileName.substring("C:\\fakepath\\".length());
}
-
- String tmpName = fileName; // TODO figure out the tmp-name biz with the AS guys
+ String runtimeName = fileName;
+ PropertySimple rtNameProp =
report.getPackageDetails().getDeploymentTimeConfiguration().getSimple("runtimeName");
+ if (rtNameProp != null) {
+ String rtn = rtNameProp.getStringValue();
+ if (rtn!=null && !rtn.isEmpty())
+ runtimeName = rtn;
+ }
JsonNode resultNode = uploadResult.get("result");
String hash = resultNode.get("BYTES_VALUE").getTextValue();
- return runDeploymentMagicOnServer(report, fileName, tmpName, hash);
+ return runDeploymentMagicOnServer(report, runtimeName, fileName, hash);
}
/**
@@ -367,7 +373,7 @@ public class BaseComponent<T extends ResourceComponent<?>>
implements ResourceCo
ASConnection connection = getASConnection();
- Operation step1 = new
Operation("add","deployment",deploymentName);
+ Operation step1 = new
Operation("add","deployment",runtimeName);
// step1.addAdditionalProperty("hash", new
PROPERTY_VALUE("BYTES_VALUE", hash));
List<Object> content = new ArrayList<Object>(1);
Map<String,Object> contentValues = new HashMap<String,Object>();
@@ -429,6 +435,8 @@ public class BaseComponent<T extends ResourceComponent<?>>
implements ResourceCo
report.setStatus(CreateResourceStatus.SUCCESS);
report.setResourceName(runtimeName);
report.setResourceKey(resourceKey);
+ report.getPackageDetails().setSHA256(hash);
+
report.getPackageDetails().setInstallationTimestamp(System.currentTimeMillis());
log.info(" ... with success and key [" + resourceKey +
"]" );
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DeploymentComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DeploymentComponent.java
index 56eee84..2e6163d 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DeploymentComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DeploymentComponent.java
@@ -1,18 +1,46 @@
package org.rhq.modules.plugins.jbossas7;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.codehaus.jackson.JsonNode;
+
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.content.PackageDetailsKey;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.transfer.ContentResponseResult;
+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.measurement.AvailabilityType;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.content.ContentFacet;
+import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
+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.PROPERTY_VALUE;
import org.rhq.modules.plugins.jbossas7.json.ReadAttribute;
+import org.rhq.modules.plugins.jbossas7.json.ReadChildrenResources;
import org.rhq.modules.plugins.jbossas7.json.Result;
/**
* Deal with deployments
* @author Heiko W. Rupp
*/
-public class DeploymentComponent extends BaseComponent implements OperationFacet{
+public class DeploymentComponent extends BaseComponent implements OperationFacet,
ContentFacet {
+
+ private boolean verbose = ASConnection.verbose;
@Override
public AvailabilityType getAvailability() {
@@ -21,7 +49,7 @@ public class DeploymentComponent extends BaseComponent implements
OperationFacet
if (!res.isSuccess())
return AvailabilityType.DOWN;
- if (!(Boolean)(res.getResult()))
+ if (res.getResult()== null || !(Boolean)(res.getResult()))
return AvailabilityType.DOWN;
return AvailabilityType.UP;
@@ -50,4 +78,121 @@ public class DeploymentComponent extends BaseComponent implements
OperationFacet
return result;
}
+
+
+ @Override
+ public List<DeployPackageStep> generateInstallationSteps(ResourcePackageDetails
packageDetails) {
+ return new ArrayList<DeployPackageStep>();
+ }
+
+ @Override
+ public DeployPackagesResponse deployPackages(Set<ResourcePackageDetails>
packages,
+ ContentServices contentServices) {
+
+ DeployPackagesResponse response = new DeployPackagesResponse();
+
+ if (packages.size()!=1) {
+ response.setOverallRequestResult(ContentResponseResult.FAILURE);
+ response.setOverallRequestErrorMessage("Can only deploy one package at a
time");
+ }
+
+ ResourcePackageDetails detail = packages.iterator().next();
+
+ ASUploadConnection uploadConnection = new ASUploadConnection(getASConnection());
+ OutputStream out = uploadConnection.getOutputStream(detail.getFileName());
+ ResourceType resourceType = context.getResourceType();
+
+ log.info("trying " + resourceType.getName() + ", " +
detail.getKey() );
+
+ contentServices.downloadPackageBits(context.getContentContext(),
+ detail.getKey(), out, true);
+
+ JsonNode uploadResult = uploadConnection.finishUpload();
+ if (verbose)
+ log.info(uploadResult);
+
+ if (ASUploadConnection.isErrorReply(uploadResult)) {
+ response.setOverallRequestResult(ContentResponseResult.FAILURE);
+
response.setOverallRequestErrorMessage(ASUploadConnection.getFailureDescription(uploadResult));
+
+ return response;
+ }
+ JsonNode resultNode = uploadResult.get("result");
+ String hash = resultNode.get("BYTES_VALUE").getTextValue();
+
+
+ CreateResourceReport report1 = new CreateResourceReport("",
resourceType, new Configuration(),
+ new Configuration(), detail);
+ //CreateResourceReport report =
runDeploymentMagicOnServer(report1,detail.getKey().getName(),hash, hash);
+
+ try {
+ redeployOnServer(detail.getKey().getName(), hash);
+ response.setOverallRequestResult(ContentResponseResult.SUCCESS);
+ }
+ catch (Exception e) {
+ response.setOverallRequestResult(ContentResponseResult.FAILURE);
+ }
+
+
+ return response;
+ }
+
+ private void redeployOnServer(String name, String hash) throws Exception {
+
+ Operation op = new Operation("full-replace-deployment", new
Address());
+ op.addAdditionalProperty("name",name);
+ List<Object> content = new ArrayList<Object>(1);
+ Map<String,Object> contentValues = new HashMap<String,Object>();
+ contentValues.put("hash",new
PROPERTY_VALUE("BYTES_VALUE",hash));
+ content.add(contentValues);
+ op.addAdditionalProperty("content",content);
+ Result result = getASConnection().execute(op);
+ if (result.isRolledBack())
+ throw new Exception(result.getFailureDescription());
+ }
+
+ @Override
+ public RemovePackagesResponse removePackages(Set<ResourcePackageDetails>
packages) {
+ return null; // TODO: Customise this generated block
+ }
+
+ @Override
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type)
{
+
+ Set<ResourcePackageDetails> details = new
HashSet<ResourcePackageDetails>();
+
+ // PackageType = "Deployment"
+ Address address1 = getAddress().getParent();
+ Operation op = new ReadChildrenResources(address1,"deployment");
+ ComplexResult cres = getASConnection().executeComplex(op);
+
+ if (!cres.isSuccess())
+ return details;
+
+ Map<String,Object> deployments = cres.getResult();
+ for (String key : deployments.keySet()) {
+ Map<String,Object> deployment = (Map<String, Object>)
deployments.get(key);
+
+ List<Map> contentList = (List<Map>)
deployment.get("content");
+ Map<String,Map> hashMap = contentList.get(0);
+ Map<String,String> bvMap = hashMap.get("hash");
+ String content = bvMap.get("BYTES_VALUE");
+ PackageDetailsKey pdKey = new PackageDetailsKey(key,
+ content, // no way to obtain the user defined version from the
server
+ type.getName(),
+ "noarch"
+ );
+ ResourcePackageDetails detail = new ResourcePackageDetails(pdKey);
+ detail.setSHA256(content);
+
+ details.add(detail);
+ }
+
+ return details;
+ }
+
+ @Override
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ return null; // TODO: Customise this generated block
+ }
}
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 b044848..fdebf0a 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
@@ -185,8 +185,6 @@
displayType="summary" measurementType="dynamic"
description="Max time for a request since last metric get"
units="milliseconds"
displayName="Maximum request time"/>
- <metric property="server-state" dataType="trait"
displayName="Server state" description="Detailed server state"
- displayType="summary"/>
<metric property="release-codename" dataType="trait"
displayName="Code name of the release" displayType="summary"/>
<metric property="release-version" dataType="trait"
displayName="Version of the server" displayType="summary"/>
<metric property="product-name" dataType="trait"
displayName="Name of the product"/>
@@ -1108,17 +1106,13 @@
description="The number of times that statements from the cache
were used"/>
<metric property="AverageBlockingTime"
units="milliseconds"
description="The average time spent blocking for a
connection"/>
- <metric property="MaxWaitTime" units="milliseconds"
- description="The maximum wait time for a connection"
displayType="summary"/>
<metric property="ActiveCount"
description="The active count"/>
<metric property="CreatedCount" description="The created
count" measurementType="trendsup"/>
<metric property="MaxCreationTime" description="The maximum
time for creating a physical connection" units="milliseconds"/>
- <metric property="MaxWaitCount" description="The maximum
number of threads waiting for a connection" units="milliseconds"
displayType="summary"/>
<metric property="TotalCreationTime" description="The total
time spent creating physical connections" measurementType="trendsup"
units="milliseconds"/>
<metric property="AvailableCount" description="The
available count" units="milliseconds"/>
<metric property="MaxUsedCount" description="The maximum
number of connections used"/>
- <metric property="TimedOut" description="The timed out
count" measurementType="trendsup" displayType="summary"/>
<metric property="TotalBlockingTime" description="The total
blocking time" measurementType="trendsup"
units="milliseconds"/>
<metric property="AverageCreationTime" description="The
average time spent creating a physical connection"
units="milliseconds"/>
<metric property="DestroyedCount" description="The
destroyed count" measurementType="trendsup"/>
@@ -2155,7 +2149,7 @@ working area for individual server
instances</li></ul>"/>
<content name="file" category="deployable"
isCreationType="true" description="Deployments on this server
group">
<configuration>
<c:group name="deployment" displayName="Deployment
Options">
- <c:simple-property name="runtimeName"
required="false"/>
+ <c:simple-property name="runtimeName"
required="false" description="Runtime name of the uploaded file (e.g.
'my.war'). If not present, the file name is used."/>
</c:group>
</configuration>
</content>