Package org.rhq.core.domain.drift

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


            // Only use templates that have the same base dir and filters as the definition from which
            // this snapshot is coming.  Otherwise the file set does not map.
            final HashMap<String, DriftDefinitionTemplate> templatesMap = new HashMap<String, DriftDefinitionTemplate>(
                templates.size());
            DriftDefinitionComparator ddc = new DriftDefinitionComparator(CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);
            for (DriftDefinitionTemplate template : templates) {

                if (0 == ddc.compare(template.getTemplateDefinition(), wizard.getSnapshotDriftDef())) {
                    templatesMap.put(template.getName(), template);
                }
            }

            Set<String> templatesMapKeySet = templatesMap.keySet();
View Full Code Here


        assertDriftDefEquals(msg + ": template definitions do not match", expected.getTemplateDefinition(),
            actual.getTemplateDefinition());
    }

    private void assertDriftDefEquals(String msg, DriftDefinition expected, DriftDefinition actual) {
        DriftDefinitionComparator comparator = new DriftDefinitionComparator(
            BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
        assertEquals(msg, 0, comparator.compare(expected, actual));
    }
View Full Code Here

        definition.setTemplate(template);
        driftMgr.updateDriftDefinition(getOverlord(), EntityContext.forResource(resource.getId()), definition);

        // verify that the definition was created
        DriftDefinition newDef = loadDefinition(definition.getName());
        DriftDefinitionComparator comparator = new DriftDefinitionComparator(
            BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);

        HibernateDetachUtility.nullOutUninitializedFields(newDef, SerializationType.SERIALIZATION);
        assertEquals("The drift definition was not persisted correctly", 0, comparator.compare(definition, newDef));
        assertEquals("The template association was not set on the definition", template, newDef.getTemplate());
    }
View Full Code Here

                throw new IllegalArgumentException("Cannot create drift definition. The resource type " +
                        resource.getResourceType() + " does not support drift management");
            }

            // Update or add the driftDef as necessary
            DriftDefinitionComparator comparator = new DriftDefinitionComparator(
                CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);
            boolean isUpdated = false;
            for (DriftDefinition dc : resource.getDriftDefinitions()) {
                if (dc.getName().equals(driftDef.getName())) {
                    // compare the directory specs (basedir/includes-excludes filters only - if they are different, abort.
                    // you cannot update drift def that changes basedir/includes/excludes from the original.
                    // the user must delete the drift def and create a new one, as opposed to trying to update the existing one.
                    if (comparator.compare(driftDef, dc) == 0) {
                        if (dc.isPinned() && !driftDef.isPinned()) {
                            dc.setComplianceStatus(DriftComplianceStatus.IN_COMPLIANCE);
                        }
                        dc.setConfiguration(driftDef.getConfiguration().deepCopyWithoutProxies());
                        isUpdated = true;
View Full Code Here

        // note: the size of the sets are typically really small (usually between 1 and 3),
        // so iterating through them is fast.

        // look at all the configs to ensure we detect any changes to individual settings on the templates
        Set<String> existingNames = new HashSet<String>(existingPluginDriftTemplates.size());
        DriftDefinitionComparator dirComp = new DriftDefinitionComparator(CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);

        for (Iterator<DriftDefinitionTemplate> i = existingDriftTemplates.iterator(); i.hasNext();) {
            DriftDefinitionTemplate existingTemplate = i.next();

            String existingName = existingTemplate.getName();
            DriftDefinition existingDef = existingTemplate.getTemplateDefinition();
            Set<DriftDefinition> attachedDefs = existingTemplate.getDriftDefinitions();
            boolean noAttachedDefs = (null == attachedDefs || attachedDefs.isEmpty());
            boolean notPinned = !existingTemplate.isPinned();
            boolean stillDefined = false;

            // for later to determine if any existing templates are no longer defined in the plugin
            existingNames.add(existingName);

            for (DriftDefinitionTemplate newTemplate : newPluginDriftTemplates) {
                String newName = newTemplate.getName();

                // The new template existed previously. See if it has changed and if so, in what way:
                //
                // IF      the existingTemplate
                //         has no attached defs AND
                //         is not pinned
                // THEN    we can update it with impunity
                // ELSE IF the directories have not changed
                // THEN    we can update the base info fields only
                //    Note that in the latter case we update the template but we will not push the
                //    changes down to attached defs.  This is a little odd because the template and defs can
                //    get out of sync, but we don't want a plugin change to affect existing defs in case
                //    the user has made manual changes, or wants it the way it is.
                if (newName.equals(existingName)) {
                    stillDefined = true;

                    DriftDefinition newDef = newTemplate.getTemplateDefinition();
                    boolean noDirChanges = (0 == dirComp.compare(existingDef, newDef));

                    if ((noAttachedDefs && notPinned) || noDirChanges) {
                        existingTemplate.setTemplateDefinition(newDef);

                    } else {
View Full Code Here

            throw new IllegalArgumentException("Plugin-defined templates cannot be be modified");
        }
        if (!template.getName().equals(updatedTemplate.getName())) {
            throw new IllegalArgumentException("The template's name cannot be modified");
        }
        DriftDefinitionComparator comparator = new DriftDefinitionComparator(
            DriftDefinitionComparator.CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);
        if (comparator.compare(template.getTemplateDefinition(), updatedTemplate.getTemplateDefinition()) != 0) {
            throw new IllegalArgumentException("The template's base directory and filters cannot be modified");
        }

        template.setTemplateDefinition(updatedTemplate.getTemplateDefinition());
        template = entityMgr.merge(template);
View Full Code Here

    private void syncDriftDefinitions(DriftSynchronizer synchronizer, Set<Integer> resourceIds) {
        log.info("Starting server sync for drift definitions...");
        long startTime = System.currentTimeMillis();

        Map<Integer, List<DriftDefinition>> driftDefs = driftServer.getDriftDefinitions(resourceIds);
        DriftDefinitionComparator comparator = new DriftDefinitionComparator(
            BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);

        int totalDeleted = 0;
        int totalAdded = 0;
View Full Code Here

    @Override
    public List<DriftDefinition> getAddedDefinitions(int resourceId, Set<DriftDefinition> definitionsFromServer) {
        log.debug("Checking for drift definitions that need to be added for resource id " + resourceId);

        ScheduleQueue queue = driftMgr.getSchedulesQueue();
        DriftDefinitionComparator comparator = new DriftDefinitionComparator(
            BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
        List<DriftDefinition> added = new LinkedList<DriftDefinition>();

        for (DriftDefinition c : definitionsFromServer) {
            if (!queue.contains(resourceId, c, comparator)) {
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.drift.DriftDefinitionComparator

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.