[jboss-svn-commits] JBL Code SVN: r30479 - in labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin: as4/src/main/java/org/jbosson/plugins/jbossesb and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Dec 5 03:59:03 EST 2009
Author: tcunning
Date: 2009-12-05 03:59:03 -0500 (Sat, 05 Dec 2009)
New Revision: 30479
Added:
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5ContentFacetDelegate.java
Modified:
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBDeploymentComponent.java
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5DeploymentComponent.java
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/resources/META-INF/rhq-plugin.xml
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/build.xml
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java
labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java
Log:
JBESB-3025
Switch the AS5 plugin to use the profile service when adding or deleting
an ESB deployment through JON.
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBComponent.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -109,4 +109,24 @@
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;
+ }
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBDeploymentComponent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBDeploymentComponent.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as4/src/main/java/org/jbosson/plugins/jbossesb/ESBDeploymentComponent.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -24,110 +24,11 @@
* @param <T>
*/
public class ESBDeploymentComponent extends AbstractDeploymentComponent {
- 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(), 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);
- }
- }
-
public void deleteResource() throws Exception {
- Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ Configuration pluginConfiguration = getResourceContext().getPluginConfiguration();
String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
- ESBComponent jbossASComponent = (ESBComponent) super.resourceContext.getParentResourceComponent();
+ ESBComponent jbossASComponent = (ESBComponent) getResourceContext().getParentResourceComponent();
//File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
final File deploy = new File(jbossASComponent.getConfigurationPath(), "deploy");
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5Component.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -1,143 +1,240 @@
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.net.URI;
+import java.net.URISyntaxException;
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;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.jboss.on.common.jbossas.JBPMWorkflowManager;
+import org.jboss.on.common.jbossas.JBossASPaths;
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.domain.resource.ResourceType;
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.jbossas5.ApplicationServerComponent;
+import org.rhq.plugins.jbossas5.connection.LocalProfileServiceConnectionProvider;
+import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
+import org.rhq.plugins.jbossas5.connection.ProfileServiceConnectionProvider;
+import org.rhq.plugins.jbossas5.connection.RemoteProfileServiceConnectionProvider;
+import org.rhq.plugins.jbossas5.deploy.Deployer;
+import org.rhq.plugins.jbossas5.deploy.LocalDeployer;
+import org.rhq.plugins.jbossas5.deploy.RemoteDeployer;
+import com.jboss.jbossnetwork.product.jbpm.handlers.ControlActionFacade;
+/**
+ * Component for ESB deployments.
+ *
+ * @author Tom Cunningham
+ */
public class ESB5Component extends AbstractESBComponent
{
- public File getConfigurationPath()
- {
- ApplicationServerComponent jass = (ApplicationServerComponent)this.resourceContext.getParentResourceComponent();
- ResourceContext rc = jass.getResourceContext();
- Configuration config = rc.getPluginConfiguration();
+ static final String HOME_DIR = "homeDir";
+ static final String SERVER_HOME_DIR = "serverHomeDir";
- String configurationPath = config.getSimpleValue("serverHomeDir", null);
+ static final String NAMING_URL = "namingURL";
+ static final String CREDENTIALS = "credentials";
+ static final String PRINCIPAL = "principal";
- return new File(configurationPath);
- }
-
- protected void esbCreate(CreateResourceReport report, String resourceTypeName) {
- ResourcePackageDetails details = report.getPackageDetails();
- PackageDetailsKey key = details.getKey();
- String archiveName = key.getName();
+ private ProfileServiceConnection connection;
+
+ private ESB5ContentFacetDelegate contentFacetDelegate;
+
+ @Override
+ public void start(ResourceContext context) {
+ super.start(context);
+ JBPMWorkflowManager workflowManager = createJbpmWorkflowManager(resourceContext);
- 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;
- }
+ connectToProfileService();
+
+ this.contentFacetDelegate = new ESB5ContentFacetDelegate(workflowManager, configPath,
+ resourceContext.getContentContext());
+ }
- Configuration deployTimeConfiguration = details.getDeploymentTimeConfiguration();
- String deployDirectory = deployTimeConfiguration.getSimple("deployDirectory").getStringValue();
+ public void stop() {
+ disconnectFromProfileService();
+ }
+
+ private JBPMWorkflowManager createJbpmWorkflowManager(ResourceContext resourceContext) {
+ ContentContext contentContext = resourceContext.getContentContext();
+ ControlActionFacade controlActionFacade = null;
+ JBPMWorkflowManager workflowManager = new JBPMWorkflowManager(contentContext, controlActionFacade, this
+ .getJBossASPaths());
+ return workflowManager;
+ }
+
+ public boolean runningEmbedded() {
+ ApplicationServerComponent jass = (ApplicationServerComponent)this.resourceContext.getParentResourceComponent();
+ ResourceContext rc = jass.getResourceContext();
- // 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);
+ Configuration pluginConfiguration = rc.getPluginConfiguration();
+ String namingUrl = pluginConfiguration.getSimpleValue(NAMING_URL, null);
+ return namingUrl == null;
+ }
+
+ private static void validateNamingURL(String namingURL) {
+ URI namingURI;
+ try {
+ namingURI = new URI(namingURL);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Naming URL '" + namingURL + "' is not valid: " + e.getLocalizedMessage());
+ }
+ if (!namingURI.isAbsolute())
+ throw new RuntimeException("Naming URL '" + namingURL + "' is not absolute.");
+ if (!namingURI.getScheme().equals("jnp"))
+ throw new RuntimeException("Naming URL '" + namingURL
+ + "' has an invalid protocol - the only valid protocol is 'jnp'.");
+ }
+
+ private void connectToProfileService() {
+ ApplicationServerComponent jass = (ApplicationServerComponent)this.resourceContext.getParentResourceComponent();
+ ResourceContext rc = jass.getResourceContext();
- 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);
- }
+ if (this.connection != null)
+ return;
+ // TODO: Check for a defunct connection and if found try to reconnect.
+ ProfileServiceConnectionProvider connectionProvider;
+ if (runningEmbedded()) {
+ connectionProvider = new LocalProfileServiceConnectionProvider();
+ } else {
+ Configuration pluginConfig = rc.getPluginConfiguration();
+ String namingURL = pluginConfig.getSimpleValue(NAMING_URL, null);
+ validateNamingURL(namingURL);
+ String principal = pluginConfig.getSimpleValue(PRINCIPAL, null);
+ String credentials = pluginConfig.getSimpleValue(CREDENTIALS, null);
+ connectionProvider = new RemoteProfileServiceConnectionProvider(namingURL, principal, credentials);
+ }
+ try {
+ this.connection = connectionProvider.connect();
+ } catch (RuntimeException e) {
+ Throwable rootCause = ExceptionUtils.getRootCause(e);
+ if (rootCause instanceof SecurityException) {
+ if (log.isDebugEnabled()) {
+ log.debug("Failed to connect to Profile Service.", e);
+ } else {
+ log.warn("Failed to connect to Profile Service - cause: " + rootCause);
+ }
+ throw new InvalidPluginConfigurationException(
+ "Values of 'principal' and/or 'credentials' connection properties are invalid.", rootCause);
+ }
+ log.debug("Failed to connect to Profile Service.", e);
+ }
+ }
- // Perform the deployment
- FileContentDelegate deployer = new FileContentDelegate(new File(getConfigurationPath(),deployDirectory),
- "", details.getPackageTypeName());
+ public void disconnectFromProfileService() {
+ if (this.connection != null) {
+ try {
+ this.connection.getConnectionProvider().disconnect();
+ } catch (RuntimeException e) {
+ log.debug("Failed to disconnect from Profile Service.", e);
+ } finally {
+ this.connection = null;
+ }
+ }
+ }
+
+ private File resolvePathRelativeToHomeDir(String path) {
+ File configDir = new File(path);
+ if (!configDir.isAbsolute()) {
+ Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
+ String homeDir = pluginConfig.getSimple(HOME_DIR).getStringValue();
+ configDir = new File(homeDir, path);
+ }
+ return configDir;
+ }
+
+ private JBossASPaths getJBossASPaths() {
+ Configuration pluginConfiguration = this.resourceContext.getPluginConfiguration();
- PropertySimple zipProperty = deployTimeConfiguration.getSimple("deployZipped");
+ String homeDir = pluginConfiguration.getSimpleValue(HOME_DIR, null);
+ String serverHomeDir = pluginConfiguration.getSimpleValue(SERVER_HOME_DIR, null);
- if (zipProperty != null && zipProperty.getBooleanValue() != null) {
- boolean zip = zipProperty.getBooleanValue();
+ return new JBossASPaths(homeDir, serverHomeDir);
+ }
+
+ public File getConfigurationPath() {
+ ApplicationServerComponent jass = (ApplicationServerComponent)this.resourceContext.getParentResourceComponent();
+ ResourceContext rc = jass.getResourceContext();
+ Configuration config = rc.getPluginConfiguration();
+ String configurationPath = config.getSimpleValue("serverHomeDir", null);
+ File configPath = new File(configurationPath);
+ if (!configPath.isDirectory()) {
+ throw new InvalidPluginConfigurationException("Configuration path '" + configPath + "' does not exist.");
+ }
+
+ return configPath;
+ }
+
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ ResourceType resourceType = report.getResourceType();
+ String resourceTypeName = report.getResourceType().getName();
- File tempDir = resourceContext.getTemporaryDirectory();
- File tempFile = new File(tempDir.getAbsolutePath(), "esb.bin");
- OutputStream osForTempDir = new BufferedOutputStream(new FileOutputStream(tempFile));
+ // Hack - AbstractDeployer is looking for a "deployExploded" value rather than a
+ // deployZipped value - if we don't already have these properties, add them in
+ ResourcePackageDetails details = report.getPackageDetails();
+ Configuration deployTimeConfig = details.getDeploymentTimeConfiguration();
- contentContext = resourceContext.getContentContext();
- ContentServices contentServices = contentContext.getContentServices();
- contentServices
- .downloadPackageBitsForChildResource(contentContext, resourceTypeName, key, osForTempDir);
+ if (deployTimeConfig.get("deployExploded") == null) {
+ PropertySimple ps = new PropertySimple();
+ ps.setName("deployExploded");
+ ps.setBooleanValue(!deployTimeConfig.getSimple("deployZipped").getBooleanValue());
+ deployTimeConfig.put(ps);
+ }
+
+ if (deployTimeConfig.get("deployFarmed") == null) {
+ PropertySimple df = new PropertySimple();
+ df.setName("deployFarmed");
+ df.setBooleanValue(false);
+ deployTimeConfig.put(df);
+ }
+
+ if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
+ getDeployer().deploy(report, resourceType);
+ } else {
+ throw new UnsupportedOperationException("Unknown Resource type: " + resourceTypeName);
+ }
+
+ disconnectFromProfileService();
+ return report;
+ }
- osForTempDir.close();
+ protected Deployer getDeployer() {
+ ProfileServiceConnection profileServiceConnection = getConnection();
+ if (runningEmbedded()) {
+ return new LocalDeployer(profileServiceConnection);
+ } else {
+ return new RemoteDeployer(profileServiceConnection, this.resourceContext);
+ }
+ }
- InputStream isForTempDir = new BufferedInputStream(new FileInputStream(tempFile));
- deployer.createContent(details, isForTempDir, !zip, false);
+ public ProfileServiceConnection getConnection() {
+ connectToProfileService();
+ return this.connection;
+ }
- // Resource key should match the following:
- // ESB: jboss.esb:deployment=jbossesb.esb
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
+ return contentFacetDelegate.discoverDeployedPackages(type);
+ }
- String resourceKey;
- resourceKey = "jboss.esb:deployment=" + archiveName;
+ public List<DeployPackageStep> generateInstallationSteps(ResourcePackageDetails packageDetails) {
+ return contentFacetDelegate.generateInstallationSteps(packageDetails);
+ }
- 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 RemovePackagesResponse removePackages(Set<ResourcePackageDetails> packages) {
+ return contentFacetDelegate.removePackages(packages);
}
-
-
-}
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ return contentFacetDelegate.retrievePackageBits(packageDetails);
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5ContentFacetDelegate.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5ContentFacetDelegate.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5ContentFacetDelegate.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -0,0 +1,209 @@
+package org.jbosson.plugins.jbossesb;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.on.common.jbossas.AbstractJBossASContentFacetDelegate;
+import org.jboss.on.common.jbossas.JBPMWorkflowManager;
+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.DeployPackagesResponse;
+import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
+import org.rhq.core.pluginapi.content.ContentContext;
+import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.plugins.jbossas5.util.FileContentDelegate;
+import org.rhq.plugins.jbossas5.util.JarContentDelegate;
+
+import org.rhq.plugins.jbossas5.EmptyFileException;
+
+public class ESB5ContentFacetDelegate extends AbstractJBossASContentFacetDelegate {
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private final Map<PackageType, FileContentDelegate> contentDelegates = new HashMap<PackageType, FileContentDelegate>();
+
+ private File configurationPath;
+
+ private ContentContext contentContext;
+
+ private void setConfigurationPath(File configurationPath) {
+ this.configurationPath = configurationPath;
+ }
+
+ private File getConfigurationPath() {
+ return this.configurationPath;
+ }
+
+ private void setContentContext(ContentContext contentContext) {
+ this.contentContext = contentContext;
+ }
+
+ private ContentContext getContentContext() {
+ return this.contentContext;
+ }
+
+ protected ESB5ContentFacetDelegate(JBPMWorkflowManager workflowManager, File configurationPath,
+ ContentContext contentContext) {
+ super(workflowManager);
+ this.setConfigurationPath(configurationPath);
+ this.setContentContext(contentContext);
+ }
+
+ @Override
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
+ FileContentDelegate contentDelegate = getContentDelegate(type);
+
+ Set<ResourcePackageDetails> details = null;
+ if (contentDelegate != null) {
+ details = contentDelegate.discoverDeployedPackages();
+ }
+
+ return details;
+ }
+
+ private FileContentDelegate getContentDelegate(PackageType type) {
+ FileContentDelegate contentDelegate = contentDelegates.get(type);
+ if (contentDelegate == null) {
+ if (type.getName().equals("library")) {
+ File deployLib = new File(this.getConfigurationPath(), "lib");
+ contentDelegate = new JarContentDelegate(deployLib, type.getName());
+ }
+
+ contentDelegates.put(type, contentDelegate);
+ }
+
+ return contentDelegate;
+ }
+
+ @Override
+ 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_PATCH)) {
+
+ if (packages.size() > 1) {
+ log.warn("Attempt to install more than one patch at a time, installation aborted.");
+
+ DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
+ response
+ .setOverallRequestErrorMessage("When deploying a patch, no other packages may be deployed at the same time.");
+ return response;
+ }
+
+ try {
+ DeployIndividualPackageResponse response = getWorkflowManager().run(pkg);
+
+ if (response.getResult() == ContentResponseResult.FAILURE) {
+ overallResult = ContentResponseResult.FAILURE;
+ }
+
+ // just in case response is null, it would throw NPE on the getResult() check above but the item
+ // would already be a member in individualResponses; moving the add below the check ensures that
+ // only non-null instances of individualResponses will ever make it into the List
+ individualResponses.add(response);
+ } catch (Throwable throwable) {
+ log.error("Error deploying package: " + pkg, throwable);
+
+ // Don't forget to provide an individual response for the failed package.
+ DeployIndividualPackageResponse response = new DeployIndividualPackageResponse(pkg.getKey(),
+ ContentResponseResult.FAILURE);
+ response.setErrorMessageFromThrowable(throwable);
+ individualResponses.add(response);
+
+ overallResult = ContentResponseResult.FAILURE;
+ }
+ } else if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
+ if (packages.size() > 1) {
+ log.warn("Attempt to install more than one patch at a time, installation aborted.");
+
+ DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
+ response
+ .setOverallRequestErrorMessage("When deploying a patch, no other packages may be deployed at the same time.");
+ return response;
+ } else {
+ deployJarLibrary(pkg, contentServices);
+ }
+ }
+ }
+
+ DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
+ response.getPackageResponses().addAll(individualResponses);
+
+ return response;
+ }
+
+ public DeployPackagesResponse deployJarLibrary(ResourcePackageDetails packageDetails,
+ ContentServices contentServices) {
+ ContentResponseResult overallResult = ContentResponseResult.SUCCESS;
+ List<DeployIndividualPackageResponse> individualResponses = new ArrayList<DeployIndividualPackageResponse>(1);
+ String deployDir = this.getConfigurationPath() + File.separator + "lib";
+ String destinationFileLocation = deployDir + File.separator + packageDetails.getKey().getName() + ".jar";
+ //get the name of the uploaded file.
+
+ try {
+ downloadBits(packageDetails.getKey(), destinationFileLocation);
+ } catch (Throwable throwable) {
+ log.error("Error deploying package: " + packageDetails, throwable);
+ DeployIndividualPackageResponse response = new DeployIndividualPackageResponse(packageDetails.getKey(),
+ ContentResponseResult.FAILURE);
+ response.setErrorMessageFromThrowable(throwable);
+ individualResponses.add(response);
+ overallResult = ContentResponseResult.FAILURE;
+ }
+
+ DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
+ response.getPackageResponses().addAll(individualResponses);
+ return response;
+ }
+
+ public void downloadBits(PackageDetailsKey key, String destinationFileLocation) throws IOException,
+ EmptyFileException {
+ ContentServices contentServices = this.getContentContext().getContentServices();
+
+ // Open a stream to where the downloaded file should go
+ FileOutputStream output = new FileOutputStream(destinationFileLocation);
+ BufferedOutputStream bufferedOutput = new BufferedOutputStream(output, 4096);
+
+ // Request the bits from the server
+ try {
+ contentServices.downloadPackageBits(contentContext, key, bufferedOutput, true);
+ bufferedOutput.close();
+
+ // Verify the file was created correctly
+ File downloadedFile = new File(destinationFileLocation);
+ if (!downloadedFile.exists()) {
+ throw new FileNotFoundException("File to download [" + destinationFileLocation + "] does not exist");
+ }
+
+ if (downloadedFile.length() == 0) {
+ throw new EmptyFileException("Downloaded file [" + destinationFileLocation + "] is empty");
+ }
+ } finally {
+ // Close the stream if there was an error thrown from downloadPackageBits
+ try {
+ bufferedOutput.close();
+ } catch (IOException e1) {
+ log.error("Error closing output stream to [" + destinationFileLocation + "] after exception", e1);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5DeploymentComponent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5DeploymentComponent.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/java/org/jbosson/plugins/jbossesb/ESB5DeploymentComponent.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -2,6 +2,18 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import org.rhq.plugins.jbossas5.deploy.Deployer;
+import org.rhq.plugins.jbossas5.deploy.LocalDeployer;
+import org.rhq.plugins.jbossas5.deploy.RemoteDeployer;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -36,6 +48,7 @@
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.connection.ProfileServiceConnection;
import org.rhq.plugins.jbossas5.util.FileContentDelegate;
import org.rhq.plugins.jmx.JMXComponent;
import org.rhq.plugins.jmx.MBeanResourceComponent;
@@ -44,130 +57,48 @@
* Component for ESB package deployment.
*
* @author Tom Cunningham
- * @param <T>
*/
public class ESB5DeploymentComponent extends AbstractDeploymentComponent {
- 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(), 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);
- }
- }
-
public void deleteResource() throws Exception {
- Configuration pluginConfiguration = super.resourceContext.getPluginConfiguration();
+ Configuration pluginConfiguration = getResourceContext().getPluginConfiguration();
String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
- ESB5Component jbossASComponent = (ESB5Component) super.resourceContext.getParentResourceComponent();
- //File deploymentFile = jbossASComponent.getDeploymentFilePath(super.resourceContext.getResourceKey());
+ ESB5Component jbossASComponent = (ESB5Component) getResourceContext().getParentResourceComponent();
+ ProfileServiceConnection profileServiceConnection = jbossASComponent.getConnection();
+ DeploymentManager deployMgr = profileServiceConnection.getDeploymentManager();
- final File deploy = new File(jbossASComponent.getConfigurationPath(), "deploy");
- final File file = new File(deploy, fullFileName);
-
- if (!file.exists()) {
- throw new Exception("Cannot find application file to delete: " + fullFileName);
+ String repositoryName = null;
+ String [] arr = deployMgr.getRepositoryNames(new String[] {fullFileName});
+ for (int i = 0; i<arr.length; i++) {
+ repositoryName = arr[i];
}
-
- if (file.isDirectory()) {
- deleteDirectoryContents(file.listFiles());
+
+ DeploymentProgress stop = deployMgr.stop(repositoryName);
+ stop.run();
+ if (stop != null) {
+ DeploymentStatus stopStatus = stop.getDeploymentStatus();
+ if (stopStatus.isFailed()) {
+ log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
+ throw new Exception("Failed to stop deployment '" + repositoryName + "' - cause: "
+ + stopStatus.getFailure());
+ }
}
-
- boolean result = file.delete();
-
- if (!result) {
- throw new Exception("File delete call returned unsuccessful with no further detail");
+ DeploymentProgress remove = deployMgr.remove(repositoryName);
+ remove.run();
+ if (remove != null) {
+ DeploymentStatus status = remove.getDeploymentStatus();
+ if (status.isFailed()) {
+ log.error("Failed to remove deployment '" + repositoryName + "'.", status.getFailure());
+ throw new Exception("Failed to remove deployment '" + repositoryName + "' - cause: "
+ + status.getFailure());
+ }
+ } else {
+ throw new RuntimeException("Did not find Deployment " + fullFileName);
}
- }
+
+ ManagementView mView = profileServiceConnection.getManagementView();
+ mView.load();
+
+ jbossASComponent.disconnectFromProfileService();
+ }
}
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/resources/META-INF/rhq-plugin.xml 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/as5/src/main/resources/META-INF/rhq-plugin.xml 2009-12-05 08:59:03 UTC (rev 30479)
@@ -75,6 +75,7 @@
createDeletePolicy="both">
<plugin-configuration>
+ <c:simple-property name="deploymentTypeName" readOnly="true" default="JavaEEWebApplication"/>
<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."/>
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/build.xml 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/build.xml 2009-12-05 08:59:03 UTC (rev 30479)
@@ -79,6 +79,19 @@
<patternset refid="jonserver.patternset"/>
</unzip>
+ <path id="as5.plugin.location">
+ <fileset dir="${extract.as5.dir}" includes="**/jopr-jboss-as-5*.jar"/>
+ </path>
+ <property name="as5.plugin" refid="as5.plugin.location"/>
+ <unzip dest="${extract.as5.dir}">
+ <patternset>
+ <include name="**/jopr-jboss-as-common*.jar"/>
+ </patternset>
+ <fileset dir="${extract.as5.dir}">
+ <include name="**/jopr-jboss-as-5*.jar"/>
+ </fileset>
+ </unzip>
+
<unzip dest="${extract.as5.dir}">
<patternset>
<include name="**/org-mc4j-ems*.jar"/>
@@ -123,7 +136,8 @@
<src path="${java.as5.dir}"/>
<classpath>
<path refid="as5.classpath"/>
- <fileset dir="${product.lib.dir}" includes="commons-logging*.jar ejb3-persistence*.jar jaxb-api-*.jar jbossall-client*.jar"/>
+ <fileset dir="${product.lib.dir}" includes="jboss-metatype-8.jar jboss-managed-*.jar jboss-profileservice-spi-*.jar"/>
+ <fileset dir="${product.lib.dir}" includes="commons-logging*.jar commons-lang-*.jar ejb3-persistence*.jar jaxb-api-*.jar jbossall-client*.jar"/>
</classpath>
</javac>
</target>
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractDeploymentComponent.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -57,19 +57,7 @@
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;
- }
-
+
/**
* Check to see if the passed file is actually in jar format and contains a
* <ul>
@@ -145,8 +133,6 @@
}
}
- protected abstract void esbCreate(CreateResourceReport report, String resourceTypeName);
-
public DeployPackagesResponse deployPackages(
Set<ResourcePackageDetails> packages,
ContentServices contentServices) {
@@ -225,4 +211,4 @@
public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
return null;
}
-}
+}
\ No newline at end of file
Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java 2009-12-05 02:48:56 UTC (rev 30478)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/AbstractESBComponent.java 2009-12-05 08:59:03 UTC (rev 30479)
@@ -75,10 +75,10 @@
return av;
}
- abstract void esbCreate(CreateResourceReport report, String resourceTypeName);
+ //abstract void esbCreate(CreateResourceReport report, String resourceTypeName);
-
- public CreateResourceReport createResource(CreateResourceReport report) {
+ /*
+ public CreateResourceReport createResource(CreateResourceReport report) {
String resourceTypeName = report.getResourceType().getName();
if (resourceTypeName.equals(RESOURCE_TYPE_ESB)) {
@@ -97,7 +97,8 @@
return report;
}
-
+ */
+
public DeployPackagesResponse deployPackages(
Set<ResourcePackageDetails> packages,
ContentServices contentServices) {
More information about the jboss-svn-commits
mailing list