Examples of PackageVersionContentSource


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

            // check the count
            long pvcscount = contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
            assert (pvcscount == 1) : "-->" + pvcscount;

            // this is the new one we just added - we'll pass this to our next merge as the previous state
            PackageVersionContentSource addedPVCS = unloaded.get(0);
            assert addedPVCS.getPackageVersionContentSourcePK().getPackageVersion().getFileSize() == 1234L;
            previous.put(key, addedPVCS);

            System.out.println("content source merge ADD works!");

            // create a new report that updates the one we just added
View Full Code Here

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

            // check the count to make sure the pv was added to the repo
            assert 1 == contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
            assert 1 == repoManager.getPackageVersionCountFromRepo(overlord, repoId);

            // this is the new one we just added - we'll pass this to our next merge as the previous state
            PackageVersionContentSource addedPVCS = unloaded.get(0);
            previous.put(key, addedPVCS);

            // create a report that removes the one we added
            report = new PackageSyncReport();
            report.addDeletePackage(details);
View Full Code Here

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

        for (ContentProviderPackageDetails doomedDetails : report.getDeletedPackages()) {

            // Delete the mapping between package version and content source
            ContentProviderPackageDetailsKey doomedDetailsKey = doomedDetails.getContentProviderPackageDetailsKey();
            PackageVersionContentSource doomedPvcs = previous.get(doomedDetailsKey);
            doomedPvcs = entityManager.find(PackageVersionContentSource.class, doomedPvcs
                .getPackageVersionContentSourcePK());
            if (doomedPvcs != null) {
                entityManager.remove(doomedPvcs);
            }

            // Delete the relationship between package and repo IF no other providers provide the
            // package
            q = entityManager.createNamedQuery(RepoPackageVersion.DELETE_WHEN_NO_PROVIDER);
            q.setParameter("repoId", repo.getId());
            q.executeUpdate();

            // Delete the package version if it is sufficiently orphaned:
            // - No repos
            // - No content sources
            // - No installed packages
            PackageVersion doomedPv = doomedPvcs.getPackageVersionContentSourcePK().getPackageVersion();
            q = entityManager.createNamedQuery(PackageVersion.DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS);
            q.setParameter("packageVersionId", doomedPv.getId());
            q.executeUpdate();

            if ((++flushCount % 200) == 0) {
View Full Code Here

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

                    + " but no resource type in package " + newDetails + ".");
            }

            // now create the mapping between the package version and content source
            // now that if the mapping already exists, we overwrite it (a rare occurrence, but could happen)
            PackageVersionContentSource newPvcs = new PackageVersionContentSource(pv, contentSource, newDetails
                .getLocation());
            newPvcs = entityManager.merge(newPvcs);

            // for all repos that are associated with this content source, add this package version directly to them
            RepoPackageVersion mapping = new RepoPackageVersion(repo, pv);
