Package org.rhq.common.drift

Examples of org.rhq.common.drift.ChangeSetWriter


        headers.setVersion(0);

        String file1Hash = sha256("test-1-file-1");

        File changeSet1 = new File(changeSetsDir, "changeset-1.txt");
        ChangeSetWriter writer = new ChangeSetWriterImpl(changeSet1, headers);
        writer.write(addedFileEntry("test/file-1", file1Hash, 56789L, 1024L));
        writer.close();

        File changeSet1Zip = new File(changeSetsDir, "changeset-1.zip");
        ZipUtil.zipFileOrDirectory(changeSet1, changeSet1Zip);

        assertTrue("Expected to find change set zip file: " + changeSet1Zip.getPath(), changeSet1Zip.exists());

        jpaDriftServer.storeChangeSet(overlord, newResource.getId(), changeSet1Zip);

        JPADriftChangeSetCriteria c = new JPADriftChangeSetCriteria();
        c.addFilterResourceId(newResource.getId());
        c.fetchDrifts(true);
        List<? extends DriftChangeSet<?>> changeSets = jpaDriftServer.findDriftChangeSetsByCriteria(overlord, c);
        assertEquals(1, changeSets.size());
        DriftChangeSet<?> changeSet = changeSets.get(0);
        assertEquals(0, changeSet.getVersion());
        assertEquals("Expected to find one entry in change set", 1, changeSet.getDrifts().size());

        DriftFile driftFile = jpaDriftServer.getDriftFile(overlord, file1Hash);
        assertNotNull(driftFile);
        assertEquals(DriftFileStatus.REQUESTED, driftFile.getStatus());

        // the second change set should report drift
        String modifiedFile1Hash = sha256("test-2-file-1-modified");
        headers.setType(DRIFT);
        headers.setVersion(1);
        File changeSet2 = new File(changeSetsDir, "changeset-2.txt");

        writer = new ChangeSetWriterImpl(changeSet2, headers);
        writer.write(changedFileEntry("test/file-1", file1Hash, modifiedFile1Hash, 56789L, 1024L));
        writer.close();

        File changeSet2Zip = new File(changeSetsDir, "changeset-2.zip");
        ZipUtil.zipFileOrDirectory(changeSet2, changeSet2Zip);

        assertTrue("Expected to find change set file: " + changeSet2Zip.getPath(), changeSet2Zip.exists());
View Full Code Here


    }

    private void updateDeltaSnapshot(DriftDetectionSummary summary, DriftDetectionSchedule schedule,
        List<FileEntry> deltaEntries, int newVersion, File oldSnapshot, File newSnapshot) throws IOException {

        ChangeSetWriter deltaWriter = null;

        try {
            Headers deltaHeaders = createHeaders(schedule, DRIFT, newVersion);
            File driftChangeSet = changeSetMgr.findChangeSet(schedule.getResourceId(), schedule.getDriftDefinition()
                .getName(), DRIFT);
            deltaWriter = changeSetMgr.getChangeSetWriter(driftChangeSet, deltaHeaders);

            summary.setDriftChangeSet(driftChangeSet);
            summary.setNewSnapshot(newSnapshot);
            summary.setOldSnapshot(oldSnapshot);

            for (FileEntry entry : deltaEntries) {
                deltaWriter.write(entry);
            }
        } finally {
            if (deltaWriter != null) {
                deltaWriter.close();
            }
        }
    }
View Full Code Here

    }

    private File updateCurrentSnapshot(DriftDetectionSchedule schedule, List<FileEntry> snapshotEntries, int newVersion)
        throws IOException {

        ChangeSetWriter newSnapshotWriter = null;

        try {
            Headers snapshotHeaders = createHeaders(schedule, COVERAGE, newVersion);
            File newSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(), schedule.getDriftDefinition()
                .getName(), COVERAGE);
            newSnapshotWriter = changeSetMgr.getChangeSetWriter(schedule.getResourceId(), snapshotHeaders);

            for (FileEntry entry : snapshotEntries) {
                newSnapshotWriter.write(entry);
            }
            return newSnapshot;
        } finally {
            if (null != newSnapshotWriter) {
                newSnapshotWriter.close();
            }
        }
    }
