modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleDistributionFileUploadServlet.java | 76 +++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleGWTServiceImpl.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/UberBundleFileUploadServlet.java | 77 ------
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleDistributionInfo.java | 80 ++++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java | 128 +++++++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerRemote.java | 43 ++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/UberBundleFileInfo.java | 84 ------
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginFacet.java | 14 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginManager.java | 55 +++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java | 20 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java | 30 +-
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java | 2
modules/enterprise/server/plugins/ant-bundle/src/main/java/org/rhq/enterprise/server/plugins/ant/AntBundleServerPluginComponent.java | 118 ++++++++-
modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java | 4
15 files changed, 512 insertions(+), 223 deletions(-)
New commits:
commit 77f452bdb05782fe0be91384cb75888a0684523e
Merge: e9946ba... 2a9da73...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Apr 29 12:33:50 2010 -0400
Merge branch 'gwt' into gwt-jay
commit e9946babe0658a14bf856e2ead582cd7880c8425
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Apr 29 12:33:10 2010 -0400
first pass at supporting distribution file based bundle version creation.
not yet tested...
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
index 9b3f606..a5f918b 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
@@ -261,7 +261,7 @@ public class BundleVersion implements Serializable {
@Override
public String toString() {
- return "BundleVersion[id=" + id + ",name=" + name + ",version=" + version + ",bundle=" + bundle + "]";
+ return "BundleVersion[id=" + id + ",name=" + name + ",version=" + version + ",bundle=" + bundle.getName() + "]";
}
@Override
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleDistributionFileUploadServlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleDistributionFileUploadServlet.java
new file mode 100644
index 0000000..e14ce9c
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleDistributionFileUploadServlet.java
@@ -0,0 +1,76 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.server.gwt;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.bundle.BundleVersion;
+import org.rhq.enterprise.server.bundle.BundleManagerLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Accepts a "bundle distribution file" - which is simply a zip file that contains within it
+ * a bundle recipe and additional bundle files.
+ *
+ * @author John Mazzitelli
+ */
+public class BundleDistributionFileUploadServlet extends FileUploadServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void processUploadedFiles(Subject subject, Map<String, File> files, Map<String, String> formFields,
+ HttpServletRequest request, HttpServletResponse response) throws IOException {
+
+ String successMsg;
+
+ try {
+ // note that this assumes 1 and only 1 file is uploaded
+ File file = files.values().iterator().next();
+
+ BundleManagerLocal bundleManager = LookupUtil.getBundleManager();
+ BundleVersion bundleVersion = bundleManager.createBundleVersionViaURL(subject, file.toURI().toURL());
+ successMsg = "success [" + bundleVersion.getId() + "]";
+ } catch (Exception e) {
+ writeExceptionResponse(response, "Failed to upload bundle distribution file", e); // clients will look for this string!
+ return;
+ }
+
+ PrintWriter writer = response.getWriter();
+ writer.println("<html>");
+ writer.println(successMsg);
+ writer.println("</html>");
+ writer.flush();
+ return;
+ }
+
+ private String getFormField(Map<String, String> formFields, String key, String defaultValue) {
+ String value = formFields.get(key);
+ if (value == null) {
+ value = defaultValue;
+ }
+ return value;
+ }
+}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleGWTServiceImpl.java
index 2b14ef5..c76dd44 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleGWTServiceImpl.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/BundleGWTServiceImpl.java
@@ -127,7 +127,7 @@ public class BundleGWTServiceImpl extends AbstractGWTServiceImpl implements Bund
BundleCriteria criteria) throws Exception {
try {
PageList<BundleWithLatestVersionComposite> results;
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(getSessionSubject(), criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(getSessionSubject(), criteria);
return SerialUtility.prepare(results, "findBundlesWithLastestVersionCompositesByCriteria");
} catch (Exception e) {
throw new RuntimeException(ThrowableUtil.getAllMessages(e));
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/UberBundleFileUploadServlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/UberBundleFileUploadServlet.java
deleted file mode 100644
index 9033dc8..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/UberBundleFileUploadServlet.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.server.gwt;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.bundle.BundleVersion;
-import org.rhq.enterprise.server.bundle.BundleManagerLocal;
-import org.rhq.enterprise.server.util.LookupUtil;
-
-/**
- * Accepts a "uber bundle file" - which is simply a zip file that contains within it
- * a bundle recipe and additional bundle files.
- *
- * @author John Mazzitelli
- */
-public class UberBundleFileUploadServlet extends FileUploadServlet {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void processUploadedFiles(Subject subject, Map<String, File> files, Map<String, String> formFields,
- HttpServletRequest request, HttpServletResponse response) throws IOException {
-
- String successMsg;
-
- try {
- // note that this assumes 1 and only 1 file is uploaded
- File file = files.values().iterator().next();
-
- BundleManagerLocal bundleManager = LookupUtil.getBundleManager();
- BundleVersion bundleVersion = bundleManager.createBundleVersionViaUberBundleFileURL(subject, file.toURI()
- .toURL());
- successMsg = "success [" + bundleVersion.getId() + "]";
- } catch (Exception e) {
- writeExceptionResponse(response, "Failed to upload uber bundle file", e); // clients will look for this string!
- return;
- }
-
- PrintWriter writer = response.getWriter();
- writer.println("<html>");
- writer.println(successMsg);
- writer.println("</html>");
- writer.flush();
- return;
- }
-
- private String getFormField(Map<String, String> formFields, String key, String defaultValue) {
- String value = formFields.get(key);
- if (value == null) {
- value = defaultValue;
- }
- return value;
- }
-}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleDistributionInfo.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleDistributionInfo.java
new file mode 100644
index 0000000..6f7eccd
--- /dev/null
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleDistributionInfo.java
@@ -0,0 +1,80 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.server.bundle;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * Information found when a Bundle Distribution file is cracked open and inspected.
+ *
+ * @author John Mazzitelli
+ */
+public class BundleDistributionInfo {
+ private final String recipe;
+ private final RecipeParseResults recipeParseResults;
+ private final Map<String, File> bundleFiles;
+ private String bundleTypeName;
+
+ public BundleDistributionInfo(String recipe, RecipeParseResults recipeParseResults, Map<String, File> bundleFiles) {
+
+ this.recipe = recipe;
+ this.recipeParseResults = recipeParseResults;
+ this.bundleFiles = bundleFiles;
+ this.bundleTypeName = null; // typically set later
+ }
+
+ /**
+ * The information gleened from the recipe that was found in the bundle distribution file.
+ *
+ * @return the recipe information
+ */
+ public RecipeParseResults getRecipeParseResults() {
+ return recipeParseResults;
+ }
+
+ /**
+ * If the bundle distribution file contained within it one or more bundle files that need
+ * to be associated with the bundle version, this map will contain those files.
+ * The key to the map is the name of the bundle file as referenced to it via
+ * the recipe (i.e. the keys will be filenames that are mentioned in the
+ * {@link #getRecipeParseResults() parse results}). The values are files referencing
+ * the bundle files' content - it is the job of the server side plugin to extract
+ * the bundle files from the bundle distribution file and store them on the local file
+ * system.
+ *
+ * @return names and file locations of all bundle files found in the bundle distribution file
+ */
+ public Map<String, File> getBundleFiles() {
+ return bundleFiles;
+ }
+
+ public String getBundleTypeName() {
+ return bundleTypeName;
+ }
+
+ public String getRecipe() {
+ return recipe;
+ }
+
+ public void setBundleTypeName(String bundleTypeName) {
+ this.bundleTypeName = bundleTypeName;
+ }
+}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
index dbb2094..b2eaaf0 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
@@ -19,11 +19,16 @@
package org.rhq.enterprise.server.bundle;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.ejb.EJB;
@@ -73,6 +78,7 @@ import org.rhq.core.domain.resource.group.ResourceGroup;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.domain.util.StringUtils;
import org.rhq.core.util.NumberUtil;
+import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.agentclient.AgentClient;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
@@ -81,6 +87,7 @@ import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.content.ContentManagerLocal;
import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.core.AgentManagerLocal;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginManager;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
import org.rhq.enterprise.server.util.HibernateDetachUtility;
@@ -316,9 +323,90 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return bundleVersion;
}
- public BundleVersion createBundleVersionViaUberBundleFileURL(Subject subject, URL uberBundleFile) throws Exception {
- // TODO: bundle implement me
- return null;
+ public BundleVersion createBundleVersionViaFile(Subject subject, File distributionFile) throws Exception {
+
+ BundleServerPluginManager manager = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager();
+ BundleDistributionInfo info = manager.processBundleDistributionFile(distributionFile);
+ BundleVersion bundleVersion = createBundleVersionViaDistributionInfo(subject, info);
+
+ return bundleVersion;
+ }
+
+ public BundleVersion createBundleVersionViaURL(Subject subject, URL distributionFileUrl) throws Exception {
+
+ // get the distro file into a tmp dir
+ // create temp file
+ File tempDistributionFile = null;
+ InputStream is = null;
+ OutputStream os = null;
+ BundleVersion bundleVersion = null;
+
+ try {
+ tempDistributionFile = File.createTempFile("bundle-" + distributionFileUrl.hashCode(), "zip");
+
+ is = distributionFileUrl.openStream();
+ os = new FileOutputStream(tempDistributionFile);
+ long len = StreamUtil.copy(is, os);
+ log.debug("Copied [" + len + "] bytes from [" + distributionFileUrl + "] into ["
+ + tempDistributionFile.getPath() + "]");
+
+ bundleVersion = bundleManager.createBundleVersionViaFile(subject, tempDistributionFile);
+ } finally {
+ if (null != tempDistributionFile) {
+ tempDistributionFile.delete();
+ }
+ }
+
+ return bundleVersion;
+ }
+
+ private BundleVersion createBundleVersionViaDistributionInfo(Subject subject, BundleDistributionInfo info)
+ throws Exception {
+
+ BundleType bundleType = bundleManager.getBundleType(subject, info.getBundleTypeName());
+ String bundleName = info.getRecipeParseResults().getBundleMetadata().getBundleName();
+ String bundleDescription = info.getRecipeParseResults().getBundleMetadata().getDescription();
+ String name = "TODO: bundleVersionName";
+ String description = "TODO: bundleVersionDesc";
+ String version = info.getRecipeParseResults().getBundleMetadata().getBundleVersion();
+ String recipe = info.getRecipe();
+
+ // first see if the bundle exists or not; if not, create one
+ BundleCriteria criteria = new BundleCriteria();
+ criteria.setStrict(true);
+ criteria.addFilterBundleTypeId(bundleType.getId());
+ criteria.addFilterName(bundleName);
+ PageList<Bundle> bundles = findBundlesByCriteria(subject, criteria);
+ Bundle bundle;
+ if (bundles.getTotalSize() == 0) {
+ bundle = createBundle(subject, bundleName, bundleDescription, bundleType.getId());
+ } else {
+ bundle = bundles.get(0);
+ }
+
+ // now create the bundle version with the bundle we either found or created
+ BundleVersion bundleVersion = createBundleVersion(subject, bundle.getId(), name, description, version, recipe);
+
+ // now that we have the bundle version we can actually create the bundle files that were provided in
+ // the bundle distribution
+ Map<String, File> bundleFiles = info.getBundleFiles();
+ for (String fileName : bundleFiles.keySet()) {
+ File file = bundleFiles.get(fileName);
+ InputStream is = null;
+ try {
+ is = new FileInputStream(file);
+ BundleFile bundleFile = bundleManager.addBundleFile(subject, bundleVersion.getId(), fileName, "1.0",
+ null, is);
+ log.debug("Added bundle file [" + bundleFile + "] to BundleVersion [" + bundleVersion + "]");
+ } finally {
+ safeClose(is);
+ if (null != file) {
+ file.delete();
+ }
+ }
+ }
+
+ return bundleVersion;
}
@SuppressWarnings("unchecked")
@@ -690,6 +778,15 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return types;
}
+ @SuppressWarnings("unchecked")
+ public BundleType getBundleType(Subject subject, String bundleTypeName) {
+ // the list of types will be small, no need to support paging
+ Query q = entityManager.createNamedQuery(BundleType.QUERY_FIND_BY_NAME);
+ q.setParameter("name", bundleTypeName);
+ BundleType type = (BundleType) q.getSingleResult();
+ return type;
+ }
+
public PageList<BundleDeployment> findBundleDeploymentsByCriteria(Subject subject, BundleDeploymentCriteria criteria) {
CriteriaQueryGenerator generator = new CriteriaQueryGenerator(criteria);
@@ -742,8 +839,8 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return queryRunner.execute();
}
- public PageList<BundleWithLatestVersionComposite> findBundlesWithLastestVersionCompositesByCriteria(
- Subject subject, BundleCriteria criteria) {
+ public PageList<BundleWithLatestVersionComposite> findBundlesWithLatestVersionCompositesByCriteria(Subject subject,
+ BundleCriteria criteria) {
CriteriaQueryGenerator generator = new CriteriaQueryGenerator(criteria);
String replacementSelectList = ""
@@ -812,4 +909,25 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return;
}
+
+ private void safeClose(InputStream is) {
+ if (null != is) {
+ try {
+ is.close();
+ } catch (Exception e) {
+ log.warn("Failed to close InputStream", e);
+ }
+ }
+ }
+
+ private void safeClose(OutputStream os) {
+ if (null != os) {
+ try {
+ os.close();
+ } catch (Exception e) {
+ log.warn("Failed to close InputStream", e);
+ }
+ }
+ }
+
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerRemote.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerRemote.java
index 534cff1..6ea2bff 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerRemote.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerRemote.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.server.bundle;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
@@ -167,17 +168,38 @@ public interface BundleManagerRemote {
@WebParam(name = "recipe") String recipe) throws Exception;
/**
- * Creates a bundle version based on a "uber bundle" zip file. The "uber bundle" zip file should contain
- * the recipe for a supported bundle type, along with 0, 1 or more bundle files that will be associated
- * with the bundle version.
+ * Creates a bundle version based on a Bundle Distribution file. Typically a zip file, the bundle distribution
+ * contains the recipe for a supported bundle type, along with 0, 1 or more bundle files that will be associated
+ * with the bundle version. The recipe specifies the bundle name, version, version name and version description.
+ * If this is the initial version for the named bundle the bundle will be implicitly created. The bundle type
+ * is discovered by inspecting the distribution file.
*
* @param subject
- * @param uberBundleZipFile a zip file containing a bundle recipe and bundle files
+ * @param distributionFile a local Bundle Distribution file. It must be read accessible by the RHQ server process.
* @return the persisted BundleVersion (id is assigned)
*/
- BundleVersion createBundleVersionViaUberBundleFileURL( //
- @WebParam(name = "subject") Subject subject, //
- @WebParam(name = "url") URL uberBundleZipFile) throws Exception;
+ BundleVersion createBundleVersionViaFile( //
+ @WebParam(name = "subject") Subject subject, //
+ @WebParam(name = "distributionFile") File distributionFile) throws Exception;
+
+ /**
+ * Creates a bundle version based on a Bundle Distribution file. Typically a zip file, the bundle distribution
+ * contains the recipe for a supported bundle type, along with 0, 1 or more bundle files that will be associated
+ * with the bundle version. The recipe specifies the bundle name, version, version name and version description.
+ * If this is the initial version for the named bundle the bundle will be implicitly created. The bundle type
+ * is discovered by inspecting the distribution file.
+ * <br/></br>
+ * Note, if the file is local it is more efficient to use {@link createBundleVersionViaFile(Subject,File)}.
+ *
+ * @param subject
+ * @param distributionFileUrl a URL to the Bundle Distribution file. It must be live, resolvable and read accessible
+ * by the RHQ server process.
+ *
+ * @return the persisted BundleVersion (id is assigned)
+ */
+ BundleVersion createBundleVersionViaURL( //
+ @WebParam(name = "subject") Subject subject, //
+ @WebParam(name = "distributionFileUrl") URL distributionFileUrl) throws Exception;
/**
* Convienence method that combines {@link #createBundle(Subject, String, int)} and {@link #createBundleVersion(Subject, int, String, String, String)}.
@@ -260,7 +282,7 @@ public interface BundleManagerRemote {
@WebParam(name = "criteria") BundleVersionCriteria criteria);
@WebMethod
- PageList<BundleWithLatestVersionComposite> findBundlesWithLastestVersionCompositesByCriteria( //
+ PageList<BundleWithLatestVersionComposite> findBundlesWithLatestVersionCompositesByCriteria( //
@WebParam(name = "subject") Subject subject, //
@WebParam(name = "criteria") BundleCriteria criteria);
@@ -268,6 +290,11 @@ public interface BundleManagerRemote {
List<BundleType> getAllBundleTypes( //
@WebParam(name = "subject") Subject subject);
+ @WebMethod
+ BundleType getBundleType( //
+ @WebParam(name = "subject") Subject subject, //
+ @WebParam(name = "bundleTypeName") String bundleTypeName);
+
/**
* Determine the files required for a BundleVersion and return all of the filenames or optionally, just those
* that lack BundleFiles for the BundleVersion. The recipe may be parsed as part of this call.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/UberBundleFileInfo.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/UberBundleFileInfo.java
deleted file mode 100644
index 66881a9..0000000
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/UberBundleFileInfo.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.enterprise.server.bundle;
-
-import java.io.File;
-import java.util.Map;
-
-import org.rhq.core.domain.bundle.BundleVersion;
-
-/**
- * Information found when a uber bundle file was cracked open and inspected.
- *
- * @author John Mazzitelli
- */
-public class UberBundleFileInfo {
- private final BundleVersion bundleVersion;
- private final RecipeParseResults recipeParseResults;
- private final Map<String, File> bundleFiles;
-
- public UberBundleFileInfo(BundleVersion bundleVersion, RecipeParseResults recipeParseResults,
- Map<String, File> bundleFiles) {
-
- this.bundleVersion = bundleVersion;
- this.recipeParseResults = recipeParseResults;
- this.bundleFiles = bundleFiles;
- }
-
- /**
- * The metadata about the bundle version represented by the uber bundle file.
- * The uber bundle file must have metadata encoded in it that provides details
- * such as the name of the bundle, the version of the bundle, etc. Usually this
- * information is found within the recipe itself but that is not a requirement - the
- * uber bundle file merely has to have the information somewhere that the bundle type
- * server side plugin can find.
- *
- * @return the bundle version information
- */
- public BundleVersion getBundleVersion() {
- return bundleVersion;
- }
-
- /**
- * The information gleened from the recipe that was found in the uber bundle file.
- *
- * @return the recipe information
- */
- public RecipeParseResults getRecipeParseResults() {
- return recipeParseResults;
- }
-
- /**
- * If the uber bundle file contained within it one or more bundle files that need
- * to be associated with the bundle version, this map will contain those files.
- * The key to the map is the name of the bundle file as referenced to it via
- * the recipe (i.e. the keys will be filenames that are mentioned in the
- * {@link #getRecipeParseResults() parse results}). The values are files referencing
- * the bundle files' content - it is the job of the server side plugin to extract
- * the bundle files from the uber bundle file and store them on the local file
- * system.
- *
- * @return names and file locations of all bundle files found in the uber bundle file
- */
- public Map<String, File> getBundleFiles() {
- return bundleFiles;
- }
-
-}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginFacet.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginFacet.java
index f798945..db616d8 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginFacet.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginFacet.java
@@ -21,8 +21,8 @@ package org.rhq.enterprise.server.plugin.pc.bundle;
import java.io.File;
+import org.rhq.enterprise.server.bundle.BundleDistributionInfo;
import org.rhq.enterprise.server.bundle.RecipeParseResults;
-import org.rhq.enterprise.server.bundle.UberBundleFileInfo;
/**
* All bundle server plugins must implement this facet.
@@ -41,14 +41,14 @@ public interface BundleServerPluginFacet {
RecipeParseResults parseRecipe(String recipe) throws Exception;
/**
- * The server side plugin is being given an uber bundle file that must be procssed.
+ * The server side plugin is being given an bundle distribution file that must be procssed.
* The results of the processing are to be returned.
*
- * An uber bundle file is a zip file that contains a recipe and 0, 1 or more bundle files.
+ * An bundle distribution file is a zip file that contains a recipe and 0, 1 or more bundle files.
*
- * @param uberBundleFile
- * @return the information gleened by cracking open the uber bundle file and examining its contents
- * @throws Exception if the uber bundle file could not be processed successfully
+ * @param distributionFile
+ * @return the information gleened by cracking open the bundle distribution file and examining its contents
+ * @throws Exception if the bundle distribution file could not be processed successfully
*/
- UberBundleFileInfo processUberBundleFile(File uberBundleFile) throws Exception;
+ BundleDistributionInfo processBundleDistributionFile(File distributionFile) throws Exception;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginManager.java
index 1358348..9ca73ae 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/bundle/BundleServerPluginManager.java
@@ -20,8 +20,8 @@ package org.rhq.enterprise.server.plugin.pc.bundle;
import java.io.File;
+import org.rhq.enterprise.server.bundle.BundleDistributionInfo;
import org.rhq.enterprise.server.bundle.RecipeParseResults;
-import org.rhq.enterprise.server.bundle.UberBundleFileInfo;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
@@ -121,17 +121,52 @@ public class BundleServerPluginManager extends ServerPluginManager {
}
/**
- * Given an uber bundle file, this will find the appropriate server side plugin that can process it
- * and will ask that plugin to crack open the uber bundle file and return information about it.
+ * Given an bundle distribution file, this will find the appropriate server side plugin that can process it
+ * and will ask that plugin to crack open the bundle distribution file and return information about it.
*
- * An uber bundle file is a zip file that contains a recipe and 0, 1 or more bundle files.
+ * An bundle distribution file is a zip file that contains a recipe and 0, 1 or more bundle files.
*
- * @param uberBundleFile
- * @return the information gleened by cracking open the uber bundle file and examining its contents
- * @throws Exception if the uber bundle file could not be processed successfully
+ * @param distributionFile
+ * @return the information gleened by cracking open the bundle distribution file and examining its contents
+ * @throws Exception if the bundle distribution file could not be processed successfully
*/
- public UberBundleFileInfo processUberBundleFile(File uberBundleFile) throws Exception {
- // TODO: bundle implement me
- return null;
+ public BundleDistributionInfo processBundleDistributionFile(File distributionFile) throws Exception {
+
+ if (null == distributionFile) {
+ throw new IllegalArgumentException("bundleDistributionFile == null");
+ }
+
+ // find the bundle plugin that can handle this distribution and get the distro info
+ BundleDistributionInfo info = null;
+
+ for (ServerPluginEnvironment env : getPluginEnvironments()) {
+ BundlePluginDescriptorType descriptor = (BundlePluginDescriptorType) env.getPluginDescriptor();
+
+ // get the facet and see if this plugin can deal with the distro
+ String pluginName = env.getPluginKey().getPluginName();
+ ServerPluginComponent component = getServerPluginComponent(pluginName);
+ BundleServerPluginFacet facet = (BundleServerPluginFacet) component; // we know this cast will work because our loadPlugin ensured so
+ getLog().debug(
+ "Bundle server plugin [" + pluginName + "] is parsing a distribution file [" + distributionFile + "]");
+ ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(env.getPluginClassLoader());
+ try {
+ info = facet.processBundleDistributionFile(distributionFile);
+ info.setBundleTypeName(descriptor.getBundle().getType());
+ break;
+ } catch (IllegalArgumentException e) {
+ info = null;
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalContextClassLoader);
+ }
+ }
+ if (null == info) {
+ throw new IllegalArgumentException(
+ "Invalid bundle distribution file. BundleType/Recipe not recognized by any deployed server bundle plugin.");
+ }
+
+ return info;
}
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java
index 05978b8..b33d69a 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java
@@ -22,6 +22,7 @@
*/
package org.rhq.enterprise.server.webservices;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
@@ -353,9 +354,12 @@ public class WebservicesManagerBean implements WebservicesRemote {
return bundleManager.createBundleVersion(subject, bundleId, name, description, version, recipe);
}
- public BundleVersion createBundleVersionViaUberBundleFileURL(Subject subject, URL uberBundleZipFile)
- throws Exception {
- return bundleManager.createBundleVersionViaUberBundleFileURL(subject, uberBundleZipFile);
+ public BundleVersion createBundleVersionViaFile(Subject subject, File distributionFile) throws Exception {
+ return bundleManager.createBundleVersionViaFile(subject, distributionFile);
+ }
+
+ public BundleVersion createBundleVersionViaURL(Subject subject, URL distributionFileUrl) throws Exception {
+ return bundleManager.createBundleVersionViaURL(subject, distributionFileUrl);
}
public BundleVersion createBundleAndBundleVersion(Subject subject, String bundleName, String bundleDescription,
@@ -394,15 +398,19 @@ public class WebservicesManagerBean implements WebservicesRemote {
return bundleManager.findBundleVersionsByCriteria(subject, criteria);
}
- public PageList<BundleWithLatestVersionComposite> findBundlesWithLastestVersionCompositesByCriteria(
- Subject subject, BundleCriteria criteria) {
- return bundleManager.findBundlesWithLastestVersionCompositesByCriteria(subject, criteria);
+ public PageList<BundleWithLatestVersionComposite> findBundlesWithLatestVersionCompositesByCriteria(Subject subject,
+ BundleCriteria criteria) {
+ return bundleManager.findBundlesWithLatestVersionCompositesByCriteria(subject, criteria);
}
public List<BundleType> getAllBundleTypes(Subject subject) {
return bundleManager.getAllBundleTypes(subject);
}
+ public BundleType getBundleType(Subject subject, String bundleTypeName) {
+ return bundleManager.getBundleType(subject, bundleTypeName);
+ }
+
public Set<String> getBundleVersionFilenames(Subject subject, int bundleVersionId, boolean withoutBundleFileOnly)
throws Exception {
return bundleManager.getBundleVersionFilenames(subject, bundleVersionId, withoutBundleFileOnly);
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
index 7fc43f2..78559df 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
@@ -221,6 +221,13 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
em.remove(em.getReference(Repo.class, ((Repo) removeMe).getId()));
}
+ // remove Resource Groups left over from test deployments freeing up test resources
+ q = em.createQuery("SELECT rg FROM ResourceGroup rg WHERE rg.name LIKE '" + TEST_PREFIX + "%'");
+ doomed = q.getResultList();
+ for (Object removeMe : doomed) {
+ em.remove(em.getReference(ResourceGroup.class, ((ResourceGroup) removeMe).getId()));
+ }
+
// remove ResourceTypes which cascade remove BundleTypes
q = em.createQuery("SELECT rt FROM ResourceType rt WHERE rt.name LIKE '" + TEST_PREFIX + "%'");
doomed = q.getResultList();
@@ -242,13 +249,6 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
em.remove(em.getReference(Agent.class, ((Agent) removeMe).getId()));
}
- // remove Resource Groups left over from test deployments
- q = em.createQuery("SELECT rg FROM ResourceGroup rg WHERE rg.name LIKE '" + TEST_PREFIX + "%'");
- doomed = q.getResultList();
- for (Object removeMe : doomed) {
- em.remove(em.getReference(ResourceGroup.class, ((ResourceGroup) removeMe).getId()));
- }
-
getTransactionManager().commit();
em.close();
em = null;
@@ -382,7 +382,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
PageList<BundleWithLatestVersionComposite> results;
// verify there are no bundle versions yet
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
assert results.get(0).getBundleDescription().equals(b1.getDescription());
@@ -393,7 +393,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
assertNotNull(bv1);
assertEquals("1.0", bv1.getVersion());
assert 0 == bv1.getVersionOrder();
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
assert results.get(0).getBundleDescription().equals(b1.getDescription());
@@ -404,7 +404,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
assertNotNull(bv2);
assertEquals("2.0", bv2.getVersion());
assert 1 == bv2.getVersionOrder();
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
assert results.get(0).getBundleDescription().equals(b1.getDescription());
@@ -415,7 +415,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
assertNotNull(bv3);
assertEquals("1.5", bv3.getVersion());
assert 1 == bv3.getVersionOrder();
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
assert results.get(0).getBundleDescription().equals(b1.getDescription());
@@ -475,7 +475,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
// verify our composite criteria query can return more than one item
Bundle b2 = createBundle("two");
assertNotNull(b2);
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.size() == 2 : results;
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
@@ -492,7 +492,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
assertNotNull(b2_bv1);
assertEquals("9.1", b2_bv1.getVersion());
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.size() == 2 : results;
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
@@ -507,7 +507,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
// test sorting of the BundleWithLastestVersionComposite
criteria.addSortName(PageOrdering.DESC);
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.size() == 2 : results;
assert results.get(1).getBundleId().equals(b1.getId());
assert results.get(1).getBundleName().equals(b1.getName());
@@ -521,7 +521,7 @@ public class BundleManagerBeanTest extends UpdateSubsytemTestBase {
assert results.get(0).getVersionsCount().longValue() == 1L;
criteria.addSortName(PageOrdering.ASC);
- results = bundleManager.findBundlesWithLastestVersionCompositesByCriteria(overlord, criteria);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
assert results.size() == 2 : results;
assert results.get(0).getBundleId().equals(b1.getId());
assert results.get(0).getBundleName().equals(b1.getName());
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
index 196a7f1..871c812 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
@@ -217,7 +217,7 @@ public class TestBundleServerPluginService extends ServerPluginService implement
return new RecipeParseResults(metadata, configDef, bundleFileNames);
}
- public UberBundleFileInfo processUberBundleFile(File uberBundleFile) throws Exception {
+ public BundleDistributionInfo processBundleDistributionFile(File uberBundleFile) throws Exception {
// TODO: bundle implement me
throw new UnsupportedOperationException("this mock object cannot do this");
}
diff --git a/modules/enterprise/server/plugins/ant-bundle/src/main/java/org/rhq/enterprise/server/plugins/ant/AntBundleServerPluginComponent.java b/modules/enterprise/server/plugins/ant-bundle/src/main/java/org/rhq/enterprise/server/plugins/ant/AntBundleServerPluginComponent.java
index 28b8137..b68a20f 100644
--- a/modules/enterprise/server/plugins/ant-bundle/src/main/java/org/rhq/enterprise/server/plugins/ant/AntBundleServerPluginComponent.java
+++ b/modules/enterprise/server/plugins/ant-bundle/src/main/java/org/rhq/enterprise/server/plugins/ant/AntBundleServerPluginComponent.java
@@ -22,7 +22,12 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -30,10 +35,12 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.bundle.ant.AntLauncher;
import org.rhq.bundle.ant.BundleAntProject;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.util.ZipUtil;
+import org.rhq.core.util.file.FileUtil;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.core.util.updater.DeploymentProperties;
+import org.rhq.enterprise.server.bundle.BundleDistributionInfo;
import org.rhq.enterprise.server.bundle.RecipeParseResults;
-import org.rhq.enterprise.server.bundle.UberBundleFileInfo;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginFacet;
@@ -94,8 +101,8 @@ public class AntBundleServerPluginComponent implements ServerPluginComponent, Bu
BundleAntProject project = antLauncher.parseBundleDeployFile(recipeFile);
// obtain the parse results
- deploymentProps = new DeploymentProperties(0, project.getBundleName(),
- project.getBundleVersion(), project.getBundleDescription()) ;
+ deploymentProps = new DeploymentProperties(0, project.getBundleName(), project.getBundleVersion(), project
+ .getBundleDescription());
bundleFiles = project.getBundleFileNames();
configDef = project.getConfigurationDefinition();
} catch (Throwable t) {
@@ -115,9 +122,108 @@ public class AntBundleServerPluginComponent implements ServerPluginComponent, Bu
return results;
}
- public UberBundleFileInfo processUberBundleFile(File uberBundleFile) throws Exception {
- // TODO: bundle implement me
- return null;
+ public BundleDistributionInfo processBundleDistributionFile(File distributionFile) throws Exception {
+ if (null == distributionFile) {
+ throw new IllegalArgumentException("distributionFile == null");
+ }
+
+ BundleDistributionInfo info = null;
+ String recipe = null;
+ RecipeParseResults recipeParseResults = null;
+
+ // try and parse the recipe, if successful then process the distributionFile completely
+ RecipeVisitor recipeVisitor = new RecipeVisitor(this, "deploy.xml");
+ ZipUtil.walkZipFile(distributionFile, recipeVisitor);
+ recipe = recipeVisitor.getRecipe();
+ recipeParseResults = recipeVisitor.getResults();
+
+ if (null == recipeParseResults) {
+ throw new IllegalArgumentException("Not an Ant Bundle");
+ }
+
+ // if we parsed the recipe then this is a distribution we can deal with, get the bundle file Map
+ BundleFileVisitor bundleFileVisitor = new BundleFileVisitor(recipeParseResults.getBundleMetadata()
+ .getBundleName(), recipeParseResults.getBundleFileNames());
+ ZipUtil.walkZipFile(distributionFile, bundleFileVisitor);
+
+ info = new BundleDistributionInfo(recipe, recipeParseResults, bundleFileVisitor.getBundleFiles());
+
+ return info;
+ }
+
+ private static class RecipeVisitor implements ZipUtil.ZipEntryVisitor {
+ private RecipeParseResults results = null;
+ private String recipeName = null;
+ private BundleServerPluginFacet facet = null;
+ private String recipe = null;
+
+ public RecipeVisitor(BundleServerPluginFacet facet, String recipeName) {
+ this.facet = facet;
+ this.recipeName = recipeName;
+ }
+
+ public boolean visit(ZipEntry entry, ZipInputStream stream) throws Exception {
+ if (recipeName.equalsIgnoreCase(entry.getName())) {
+ // this should be safe downcast, recipes are not that big
+ byte[] recipeBytes = new byte[(int) entry.getSize()];
+ recipeBytes = StreamUtil.slurp(stream);
+ this.recipe = new String(recipeBytes);
+ try {
+ this.results = facet.parseRecipe(this.recipe);
+ } catch (Throwable t) {
+ results = null;
+ }
+ }
+ return true;
+ }
+
+ public RecipeParseResults getResults() {
+ return results;
+ }
+
+ public String getRecipe() {
+ return recipe;
+ }
+ }
+
+ private static class BundleFileVisitor implements ZipUtil.ZipEntryVisitor {
+ private Set<String> bundleFileNames;
+ private Map<String, File> bundleFiles;
+ private File tmpDir;
+
+ public BundleFileVisitor(String bundleName, Set<String> bundleFileNames) throws IOException {
+ this.bundleFileNames = bundleFileNames;
+ this.bundleFiles = new HashMap<String, File>(bundleFileNames.size());
+ tmpDir = FileUtil.createTempDirectory("bundle-" + bundleName, String.valueOf(System.currentTimeMillis()),
+ null);
+ }
+
+ public boolean visit(ZipEntry entry, ZipInputStream stream) throws Exception {
+ if (bundleFileNames.contains(entry.getName())) {
+
+ File bundleFile = new File(tmpDir, entry.getName());
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(bundleFile);
+ StreamUtil.copy(stream, fos, false);
+ } finally {
+ if (null != fos) {
+ try {
+ fos.close();
+ } catch (Exception e) {
+ //
+ }
+ }
+ }
+ this.bundleFiles.put(entry.getName(), bundleFile);
+ }
+
+ return true;
+ }
+
+ public Map<String, File> getBundleFiles() {
+ return bundleFiles;
+ }
}
@Override
diff --git a/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java b/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
index 4d36238..556bab3 100644
--- a/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
+++ b/modules/enterprise/server/plugins/filetemplate-bundle/src/main/java/org/rhq/enterprise/server/plugins/filetemplate/BundleServerPluginComponent.java
@@ -36,7 +36,7 @@ import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.util.updater.DeploymentProperties;
import org.rhq.enterprise.server.bundle.RecipeParseResults;
-import org.rhq.enterprise.server.bundle.UberBundleFileInfo;
+import org.rhq.enterprise.server.bundle.BundleDistributionInfo;
import org.rhq.enterprise.server.plugin.pc.ControlFacet;
import org.rhq.enterprise.server.plugin.pc.ControlResults;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
@@ -102,7 +102,7 @@ public class BundleServerPluginComponent implements ServerPluginComponent, Bundl
}
- public UberBundleFileInfo processUberBundleFile(File uberBundleFile) throws Exception {
+ public BundleDistributionInfo processBundleDistributionFile(File uberBundleFile) throws Exception {
// TODO: bundle implement me
return null;
}
commit 10995f9ae72be6a2d286fe6db4b928ff1e471109
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Apr 29 10:24:44 2010 -0400
add eclipse lib for new ssh dep
diff --git a/.classpath b/.classpath
index 62622d5..fc26ab4 100644
--- a/.classpath
+++ b/.classpath
@@ -250,5 +250,6 @@
<classpathentry exported="true" kind="var" path="M2_REPO/com/google/gwt/gwt-dev/2.0.0/gwt-dev-2.0.0.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/com/smartgwt/smartgwt/2.1/smartgwt-2.1.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/ca/nanometrics/gflot/1.0.0/gflot-1.0.0.jar"/>
+ <classpathentry exported="true" kind="var" path="M2_REPO/com/jcraft/jsch/0.1.29/jsch-0.1.29.jar"/>
<classpathentry kind="output" path="eclipse-classes"/>
</classpath>