View Full Code Here

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

        // then we have to get the current PVCS and merge its updates

        for (ContentProviderPackageDetails updatedDetails : report.getUpdatedPackages()) {
            ContentProviderPackageDetailsKey key = updatedDetails.getContentProviderPackageDetailsKey();

            PackageVersionContentSource previousPvcs = previous.get(key);
            PackageVersionContentSource attachedPvcs; // what we will find in the DB, in jpa session

            attachedPvcs = entityManager.find(PackageVersionContentSource.class, previousPvcs
                .getPackageVersionContentSourcePK());
            if (attachedPvcs == null) {
                log.warn("Content source adapter reported that a non-existing package was updated, adding it [" + key
                    + "]");
                // I should probably not rely on persist cascade and use contentmanager.persistOrMergePackageVersionSafely
                // however, this rarely will occur (should never occur really) so I won't worry about it
                entityManager.persist(previousPvcs);
                attachedPvcs = previousPvcs;
            }

            PackageVersion pv = previousPvcs.getPackageVersionContentSourcePK().getPackageVersion();
            pv.setDisplayName(updatedDetails.getDisplayName());
            pv.setDisplayVersion(updatedDetails.getDisplayVersion());
            pv.setExtraProperties(updatedDetails.getExtraProperties());
            pv.setFileCreatedDate(updatedDetails.getFileCreatedDate());
            pv.setFileName(updatedDetails.getFileName());
            pv.setFileSize(updatedDetails.getFileSize());
            pv.setLicenseName(updatedDetails.getLicenseName());
            pv.setLicenseVersion(updatedDetails.getLicenseVersion());
            pv.setLongDescription(updatedDetails.getLongDescription());
            pv.setMD5(updatedDetails.getMD5());
            pv.setMetadata(updatedDetails.getMetadata());
            pv.setSHA256(updatedDetails.getSHA256());
            pv.setShortDescription(updatedDetails.getShortDescription());

            // we normally would want to do this:
            //    pv = entityManager.merge(pv);
            // but we have to watch out for an agent sending us a content report at the same time that
            // would create this PV concurrently.  If the below line takes too hard a hit on performance,
            // we can replace it with the merge call mentioned above and hope this concurrency doesn't happen.
            // if it does happen, we will rollback our tx and we'll have to wait for the next sync to fix it.
            pv = contentManager.persistOrMergePackageVersionSafely(pv);

            attachedPvcs.setLocation(updatedDetails.getLocation());

            if ((++flushCount % 200) == 0) {
                entityManager.flush();
                entityManager.clear();
            }
View Full Code Here

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

                        + "] has had its bits file deleted but cannot download it again.", e);
                }
            }
        }

        PackageVersionContentSource pvcs = null; // will be non-null only if package bits were not originally available

        if (!packageBitsAreAvailable) {
            if (resourceId == -1) {
                throw new IllegalStateException("Package bits must be inserted prior to the agent asking for them "
                    + "during a cotent-based resource creation");
View Full Code Here

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

                        + "] has had its bits file deleted but cannot download it again.", e);
                }
            }
        }

        PackageVersionContentSource pvcs = null; // will be non-null only if package bits were not originally available

        if (!packageBitsAreAvailable) {
            if (resourceId == -1) {
                throw new IllegalStateException("Package bits must be inserted prior to the agent asking for them "
                    + "during a cotent-based resource creation");
            }
            // if we got here, the package bits have not been downloaded yet.  This eliminates the
            // possibility that the package version were directly uploaded by a user
            // or auto-discovered by a resource and attached to a repo. So, that leaves
            // the only possibility - the package version comes from a content source and therefore has
            // a PackageVersionContentSource mapping.  Let's find that mapping.
            Query q2 = entityManager.createNamedQuery(PackageVersionContentSource.QUERY_FIND_BY_PKG_VER_ID_AND_RES_ID);
            q2.setParameter("resourceId", resourceId);
            q2.setParameter("packageVersionId", packageVersionId);
            List<PackageVersionContentSource> pvcss = q2.getResultList();

            // Note that its possible more than one content source can deliver a PV - if a resource is subscribed
            // to repo(s) that contain multiple content sources that can deliver a PV, we just take
            // the first one we find.

            if (pvcss.size() == 0) {
                throw new RuntimeException("Resource [" + resourceId + "] cannot access package version ["
                    + packageDetailsKey + "] - no content source exists to deliver it");
            }

            pvcs = pvcss.get(0);

            // Make it a true EJB call so we suspend our tx and get a new tx.
            // This way, we start with a fresh tx timeout when downloading and this
            // won't affect the time we are in in this method's tx (I hope that's how it works).
            // This is because this method itself may take a long time to send the data to the output stream
            // and we don't want out tx timing out due to the time it takes downloading.
            PackageBits bits = null;
            bits = contentSourceManager.downloadPackageBits(subjectManager.getOverlord(), pvcs);

            if (bits != null) {
                // rerun the query just to make sure we really downloaded it successfully
                query.setParameter("id", pvcs.getPackageVersionContentSourcePK().getPackageVersion().getId());
                composite = (LoadedPackageBitsComposite) query.getSingleResult();

                if (!composite.isPackageBitsAvailable()) {
                    throw new RuntimeException("Failed to download package bits [" + packageDetailsKey
                        + "] for resource [" + resourceId + "]");
                }
            } else {
                // package bits are not loaded and never will be loaded due to content source's download mode == NEVER
                composite = null;
            }
        }

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet results = null;
        InputStream bitsStream = null;

        try {
            if (composite == null) {
                // this is DownloadMode.NEVER and we are really in pass-through mode, stream directly from adapter
                ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
                ContentProviderManager adapterMgr = pc.getAdapterManager();
                int contentSourceId = pvcs.getPackageVersionContentSourcePK().getContentSource().getId();
                bitsStream = adapterMgr.loadPackageBits(contentSourceId, pvcs.getLocation());
            } else {
                if (composite.isPackageBitsInDatabase()) {
                    // this is  DownloadMode.DATABASE - put the bits in the database

                    conn = dataSource.getConnection();
View Full Code Here

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

            PackageType pt = new PackageType("testPVCSInsertPT", resource.getResourceType());
            Package pkg = new Package("testPVCSInsertPackage", pt);
            PackageVersion pv = new PackageVersion(pkg, "version", arch);
            ContentSourceType cst = new ContentSourceType("testPVCSContentSourceType");
            ContentSource cs = new ContentSource("testPVCSContentSource", cst);
            PackageVersionContentSource pvcs = new PackageVersionContentSource(pv, cs, "fooLocation");

            Configuration csConfig = new Configuration();
            csConfig.put(new PropertySimple("csConfig1", "csConfig1Value"));
            cs.setConfiguration(csConfig);

            Configuration pvConfig = new Configuration();
            pvConfig.put(new PropertySimple("pvConfig1", "pvConfig1Value"));
            pv.setExtraProperties(pvConfig);

            String pvMetadata = "testInsertMetadata";
            pv.setMetadata(pvMetadata.getBytes());

            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(pvcs);
            em.flush();
            em.clear();

            PackageVersionContentSourcePK pk = new PackageVersionContentSourcePK(pv, cs);
            PackageVersionContentSource pvcsDup = em.find(PackageVersionContentSource.class, pk);

            em.clear();

            assert pvcsDup != null;
            assert pvcsDup.equals(pvcs);
            assert pvcsDup.getLocation().equals("fooLocation");

            PackageVersionContentSourcePK pkDup = pvcsDup.getPackageVersionContentSourcePK();
            assert pkDup.getContentSource().getName().equals("testPVCSContentSource");
            assert pkDup.getPackageVersion().getGeneralPackage().getName().equals("testPVCSInsertPackage");

            Query q = em.createNamedQuery(PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID);
            q.setParameter("id", cs.getId());
View Full Code Here

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

            PackageType pt = new PackageType("testPVCSInsertPT", resource.getResourceType());
            Package pkg = new Package("testPVCSInsertPackage", pt);
            PackageVersion pv = new PackageVersion(pkg, "version", arch);
            ContentSourceType cst = new ContentSourceType("testPVCSContentSourceType");
            ContentSource cs = new ContentSource("testPVCSContentSource", cst);
            PackageVersionContentSource pvcs = new PackageVersionContentSource(pv, cs, "fooLocation");

            Configuration csConfig = new Configuration();
            csConfig.put(new PropertySimple("csConfig1", "csConfig1Value"));
            cs.setConfiguration(csConfig);

            Configuration pvConfig = new Configuration();
            pvConfig.put(new PropertySimple("pvConfig1", "pvConfig1Value"));
            pv.setExtraProperties(pvConfig);

            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(pvcs);
            em.flush();
            em.clear();

            PackageVersionContentSourcePK pk = new PackageVersionContentSourcePK(pv, cs);
            PackageVersionContentSource pvcsDup = em.find(PackageVersionContentSource.class, pk);

            em.clear();

            assert pvcsDup != null;
            assert pvcsDup.equals(pvcs);
            assert pvcsDup.getLocation().equals("fooLocation");

            Query q = em.createNamedQuery(PackageVersionContentSource.DELETE_BY_CONTENT_SOURCE_ID);
            q.setParameter("contentSourceId", cs.getId());
            assert 1 == q.executeUpdate();
            em.clear();
View Full Code Here

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

            Package pkg = new Package("testPVCSInsertPackage", pt);
            PackageBits bits = createPackageBits(em);
            PackageVersion pv = new PackageVersion(pkg, "version", arch);
            ContentSourceType cst = new ContentSourceType("testPVCSContentSourceType");
            ContentSource cs = new ContentSource("testPVCSContentSource", cst);
            PackageVersionContentSource pvcs = new PackageVersionContentSource(pv, cs, "fooLocation");

            Configuration csConfig = new Configuration();
            csConfig.put(new PropertySimple("csConfig1", "csConfig1Value"));
            cs.setConfiguration(csConfig);

            Configuration pvConfig = new Configuration();
            pvConfig.put(new PropertySimple("pvConfig1", "pvConfig1Value"));
            pv.setExtraProperties(pvConfig);

            bits.getBlob().setBits("testDeleteOrphanedPV".getBytes());
            pv.setPackageBits(bits);

            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(pvcs);
            em.flush();
            em.clear();

            PackageVersionContentSourcePK pk = new PackageVersionContentSourcePK(pv, cs);
            PackageVersionContentSource pvcsDup = em.find(PackageVersionContentSource.class, pk);
            em.clear();

            assert pvcsDup != null;
            assert pvcsDup.equals(pvcs);
            assert pvcsDup.getLocation().equals("fooLocation");

            Query q = em.createNamedQuery(PackageVersionContentSource.DELETE_BY_CONTENT_SOURCE_ID);
            q.setParameter("contentSourceId", cs.getId());
            assert 1 == q.executeUpdate();
            em.clear();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.