@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 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); }
@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 public void deleteBundleDeployment(Subject subject, int bundleDeploymentId) throws Exception { BundleDeployment doomed = this.entityManager.find(BundleDeployment.class, bundleDeploymentId); if (null == doomed) { return; } checkDeployBundleAuthz(subject, doomed.getBundleVersion().getBundle().getId(), doomed.getDestination() .getGroup().getId()); // only allow deployments to be deleted if they are not started or finished if (BundleDeploymentStatus.PENDING == doomed.getStatus() || BundleDeploymentStatus.SUCCESS == doomed.getStatus() || BundleDeploymentStatus.FAILURE == doomed.getStatus() || BundleDeploymentStatus.MIXED == doomed.getStatus()) { // change the pointer like in the linked list (ie. when removing B from A -> B -> C, it should result // in following situation: A -> C) Query q = entityManager.createNamedQuery(BundleDeployment.QUERY_UPDATE_FOR_DEPLOYMENT_REMOVE); q.setParameter("bundleId", doomed.getId()); q.executeUpdate(); entityManager.flush(); entityManager.remove(doomed); } else { throw new IllegalArgumentException("Can not delete deployment with status [" + doomed.getStatus() + "]"); } }
@Override public PageList<BundleDeployment> findBundleDeploymentsByCriteria(Subject subject, BundleDeploymentCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); // filter by bundles that are viewable if (!authorizationManager.hasGlobalPermission(subject, Permission.VIEW_BUNDLES)) { generator.setAuthorizationBundleFragment(CriteriaQueryGenerator.AuthorizationTokenType.BUNDLE, subject.getId(), "bundleVersion.bundle"); } CriteriaQueryRunner<BundleDeployment> queryRunner = new CriteriaQueryRunner<BundleDeployment>(criteria, generator, entityManager); PageList<BundleDeployment> result = queryRunner.execute(); // The result currently holds bundle deployments for bundles viewable by the caller, but we must remove // those bundle deployments for destinations not viewable by the user. In essence we wanted two authz tokens, // one for bundle and one for resource group, but we can only supply one. if (!(result.isEmpty() || authorizationManager.isInventoryManager(subject))) { for (Iterator<BundleDeployment> i = result.iterator(); i.hasNext();) { BundleDeployment bd = i.next(); int groupId = bd.getDestination().getGroup().getId(); if (!authorizationManager.canViewGroup(subject, groupId)) { i.remove(); } } } return result; }
ResourceGroup group = destination.getGroup();
.getDestination().getGroup().getId());
result.setErrorMessage("The patch to revert to (" + stopPid + ") was not previously deployed by RHQ. This means that this server joined the resource group '" + request.getResourceDeployment().getBundleDeployment().getDestination().getGroup().getName() + "' after this patch was already deployed. To prevent accidental damage no changes will be made to the server.");
.getDestination().getGroup().getId());