/** * This does not set the inverse relationship. You may want {@link BundleGroup#removeBundle(Bundle)}. * @param bundleGroup * @return true if bundle group is removed, otherwise false */ public boolean removeBundleGroup(BundleGroup bundleGroup) { return getBundleGroups().remove(bundleGroup); }
@SuppressWarnings("unchecked") private String getVersion(String version, Bundle bundle) { if (null != version && version.trim().length() > 0) { return version; } BundleVersion latestBundleVersion = null; Query q = entityManager.createNamedQuery(BundleVersion.QUERY_FIND_LATEST_BY_BUNDLE_ID); q.setParameter("bundleId", bundle.getId()); List<BundleVersion> list = q.getResultList(); if (list.size() > 0) { if (list.size() == 1) { latestBundleVersion = list.get(0); } else { throw new RuntimeException("Bundle [" + bundle.getName() + "] (id=" + bundle.getId() + ") has more than 1 'latest' version. This should not happen - aborting"); } } // note - this is the same algo used by ResourceClientProxy in updatebackingContent (for a resource) String latestVersion = latestBundleVersion != null ? latestBundleVersion.getVersion() : null; String newVersion = NumberUtil.autoIncrementVersion(latestVersion); return newVersion; }
public Bundle(String name, BundleType type, Repo repo, PackageType packageType) { setName(name); setBundleType(type); setRepo(repo); setPackageType(packageType); }
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); BundleType bundleType = bundleVersion.getBundle().getBundleType(); RecipeParseResults parseResults = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager() .parseRecipe(bundleType.getName(), bundleVersion.getRecipe());
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); PackageType packageType = bundle.getPackageType(); architecture = (null == architecture) ? contentManager.getNoArchitecture() : architecture; if (architecture.getId() == 0) { Repo repo = bundle.getRepo(); generalPackage.setClassification(bundle.getName());
packageType.setDeploymentConfigurationDefinition(null); Bundle bundle = new Bundle(name, bundleType, repo, packageType); bundle.setDescription(description); bundle.setPackageType(packageType);
/** * @deprecated since 4.13, see * {@link BundleManagerLocal#createBundleVersion(org.rhq.core.domain.auth.Subject, int, String, String, String, String)} */ @Override @SuppressWarnings("unchecked") @Deprecated public BundleVersion createBundleVersion(Subject subject, int bundleId, String name, String description, 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); } checkCreateBundleVersionAuthz(subject, bundleId); // parse the recipe (validation occurs here) and get the config def and list of files BundleType bundleType = bundle.getBundleType(); RecipeParseResults results; try { results = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager() .parseRecipe(bundleType.getName(), recipe); } catch (Exception e) { // ensure that we throw a runtime exception to force a rollback throw new RuntimeException("Failed to parse recipe", e); } return createBundleVersionInternal(bundle, name, version, description, recipe, results.getConfigurationDefinition()); }
@Override public void deleteBundleDestination(Subject subject, int destinationId) throws Exception { BundleDestination doomed = this.entityManager.find(BundleDestination.class, destinationId); if (null == doomed) { return; } checkDeployBundleAuthz(subject, doomed.getBundle().getId(), doomed.getGroup().getId()); // deployments replace other deployments and have a self-referring FK. The deployments // need to be removed in a way that will ensure that a replaced deployment is not removed // prior to the replacer. To do this we'll just blanket update all the doomed deployments // to break the FK dependency with nulls. Query q = entityManager.createNamedQuery(BundleDeployment.QUERY_UPDATE_FOR_DESTINATION_REMOVE); q.setParameter("destinationId", destinationId); q.executeUpdate(); entityManager.flush(); entityManager.remove(doomed); }
@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()); }
@Override public PageList<Bundle> findBundlesByCriteria(Subject subject, BundleCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); if (!authorizationManager.hasGlobalPermission(subject, Permission.VIEW_BUNDLES)) { generator.setAuthorizationBundleFragment(CriteriaQueryGenerator.AuthorizationTokenType.BUNDLE, subject.getId(), null); } CriteriaQueryRunner<Bundle> queryRunner = new CriteriaQueryRunner<Bundle>(criteria, generator, entityManager); PageList<Bundle> result = queryRunner.execute(); // If asking for optional data that the subject may not be able to see then ensure that the optional // data is filtered appropriately. In this case only destinations viewable by the subject can be returned. // The result currently holds bundles viewable by the caller, but the bundle may have been deployed to // destinations for which the user does not have access to the destination's resource group. (BZ 694741) if (!result.isEmpty() && criteria.isInventoryManagerRequired() && !authorizationManager.isInventoryManager(subject)) { // this works because findBundleDestinationsByCriteria() authorizes against resource group associations for (Bundle bundle : result) { if (bundle.getDestinations().isEmpty()) { continue; } BundleDestinationCriteria destinationCriteria = new BundleDestinationCriteria(); destinationCriteria.clearPaging(); //disable paging as the code assumes all the results will be returned. destinationCriteria.addFilterBundleId(bundle.getId()); List<BundleDestination> destinations = findBundleDestinationsByCriteria(subject, destinationCriteria); entityManager.detach(bundle); // make sure the narrowed set of destinations does not get persisted bundle.setDestinations(destinations); } } return result; }
@Override public String toString() { return "BundleDestination[id=" + id // + ((null != bundle) ? (", bundle=" + bundle.getName()) : "") // + ((null != group) ? (", group=" + group.getName()) : "") // + ", name=" + name + "]"; }
public void addBundle(Bundle bundle) { if (bundles == null) { bundles = new HashSet<Bundle>(); } bundle.addTag(this); bundles.add(bundle); }
/** * This also updates the inverse relation (add this bundle group to bundle) * @param bundle */ public void addBundle(Bundle bundle) { getBundles().add(bundle); bundle.addBundleGroup(this); }
return false; } else if (!this.bundle.equals(other.bundle)) { return false;
checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId()); BundleType bundleType = bundleVersion.getBundle().getBundleType(); RecipeParseResults parseResults = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager() .parseRecipe(bundleType.getName(), bundleVersion.getRecipe());
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType(); ResourceType resourceType = bundleType.getResourceType(); Set<Resource> resources = inventoryManager.getResourcesWithType(resourceType);
int bundleId = bundleVersion.getBundle().getId();
checkDeployBundleAuthz(subject, bundle.getId(), groupId); Set<ResourceType> targetedResourceTypes = bundle.getBundleType().getExplicitlyTargetedResourceTypes(); throw new IllegalArgumentException("Bundle of type [" + bundle.getBundleType().getName() + "] is incompatible with resource type " + group.getResourceType()); String bundleType = bundle.getBundleType().getName(); ResourceType rt = group.getResourceType(); ResourceTypeBundleConfiguration bundleConfig = rt.getResourceTypeBundleConfiguration();
BundleType bundleType = bundleDeployment.getBundleVersion().getBundle().getBundleType(); ResourceType resourceType = bundleType.getResourceType(); Set<Resource> resources = inventoryManager.getResourcesWithType(resourceType);
@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; }