Package org.rhq.core.domain.drift

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


        templateDef.setEnabled(true);
        templateDef.setDriftHandlingMode(normal);
        templateDef.setInterval(2400L);
        templateDef.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));

        final DriftDefinitionTemplate template = templateMgr.createTemplate(getOverlord(), resourceType.getId(), true,
            templateDef);

        // next create some resource level definitions
        final DriftDefinition attachedDef1 = createDefinition(template, NAME_PREFIX + "attachedDef1", true);
        final DriftDefinition attachedDef2 = createDefinition(template, NAME_PREFIX + "attachedDef2", true);
        final DriftDefinition detachedDef1 = createDefinition(template, NAME_PREFIX + "detachedDef1", false);
        final DriftDefinition detachedDef2 = createDefinition(template, NAME_PREFIX + "detachedDef2", false);

        // create some change sets
        final JPADriftChangeSet changeSet0 = new JPADriftChangeSet(resource, 0, COVERAGE, attachedDef1);

        driftFile1 = new JPADriftFile(driftFile1Hash);
        drift1 = new JPADrift(changeSet0, drift1Path, FILE_ADDED, null, driftFile1);

        final JPADriftSet driftSet0 = new JPADriftSet();
        driftSet0.addDrift(drift1);

        final JPADriftChangeSet changeSet1 = new JPADriftChangeSet(resource, 0, DRIFT, detachedDef1);

        driftFile2 = new JPADriftFile(driftFile2Hash);
        drift2 = new JPADrift(changeSet1, drift2Path, FILE_ADDED, null, driftFile2);

        final JPADriftSet driftSet1 = new JPADriftSet();
        driftSet1.addDrift(drift2);

        executeInTransaction(false, new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                em.persist(attachedDef1);
                em.persist(attachedDef2);
                em.persist(detachedDef1);
                em.persist(detachedDef2);

                em.persist(driftFile1);
                em.persist(driftFile2);

                em.persist(changeSet0);
                em.persist(driftSet0);
                changeSet0.setInitialDriftSet(driftSet0);
                em.merge(changeSet0);

                em.persist(changeSet1);
                em.persist(driftSet1);
                changeSet1.setInitialDriftSet(driftSet1);
                em.merge(changeSet1);
            }
        });

        // delete the template
        templateMgr.deleteTemplate(getOverlord(), template.getId());

        // verify that attached definitions along with their change sets have
        // been deleted
        assertNull("Change sets belonging to attached definitions should be deleted", loadChangeSet(changeSet0.getId()));
        assertNull("Attached definition " + toString(attachedDef1) + " should be deleted",
            loadDefinition(attachedDef1.getId()));
        assertNull("Attached definition " + toString(attachedDef2) + " should be deleted",
            loadDefinition(attachedDef2.getId()));

        // verify that detached definitions along with their change sets have not been deleted
        assertNotNull("Change sets belonging to detached definitions should not be deleted",
            loadChangeSet(changeSet1.getId()));
        assertDetachedDefinitionNotDeleted(detachedDef1.getId());
        assertDetachedDefinitionNotDeleted(detachedDef2.getId());

        // verify that the template itself has been deleted
        assertNull("The template " + toString(template) + " should have been deleted",
            loadTemplate(template.getName(), false));
    }
View Full Code Here


        templateDef.setDriftHandlingMode(normal);
        templateDef.setInterval(2400L);
        templateDef.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));

        // persist the template
        DriftDefinitionTemplate template = templateMgr.createTemplate(getOverlord(), resourceType.getId(), false,
            templateDef);

        // create and persist the definition
        DriftDefinition definition = template.createDefinition();
        definition.setTemplate(template);
        driftMgr.updateDriftDefinition(getOverlord(), EntityContext.forResource(resource.getId()), definition);

        // verify that the definition was created
        DriftDefinition newDef = loadDefinition(definition.getName());
View Full Code Here

        templateDef.setDriftHandlingMode(normal);
        templateDef.setInterval(2400L);
        templateDef.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));
        templateDef.setPinned(true);

        final DriftDefinitionTemplate template = templateMgr.createTemplate(getOverlord(), resourceType.getId(), true,
            templateDef);

        executeInTransaction(false, new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                EntityManager em = getEntityManager();

                em.persist(driftFile1);
                em.persist(driftFile2);
                em.persist(changeSet0);
                em.persist(driftSet);
                changeSet0.setInitialDriftSet(driftSet);
                em.merge(changeSet0);

                // setting the change set id on the template is the last and the
                // most important step in making the template pinned
                template.setChangeSetId(changeSet0.getId());
                em.merge(template);
            }
        });

        // Create and persist a resource-level definition.
        final DriftDefinition definition = template.createDefinition();
        definition.setTemplate(template);

        final AtomicBoolean agentInvoked = new AtomicBoolean(false);

        agentServiceContainer.driftService = new TestDefService() {
View Full Code Here

        templateDef.setEnabled(true);
        templateDef.setDriftHandlingMode(normal);
        templateDef.setInterval(2400L);
        templateDef.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));

        final DriftDefinitionTemplate template = templateMgr.createTemplate(getOverlord(), resourceType.getId(), true,
            templateDef);

        // First create the definition
        DriftDefinition definition = template.createDefinition();
        definition.setName(NAME_PREFIX + "unpin");
        definition.setEnabled(true);
        definition.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, "/foo/bar/test"));
        definition.setComplianceStatus(DriftComplianceStatus.OUT_OF_COMPLIANCE_DRIFT);
        definition.setInterval(1800L);
