@SuppressWarnings("unchecked") @RequiredPermission(Permission.MANAGE_REPOSITORIES) public void deleteCandidatesWithOnlyContentSource(Subject subject, int contentSourceId) { Query query = entityManager.createNamedQuery(Repo.QUERY_FIND_CANDIDATES_WITH_ONLY_CONTENT_SOURCE); query.setParameter("contentSourceId", contentSourceId); List<Repo> repoList = query.getResultList(); for (Repo deleteMe : repoList) { deleteRepo(subject, deleteMe.getId()); } }
/** * @param repoSyncResults * @param progressWatcher */ public SyncTracker(RepoSyncResults repoSyncResultsIn, ProgressWatcher progressWatcherIn) { super(); this.repoId = repoSyncResultsIn.getRepo().getId(); this.repoSyncResults = repoSyncResultsIn; this.progressWatcher = progressWatcherIn; this.progressWatcher.start(); }
@SuppressWarnings("unchecked") @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public RepoSyncResults persistRepoSyncResults(RepoSyncResults results) { ContentManagerHelper helper = new ContentManagerHelper(entityManager); Query q = entityManager.createNamedQuery(RepoSyncResults.QUERY_GET_INPROGRESS_BY_REPO_ID); q.setParameter("repoId", results.getRepo().getId()); RepoSyncResults persistedSyncResults = (RepoSyncResults) helper.persistSyncResults(q, results); return (null != persistedSyncResults) ? persistedSyncResults : results; }
public Repo updateRepo(Subject subject, Repo repo) throws RepoException { validateFields(repo); if (!authzManager.hasGlobalPermission(subject, Permission.MANAGE_REPOSITORIES)) { if (!authzManager.canUpdateRepo(subject, repo.getId())) { throw new PermissionException("User [" + subject + "] can't update repo with id " + repo.getId()); } //only the repo manager can update the owner of a repo. //make sure that's the case. repo.setOwner(subject); } // HHH-2864 - Leave this in until we move to hibernate > 3.2.r14201-2 getRepo(subject, repo.getId()); // should we check non-null repo relationships and warn that we aren't changing them? log.debug("User [" + subject + "] is updating [" + repo + "]..."); repo = entityManager.merge(repo); log.debug("User [" + subject + "] updated [" + repo + "]."); try { ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer(); pc.unscheduleRepoSyncJob(repo); pc.scheduleRepoSyncJob(repo); } catch (Exception e) { log.warn("Failed to reschedule repository synchronization job for [" + repo + "].", e); } return repo; }
repoManager.internalSynchronizeRepos(overlord, new Integer[] { repoToSync.getId() });
@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()); }
q.setParameter("repoId", repo.getId()); q.executeUpdate();
public List<SubscribedRepo> findSubscriptions(Subject subject, int resourceId) { if (!authzManager.canViewResource(subject, resourceId)) { throw new PermissionException("User [" + subject + "] can't view resource with id " + resourceId); } List<SubscribedRepo> list = new ArrayList<SubscribedRepo>(); PageControl pc = new PageControl(); for (RepoComposite repoComposite : findResourceSubscriptions(subject, resourceId, pc)) { Repo repo = repoComposite.getRepo(); SubscribedRepo summary = new SubscribedRepo(repo.getId(), repo.getName()); list.add(summary); } return list; }
List<Advisory> advs = repoManager.findAssociatedAdvisory(overlord, repo.getId(), pc); log.error("Found " + advs.size() + " advisories for repo " + repo.getId()); ThreadUtil.checkInterrupted(); AdvisorySyncReport advReport = new AdvisorySyncReport(repo.getId()); List<AdvisoryDetails> advDetails = new ArrayList<AdvisoryDetails>(advs.size()); translateDomainToDto(advs, advDetails);
private void syncImportedRepos(ContentSource contentSource) throws InterruptedException { SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager(); final Subject overlord = subjectManager.getOverlord(); final RepoCriteria repoCriteria = new RepoCriteria(); repoCriteria.addFilterContentSourceIds(contentSource.getId()); repoCriteria.addFilterCandidate(false); final RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal(); //Use CriteriaQuery to automatically chunk/page through criteria query results CriteriaQueryExecutor<Repo, RepoCriteria> queryExecutor = new CriteriaQueryExecutor<Repo, RepoCriteria>() { @Override public PageList<Repo> execute(RepoCriteria criteria) { return repoManager.findReposByCriteria(overlord, repoCriteria); } }; CriteriaQuery<Repo, RepoCriteria> repos = new CriteriaQuery<Repo, RepoCriteria>(repoCriteria, queryExecutor); ArrayList<Integer> repoIdList = new ArrayList<Integer>(); for (Repo repo : repos) { repoIdList.add(repo.getId()); } Integer[] repoIds = new Integer[repoIdList.size()]; repoIds = repoIdList.toArray(repoIds); repoManager.internalSynchronizeRepos(overlord, repoIds); }
List<Distribution> dists = repoManager.findAssociatedDistributions(overlord, repo.getId(), pc); log.debug("Found " + dists.size() + " distributions for repo " + repo.getId()); DistributionSyncReport distReport = new DistributionSyncReport(repo.getId()); List<DistributionDetails> distDetails = new ArrayList<DistributionDetails>(dists.size()); translateDomainToDto(dists, distDetails);
final PackageCriteria pCrit = new PackageCriteria(); pCrit.addFilterName(scriptName); pCrit.addFilterRepoId(repo.getId()); PackageAndLatestVersionComposite pv = pvs.iterator().next(); byte[] bytes = repoManager.getPackageVersionBytes(rhqFacade.getSubject(), repo.getId(), pv .getLatestPackageVersion().getId());
for (Repo repo : repos) { repoCount++; log.debug("downloadDistributionBits operating on repo: " + repo.getName() + " id = " + repo.getId()); log.debug("Looking up existing distributions for repoId: " + repo.getId()); List<Distribution> dists = repoManager.findAssociatedDistributions(overlord, repo.getId(), pageControl); log.debug("Found " + dists.size() + " Distributions for repoId " + repo.getId());
@RequiredPermission(Permission.MANAGE_REPOSITORIES) public void cancelSync(Subject subject, int repoId) throws ContentException { ContentServerPluginContainer pc; try { pc = ContentManagerHelper.getPluginContainer(); } catch (Exception e) { throw new RuntimeException(e); } Repo repo = this.getRepo(subject, repoId); try { pc.cancelRepoSync(subject, repo); } catch (SchedulerException e) { throw new ContentException(e); } RepoSyncResults results = this.getMostRecentSyncResults(subject, repo.getId()); results.setStatus(ContentSyncStatus.CANCELLING); repoManager.mergeRepoSyncResults(results); }
repoManager.addPackageVersionsToRepo(subjectManager.getOverlord(), repo.getId(), new int[] { packageVersion.getId() });
Repo repo = repoManager.getRepo(overlord, report.getRepoId()); RepoDistribution repoDist = new RepoDistribution(repo, newDist); log.debug("Created new mapping of RepoDistribution repoId = " + repo.getId() + ", distId = " + newDist.getId()); entityManager.persist(repoDist);
.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, source.getId(), repo.getId(), pc); String msg = "Synchronize Package Bits: [" + source.getName() + "], repo [" + repo.getName() + "]: loaded package list for sync (" + (System.currentTimeMillis() - start) + ")ms";