Examples of DriftChangeSetSummary


Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

                + driftDef.getId() + ", version: " + version + "]");
            return;
        }

        DriftChangeSet<?> changeSet = changeSets.get(0);
        DriftChangeSetSummary summary = new DriftChangeSetSummary();
        summary.setCategory(changeSet.getCategory());
        // TODO ctime should come from agent
        summary.setCreatedTime(System.currentTimeMillis());
        summary.setResourceId(changeSet.getResourceId());
        summary.setDriftDefinitionName(driftDef.getName());
        summary.setDriftHandlingMode(driftDef.getDriftHandlingMode());

        for (Drift<?, ?> drift : changeSet.getDrifts()) {
            summary.addDriftPathname(drift.getPath());
        }

        notifyAlertConditionCacheManager("processRepeatChangeSet", summary);
    }
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

    @Override
    @TransactionAttribute(REQUIRES_NEW)
    public DriftChangeSetSummary saveChangeSet(Subject subject, int resourceId, File changeSetZip) throws Exception {
        authorizeOrFail(subject, resourceId, "Can not update/create drifts");
        DriftServerPluginFacet driftServerPlugin = getServerPlugin();
        DriftChangeSetSummary summary = driftServerPlugin.saveChangeSet(subject, resourceId, changeSetZip);

        if (DriftHandlingMode.plannedChanges != summary.getDriftHandlingMode()) {
            notifyAlertConditionCacheManager("saveChangeSet", summary);
        }

        DriftDefinitionCriteria criteria = new DriftDefinitionCriteria();
        criteria.setStrict(true);
        criteria.addFilterName(summary.getDriftDefinitionName());
        criteria.addFilterResourceIds(resourceId);
        criteria.clearPaging();//disable paging as the code assumes all the results will be returned.

        PageList<DriftDefinition> definitions = findDriftDefinitionsByCriteria(subject, criteria);

        if (definitions.isEmpty()) {
            log.warn("Could not find drift definition for [resourceId: " + resourceId + ", driftDefinitionName: "
                + summary.getDriftDefinitionName() + "]. Will not be able check compliance for thiis drift definition");
        } else {
            updateCompliance(subject, definitions.get(0), summary);
        }

        return summary;
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

        // a List to be populated by storeChangeSetInNewTransaction for use in ackChangeSetInNewTransaction
        List<JPADriftFile> driftFilesToRequest = new ArrayList<JPADriftFile>();
        // a 1 element array so storeChangeSetInNewTransaction can return the Headers for use in ackChangeSetInNewTransaction
        Headers[] headers = new Headers[1];

        DriftChangeSetSummary result = JPADriftServer.storeChangeSetInNewTransaction(subject, resourceId, changeSetZip,
            driftFilesToRequest, headers);

        if (null == result) {
            return null;
        }
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

    public DriftChangeSetSummary storeChangeSetInNewTransaction(Subject subject, final int resourceId,
        final File changeSetZip, final List<JPADriftFile> driftFilesToRequest, final Headers[] headers)
        throws Exception {

        final Resource resource = getResource(resourceId);
        final DriftChangeSetSummary summary = new DriftChangeSetSummary();
        final boolean storeBinaryContent = isBinaryContentStorageEnabled();

        try {
            ZipUtil.walkZipFile(changeSetZip, new ChangeSetFileVisitor() {

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

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

        }});
        driftServer.setDriftAgentService(driftAgentService);

        // We can pass null for the subject because MongoDBDriftServer currently does not
        // use the subject argument.
        DriftChangeSetSummary actualSummary = driftServer.saveChangeSet(null, resourceId, changeSetZip);

        // verify that the change set was persisted       
        List<MongoDBChangeSet> changeSets = changeSetDAO.find().asList();

        assertEquals(changeSets.size(), 1, "Expected to find one change set in the database.");
        MongoDBChangeSet actual = changeSets.get(0);

        MongoDBChangeSet expected = new MongoDBChangeSet();
        // Need to set the id to actual.id. Since ids are random, we cannot use a canned
        // value. We have to set it the same value that is in the database.
        expected.setId(actual.getId());
        expected.setDriftDefinitionId(driftDefId);
        expected.setResourceId(resourceId);
        expected.setDriftDefinitionName(driftDefName);
        expected.setCategory(COVERAGE);
        expected.setVersion(0);
        expected.setDriftHandlingMode(normal);

        MongoDBChangeSetEntry entry1 = new MongoDBChangeSetEntry("1.bin", FILE_ADDED);
        entry1.setNewFileHash(file1SHA);
        expected.add(entry1);

        MongoDBChangeSetEntry entry2 = new MongoDBChangeSetEntry("2.bin", FILE_ADDED);
        entry2.setNewFileHash(file2SHA);
        expected.add(entry2);

        String[] ignore = new String[] {"id", "objectId", "ctime"};
        assertChangeSetMatches("Failed to persist change set", expected, actual, ignore);

        DriftChangeSetSummary expectedSummary = new DriftChangeSetSummary();
        expectedSummary.setCategory(COVERAGE);
        expectedSummary.setResourceId(resourceId);
        expectedSummary.setDriftDefinitionName(driftDefName);
        expectedSummary.setCreatedTime(actual.getCtime());

        assertPropertiesMatch("The change set summary is wrong", expectedSummary, actualSummary);
    }
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

        }});
        driftServer.setDriftAgentService(driftAgentService);

        // We can pass null for the subject because MongoDBDriftServer currently does not
        // use the subject argument.
        DriftChangeSetSummary actualSummary = driftServer.saveChangeSet(null, resourceId, changeSetZip);

        // verify that the change set was persisted
        ChangeSetDAO changeSetDAO = new ChangeSetDAO(morphia, connection, "rhqtest");
        List<MongoDBChangeSet> changeSets = changeSetDAO.find().asList();

        assertEquals(changeSets.size(), 1, "Expected to find one change set in the database.");
        MongoDBChangeSet actual = changeSets.get(0);

        MongoDBChangeSet expected = new MongoDBChangeSet();
        // Need to set the id to actual.id. Since ids are random, we cannot use a canned
        // value. We have to set it the same value that is in the database.
        expected.setId(actual.getId());
        expected.setDriftDefinitionId(driftDefId);
        expected.setResourceId(resourceId);
        expected.setDriftDefinitionName(driftDefName);
        expected.setCategory(COVERAGE);
        expected.setVersion(0);
        expected.setDriftHandlingMode(normal);

        MongoDBChangeSetEntry entry1 = new MongoDBChangeSetEntry("1.bin", FILE_ADDED);
        entry1.setNewFileHash(file1SHA);
        expected.add(entry1);

        MongoDBChangeSetEntry entry2 = new MongoDBChangeSetEntry("2.bin", FILE_ADDED);
        entry2.setNewFileHash(file2SHA);
        expected.add(entry2);

        String[] ignore = new String[] {"id", "objectId", "ctime"};
        assertChangeSetMatches("Failed to persist change set", expected, actual, ignore);

        DriftChangeSetSummary expectedSummary = new DriftChangeSetSummary();
        expectedSummary.setCategory(COVERAGE);
        expectedSummary.setResourceId(resourceId);
        expectedSummary.setDriftDefinitionName(driftDefName);
        expectedSummary.setCreatedTime(actual.getCtime());

        assertPropertiesMatch("The change set summary is wrong", expectedSummary, actualSummary);
    }
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

        }});
        driftServer.setDriftAgentService(driftAgentService);

        // We can pass null for the subject because MongoDBDriftServer currently does not
        // use the subject argument.
        DriftChangeSetSummary actualSummary = driftServer.saveChangeSet(null, resourceId, changeSetZip);

        // verify that the change set was persisted
        ChangeSetDAO changeSetDAO = new ChangeSetDAO(morphia, connection, "rhqtest");
        List<MongoDBChangeSet> changeSets = changeSetDAO.find().asList();

        assertEquals(changeSets.size(), 1, "Expected to find one change set in the database.");
        MongoDBChangeSet actual = changeSets.get(0);

        MongoDBChangeSet expected = new MongoDBChangeSet();
        // Need to set the id to actual.id. Since ids are random, we cannot use a canned
        // value. We have to set it the same value that is in the database.
        expected.setId(actual.getId());
        expected.setDriftDefinitionId(driftDefId);
        expected.setResourceId(resourceId);
        expected.setDriftDefinitionName(driftDefName);
        expected.setCategory(DRIFT);
        expected.setVersion(1);
        expected.setDriftHandlingMode(normal);

        MongoDBChangeSetEntry entry1 = new MongoDBChangeSetEntry("1.bin", FILE_CHANGED);
        entry1.setOldFileHash(oldFile1SHA);
        entry1.setNewFileHash(newFile1SHA);
        expected.add(entry1);

        MongoDBChangeSetEntry entry2 = new MongoDBChangeSetEntry("2.bin", FILE_REMOVED);
        entry2.setOldFileHash(file2SHA);
        expected.add(entry2);

        String[] ignore = new String[] {"id", "objectId", "ctime"};
        assertChangeSetMatches("Failed to persist change set", expected, actual, ignore);

        DriftChangeSetSummary expectedSummary = new DriftChangeSetSummary();
        expectedSummary.setCategory(DRIFT);
        expectedSummary.setResourceId(resourceId);
        expectedSummary.setDriftDefinitionName(driftDefName);
        expectedSummary.setCreatedTime(actual.getCtime());
        expectedSummary.addDriftPathname("1.bin");
        expectedSummary.addDriftPathname("2.bin");

        assertPropertiesMatch("The change set summary is wrong", expectedSummary, actualSummary);
    }
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

    @Override
    public DriftChangeSetSummary saveChangeSet(final Subject subject, final int resourceId, final File changeSetZip)
            throws Exception {

        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());
                changeSet.setResourceId(resourceId);
                changeSet.setDriftDefinitionId(headers.getDriftDefinitionId());
                changeSet.setDriftDefinitionName(headers.getDriftDefinitionName());
                changeSet.setDriftHandlingMode(DriftHandlingMode.normal);
                changeSet.setVersion(headers.getVersion());

                summary.setCategory(headers.getType());
                summary.setResourceId(resourceId);
                summary.setDriftDefinitionName(headers.getDriftDefinitionName());
                summary.setCreatedTime(changeSet.getCtime());

                for (FileEntry fileEntry : reader) {
                    String path = FileUtil.useForwardSlash(fileEntry.getFile());
                    MongoDBChangeSetEntry entry = new MongoDBChangeSetEntry(path, fileEntry.getType());

                    switch (fileEntry.getType()) {
                        case FILE_ADDED:
                            entry.setNewFileHash(fileEntry.getNewSHA());
                            if (fileDAO.findOne(fileEntry.getNewSHA()) == null) {
                                missingContent.add(newDriftFile(fileEntry.getNewSHA()));
                            }
                            break;
                        case FILE_CHANGED:
                            entry.setOldFileHash(fileEntry.getOldSHA());
                            entry.setNewFileHash(fileEntry.getNewSHA());
                            if (fileDAO.findOne(fileEntry.getNewSHA()) == null) {
                                missingContent.add(newDriftFile(fileEntry.getNewSHA()));
                            }
                            if (fileDAO.findOne(fileEntry.getOldSHA()) == null) {
                                missingContent.add(newDriftFile(fileEntry.getNewSHA()));
                            }
                            break;
                        default: // FILE_REMOVED
                            entry.setOldFileHash(fileEntry.getOldSHA());
                            if (fileDAO.findOne(fileEntry.getOldSHA()) == null) {
                                missingContent.add(newDriftFile(fileEntry.getOldSHA()));
                            }
                    }
                    changeSet.add(entry);

                    // 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 (headers.getType() == DriftChangeSetCategory.DRIFT) {
                        summary.addDriftPathname(path);
                    }
                }

                ds.save(changeSet);
View Full Code Here

Examples of org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary

    @Override
    public boolean matches(Object providedValue, Object... extraParams) {

        if (alertConditionOperator == AlertConditionOperator.CHANGES) {
            DriftChangeSetSummary summary = (DriftChangeSetSummary) extraParams[0];

            if (summary.getCategory() == DriftChangeSetCategory.COVERAGE) {
                return false; // we never alert on coverage reports, we only alert when files have drifted from previous known states
            }

            if (driftDefNameRegex != null) {
                if (!driftDefNameRegex.matcher(summary.getDriftDefinitionName()).matches()) {
                    return false; // drift definition name did not match, our condition is false so don't alert
                }
            }

            boolean pathNameMatches;
            if (driftPathNameRegex != null) {
                pathNameMatches = false; // assume we don't match anything
                for (String pathname : summary.getDriftPathnames()) {
                    if (driftPathNameRegex.matcher(pathname).matches()) {
                        // at least one file that drifted matches our regex
                        pathNameMatches = true;
                        break;
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.