Package org.rhq.core.domain.content

Examples of org.rhq.core.domain.content.ContentSourceSyncResults


            list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
                PageControl.getUnlimitedInstance());
            assert list.size() == 0 : "-->" + list;

            // create our first INPROGRESS result
            ContentSourceSyncResults results = new ContentSourceSyncResults(contentSource);
            results = contentSourceManager.persistContentSourceSyncResults(results);
            assert results != null;

            // make sure it persisted
            list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
                PageControl.getUnlimitedInstance());
            assert list.size() == 1 : "-->" + list;
            assert list.get(0).getId() == results.getId() : "-->" + list;

            // try to create another INPROGRESS, this is not allowed so null must be returned by persist
            ContentSourceSyncResults another = new ContentSourceSyncResults(contentSource);
            another = contentSourceManager.persistContentSourceSyncResults(another);
            assert another == null : "Not allowed to have two INPROGRESS results persisted";

            // verify that we really did not persist a second one
            list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
                PageControl.getUnlimitedInstance());
            assert list.size() == 1 : "-->" + list;
            assert list.get(0).getId() == results.getId() : "-->" + list;

            // try to create another but this one is a FAILURE, this is allowed
            another = new ContentSourceSyncResults(contentSource);
            another.setStatus(ContentSyncStatus.FAILURE);
            another.setEndTime(System.currentTimeMillis());
            another = contentSourceManager.persistContentSourceSyncResults(another);
            assert another != null : "Allowed to have two results persisted if only one is INPROGRESS";

            // verify that we really did persist a second one
            list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
                PageControl.getUnlimitedInstance());
            assert list.size() == 2 : "-->" + list;
            assert list.get(0).getId() == another.getId() : "-->" + list;
            assert list.get(1).getId() == results.getId() : "-->" + list;

            // delete the content source and make sure we cascade delete the results
            contentSourceManager.deleteContentSource(overlord, contentSource.getId());
View Full Code Here


    @RequiredPermission(Permission.MANAGE_REPOSITORIES)
    public void deleteContentSourceSyncResults(Subject subject, int[] ids) {
        if (ids != null) {
            for (int id : ids) {
                ContentSourceSyncResults doomed = entityManager.getReference(ContentSourceSyncResults.class, id);
                entityManager.remove(doomed);
            }
        }

        return;
View Full Code Here

    public boolean synchronizeContentProvider(int contentSourceId) throws Exception {

        ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager();

        ContentProvider provider = getIsolatedContentProvider(contentSourceId);
        ContentSourceSyncResults results = null;
        SubjectManagerLocal subjMgr = LookupUtil.getSubjectManager();
        Subject overlord = subjMgr.getOverlord();

        // append to this as we go along, building a status report
        StringBuilder progress = new StringBuilder();

        try {
            ContentSource contentSource = contentSourceManager.getContentSource(overlord, contentSourceId);
            if (contentSource == null) {
                throw new Exception("Cannot sync a non-existing content source [" + contentSourceId + "]");
            }

            // This should not take very long so it should be OK to block other
            // callers.
            // We are avoiding the problem that would occur if we try to
            // synchronize the same source
            // at the same time. We could do it more cleverly by synchronizing
            // on a per content source
            // basis, but I don't see a need right now to make this more
            // complicated.
            // We can come back and revisit if we need more fine-grained
            // locking.
            synchronized (synchronizeContentSourceLock) {
                progress.append(new Date()).append(": ");
                progress.append("Start synchronization of content source [").append(contentSource.getName()).append(
                    "]\n");
                progress.append(new Date()).append(": ");
                progress.append("Getting currently known list of packages...\n");
                results = new ContentSourceSyncResults(contentSource);
                results.setResults(progress.toString());
                results = contentSourceManager.persistContentSourceSyncResults(results);
            }

            if (results == null) {
                // note that it technically is still possible to have concurrent
                // syncs - if two
                // threads running in two different servers (i.e. different VMs)
                // both try to sync the
                // same content source and both enter the
                // persistContentSourceSyncResults method at
                // the same time, you'll get two inprogress rows - this is so
                // rare as to not care.
                // Even if it does happen, it may still work, or
                // one sync will get an error and rollback its tx and no harm
                // will be done.
                log.info("Content source [" + contentSource.getName()
                    + "] is already being synchronized - this sync request will be ignored.");
                return false;
            }

            RepoSourceSynchronizer repoSourceSynchronizer = new RepoSourceSynchronizer(contentSource, provider);
            repoSourceSynchronizer.synchronizeCandidateRepos(progress);
            results.setStatus(ContentSyncStatus.SUCCESS);
            results.setResults(progress.toString());

        } catch (Throwable t) {
            if (results != null) {
                // try to reload the results in case it was updated by the SLSB
                // before the
                // exception happened
                ContentSourceSyncResults reloadedResults = contentSourceManager.getContentSourceSyncResults(results
                    .getId());
                if (reloadedResults != null) {
                    results = reloadedResults;
                    if (results.getResults() != null) {
                        progress = new StringBuilder(results.getResults());
View Full Code Here

            PackageType pt = new PackageType("testCSSRInsertPT", resource.getResourceType());
            Package pkg = new Package("testCSSRInsertPackage", pt);
            PackageVersion pv = new PackageVersion(pkg, "version", arch);
            ContentSourceType cst = new ContentSourceType("testCSSRContentSourceType");
            ContentSource cs = new ContentSource("testCSSRContentSource", cst);
            ContentSourceSyncResults results = new ContentSourceSyncResults(cs);
            Repo repo = new Repo("testCSSRRepo");
            repo.addContentSource(cs);

            em.persist(rt);
            em.persist(resource);
            em.persist(arch);
            em.persist(pt);
            em.persist(pkg);
            em.persist(pv);
            em.persist(cst);
            em.persist(cs);
            em.persist(repo);
            em.persist(results);
            cs.addSyncResult(results);
            em.flush();

            cs = em.find(ContentSource.class, cs.getId());
            assert cs != null;
            List<ContentSourceSyncResults> syncResults = cs.getSyncResults();
            assert syncResults != null;
            assert syncResults.size() == 1;
            results = syncResults.get(0);
            assert results.getContentSource().equals(cs);
            assert results.getStatus() == ContentSyncStatus.INPROGRESS;
            assert results.getResults() == null;
            assert results.getEndTime() == null;
            assert results.getStartTime() <= System.currentTimeMillis();

            results.setEndTime(System.currentTimeMillis());
            results.setStatus(ContentSyncStatus.FAILURE);
            results.setResults("dummy failure");
            results = em.merge(results);

            // add another (make sure the start time is long enough to pass the time check below
            Thread.sleep(100);
            results = new ContentSourceSyncResults(cs);
            em.persist(results);
            cs.addSyncResult(results);
            em.flush();

            cs = em.find(ContentSource.class, cs.getId());
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.content.ContentSourceSyncResults

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.