Package org.rhq.core.util.updater

Examples of org.rhq.core.util.updater.DeploymentsMetadata


        assertFalse(new File(DEPLOY_DIR, "archived-bundle-file.txt").exists(), "should not have exploded this");
        assertFalse(new File(DEPLOY_DIR, "archived-subdir/archived-file-in-subdir.properties").exists(),
            "should not have exploded this");
        assertFalse(new File(DEPLOY_DIR, "archived-subdir").isDirectory(), "should not still have the exploded dir");

        DeploymentsMetadata dm = new DeploymentsMetadata(DEPLOY_DIR);
        if (!dryRun) {
            FileHashcodeMap fhm = dm.getCurrentDeploymentFileHashcodes();
            assertFalse(fhm.containsKey("archived-bundle-file.txt"),
                "should not have metadata - this is inside the compressed zip");
            assertFalse(fhm.containsKey("archived-subdir/archived-file-in-subdir.properties"),
                "should not have metadata - this is inside the compressed zip");
            assertTrue(fhm.containsKey("file.zip"),
                String
                    .valueOf("should have metadata for this - we didn't explode it, we just have this compressed file"));

            // test that we created the zip OK. Note that our test did not do any file replacing/realization of templates
            final String[] templateVarValue = new String[1];
            final int[] entries = new int[1];
            ZipUtil.walkZipFile(new File(DEPLOY_DIR, "file.zip"), new ZipUtil.ZipEntryVisitor() {
                @Override
                public boolean visit(ZipEntry entry, ZipInputStream stream) throws Exception {
                    if (entry.getName().equals("archived-subdir/archived-file-in-subdir.properties")) {
                        Properties props = new Properties();
                        props.load(stream);
                        templateVarValue[0] = props.getProperty("templatized.variable");
                    }
                    if (!entry.isDirectory()) {
                        entries[0] = entries[0] + 1;
                    }
                    return true;
                }
            });
            assertNotNull(templateVarValue[0]);
            assertEquals(templateVarValue[0], "@@listener.port@@");
            assertEquals(entries[0], 2, String.valueOf(entries[0])); // we only counted the file entries
        } else {
            try {
                dm.getCurrentDeploymentFileHashcodes();
                fail("this was a dry run, we should not have written our metadata to the filesystem");
            } catch (Exception e) {
                // expected
            }
        }
View Full Code Here


        assertFalse(new File(DEPLOY_DIR, "archived-bundle-file.txt").exists(), "should not have exploded this");
        assertFalse(new File(DEPLOY_DIR, "archived-subdir/archived-file-in-subdir.properties").exists(),
            "should not have exploded this");
        assertFalse(new File(DEPLOY_DIR, "archived-subdir").isDirectory(), "should not still have the exploded dir");

        DeploymentsMetadata dm = new DeploymentsMetadata(DEPLOY_DIR);
        if (!dryRun) {
            FileHashcodeMap fhm = dm.getCurrentDeploymentFileHashcodes();
            assertFalse(fhm.containsKey("archived-bundle-file.txt"),
                "should not have metadata - this is inside the compressed zip");
            assertFalse(fhm.containsKey("archived-subdir/archived-file-in-subdir.properties"),
                "should not have metadata - this is inside the compressed zip");
            assertTrue(fhm.containsKey("file.zip"),
                String
                    .valueOf("should have metadata for this - we didn't explode it, we just have this compressed file"));

            // test that the file in the zip is realized
            final String[] templateVarValue = new String[1];
            final int[] entries = new int[1];
            ZipUtil.walkZipFile(new File(DEPLOY_DIR, "file.zip"), new ZipUtil.ZipEntryVisitor() {
                @Override
                public boolean visit(ZipEntry entry, ZipInputStream stream) throws Exception {
                    if (entry.getName().equals("archived-subdir/archived-file-in-subdir.properties")) {
                        Properties props = new Properties();
                        props.load(stream);
                        templateVarValue[0] = props.getProperty("templatized.variable");
                    }
                    if (!entry.isDirectory()) {
                        entries[0] = entries[0] + 1;
                    }
                    return true;
                }
            });
            assertNotNull(templateVarValue[0]);
            assertEquals(templateVarValue[0], "12345");
            assertEquals(entries[0], 2, String.valueOf(entries[0])); // we only counted the file entries
        } else {
            try {
                dm.getCurrentDeploymentFileHashcodes();
                fail("this was a dry run, we should not have written our metadata to the filesystem");
            } catch (Exception e) {
                // expected
            }
        }
