Package org.rhq.core.domain.content

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


        repoManager.addPackageVersionsToRepo(subjectManager.getOverlord(), repo.getId(),
            new int[] { packageVersion.getId() });

        // Classify the Package with the Bundle name in order to distinguish it from the same package name for
        // a different bundle.
        Package generalPackage = packageVersion.getGeneralPackage();
        generalPackage.setClassification(bundle.getName());

        // With all the plumbing in place, create and persist the BundleFile. Tie it to the Package if the caller
        // wants this BundleFile pinned to themost recent version.
        BundleFile bundleFile = new BundleFile();
        bundleFile.setBundleVersion(bundleVersion);
View Full Code Here


    @Override
    public void handleDiscoveredPackage(Resource resource, ResourcePackageDetails discoveredPackage,
        Set<InstalledPackage> doomedPackages, long timestamp) {

        Package generalPackage = null;
        PackageVersion packageVersion = null;

        // Load the overall package (used in a few places later in this loop)
        Query packageQuery = entityManager.createNamedQuery(Package.QUERY_FIND_BY_NAME_PKG_TYPE_RESOURCE_TYPE);
        packageQuery.setFlushMode(FlushModeType.COMMIT);
        // these form a query for a unique package
        packageQuery.setParameter("name", discoveredPackage.getName());
        packageQuery.setParameter("packageTypeName", discoveredPackage.getPackageTypeName());
        packageQuery.setParameter("resourceTypeId", resource.getResourceType().getId());
        List<Package> resultPackages = packageQuery.getResultList();
        if (resultPackages.size() > 0) {
            generalPackage = resultPackages.get(0); // returns at most 1 Package
        }

        // If the package exists see if package version already exists
        if (null != generalPackage) {
            Query packageVersionQuery = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_BY_PACKAGE_VERSION);
            packageVersionQuery.setFlushMode(FlushModeType.COMMIT);
            packageVersionQuery.setParameter("packageId", generalPackage.getId());
            packageVersionQuery.setParameter("version", discoveredPackage.getVersion());
            List<PackageVersion> resultPackageVersions = packageVersionQuery.getResultList();
            // Although the PV unique index is (package,version,arch) in reality the architecture portion is
            // superfluous.  The version is now basically unique (it's basically an enhanced SHA) so it means that
            // two different architectures would basically have two different versions anyway.  So, despite the
            // DB model, this query will return at most 1 PV.
            if (resultPackageVersions.size() > 0) {
                packageVersion = resultPackageVersions.get(0); // returns at most 1 PackageVersion
            }
        }

        // If we didn't find a package version for this deployed package, we will need to create it
        if (null == packageVersion) {
            if (null == generalPackage) {
                Query packageTypeQuery = entityManager
                    .createNamedQuery(PackageType.QUERY_FIND_BY_RESOURCE_TYPE_ID_AND_NAME);
                packageTypeQuery.setFlushMode(FlushModeType.COMMIT);
                packageTypeQuery.setParameter("typeId", resource.getResourceType().getId());
                packageTypeQuery.setParameter("name", discoveredPackage.getPackageTypeName());

                PackageType packageType = (PackageType) packageTypeQuery.getSingleResult();

                generalPackage = new Package(discoveredPackage.getName(), packageType);
                generalPackage = persistOrMergePackageSafely(generalPackage);
            }

            // Create a new package version and attach to the general package
            Architecture packageArchitecture;
View Full Code Here

        // If the package doesn't exist, create that here
        Query packageQuery = entityManager.createNamedQuery(Package.QUERY_FIND_BY_NAME_PKG_TYPE_ID);
        packageQuery.setParameter("name", packageName);
        packageQuery.setParameter("packageTypeId", packageTypeId);

        Package existingPackage;

        List existingPackageList = packageQuery.getResultList();

        if (existingPackageList.size() == 0) {
            existingPackage = new Package(packageName, packageType);
            existingPackage = persistOrMergePackageSafely(existingPackage);
        } else {
            existingPackage = (Package) existingPackageList.get(0);
        }

        // Create a package version and add it to the package
        PackageVersion newPackageVersion = new PackageVersion(existingPackage, version, architecture);
        newPackageVersion.setDisplayName(existingPackage.getName());

        newPackageVersion = persistOrMergePackageVersionSafely(newPackageVersion);

        Map<String, String> contentDetails = new HashMap<String, String>();
        PackageBits bits = loadPackageBits(packageBitStream, newPackageVersion.getId(), packageName, version, null,
            contentDetails);

        newPackageVersion.setPackageBits(bits);
        newPackageVersion.setFileSize(Long.valueOf(contentDetails.get(UPLOAD_FILE_SIZE)).longValue());
        newPackageVersion.setSHA256(contentDetails.get(UPLOAD_SHA256));
        newPackageVersion.setDisplayVersion(displayVersion);

        existingPackage.addVersion(newPackageVersion);

        return newPackageVersion;
    }
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public Package persistOrMergePackageSafely(Package pkg) {
        Package persisted = null;
        RuntimeException error = null;

        try {
            if (pkg.getId() == 0) {
                persisted = contentManager.persistPackage(pkg);
            }
        } catch (RuntimeException re) {
            error = re;
        }

        // If we didn't persist, the package already exists, so we should be able to find it.
        if (persisted == null) {
            Query q = entityManager.createNamedQuery(Package.QUERY_FIND_BY_NAME_PKG_TYPE_ID);
            q.setParameter("name", pkg.getName());
            q.setParameter("packageTypeId", pkg.getPackageType().getId());

            List<Package> found = q.getResultList();
            if (error != null && found.size() == 0) {
                throw error;
            }
            if (found.size() != 1) {
                throw new RuntimeException("Expecting 1 package matching [" + pkg + "] but got: " + found);
            }
            pkg.setId(found.get(0).getId());
            persisted = entityManager.merge(pkg);

            if (error != null) {
                LOG.warn("There was probably a very big and ugly EJB/hibernate error just above this log message - "
                    + "you can normally ignore that. We detected that a package was already created when we"
                    + " tried to do it also - we will ignore this and just use the new package that was "
                    + "created in the other thread");
            }
        } else {
            // the persisted object is unattached right now,
            // we want it attached so the caller always has an attached entity returned to it
            persisted = entityManager.find(Package.class, persisted.getId());
            persisted.getPackageType().getId();
        }

        return persisted;
    }
