int bundleId = bundleVersion.getBundle().getId(); int doomedBundleVersionOrder = bundleVersion.getVersionOrder();
@Override public List<PackageVersion> getAllBundleVersionPackageVersions(BundleVersion bundleVersion) throws Exception { int bvId = bundleVersion.getId(); List<PackageVersion> pvs = getBundleServerService().getAllBundleVersionPackageVersions(bvId); return pvs; }
public BundleVersion(String name, String version, Bundle bundle, String recipe) { setName(name); setVersion(version); setBundle(bundle); setRecipe(recipe); }
BundleVersion bundleVersion = new BundleVersion(name, version, bundle, recipe); bundleVersion.setVersionOrder(versionOrder); bundleVersion.setDescription(description); bundleVersion.setConfigurationDefinition(configurationDefinition);
@Override public BundleFile addBundleFileViaPackageVersion(Subject subject, int bundleVersionId, String name, int packageVersionId) 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); } // Check authorization checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); // With all the plumbing in place, create and persist the BundleFile. Tie it to the Package if the caller // wants this BundleFile pinned to the most recent version. BundleFile bundleFile = new BundleFile(); bundleFile.setBundleVersion(bundleVersion); bundleFile.setPackageVersion(packageVersion); entityManager.persist(bundleFile); return bundleFile; }
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); BundleType bundleType = bundleVersion.getBundle().getBundleType(); RecipeParseResults parseResults = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager() .parseRecipe(bundleType.getName(), bundleVersion.getRecipe()); List<BundleFile> bundleFiles = bundleVersion.getBundleFiles(); for (String filename : filenames) { boolean found = false;
checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment .getDestination().getGroup().getId()); .deepCopy(false); BundleDeployment revertDeployment = bundleManager.createBundleDeploymentInNewTrans(subject, prevDeployment .getBundleVersion().getId(), bundleDestinationId, name, desc, config);
BundleFile bundleFile = bundleManager.addBundleFile(subject, bundleVersion.getId(), fileName, bundleVersion.getVersion(), null, is); if (LOG.isDebugEnabled()) { LOG.debug("Added bundle file [" + bundleFile + "] to BundleVersion [" + bundleVersion + "]"); + "], will not create the new bundle", e); try { bundleManager.deleteBundleVersion(subjectManager.getOverlord(), bundleVersion.getId(), createdBundle); } catch (Exception e1) { LOG.error("Failed to delete the partially created bundle version: " + bundleVersion, e1); bvCriteria.addFilterId(bundleVersion.getId()); bvCriteria.fetchBundle(true); bvCriteria.fetchBundleFiles(true); if (bundleVersions != null && bundleVersions.size() == 1) { bundleVersion = bundleVersions.get(0); List<BundleFile> bundleFiles = bundleVersion.getBundleFiles(); if (bundleFiles != null && bundleFiles.size() > 0) { final BundleFileCriteria bfCriteria = new BundleFileCriteria(); bfCriteria.addFilterBundleVersionId(bundleVersion.getId()); bfCriteria.fetchPackageVersion(true); bundleVersion.setBundleDeployments(new ArrayList<BundleDeployment>()); } else { LOG.error("Failed to obtain the full bundle version, returning only what we currently know about it: "
int numDeployments = bundleVersion.getBundleDeployments().size(); if (0 == numDeployments) { continue; Bundle bundle = bundleVersion.getBundle(); BundleDestinationCriteria destinationCriteria = new BundleDestinationCriteria(); List<BundleDeployment> filteredDeployments = new ArrayList<BundleDeployment>(numDeployments); for (BundleDeployment deployment : bundleVersion.getBundleDeployments()) { if (containsDestination(destinations, deployment.getDestination())) filteredDeployments.add(deployment); bundleVersion.setBundleDeployments(filteredDeployments);
public void addBundleVersion(BundleVersion bundleVersion) { this.bundleVersions.add(bundleVersion); bundleVersion.setBundle(this); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof BundleFile)) { return false; } BundleFile other = (BundleFile) obj; if (bundleVersion == null) { if (other.bundleVersion != null) { return false; } } else if (!bundleVersion.equals(other.bundleVersion)) { return false; } if (packageVersion == null) { if (other.packageVersion != null) { return false; } } else if (!packageVersion.equals(other.packageVersion)) { return false; } return true; } }
public void addBundleVersion(BundleVersion bundleVersion) { if (bundleVersions == null) { bundleVersions = new HashSet<BundleVersion>(); } bundleVersion.addTag(this); bundleVersions.add(bundleVersion); }
private BundleDeployment createBundleDeploymentImpl(Subject subject, BundleVersion bundleVersion, BundleDestination bundleDestination, String name, String description, Configuration configuration) throws Exception { ConfigurationDefinition configDef = bundleVersion.getConfigurationDefinition(); if (null != configDef) { if (null == configuration) { throw new IllegalArgumentException( "Missing Configuration. Configuration is required when the specified BundleVersion defines Configuration Properties."); } // passing in the default configuration will make sure that the readonly properties with the non-null // default values defined in the config def cannot be overridden by the caller. // Those properties are meant to be set by the bundle plugins, not by the user. Configuration defaultConfig = ConfigurationUtility.createDefaultConfiguration(configDef); List<String> errors = ConfigurationUtility.validateConfiguration(configuration, defaultConfig, configDef); if (!errors.isEmpty()) { throw new IllegalArgumentException("Invalid Configuration: " + errors.toString()); } } BundleDeployment deployment = new BundleDeployment(bundleVersion, bundleDestination, name); deployment.setDescription(description); deployment.setConfiguration(configuration); deployment.setSubjectName(subject.getName()); PropertySimple discoveryDelayProperty = configuration.getSimple("org.rhq.discoveryDelay"); if(discoveryDelayProperty != null) { deployment.setDiscoveryDelay(discoveryDelayProperty.getIntegerValue()); } entityManager.persist(deployment); return deployment; }
@Override public String getBundleDeploymentName(Subject subject, int bundleDestinationId, int bundleVersionId, int prevDeploymentId) { BundleDestination bundleDestination = entityManager.find(BundleDestination.class, bundleDestinationId); if (null == bundleDestination) { throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleDestinationId); } BundleVersion bundleVersion = null; BundleDeployment prevDeployment = null; if (bundleVersionId > 0) { bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId); if (null == bundleVersion) { throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId); } } else if (prevDeploymentId > 0) { prevDeployment = entityManager.find(BundleDeployment.class, prevDeploymentId); if (null == prevDeployment) { throw new IllegalArgumentException("Invalid prevDeploymentId: " + prevDeploymentId); } } else { throw new IllegalArgumentException("Must specify either a valid bundleVersionId [" + bundleVersionId + "] or prevDeploymentId [" + prevDeploymentId + "]"); } if (bundleVersion != null) { checkDeployBundleAuthz(subject, bundleVersion.getBundle().getId(), bundleDestination.getGroup().getId()); } return getBundleDeploymentNameImpl(subject, bundleDestination, bundleVersion, prevDeployment); }
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); BundleType bundleType = bundleVersion.getBundle().getBundleType(); RecipeParseResults parseResults = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager() .parseRecipe(bundleType.getName(), bundleVersion.getRecipe()); List<BundleFile> bundleFiles = bundleVersion.getBundleFiles(); Set<String> allFilenames = result; result = new HashSet<String>(allFilenames.size() - bundleFiles.size());
checkDeployBundleAuthz(subject, liveDeployment.getBundleVersion().getBundle().getId(), liveDeployment .getDestination().getGroup().getId()); bvc.addFilterId(liveDeployment.getBundleVersion().getId()); bvc.fetchBundle(true); // will eagerly fetch the bundle type PageList<BundleVersion> bvs = bundleManager.findBundleVersionsByCriteria(subject, bvc); rtc.addFilterBundleTypeId(liveDeployment.getBundleVersion().getBundle().getBundleType().getId()); PageList<ResourceType> rts = resourceTypeManager.findResourceTypesByCriteria(subject, rtc); liveDeployment.getBundleVersion().getBundle().getBundleType().setResourceType(rts.get(0));
bundle.getBundleType().setResourceType(resourceType); deployment.getBundleVersion().setBundle(bundle); deployment.getDestination().setBundle(bundle);
return false; } else if (!bundleVersion.equals(other.bundleVersion)) { return false;
@Override public BundleDeployment createBundleDeployment(Subject subject, int bundleVersionId, int bundleDestinationId, String description, Configuration configuration) throws Exception { BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId); if (null == bundleVersion) { throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId); } BundleDestination bundleDestination = entityManager.find(BundleDestination.class, bundleDestinationId); if (null == bundleDestination) { throw new IllegalArgumentException("Invalid bundleDestinationId: " + bundleDestinationId); } checkDeployBundleAuthz(subject, bundleVersion.getBundle().getId(), bundleDestination.getGroup().getId()); String name = getBundleDeploymentNameImpl(subject, bundleDestination, bundleVersion, null); return this.createBundleDeploymentImpl(subject, bundleVersion, bundleDestination, name, description, configuration); }
@Override @SuppressWarnings("unchecked") public void deleteBundle(Subject subject, int bundleId) throws Exception { Bundle bundle = this.entityManager.find(Bundle.class, bundleId); if (null == bundle) { return; } checkDeleteBundleAuthz(subject, bundleId); Query q = entityManager.createNamedQuery(BundleVersion.QUERY_FIND_BY_BUNDLE_ID); q.setParameter("bundleId", bundleId); List<BundleVersion> bvs = q.getResultList(); for (BundleVersion bv : bvs) { bundleManager.deleteBundleVersion(subject, bv.getId(), false); entityManager.flush(); } // remove bundle from any assigned bundle groups // wrap in new HashSet to avoid ConcurrentModificationExceptions. Set<BundleGroup> BundleGroupsToRemove = new HashSet<BundleGroup>(bundle.getBundleGroups()); for (BundleGroup bg : BundleGroupsToRemove) { bg.removeBundle(bundle); } // we need to whack the Repo once the Bundle no longer refers to it Repo bundleRepo = bundle.getRepo(); this.entityManager.remove(bundle); this.entityManager.flush(); // delete the repo as overlord, this allows users without MANAGE_INVENTORY permission to delete bundles repoManager.deleteRepo(subjectManager.getOverlord(), bundleRepo.getId()); }