Package org.rhq.core.domain.drift

Examples of org.rhq.core.domain.drift.DriftDefinition


    }

    @Test
    public void generatePinnedSnapshotFileWhenInitialVersionIsPinned() throws Exception {
        DriftDefinition driftDef = driftDefinition("initial-snapshot-pinned-test", resourceDir.getAbsolutePath());
        driftDef.setPinned(true);

        File confDir = mkdir(resourceDir, "conf");
        File serverConf = createRandomFile(confDir, "server.conf");

        scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), driftDef));
        detector.run();

        File changeSet = changeSet(driftDef.getName(), COVERAGE);
        File pinnedSnapshot = new File(changeSet.getParentFile(), "snapshot.pinned");
        List<FileEntry> entries = asList(addedFileEntry("conf/server.conf", sha256(serverConf), serverConf
            .lastModified(), serverConf.length()));

        assertTrue(changeSet.exists(), "An initial snapshot file should be generated even when it is pinned");
View Full Code Here


            + "initial snapshot should be identical");
    }

    @Test
    public void notifyServerOfRepeatChangeSet() throws Exception {
        final DriftDefinition driftDef = driftDefinition("repeat-changeset", resourceDir.getAbsolutePath());
        driftDef.setId(1);
        driftDef.setPinned(true);

        File confDir = mkdir(resourceDir, "conf");
        createRandomFile(confDir, "server1.conf");

        DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), driftDef);

        scheduleQueue.addSchedule(schedule);
        detector.run();

        // generate some drift
        createRandomFile(confDir, "server2.conf");
        schedule.resetSchedule();
        detector.run();

        File currentSnapshot = changeSet(driftDef.getName(), COVERAGE);
        String currentSnapshotHash = sha256(currentSnapshot);

        File driftChangeSet = changeSet(driftDef.getName(), DRIFT);
        String driftChangeSetHash = sha256(driftChangeSet);

        // We have to delete the previous version snapshot so that the detector will
        // run again.
        File previousSnapshot = previousSnapshot(driftDef.getName());
        previousSnapshot.delete();

        // Now do another drift detection run. This should re-detect the same drift that
        // was previously detected. It should not however, produce a new current snapshot
        // since there are no changes on the file system.
        final AtomicBoolean repeatChangeSetCalled = new AtomicBoolean(false);
        DriftClientTestStub driftClient = new DriftClientTestStub() {
            {
                setBaseDir(resourceDir);
            }

            @Override
            public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
                fail("Do not send repeat change set to server.");
            }

            @Override
            public void repeatChangeSet(int resourceId, String driftDefName, int version) {
                repeatChangeSetCalled.set(true);
                assertEquals(resourceId, resourceId(), "The resource id for the repeat change set is wrong");
                assertEquals(driftDefName, driftDef.getName(), "The drift definition name for the repeat change set "
                    + "is wrong");
                assertEquals(version, 1, "The snapshot version should not have changed since no new drift was detected");
            }
        };
View Full Code Here

    }

    @Test
    public void detectWhenResourceComesBackIntoCompliance() throws Exception {
        DriftDefinition driftDef = driftDefinition("back-into-compliance", resourceDir.getAbsolutePath());
        driftDef.setPinned(true);

        File confDir = mkdir(resourceDir, "conf");
        File serverConf = createRandomFile(confDir, "server.conf");
        String serverConfHash = sha256(serverConf);

        Headers headers = createHeaders(driftDef, COVERAGE);

        // generate the pinned snapshot which is version zero
        File pinnedSnapshot = pinnedSnapshot(driftDef.getName());
        ChangeSetWriter writer = new ChangeSetWriterImpl(pinnedSnapshot, headers);
        writer
            .write(addedFileEntry("conf/server.conf", serverConfHash, serverConf.lastModified(), serverConf.length()));
        writer.close();

        // generate the current snapshot file. we will take a shortcut here by
        // just copying the pinned snapshot. We can do this since the current
        // snapshot will be identical to the pinned snapshot after the current
        // snapshot is first generated.
        File currentSnapshot = changeSet(driftDef.getName(), COVERAGE);
        copyFile(pinnedSnapshot, currentSnapshot);

        // now generate some drift causing the resource to go out of compliance
        File newServerConf = createRandomFile(confDir, "new_server.conf");
        String newServerConfHash = sha256(newServerConf);
        assert (null != newServerConfHash);

        // do a drift detection run
        DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), driftDef);
        scheduleQueue.addSchedule(schedule);
        // this run should produce version one
        detector.run();

        // now put the resource back into compliance
        newServerConf.delete();

        // do another drift detection run but first we have to delete the
        // previous snapshot file otherwise the detection scan will not run.
        previousSnapshot(driftDef.getName()).delete();
        schedule.resetSchedule();
        // this run should produce version two
        detector.run();

        // verify that that current snapshot has been updated to reflect that