View Full Code Here

                buildListeners.add(auditor);

                // Parse and execute the Ant script.
                executeDeploymentPhase(recipeFile, antProps, buildListeners, DeploymentPhase.STOP, null);
                File deployDir = request.getAbsoluteDestinationDirectory();
                DeploymentsMetadata deployMetadata = new DeploymentsMetadata(deployDir);
                DeploymentPhase installPhase = (deployMetadata.isManaged()) ? DeploymentPhase.UPGRADE
                    : DeploymentPhase.INSTALL;
                BundleAntProject project = executeDeploymentPhase(recipeFile, antProps, buildListeners, installPhase,
                    new PluginContainerHandoverTarget(request));
                executeDeploymentPhase(recipeFile, antProps, buildListeners, DeploymentPhase.START, null);
View Full Code Here

            File metadataDirectoryToPurge = null;

            // If the receipe copied file(s) outside of the deployment directory (external, raw files), they will still exist.
            // Let's get the metadata information that tells us if such files exist, and if so, remove them.
            // Since we are iterating over the manage files anyway, let's also remove the files/subdirs under the deploy directory too.
            DeploymentsMetadata metadata = new DeploymentsMetadata(deployDir);
            if (metadata.isManaged()) {
                metadataDirectoryToPurge = metadata.getMetadataDirectory();

                //as of RHQ 4.9.0, we only only support "full" and "filesAndDirectories" destination compliance modes
                //which we used to describe by boolean "manageRootDir"... Let's not use the deprecated API's but not
                // change the code too much...
                manageAllDeployDir = metadata.getCurrentDeploymentProperties().getDestinationCompliance() == DestinationComplianceMode.full;

                int totalExternalFiles = 0;
                ArrayList<String> externalDeleteSuccesses = new ArrayList<String>(0);
                ArrayList<String> externalDeleteFailures = new ArrayList<String>(0);
                FileHashcodeMap deployDirFileHashcodes = metadata.getCurrentDeploymentFileHashcodes();
                for (String filePath : deployDirFileHashcodes.keySet()) {
                    File file = new File(filePath);
                    if (file.isAbsolute()) {
                        totalExternalFiles++;
                        if (file.exists()) {
View Full Code Here

        // 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);

        // check the backup directory - note, clean flag is irrelevent when determining what should be backed up
        File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
        File ignoredBackupFile = new File(backupDir, "ignore/ignore-file.txt");
        assert ignoredBackupFile.isFile() : "old recipe didn't ignore these, should be backed up";

        DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(789);
        assert previousProps != null : "There should be previous deployment metadata";
        assert previousProps.getDeploymentId() == 456 : "bad previous deployment metadata"; // testAntBundleUpgrade used 456
        assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
        assert previousProps.getBundleVersion().equals("3.0"); // testAntBundleUpgrade deployed version 3.0
    }
View Full Code Here

        assert twoFile.exists() : "two file missing";
        assert readFile(zeroFile).startsWith("zero");
        assert readFile(oneFile).startsWith(onePropValue);
        assert readFile(twoFile).startsWith("@@two.prop@@");

        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);
        DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(deployment.getId());
        assert previousProps == null : "There should not be any previous deployment metadata";
    }
View Full Code Here

        assert (TEST2 + "update").equals(readFile(file2Dest)); // inside dest dir
        assert (TEST3 + "update").equals(readFile(file3Dest)); // outside dest dir
        assert (TEST4 + "update").equals(readFile(file4Dest)); // outside dest dir

        // test that our changed files that were under dest dir were properly backed up
        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
        File file1Backup = new File(backupDir, "subdir/" + TEST1);
        File file2Backup = new File(backupDir, TEST2);
        assert file1Backup.isFile() : "should have been backed up: " + file1Backup;
        assert file2Backup.isFile() : "should have been backed up: " + file2Backup;
        assert (TEST1 + "modified").equals(readFile(file1Backup)) : "bad backup file: " + file1Backup;
        assert (TEST2 + "modified").equals(readFile(file2Backup)) : "bad backup file: " + file2Backup;

        // test that our changed files that were above dest dir were properly backed up
        Map<String, File> winDirs = metadata.getDeploymentExternalBackupDirectoriesForWindows(deployment.getId());
        if (winDirs == null) {
            // we are running on non-windows platform
            backupDir = metadata.getDeploymentExternalBackupDirectory(deployment.getId());
        } else {
            // we are on windows, our test only uses a single drive root, so we can grab the only item in the map
            assert winDirs.size() == 1 : "should only have 1 ext backup dir on windows: " + winDirs;
            backupDir = winDirs.values().iterator().next().getAbsoluteFile();
        }
View Full Code Here

        loadProperties(props, new FileInputStream(new File(this.destDir, "subdir1/one.properties")));
        assert "1".equals(props.getProperty("one")) : "did not deploy bundle correctly 1";
        loadProperties(props, new FileInputStream(new File(this.destDir, "subdir2/two.properties")));
        assert "2".equals(props.getProperty("two")) : "did not deploy bundle correctly 2";

        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        assert metadata.isManaged() == true : "missing metadata directory";
        assert metadata.getCurrentDeploymentProperties().getManageRootDir() == false : "should not be managing root dir";

        // make sure our unmanaged files/directories weren't removed
        props.clear();
        loadProperties(props, new FileInputStream(new File(this.destDir, "external1.properties")));
        assert "1".equals(props.getProperty("external1")) : "bundle deployment removed our unmanaged file 1";
        loadProperties(props, new FileInputStream(new File(this.destDir, "extdir/external2.properties")));
        assert "2".equals(props.getProperty("external2")) : "bundle deployment removed our unmanaged file 2";

        // make sure that extra file that was underneath the dest dir was removed
        assert !extraSubdirFile.exists() : "the extra file in subdir1 was not removed during initial deploy";

        // now purge the bundle - this should only purge those files that were laid down by the bundle plus the metadata directory
        BundlePurgeRequest purgeRequest = new BundlePurgeRequest();
        purgeRequest.setLiveResourceDeployment(createNewBundleDeployment(deployment));
        purgeRequest.setBundleManagerProvider(new MockBundleManagerProvider());
        purgeRequest.setAbsoluteDestinationDirectory(this.destDir);

        BundlePurgeResult purgeResults = plugin.purgeBundle(purgeRequest);
        assertResultsSuccess(purgeResults);

        // make sure our bundle files have been completely purged; the metadata directory should have been purged too
        assert new File(this.destDir, "zero.properties").exists() == false;
        assert new File(this.destDir, "subdir1/one.properties").exists() == false;
        assert new File(this.destDir, "subdir2/two.properties").exists() == false;
        assert new File(this.destDir, "subdir1").exists() == false;
        assert new File(this.destDir, "subdir2").exists() == false;
        assert this.destDir.exists() == true : "deploy dir should still exist, we were told not to fully manage it";

        metadata = new DeploymentsMetadata(this.destDir);
        assert metadata.getMetadataDirectory().exists() == false : "metadata directory should not exist";

        // make sure our external, unmanaged files still exist - the purge should not have deleted these
        props.clear();
        loadProperties(props, new FileInputStream(new File(this.destDir, "external1.properties")));
        assert "1".equals(props.getProperty("external1")) : "bundle purge removed our unmanaged file 1";
View Full Code Here

        loadProperties(props, new FileInputStream(new File(this.destDir, "subdir1/one.properties")));
        assert "1".equals(props.getProperty("one")) : "did not deploy bundle correctly 1";
        loadProperties(props, new FileInputStream(new File(this.destDir, "subdir2/two.properties")));
        assert "2".equals(props.getProperty("two")) : "did not deploy bundle correctly 2";

        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        assert metadata.isManaged() == true : "missing metadata directory";
        assert metadata.getCurrentDeploymentProperties().getManageRootDir() == true : "should be managing root dir";

        // make sure our external files/directories were removed because
        // they aren't part of the bundle and we are fully managing the dest dir
        props.clear();
        try {
            loadProperties(props, new FileInputStream(new File(this.destDir, "external1.properties")));
            assert false : "bundle deployment did not remove our managed file 1";
        } catch (Exception ok) {
        }
        try {
            loadProperties(props, new FileInputStream(new File(this.destDir, "extdir/external2.properties")));
            assert false : "bundle deployment did not remove our managed file 2";
        } catch (Exception ok) {
        }

        // now purge the bundle - this should purge everything in the deploy dir because we are fully managing it
        BundlePurgeRequest purgeRequest = new BundlePurgeRequest();
        purgeRequest.setLiveResourceDeployment(createNewBundleDeployment(deployment));
        purgeRequest.setBundleManagerProvider(new MockBundleManagerProvider());
        purgeRequest.setAbsoluteDestinationDirectory(this.destDir);

        BundlePurgeResult purgeResults = plugin.purgeBundle(purgeRequest);
        assertResultsSuccess(purgeResults);

        // make sure our bundle files have been completely purged; the metadata directory should have been purged too
        assert new File(this.destDir, "zero.properties").exists() == false;
        assert new File(this.destDir, "subdir1/one.properties").exists() == false;
        assert new File(this.destDir, "subdir2/two.properties").exists() == false;
        assert new File(this.destDir, "subdir1").exists() == false;
        assert new File(this.destDir, "subdir2").exists() == false;
        assert this.destDir.exists() == false : "deploy dir should not exist, we were told to fully manage it";

        metadata = new DeploymentsMetadata(this.destDir);
        assert metadata.getMetadataDirectory().exists() == false : "metadata directory should not exist";
    }
