Package org.rhq.enterprise.server.content

Examples of org.rhq.enterprise.server.content.RepoManagerLocal


     */
    private void sync(String repoName) throws InterruptedException {
        log.debug("Syncing repo [" + repoName + "]...");

        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();

        // Note that we will keep calling getOverlord on this subject manager - the overlord
        // has a very short session lifespan so we need to keep asking for a new one, due to
        // the possibility that some of the methods we call here take longer than its lifespan
        Subject overlord;

        overlord = subjectManager.getOverlord();
        List<Repo> repoList = repoManager.getRepoByName(repoName);

        if (repoList.size() != 1) {
            throw new RuntimeException("Unexpected number of repos found for name [" + repoName + "]. " + "Found ["
                + repoList.size() + "] repos");
        }
        Repo repoToSync = repoList.get(0);

        // This call executes all of the logic associated with synchronizing the given repo
        repoManager.internalSynchronizeRepos(overlord, new Integer[] { repoToSync.getId() });
    }
View Full Code Here


        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);
    }
View Full Code Here

     *             invalid
     */
    public boolean synchronizeRepo(int repoId) {
        log.debug("synchronizeRepo() :: start");

        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        Subject overlord = subjectManager.getOverlord();

        // Load the repo to sync
        Repo repo = repoManager.getRepo(overlord, repoId);
        if (repo == null) {
            throw new IllegalArgumentException("Invalid repository with id [" + repoId + "] specified for sync.");
        }

        // results =
        // contentSourceManager.persistContentSourceSyncResults(results);
        StringBuilder progress = new StringBuilder();
        progress.append(new Date()).append(": ");
        progress.append("Start synchronization of Repository [").append(repo.getName()).append("]\n");
        progress.append(new Date()).append(": ");
        progress.append("Getting currently known list of content source packages...\n");
        SyncTracker tracker = new SyncTracker(new RepoSyncResults(repo), new ProgressWatcher());
        tracker.setResults(progress.toString());
        tracker.setRepoSyncResults(repoManager.persistRepoSyncResults(tracker.getRepoSyncResults()));
        log.debug("synchronizeRepo :: inProgress");
        tracker = updatePercentComplete(tracker, repoManager);

        if (tracker.getRepoSyncResults() == null) {
            log.info("Repository [" + repo.getName()
                + "] is already currently being synchronized - this sync request will be ignored.");
            return false;
        }

        boolean syncCancelled = false;
        try {
            ThreadUtil.checkInterrupted();

            // Sync each of the content sources associated with the repo.
            for (ContentSource source : repo.getContentSources()) {
                try {
                    ContentProvider provider = getIsolatedContentProvider(source.getId());
                    SyncProgressWeight sw = provider.getSyncProgressWeight();
                    PackageSourceSynchronizer packageSourceSynchronizer = new PackageSourceSynchronizer(repo, source,
                        provider);
                    log.debug("synchronizeRepo :: synchronizePackageMetadata");

                    tracker = updateSyncStatus(tracker, ContentSyncStatus.PACKAGEMETADATA);
                    tracker = packageSourceSynchronizer.synchronizePackageMetadata(tracker);
                } catch (Exception e) {
                    processSyncException(e, tracker, repo, source, repoManager);
                }
            }
            ThreadUtil.checkInterrupted();

            // Setup ProgressWatcher
            for (ContentSource source : repo.getContentSources()) {
                ContentProvider provider = getIsolatedContentProvider(source.getId());
                SyncProgressWeight sw = provider.getSyncProgressWeight();
                tracker.getProgressWatcher().addWork(sw.getPackageMetadataWeight());
                tracker.addAdvisoryMetadataWork(provider);
                tracker.getProgressWatcher().addWork(sw.getDistribtutionBitsWeight());
                tracker.getProgressWatcher().addWork(sw.getDistribtutionMetadataWeight());
                tracker.addPackageBitsWork(provider);
                tracker.getProgressWatcher().finishWork(sw.getPackageMetadataWeight());
            }
            tracker = updatePercentComplete(tracker, repoManager);

            // Sync package bits.
            for (ContentSource source : repo.getContentSources()) {
                // Don't let the entire sync fail if a single content source
                // fails
                try {
                    ContentProvider provider = getIsolatedContentProvider(source.getId());
                    if (provider instanceof PackageSource) {
                        PackageSourceSynchronizer packageSourceSyncer = new PackageSourceSynchronizer(repo, source,
                            provider);
                        log.debug("synchronizeRepo :: synchronizePackageBits");
                        tracker = updateSyncStatus(tracker, ContentSyncStatus.PACKAGEBITS);
                        tracker = packageSourceSyncer.synchronizePackageBits(tracker, provider);
                        tracker = updatePercentComplete(tracker, repoManager);
                    }
                } catch (Exception e) {
                    processSyncException(e, tracker, repo, source, repoManager);
                }
                // Check for cancellation after each content source.
                ThreadUtil.checkInterrupted();
            }

            // Sync distro metadata.
            log.debug("synchronizeRepo :: synchronizeDistributionMetadata");
            for (ContentSource source : repo.getContentSources()) {
                try {
                    ContentProvider provider = getIsolatedContentProvider(source.getId());
                    if (provider instanceof DistributionSource) {
                        DistributionSourceSynchronizer distroSourceSyncer = new DistributionSourceSynchronizer(
                            repo, source, provider);
                        tracker = updateSyncStatus(tracker, ContentSyncStatus.DISTROMETADATA);
                        tracker = distroSourceSyncer.synchronizeDistributionMetadata(tracker);
                        tracker = updatePercentComplete(tracker, repoManager);
                    }
                } catch (Exception e) {
                    processSyncException(e, tracker, repo, source, repoManager);
                }
                // Check for cancellation after each content source.
                ThreadUtil.checkInterrupted();
            }

            // Sync distro bits.
            log.debug("synchronizeRepo :: synchronizeDistributionBits");
            for (ContentSource source : repo.getContentSources()) {
                try {
                    ContentProvider provider = getIsolatedContentProvider(source.getId());
                    if (provider instanceof DistributionSource) {
                        DistributionSourceSynchronizer distroSourceSyncer = new DistributionSourceSynchronizer(
                            repo, source, provider);
                        tracker = updateSyncStatus(tracker, ContentSyncStatus.DISTROBITS);
                        tracker = distroSourceSyncer.synchronizeDistributionBits(tracker);
                        tracker = updatePercentComplete(tracker, repoManager);
                    }
                    ThreadUtil.checkInterrupted();
                } catch (Exception e) {
                    processSyncException(e, tracker, repo, source, repoManager);
                }
                // Check for cancellation after each content source.
                ThreadUtil.checkInterrupted();
            }

            // Sync advisory metadata.
            log.debug("synchronizeRepo :: synchronizeAdvisoryMetadata");
            for (ContentSource source : repo.getContentSources()) {
                try {

                    ContentProvider provider = getIsolatedContentProvider(source.getId());
                    if (provider instanceof AdvisorySource) {
                        tracker = updateSyncStatus(tracker, ContentSyncStatus.ADVISORYMETADATA);
                        AdvisorySourceSynchronizer advisorySourceSyncer = new AdvisorySourceSynchronizer(repo, source,
                            provider);
                        tracker = advisorySourceSyncer.synchronizeAdvisoryMetadata(tracker);
                        tracker = updatePercentComplete(tracker, repoManager);
                    }
                } catch (Exception e) {
                    processSyncException(e, tracker, repo, source, repoManager);
                }
                // Check for cancellation after each content source.
                ThreadUtil.checkInterrupted();
            }

            // Update status to finished.
            if (tracker.getRepoSyncResults().getStatus() != ContentSyncStatus.FAILURE) {
                tracker.getRepoSyncResults().setStatus(ContentSyncStatus.SUCCESS);
            }
            tracker = updateSyncStatus(tracker, tracker.getRepoSyncResults().getStatus());

            progress = new StringBuilder();
            progress.append("\n");
            progress.append(tracker.getRepoSyncResults().getResults());
            progress.append("\n");
            progress.append(new Date()).append(": ");
            progress.append("Repository [").append(repo.getName()).append("] ");
            progress.append("completed syncing with ");
            progress.append((tracker.getRepoSyncResults().getStatus() == ContentSyncStatus.FAILURE) ? "one or more" : "no");
            progress.append(" errors.\n");
            tracker.setResults(progress.toString());
           
            log.debug("synchronizeRepo :: " + tracker.getRepoSyncResults().getStatus());
        } catch (InterruptedException e) {
            RepoSyncResults recentResults = repoManager.getMostRecentSyncResults(overlord, repo.getId());
            log.debug("Caught InterruptedException during sync of repo with id [" + repoId + "].");
            progress.append("\n ** Cancelled syncing **");
            tracker.setResults(progress.toString());
            tracker.getProgressWatcher().resetToZero();
            tracker = updatePercentComplete(tracker, repoManager);
            try {
                tracker = updateSyncStatus(tracker, ContentSyncStatus.CANCELLED);
            } catch (InterruptedException e1) {
                throw new RuntimeException("Unexpected InterruptedException", e1);
            }
            syncCancelled = true;
        }

        if (tracker.getRepoSyncResults() != null) {
            // pw.stop();
            tracker.getRepoSyncResults().setEndTime(System.currentTimeMillis());
            // results.setPercentComplete(new
            // Long(pw.getPercentComplete()));
            repoManager.mergeRepoSyncResults(tracker.getRepoSyncResults());
            log.debug("synchronizeRepo :: merging results.");
        }
       
        return !syncCancelled;
    }