View Full Code Here

        } catch (Exception e) {
            LOG.error("Failed to get the package type plugin container. This is a bug.", e);
            throw new IllegalStateException("Failed to get the package type plugin container.", e);
        }

        Package existingPackage = null;

        Query packageQuery = entityManager.createNamedQuery(Package.QUERY_FIND_BY_NAME_PKG_TYPE_ID);
        packageQuery.setParameter("name", packageName);
        packageQuery.setParameter("packageTypeId", packageTypeId);
        List<Package> existingPackageList = packageQuery.getResultList();

        if (existingPackageList.size() == 0) {
            // If the package doesn't exist, create that here
            existingPackage = new Package(packageName, packageType);
            existingPackage = persistOrMergePackageSafely(existingPackage);
        } else {
            existingPackage = existingPackageList.get(0);
        }

        //initialize package version if not already
        if (packageVersion == null) {
            packageVersion = new PackageVersion(existingPackage, version, architecture);
            packageVersion.setDisplayName(existingPackage.getName());
            entityManager.persist(packageVersion);
        }

        //get the data
        Map<String, String> contentDetails = new HashMap<String, String>();
View Full Code Here

            StringBuffer sb = new StringBuffer("Packages: ");
            int counter = 0;
            for (int pkgId : packageIds) {
                PackageVersion packageVersion = contentUIManager.getPackageVersion(pkgId);
                Package generalPackage = packageVersion.getGeneralPackage();

                String version = packageVersion.getDisplayVersion() != null ? packageVersion.getDisplayVersion()
                    : packageVersion.getVersion();

                String packageToAppend = generalPackage.getName() + " " + version;

                // Don't generate notes that would fail our own validation
                if (sb.toString().length() + packageToAppend.length() > 508) {

                    // If we're not at the last package yet, add ... to show there were more
View Full Code Here

            StringBuffer sb = new StringBuffer("Packages: ");
            int counter = 0;
            for (InstalledPackage installedPackage : installedPackages) {
                PackageVersion packageVersion = installedPackage.getPackageVersion();
                Package generalPackage = packageVersion.getGeneralPackage();

                String version = packageVersion.getDisplayVersion() != null ? packageVersion.getDisplayVersion()
                    : packageVersion.getVersion();

                String packageToAppend = generalPackage.getName() + " " + version;

                // Don't generate notes that would fail our own validation
                if (sb.toString().length() + packageToAppend.length() > 508) {

                    // If we're not at the last package yet, add ... to show there were more
View Full Code Here

     *
     * @param packageVersion populated domain entity for a package version
     * @return transfer object populated with the necessary data to request package deployment related activities
     */
    public static ResourcePackageDetails toResourcePackageDetails(PackageVersion packageVersion) {
        Package pkg = packageVersion.getGeneralPackage();
        PackageType pkgType = pkg.getPackageType();

        PackageDetailsKey key = new PackageDetailsKey(pkg.getName(), packageVersion.getVersion(), pkgType.getName(),
            packageVersion.getArchitecture().getName());

        ResourcePackageDetails details = new ResourcePackageDetails(key);
        details.setClassification(pkg.getClassification());
        details.setDisplayName(packageVersion.getDisplayName());
        details.setDisplayVersion(packageVersion.getDisplayVersion());
        //        details.setExtraProperties(packageVersion.getExtraProperties());
        details.setFileCreatedDate(packageVersion.getFileCreatedDate());
        details.setFileName(packageVersion.getFileName());
View Full Code Here

            ContentUIManagerLocal contentUIManager = LookupUtil.getContentUIManager();

            // Load the current installed package so we can get the general package in question
            InstalledPackage currentInstalledPackage = contentUIManager.getInstalledPackage(currentInstalledPackageId);
            Package generalPackage = currentInstalledPackage.getPackageVersion().getGeneralPackage();

            PageList<InstalledPackageHistory> result = contentUIManager.getInstalledPackageHistory(subject, resource
                .getId(), generalPackage.getId(), pc);
            return result;
        }
View Full Code Here

    }

    public String getBackingPackageName() {
        InstalledPackage installedPackage = lookupBackingPackage();
        PackageVersion packageVersion = installedPackage.getPackageVersion();
        Package pkg = packageVersion.getGeneralPackage();

        return pkg.getName();
    }
View Full Code Here

TOP

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

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.