View Full Code Here

            + "once the resource has gone back into compliance.", entries, currentSnapshot);
    }

    @Test
    public void updateTimestampInfoNoDriftTest() throws Exception {
        DriftDefinition def = driftDefinition("update-timestamp-nodrift-test", resourceDir.getAbsolutePath());

        File confDir = mkdir(resourceDir, "conf");
        File server1Conf = createRandomFile(confDir, "server-1.conf");
        String server1Hash = sha256(server1Conf);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), createHeaders(def, COVERAGE));
        writer.write(addedFileEntry("conf/server-1.conf", server1Hash, -1L, -1L));
        writer.close();

        scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
        detector.run();

        // verify that no drift change set was generated
        File driftChangeSet = changeSet(def.getName(), DRIFT);
        assertFalse(driftChangeSet.exists(), "Expected no drift change set " + driftChangeSet.getPath());

        // verify that the coverage change set was updated with timestamp info, version is still 0
        File coverageChangeSet = changeSet(def.getName(), COVERAGE);
        List<FileEntry> coverageEntries = asList(addedFileEntry("conf/server-1.conf", server1Hash, server1Conf
            .lastModified(), server1Conf.length()));

        assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 0));
        assertFileEntriesMatch("The coverage change set was not updated as expected", coverageEntries,
View Full Code Here

            coverageChangeSet);
    }

    @Test
    public void updateTimestampInfoDriftTest() throws Exception {
        DriftDefinition def = driftDefinition("update-timestamp-drift-test", resourceDir.getAbsolutePath());

        File confDir = mkdir(resourceDir, "conf");
        File server1Conf = createRandomFile(confDir, "server-1.conf");
        String server1Hash = sha256(server1Conf);
        File server2Conf = createRandomFile(confDir, "server-2.conf");
        String server2Hash = sha256(server2Conf);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), createHeaders(def, COVERAGE));
        writer.write(addedFileEntry("conf/server-1.conf", server1Hash, -1L, -1L));
        writer.write(addedFileEntry("conf/server-2.conf", server2Hash, -1L, -1L));
        writer.close();

        // create some drift
        server1Conf.delete();
        confDir.delete();

        scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
        detector.run();

        File driftChangeSet = changeSet(def.getName(), DRIFT);
        List<FileEntry> driftEntries = asList(removedFileEntry("conf/server-1.conf", server1Hash));

        // verify that the drift change set was generated
        assertTrue(driftChangeSet.exists(), "Expected to find drift change set " + driftChangeSet.getPath());
        assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
        assertFileEntriesMatch("The drift change set does not match the expected values", driftEntries, driftChangeSet);

        // verify that the coverage change set was updated with timestamp info and incremented version
        File coverageChangeSet = changeSet(def.getName(), COVERAGE);
        List<FileEntry> coverageEntries = asList(addedFileEntry("conf/server-2.conf", server2Hash, server2Conf
            .lastModified(), server2Conf.length()));

        assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
        assertFileEntriesMatch("The coverage change set was not updated as expected", coverageEntries,
View Full Code Here

            "</plugin>");

        verifyDriftDefinition(descriptor, "TestServer", "test1", new AssertDriftTemplateRunnable() {
            @Override
            public void assertDriftTemplate(DriftDefinitionTemplate driftTemplate) throws Exception {
                DriftDefinition dc = new DriftDefinition(driftTemplate.getConfiguration());
                BaseDirectory basedir = dc.getBasedir();
                assertEquals(basedir.getValueContext(), BaseDirValueContext.pluginConfiguration, "Bad value context");
                assertEquals(basedir.getValueName(), "var.lib.test1", "Bad value name");
            }
        });
    }
