modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
| 16
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
| 13
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
| 228 ++++++++--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
| 34 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
| 72 ++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
| 10
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
| 31 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
| 218 +++++++++
8 files changed, 583 insertions(+), 39 deletions(-)
New commits:
commit 3a19b87d9f21a5ffa2df1ed6ea2d06421310adb1
Merge: 85ce0d5... cdccd36...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Mar 2 15:14:51 2010 -0500
Merge branch 'bundle' into bundle-jay
commit 85ce0d5d01e8b74849346640590edcff1afe8b6f
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Mar 2 15:10:22 2010 -0500
SLSB work for Bundles
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 6d67e56..29b25cf 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
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.server.bundle;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -32,11 +34,17 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
+import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
+import org.rhq.core.domain.content.Architecture;
+import org.rhq.core.domain.content.Package;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.criteria.BundleCriteria;
import org.rhq.core.domain.criteria.BundleDeployDefinitionCriteria;
@@ -48,6 +56,9 @@ import org.rhq.core.domain.util.PersistenceUtility;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
+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.plugin.pc.bundle.BundleServerPluginFacet;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
@@ -70,49 +81,208 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
private AuthorizationManagerLocal authorizationManager;
@EJB
+ private ContentManagerLocal contentManager;
+
+ @EJB
+ private RepoManagerLocal repoManager;
+
+ @EJB
private ResourceTypeManagerLocal resourceTypeManager;
- public Bundle createBundle(Subject subject, Bundle bundle) {
- if (null == bundle || null == bundle.getName())
- throw new IllegalArgumentException("Missing one or more of: bundle,
name");
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public Bundle createBundle(Subject subject, String name, int bundleTypeId) {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleName: " + name);
+ }
- // add the implicit bundle repo, if necessary
- if (null == bundle.getRepo()) {
- Repo repo = new Repo(bundle.getName());
- repo.setCandidate(false);
- repo.setSyncSchedule(null);
- bundle.setRepo(repo);
+ BundleType bundleType = entityManager.find(BundleType.class, bundleTypeId);
+ if (null == bundleType) {
+ throw new IllegalArgumentException("Invalid bundleTypeId: " +
bundleTypeId);
}
- log.info("Creating bundle: " + bundle);
+ Bundle bundle = new Bundle(name, bundleType);
+
+ // add the implicit bundle repo
+ Repo repo = new Repo(name);
+ repo.setCandidate(false);
+ repo.setSyncSchedule(null);
+ bundle.setRepo(repo);
+ log.info("Creating bundle: " + bundle);
entityManager.persist(bundle);
+
return bundle;
}
- public BundleType createBundleType(Subject subject, BundleType bundleType) throws
Exception {
- if (null == bundleType || null == bundleType.getName())
- throw new IllegalArgumentException("Missing one or more of: bundleType,
name");
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleType createBundleType(Subject subject, String name, int resourceTypeId)
throws Exception {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleTypeName: " +
name);
+ }
+ ResourceType resourceType = entityManager.find(ResourceType.class,
resourceTypeId);
+ if (null == resourceType) {
+ throw new IllegalArgumentException("Invalid resourceeTypeId: " +
resourceTypeId);
+ }
+
+ BundleType bundleType = new BundleType(name, resourceType);
entityManager.persist(bundleType);
return bundleType;
}
- public BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion
bundleVersion)
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleVersion createBundleVersion(Subject subject, int bundleId, String name,
String version, String recipe)
throws Exception {
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleVersionName: " +
name);
+ }
+
Bundle bundle = entityManager.find(Bundle.class, bundleId);
+ if (null == bundle) {
+ throw new IllegalArgumentException("Invalid bundleId: " +
bundleId);
+ }
+
+ // parse the recipe (validation occurs here) and get the config def and list of
files
+ BundleType bundleType = bundle.getBundleType();
+ BundleServerPluginFacet bp =
BundleManagerHelper.getPluginContainer().getBundleServerPluginManager()
+ .getBundleServerPluginFacet(bundleType.getName());
+ RecipeParseResults results = bp.parseRecipe(recipe);
- if (null == bundleVersion || null == bundle || null ==
bundleVersion.getRecipe())
- throw new IllegalArgumentException("Missing one or more of: bundle,
bundleVersion, recipe");
+ // ensure we have a version
+ version = getVersion(version, bundle);
- // parse the recipe and get the config def and list of files
- BundleServerPluginFacet bp;
- // bp.parseRecipe;
+ BundleVersion bundleVersion = new BundleVersion(name, version, bundle, recipe);
+ bundleVersion.setConfigurationDefinition(results.getConfigDef());
entityManager.persist(bundleVersion);
return bundleVersion;
}
+ private String getVersion(String version, Bundle bundle) {
+ if (!(null == version || "".equals(version.trim()))) {
+ return version;
+ }
+
+ BundleVersion currentBundleVersion = null;
+ for (BundleVersion bundleVersion : bundle.getBundleVersions()) {
+ if ((null == currentBundleVersion) || (bundleVersion.getId() >
currentBundleVersion.getId())) {
+ currentBundleVersion = bundleVersion;
+ }
+ }
+
+ // note - this is the same algo used by ResourceClientProxy in
updatebackingContent (for a resource)
+ String oldVersion = (null == currentBundleVersion) ? null :
currentBundleVersion.getVersion();
+ String newVersion = "1.0";
+ if (oldVersion != null && oldVersion.length() != 0) {
+ String[] parts = oldVersion.split("[^a-zA-Z0-9]");
+ String lastPart = parts[parts.length - 1];
+ try {
+ int lastNumber = Integer.parseInt(lastPart);
+ newVersion = oldVersion.substring(0, oldVersion.length() -
lastPart.length()) + (lastNumber + 1);
+ } catch (NumberFormatException nfe) {
+ newVersion = oldVersion + ".1";
+ }
+ }
+
+ return newVersion;
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFile(Subject subject, int bundleVersionId, String name,
String version,
+ Architecture architecture, InputStream fileStream, boolean pinToPackage) throws
Exception {
+
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileName: " +
name);
+ }
+ if (null == version || "".equals(version.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileVersion: " +
version);
+ }
+ if (null == fileStream) {
+ throw new IllegalArgumentException("Invalid fileStream: " + null);
+ }
+ BundleVersion bundleVersion = entityManager.find(BundleVersion.class,
bundleVersionId);
+ if (null == bundleVersion) {
+ throw new IllegalArgumentException("Invalid bundleVersionId: " +
bundleVersionId);
+ }
+
+ // Create the PackageVersion the BundleFile is tied to. This implicitly creates
the
+ // Package for the PackageVersion.
+ Bundle bundle = bundleVersion.getBundle();
+ PackageType packageType = getBundleTypePackageType(bundle.getBundleType());
+ architecture = (null == architecture) ? contentManager.getNoArchitecture() :
architecture;
+ PackageVersion packageVersion = contentManager.createPackageVersion(name,
packageType.getId(), version,
+ architecture.getId(), fileStream);
+
+ // Create the mapping between the Bundle's Repo and the BundleFile's
PackageVersion
+ Repo repo = bundle.getRepo();
+ repoManager.addPackageVersionsToRepo(subject, repo.getId(), new int[] {
packageVersion.getId() });
+
+ // Classify the Package with the Bundle name in order to distinguish it from the
same package name for
+ // a different bundle.
+ Package generalPackage = packageVersion.getGeneralPackage();
+ generalPackage.setClassification(bundle.getName());
+
+ // With all the plumbing in place, create and persist the BundleFile. Tie it to
the Package if the caller
+ // wants this BundleFile pinned to themost recent version.
+ BundleFile bundleFile = new BundleFile();
+ bundleFile.setBundleVersion(bundleVersion);
+ bundleFile.setPackageVersion(packageVersion);
+ if (pinToPackage) {
+ bundleFile.setPackage(generalPackage);
+ }
+
+ entityManager.persist(bundleFile);
+
+ return bundleFile;
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFileViaByteArray(Subject subject, int bundleVersionId,
String name, String version,
+ Architecture architecture, byte[] fileBytes, boolean pinToPackage) throws
Exception {
+
+ return addBundleFile(subject, bundleVersionId, name, version, architecture,
+ new ByteArrayInputStream(fileBytes), pinToPackage);
+ }
+
+ @RequiredPermission(Permission.MANAGE_INVENTORY)
+ public BundleFile addBundleFileViaPackageVersion(Subject subject, int
bundleVersionId, String name,
+ int packageVersionId, boolean pinToPackage) throws Exception {
+
+ if (null == name || "".equals(name.trim())) {
+ throw new IllegalArgumentException("Invalid bundleFileName: " +
name);
+ }
+ BundleVersion bundleVersion = entityManager.find(BundleVersion.class,
bundleVersionId);
+ if (null == bundleVersion) {
+ throw new IllegalArgumentException("Invalid bundleVersionId: " +
bundleVersionId);
+ }
+ PackageVersion packageVersion = entityManager.find(PackageVersion.class,
packageVersionId);
+ if (null == packageVersion) {
+ throw new IllegalArgumentException("Invalid packageVersionId: " +
packageVersionId);
+ }
+
+ // With all the plumbing in place, create and persist the BundleFile. Tie it to
the Package if the caller
+ // wants this BundleFile pinned to themost recent version.
+ BundleFile bundleFile = new BundleFile();
+ bundleFile.setBundleVersion(bundleVersion);
+ bundleFile.setPackageVersion(packageVersion);
+ if (pinToPackage) {
+ bundleFile.setPackage(packageVersion.getGeneralPackage());
+ }
+
+ entityManager.persist(bundleFile);
+
+ return bundleFile;
+ }
+
+ private PackageType getBundleTypePackageType(BundleType bundleType) {
+
+ Query packageTypeQuery =
entityManager.createNamedQuery(PackageType.QUERY_FIND_BY_RESOURCE_TYPE_ID_AND_NAME);
+ packageTypeQuery.setParameter("typeId",
bundleType.getResourceType().getId());
+ packageTypeQuery.setParameter("name", bundleType.getName());
+
+ return (PackageType) packageTypeQuery.getSingleResult();
+ }
+
@SuppressWarnings("unchecked")
public List<BundleType> getAllBundleTypes(Subject subject) {
// the list of types will be small, no need to support paging
@@ -198,8 +368,7 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
try {
ResourceType linuxPlatformResourceType =
this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
"Platforms");
- BundleType bundleType = new BundleType(UUID.randomUUID().toString(),
linuxPlatformResourceType);
- return createBundleType(subject, bundleType);
+ return createBundleType(subject, UUID.randomUUID().toString(),
linuxPlatformResourceType.getId());
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -215,9 +384,8 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
int randomIndex = random.nextInt(bundleTypes.size());
bundleType = bundleTypes.get(randomIndex);
}
- Bundle bundle = new Bundle(UUID.randomUUID().toString(), bundleType);
- bundle = createBundle(subject, bundle);
+ Bundle bundle = createBundle(subject, UUID.randomUUID().toString(),
bundleType.getId());
// Add 1 to 5 bundle versions.
int bundleVersionCount = random.nextInt(5) + 1;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
new file mode 100644
index 0000000..7ba49db
--- /dev/null
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerHelper.java
@@ -0,0 +1,34 @@
+package org.rhq.enterprise.server.bundle;
+
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginContainer;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+public class BundleManagerHelper {
+
+ public static BundleServerPluginContainer getPluginContainer() {
+ BundleServerPluginContainer pc;
+
+ try {
+ ServerPluginServiceManagement mbean = LookupUtil.getServerPluginService();
+ if (!mbean.isMasterPluginContainerStarted()) {
+ throw new IllegalStateException("The master plugin container is not
started!");
+ }
+
+ MasterServerPluginContainer master = mbean.getMasterPluginContainer();
+ pc = master.getPluginContainerByClass(BundleServerPluginContainer.class);
+ } catch (IllegalStateException ise) {
+ throw ise;
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot obtain the Bundle plugin
container!", e);
+ }
+
+ if (pc == null) {
+ throw new IllegalStateException("Bundle plugin container is
null!");
+ }
+
+ return pc;
+ }
+
+}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
index 42f573d..ec3b73b 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.server.bundle;
+import java.io.InputStream;
import java.util.List;
import javax.ejb.Local;
@@ -26,8 +27,10 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
+import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
+import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.criteria.BundleCriteria;
import org.rhq.core.domain.criteria.BundleDeployDefinitionCriteria;
import org.rhq.core.domain.criteria.BundleDeploymentCriteria;
@@ -43,26 +46,73 @@ import org.rhq.core.domain.util.PageList;
public interface BundleManagerLocal {
/**
+ * Adds a BundleFile to the BundleVersion and implicitly creates the backing
PackageVersion. If the PackageVersion
+ * already exists use {@link addBundleFile(Subject, int, String, int, boolean)}
+ *
* @param subject must be InventoryManager
- * @param bundle required fields: name
+ * @param bundleVersionId id of the BundleVersion incorporating this BundleFile
+ * @param name name of the BundleFile (and the resulting Package)
+ * @param version version of the backing package
+ * @param architecture architecture appropriate for the backing package. Defaults to
noarch (i.e. any architecture).
+ * @param fileStream the file bits
+ * @param pinToPackage if true a new version of the backing package can trigger
automatic creation of a new
+ * BundleVersion. if false new versions of the backing package have no effect
on the BundleFile or its BundleVersion.
+ * @return the new BundleFile
+ * @throws Exception
+ */
+ BundleFile addBundleFile(Subject subject, int bundleVersionId, String bundleFileName,
String version,
+ Architecture architecture, InputStream fileStream, boolean pinToPackage) throws
Exception;
+
+ /**
+ * A convenience method taking a byte array as opposed to a stream for the file
bits.
+ *
+ * @see {@link addBundleFile(Subject, int, String, String, Architecture, InputStream,
boolean)}
+ */
+ BundleFile addBundleFileViaByteArray(Subject subject, int bundleVersionId, String
name, String version,
+ Architecture architecture, byte[] fileBytes, boolean pinToPackage) throws
Exception;
+
+ /**
+ * @param subject must be InventoryManager
+ * @param bundleVersionId id of the BundleVersion incorporating this BundleFile
+ * @param name name of the BundleFile (and the resulting Package)
+ * @param packageVersionId id of the PackageVersion this BundleFile is tied to for
this BundleVersion. It is assumed
+ * the PackageVersion is already associated with the Bundle's Repo and the
package is classified for the
+ * Bundle.
+ * @param pinToPackage if true a new version of the backing package can trigger
automatic creation of a new
+ * BundleVersion. if false new versions of the backing package have no effect
on the BundleFile or its BundleVersion.
+ * @return the new BundleFile
+ * @throws Exception
+ */
+ BundleFile addBundleFileViaPackageVersion(Subject subject, int bundleVersionId,
String name, int packageVersionId,
+ boolean pinToPackage) throws Exception;
+
+ /**
+ * @param subject must be InventoryManager
+ * @param name not null or empty
+ * @param bundleTypeId valid bundleType
* @return the persisted Bundle (id is assigned)
*/
- Bundle createBundle(Subject subject, Bundle bundle) throws Exception;
+ Bundle createBundle(Subject subject, String name, int bundleTypeId) throws
Exception;
/**
+ * Not generally called. For use by Server Side Plugins when registering a Bundle
Plugin.
+ *
* @param subject must be InventoryManager
- * @param bundleType required fields: name
+ * @param name not null or empty
+ * @param resourceTypeId id of the ResourceType that handles this BundleType
* @return the persisted BundleType (id is assigned)
*/
- BundleType createBundleType(Subject subject, BundleType bundleType) throws
Exception;
+ BundleType createBundleType(Subject subject, String name, int resourceTypeId) throws
Exception;
/**
* @param subject must be InventoryManager
- * @param int bundleId the bundle for which this will be the next version
- * @param bundleVersion required fields: recipe (the full recipe as a String)
+ * @param bundleId the bundle for which this will be the next version
+ * @param name not null or empty
+ * @param bundleVersion optional. If not supplied set to 1.0 for first version, or
incremented (as best as possible) for subsequent version
* @return the persisted BundleVersion (id is assigned)
*/
- BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion
bundleVersion) throws Exception;
+ BundleVersion createBundleVersion(Subject subject, int bundleId, String name, String
bundleVersion, String recipe)
+ throws Exception;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
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 e381dd4..e8ac546 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
@@ -41,6 +41,7 @@ import org.rhq.core.domain.criteria.BundleVersionCriteria;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -57,8 +58,20 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleManagerLocal bundleManagerBean;
+ private TestBundleServerPluginService ps;
+ private MasterServerPluginContainer pc;
+
@BeforeMethod
public void beforeMethod() {
+ super.startTest();
+
+ if (null == ps) {
+ ps = new TestBundleServerPluginService();
+ pc = ps.createMasterPluginContainer();
+ } else {
+ pc.initialize(ps.masterConfig);
+ }
+
bundleManagerBean = LookupUtil.getBundleManager();
}
@@ -119,6 +132,12 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
em.close();
}
}
+
+ if (null != pc) {
+ pc.shutdown();
+ }
+
+ super.endTest();
}
@Test(enabled = ENABLED)
@@ -232,8 +251,7 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleType createBundleType(String name) throws Exception {
final String fullName = TEST_PREFIX + "-type-" + name;
- BundleType bt = new BundleType(fullName, createResourceType(name));
- bt = bundleManagerBean.createBundleType(getOverlord(), bt);
+ BundleType bt = bundleManagerBean.createBundleType(getOverlord(), fullName,
createResourceType(name).getId());
assert bt.getId() > 0;
assert bt.getName().endsWith(fullName);
@@ -247,8 +265,7 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private Bundle createBundle(String name, BundleType bt) throws Exception {
final String fullName = TEST_PREFIX + "-bundle-" + name;
- Bundle b = new Bundle(fullName, bt);
- b = bundleManagerBean.createBundle(getOverlord(), b);
+ Bundle b = bundleManagerBean.createBundle(getOverlord(), fullName, bt.getId());
assert b.getId() > 0;
assert b.getName().endsWith(fullName);
@@ -257,9 +274,9 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
private BundleVersion createBundleVersion(String name, String version, Bundle bundle)
throws Exception {
final String fullName = TEST_PREFIX + "-version-" + version +
"-" + name;
- final String recipe = TEST_PREFIX + "-recipe-" + name;
- BundleVersion bv = new BundleVersion(fullName, version, bundle, recipe);
- bv = bundleManagerBean.createBundleVersion(getOverlord(), bv);
+ final String recipe = "deploy -f " + TEST_PREFIX + ".zip -d <%
test.path %>";
+ BundleVersion bv = bundleManagerBean.createBundleVersion(getOverlord(),
bundle.getId(), fullName, version,
+ recipe);
assert bv.getId() > 0;
assert bv.getName().endsWith(fullName);
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
new file mode 100644
index 0000000..dcbc951
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/TestBundleServerPluginService.java
@@ -0,0 +1,218 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.server.bundle;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
+import org.rhq.enterprise.server.plugin.pc.generic.GenericServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginServiceMBean;
+import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+
+/**
+ * Used as a mock service for the generic server plugin container.
+ */
+public class TestBundleServerPluginService extends ServerPluginService implements
TestGenericServerPluginServiceMBean {
+ public enum State {
+ INITIALIZED, STARTED, STOPPED, UNINITIALIZED
+ }
+
+ // public so tests can directly set these
+ public TestMasterServerPluginContainer master;
+ public TestBundleServerPluginContainer bundlePC;
+ public MasterServerPluginContainerConfiguration masterConfig;
+
+ public TestBundleServerPluginService() {
+ // build the config at constructor time so tests have it even before the PC is
initialized
+ File dir = new File(System.getProperty("java.io.tmpdir"),
"test-server-plugins");
+ this.masterConfig = new MasterServerPluginContainerConfiguration(dir, dir, dir,
null);
+ }
+
+ @Override
+ public MasterServerPluginContainer createMasterPluginContainer() {
+ this.master = new TestMasterServerPluginContainer();
+ this.master.initialize(this.masterConfig);
+ return this.master;
+ }
+
+ /**
+ * The test master PC
+ */
+ class TestMasterServerPluginContainer extends MasterServerPluginContainer {
+ @Override
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers()
{
+ ArrayList<AbstractTypeServerPluginContainer> pcs = new
ArrayList<AbstractTypeServerPluginContainer>(1);
+ bundlePC = new TestBundleServerPluginContainer(this);
+ pcs.add(bundlePC);
+ return pcs;
+ }
+
+ @Override
+ protected ClassLoader createRootServerPluginClassLoader() {
+ return this.getClass().getClassLoader();
+ }
+
+ @Override
+ protected Map<URL, ? extends ServerPluginDescriptorType>
preloadAllPlugins() throws Exception {
+ // if our test never setup any plugins, ignore it and just return an empty
map
+ File pluginDir = getConfiguration().getPluginDirectory();
+ if (pluginDir == null || pluginDir.listFiles() == null ||
pluginDir.listFiles().length == 0) {
+ return new HashMap<URL, ServerPluginDescriptorType>();
+ } else {
+ return super.preloadAllPlugins();
+ }
+ }
+
+ @Override
+ protected List<PluginKey> getDisabledPluginKeys() {
+ // in the real world, the db is checked for enable flag, here we say all
plugins are enabled
+ return new ArrayList<PluginKey>();
+ }
+ }
+
+ public class TestBundleServerPluginContainer extends GenericServerPluginContainer {
+ public State state = State.UNINITIALIZED;
+
+ public TestBundleServerPluginContainer(MasterServerPluginContainer master) {
+ super(master);
+ }
+
+ @Override
+ protected ServerPluginManager createPluginManager() {
+ TestBundlePluginManager pm = new TestBundlePluginManager(this);
+ return pm;
+ }
+
+ @Override
+ public synchronized void initialize() throws Exception {
+ if (state == State.UNINITIALIZED) {
+ state = State.INITIALIZED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG
!!!");
+ throw new IllegalStateException("not uninitialized: " +
state);
+ }
+ super.initialize();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (state == State.INITIALIZED) {
+ state = State.STARTED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG
!!!");
+ throw new IllegalStateException("not initialized: " + state);
+ }
+ super.start();
+ }
+
+ @Override
+ public synchronized void stop() {
+ if (state == State.STARTED) {
+ state = State.STOPPED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG
!!!");
+ throw new IllegalStateException("not started: " + state);
+ }
+ super.stop();
+ }
+
+ @Override
+ public synchronized void shutdown() {
+ if (state == State.STOPPED) {
+ state = State.UNINITIALIZED;
+ } else {
+ System.out.println("!!! PC LIFECYCLE WAS BAD - THIS IS A BUG
!!!");
+ throw new IllegalStateException("not stopped: " + state);
+ }
+ super.shutdown();
+ }
+ }
+
+ /**
+ * The test plugin manager.
+ */
+ class TestBundlePluginManager extends ServerPluginManager {
+ public final Map<String, ServerPluginComponent> components;
+
+ public TestBundlePluginManager(TestBundleServerPluginContainer pc) {
+ super(pc);
+ components = new HashMap<String, ServerPluginComponent>();
+ }
+
+ @Override
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
+
+ try {
+ Configuration pluginConfig = null;
+ Configuration scheduledJobsConfig = null;
+ ConfigurationDefinition configDef;
+
+ ServerPluginDescriptorType pluginDescriptor = env.getPluginDescriptor();
+
+ configDef =
ServerPluginDescriptorMetadataParser.getPluginConfigurationDefinition(pluginDescriptor);
+ if (configDef != null) {
+ pluginConfig = configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ configDef =
ServerPluginDescriptorMetadataParser.getScheduledJobsDefinition(pluginDescriptor);
+ if (configDef != null) {
+ scheduledJobsConfig =
configDef.getDefaultTemplate().createConfiguration();
+ }
+
+ File pluginFile = new File(env.getPluginUrl().toURI());
+ ServerPlugin plugin = new ServerPlugin(0,
env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED,
pluginDescriptor
+ .getDescription(), "",
MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(),
System.currentTimeMillis(), System
+ .currentTimeMillis());
+ return plugin;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected ServerPluginComponent
createServerPluginComponent(ServerPluginEnvironment environment)
+ throws Exception {
+ ServerPluginComponent component =
super.createServerPluginComponent(environment);
+ components.put(environment.getPluginKey().getPluginName(), component);
+ return component;
+ }
+ }
+}
\ No newline at end of file
commit f2f559b7cdb5055bf572804b82db5f1322913582
Merge: 84ebcfc... 7f70926...
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:50:20 2010 -0500
Merge branch 'bundle' into bundle-jay
commit 84ebcfc94992d0d7f0d6cb1a0a441ece7131d69e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:50:13 2010 -0500
local intermittent check-in for merge purposes
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 ce559bf..6d67e56 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
@@ -35,7 +35,6 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
-import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.content.Repo;
@@ -49,6 +48,7 @@ import org.rhq.core.domain.util.PersistenceUtility;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
+import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginFacet;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
@@ -72,15 +72,10 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
@EJB
private ResourceTypeManagerLocal resourceTypeManager;
- @SuppressWarnings("unchecked")
- public List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId)
throws Exception {
- Query q =
entityManager.createNamedQuery(BundleFile.QUERY_FIND_BY_BUNDLE_VERSION_ID);
- q.setParameter("id", bundleVersionId);
- List<BundleFile> bundleFiles = (List<BundleFile>) q.getResultList();
- return bundleFiles;
- }
-
public Bundle createBundle(Subject subject, Bundle bundle) {
+ if (null == bundle || null == bundle.getName())
+ throw new IllegalArgumentException("Missing one or more of: bundle,
name");
+
// add the implicit bundle repo, if necessary
if (null == bundle.getRepo()) {
Repo repo = new Repo(bundle.getName());
@@ -95,12 +90,25 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
return bundle;
}
- public BundleType createBundleType(Subject subject, BundleType bundleType) {
+ public BundleType createBundleType(Subject subject, BundleType bundleType) throws
Exception {
+ if (null == bundleType || null == bundleType.getName())
+ throw new IllegalArgumentException("Missing one or more of: bundleType,
name");
+
entityManager.persist(bundleType);
return bundleType;
}
- public BundleVersion createBundleVersion(Subject subject, BundleVersion
bundleVersion) {
+ public BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion
bundleVersion)
+ throws Exception {
+ Bundle bundle = entityManager.find(Bundle.class, bundleId);
+
+ if (null == bundleVersion || null == bundle || null ==
bundleVersion.getRecipe())
+ throw new IllegalArgumentException("Missing one or more of: bundle,
bundleVersion, recipe");
+
+ // parse the recipe and get the config def and list of files
+ BundleServerPluginFacet bp;
+ // bp.parseRecipe;
+
entityManager.persist(bundleVersion);
return bundleVersion;
}
@@ -186,10 +194,16 @@ public class BundleManagerBean implements BundleManagerLocal,
BundleManagerRemot
}
public BundleType createMockBundleType(Subject subject) {
- ResourceType linuxPlatformResourceType =
this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
- "Platforms");
- BundleType bundleType = new BundleType(UUID.randomUUID().toString(),
linuxPlatformResourceType);
- return createBundleType(subject, bundleType);
+
+ try {
+ ResourceType linuxPlatformResourceType =
this.resourceTypeManager.getResourceTypeByNameAndPlugin("Linux",
+ "Platforms");
+ BundleType bundleType = new BundleType(UUID.randomUUID().toString(),
linuxPlatformResourceType);
+ return createBundleType(subject, bundleType);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
}
public Bundle createMockBundle(Subject subject, List<BundleType> bundleTypes)
{
commit 74b491f9cc626a1fa2f603fb0a0dbb22343b0605
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Mar 1 14:42:07 2010 -0500
Add bundleFiles field to BundleVersion and update the criteria object.
Eliminate the getBundleFilesForBundleVersion convenience routine in favor
of a standard criteria fetch.
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 125baa7..b70c53d 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
@@ -94,6 +94,9 @@ public class BundleVersion implements Serializable {
@OneToMany(mappedBy = "bundleVersion", fetch = FetchType.LAZY, cascade =
CascadeType.ALL)
private List<BundleDeployDefinition> bundleDeployDefinitions = new
ArrayList<BundleDeployDefinition>();
+ @OneToMany(mappedBy = "bundleVersion", fetch = FetchType.LAZY, cascade =
CascadeType.ALL)
+ private List<BundleFile> bundleFiles = new ArrayList<BundleFile>();
+
public BundleVersion() {
// for JPA use
}
@@ -182,6 +185,19 @@ public class BundleVersion implements Serializable {
this.bundleDeployDefinitions = bundleDeployDefinitions;
}
+ public List<BundleFile> getBundleFiles() {
+ return bundleFiles;
+ }
+
+ public void addBundleFile(BundleFile bundleFile) {
+ this.bundleFiles.add(bundleFile);
+ bundleFile.setBundleVersion(this);
+ }
+
+ public void setBundleFiles(List<BundleFile> bundleFiles) {
+ this.bundleFiles = bundleFiles;
+ }
+
@Override
public String toString() {
return "BundleVersion[id=" + id + ",name=" + name +
",version=" + version + ",bundle=" + bundle + "]";
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
index 72c07ed..5264a76 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleVersionCriteria.java
@@ -41,6 +41,7 @@ public class BundleVersionCriteria extends Criteria {
private boolean fetchBundle;
private boolean fetchBundleDeployDefinitions;
+ private boolean fetchBundleFiles;
private boolean fetchDistribution;
private boolean fetchConfigurationDefinition;
@@ -70,12 +71,16 @@ public class BundleVersionCriteria extends Criteria {
this.fetchBundle = fetchBundle;
}
- public void fetchDistribution(boolean fetchDistribution) {
- this.fetchDistribution = fetchDistribution;
- }
-
public void fetchBundleDeployDefinitions(boolean fetchBundleDeployDefinitions) {
this.fetchBundleDeployDefinitions = fetchBundleDeployDefinitions;
}
+ public void fetchBundleFiles(boolean fetchBundleFiles) {
+ this.fetchBundleFiles = fetchBundleFiles;
+ }
+
+ public void fetchDistribution(boolean fetchDistribution) {
+ this.fetchDistribution = fetchDistribution;
+ }
+
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
index 9266530..42f573d 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java
@@ -26,7 +26,6 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.Bundle;
import org.rhq.core.domain.bundle.BundleDeployDefinition;
import org.rhq.core.domain.bundle.BundleDeployment;
-import org.rhq.core.domain.bundle.BundleFile;
import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.criteria.BundleCriteria;
@@ -42,13 +41,28 @@ import org.rhq.core.domain.util.PageList;
*/
@Local
public interface BundleManagerLocal {
- Bundle createBundle(Subject subject, Bundle b);
- BundleType createBundleType(Subject subject, BundleType bundleType);
+ /**
+ * @param subject must be InventoryManager
+ * @param bundle required fields: name
+ * @return the persisted Bundle (id is assigned)
+ */
+ Bundle createBundle(Subject subject, Bundle bundle) throws Exception;
- BundleVersion createBundleVersion(Subject subject, BundleVersion bundleVersion);
+ /**
+ * @param subject must be InventoryManager
+ * @param bundleType required fields: name
+ * @return the persisted BundleType (id is assigned)
+ */
+ BundleType createBundleType(Subject subject, BundleType bundleType) throws
Exception;
- List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId) throws
Exception;
+ /**
+ * @param subject must be InventoryManager
+ * @param int bundleId the bundle for which this will be the next version
+ * @param bundleVersion required fields: recipe (the full recipe as a String)
+ * @return the persisted BundleVersion (id is assigned)
+ */
+ BundleVersion createBundleVersion(Subject subject, int bundleId, BundleVersion
bundleVersion) throws Exception;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
index 09f4669..71d038c 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java
@@ -27,8 +27,11 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.clientapi.server.bundle.BundleServerService;
import org.rhq.core.clientapi.server.bundle.BundleStatusUpdate;
+import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.bundle.BundleFile;
+import org.rhq.core.domain.bundle.BundleVersion;
import org.rhq.core.domain.content.PackageVersion;
+import org.rhq.core.domain.criteria.BundleVersionCriteria;
import org.rhq.core.util.exception.WrappedRemotingException;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -49,7 +52,12 @@ public class BundleServerServiceImpl implements BundleServerService {
public List<PackageVersion> getAllBundleVersionPackageVersions(int
bundleVersionId) {
try {
BundleManagerLocal bm = LookupUtil.getBundleManager();
- List<BundleFile> bundleFiles =
bm.findBundleFilesForBundleVersion(bundleVersionId);
+ BundleVersionCriteria c = new BundleVersionCriteria();
+ Subject subject = LookupUtil.getSubjectManager().getOverlord();
+ c.addFilterId(bundleVersionId);
+ c.fetchBundleFiles(true);
+ List<BundleVersion> bundleVersions =
bm.findBundleVersionsByCriteria(subject, c);
+ List<BundleFile> bundleFiles = bundleVersions.get(0).getBundleFiles();
List<PackageVersion> packageVersions = new
ArrayList<PackageVersion>(bundleFiles.size());
for (BundleFile bundleFile : bundleFiles) {
packageVersions.add(bundleFile.getPackageVersion());