[teiid-commits] teiid SVN: r2839 - in branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin: deployer and 1 other directory.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Wed Jan 12 18:13:10 EST 2011
Author: tejones
Date: 2011-01-12 18:13:09 -0500 (Wed, 12 Jan 2011)
New Revision: 2839
Added:
branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/
branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/AbstractDeployer.java
branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/Deployer.java
branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/RemoteDeployer.java
Modified:
branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/Facet.java
Log:
TEIID-1430 - Updated VDB deployment process to work properly in JON and Embedded Jopr
Modified: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/Facet.java
===================================================================
--- branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2011-01-12 21:38:28 UTC (rev 2838)
+++ branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2011-01-12 23:13:09 UTC (rev 2839)
@@ -80,6 +80,8 @@
import org.rhq.plugins.jbossas5.ProfileServiceComponent;
import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
import org.teiid.rhq.admin.DQPManagementView;
+import org.teiid.rhq.plugin.deployer.Deployer;
+import org.teiid.rhq.plugin.deployer.RemoteDeployer;
import org.teiid.rhq.plugin.objects.ExecutedOperationResultImpl;
import org.teiid.rhq.plugin.objects.ExecutedResult;
import org.teiid.rhq.plugin.util.DeploymentUtils;
@@ -792,44 +794,15 @@
protected void createContentBasedResource(
CreateResourceReport createResourceReport) {
+
+ getDeployer().deploy(createResourceReport, createResourceReport.getResourceType());
- ResourcePackageDetails details = createResourceReport
- .getPackageDetails();
- PackageDetailsKey key = details.getKey();
- // This is the full path to a temporary file which was written by the UI
- // layer.
- String archivePath = key.getName();
-
- try {
- File archiveFile = new File(archivePath);
-
- if (!DeploymentUtils.hasCorrectExtension(archiveFile.getName(),
- resourceContext.getResourceType())) {
- createResourceReport.setStatus(CreateResourceStatus.FAILURE);
- createResourceReport
- .setErrorMessage("Incorrect extension specified on filename [" //$NON-NLS-1$
- + archivePath + "]"); //$NON-NLS-1$
-
- }
-
- DeploymentManager deploymentManager = getConnection()
- .getDeploymentManager();
- DeploymentUtils
- .deployArchive(deploymentManager, archiveFile, false);
-
- deploymentName = archivePath;
- createResourceReport.setResourceName(archivePath);
- createResourceReport.setResourceKey(archivePath);
- createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
-
- } catch (Throwable t) {
- log.error("Error deploying application for report: " //$NON-NLS-1$
- + createResourceReport, t);
- createResourceReport.setStatus(CreateResourceStatus.FAILURE);
- createResourceReport.setException(t);
- }
-
}
+
+ private Deployer getDeployer() {
+ ProfileServiceConnection profileServiceConnection = getConnection();
+ return new RemoteDeployer(profileServiceConnection, this.resourceContext);
+ }
private static String getResourceName(Configuration pluginConfig,
Configuration resourceConfig) {
Added: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/AbstractDeployer.java
===================================================================
--- branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/AbstractDeployer.java (rev 0)
+++ branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/AbstractDeployer.java 2011-01-12 23:13:09 UTC (rev 2839)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.deployer;
+
+import java.io.File;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.content.PackageDetailsKey;
+import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
+import org.rhq.core.domain.resource.CreateResourceStatus;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
+import org.teiid.rhq.plugin.util.DeploymentUtils;
+
+/**
+ * Abstract base class capturing the common deploy functionality for embedded
+ * and remote scenarios.
+ *
+ */
+public abstract class AbstractDeployer implements Deployer {
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private ProfileServiceConnection profileServiceConnection;
+
+ protected AbstractDeployer(ProfileServiceConnection profileService) {
+ this.profileServiceConnection = profileService;
+ }
+
+ public void deploy(CreateResourceReport createResourceReport, ResourceType resourceType) {
+ File archiveFile = null;
+ try {
+ ResourcePackageDetails details = createResourceReport.getPackageDetails();
+ PackageDetailsKey key = details.getKey();
+
+ archiveFile = prepareArchive(key, resourceType);
+
+ String archiveName = key.getName();
+
+ if (!DeploymentUtils.hasCorrectExtension(archiveName, resourceType)) {
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setErrorMessage("Incorrect extension specified on filename [" + archiveName + "]");
+ return;
+ }
+
+ // abortIfApplicationAlreadyDeployed(resourceType, archiveFile);
+
+ Configuration deployTimeConfig = details.getDeploymentTimeConfiguration();
+ @SuppressWarnings( { "ConstantConditions" })
+
+ DeploymentManager deploymentManager = this.profileServiceConnection.getDeploymentManager();
+
+ DeploymentUtils.deployArchive(deploymentManager, archiveFile, false);
+
+ // Deployment was successful!
+ createResourceReport.setResourceName(archiveName);
+ createResourceReport.setResourceKey(archiveName);
+ createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
+
+ } catch (Throwable t) {
+ log.error("Error deploying application for request [" + createResourceReport + "].", t);
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setException(t);
+ } finally {
+ if (archiveFile != null) {
+ destroyArchive(archiveFile);
+ }
+ }
+
+ }
+
+ protected Log getLog() {
+ return log;
+ }
+
+ protected ProfileServiceConnection getProfileServiceConnection() {
+ return profileServiceConnection;
+ }
+
+ protected abstract File prepareArchive(PackageDetailsKey key,
+ ResourceType resourceType);
+
+ protected abstract void destroyArchive(File archive);
+
+ // private void abortIfApplicationAlreadyDeployed(ResourceType resourceType,
+ // File archiveFile) throws Exception {
+ // String archiveFileName = archiveFile.getName();
+ // KnownDeploymentTypes deploymentType =
+ // ConversionUtils.getDeploymentType(resourceType);
+ // String deploymentTypeString = deploymentType.getType();
+ // ManagementView managementView =
+ // profileServiceConnection.getManagementView();
+ // managementView.load();
+ // Set<ManagedDeployment> managedDeployments =
+ // managementView.getDeploymentsForType(deploymentTypeString);
+ // for (ManagedDeployment managedDeployment : managedDeployments) {
+ // if (managedDeployment.getSimpleName().equals(archiveFileName))
+ // throw new IllegalArgumentException("An application named '" +
+ // archiveFileName
+ // + "' is already deployed.");
+ // }
+ // }
+}
Property changes on: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/AbstractDeployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/Deployer.java
===================================================================
--- branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/Deployer.java (rev 0)
+++ branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/Deployer.java 2011-01-12 23:13:09 UTC (rev 2839)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.deployer;
+
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+
+/**
+ * An abstraction of the deployment process.
+ *
+ */
+public interface Deployer {
+
+ /**
+ * Handles the deployment process end to end and updates the createResourceReport with
+ * appropriate results.
+ *
+ * @param createResourceReport the report to get the deployment from
+ * @param resourceType the target resource type
+ */
+ void deploy(CreateResourceReport createResourceReport, ResourceType resourceType);
+}
Property changes on: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/Deployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/RemoteDeployer.java
===================================================================
--- branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/RemoteDeployer.java (rev 0)
+++ branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/RemoteDeployer.java 2011-01-12 23:13:09 UTC (rev 2839)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.deployer;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.rhq.core.domain.content.PackageDetailsKey;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.content.ContentContext;
+import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
+import org.rhq.plugins.jbossas5.util.ManagedComponentUtils;
+
+/**
+ *
+ */
+public class RemoteDeployer extends AbstractDeployer {
+
+ private ResourceContext<?> resourceContext;
+
+ /**
+ * @param profileServiceConnection
+ */
+ public RemoteDeployer(ProfileServiceConnection profileServiceConnection, ResourceContext<?> resourceContext) {
+ super(profileServiceConnection);
+ this.resourceContext = resourceContext;
+ }
+
+ @Override
+ protected void destroyArchive(File archive) {
+ File tempDir = archive.getParentFile();
+ archive.delete();
+ tempDir.delete();
+ }
+
+ @Override
+ protected File prepareArchive(PackageDetailsKey key, ResourceType resourceType) {
+ //we're running in the agent. During the development of this functionality, there was
+ //a time when the deployment only worked from within the JBossAS server home.
+ //Further investigation never confirmed the problem again but since we have access to
+ //server home directory anyway, why not stay on the safe side... ;)
+ OutputStream os = null;
+
+ try {
+ File tempDir = createTempDirectory("teiid-deploy-content", null, getServerTempDirectory());
+
+ File archiveFile = new File(key.getName());
+
+ //this is to ensure that we only get the filename part no matter whether the key contains
+ //full path or not.
+ File contentCopy = new File(tempDir, archiveFile.getName());
+
+ os = new BufferedOutputStream(new FileOutputStream(contentCopy));
+ ContentContext contentContext = resourceContext.getContentContext();
+ ContentServices contentServices = contentContext.getContentServices();
+ contentServices.downloadPackageBitsForChildResource(contentContext, resourceType.getName(), key, os);
+
+ return contentCopy;
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to copy the deployed archive to destination.", e);
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ getLog().warn("Failed to close the stream when copying deployment to destination.");
+ }
+ }
+ }
+ }
+
+ private File getServerTempDirectory() {
+ ManagementView managementView = getProfileServiceConnection().getManagementView();
+ ManagedComponent serverConfigComponent = ManagedComponentUtils.getSingletonManagedComponent(managementView,
+ new ComponentType("MCBean", "ServerConfig"));
+ String serverTempDir = (String) ManagedComponentUtils.getSimplePropertyValue(serverConfigComponent,
+ "serverTempDir");
+
+ return new File(serverTempDir);
+ }
+
+ /**
+ * TODO this should go somewhere nice...
+ *
+ * Creates a temporary directory in a given directory.
+ * Reuses the logic of {@link File#createTempFile(String, String, File)} but the returned
+ * file is a directory instead of a regular file.
+ *
+ * @param prefix the unique name prefix
+ * @param suffix the unique name suffix
+ * @param parentDirectory the parent directory to create the temp dir in
+ *
+ * @return the temporary directory
+ *
+ * @throws IOException on error
+ */
+ private static File createTempDirectory(String prefix, String suffix, File parentDirectory) throws IOException {
+ // Let's reuse the algorithm the JDK uses to determine a unique name:
+ // 1) create a temp file to get a unique name using JDK createTempFile
+ // 2) then quickly delete the file and...
+ // 3) convert it to a directory
+
+ File tmpDir = File.createTempFile(prefix, suffix, parentDirectory); // create file with unique name
+ boolean deleteOk = tmpDir.delete(); // delete the tmp file and...
+ boolean mkdirsOk = tmpDir.mkdirs(); // ...convert it to a directory
+
+ if (!deleteOk || !mkdirsOk) {
+ throw new IOException("Failed to create temp directory named [" + tmpDir + "]");
+ }
+
+ return tmpDir;
+ }
+}
Property changes on: branches/7.1.x/console/src/main/java/org/teiid/rhq/plugin/deployer/RemoteDeployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the teiid-commits
mailing list