View Full Code Here

        verifyDriftDefinition(descriptor, "TestServer", "test1", new AssertDriftTemplateRunnable() {
            @Override
            public void assertDriftTemplate(DriftDefinitionTemplate driftTemplate) throws Exception {
                Configuration config = driftTemplate.getConfiguration();
                DriftDefinition dconfig = new DriftDefinition(config);

                assertEquals(dconfig.getInterval(), 11111L);
                assertEquals(dconfig.getBasedir().getValueContext(), BaseDirValueContext.pluginConfiguration);
                assertEquals(dconfig.getBasedir().getValueName(), "var.lib.test1");

                assertNotNull(dconfig.getExcludes(), "though we have no excludes, still expect non-null empty list");
                assertEquals(dconfig.getExcludes().size(), 0);

                List<Filter> includes = dconfig.getIncludes();

                assertNotNull(includes, "Expected to find default property set for <includes>");
                assertEquals(includes.size(), 2, "Expected <includes> property list to have two property elements.");

                Filter include1 = includes.get(0);
                String path1 = include1.getPath();
                String pattern1 = include1.getPattern();

                assertNotNull(path1, "Expected to find a simple property for the path of the first <include>");
                assertEquals(path1, "ilib", "The value is wrong for the path of the first <include>");

                assertNotNull(pattern1, "Expected to find a simple property for the pattern of the first <include>");
                assertEquals(pattern1, "*.ijar", "The value is wrong for the pattern of the first <include>");

                Filter include2 = includes.get(1);
                String path2 = include2.getPath();
                String pattern2 = include2.getPattern();

                assertNotNull(path2, "Expected to find a simple property for the path of the second <include>");
                assertEquals(path2, "iconf", "The value is wrong for the path of the second <include>");

                assertNotNull(pattern2, "Expected to find a simple property for the pattern of the second <include>");
                assertEquals(pattern2, "*.ixml", "The value is wrong for the pattern of the second <include>");
            }
        });

        verifyDriftDefinition(descriptor, "TestServer", "test2", new AssertDriftTemplateRunnable() {
            @Override
            public void assertDriftTemplate(DriftDefinitionTemplate driftTemplate) throws Exception {
                Configuration config = driftTemplate.getConfiguration();
                DriftDefinition dconfig = new DriftDefinition(config);

                assertEquals(dconfig.getInterval(), 22222L);
                assertEquals(dconfig.getBasedir().getValueContext(), BaseDirValueContext.resourceConfiguration);
                assertEquals(dconfig.getBasedir().getValueName(), "var.lib.test2");

                assertNotNull(dconfig.getIncludes(), "though we have no includes, still expect non-null empty list");
                assertEquals(dconfig.getIncludes().size(), 0);

                List<Filter> excludes = dconfig.getExcludes();

                assertNotNull(excludes, "Expected to find default property set for <excludes>");
                assertEquals(excludes.size(), 2, "Expected <excludes> property list to have two property elements.");

                Filter exclude1 = excludes.get(0);
                String path1 = exclude1.getPath();
                String pattern1 = exclude1.getPattern();

                assertNotNull(path1, "Expected to find a simple property for the path of the first <exclude>");
                assertEquals(path1, "elib", "The value is wrong for the path of the first <exclude>");

                assertNotNull(pattern1, "Expected to find a simple property for the pattern of the first <exclude>");
                assertEquals(pattern1, "*.ejar", "The value is wrong for the pattern of the first <exclude>");

                Filter exclude2 = excludes.get(1);
                String path2 = exclude2.getPath();
                String pattern2 = exclude2.getPattern();

                assertNotNull(path2, "Expected to find a simple property for the path of the second <exclude>");
                assertEquals(path2, "econf", "The value is wrong for the path of the second <exclude>");

                assertNotNull(pattern2, "Expected to find a simple property for the pattern of the second <exclude>");
                assertEquals(pattern2, "*.exml", "The value is wrong for the pattern of the second <exclude>");
            }
        });

        verifyDriftDefinition(descriptor, "TestServer", "test3", new AssertDriftTemplateRunnable() {
            @Override
            public void assertDriftTemplate(DriftDefinitionTemplate driftTemplate) throws Exception {
                Configuration config = driftTemplate.getConfiguration();
                DriftDefinition dconfig = new DriftDefinition(config);

                assertEquals(dconfig.getInterval(), 33333L);
                assertEquals(dconfig.getBasedir().getValueContext(), BaseDirValueContext.measurementTrait);
                assertEquals(dconfig.getBasedir().getValueName(), "var.lib.test3");

                List<Filter> includes = dconfig.getIncludes();

                assertNotNull(includes, "Expected to find default property set for <includes>");
                assertEquals(includes.size(), 2, "Expected <includes> property list to have two property elements.");

                Filter include1 = includes.get(0);
                String path1 = include1.getPath();
                String pattern1 = include1.getPattern();

                assertNotNull(path1, "Expected to find a simple property for the path of the first <include>");
                assertEquals(path1, "ilib", "The value is wrong for the path of the first <include>");

                assertNotNull(pattern1, "Expected to find a simple property for the pattern of the first <include>");
                assertEquals(pattern1, "*.ijar", "The value is wrong for the pattern of the first <include>");

                Filter include2 = includes.get(1);
                String path2 = include2.getPath();
                String pattern2 = include2.getPattern();

                assertNotNull(path2, "Expected to find a simple property for the path of the second <include>");
                assertEquals(path2, "iconf", "The value is wrong for the path of the second <include>");

                assertNotNull(pattern2, "Expected to find a simple property for the pattern of the second <include>");
                assertEquals(pattern2, "*.ixml", "The value is wrong for the pattern of the second <include>");

                List<Filter> excludes = dconfig.getExcludes();

                assertNotNull(excludes, "Expected to find default property set for <excludes>");
                assertEquals(excludes.size(), 2, "Expected <excludes> property list to have two property elements.");

                Filter exclude1 = excludes.get(0);
                path1 = exclude1.getPath();
                pattern1 = exclude1.getPattern();

                assertNotNull(path1, "Expected to find a simple property for the path of the first <exclude>");
                assertEquals(path1, "elib", "The value is wrong for the path of the first <exclude>");

                assertNotNull(pattern1, "Expected to find a simple property for the pattern of the first <exclude>");
                assertEquals(pattern1, "*.ejar", "The value is wrong for the pattern of the first <exclude>");

                Filter exclude2 = excludes.get(1);
                path2 = exclude2.getPath();
                pattern2 = exclude2.getPattern();

                assertNotNull(path2, "Expected to find a simple property for the path of the second <exclude>");
                assertEquals(path2, "econf", "The value is wrong for the path of the second <exclude>");

                assertNotNull(pattern2, "Expected to find a simple property for the pattern of the second <exclude>");
                assertEquals(pattern2, "*.exml", "The value is wrong for the pattern of the second <exclude>");
            }
        });

        verifyDriftDefinition(descriptor, "TestServer", "test4", new AssertDriftTemplateRunnable() {
            @Override
            public void assertDriftTemplate(DriftDefinitionTemplate driftTemplate) throws Exception {
                Configuration config = driftTemplate.getConfiguration();
                DriftDefinition dconfig = new DriftDefinition(config);

                assertEquals(dconfig.getInterval(), 44444L);
                assertEquals(dconfig.getBasedir().getValueContext(), BaseDirValueContext.fileSystem);
                assertEquals(dconfig.getBasedir().getValueName(), "/wot/gorilla");

                assertNotNull(dconfig.getIncludes(), "though we have no includes, still expect non-null empty list");
                assertEquals(dconfig.getIncludes().size(), 0);

                assertNotNull(dconfig.getExcludes(), "though we have no excludes, still expect non-null empty list");
                assertEquals(dconfig.getExcludes().size(), 0);
            }
        });
    }
View Full Code Here

        newChangeSet.setDriftHandlingMode(changeSet.getDriftHandlingMode());
        newChangeSet.setCategory(changeSet.getCategory());
        newChangeSet.setDriftDefinitionId(changeSet.getDriftDefinitionId());

        if (!isTemplateChangeSet(changeSet)) {
            DriftDefinition driftDef = getDriftDef(subject, changeSet.getDriftDefinitionId());
            if (driftDef == null) {
                throw new IllegalArgumentException("Cannot persist change set. " +
                        DriftDefinition.class.getSimpleName() + " with id " + changeSet.getDriftDefinitionId() +
                        " cannot be found.");
            }
            newChangeSet.setDriftDefinitionName(driftDef.getName());
        }

        for (Drift drift : changeSet.getDrifts()) {
            MongoDBChangeSetEntry entry = new MongoDBChangeSetEntry();
            entry.setPath(drift.getPath());
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.drift.DriftDefinition

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.