Package org.rhq.core.domain.bundle

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


    @Override
    public BundleDeployResult deployBundle(final BundleDeployRequest request) {
        BundleDeployResult result = new BundleDeployResult();
        try {
            BundleResourceDeployment resourceDeployment = request.getResourceDeployment();
            BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
            BundleVersion bundleVersion = bundleDeployment.getBundleVersion();

            String recipe = bundleVersion.getRecipe();
            File recipeFile = File.createTempFile("ant-bundle-recipe", ".xml", request.getBundleFilesLocation());
            File logFile = File.createTempFile("ant-bundle-recipe", ".log", this.tmpDirectory);
            PrintWriter logFileOutput = null;
View Full Code Here


    private Properties createAntProperties(BundleDeployRequest request) {
        Properties antProps = new Properties();

        BundleResourceDeployment resourceDeployment = request.getResourceDeployment();
        BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
        int deploymentId = bundleDeployment.getId();
        String deployDir = request.getAbsoluteDestinationDirectory().getAbsolutePath();

        antProps.setProperty(DeployPropertyNames.DEPLOY_ID, Integer.toString(deploymentId));
        antProps.setProperty(DeployPropertyNames.DEPLOY_DIR, deployDir);
        antProps.setProperty(DeployPropertyNames.DEPLOY_NAME, bundleDeployment.getName());
        antProps.setProperty(DeployPropertyNames.DEPLOY_REVERT, String.valueOf(request.isRevert()));
        antProps.setProperty(DeployPropertyNames.DEPLOY_CLEAN, String.valueOf(request.isCleanDeployment()));

        // add the resource tags
        Set<Tag> tags = resourceDeployment.getResource().getTags();
        if (tags != null) {
            for (Tag tag : tags) {
                String tagPropName = getTagPropertyName(tag);
                if (tagPropName != null) {
                    antProps.setProperty(tagPropName, tag.getName());
                }
            }
        }

        // add the system info "facts"
        Map<String, String> sysFacts = SystemInfoFactory.fetchTemplateEngine().getTokens();
        for (Map.Entry<String, String> fact : sysFacts.entrySet()) {
            antProps.setProperty(fact.getKey(), fact.getValue());
        }

        // add the deployment parameter properties
        Configuration config = bundleDeployment.getConfiguration();
        if (config != null) {
            Map<String, Property> allProperties = config.getAllProperties();
            for (Map.Entry<String, Property> entry : allProperties.entrySet()) {
                String name = entry.getKey();
                Property prop = entry.getValue();
View Full Code Here

            return result;
        }

        try {
            BundleResourceDeployment resourceDeployment = request.getResourceDeployment();
            BundleDeployment bundleDeployment = resourceDeployment.getBundleDeployment();
            BundleVersion bundleVersion = bundleDeployment.getBundleVersion();
            BundleManagerProvider bundleManagerProvider = request.getBundleManagerProvider();

            // before processing the recipe, wipe the dest dir if we need to perform a clean deployment
            if (request.isCleanDeployment()) {
                File deployDir = request.getAbsoluteDestinationDirectory();
                if (deployDir.exists()) {
                    bundleManagerProvider.auditDeployment(resourceDeployment, "Cleaning Deployment", deployDir
                        .getAbsolutePath(), null, null, "The existing deployment found at ["
                        + deployDir.getAbsolutePath() + "] will be removed.", null);
                    FileUtils.purge(deployDir, true);
                }
            }

            // process the recipe
            String recipe = bundleVersion.getRecipe();
            RecipeParser parser = new RecipeParser();
            ProcessingRecipeContext recipeContext = new ProcessingRecipeContext(recipe, request
                .getPackageVersionFiles(), this.resourceContext.getSystemInformation(), request
                .getBundleFilesLocation().getAbsolutePath(), resourceDeployment, bundleManagerProvider);

            bundleManagerProvider.auditDeployment(resourceDeployment, "Configurtion Variable Replacement",
                bundleDeployment.getName(), null, null, "setting replacement variable values using ["
                    + bundleDeployment.getConfiguration().toString(true) + "]", null);
            recipeContext.setReplacementVariableValues(bundleDeployment.getConfiguration());
            recipeContext.addReplacementVariableValue(DEPLOY_DIR, request.getAbsoluteDestinationDirectory()
                .getAbsolutePath());
            recipeContext.addReplacementVariableValue(DEPLOY_ID, Integer.toString(bundleDeployment.getId()));
            recipeContext.addReplacementVariableValue(DEPLOY_NAME, bundleDeployment.getName());

            parser.setReplaceReplacementVariables(true);

            bundleManagerProvider.auditDeployment(resourceDeployment, "Parse Recipe", bundleDeployment.getName(), null,
                null, "Parsing Recipe using context [" + recipeContext + "]", null);
            parser.parseRecipe(recipeContext);
        } catch (Throwable t) {
            log.error("Failed to deploy bundle [" + request + "]", t);
            result.setErrorMessage(t);
View Full Code Here

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

        // 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";
View Full Code Here

        String onePropName = "one.prop";
        String onePropValue = "111";
        config.put(new PropertySimple(customPropName, customPropValue));
        config.put(new PropertySimple(onePropName, onePropValue));

        BundleDeployment deployment = new BundleDeployment();
        deployment.setId(123);
        deployment.setName("test bundle 2 deployment name");
        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();

        // if we are not to start clean, create some junk files that will need to be backed up and moved away
        if (startClean == false) {
            this.destDir.mkdirs();
            File junk1 = new File(this.destDir, "junk1.properties");
            Properties junkProps = new Properties();
            junkProps.setProperty("junk1", "wot gorilla?");
            FileOutputStream os = new FileOutputStream(junk1);
            junkProps.store(os, "junk1.properties comment");
            os.close();

            File junk2 = new File(this.destDir, "junksubdir" + File.separatorChar + "junk2.properties");
            junk2.getParentFile().mkdirs();
            junkProps = new Properties();
            junkProps.setProperty("junk2", "more junk");
            os = new FileOutputStream(junk2);
            junkProps.store(os, "junk2.properties comment");
            os.close();
        }

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

        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
        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");
        assert zeroFile.exists() : "zero file missing";
        assert oneFile.exists() : "one file missing";
        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

        Configuration config = new Configuration();
        String realPropValue = "ABC123";
        config.put(new PropertySimple("custom.prop1", realPropValue));

        BundleDeployment deployment = new BundleDeployment();
        deployment.setName("test bundle deployment name");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // create test file
        File file1 = new File(this.bundleFilesDir, "test.properties");
        Properties props = new Properties();
        props.setProperty("custom.prop1", "@@custom.prop1@@");
View Full Code Here

            getRecipeFromFile("test-bundle-dotdot.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle", new ResourceGroup(
            "testSimpleBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();

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

        // create test files (see bundle recipe for why these files are created)
        final String TEST1 = "test1.txt";
        File file1 = new File(this.bundleFilesDir, TEST1);
        writeFile(TEST1, file1);

        final String TEST2 = "test2.txt";
        File file2 = new File(this.bundleFilesDir, TEST2);
        writeFile(TEST2, file2);

        final String TEST3 = "test3.txt";
        File file3 = new File(this.bundleFilesDir, TEST3);
        writeFile(TEST3, file3);

        final String TEST4 = "test4.txt";
        File file4 = new File(this.bundleFilesDir, TEST4);
        writeFile(TEST4, file4);

        // ----- initial deployment -----
        BundleDeployRequest request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);
        BundleDeployResult results = plugin.deployBundle(request);
        assertResultsSuccess(results);

        // test that the files were put where we expected them to be
        File file1Dest = new File(this.destDir, "subdir/" + TEST1);
        File file2Dest = new File(this.destDir, TEST2);
        File file3Dest = new File(externalDir, TEST3);
        File file4Dest = new File(externalDir, TEST4);
        assert TEST1.equals(readFile(file1Dest)); // inside dest dir
        assert TEST2.equals(readFile(file2Dest)); // inside dest dir
        assert TEST3.equals(readFile(file3Dest)); // outside dest dir
        assert TEST4.equals(readFile(file4Dest)); // outside dest dir

        // ----- prepare to update the bundle ----
        cleanPluginDirs(); // clean everything but the dest dir - we want to keep the metadata (this should not purge ext/ dir)
        prepareBeforeTestMethod(); // prepare for our new test
        // our src files will have different content for this bundle deployment compared to the initial deployment
        writeFile(TEST1 + "update", file1);
        writeFile(TEST2 + "update", file2);
        writeFile(TEST3 + "update", file3);
        writeFile(TEST4 + "update", file4);
        // change our initial deployment files, RHQ should see the changes and back these files up
        writeFile(TEST1 + "modified", file1Dest);
        writeFile(TEST2 + "modified", file2Dest);
        writeFile(TEST3 + "modified", file3Dest);
        writeFile(TEST4 + "modified", file4Dest);

        // ----- update deployment -----
        deployment.setId(1);
        request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);
        results = plugin.deployBundle(request);
        assertResultsSuccess(results);

        // test that all files were updated
        assert (TEST1 + "update").equals(readFile(file1Dest)); // inside dest dir
        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();
        }

        File file3Backup;
        File file4Backup;
        boolean isWindows = (File.separatorChar == '\\');
        if (isWindows) {
            StringBuilder file3AbsPath = new StringBuilder(file3Dest.getAbsolutePath());
            StringBuilder file4AbsPath = new StringBuilder(file4Dest.getAbsolutePath());
            FileUtil.stripDriveLetter(file3AbsPath);
            FileUtil.stripDriveLetter(file4AbsPath);
            file3Backup = new File(backupDir, file3AbsPath.toString());
            file4Backup = new File(backupDir, file4AbsPath.toString());
        } else {
            file3Backup = new File(backupDir, file3Dest.getAbsolutePath());
            file4Backup = new File(backupDir, file4Dest.getAbsolutePath());
        }
        assert file3Backup.isFile() : "should have been backed up: " + file3Backup;
        assert file4Backup.isFile() : "should have been backed up: " + file4Backup;
        assert (TEST3 + "modified").equals(readFile(file3Backup)) : "bad backup file: " + file3Backup;
        assert (TEST4 + "modified").equals(readFile(file4Backup)) : "bad backup file: " + file4Backup;

        // ----- revert to last deployment, restoring backed up files
        deployment.setId(2);
        request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);
View Full Code Here

        BundleVersion bundleVersion = new BundleVersion("testSimpleBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle", new ResourceGroup(
            "testSimpleBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());

        BundleDeployment deployment = new BundleDeployment();
        deployment.setName("test bundle deployment name");
        deployment.setBundleVersion(bundleVersion);
        deployment.setDestination(destination);

        // create test file that will have @@ tokens for all our tags
        // note that only tags that have semantics specified will be replaced
        // our createNewBundleDeployment creates our test tags
        File file1 = new File(this.bundleFilesDir, "test.properties");
View Full Code Here

            getRecipeFromFile("test-bundle-no-manage-root-dir.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testNoManageRootDirBundle", new ResourceGroup(
            "testNoManageRootDirBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();

        BundleDeployment deployment = new BundleDeployment();
        deployment.setName("test bundle deployment name");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // create bundle test files
        File file0 = new File(this.bundleFilesDir, "zero.properties");
        Properties props = new Properties();
        props.setProperty("zero", "0");
View Full Code Here

            getRecipeFromFile("test-bundle-manage-root-dir.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testManageRootDirBundle", new ResourceGroup(
            "testManageRootDirBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();

        BundleDeployment deployment = new BundleDeployment();
        deployment.setName("test bundle deployment name");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // create bundle test files
        File file0 = new File(this.bundleFilesDir, "zero.properties");
        Properties props = new Properties();
        props.setProperty("zero", "0");
View Full Code Here

TOP

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

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.