Package org.rhq.core.domain.bundle

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


        // need a dummy deployment

        ResourceType resourceType = new ResourceType("name", "plugin", ResourceCategory.PLATFORM, null);
        Resource resource = new Resource("key", "name", resourceType);
        BundleType bundleType = new BundleType("name", resourceType);
        Bundle bundle = new Bundle("name", bundleType, null, null);
        BundleVersion bundleVersion = new BundleVersion("bname", "bversion", bundle, "");
        String name = "name";
        String destBaseDirName = "destBaseDirName";
        String installDir = "installDir";
        BundleDestination bundleDestination = new BundleDestination(bundle, "destName", new ResourceGroup("groupName"),
View Full Code Here


            assert q.getResultList().size() == 0 : "should not have repo1 mapping in the db yet";
            q.setParameter("id", repo2.getId());
            assert q.getResultList().size() == 0 : "should not have repo2 mapping in the db yet";

            BundleType bundleType = createBundleType(em, name + "-Type", createResourceType(em));
            Bundle bundle = createBundle(em, name + "-Bundle", bundleType);

            BundleVersion bundleVersion = new BundleVersion(name, "1.0.0.BETA", bundle, recipe);
            bundleVersion.setVersionOrder(0);
            em.persist(bundleVersion);
            id = bundleVersion.getId();
View Full Code Here

            String name = "BundleTest-testBundleVersion";
            String recipe = "action/script/recipe is here";

            BundleType bundleType = createBundleType(em, name + "-Type", createResourceType(em));
            Bundle bundle = createBundle(em, name + "-Bundle", bundleType);
            id = bundle.getId();
            assert id > 0;
            assert bundle.getBundleType().getId() != 0 : "bundleType should have been cascade persisted too";

            BundleVersion bv = new BundleVersion(name, "1.0.0.BETA", bundle, recipe);
            bv.setVersionOrder(777);
            Query q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", bv.getName());
            assert q.getResultList().size() == 0; // not in the db yet

            em.persist(bv);
            id = bv.getId();
            assert id > 0;

            q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", bv.getName());
            assert q.getResultList().size() == 1;
            assert ((BundleVersion) q.getSingleResult()).getName().equals(bv.getName());

            BundleVersion bvFind = em.find(BundleVersion.class, id);
            assert bvFind != null;
            assert bvFind.getId() == bv.getId();
            assert bvFind.getName().equals(bv.getName());
            assert bvFind.getVersion().equals(bv.getVersion());
            assert bvFind.getVersionOrder() == bv.getVersionOrder();
            assert bvFind.getRecipe().equals(bv.getRecipe());
            assert bvFind.getBundle().equals(bv.getBundle());
            assert bvFind.equals(bv);
            assert bvFind.hashCode() == bv.hashCode();

            // clean up - delete our test entity
            em.clear();

            q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", bv.getName());
            BundleVersion doomed = (BundleVersion) q.getSingleResult();
            doomed = em.getReference(BundleVersion.class, doomed.getId());
            em.remove(doomed);
            assert q.getResultList().size() == 0 : "didn't remove the entity";
            em.clear();

            // make sure we didn't delete the bundle - it should not be cascade deleted
            q = em.createNamedQuery(Bundle.QUERY_FIND_BY_NAME);
            q.setParameter("name", bundle.getName());
            assert q.getResultList().size() == 1;
            bundle = (Bundle) q.getSingleResult();
            bundleType = bundle.getBundleType();
            Repo repo = bundle.getRepo();
            em.remove(bundle);
            em.remove(repo);

            deleteResourceType(em, bundleType.getResourceType());
View Full Code Here

            String name = "BundleTest-testMultipleBundleVersions";
            String recipe = "action/script/recipe is here";

            BundleType bundleType = createBundleType(em, name + "-Type", createResourceType(em));
            Bundle bundle = createBundle(em, name + "-Bundle", bundleType);
            id = bundle.getId();
            assert id > 0;
            assert bundle.getBundleType().getId() != 0 : "bundleType should have been cascade persisted too";

            // make sure these queries can return empty lists
            Query q = em.createNamedQuery(BundleVersion.QUERY_FIND_LATEST_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            assert q.getResultList().size() == 0;
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_VERSION_INFO_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            assert q.getResultList().size() == 0;
            q = em.createNamedQuery(BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            q.setParameter("versionOrder", 0);
            assert q.executeUpdate() == 0 : "should not have updated anything";

            BundleVersion bv = new BundleVersion(name, "1.0", bundle, recipe);
            bv.setVersionOrder(0);
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", name);
            assert q.getResultList().size() == 0; // not in the db yet
            em.persist(bv);
            id = bv.getId();
            assert id > 0;

            BundleVersion bv2 = new BundleVersion(name, "2.0", bundle, recipe);
            bv2.setVersionOrder(1);
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", name);
            assert q.getResultList().size() == 1;
            em.persist(bv2);
            id = bv2.getId();
            assert id > 0;

            q = em.createNamedQuery(BundleVersion.QUERY_FIND_LATEST_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            assert q.getResultList().size() == 1;
            assert ((BundleVersion) q.getSingleResult()).getVersion().equals(bv2.getVersion());
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_VERSION_INFO_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            List<Object[]> versionsArrays = q.getResultList(); // returns in DESC sort order!
            assert versionsArrays.size() == 2;
            assert ((String) versionsArrays.get(0)[0]).equals(bv2.getVersion());
            assert ((Number) versionsArrays.get(0)[1]).intValue() == bv2.getVersionOrder();
            assert ((String) versionsArrays.get(1)[0]).equals(bv.getVersion());
            assert ((Number) versionsArrays.get(1)[1]).intValue() == bv.getVersionOrder();

            // increment all version orders, starting at order #1
            q = em.createNamedQuery(BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            q.setParameter("versionOrder", 1);
            assert q.executeUpdate() == 1 : "should have auto-incremented version order in one row";
            em.flush();
            em.clear();
            bv = em.find(BundleVersion.class, bv.getId());
            assert bv.getVersionOrder() == 0 : "should not have incremented version order";
            bv2 = em.find(BundleVersion.class, bv2.getId());
            assert bv2.getVersionOrder() == 2 : "didn't increment version order";

            BundleVersion bv3 = new BundleVersion(name, "1.5", bundle, recipe);
            bv3.setVersionOrder(1);
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_BY_NAME);
            q.setParameter("name", name);
            assert q.getResultList().size() == 2;
            em.persist(bv3);
            id = bv3.getId();
            assert id > 0;

            q = em.createNamedQuery(BundleVersion.QUERY_FIND_LATEST_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            assert q.getResultList().size() == 1;
            assert ((BundleVersion) q.getSingleResult()).getVersion().equals(bv2.getVersion());
            q = em.createNamedQuery(BundleVersion.QUERY_FIND_VERSION_INFO_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            versionsArrays = q.getResultList(); // returns in DESC sort order!
            assert versionsArrays.size() == 3;
            assert ((String) versionsArrays.get(0)[0]).equals(bv2.getVersion()); // 2.0
            assert ((Number) versionsArrays.get(0)[1]).intValue() == bv2.getVersionOrder();
            assert ((String) versionsArrays.get(1)[0]).equals(bv3.getVersion()); // 1.5
            assert ((Number) versionsArrays.get(1)[1]).intValue() == bv3.getVersionOrder();
            assert ((String) versionsArrays.get(2)[0]).equals(bv.getVersion()); // 1.0
            assert ((Number) versionsArrays.get(2)[1]).intValue() == bv.getVersionOrder();

            // increment all version orders, starting at order #0 - makes sure we can update >1 rows
            q = em.createNamedQuery(BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID);
            q.setParameter("bundleId", bundle.getId());
            q.setParameter("versionOrder", 0);
            assert q.executeUpdate() == 3 : "should have auto-incremented version orders";
            em.flush();
            em.clear();
            bv = em.find(BundleVersion.class, bv.getId());
View Full Code Here

            Query q = em.createNamedQuery(Bundle.QUERY_FIND_BY_NAME);
            q.setParameter("name", name);
            assert q.getResultList().size() == 0; // not in the db yet

            BundleType bundleType = createBundleType(em, name + "-Type", createResourceType(em));
            Bundle b = createBundle(em, name, bundleType);
            id = b.getId();
            assert id > 0;
            assert b.getBundleType().getId() != 0 : "bundleType should have been persisted independently";
            assert b.getRepo().getId() != 0 : "bundle's repo should have been cascade persisted with the bundle";
            assert b.getName().equals(b.getRepo().getName()) : "bundle's repo should have same name as bundle";

            q = em.createNamedQuery(Bundle.QUERY_FIND_BY_NAME);
            q.setParameter("name", name);
            assert q.getResultList().size() == 1;
            assert ((Bundle) q.getSingleResult()).getName().equals(b.getName());

            Bundle bFind = em.find(Bundle.class, id);
            assert bFind != null;
            assert bFind.getId() == b.getId();
            assert bFind.getName().equals(b.getName());
            assert bFind.getBundleType().equals(b.getBundleType());
            assert bFind.equals(b);
            assert bFind.hashCode() == b.hashCode();

            // clean up - delete our test entity
            em.clear();

            q = em.createNamedQuery(Bundle.QUERY_FIND_BY_NAME);
            q.setParameter("name", b.getName());
            Bundle doomed = (Bundle) q.getSingleResult();
            doomed = em.getReference(Bundle.class, doomed.getId());
            em.remove(doomed);
            assert q.getResultList().size() == 0 : "didn't remove the entity";
            em.clear();

            // make sure we didn't delete the bundle type - it should not be cascade deleted
View Full Code Here

                        records.add(deploymentsNode);
                    }
                }

            } else if (item instanceof Bundle) {
                Bundle bundle = (Bundle) item;

                // each bundle has two direct children - the versions and destinations folders
                TreeNode versionNode = new TreeNode(MSG.view_bundle_versions());
                versionNode.setID(bundleGroupId.toString() + "_" + bundle.getId() + "_versions");
                versionNode.setParentID(bundleGroupId.toString() + "_" + bundle.getId());
                versionNode.setName(MSG.view_bundle_versions());
                records.add(versionNode);

                TreeNode deploymentsNode = new TreeNode(MSG.view_bundle_destinations());
                deploymentsNode.setID(bundleGroupId.toString() + "_" + bundle.getId() + "_destinations");
                deploymentsNode.setParentID(bundleGroupId.toString() + "_" + bundle.getId());
                deploymentsNode.setName(MSG.view_bundle_destinations());
                records.add(deploymentsNode);

            } else if (item instanceof BundleDestination) {
                BundleDestination dest = (BundleDestination) item;
View Full Code Here

                sortValue = "\uFFFDZZZZ"; // always show this as the last folder node in the tree
            } else{
                sortValue = bundleGroup.getName();
            }
        } else if (from instanceof Bundle) {
            Bundle bundle = (Bundle) from;
            node.setIsFolder(true);
            node.setIcon("subsystems/bundle/Bundle_16.png");
            node.setID(String.valueOf(bundleGroupId) + "_" + bundle.getId());
            node.setParentID(String.valueOf(bundleGroupId));
            node.setName(StringUtility.escapeHtml(bundle.getName()));
            sortValue = bundle.getName();
        } else if (from instanceof BundleVersion) {
            BundleVersion version = (BundleVersion) from;
            node.setIsFolder(false);
            node.setIcon("subsystems/bundle/BundleVersion_16.png");
            parentID = bundleGroupId.toString() + "_" + version.getBundle().getId() + "_versions";
View Full Code Here

                        getErrorHandler().handleError(MSG.view_bundle_deploy_loadBundleFailure(), caught);
                    }

                    @Override
                    public void onSuccess(PageList<Bundle> result) {
                        final Bundle bundle = result.get(0);
                        deployment.getBundleVersion().setBundle(bundle);
                        BundleResourceDeploymentCriteria criteria = new BundleResourceDeploymentCriteria();
                        criteria.addFilterBundleDeploymentId(deployment.getId());
                        criteria.fetchResource(true);
                        criteria.fetchBundleDeployment(true);
View Full Code Here

        // Bundle's packageType
        PackageType pt = new PackageType(name, bt.getResourceType());
        pt.setCategory(PackageCategory.BUNDLE);

        Bundle bundle = new Bundle(name, bt, repo, pt);
        em.persist(bundle);
        return bundle;
    }
View Full Code Here

        // now we want to revert back to 2.5
        ResourceType resourceType = new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
        Repo repo = new Repo("test-bundle-two");
        PackageType packageType = new PackageType("test-bundle-two", resourceType);
        Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("test-bundle-two", "2.5", bundle,
            getRecipeFromFile("test-bundle-two.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle2Dest", new ResourceGroup(
            "testSimpleBundle2Group"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());

        Configuration config = new Configuration();
        String customPropName = "custom.prop";
        String customPropValue = "ABC-revert";
        String onePropName = "one.prop";
        String onePropValue = "111-revert";
        config.put(new PropertySimple(customPropName, customPropValue));
        config.put(new PropertySimple(onePropName, onePropValue));

        BundleDeployment deployment = new BundleDeployment();
        deployment.setId(789);
        deployment.setName("test bundle 2 deployment name - REVERT");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // copy the test archive file to the bundle files dir
        FileUtil.copyFile(new File("src/test/resources/test-bundle-two-archive.zip"), new File(this.bundleFilesDir,
            "test-bundle-two-archive.zip"));

        // create test.properties file in the bundle files dir
        File file1 = new File(this.bundleFilesDir, "test.properties");
        Properties props = new Properties();
        props.setProperty(customPropName, "@@" + customPropName + "@@");
        FileOutputStream outputStream = new FileOutputStream(file1);
        props.store(outputStream, "test.properties comment");
        outputStream.close();

        BundleDeployRequest request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);
        request.setRevert(true);

        BundleDeployResult results = plugin.deployBundle(request);

        assertResultsSuccess(results);

        // test that the prop was replaced in raw file test.properties
        Properties realizedProps = new Properties();
        loadProperties(realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
        assert customPropValue.equals(realizedProps.getProperty(customPropName)) : "didn't replace prop";

        // test that the archive was extracted properly. These are the files in the archive:
        // zero-file.txt (content: "zero")
        // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
        // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
        // REMOVED: three/three-file.txt <-- this existed in the upgrade, but not the original
        // ----- the following was backed up and should be reverted
        // extra/extra-file.txt

        File zeroFile = new File(this.destDir, "zero-file.txt");
        File oneFile = new File(this.destDir, "one/one-file.txt");
        File twoFile = new File(this.destDir, "two/two-file.txt");
        File threeFile = new File(this.destDir, "three/three-file.txt");
        assert zeroFile.exists() : "zero file should have been restored during revert";
        assert oneFile.exists() : "one file missing";
        assert twoFile.exists() : "two file missing";
        assert !threeFile.exists() : "three file should have been deleted during revert";

        assert readFile(zeroFile).startsWith("zero") : "bad restore of zero file";
        assert readFile(oneFile).startsWith(onePropValue);
        assert readFile(twoFile).startsWith("@@two.prop@@");

        // make sure the revert restored the backed up files
        File extraFile = new File(this.destDir, "extra/extra-file.txt");
        assert extraFile.exists() : "extra file should have been restored due to revert deployment request";
        assert readFile(extraFile).startsWith("extra") : "bad restore of extra file";

        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
        assert deploymentProps.getDeploymentId() == deployment.getId();
        assert deploymentProps.getBundleName().equals(bundle.getName());
        assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
        assert deploymentProps.getManageRootDir() == true;

        DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
        assert deploymentProps.equals(currentProps);
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.