View Full Code Here

    }

    private SyncTracker updateSyncStatus(SyncTracker tracker, ContentSyncStatus status)
        throws InterruptedException {
        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
        SubjectManagerLocal subjMgr = LookupUtil.getSubjectManager();
        Subject overlord = subjMgr.getOverlord();
        int repoId = tracker.getRepoId();
        RepoSyncResults cancelCheck = repoManager.getMostRecentSyncResults(overlord, repoId);
        if (cancelCheck.getStatus() == ContentSyncStatus.CANCELLING) {
            throw new InterruptedException();
        }
        RepoSyncResults results = tracker.getRepoSyncResults();
        results.setStatus(status);
        results = repoManager.mergeRepoSyncResults(results);
        tracker.setRepoSyncResults(results);
        return tracker;
    }
View Full Code Here

        int repoId = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
        int[] resourceIds = getIntegerArray(selected);

        if ((resourceIds != null) && (resourceIds.length > 0)) {
            try {
                RepoManagerLocal manager = LookupUtil.getRepoManagerLocal();
                for (int resourceId : resourceIds) {
                    manager.unsubscribeResourceFromRepos(subject, resourceId, new int[] { repoId });
                }

                FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Unsubscribed [" + resourceIds.length
                    + "] resources from repository");
            } catch (Exception e) {
View Full Code Here

        }

        public PageList<Resource> fetchDataForPage(PageControl pc) {
            Subject subject = EnterpriseFacesContextUtility.getSubject();
            int id = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
            RepoManagerLocal manager = LookupUtil.getRepoManagerLocal();

            PageList<Resource> results = manager.findSubscribedResources(subject, id, pc);
            return results;
        }
View Full Code Here

        @Override
        @SuppressWarnings("unchecked")
        public PageList<Advisory> fetchPage(PageControl pc) {
            Subject subject = EnterpriseFacesContextUtility.getSubject();
            int id = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
            RepoManagerLocal manager = LookupUtil.getRepoManagerLocal();
            PageList<Advisory> results = manager.findAssociatedAdvisory(subject, id, pc);
            log.debug("Resulsts for advisory" + results);
            return results;
        }
View Full Code Here

        int contentProviderId = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
        int[] repoIds = getIntegerArray(selected);

        if (repoIds.length > 0) {
            try {
                RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
                List<Integer> ids = new ArrayList<Integer>(repoIds.length);
                for (int repoId : repoIds) {
                    ids.add(repoId);
                }
                repoManager.importCandidateRepo(subject, ids);

                FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Imported " + repoIds.length
                    + " repositories from content source.");
            } catch (Exception e) {
                FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
View Full Code Here

        int repoId = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
        int[] resourceIds = getIntegerArray(selected);

        if ((resourceIds != null) && (resourceIds.length > 0)) {
            try {
                RepoManagerLocal manager = LookupUtil.getRepoManagerLocal();

                for (int resourceId : resourceIds) {
                    manager.subscribeResourceToRepos(subject, resourceId, new int[] { repoId });
                }

                FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Subscribed [" + resourceIds.length
                    + "] resources with repository");
            } catch (Exception e) {
View Full Code Here

    public void installSelectedPackages() {
        Subject subject = EnterpriseFacesContextUtility.getSubject();
        String[] selectedPackages = FacesContextUtility.getRequest().getParameterValues("selectedPackages");
        int repoId = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));

        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
        ContentManagerLocal contentManager = LookupUtil.getContentManager();

        int[] packageIds = new int[selectedPackages.length];
        for (int i = 0; i < packageIds.length; i++) {
            packageIds[i] = Integer.parseInt(selectedPackages[i]);
        }

        try {
            List<Resource> resources = repoManager.findSubscribedResources(subject, repoId, PageControl
                .getUnlimitedInstance());
            int[] resourceIds = new int[resources.size()];
            for (int i = 0; i < resourceIds.length; i++) {
                resourceIds[i] = resources.get(i).getId();
            }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.content.RepoManagerLocal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.