[jboss-svn-commits] JBL Code SVN: r22826 - in labs/jbossesb/trunk/product/tools/jonplugin: src/main/java/org/jbosson/plugins/jbossesb and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 16 22:11:54 EDT 2008
Author: tcunning
Date: 2008-09-16 22:11:54 -0400 (Tue, 16 Sep 2008)
New Revision: 22826
Added:
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceDiscoveryComponent.java
Modified:
labs/jbossesb/trunk/product/tools/jonplugin/install.sh
labs/jbossesb/trunk/product/tools/jonplugin/pom.xml
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionDiscoveryComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBDiscoveryComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ListenerComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml
Log:
JBESB-668
Commit fixes for deployment.
Modified: labs/jbossesb/trunk/product/tools/jonplugin/install.sh
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/install.sh 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/install.sh 2008-09-17 02:11:54 UTC (rev 22826)
@@ -1,4 +1,6 @@
#!/bin/sh
+rm -rf ~/.m2/repository/org/jboss/on/rhq-jbossesb-plugin
mvn -Dmaven.test.skip=true clean install
cp target/rhq-jbossesb-plugin-2.1.0-SNAPSHOT.jar ~/src/rhq/dev-container/jbossas/server/default/deploy/rhq.ear/rhq-downloads/rhq-plugins
cp target/rhq-jbossesb-plugin-2.1.0-SNAPSHOT.jar ~/src/jon/jon/dist/agent/target/jon-agent-2.1.0-SNAPSHOT/plugins/rhq-jbossesb-plugin-2.1.0-SNAPSHOT.jar
+
Modified: labs/jbossesb/trunk/product/tools/jonplugin/pom.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/pom.xml 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/pom.xml 2008-09-17 02:11:54 UTC (rev 22826)
@@ -25,6 +25,15 @@
<scm.module.path>jon/plugins/jbossesb/</scm.module.path>
</properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.on</groupId>
+ <artifactId>rhq-jbossas-plugin</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
@@ -66,7 +75,6 @@
<build>
<plugins>
-
<!-- Integration testing voodoo to load and test this plugin with its plugin dependencies -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionComponent.java 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -21,7 +21,7 @@
import java.util.Set;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
-import org.mc4j.ems.connection.bean.operation.EmsOperation;
+import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
@@ -52,10 +52,40 @@
private static final String BYTESPROCESSED_METRIC_NAME = "overallBytesProcessed";
private static final String BYTESFAILED_METRIC_NAME = "overallBytesFailed";
+ /**
+ * Is this service alive?
+ *
+ * @return true if the service is running
+ */
@Override
+ public AvailabilityType getAvailability() {
+ try {
+ EmsBean emsbean = getEmsBean();
+ if (emsbean.isRegistered()) {
+ String actionName = this.context.getResourceKey();
+ actionName = actionName.trim();
+ EmsAttribute attribute = this.bean.getAttribute(actionName + " " + SUCCESS_PROCESSED);
+ if (attribute != null) {
+ return AvailabilityType.UP;
+ }
+ return AvailabilityType.DOWN;
+ } else {
+ return AvailabilityType.DOWN;
+ }
+ } catch (NullPointerException npe) {
+ if (resourceContext != null) {
+ log.warn("Could not determine availability of unknown ems bean for ["
+ + resourceContext.getResourceType() + ":" + resourceContext.getResourceKey() + "]");
+ }
+
+ return AvailabilityType.DOWN;
+ }
+ }
+
+ @Override
public void start(ResourceContext<MBeanResourceComponent> context) {
super.start(context);
- this.context = context;
+ this.context = context;
this.bean = context.getParentResourceComponent().getEmsBean();
}
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionDiscoveryComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionDiscoveryComponent.java 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ActionDiscoveryComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -22,7 +22,6 @@
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -31,11 +30,9 @@
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.ResourceContext;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.plugins.jmx.JMXComponent;
import org.rhq.plugins.jmx.MBeanResourceComponent;
Added: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -0,0 +1,303 @@
+package org.jbosson.plugins.jbossesb;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+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.DeployIndividualPackageResponse;
+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.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.event.EventContext;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.operation.OperationContext;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.plugins.jbossas.util.FileContentDelegate;
+import org.rhq.plugins.jmx.JMXComponent;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+import org.rhq.plugins.utils.FileUtils;
+
+/**
+ * Component for ESB package deployment.
+ *
+ * @author Tom Cunningham
+ * @param <T>
+ */
+public class DeploymentComponent extends MBeanResourceComponent<JMXComponent> implements
+ OperationFacet, DeleteResourceFacet, ContentFacet {
+ public static final String JBOSS_WEB_NAME = "jbossWebName";
+ private EmsBean jbossWebMBean;
+ private File configPath;
+
+ private ResourceContext resourceContext;
+ private ContentContext contentContext;
+ private OperationContext operationContext;
+ private EventContext eventContext;
+
+ // The following constants reference the exact name of the package types as defined in the plugin descriptor
+ private static final String PACKAGE_TYPE_PATCH = "cumulativePatch";
+ private static final String PACKAGE_TYPE_LIBRARY = "library";
+
+
+ private static final String RESOURCE_TYPE_ESB = "JBoss ESB Deployments";
+
+ public File getConfigurationPath() {
+ return this.configPath;
+ }
+
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ String resourceTypeName = report.getResourceType().getName();
+
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ esbCreate(report, resourceTypeName);
+ } else {
+ throw new UnsupportedOperationException("Unknown Resource type: " + resourceTypeName);
+ }
+
+ return report;
+ }
+
+ private void esbCreate(CreateResourceReport report, String resourceTypeName) {
+ ResourcePackageDetails details = report.getPackageDetails();
+ PackageDetailsKey key = details.getKey();
+ String archiveName = key.getName();
+
+ try {
+ // First check to see if the file name has the correct extension. Reject if the user attempts to
+ // deploy a WAR file with a bad extension.
+ String expectedExtension;
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ expectedExtension = "esb";
+ } else {
+ expectedExtension = "";
+ }
+
+ int lastPeriod = archiveName.lastIndexOf(".");
+ String extension = archiveName.substring(lastPeriod + 1);
+ if (lastPeriod == -1 || !expectedExtension.equals(extension)) {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("Incorrect extension specified on filename [" + archiveName + "]. Expected ["
+ + expectedExtension + "]");
+ return;
+ }
+
+ Configuration deployTimeConfiguration = details.getDeploymentTimeConfiguration();
+ String deployDirectory = deployTimeConfiguration.getSimple("deployDirectory").getStringValue();
+
+ // Verify the user did not enter a path that represents a security issue:
+ // - No absolute directories; must be relative to the configuration path
+ // - Cannot contain parent directory references
+ File testPath = new File(deployDirectory);
+
+ if (testPath.isAbsolute()) {
+ throw new RuntimeException("Path to deploy (deployDirectory) must be a relative path. Path specified: "
+ + deployDirectory);
+ }
+
+ if (deployDirectory.contains("..")) {
+ throw new RuntimeException(
+ "Path to deploy (deployDirectory) may not reference the parent directory. Path specified: "
+ + deployDirectory);
+ }
+
+ // Perform the deployment
+ FileContentDelegate deployer = new FileContentDelegate(new File(getConfigurationPath() + File.separator
+ + deployDirectory), "", details.getPackageTypeName());
+
+ PropertySimple zipProperty = deployTimeConfiguration.getSimple("deployZipped");
+
+ if (zipProperty != null && zipProperty.getBooleanValue() != null) {
+ boolean zip = zipProperty.getBooleanValue();
+
+ File tempDir = resourceContext.getTemporaryDirectory();
+ File tempFile = new File(tempDir.getAbsolutePath(), "esb.bin");
+ OutputStream osForTempDir = new BufferedOutputStream(new FileOutputStream(tempFile));
+
+ ContentServices contentServices = contentContext.getContentServices();
+ contentServices
+ .downloadPackageBitsForChildResource(contentContext, resourceTypeName, key, osForTempDir);
+
+ osForTempDir.close();
+
+ // check for content
+ boolean valid = isOfType(tempFile, resourceTypeName);
+ if (!valid) {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("Expected a " + resourceTypeName
+ + " file, but its format/content did not match");
+ return;
+ }
+
+ InputStream isForTempDir = new BufferedInputStream(new FileInputStream(tempFile));
+ deployer.createContent(details, isForTempDir, !zip);
+
+ // Resource key should match the following:
+ // EAR: jboss.management.local:J2EEServer=Local,j2eeType=J2EEApplication,name=rhq.ear
+ // WAR: jboss.management.local:J2EEApplication=null,J2EEServer=Local,j2eeType=WebModule,name=embedded-console.war
+
+ String resourceKey;
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ resourceKey = "jboss.esb:deployment="
+ + archiveName;
+ }
+
+ report.setResourceName(archiveName);
+ //report.setResourceKey(resourceKey);
+ report.setStatus(CreateResourceStatus.SUCCESS);
+ sleepAfterConfigXmlUpdate();
+ } else {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("Zipped property is required");
+ }
+ } catch (Throwable t) {
+ log.error("Error deploying application for report: " + report, t);
+ report.setException(t);
+ report.setStatus(CreateResourceStatus.FAILURE);
+ }
+ }
+
+ /**
+ * Check to see if the passed file is actually in jar format and contains a
+ * <ul>
+ * <li>WEB-INF/web.xml for .war </li>
+ * <li>META-INF/application.xml for .ear</li>
+ * <li>META-INF/jboss.service.xml for .sar</li>
+ * </ul>
+ * @param file File to check
+ * @param type Type to match - see RESOURCE_TYPE_SAR, RESOURCE_TYPE_WAR and RESOURCE_TYPE_EAR
+ * @return true is the file is in jar format and matches the type
+ */
+ private boolean isOfType(File file, String type) {
+ JarFile jfile = null;
+ try {
+ jfile = new JarFile(file);
+ JarEntry entry;
+ if (RESOURCE_TYPE_ESB.equals(type))
+ entry = jfile.getJarEntry("META-INF/jboss-esb.xml");
+ else {
+ entry = null; // unknown type
+ log.warn("isOfType: " + type + " is unknown - not a valid file");
+ }
+
+ if (entry != null)
+ return true;
+
+ return false;
+ } catch (Exception e) {
+ log.info(e.getMessage());
+ return false;
+ } finally {
+ if (jfile != null)
+ try {
+ jfile.close();
+ } catch (IOException e) {
+ log.info("Exception when trying to close the war file: " + e.getMessage());
+ }
+ }
+ }
+
+ private void sleepAfterConfigXmlUpdate() {
+ // JBNADM-1984 - The contract with this method is that the newly created managed resource should be discoverable.
+ // Wait here so JBoss can recognize that the new managed resource has been created.
+ try {
+ Thread.sleep(5000L);
+ } catch (InterruptedException e) {
+ log.info("Sleep after Resource create interrupted", e);
+ }
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+ // JBossASTomcatServerComponent parentTomcatComponent = (JBossASTomcatServerComponent) super.resourceContext
+ // .getParentResourceComponent();
+ // EmsConnection connection = parentTomcatComponent.getEmsConnection();
+ boolean isreg = bean.isRegistered();
+ return isreg ? AvailabilityType.UP : AvailabilityType.DOWN;
+ }
+
+ public void deleteResource() throws Exception {
+ Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ String fullFileName = pluginConfiguration.getSimple("filename").getStringValue();
+
+ File file = new File(fullFileName);
+
+ if (!file.exists()) {
+ throw new Exception("Cannot find application file to delete: " + fullFileName);
+ }
+
+ if (file.isDirectory()) {
+ FileUtils.deleteDirectoryContents(file.listFiles());
+ }
+
+ boolean result = file.delete();
+
+ if (!result) {
+ throw new Exception("File delete call returned unsuccessful with no further detail");
+ }
+ }
+
+ public DeployPackagesResponse deployPackages(
+ Set<ResourcePackageDetails> packages,
+ ContentServices contentServices) {
+ ContentResponseResult overallResult = ContentResponseResult.SUCCESS;
+ List<DeployIndividualPackageResponse> individualResponses = new ArrayList<DeployIndividualPackageResponse>(
+ packages.size());
+
+ for (ResourcePackageDetails pkg : packages) {
+ log.info("Attempting to deploy package: " + pkg);
+
+ String packageTypeName = pkg.getPackageTypeName();
+ if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
+ throw new UnsupportedOperationException("Deployment of new libraries is not supported by the plugin.");
+ }
+ }
+
+ DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
+ response.getPackageResponses().addAll(individualResponses);
+
+ return response;
+ }
+
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
+ return null;
+ }
+
+ public List<DeployPackageStep> generateInstallationSteps(
+ ResourcePackageDetails packageDetails) {
+ return null;
+ }
+
+ public RemovePackagesResponse removePackages(
+ Set<ResourcePackageDetails> packages) {
+ return null;
+ }
+
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ return null;
+ }
+
+}
Added: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -0,0 +1,228 @@
+package org.jbosson.plugins.jbossesb;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+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.DeployIndividualPackageResponse;
+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.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;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.operation.OperationContext;
+import org.rhq.core.pluginapi.util.ResponseTimeLogParser;
+import org.rhq.plugins.jbossas.JBossASServerComponent;
+import org.rhq.plugins.jbossas.util.FileContentDelegate;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+public class ESBComponent extends MBeanResourceComponent implements CreateChildResourceFacet, ContentFacet {
+ private static final String RESOURCE_TYPE_ESB = "JBoss ESB Deployment";
+
+ private String configSet;
+ private ResponseTimeLogParser logParser;
+ private File configPath;
+
+ private ContentContext contentContext;
+ private OperationContext operationContext;
+ public static final String CONTEXT_ROOT_CONFIG_PROP = "contextRoot";
+ // The following constants reference the exact name of the package types as defined in the plugin descriptor
+ private static final String PACKAGE_TYPE_PATCH = "cumulativePatch";
+ private static final String PACKAGE_TYPE_LIBRARY = "library";
+
+ public static final String CONFIGURATION_PATH_CONFIG_PROP = "configurationPath";
+ public static final String SCRIPT_PREFIX_CONFIG_PROP = "scriptPrefix";
+ public static final String CONFIGURATION_SET_CONFIG_PROP = "configurationSet";
+
+ public static final String JBOSS_HOME_DIR_CONFIG_PROP = "jbossHomeDir";
+
+
+ @Override
+public void start(ResourceContext context) {
+ super.start(context);
+ Configuration pluginConfig = context.getPluginConfiguration();
+
+ this.configPath = getConfigurationPath();
+ if (!this.configPath.exists()) {
+ throw new InvalidPluginConfigurationException("Configuration path '" + configPath + "' does not exist.");
+ }
+ this.configSet = pluginConfig.getSimpleValue(CONFIGURATION_SET_CONFIG_PROP, this.configPath.getName());
+ }
+
+ public File getConfigurationPath() {
+ JBossASServerComponent jass = (JBossASServerComponent) resourceContext.getParentResourceComponent();
+ return jass.getConfigurationPath();
+ }
+
+ @Override
+public AvailabilityType getAvailability() {
+ AvailabilityType av = super.getAvailability();
+ return av;
+ }
+
+ private void esbCreate(CreateResourceReport report, String resourceTypeName) {
+ ResourcePackageDetails details = report.getPackageDetails();
+ PackageDetailsKey key = details.getKey();
+ String archiveName = key.getName();
+
+ try {
+ // First check to see if the file name has the correct extension. Reject if the user attempts to
+ // deploy a WAR file with a bad extension.
+ String expectedExtension;
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ expectedExtension = "esb";
+ } else {
+ expectedExtension = "";
+ }
+
+ int lastPeriod = archiveName.lastIndexOf(".");
+ String extension = archiveName.substring(lastPeriod + 1);
+ if (lastPeriod == -1 || !expectedExtension.equals(extension)) {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("Incorrect extension specified on filename [" + archiveName + "]. Expected ["
+ + expectedExtension + "]");
+ return;
+ }
+
+ Configuration deployTimeConfiguration = details.getDeploymentTimeConfiguration();
+ String deployDirectory = deployTimeConfiguration.getSimple("deployDirectory").getStringValue();
+
+ // Verify the user did not enter a path that represents a security issue:
+ // - No absolute directories; must be relative to the configuration path
+ // - Cannot contain parent directory references
+ File testPath = new File(deployDirectory);
+
+ if (testPath.isAbsolute()) {
+ throw new RuntimeException("Path to deploy (deployDirectory) must be a relative path. Path specified: "
+ + deployDirectory);
+ }
+
+ if (deployDirectory.contains("..")) {
+ throw new RuntimeException(
+ "Path to deploy (deployDirectory) may not reference the parent directory. Path specified: "
+ + deployDirectory);
+ }
+
+ // Perform the deployment
+ FileContentDelegate deployer = new FileContentDelegate(new File(getConfigurationPath() + File.separator
+ + deployDirectory), "", details.getPackageTypeName());
+
+ PropertySimple zipProperty = deployTimeConfiguration.getSimple("deployZipped");
+
+ if (zipProperty != null && zipProperty.getBooleanValue() != null) {
+ boolean zip = zipProperty.getBooleanValue();
+
+ File tempDir = resourceContext.getTemporaryDirectory();
+ File tempFile = new File(tempDir.getAbsolutePath(), "esb.bin");
+ OutputStream osForTempDir = new BufferedOutputStream(new FileOutputStream(tempFile));
+
+ contentContext = resourceContext.getContentContext();
+ ContentServices contentServices = contentContext.getContentServices();
+ contentServices
+ .downloadPackageBitsForChildResource(contentContext, resourceTypeName, key, osForTempDir);
+
+ osForTempDir.close();
+
+ InputStream isForTempDir = new BufferedInputStream(new FileInputStream(tempFile));
+ deployer.createContent(details, isForTempDir, !zip);
+
+ // Resource key should match the following:
+ // ESB: jboss.esb:deployment=jbossesb.esb
+
+ String resourceKey;
+ resourceKey = "jboss.esb:deployment=" + archiveName;
+
+ report.setResourceName(archiveName);
+ report.setResourceKey(resourceKey);
+ report.setStatus(CreateResourceStatus.SUCCESS);
+ } else {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("Zipped property is required");
+ }
+ } catch (Throwable t) {
+ log.error("Error deploying application for report: " + report, t);
+ report.setException(t);
+ report.setStatus(CreateResourceStatus.FAILURE);
+ }
+ }
+
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ String resourceTypeName = report.getResourceType().getName();
+
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ esbCreate(report, resourceTypeName);
+ } else {
+ throw new UnsupportedOperationException("Unknown Resource type: " + resourceTypeName);
+ }
+
+ // JBNADM-1984 - The contract with this method is that the newly created managed resource should be discoverable.
+ // Wait here so JBoss can recognize that the new managed resource has been created.
+ try {
+ Thread.sleep(5000L);
+ } catch (InterruptedException e) {
+ log.info("Sleep after datasource create interrupted", e);
+ }
+
+ return report;
+ }
+
+ public DeployPackagesResponse deployPackages(
+ Set<ResourcePackageDetails> packages,
+ ContentServices contentServices) {
+ ContentResponseResult overallResult = ContentResponseResult.SUCCESS;
+ List<DeployIndividualPackageResponse> individualResponses = new ArrayList<DeployIndividualPackageResponse>(
+ packages.size());
+
+ for (ResourcePackageDetails pkg : packages) {
+ log.info("Attempting to deploy package: " + pkg);
+
+ String packageTypeName = pkg.getPackageTypeName();
+ if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
+ throw new UnsupportedOperationException("Deployment of new libraries is not supported by the plugin.");
+ }
+ }
+
+ DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
+ response.getPackageResponses().addAll(individualResponses);
+
+ return response;
+ }
+
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
+ return null;
+ }
+
+ public List<DeployPackageStep> generateInstallationSteps(
+ ResourcePackageDetails packageDetails) {
+ return null;
+ }
+
+ public RemovePackagesResponse removePackages(
+ Set<ResourcePackageDetails> packages) {
+ throw new UnsupportedOperationException();
+ }
+
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ throw new UnsupportedOperationException();
+ }
+}
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBDiscoveryComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBDiscoveryComponent.java 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBDiscoveryComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -1,21 +1,11 @@
package org.jbosson.plugins.jbossesb;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.List;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.mc4j.ems.connection.bean.EmsBean;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-import org.rhq.core.domain.configuration.Configuration;
import org.rhq.plugins.jmx.JMXComponent;
-import org.rhq.plugins.jmx.JMXDiscoveryComponent;
-import org.rhq.plugins.jmx.MBeanResourceComponent;
import org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent;
/**
@@ -25,7 +15,8 @@
* @author Tom Cunningham
*/
public class ESBDiscoveryComponent extends MBeanResourceDiscoveryComponent {
- public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<JMXComponent> context) {
+ @Override
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<JMXComponent> context) {
Set<DiscoveredResourceDetails> jmxResources = super.discoverResources(context);
String versionNumber;
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ListenerComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ListenerComponent.java 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ListenerComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -21,8 +21,6 @@
import java.util.Set;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
-import org.mc4j.ems.connection.bean.operation.EmsOperation;
-import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementDataTrait;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
@@ -31,7 +29,6 @@
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.mc4j.ems.connection.bean.EmsBean;
/**
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -21,7 +21,6 @@
import java.util.Set;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
-import org.mc4j.ems.connection.bean.operation.EmsOperation;
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
@@ -30,7 +29,6 @@
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.mc4j.ems.connection.bean.EmsBean;
/**
@@ -56,7 +54,6 @@
this.context = context;
}
-
@Override
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) {
Configuration pluginConfig = this.context.getPluginConfiguration();
Added: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceDiscoveryComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceDiscoveryComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceDiscoveryComponent.java 2008-09-17 02:11:54 UTC (rev 22826)
@@ -0,0 +1,72 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 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.jbosson.plugins.jbossesb;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.plugins.jmx.JMXComponent;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+/**
+ * Discovers ESB Service entities from a ESB stats mbean
+ *
+ * @author Greg Hinkle
+ * @param <T>
+ */
+public class ServiceDiscoveryComponent<T extends JMXComponent> implements ResourceDiscoveryComponent<MBeanResourceComponent> {
+
+ private static Log log = LogFactory.getLog(ServiceDiscoveryComponent.class);
+
+ protected ResourceContext<T> resourceContext;
+
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<MBeanResourceComponent> context) {
+ Set<DiscoveredResourceDetails> entities = new HashSet<DiscoveredResourceDetails>();
+
+ EmsBean serviceBean = context.getParentResourceComponent().getEmsBean();
+ Set<EmsAttribute> attributeSet = serviceBean.getAttributes();
+ for (Iterator i = attributeSet.iterator(); i.hasNext();) {
+ EmsAttribute attr = (EmsAttribute) i.next();
+ System.out.println(attr.getName());
+ //entities.add(detail);
+ }
+
+ /*
+ String serviceName = serviceBean.getBeanName().getKeyProperty(SERVICE_NAME);
+
+ // Do two passes - one to grab the entity names (ex. "data fileraction"
+ // and then a second to build up the metrics for the entity
+ Set<EmsAttribute> attributeSet = actionBean.getAttributes();
+ for (Iterator i = attributeSet.iterator(); i.hasNext();) {
+ EmsAttribute attr = (EmsAttribute) i.next();
+ entities.add(detail);
+ }
+ */
+ return entities;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml 2008-09-16 22:29:47 UTC (rev 22825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml 2008-09-17 02:11:54 UTC (rev 22826)
@@ -15,7 +15,7 @@
<service name="ESB"
discovery="org.jbosson.plugins.jbossesb.ESBDiscoveryComponent"
- class="org.rhq.plugins.jmx.MBeanResourceComponent"
+ class="org.jbosson.plugins.jbossesb.ESBComponent"
description="Overall statistics for JBoss ESB"
singleton="true">
<runs-inside>
@@ -26,6 +26,24 @@
<c:simple-property name="objectName" readOnly="true" default="jboss.esb:service=MessageCounter"/>
<c:simple-property name="nameTemplate" default="JBoss ESB Statistics"/>
<c:simple-property name="descriptionTemplate" default="JBoss ESB statistics."/>
+ <c:group name="connection" displayName="Connection Info">
+ <c:simple-property name="namingURL" displayName="Naming Provider URL"
+ description="The JNP URL with which to connect to the JBoss Application Server instance (e.g. jnp://127.0.0.1:1099)."
+ default="jnp://127.0.0.1:1099"/>
+ <c:simple-property name="principal" required="false" description="The name of the principal (i.e. user) to authenticate."/>
+ <c:simple-property name="credentials" type="password" required="false"
+ description="The credentials (i.e. password) that should be used to authenticate the principal."/>
+ <c:simple-property name="jbossHomeDir" displayName="JBoss Home Directory" type="directory" readOnly="true"
+ description="The absolute path to the directory where JBossAS is installed (e.g. /opt/jboss-4.2.2.GA)."/>
+ <c:simple-property name="configurationPath" displayName="Configuration Path" type="directory" readOnly="true"
+ description="The path to the configuration directory under which this instance
+ operates (e.g. /opt/jboss-4.2.2.GA/server/default); if the path is not absolute,
+ then it will be resolved relative to {jbossHomeDir}."/>
+ <c:simple-property name="configurationSet" displayName="Configuration Set" required="false"
+ description="The name of the server configuration (e.g. minimal, default, or all);
+ if not specified, it will default to the last path component of {configurationPath}."
+ default="default"/>
+ </c:group>
</plugin-configuration>
<operation name="start" displayName="Start deployment" description="Start the JBoss ESB deployment"/>
<operation name="stop" displayName="Stop deployment" description="Stop the JBoss ESB deployment"/>
@@ -39,33 +57,57 @@
<metric property="LastFailedMessageDate" displayName="Last Failed Message Date" dataType="trait" displayType="summary" defaultOn="true" description="Last Failed Message Date"/>
<metric property="StateString" dataType="trait" displayName="State" displayType="summary" defaultOn="true" description="State of the ESB"/>
<metric displayName="Bytes Processed" property="ProcessedBytes" units="bytes" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Bytes Processed"/>
-
+ <content name="library" displayName="Jar Library" category="deployable"
+ description="Library Jar files deployed in JBoss AS">
+ <configuration>
+ <c:simple-property name="version" readOnly="true" description="The version declared by the JAR's manifest."/>
+ <c:simple-property name="title" readOnly="true" description="The title declared by the JAR's manifest."/>
+ <c:simple-property name="url" readOnly="true" description="The url declared by the JAR's manifest."/>
+ <c:simple-property name="vendor" readOnly="true" description="The vendor declared by the JAR's manifest."/>
+ <c:simple-property name="classpath" readOnly="true"
+ description="The classpath declared by the JAR's manifest."/>
+ <c:simple-property name="sealed" readOnly="true" type="boolean" description="True if the JAR is sealed."/>
+ </configuration>
+ </content>
<service name="JBoss ESB Deployment"
discovery="org.jbosson.plugins.jbossesb.ESBDiscoveryComponent"
- class="org.rhq.plugins.jmx.MBeanResourceComponent"
- description="Statistics for JBoss ESB Deployments">
+ class="org.jbosson.plugins.jbossesb.DeploymentComponent"
+ description="Statistics for JBoss ESB Deployments"
+ creationDataType="content"
+ createDeletePolicy="both">
<plugin-configuration>
<c:simple-property name="objectName" readOnly="true" default="jboss.esb:deployment=%deployment%"/>
<c:simple-property name="nameTemplate" default="{deployment} JBoss ESB Statistics"/>
<c:simple-property name="descriptionTemplate" default="JBoss ESB statistics for the {deployment} deployment."/>
<c:simple-property name="deployment" type="string" description="the JBoss ESB deployment name"/>
+ <c:group name="advanced" displayName="Advanced" hiddenByDefault="true">
+ <c:simple-property name="extension" default="esb" readOnly="true"/>
+ <c:simple-property name="descriptionTemplate" default="ESB package" readOnly="true"/>
+ </c:group>
</plugin-configuration>
-
-
<operation name="start" displayName="Start deployment" description="Start the JBoss ESB deployment"/>
<operation name="stop" displayName="Stop deployment" description="Stop the JBoss ESB deployment"/>
<operation name="create" displayName="Move .esb deployment into the create state" description="Move the .esb deployment into the create state"/>
<operation name="destroy" displayName="Move .esb deployment into the destroy state" description="Move the .esb deployment into the destroy state"/>
-
<metric property="Name" displayName="Deployment Type" dataType="trait" displayType="summary" defaultOn="true" description="Type of deployment"/>
<metric property="StateString" displayName=".esb State String" dataType="trait" displayType="summary" defaultOn="true" description="Current state of the ESB"/>
<metric property="State" displayName=".esb State" dataType="trait" displayType="summary" defaultOn="true" description="Numeric value of the state of the ESB deployment"/>
- <help>
+ <!--help>
<![CDATA[
JBoss ESB deployments are .esb packages deployed within a server.
]]>
- </help>
+ </help-->
+ <content name="file" displayName="ESB Package" category="deployable" isCreationType="true">
+ <configuration>
+ <c:group name="deployment" displayName="Deployment Options">
+ <c:simple-property name="deployZipped" displayName="Deploy Zipped" type="boolean" default="false" required="true"
+ description="Indicates if the ESB is deployed either zipped or exploded."/>
+ <c:simple-property name="deployDirectory" displayName="Deploy Directory" type="string" default="deploy" required="true"
+ description="Path to deploy the file. This must be a path relative to the AS configuration set in use."/>
+ </c:group>
+ </configuration>
+ </content>
<service name="JBoss ESB Services"
discovery="org.jbosson.plugins.jbossesb.ESBDiscoveryComponent"
class="ServiceComponent"
More information about the jboss-svn-commits
mailing list