Package org.rhq.common.drift

Examples of org.rhq.common.drift.Headers


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

        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();
View Full Code Here


        assertTrue(file.exists(), "Expected to find file named " + file.getName() + " in content directory "
            + contentDir.getPath() + ". The SHA-256 hash should be used as the file name.");
    }

    Headers createHeaders(String configName, DriftChangeSetCategory type) {
        Headers headers = new Headers();
        headers.setResourceId(resourceId());
        headers.setDriftDefinitionId(0);
        headers.setDriftDefinitionName(configName);
        headers.setBasedir(resourceDir.getAbsolutePath());
        headers.setType(type);

        return headers;
    }
View Full Code Here

        String config = "changeset-exists-test";

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

        Headers headers = createHeaders(config, COVERAGE);

        ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(), headers);
        writer.write(addedFileEntry("conf/server.conf", sha256(serverConf), serverConf.lastModified(), serverConf.length()));
        writer.close();
View Full Code Here

        assertNotNull(reader.read(), "Expected to find a file entry");
    }

    Headers createHeaders(String driftDefName, DriftChangeSetCategory type) {
        Headers headers = new Headers();
        headers.setResourceId(resourceId());
        headers.setDriftDefinitionId(1);
        headers.setDriftDefinitionName(driftDefName);
        headers.setBasedir(resourceDir.getPath());
        headers.setType(type);

        return headers;
    }
