Package org.rhq.core.domain.configuration.definition

Examples of org.rhq.core.domain.configuration.definition.PropertyDefinition


        assert bundleBasedir.getValueContext().equals(BUNDLE_BASEDIR_CONTEXT);
        assert bundleBasedir.getValueName().equals(BUNDLE_BASEDIR_VALUE);
    }

    private void assertVersion2(ResourceType resourceType) {
        PropertyDefinition prop;
        Set<String> seen = new HashSet<String>(2); // we use to this remember names of the things that we've seen

        assert resourceType.getChildSubCategories() == null;

        seen.clear();
        ConfigurationDefinition pcDef = resourceType.getPluginConfigurationDefinition();
        assert pcDef.getGroupDefinitions().size() == 2;
        for (PropertyGroupDefinition group : pcDef.getGroupDefinitions()) {
            seen.add(group.getName());
            if (group.getName().equals(CHANGED_PC_GROUP)) {
                assert group.isDefaultHidden() == CHANGED_PC_GROUP_HIDDEN;
            } else if (group.getName().equals(NEW_PC_GROUP)) {
                assert group.isDefaultHidden() == NEW_PC_GROUP_HIDDEN;
            } else {
                assert false : "Unexpected group [" + group.getName() + "]:" + group;
            }
        }
        if (seen.size() != 2) {
            assert false : "did not see what we expected to see: " + seen;
        }

        prop = pcDef.get(CHANGED_PC_PROP);
        assert prop != null;
        assert prop.getName().equals(CHANGED_PC_PROP);
        assert prop.isRequired() == CHANGED_PC_PROP_REQUIRED;
        assert prop.getPropertyGroupDefinition().getName().equals(CHANGED_PC_GROUP);
        prop = pcDef.get(NEW_PC_PROP);
        assert prop != null;
        assert prop.getName().equals(NEW_PC_PROP);
        assert prop.isRequired() == NEW_PC_PROP_REQUIRED;
        assert prop.getPropertyGroupDefinition().getName().equals(NEW_PC_GROUP);

        seen.clear();
        assert resourceType.getProcessScans().size() == 2;
        for (ProcessScan processScan : resourceType.getProcessScans()) {
            seen.add(processScan.getName());
            if (processScan.getName().equals(CHANGED_PROCESS_SCAN_NAME)) {
                assert processScan.getQuery().equals(CHANGED_PROCESS_SCAN_QUERY);
            } else if (processScan.getName().equals(NEW_PROCESS_SCAN_NAME)) {
                assert processScan.getQuery().equals(NEW_PROCESS_SCAN_QUERY);
            } else {
                assert false : "Unexpected process scan[" + processScan.getName() + "]:" + processScan;
            }
        }
        if (seen.size() != 2) {
            assert false : "did not see what we expected to see: " + seen;
        }

        seen.clear();
        assert resourceType.getOperationDefinitions().size() == 2;
        for (OperationDefinition op : resourceType.getOperationDefinitions()) {
            seen.add(op.getName());
            if (op.getName().equals(CHANGED_OP_NAME)) {
                assert op.getTimeout().intValue() == CHANGED_OP_TIMEOUT;
                assert op.getDescription().equals(CHANGED_OP_DESC);
            } else if (op.getName().equals(NEW_OP_NAME)) {
                assert op.getTimeout().intValue() == NEW_OP_TIMEOUT;
                assert op.getDescription().equals(NEW_OP_DESC);
            } else {
                assert false : "Unexpected operation [" + op.getName() + "]:" + op;
            }
        }
        if (seen.size() != 2) {
            assert false : "did not see what we expected to see: " + seen;
        }

        seen.clear();
        assert resourceType.getMetricDefinitions().size() == 3; // include built-in Availability metric
        for (MeasurementDefinition metric : resourceType.getMetricDefinitions()) {
            if (metric.getName().equals(MeasurementDefinition.AVAILABILITY_NAME)) {
                // expected, ignore
                continue;
            }

            seen.add(metric.getName());
            if (metric.getName().equals(CHANGED_METRIC_PROP)) {
                // even though our _v2 plugin set this to something different, our upgrade doesn't change it because
                // we don't want to overwrite changes a user possibly made to the defaut interval (aka metric template)
                assert metric.getDefaultInterval() == METRIC_DEFAULT_INTERVAL;
            } else if (metric.getName().equals(NEW_METRIC_PROP)) {
                assert metric.getDefaultInterval() == NEW_METRIC_DEFAULT_INTERVAL;
            } else {
                assert false : "Unexpected metric [" + metric.getName() + "]:" + metric;
            }
        }
        if (seen.size() != 2) {
            assert false : "did not see what we expected to see: " + seen;
        }

        seen.clear();
        assert resourceType.getEventDefinitions().size() == 2;
        for (EventDefinition event : resourceType.getEventDefinitions()) {
            seen.add(event.getName());
            if (event.getName().equals(CHANGED_EVENT_NAME)) {
                assert event.getDescription().equals(CHANGED_EVENT_DESC);
            } else if (event.getName().equals(NEW_EVENT_NAME)) {
                assert event.getDescription().equals(NEW_EVENT_DESC);
            } else {
                assert false : "Unexpected event [" + event.getName() + "]:" + event;
            }
        }
        if (seen.size() != 2) {
            assert false : "did not see what we expected to see: " + seen;
        }

        assert resourceType.getResourceConfigurationDefinition().getGroupDefinitions().size() == 0;
        prop = resourceType.getResourceConfigurationDefinition().get(CHANGED_RC_PROP);
        assert prop != null;
        assert prop.getName().equals(CHANGED_RC_PROP);
        assert prop.isRequired() == CHANGED_RC_PROP_REQUIRED;
        prop = resourceType.getResourceConfigurationDefinition().get(NEW_RC_PROP);
        assert prop != null;
        assert prop.getName().equals(NEW_RC_PROP);
        assert prop.isRequired() == NEW_RC_PROP_REQUIRED;

        seen.clear();
        assert resourceType.getDriftDefinitionTemplates().size() == 2;
        for (DriftDefinitionTemplate drift : resourceType.getDriftDefinitionTemplates()) {
            DriftDefinition def = drift.getTemplateDefinition();
View Full Code Here


            assert !options.getPropertyDefinitions().entrySet().isEmpty() : "No PropertyDefinitionSimple instances found.";

            PropertyDefinitionSimple locatedPropertyDefSimple = null;
            int locatedCount = 0;
            for (Map.Entry<String, PropertyDefinition> entry : options.getPropertyDefinitions().entrySet()) {
                PropertyDefinition pd = entry.getValue();
                if (pd instanceof PropertyDefinitionSimple) {
                    locatedPropertyDefSimple = (PropertyDefinitionSimple) pd;
                    locatedCount++;
                    parsedNames.remove(locatedPropertyDefSimple.getName());
                }
View Full Code Here

        if (cd==null) {
            return;
        }

        for (Map.Entry<String,PropertyDefinition> entry : cd.getPropertyDefinitions().entrySet()) {
            PropertyDefinition pd = entry.getValue();
            if (pd instanceof PropertyDefinitionSimple) {
                PropertyDefinitionSimple pds = (PropertyDefinitionSimple) pd;
                SimplePropDef prop = new SimplePropDef();
                prop.setName(pds.getName());
                prop.setRequired(pds.isRequired());
                prop.setType(pds.getType());
                prop.setDefaultValue(pds.getDefaultValue());
                definitionRest.addParam(prop);
            }
            log.debug("copyParams: " + pd.getName() + " not yet supported");
        }
    }
View Full Code Here

        } else if (resource != null) {
            baseResource = ResourceUtility.getBaseServerOrService(resource);
        }

        for (Map.Entry<String, PropertyDefinition> entry : def.getPropertyDefinitions().entrySet()) {
            PropertyDefinition pd = entry.getValue();

            if (pd instanceof PropertyDefinitionSimple) {
                PropertyDefinitionSimple pds = (PropertyDefinitionSimple) pd;
                handlePDS(subject, resource, baseResource, pds);

            } else if (pd instanceof PropertyDefinitionList) {
                PropertyDefinitionList pdl = (PropertyDefinitionList) pd;
                PropertyDefinition memberDef = pdl.getMemberDefinition();
                if (memberDef instanceof PropertyDefinitionSimple) {
                    PropertyDefinitionSimple pds = (PropertyDefinitionSimple) memberDef;
                    handlePDS(subject, resource, baseResource, pds);
                } else if (memberDef instanceof PropertyDefinitionMap) {
                    PropertyDefinitionMap pdm = (PropertyDefinitionMap) memberDef;
                    for (PropertyDefinition inner : pdm.getOrderedPropertyDefinitions()) {
                        if (inner instanceof PropertyDefinitionSimple) {
                            handlePDS(subject, resource, baseResource, (PropertyDefinitionSimple) inner);
                        }
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("3 ____[ " + inner.toString() + " in " + pdl.toString()
                                + " ]____ not yet supported");
                        }
                    }
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("2 ____[ " + memberDef.toString() + " in " + pdl.toString()
                            + " ]____ not yet supported");
                    }
                }

            } else if (pd instanceof PropertyDefinitionMap) {
View Full Code Here

            PropertyMap propertyMap = parentPropertyMap.getMap(propertyDefinition.getName());
            PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) propertyDefinition;
            maskPropertyMap(propertyMap, propertyDefinitionMap);
        } else if (propertyDefinition instanceof PropertyDefinitionList) {
            PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition;
            PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition();
            // If the property is a List of Maps, iterate the list, and recurse into each Map and mask its child
            // properties.
            if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
                PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
                PropertyList propertyList = parentPropertyMap.getList(propertyDefinition.getName());
View Full Code Here

        List<PropertyDefinition> existingPropertyDefinitions = existingDefinition.getNonGroupedProperties();
        List<PropertyDefinition> newPropertyDefinitions = newDefinition.getNonGroupedProperties();
        if (existingPropertyDefinitions != null) {
            for (PropertyDefinition newProperty : newPropertyDefinitions) {
                PropertyDefinition existingProp = existingDefinition.get(newProperty.getName());
                if (existingProp != null) {
                    log.debug("Updating nonGrouped property [" + existingProp + "]");

                    updatePropertyDefinition(existingProp, newProperty);
                    updateReport.addUpdatedPropertyDefinition(newProperty);
                } else {
                    log.debug("Adding nonGrouped property [" + newProperty + "]");

                    existingDefinition.put(newProperty);
                    updateReport.addNewPropertyDefinition(newProperty);
                }
            }

            existingDefinition = removeNoLongerUsedProperties(newDefinition, existingDefinition,
                existingPropertyDefinitions);

        } else {
            // TODO what if existingDefinitions is null?
            // we probably don't run in here, as the initial persisting is done
            // somewhere else.
        }

        /*
         * Now update / delete contained groups We need to be careful here, as groups are present in PropertyDefinition
         * as "backlink" from PropertyDefinition to group
         */
        List<PropertyGroupDefinition> existingGroups = existingDefinition.getGroupDefinitions();
        List<PropertyGroupDefinition> newGroups = newDefinition.getGroupDefinitions();

        List<PropertyGroupDefinition> toPersist = missingInFirstList(existingGroups, newGroups);
        List<PropertyGroupDefinition> toDelete = missingInFirstList(newGroups, existingGroups);
        List<PropertyGroupDefinition> toUpdate = intersection(existingGroups, newGroups);

        // delete groups no longer present
        for (PropertyGroupDefinition group : toDelete) {
            List<PropertyDefinition> groupedDefinitions = existingDefinition.getPropertiesInGroup(group.getName());

            // first look for contained stuff
            for (PropertyDefinition def : groupedDefinitions) {
                log.debug("Removing property [" + def + "] from group [" + group + "]");

                existingPropertyDefinitions.remove(def);
                existingDefinition.getPropertyDefinitions().remove(def.getName());
                def.setPropertyGroupDefinition(null);
                entityManager.remove(def);
            }

            // then remove the definition itself
            log.debug("Removing group [" + group + "]");

            existingGroups.remove(group);
            entityManager.remove(group);
        }

        // update existing groups that stay
        for (PropertyGroupDefinition group : toUpdate) {
            String groupName = group.getName();

            List<PropertyDefinition> newGroupedDefinitions = newDefinition.getPropertiesInGroup(groupName);
            for (PropertyDefinition nDef : newGroupedDefinitions) {
                PropertyDefinition existingProperty = existingDefinition.getPropertyDefinitions().get(nDef.getName());
                if (existingProperty != null) {
                    log.debug("Updating property [" + nDef + "] in group [" + group + "]");

                    updatePropertyDefinition(existingProperty, nDef);
                    updateReport.addUpdatedPropertyDefinition(nDef);
View Full Code Here

    private ConfigurationDefinition removeNoLongerUsedProperties(ConfigurationDefinition newConfigDef,
        ConfigurationDefinition existingConfigDef, List<PropertyDefinition> existingProperties) {

        List<PropertyDefinition> propDefsToDelete = new ArrayList<PropertyDefinition>();
        for (PropertyDefinition existingPropDef : existingProperties) {
            PropertyDefinition newPropDef = newConfigDef.get(existingPropDef.getName());
            if (newPropDef == null) {
                // not in new configuration
                propDefsToDelete.add(existingPropDef);
            }
        }
View Full Code Here

                    if (!newKeys.contains(existingKey)) {
                        doomedKeys.add(existingKey);
                    }
                }
                for (String doomedKey : doomedKeys) {
                    PropertyDefinition doomed = existingPropDefs.get(doomedKey);
                    existingPropDefs.remove(doomedKey);
                    entityManager.remove(entityManager.getReference(PropertyDefinition.class, doomed.getId()));
                }

                int order = 0;
                for (String key : newKeys) {
                    PropertyDefinition existingPropDef = existingPropDefs.get(key);
                    PropertyDefinition newPropDef = newPropDefs.get(key);
                    if (null == existingPropDef) {
                        newPropDef.setOrder(order++);
                        newPropDef.setParentPropertyMapDefinition((PropertyDefinitionMap) existingProperty);
                        entityManager.persist(newPropDef);
                        existingPropDefs.put(key, newPropDef);
                    } else {
                        existingPropDef.setOrder(order++);
                        updatePropertyDefinition(existingPropDef, newPropDef);
View Full Code Here

     *
     * @param exList the existing prop def list
     * @param newList the new prop def list
     */
    private void replaceListProperty(PropertyDefinitionList exList, PropertyDefinitionList newList) {
        PropertyDefinition doomedMemberDef = null;

        if (newList.getMemberDefinition() == null) {
            log.error("\n\n!! Member definition for new list property [" + newList.getName()
                + "] is null - check and fix the plugin descriptor\n");
            return;
        }

        // We did not have a member definition before (which is wrong )
        // we need to add it now
        // only remove the existing member if it is a different entity
        PropertyDefinition exListMemberDefinition = exList.getMemberDefinition();
        if (exListMemberDefinition != null && exListMemberDefinition.getId() != newList.getMemberDefinition().getId()) {
            doomedMemberDef = exListMemberDefinition;
        }

        exList.setMemberDefinition(newList.getMemberDefinition());
        exList.setMax(newList.getMax());
View Full Code Here

        Configuration conf = ccd.configuration;

        assertEquals(def.getPropertyDefinitions().size(), 1, "Unexpected number of defined properties");
        assertEquals(conf.getProperties().size(), 1, "Unexpected number of properties");

        PropertyDefinition propDef = def.get("my-name");
        Property prop = conf.get("my-name");

        assertNotNull(propDef, "Could not find the expected property definition");
        assertNotNull(prop, "Could not find the expected property");

        assertEquals(propDef.getClass(), PropertyDefinitionSimple.class, "Unexpected type of the property definition");
        assertEquals(prop.getClass(), PropertySimple.class, "Unexpecetd type of the property");

        PropertyDefinitionSimple simpleDef = (PropertyDefinitionSimple) propDef;
        PropertySimple simpleProp = (PropertySimple) prop;
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.configuration.definition.PropertyDefinition

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.