[jboss-svn-commits] JBL Code SVN: r29826 - in labs/jbossesb/trunk/product/tools/jonplugin: as4/src/main/java and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 26 23:01:26 EDT 2009
Author: tcunning
Date: 2009-10-26 23:01:26 -0400 (Mon, 26 Oct 2009)
New Revision: 29826
Added:
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/ivy.xml
labs/jbossesb/trunk/product/tools/jonplugin/ivysettings.xml
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java
Removed:
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
Modified:
labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java
labs/jbossesb/trunk/product/tools/jonplugin/build.xml
Log:
JBESB-2907
Fix compilation issues with as4/as5 plugin build.
Added: labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,322 @@
+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.JBossASServerComponent;
+import org.rhq.plugins.jbossas.util.FileContentDelegate;
+import org.rhq.plugins.jmx.JMXComponent;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+/**
+ * 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, false);
+
+ // 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;
+ }
+
+ /**
+ * Recursively deletes a series of files. Any directories found in the list of files will be recursively deleted as
+ * well.
+ *
+ * @param contents list of files to delete
+ */
+ public static void deleteDirectoryContents(File[] contents) {
+ for (File file : contents) {
+ if (file.isDirectory()) {
+ deleteDirectoryContents(file.listFiles());
+ }
+
+ file.delete();
+ }
+ }
+
+ public void deleteResource() throws Exception {
+ Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
+
+ ESBComponent jbossASComponent = (ESBComponent) super.resourceContext.getParentResourceComponent();
+ //File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
+
+ File file = new File(jbossASComponent.getConfigurationPath() + "/deploy/" + fullFileName);
+
+ if (!file.exists()) {
+ throw new Exception("Cannot find application file to delete: " + fullFileName);
+ }
+
+ if (file.isDirectory()) {
+ 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/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -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 AbstractESBComponent {
+ 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;
+ }
+
+ protected 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, false);
+
+ // 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();
+ }
+}
Added: labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,322 @@
+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.jbossas5.ApplicationServerComponent;
+import org.rhq.plugins.jbossas5.util.FileContentDelegate;
+import org.rhq.plugins.jmx.JMXComponent;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+/**
+ * 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, false);
+
+ // 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;
+ }
+
+ /**
+ * Recursively deletes a series of files. Any directories found in the list of files will be recursively deleted as
+ * well.
+ *
+ * @param contents list of files to delete
+ */
+ public static void deleteDirectoryContents(File[] contents) {
+ for (File file : contents) {
+ if (file.isDirectory()) {
+ deleteDirectoryContents(file.listFiles());
+ }
+
+ file.delete();
+ }
+ }
+
+ public void deleteResource() throws Exception {
+ Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
+
+ ESB5Component jbossASComponent = (ESB5Component) super.resourceContext.getParentResourceComponent();
+ //File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
+
+ File file = new File(jbossASComponent.getConfigurationPath() + "/deploy/" + fullFileName);
+
+ if (!file.exists()) {
+ throw new Exception("Cannot find application file to delete: " + fullFileName);
+ }
+
+ if (file.isDirectory()) {
+ 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;
+ }
+
+}
Modified: labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java 2009-10-26 18:07:09 UTC (rev 29825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -1,11 +1,45 @@
package org.jbosson.plugins.jbossesb;
import java.io.File;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+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.pluginapi.inventory.ResourceContext;
import org.rhq.plugins.jbossas5.ApplicationServerComponent;
+import org.rhq.plugins.jbossas5.util.FileContentDelegate;
-public class ESB5Component extends ESBComponent
+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;
+
+
+public class ESB5Component extends AbstractESBComponent
{
public File getConfigurationPath()
{
@@ -17,4 +51,93 @@
return new File(configurationPath);
}
+
+ protected 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, false);
+
+ // 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);
+ }
+ }
+
+
+
}
Modified: labs/jbossesb/trunk/product/tools/jonplugin/build.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/build.xml 2009-10-26 18:07:09 UTC (rev 29825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/build.xml 2009-10-27 03:01:26 UTC (rev 29826)
@@ -1,10 +1,15 @@
-<project name="jon-build" default="build-plugins" basedir=".">
+<project name="jon-build" default="build-plugins" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
+ <property name="build.dir" location="build"/>
+
+ <property name="ivy.lib.dir" location="${build.dir}/lib"/>
+ <property name="classpath.dir" location="../../../antlib"/>
<property name="product.dir" location="../.."/>
<property name="product.build.dir" location="${product.dir}/build"/>
<property name="product.lib.dir" location="${product.build.dir}/lib"/>
- <property name="build.dir" location="build"/>
+ <property name="server.default.lib.dir" location="${product.build.dir}/jbossesb-server-4.6/server/default/lib"/>
+
<property name="extract.dir" location="${build.dir}/extract"/>
<property name="extract.as4.dir" location="${extract.dir}/as4"/>
<property name="extract.as5.dir" location="${extract.dir}/as5"/>
@@ -21,8 +26,12 @@
<property name="classes.as4.dir" location="${classes.dir}/as4"/>
<property name="classes.as5.dir" location="${classes.dir}/as5"/>
- <property name="jonserver.as4" location="jonserver/jbas4-admin-console.war"/>
- <property name="jonserver.as5" location="jonserver/jbas5-admin-console.war"/>
+ <property name="jonserver.as4" location="build/lib/jopr-embedded-jbas4-1.2.0.GA.war"/>
+ <property name="jonserver.as5" location="build/lib/jopr-embedded-jbas5-1.3.2.GA.war"/>
+ <path id="classpath.ivy">
+ <fileset dir="${classpath.dir}" includes="ivy-*.jar" />
+ </path>
+ <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="classpath.ivy" />
<patternset id="jonserver.patternset">
<include name="**/rhq-jbossas-plugin*.jar"/>
@@ -34,6 +43,22 @@
<include name="**/jopr-jboss-as-*plugin-*.jar"/>
</patternset>
+ <target name="ivy.init" depends="clean">
+ <ivy:settings file="ivysettings.xml" />
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${ivy.lib.dir}"/>
+ <mkdir dir="${extract.dir}"/>
+ <mkdir dir="${classes.dir}"/>
+ </target>
+
+ <target name="retrieve" depends="ivy.init">
+ <ivy:retrieve/>
+ </target>
+
+ <target name="cleancache" depends="ivy.init">
+ <ivy:cleancache/>
+ </target>
+
<target name="init" depends="clean">
<mkdir dir="${build.dir}"/>
<mkdir dir="${extract.dir}"/>
@@ -45,7 +70,7 @@
</target>
<target name="clean">
- <delete dir="${build.dir}"/>
+ <delete dir="build"/>
</target>
<target name="extract-as4-classpath-jars" depends="init">
@@ -112,24 +137,26 @@
</pathconvert>
</target>
- <target name="compile-as4-plugin" depends="extract-as4-classpath-jars">
+ <target name="compile-as4-plugin" depends="retrieve,extract-as4-classpath-jars">
<javac destdir="${classes.as4.dir}" debug="true" source="1.5">
<src path="${java.dir}"/>
<src path="${java.as4.dir}"/>
<classpath>
<path refid="as4.classpath"/>
<fileset dir="${product.lib.dir}" includes="commons-logging*.jar"/>
+ <fileset dir="${server.default.lib.dir}" includes="ejb3-persistence.jar, hibernate3.jar, hibernate-annotations.jar, hibernate-entitymanager.jar"/>
</classpath>
</javac>
</target>
- <target name="compile-as5-plugin" depends="extract-as5-classpath-jars">
+ <target name="compile-as5-plugin" depends="retrieve,extract-as5-classpath-jars">
<javac destdir="${classes.as5.dir}" debug="true" source="1.5">
<src path="${java.dir}"/>
<src path="${java.as5.dir}"/>
<classpath>
<path refid="as5.classpath"/>
<fileset dir="${product.lib.dir}" includes="commons-logging*.jar"/>
+ <fileset dir="${server.default.lib.dir}" includes="ejb3-persistence.jar, hibernate3.jar, hibernate-annotations.jar, hibernate-entitymanager.jar"/>
</classpath>
</javac>
</target>
Added: labs/jbossesb/trunk/product/tools/jonplugin/ivy.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/ivy.xml (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/ivy.xml 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,12 @@
+<ivy-module version="2.0">
+ <info organisation="org.jboss" module="jbossesb"/>
+ <dependencies>
+ <dependency org="org.jboss.jopr" name="jopr-embedded-jbas4" rev="1.2.0.GA">
+ <artifact name="jopr-embedded-jbas4" type="war"/>
+ </dependency>
+
+ <dependency org="org.jboss.jopr" name="jopr-embedded-jbas5" rev="1.3.2.GA">
+ <artifact name="jopr-embedded-jbas5" type="war"/>
+ </dependency>
+ </dependencies>
+</ivy-module>
Added: labs/jbossesb/trunk/product/tools/jonplugin/ivysettings.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/ivysettings.xml (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/ivysettings.xml 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,8 @@
+<ivysettings>
+ <settings defaultResolver="jbossMaven"/>
+ <resolvers>
+ <url name="jbossMaven">
+ <artifact pattern="http://repository.jboss.com/maven2/org/jboss/jopr/[artifact]/[revision]/[artifact]-[revision].[ext]"/>
+ </url>
+ </resolvers>
+</ivysettings>
Added: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,221 @@
+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.jmx.JMXComponent;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+
+public abstract class AbstractDeploymentComponent 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Recursively deletes a series of files. Any directories found in the list of files will be recursively deleted as
+ * well.
+ *
+ * @param contents list of files to delete
+ */
+ public static void deleteDirectoryContents(File[] contents) {
+ for (File file : contents) {
+ if (file.isDirectory()) {
+ deleteDirectoryContents(file.listFiles());
+ }
+
+ file.delete();
+ }
+ }
+
+ public void deleteResource() throws Exception {
+ }
+ /*
+ public void deleteResource() throws Exception {
+ Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
+
+ ESBComponent jbossASComponent = (ESBComponent) super.resourceContext.getParentResourceComponent();
+ //File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
+
+ File file = new File(jbossASComponent.getConfigurationPath() + "/deploy/" + fullFileName);
+
+ if (!file.exists()) {
+ throw new Exception("Cannot find application file to delete: " + fullFileName);
+ }
+
+ if (file.isDirectory()) {
+ deleteDirectoryContents(file.listFiles());
+ }
+
+ boolean result = file.delete();
+
+ if (!result) {
+ throw new Exception("File delete call returned unsuccessful with no further detail");
+ }
+ }
+ */
+
+ 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;
+ }
+
+ abstract void esbCreate(CreateResourceReport report, String resourceTypeName);
+
+ 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/AbstractESBComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -0,0 +1,141 @@
+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.jmx.MBeanResourceComponent;
+
+public abstract class AbstractESBComponent extends MBeanResourceComponent implements CreateChildResourceFacet, ContentFacet {
+ protected static final String RESOURCE_TYPE_ESB = "JBoss ESB Deployment";
+
+ protected String configSet;
+ protected ResponseTimeLogParser logParser;
+ protected File configPath;
+
+ protected ContentContext contentContext;
+ protected 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
+ protected static final String PACKAGE_TYPE_PATCH = "cumulativePatch";
+ protected 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());
+ }
+
+ abstract File getConfigurationPath();
+
+ @Override
+ public AvailabilityType getAvailability() {
+ AvailabilityType av = super.getAvailability();
+ return av;
+ }
+
+ abstract void esbCreate(CreateResourceReport report, String resourceTypeName);
+
+
+ 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();
+ }
+}
+
Deleted: 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 2009-10-26 18:07:09 UTC (rev 29825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/DeploymentComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -1,322 +0,0 @@
-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.JBossASServerComponent;
-import org.rhq.plugins.jbossas.util.FileContentDelegate;
-import org.rhq.plugins.jmx.JMXComponent;
-import org.rhq.plugins.jmx.MBeanResourceComponent;
-
-/**
- * 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, false);
-
- // 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;
- }
-
- /**
- * Recursively deletes a series of files. Any directories found in the list of files will be recursively deleted as
- * well.
- *
- * @param contents list of files to delete
- */
- public static void deleteDirectoryContents(File[] contents) {
- for (File file : contents) {
- if (file.isDirectory()) {
- deleteDirectoryContents(file.listFiles());
- }
-
- file.delete();
- }
- }
-
- public void deleteResource() throws Exception {
- Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
- String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
-
- ESBComponent jbossASComponent = (ESBComponent) super.resourceContext.getParentResourceComponent();
- //File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
-
- File file = new File(jbossASComponent.getConfigurationPath() + "/deploy/" + fullFileName);
-
- if (!file.exists()) {
- throw new Exception("Cannot find application file to delete: " + fullFileName);
- }
-
- if (file.isDirectory()) {
- 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;
- }
-
-}
Deleted: 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 2009-10-26 18:07:09 UTC (rev 29825)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java 2009-10-27 03:01:26 UTC (rev 29826)
@@ -1,228 +0,0 @@
-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, false);
-
- // 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();
- }
-}
More information about the jboss-svn-commits
mailing list