View Full Code Here

    public void persistInitialChangeSetWithContentNotInDB() throws Exception {
        int driftDefId = 1;
        final String driftDefName = "saveInitialChangeSetWithContentNotInDB";
        final int resourceId = 1;

        final Headers headers = new Headers();
        headers.setBasedir(getBaseDir().getAbsolutePath());
        headers.setDriftDefinitionId(driftDefId);
        headers.setDriftDefinitionName(driftDefName);
        headers.setResourceId(resourceId);
        headers.setType(COVERAGE);
        headers.setVersion(0);

        String file1SHA = sha256("1a2b3c4d");
        String file2SHA = sha256("1a2b3c4d");

        File changeSetZip = createChangeSetZipFile(headers,
View Full Code Here

    public void persistInitialChangeSetWithContentInDB() throws Exception {
        int driftDefId = 1;
        final String driftDefName = "saveInitialChangeSetWithContentInDB";
        final int resourceId = 1;

        final Headers headers = new Headers();
        headers.setBasedir(getBaseDir().getAbsolutePath());
        headers.setDriftDefinitionId(driftDefId);
        headers.setDriftDefinitionName(driftDefName);
        headers.setResourceId(resourceId);
        headers.setType(COVERAGE);
        headers.setVersion(0);

        String file1SHA = sha256("1a2b3c4d");
        String file2SHA = sha256("1a2b3c4d");

        // store content in the database
View Full Code Here

    public void persistChangeSetWithSomeContentInDB() throws Exception {
        int driftDefId = 1;
        final String driftDefName = "saveChangeSetWithSomeContentInDB";
        final int resourceId = 1;

        final Headers headers = new Headers();
        headers.setBasedir(getBaseDir().getAbsolutePath());
        headers.setDriftDefinitionId(driftDefId);
        headers.setDriftDefinitionName(driftDefName);
        headers.setResourceId(resourceId);
        headers.setType(DRIFT);
        headers.setVersion(1);

        String oldFile1SHA = sha256("1a2b3c4d");
        String newFile1SHA = sha256("2a3b4c5d");
        String file2SHA = sha256("1a2b3c4d");
View Full Code Here

            initSchedules(child, inventoryMgr);
        }
    }

    private void syncWithServer(Resource resource, DriftDefinition driftDefinition) throws IOException {
        Headers headers = createHeaders(resource.getId(), driftDefinition);
        if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
            log.info("No snapshot found for " + toString(resource.getId(), driftDefinition)
                + ". Downloading snapshot from server");
            DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();

            DriftSnapshot snapshot = driftServer.getCurrentSnapshot(driftDefinition.getId());

            if (snapshot.getVersion() == -1) {
                // A version of -1 indicates that no change sets have been reported
                // for this definition. This can occur when a user creates a
                // drift definition while the agent is offline for example. At
                // this point we just return and allow the agent to generate the
                // initial snapshot file.
                if (log.isDebugEnabled()) {
                    log.debug("The server does not have any change sets for "
                        + toString(resource.getId(), driftDefinition) + ". An initial snapshot needs to be generated.");
                }
                return;
            }

            headers.setVersion(snapshot.getVersion());

            log.info("Preparing to write snapshot at version " + snapshot.getVersion() + " to disk for "
                + toString(resource.getId(), driftDefinition));
            File currentSnapshotFile = changeSetMgr
                .findChangeSet(resource.getId(), driftDefinition.getName(), COVERAGE);
            writeSnapshotToFile(snapshot, currentSnapshotFile, headers);

            if (driftDefinition.isPinned()) {
                log.debug(driftDefinition + " is pinned. Fetching pinned snapshot...");
                // The pinned snapshot is always the initial change set and only the initial
                // change set.
                DriftSnapshot pinnedSnapshot = driftServer.getSnapshot(driftDefinition.getId(), 0, 0);
                Headers pinnedHeaders = createHeaders(resource.getId(), driftDefinition);
                File pinnedSnapshotFile = new File(currentSnapshotFile.getParent(), DriftDetector.FILE_SNAPSHOT_PINNED);
                log.info("Preparing to write pinned snapshot to disk for "
                    + toString(resource.getId(), driftDefinition));
                writeSnapshotToFile(pinnedSnapshot, pinnedSnapshotFile, pinnedHeaders);

                if (snapshot.getVersion() > 0) {
                    // Drift was previously reported. We will fetch a snapshot of the
                    // latest change set and write that to disk so that we avoid reporting
                    // drift that has already been reported to the server.
                    DriftSnapshot deltaSnapshot = driftServer.getSnapshot(driftDefinition.getId(),
                        snapshot.getVersion(), snapshot.getVersion());
                    File deltaFile = new File(currentSnapshotFile.getParentFile(), DriftDetector.FILE_CHANGESET_DELTA);
                    Headers deltaHeaders = createHeaders(resource.getId(), driftDefinition);
                    deltaHeaders.setVersion(snapshot.getVersion());
                    deltaHeaders.setType(DRIFT);
                    writeSnapshotToFile(deltaSnapshot, deltaFile, deltaHeaders);
                }
            }
        }
    }
View Full Code Here

    @Override
    public void updateDriftDetection(int resourceId, DriftDefinition driftDef, DriftSnapshot driftSnapshot) {
        File currentSnapshot = changeSetMgr.findChangeSet(resourceId, driftDef.getName(), COVERAGE);
        File pinnedSnapshot = new File(currentSnapshot.getParentFile(), DriftDetector.FILE_SNAPSHOT_PINNED);
        Headers headers = createHeaders(resourceId, driftDef);

        try {
            writeSnapshotToFile(driftSnapshot, currentSnapshot, headers);
        } catch (IOException e) {
            log.error("An error occurred while writing snapshot file [" + currentSnapshot.getPath() + "] to disk", e);
View Full Code Here

    private String toString(int resourceId, String defName) {
        return "[resourceId: " + resourceId + ", driftDefintionName: " + defName + "]";
    }

    private Headers createHeaders(int resourceId, DriftDefinition driftDef) {
        Headers headers = new Headers();
        headers.setResourceId(resourceId);
        headers.setDriftDefinitionId(driftDef.getId());
        headers.setType(COVERAGE);
        headers.setDriftDefinitionName(driftDef.getName());
        headers.setBasedir(getAbsoluteBaseDirectory(resourceId, driftDef).getAbsolutePath());
        return headers;
    }
View Full Code Here

TOP

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

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.