View Full Code Here

                // We call persist here because if this definition is created
                // from a pinned template, then we need to generate the initial
                // change set. And we need the definition id to pass to the
                // drift server plugin.
                entityManager.persist(driftDef);
                DriftDefinitionTemplate template = driftDef.getTemplate();
                if (template != null && template.isPinned()) {
                    DriftServerPluginFacet driftServerPlugin = getServerPlugin();
                    driftServerPlugin.copyChangeSet(subject, template.getChangeSetId(), driftDef.getId(), resourceId);
                }
            }
            resource.setAgentSynchronizationNeeded();

            AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
View Full Code Here

    private void validateTemplateForNewDef(DriftDefinition driftDef, Resource resource) {
        if (driftDef.getTemplate() == null) {
            return;
        }

        DriftDefinitionTemplate template = entityManager.find(DriftDefinitionTemplate.class,
                driftDef.getTemplate().getId());

        if (template == null) {
            throw new IllegalArgumentException("Cannot create drift definition with template " +
                    DriftDefinitionTemplate.class.getSimpleName() + "[" + driftDef.getTemplate().getName() +
                    "] that has not been saved");
        }

        if (!template.getResourceType().equals(resource.getResourceType())) {
            throw new IllegalArgumentException("Cannot create drift definition with template " +
                    DriftDefinitionTemplate.class.getSimpleName() + "[" + driftDef.getTemplate().getName() +
                    "] that is from a different resource type, " + template.getResourceType());
        }
    }
View Full Code Here

        // 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 {
                        // can't update directories for an existing template if pinned and/or having attached defs
                        log.error("Failed to update drift definition [" + newName + "] on type ["
                            + resourceType.getName()
                            + "]. It is not allowed to update directories on an existing template that is pinned "
                            + "or has attached definitions. It would invalidate pinned snapshots as the fileset "
                            + "would no longer map from template to definition.");
                    }

                    break;
                }
            }

            // If the template is no longer defined then what we do depends on whether it has attached
            // definitions. If not it can be deleted, otherwise we keep it around so the user doesn't lose
            // anything, but set it to user-defined, in essence removing it from the plugin.
            if (!stillDefined) {
                if (noAttachedDefs) {
                    entityManager.remove(existingTemplate);
                    i.remove();

                } else {
                    existingTemplate.setUserDefined(true);
                    log.warn("Plugin no longer defines drift template [" + existingTemplate.getName() + "] on type ["
                        + resourceType.getName()
                        + "]. This template has attached definitions.  To preserve the existing definitions the "
                        + " template will not be removed but is instead being set as user-defined.  The user will "
                        + " be responsible for further maintenance of this template.");
                }
View Full Code Here

            if (isUserDefined) {
                DriftManagerBean.validateDriftDefinition(definition);
            }

            ResourceType resourceType = resourceTypeMgr.getResourceTypeById(subject, resourceTypeId);
            DriftDefinitionTemplate template = new DriftDefinitionTemplate();
            template.setName(definition.getName());
            template.setDescription(definition.getDescription());
            template.setUserDefined(isUserDefined);
            template.setTemplateDefinition(definition);

            if (isDuplicateName(resourceType, template)) {
                throw new IllegalArgumentException("Drift definition template name must be unique. A template named "
                    + "[" + template.getName() + "] already exists for " + resourceType);
            }

            resourceType.addDriftDefinitionTemplate(template);
            entityMgr.persist(template);
View Full Code Here

        templateCriteria.addFilterId(templateId);
        templateCriteria.fetchDriftDefinitions(true);
        templateCriteria.setPageControl(PageControl.getSingleRowInstance());

        PageList<DriftDefinitionTemplate> templates = templateMgr.findTemplatesByCriteria(subject, templateCriteria);
        DriftDefinitionTemplate template = templates.get(0);

        DriftDefinitionCriteria criteria = new DriftDefinitionCriteria();
        criteria.addFilterTemplateId(templateId);
        criteria.fetchConfiguration(true);
        criteria.fetchResource(true);
View Full Code Here

    }

    @Override
    @TransactionAttribute
    public void createTemplateChangeSet(Subject subject, int templateId, int driftDefId, int snapshotVersion) {
        DriftDefinitionTemplate template = entityMgr.find(DriftDefinitionTemplate.class, templateId);
        DriftSnapshot snapshot = driftMgr.getSnapshot(subject, new DriftSnapshotRequest(driftDefId, snapshotVersion));

        DriftChangeSetDTO changeSetDTO = new DriftChangeSetDTO();
        changeSetDTO.setCategory(COVERAGE);
        changeSetDTO.setDriftHandlingMode(normal);
        changeSetDTO.setVersion(0);

        String newChangeSetId = driftMgr.persistSnapshot(subject, snapshot, changeSetDTO);
        template.setChangeSetId(newChangeSetId);
    }
View Full Code Here

TOP

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

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.