Package org.rhq.core.domain.drift

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


    }

    @Override
    @TransactionAttribute(NOT_SUPPORTED)
    public void pinSnapshot(Subject subject, int driftDefId, int snapshotVersion) {
        DriftDefinition driftDef = driftManager.getDriftDefinition(subject, driftDefId);
        authorizeOrFail(subject, driftDef.getResource().getId(), "Can not update drifts");

        if (driftDef.getTemplate() != null && driftDef.getTemplate().isPinned()) {
            throw new IllegalArgumentException(("Cannot repin a definition that has been created from a pinned "
                + "template."));
        }

        driftDef.setPinned(true);
        driftManager.updateDriftDefinition(subject, driftDef);
        driftDef.getResource().setAgentSynchronizationNeeded();

        DriftSnapshotRequest snapshotRequest = new DriftSnapshotRequest(driftDefId, snapshotVersion);
        DriftSnapshot snapshot = getSnapshot(subject, snapshotRequest);

        DriftChangeSetDTO changeSet = new DriftChangeSetDTO();
        changeSet.setCategory(COVERAGE);
        changeSet.setVersion(0);
        changeSet.setDriftDefinitionId(driftDefId);
        changeSet.setDriftHandlingMode(DriftHandlingMode.normal);
        changeSet.setResourceId(driftDef.getResource().getId());

        DriftServerPluginFacet driftServerPlugin = getServerPlugin();
        try {
            driftServerPlugin.purgeByDriftDefinitionName(subject, driftDef.getResource().getId(), driftDef.getName());
            persistSnapshot(subject, snapshot, changeSet);
        } catch (Exception e) {
            throw new RuntimeException("Failed to pin snapshot", e);
        }

        try {
            AgentClient agent = agentManager.getAgentClient(subjectManager.getOverlord(), driftDef.getResource()
                .getId());
            DriftAgentService driftService = agent.getDriftAgentService();
            driftService.pinSnapshot(driftDef.getResource().getId(), driftDef.getName(), snapshot);
        } catch (Exception e) {
            log.warn("Unable to notify agent that DriftDefinition[driftDefinitionId: " + driftDefId
                + ", driftDefinitionName: " + driftDef.getName() + "] has been pinned. The agent may be down.", e);
        }
    }
View Full Code Here


        // less memory than if we had both in memory at the same time.
        final Set<File> newFiles = new HashSet<File>(1000);

        // If the basedir is still valid we need to do a directory tree scan to look for newly added files
        if (basedir.isDirectory()) {
            DriftDefinition driftDef = schedule.getDriftDefinition();
            List<Filter> includes = driftDef.getIncludes();
            List<Filter> excludes = driftDef.getExcludes();

            for (File dir : getScanDirectories(basedir, includes)) {
                forEachFile(dir, new FilterFileVisitor(basedir, includes, excludes, new FileVisitor() {
                    @Override
                    public void visit(File file) {
View Full Code Here

        }
    }

    private void generateSnapshot(DriftDetectionSummary summary) throws IOException {
        final DriftDetectionSchedule schedule = summary.getSchedule();
        final DriftDefinition driftDef = schedule.getDriftDefinition();
        final File basedir = new File(basedir(schedule.getResourceId(), driftDef));

        if (!basedir.exists()) {
            if (log.isWarnEnabled()) {
                log.warn("The base directory [" + basedir.getAbsolutePath() + "] for " + schedule + " does not "
View Full Code Here

    public void resetSchedule() {
        nextScan = -1;
    }

    public DriftDetectionSchedule copy() {
        DriftDetectionSchedule copy = new DriftDetectionSchedule(resourceId, new DriftDefinition(driftDef
            .getConfiguration().deepCopyWithoutProxies()));
        copy.driftDef.setId(driftDef.getId());
        copy.nextScan = nextScan;
        return copy;
    }
View Full Code Here

        driftMgr.setChangeSetMgr(changeSetMgr);
    }

    @Test
    public void writeChangeSetZipFileToChangeSetDirectory() throws Exception {
        final DriftDefinition config = driftDefinition("write-changeset-file", resourceDir.getAbsolutePath());
        final File changeSetDir = changeSetDir(config.getName());
        createRandomFile(changeSetDir, "changeset.txt");

        setDriftServiceCallback(new DriftServiceCallback() {
            @Override
            public void execute() {
View Full Code Here

        driftMgr.sendChangeSetToServer(detectionSummary);
    }

    @Test
    public void sendChangeSetReportInZipFile() throws Exception {
        final DriftDefinition config = driftDefinition("send-changeset-in-zip", resourceDir.getAbsolutePath());
        final File changeSetDir = changeSetDir(config.getName());
        final File changeSetFile = createRandomFile(changeSetDir, "changeset.txt");

        setDriftServiceCallback(new DriftServiceCallback() {
            @Override
            public void execute() {
View Full Code Here

        driftMgr.sendChangeSetToServer(detectionSummary);
    }

    @Test
    public void cleanUpWhenServerAcksChangeSet() throws Exception {
        DriftDefinition config = driftDefinition("clean-up-when-server-acks-changeset", resourceDir.getAbsolutePath());
        File changeSetDir = changeSetDir(config.getName());
        File snapshotFile = createRandomFile(changeSetDir, "changeset.txt");
        File previousSnapshotFile = createRandomFile(changeSetDir, "changeset.txt.previous");

        createRandomFile(changeSetDir, "changeset_" + System.currentTimeMillis() + ".zip");

        driftMgr.ackChangeSet(resourceId(), config.getName());

        assertTrue(snapshotFile.exists(), "Snapshot file should exist after server acks change set");
        assertFalse(previousSnapshotFile.exists(), "Previous version snapshot file should be deleted when server "
            + "acks change set");
        assertEquals(findChangeSetZipFiles(changeSetDir).size(), 0, "All change set zip files should be deleted when "
View Full Code Here

        assertFalse(contentZipFile.exists(), "Content zip file should be purged after server sends content ack");
    }

    @Test
    public void unschedulingDetectionRemovesScheduleFromQueue() throws Exception {
        DriftDefinition config = driftDefinition("remove-from-queue", resourceDir.getAbsolutePath());

        driftMgr.scheduleDriftDetection(resourceId(), config);
        driftMgr.scheduleDriftDetection(resourceId() + 5, driftDefinition("another-config", "."));
        driftMgr.unscheduleDriftDetection(resourceId(), config);
View Full Code Here

            + " should have been removed from the schedule queue");
    }

    @Test
    public void unschedulingDetectionRemovesDriftDefFromResourceContainer() throws Exception {
        DriftDefinition def = driftDefinition("remove-from-queue", resourceDir.getAbsolutePath());
        DriftDefinition def2 = driftDefinition("do-not-remove", resourceDir.getAbsolutePath());

        driftMgr.scheduleDriftDetection(resourceId(), def);
        driftMgr.scheduleDriftDetection(resourceId(), def2);
        driftMgr.unscheduleDriftDetection(resourceId(), def);
View Full Code Here

            asList(def2), container.getDriftDefinitions());
    }

    @Test
    public void unschedulingDetectionDeletesChangeSetDirectoryWhenScheduleIsNotActive() throws Exception {
        DriftDefinition config = driftDefinition("delete-changeset-dir", resourceDir.getAbsolutePath());
        File changeSetDir = changeSetDir(config.getName());
        File contentDir = mkdir(changeSetDir, "content");

        createRandomFile(contentDir, "my_content");
        createRandomFile(changeSetDir, "changeset.txt");
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.