Package org.rhq.core.domain.content

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


    private void translateDomainToDto(List<PackageVersionContentSource> existingPVCS,
        Set<ContentProviderPackageDetails> allDetails,
        Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap) {

        for (PackageVersionContentSource pvcs : existingPVCS) {
            PackageVersion pv = pvcs.getPackageVersionContentSourcePK().getPackageVersion();
            org.rhq.core.domain.content.Package p = pv.getGeneralPackage();
            ResourceType rt = p.getPackageType().getResourceType();
            String resourceTypeName = rt != null ? rt.getName() : null;
            String resourceTypePlugin = rt != null ? rt.getPlugin() : null;
           
            ContentProviderPackageDetailsKey key;
            key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), p.getPackageType().getName(), pv
                .getArchitecture().getName(), resourceTypeName, resourceTypePlugin);

            ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
            details.setClassification(pv.getGeneralPackage().getClassification());
            details.setDisplayName(pv.getDisplayName());
            details.setDisplayVersion(pv.getDisplayVersion());
            details.setExtraProperties(pv.getExtraProperties());
            details.setFileCreatedDate(pv.getFileCreatedDate());
            details.setFileName(pv.getFileName());
            details.setFileSize(pv.getFileSize());
            details.setLicenseName(pv.getLicenseName());
            details.setLicenseVersion(pv.getLicenseVersion());
            details.setLocation(pvcs.getLocation());
            details.setLongDescription(pv.getLongDescription());
            details.setMD5(pv.getMD5());
            details.setMetadata(pv.getMetadata());
            details.setSHA256(pv.getSHA256());
            details.setShortDescription(pv.getShortDescription());

            allDetails.add(details);
            keyPVCSMap.put(key, pvcs);
        }
    }
View Full Code Here


            detail.setTopic(d.getTopic());
            detail.setUpdate_date(d.getUpdate_date());

            List<AdvisoryPackage> pkgs = advManager.findPackageByAdvisory(overlord, d.getId(), pc);
            for (AdvisoryPackage pkg : pkgs) {
                PackageVersion pv = advManager.findPackageVersionByPkgId(overlord, pkg.getPkg().getFileName(), pc);
                AdvisoryPackageDetails apkg = new AdvisoryPackageDetails(pv.getDisplayName(), pv.getVersion(), pv
                    .getArchitecture().getName(), pv.getFileName());
                detail.addPkg(apkg);
            }

            List<AdvisoryCVE> cves = advManager.getAdvisoryCVEByAdvId(overlord, d.getId(), pc);
            for (AdvisoryCVE cve : cves) {
View Full Code Here

        if (architecture.getId() == 0) {
            Query q = entityManager.createNamedQuery(Architecture.QUERY_FIND_BY_NAME);
            q.setParameter("name", architecture.getName());
            architecture = (Architecture) q.getSingleResult();
        }
        PackageVersion packageVersion = contentManager.createPackageVersionWithDisplayVersion(subject, name,
            packageType.getId(), version, null, architecture.getId(), fileStream);

        // set the PackageVersion's filename to the bundleFile name, it's left null by default
        packageVersion.setFileName(name);
        packageVersion = entityManager.merge(packageVersion);

        // Create the mapping between the Bundle's Repo and the BundleFile's PackageVersion
        Repo repo = bundle.getRepo();
        // add the packageVersion as overlord, this allows users without MANAGE_INVENTORY permission to add bundle files
        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();
View Full Code Here

        }
        BundleVersion bundleVersion = entityManager.find(BundleVersion.class, bundleVersionId);
        if (null == bundleVersion) {
            throw new IllegalArgumentException("Invalid bundleVersionId: " + bundleVersionId);
        }
        PackageVersion packageVersion = entityManager.find(PackageVersion.class, packageVersionId);
        if (null == packageVersion) {
            throw new IllegalArgumentException("Invalid packageVersionId: " + packageVersionId);
        }

        // Check authorization
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;
            Query architectureQuery = entityManager.createNamedQuery(Architecture.QUERY_FIND_BY_NAME);
            architectureQuery.setFlushMode(FlushModeType.COMMIT);
            architectureQuery.setParameter("name", discoveredPackage.getArchitectureName());

            // We don't have an architecture enum, so it's very possible the plugin will pass in a crap string here.
            // If the architecture is unknown just use "noarch" and log a warning.  We don't want to blow up
            // just because a plugin didn't set this correctly, as architecture is nearly useless at this point.
            try {
                packageArchitecture = (Architecture) architectureQuery.getSingleResult();
            } catch (Exception e) {
                LOG.warn("Discovered Architecture [" + discoveredPackage.getArchitectureName()
                    + "] not found for package [" + discoveredPackage.getName()
                    + "]. Setting to [noarch] and continuing...");
                packageArchitecture = getNoArchitecture();
            }

            packageVersion = new PackageVersion(generalPackage, discoveredPackage.getVersion(), packageArchitecture);
            packageVersion.setDisplayName(discoveredPackage.getDisplayName());
            packageVersion.setDisplayVersion(discoveredPackage.getDisplayVersion());
            packageVersion.setFileCreatedDate(discoveredPackage.getFileCreatedDate());
            packageVersion.setFileName(discoveredPackage.getFileName());
            packageVersion.setFileSize(discoveredPackage.getFileSize());
            packageVersion.setLicenseName(discoveredPackage.getLicenseName());
            packageVersion.setLicenseVersion(discoveredPackage.getLicenseVersion());
            packageVersion.setLongDescription(discoveredPackage.getLongDescription());
            packageVersion.setMD5(discoveredPackage.getMD5());
            packageVersion.setMetadata(discoveredPackage.getMetadata());
            packageVersion.setSHA256(discoveredPackage.getSHA256());
            packageVersion.setShortDescription(discoveredPackage.getShortDescription());
            packageVersion.setExtraProperties(discoveredPackage.getExtraProperties());

            packageVersion = persistOrMergePackageVersionSafely(packageVersion);

        } else {
            // At this point we know a PackageVersion existed previously in the DB already. If it is already
            // installed to the resource then we are done, and we can remove it from the doomed package list.
            for (Iterator<InstalledPackage> i = doomedPackages.iterator(); i.hasNext();) {
                InstalledPackage ip = i.next();
                PackageVersion pv = ip.getPackageVersion();
                if (pv.getId() == packageVersion.getId()) {
                    i.remove();
                    return;
                }
            }
        }