View Full Code Here

        }
        assert readFile(oneFile).startsWith(onePropValue);
        assert readFile(twoFile).startsWith("@@two.prop@@");
        assert readFile(threeFile).startsWith(threePropValue);

        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);

        // check the backup directory - note, clean flag is irrelevent when determining what should be backed up
        File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
        File extraBackupFile = new File(backupDir, extraDir.getName() + File.separatorChar + extraFile.getName());
        File ignoredBackupFile = new File(backupDir, ignoreDir.getName() + File.separatorChar + ignoredFile.getName());
        assert !ignoredBackupFile.exists() : "ignored file was backed up but it should not have been";
        assert extraBackupFile.exists() : "extra file was not backed up";
        assert "extra".equals(new String(StreamUtil.slurp(new FileInputStream(extraBackupFile)))) : "bad backup of extra";

        DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(456);
        assert previousProps != null : "There should be previous deployment metadata";
        assert previousProps.getDeploymentId() == 123 : "bad previous deployment metadata"; // testAntBundleInitialInstall used 123
        assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
        assert previousProps.getBundleVersion().equals("2.5"); // testAntBundleInitialInstall deployed version 2.5
        assert previousProps.getManageRootDir() == true;
View Full Code Here

TOP

Related Classes of org.rhq.core.util.updater.DeploymentsMetadata

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.