Package org.rhq.core.domain.bundle

Examples of org.rhq.core.domain.bundle.Bundle


        if (deployDir != null && (deployDir.startsWith("..") || deployDir.matches(".*[/:\\\\]\\.\\..*"))) {
            throw new IllegalArgumentException(
                "Destination directories are not allowed to have '..' parent directory path elements");
        }

        Bundle bundle = entityManager.find(Bundle.class, bundleId);
        if (null == bundle) {
            throw new IllegalArgumentException("Invalid bundleId [" + bundleId + "]");
        }

        // validate that the group exists and is a compatible group that can support bundle deployments
        ResourceGroupCriteria c = new ResourceGroupCriteria();
        c.addFilterId(groupId);
        c.addFilterBundleTargetableOnly(true);
        List<ResourceGroup> groups = resourceGroupManager.findResourceGroupsByCriteria(subject, c);
        if (null == groups || groups.isEmpty()) {
            throw new IllegalArgumentException("Invalid groupId [" + groupId
                + "]. It must be an existing compatible group whose members must be able to support bundle deployments");
        }
        ResourceGroup group = entityManager.find(ResourceGroup.class, groups.get(0).getId());

        checkDeployBundleAuthz(subject, bundle.getId(), groupId);

        // check that the resource group is compatible with the bundle type
        Set<ResourceType> targetedResourceTypes = bundle.getBundleType().getExplicitlyTargetedResourceTypes();

        if (!targetedResourceTypes.isEmpty() && !targetedResourceTypes.contains(group.getResourceType())) {
            // the bundle type defines that it explicitly targets certain resource types but the current group
            // is not of that resource type.
            throw new IllegalArgumentException("Bundle of type [" + bundle.getBundleType().getName()
                + "] is incompatible with resource type " + group.getResourceType());
        }

        // check that the destination specification is compatible with the bundle type
        String bundleType = bundle.getBundleType().getName();
        ResourceType rt = group.getResourceType();
        ResourceTypeBundleConfiguration bundleConfig = rt.getResourceTypeBundleConfiguration();
        boolean found = false;
        for (ResourceTypeBundleConfiguration.BundleDestinationSpecification spec : bundleConfig
            .getAcceptableBundleDestinationSpecifications(bundleType)) {
View Full Code Here


        criteria.addFilterBundleTypeId(Integer.valueOf(bundleTypeId));
        criteria.addFilterName(bundleName);
        criteria.clearPaging(); //disable paging as the code assumes all the results will be returned.

        PageList<Bundle> bundles = findBundlesByCriteria(subject, criteria);
        Bundle bundle;
        if (bundles.getTotalSize() == 0) {
            bundle = createBundle(subject, bundleName, bundleDescription, bundleTypeId, bundleGroupIds);
        } else {
            bundle = bundles.get(0);
        }

        //this portion is basically copied createBundleVersion, which is now deprecated and left to rot.
        if (null == bundleVersionName || "".equals(bundleVersionName.trim())) {
            throw new IllegalArgumentException("Invalid bundleVersionName: " + bundleVersionName);
        }

        checkCreateBundleVersionAuthz(subject, bundle.getId());

        // parse the recipe (validation occurs here) and get the config def and list of files
        BundleType bundleType = bundle.getBundleType();
        RecipeParseResults results;

        try {
            results = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager()
                .parseRecipe(bundleType.getName(), recipe);
View Full Code Here

        String version, String recipe) throws Exception {
        if (null == name || "".equals(name.trim())) {
            throw new IllegalArgumentException("Invalid bundleVersionName: " + name);
        }

        Bundle bundle = entityManager.find(Bundle.class, bundleId);
        if (null == bundle) {
            throw new IllegalArgumentException("Invalid bundleId: " + bundleId);
        }

        checkCreateBundleVersionAuthz(subject, bundleId);

        // parse the recipe (validation occurs here) and get the config def and list of files
        BundleType bundleType = bundle.getBundleType();
        RecipeParseResults results;

        try {
            results = BundleManagerHelper.getPluginContainer().getBundleServerPluginManager()
                .parseRecipe(bundleType.getName(), recipe);
View Full Code Here

        criteria.setStrict(true);
        criteria.addFilterBundleTypeId(bundleType.getId());
        criteria.addFilterName(bundleName);

        PageList<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, criteria);
        Bundle bundle;
        boolean isInitialVersion = (bundles.getTotalSize() == 0);

        if (!isInitialVersion && mustBeInitialVersion) {
            throw new PermissionException("This must be the initial version of a new Bundle.");
        }

        if (isInitialVersion) {
            bundle = bundleManager.createBundle(subject, bundleName, bundleDescription, bundleType.getId(),
                initialBundleGroupIds);
            createdBundle = true;
        } else {
            bundle = bundles.get(0);
            checkCreateBundleVersionAuthz(subject, bundle.getId());
            createdBundle = false;
        }

        // now create the bundle version with the bundle we either found or created
        BundleVersion bundleVersion = bundleManager.createBundleVersionInternal(bundle, name, version, description,
View Full Code Here

        // Check authorization
        checkCreateBundleVersionAuthz(subject, bundleVersion.getBundle().getId());

        // Create the PackageVersion the BundleFile is tied to.  This implicitly creates the
        // Package for the PackageVersion.
        Bundle bundle = bundleVersion.getBundle();
        PackageType packageType = bundle.getPackageType();
        architecture = (null == architecture) ? contentManager.getNoArchitecture() : architecture;
        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();
        bundleFile.setBundleVersion(bundleVersion);
View Full Code Here

        bdc.fetchDestination(true);
        BundleDeployment deployment = bundleManager.findBundleDeploymentsByCriteria(subject, bdc).get(0);

        BundleCriteria bc = new BundleCriteria();
        bc.addFilterDestinationId(deployment.getDestination().getId());
        Bundle bundle = bundleManager.findBundlesByCriteria(subject, bc).get(0);

        ResourceTypeCriteria rtc = new ResourceTypeCriteria();
        rtc.addFilterIgnored(false); // we only care about those that are not ignored
        rtc.addFilterBundleTypeId(bundle.getBundleType().getId());
        ResourceType resourceType = resourceTypeManager.findResourceTypesByCriteria(subject, rtc).get(0);
        bundle.getBundleType().setResourceType(resourceType);

        deployment.getBundleVersion().setBundle(bundle);
        deployment.getDestination().setBundle(bundle);

        resourceDeployment.setBundleDeployment(deployment);
View Full Code Here

                int numDeployments = bundleVersion.getBundleDeployments().size();
                if (0 == numDeployments) {
                    continue;
                }

                Bundle bundle = bundleVersion.getBundle();
                BundleDestinationCriteria destinationCriteria = new BundleDestinationCriteria();
                destinationCriteria.clearPaging(); //disable paging as the code assumes all the results will be returned.
                destinationCriteria.addFilterBundleId(bundle.getId());

                // get the viewable destinations and use to filter the deployments
                List<BundleDestination> destinations = findBundleDestinationsByCriteria(subject, destinationCriteria);
                List<BundleDeployment> filteredDeployments = new ArrayList<BundleDeployment>(numDeployments);
                entityManager.detach(bundleVersion); // make sure we don't persist the filtered data
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public void deleteBundle(Subject subject, int bundleId) throws Exception {
        Bundle bundle = this.entityManager.find(Bundle.class, bundleId);
        if (null == bundle) {
            return;
        }

        checkDeleteBundleAuthz(subject, bundleId);

        Query q = entityManager.createNamedQuery(BundleVersion.QUERY_FIND_BY_BUNDLE_ID);
        q.setParameter("bundleId", bundleId);
        List<BundleVersion> bvs = q.getResultList();
        for (BundleVersion bv : bvs) {
            bundleManager.deleteBundleVersion(subject, bv.getId(), false);
            entityManager.flush();
        }

        // remove bundle from any assigned bundle groups
        // wrap in new HashSet to avoid ConcurrentModificationExceptions.
        Set<BundleGroup> BundleGroupsToRemove = new HashSet<BundleGroup>(bundle.getBundleGroups());
        for (BundleGroup bg : BundleGroupsToRemove) {
            bg.removeBundle(bundle);
        }

        // we need to whack the Repo once the Bundle no longer refers to it
        Repo bundleRepo = bundle.getRepo();

        this.entityManager.remove(bundle);
        this.entityManager.flush();

        // delete the repo as overlord, this allows users without MANAGE_INVENTORY permission to delete bundles
View Full Code Here

            }

            checkAssignBundleGroupAuthz(subject, bundleGroupId, bundleIds);

            for (int bundleId : bundleIds) {
                Bundle bundle = entityManager.find(Bundle.class, bundleId);
                if (null == bundle) {
                    throw new IllegalArgumentException("Bundle does not exist for bundleId [" + bundleId + "]");
                }

                bundleGroup.addBundle(bundle);
View Full Code Here

            }

            checkUnassignBundleGroupAuthz(subject, bundleGroupId, bundleIds);

            for (int bundleId : bundleIds) {
                Bundle bundle = entityManager.find(Bundle.class, bundleId);
                if (null == bundle) {
                    throw new IllegalArgumentException("Bundle does not exist for bundleId [" + bundleId + "]");
                }

                bundleGroup.removeBundle(bundle);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.bundle.Bundle

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.