View Full Code Here

    @Override
    public void deployPackagesWithNote(Subject user, int[] resourceIds, int[] packageVersionIds, String requestNotes) {
        for (int resourceId : resourceIds) {
            Set<ResourcePackageDetails> packages = new HashSet<ResourcePackageDetails>();
            for (int packageVersionId : packageVersionIds) {
                PackageVersion packageVersion = entityManager.find(PackageVersion.class, packageVersionId);
                if (packageVersion == null) {
                    throw new IllegalArgumentException("PackageVersion: [" + packageVersionId + "] not found!");
                }

                ResourcePackageDetails details = ContentManagerHelper.packageVersionToDetails(packageVersion);
View Full Code Here

            packageVersionQuery.setParameter("packageTypeName", key.getPackageTypeName());
            packageVersionQuery.setParameter("architectureName", key.getArchitectureName());
            packageVersionQuery.setParameter("version", key.getVersion());
            packageVersionQuery.setParameter("resourceTypeId", resource.getResourceType().getId());

            PackageVersion packageVersion = (PackageVersion) packageVersionQuery.getSingleResult();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setDeploymentConfigurationValues(packageDetails.getDeploymentTimeConfiguration());
View Full Code Here

            packageVersionQuery.setParameter("packageTypeName", key.getPackageTypeName());
            packageVersionQuery.setParameter("architectureName", key.getArchitectureName());
            packageVersionQuery.setParameter("version", key.getVersion());
            packageVersionQuery.setParameter("resourceTypeId", resourceTypeId);

            PackageVersion packageVersion = (PackageVersion) packageVersionQuery.getSingleResult();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setPackageVersion(packageVersion);
            history.setResource(resource);
            history.setTimestamp(timestamp);

            // Link the deployment configuration values that were saved for the initial history entity for this
            // package with this entity as well. This will let us show the user the configuration values on the
            // last entry in the audit trail (i.e. for a failed package, the configuration values will be accessible).
            Query deploymentConfigurationQuery = entityManager
                .createNamedQuery(InstalledPackageHistory.QUERY_FIND_CONFIG_BY_PACKAGE_VERSION_AND_REQ);
            deploymentConfigurationQuery.setParameter("packageVersion", packageVersion);
            deploymentConfigurationQuery.setParameter("contentServiceRequest", persistedRequest);
            deploymentConfigurationQuery.setMaxResults(1);

            Configuration deploymentConfiguration = null;
            List deploymentConfigurationResults = deploymentConfigurationQuery.getResultList();
            if (deploymentConfigurationResults.size() > 0) {
                deploymentConfiguration = (Configuration) deploymentConfigurationResults.get(0);
                deploymentConfiguration = deploymentConfiguration.deepCopy(false);
            }

            history.setDeploymentConfigurationValues(deploymentConfiguration);

            // If the package indicated installation steps, link them to the resulting history entry
            List<DeployPackageStep> transferObjectSteps = singleResponse.getDeploymentSteps();
            if (transferObjectSteps != null) {
                List<PackageInstallationStep> installationSteps = translateInstallationSteps(transferObjectSteps,
                    history);
                history.setInstallationSteps(installationSteps);
            }

            if (singleResponse.getResult() == ContentResponseResult.SUCCESS) {
                history.setStatus(InstalledPackageHistoryStatus.INSTALLED);
            } else {
                history.setStatus(InstalledPackageHistoryStatus.FAILED);
                history.setErrorMessage(singleResponse.getErrorMessage());
            }

            entityManager.persist(history);
            persistedRequest.addInstalledPackageHistory(history);

            // We're closing out the package request for this package version, so remove it from the cache of entries
            // that need to be closed
            inProgressEntries.remove(packageVersion);
        }

        // For any entries that were not closed, add closing entries
        for (InstalledPackageHistory unclosed : inProgressEntries.values()) {
            PackageVersion packageVersion = unclosed.getPackageVersion();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setPackageVersion(packageVersion);
View Full Code Here

        long timestamp = System.currentTimeMillis();

        for (int installedPackageId : installedPackageIds) {
            // Load the InstalledPackage to get its package version for the relationship
            InstalledPackage ip = entityManager.find(InstalledPackage.class, installedPackageId);
            PackageVersion packageVersion = ip.getPackageVersion();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setPackageVersion(packageVersion);
View Full Code Here

            packageVersionQuery.setParameter("packageTypeName", key.getPackageTypeName());
            packageVersionQuery.setParameter("architectureName", key.getArchitectureName());
            packageVersionQuery.setParameter("version", key.getVersion());
            packageVersionQuery.setParameter("resourceTypeId", resourceTypeId);

            PackageVersion packageVersion = (PackageVersion) packageVersionQuery.getSingleResult();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setPackageVersion(packageVersion);
            history.setResource(resource);
            history.setTimestamp(timestamp);

            if (singleResponse.getResult() == ContentResponseResult.SUCCESS) {
                history.setStatus(InstalledPackageHistoryStatus.DELETED);

                // We used to remove the InstalledPackage entity here, but now we'll rely on the plugin container
                // to trigger a discovery after the delete request finishes.
            } else {
                history.setStatus(InstalledPackageHistoryStatus.FAILED);
                history.setErrorMessage(singleResponse.getErrorMessage());
            }

            entityManager.persist(history);
            persistedRequest.addInstalledPackageHistory(history);

            // We're closing out the package request for this package version, so remove it from the cache of entries
            // that need to be closed
            inProgressEntries.remove(packageVersion);
        }

        // For any entries that were not closed, add closing entries
        for (InstalledPackageHistory unclosed : inProgressEntries.values()) {
            PackageVersion packageVersion = unclosed.getPackageVersion();

            // Create the history entity
            InstalledPackageHistory history = new InstalledPackageHistory();
            history.setContentServiceRequest(persistedRequest);
            history.setPackageVersion(packageVersion);
View Full Code Here

TOP

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

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.