Package org.rhq.common.drift

Examples of org.rhq.common.drift.ChangeSetReaderImpl


                @Override
                public boolean visit(ZipEntry zipEntry, ZipInputStream stream) throws Exception {

                    JPADriftChangeSet driftChangeSet;

                    ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new InputStreamReader(stream)),
                        false);

                    // store the new change set info (not the actual blob)
                    DriftDefinition driftDef = findDriftDefinition(resource, reader.getHeaders());
                    if (driftDef == null) {
                        LOG.error("Unable to locate DriftDefinition for Resource [" + resource
                                + "]. Change set cannot be saved.");
                        return false;
                    }
                    // TODO: Commenting out the following line for now. We want to set the
                    // version to the value specified in the headers, but we may want to also
                    // validate it against the latest version we have in the database so that
                    // we can make sure that the agent is in sync with the server.
                    //
                    //int version = getChangeSetVersion(resource, config);
                    int version = reader.getHeaders().getVersion();

                    DriftChangeSetCategory category = reader.getHeaders().getType();
                    driftChangeSet = new JPADriftChangeSet(resource, version, category, driftDef);
                    entityManager.persist(driftChangeSet);

                    summary.setCategory(category);
                    summary.setResourceId(resourceId);
                    summary.setDriftDefinitionName(reader.getHeaders().getDriftDefinitionName());
                    summary.setDriftHandlingMode(driftDef.getDriftHandlingMode());
                    summary.setCreatedTime(driftChangeSet.getCtime());

                    if (version > 0) {
                        for (FileEntry entry : reader) {
                            boolean addToList = storeBinaryContent || !DriftUtil.isBinaryFile(entry.getFile());
                            JPADriftFile oldDriftFile = getDriftFile(entry.getOldSHA(), driftFilesToRequest, addToList);
                            JPADriftFile newDriftFile = getDriftFile(entry.getNewSHA(), driftFilesToRequest, addToList);

                            // TODO Figure out an efficient way to save coverage change sets.
                            // The initial/coverage change set could contain hundreds or even thousands
                            // of entries. We probably want to consider doing some kind of batch insert
                            //
                            // jsanda

                            // use a path with only forward slashing to ensure consistent paths across reports
                            String path = FileUtil.useForwardSlash(entry.getFile());
                            JPADrift drift = new JPADrift(driftChangeSet, path, entry.getType(), oldDriftFile,
                                newDriftFile);
                            entityManager.persist(drift);

                            // we are taking advantage of the fact that we know the summary is only used by the server
                            // if the change set is a DRIFT report. If its a coverage report, it is not used (we do
                            // not alert on coverage reports) - so don't waste memory by collecting all the paths
                            // when we know they aren't going to be used anyway.
                            if (category == DriftChangeSetCategory.DRIFT) {
                                summary.addDriftPathname(path);
                            }
                        }
                    } else {
                        summary.setInitialChangeSet(true);
                        JPADriftSet driftSet = new JPADriftSet();
                        for (FileEntry entry : reader) {
                            boolean addToList = storeBinaryContent || !DriftUtil.isBinaryFile(entry.getFile());
                            JPADriftFile newDriftFile = getDriftFile(entry.getNewSHA(), driftFilesToRequest, addToList);
                            String path = FileUtil.useForwardSlash(entry.getFile());
                            // A Drift always has a changeSet. Note that in this code section the changeset is
                            // always going to be set to a DriftDefinition's changeSet. But that is not always the
                            // case, it could also be set to a DriftDefinitionTemplate's changeSet.
                            driftSet.addDrift(new JPADrift(driftChangeSet, path, entry.getType(), null, newDriftFile));
                        }
                        entityManager.persist(driftSet);
                        driftChangeSet.setInitialDriftSet(driftSet);
                        entityManager.merge(driftChangeSet);
                    }

                    headers[0] = reader.getHeaders();

                    return true;
                }
            });
View Full Code Here


        if (changeSetFile == null) {
            return null;
        }

        return new ChangeSetReaderImpl(changeSetFile);
    }
View Full Code Here

        return new ChangeSetReaderImpl(changeSetFile);
    }

    @Override
    public ChangeSetReader getChangeSetReader(File changeSetFile) throws IOException {
        return new ChangeSetReaderImpl(changeSetFile);
    }
View Full Code Here

        assertFileEntriesMatch("The coverage change set was not updated as expected", coverageEntries,
            coverageChangeSet);
    }

    private void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
        ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new FileReader(changeSet)));
        Headers actual = reader.getHeaders();
        assertPropertiesMatch(expected, actual, "Headers for " + changeSet.getPath() + " do not match "
            + "expected values");
    }
View Full Code Here

            + "expected values");
    }

    private void assertFileEntriesMatch(String msg, List<FileEntry> expected, File changeSet) throws Exception {
        List<FileEntry> actual = new ArrayList<FileEntry>();
        ChangeSetReader reader = new ChangeSetReaderImpl(changeSet);

        for (FileEntry entry : reader) {
            actual.add(entry);
        }
View Full Code Here

        final DriftChangeSetSummary summary = new DriftChangeSetSummary();

        ZipUtil.walkZipFile(changeSetZip, new ZipUtil.ZipEntryVisitor() {
            @Override
            public boolean visit(ZipEntry zipEntry, ZipInputStream stream) throws Exception {
                ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new InputStreamReader(stream)));
                Headers headers = reader.getHeaders();

                List<DriftFileDTO> missingContent = new LinkedList<DriftFileDTO>();

                MongoDBChangeSet changeSet = new MongoDBChangeSet();
                changeSet.setCategory(headers.getType());
View Full Code Here

TOP

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

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.