View Full Code Here

    }

    private File updatePinnedSnapshot(DriftDetectionSchedule schedule, File pinnedSnapshot,
        List<FileEntry> snapshotEntries) throws IOException {

        ChangeSetWriter newSnapshotWriter = null;

        try {
            Headers snapshotHeaders = createHeaders(schedule, COVERAGE, 0);
            newSnapshotWriter = changeSetMgr.getChangeSetWriter(pinnedSnapshot, snapshotHeaders);

            for (FileEntry entry : snapshotEntries) {
                newSnapshotWriter.write(entry);
            }

            return pinnedSnapshot;

        } finally {
            if (null != newSnapshotWriter) {
                newSnapshotWriter.close();
            }
        }
    }
View Full Code Here

        log.debug("Generating coverage change set for " + schedule);

        File snapshot = changeSetMgr.findChangeSet(schedule.getResourceId(), schedule.getDriftDefinition().getName(),
            COVERAGE);

        ChangeSetWriter writer = null;
        try {
            writer = changeSetMgr.getChangeSetWriter(snapshot, createHeaders(schedule, COVERAGE, 0));

            if (basedir.isDirectory()) {
                doDirectoryScan(schedule, driftDef, basedir, writer);
                writer.close();
                writer = null;
            }
            if (schedule.getDriftDefinition().isPinned()) {
                copyFile(snapshot, new File(snapshot.getParentFile(), FILE_SNAPSHOT_PINNED));
            }
            summary.setNewSnapshot(snapshot);
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
View Full Code Here

        String serverConfHash = sha256(serverConf);

        File changeSetDir = changeSetDir(driftDefName);
        Headers headers = createHeaders(driftDefName, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer.write(addedFileEntry("server.conf", serverConfHash, serverConf.lastModified(), serverConf.length()));
        writer.close();

        sender.setDriftFiles(driftFiles(serverConfHash));
        sender.setHeaders(headers);
        sender.run();
View Full Code Here

        File changeSetDir = changeSetDir(driftDefName);

        Headers headers = createHeaders(driftDefName, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer.write(addedFileEntry("conf/server-1.conf", server1ConfHash, server1Conf.lastModified(), server1Conf
            .length()));
        writer.write(addedFileEntry("conf/server-2.conf", server2ConfHash, server2Conf.lastModified(), server2Conf
            .length()));
        writer.close();

        sender.setDriftFiles(driftFiles(server1ConfHash, server2ConfHash));
        sender.setHeaders(headers);
        sender.run();
View Full Code Here

        File changeSetDir = changeSetDir(driftDefName);

        Headers headers = createHeaders(driftDefName, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer.write(addedFileEntry("conf/server-1.conf", server1ConfHash, server1Conf.lastModified(), server1Conf
            .length()));
        writer.write(addedFileEntry("conf/server-2.conf", server2ConfHash, server2Conf.lastModified(), server2Conf
            .length()));
        writer
            .write(addedFileEntry("lib/server-1.jar", server1JarHash, server1Jar.lastModified(), server1Jar.length()));
        writer
            .write(addedFileEntry("lib/server-2.jar", server2JarHash, server2Jar.lastModified(), server2Jar.length()));
        writer.close();

        // Note that the order of the drift files is random. When the server sends a request
        // for files we cannot assume that the files will be in any particular order.
        sender.setDriftFiles(driftFiles(server1JarHash, server2ConfHash, server2JarHash, server1ConfHash));
        sender.setHeaders(headers);
View Full Code Here

        File changeSetDir = changeSetDir(driftDefName);

        Headers headers = createHeaders(driftDefName, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer.write(addedFileEntry("conf/server-1.conf", server1ConfHash, server1Conf.lastModified(), server1Conf
            .length()));
        writer.write(addedFileEntry("conf/server-2.conf", server2ConfHash, server2Conf.lastModified(), server2Conf
            .length()));
        writer.close();

        // It is possible that the server can request a file that has been deleted since it
        // it was initially detected during drift detection.
        server1Conf.delete();
View Full Code Here

        String serverConfHash = sha256(serverConf);

        Headers headers = createHeaders(driftDefName, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer
            .write(addedFileEntry("conf/server.conf", serverConfHash, serverConf.lastModified(), serverConf.length()));
        writer.close();

        serverConf.delete();

        sender.setDriftFiles(driftFiles(serverConfHash));
        sender.setHeaders(headers);
View Full Code Here

TOP

Related Classes of org.rhq.common.drift.ChangeSetWriter

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.