@Override public void configure(Configuration importConfiguration) { this.importConfiguration = importConfiguration; if (importConfiguration == null) { this.importConfiguration = getImportConfigurationDefinition().getDefaultTemplate().getConfiguration(); } }
public void setPropertyDefinitions(Map<String, PropertyDefinition> propertyDefinitions) { if (this.propertyDefinitions == propertyDefinitions) { return; } // Don't replace the possible Hibernate proxy when orphanRemoval=true. It can cause // "collection with cascade=all-delete-orphan was no longer referenced" exceptions. this.propertyDefinitions = getPropertyDefinitions(); this.propertyDefinitions.clear(); if (null != propertyDefinitions) { this.propertyDefinitions.putAll(propertyDefinitions); } }
static ConfigurationDefinition copyConfigurationDefinition(ConfigurationDefinition configurationDefinition) { ConfigurationDefinition configDefCopy = new ConfigurationDefinition(configurationDefinition.getName(), configurationDefinition.getDescription()); configDefCopy.setConfigurationFormat(configurationDefinition.getConfigurationFormat()); configDefCopy.setPropertyDefinitions(new HashMap<String, PropertyDefinition>(configurationDefinition .getPropertyDefinitions())); return configDefCopy; }
private static Collection<PropertyDefinition> getPropertyDefinitions( ConfigurationDefinition configurationDefinition, String groupName) { return (groupName != null) ? configurationDefinition.getPropertiesInGroup(groupName) : configurationDefinition .getNonGroupedProperties(); } }
@Override public Configuration getConfigurationFromDefaultTemplate(ConfigurationDefinition definition) { ConfigurationDefinition managedDefinition = entityManager.find(ConfigurationDefinition.class, definition.getId()); Configuration configuration = managedDefinition.getDefaultTemplate().getConfiguration(); ConfigurationMaskingUtility.maskConfiguration(configuration, managedDefinition); return configuration; }
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 + "]"); existingDefinition.put(newProperty); updateReport.addNewPropertyDefinition(newProperty); List<PropertyGroupDefinition> existingGroups = existingDefinition.getGroupDefinitions(); List<PropertyGroupDefinition> newGroups = newDefinition.getGroupDefinitions(); List<PropertyDefinition> groupedDefinitions = existingDefinition.getPropertiesInGroup(group.getName()); existingDefinition.getPropertyDefinitions().remove(def.getName()); def.setPropertyGroupDefinition(null); entityManager.remove(def); 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 + "]"); existingDefinition.put(nDef); updateReport.addNewPropertyDefinition(nDef);
@Override public void updateResourceConfiguration(ConfigurationUpdateReport report) { ConfigurationDefinition configDefCopy = context.getResourceType().getResourceConfigurationDefinition().copy(); Map<String, PropertyDefinition> propDefs = configDefCopy.getPropertyDefinitions(); if (configDefCopy.getDefaultTemplate().getConfiguration().get(TYPE_CONFIGURATION) != null) { } else if (configDefCopy.getDefaultTemplate().getConfiguration().get(NAME_CONFIGURATION) != null) { for (PropertyDefinition propDef : configDefCopy.getNonGroupedProperties()) {
@Override public Configuration loadResourceConfiguration() throws Exception { ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition(); if (configDef.getDefaultTemplate().getConfiguration().get(TYPE_CONFIGURATION) != null) { //__type is a fake property, do not attempt to load it from the managed server configDef.getPropertyDefinitions().remove(TYPE_CONFIGURATION); ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(configDef, getASConnection(), address); Configuration configuration = delegate.loadResourceConfiguration(); //manually load type based on the resource path PropertySimple pathProperty = (PropertySimple) context.getPluginConfiguration().get("path"); String type = pathProperty.getStringValue(); type = type.substring(type.lastIndexOf(',') + 1, type.lastIndexOf('=')); configuration.put(new PropertySimple(TYPE_CONFIGURATION, type)); return configuration; } else if (configDef.getDefaultTemplate().getConfiguration().get(NAME_CONFIGURATION) != null) { //__name is a fake property, do not attempt to load it from the managed server configDef.getPropertyDefinitions().remove(NAME_CONFIGURATION); ConfigurationLoadDelegate delegate = new ConfigurationLoadDelegate(configDef, getASConnection(), address); Configuration configuration = delegate.loadResourceConfiguration(); //manually load name based on the resource path PropertySimple pathProperty = (PropertySimple) context.getPluginConfiguration().get("path"); String name = pathProperty.getStringValue(); name = name.substring(name.lastIndexOf('=') + 1); configuration.put(new PropertySimple(NAME_CONFIGURATION, name)); return configuration; } return super.loadResourceConfiguration(); }
if ((null == protocol) || protocol.toUpperCase().contains("HTTP")) { for (PropertyDefinition propDef : configDef.getPropertiesInGroup("AJP")) { report.getConfiguration().remove(propDef.getName()); for (PropertyDefinition propDef : configDef.getPropertiesInGroup("HTTP")) { report.getConfiguration().remove(propDef.getName()); for (PropertyDefinition propDef : configDef.getPropertiesInGroup("HTTP SSL")) { report.getConfiguration().remove(propDef.getName()); continue; // skip unsupported attributes PropertyDefinitionSimple def = configDef.getPropertyDefinitionSimple(key); if (!def.isRequired()) { PropertySimple prop = report.getConfiguration().getSimple(key); PropertySimple pro = (PropertySimple) prop; if (pro.getStringValue() == null || (pro.getStringValue() != null && pro.getStringValue().equals("null"))) { String p = context.getResourceType().getResourceConfigurationDefinition().getDefaultTemplate().getConfiguration().getSimpleValue(key); log.debug("Using default value for " + key + " value: " + def.getDefaultValue()); switch (def.getType()) {
public static ConfigurationDefinition parse(@NotNull String configurationName, ConfigurationDescriptor descriptor) throws InvalidPluginDescriptorException { if (descriptor == null) { return null; } if (configurationName==null) { throw new IllegalArgumentException("ConfigurationName must not be null"); } ConfigurationDefinition configurationDefinition = new ConfigurationDefinition(configurationName, descriptor.getNotes()); configurationDefinition.setConfigurationFormat(getConfigurationFormat(descriptor)); if (configurationDefinition.getConfigurationFormat() == RAW) { return configurationDefinition; } for (ConfigurationTemplateDescriptor templateDescriptor : descriptor.getTemplate()) { configurationDefinition.putTemplate(parseTemplate(templateDescriptor)); } ConfigurationTemplate defaultTemplate = initDefaultTemplate(configurationDefinition); configurationDefinition.putTemplate(defaultTemplate); Configuration defaultConfiguration = defaultTemplate.getConfiguration(); parseProperties(descriptor, defaultConfiguration, configurationDefinition); ConfigurationUtility.normalizeConfiguration(defaultConfiguration, configurationDefinition); return configurationDefinition; }
ConfigurationDefinition configDefCopy = resourceType.getResourceConfigurationDefinition().copy(); configDefCopy.getPropertyDefinitions().remove(DISCOVERY_GROUP_NAME); configDefCopy.getPropertyDefinitions().remove(configurationUpdateHelper.getConnectorPropertyName()); ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(configDefCopy, getASConnection(), address);
/** * Removes PropertyDefinition items from the configuration * * @param newConfigDef new configuration being merged into the existing one * @param existingConfigDef existing persisted configuration * @param existingProperties list of existing properties to inspect for potential removal */ 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); } } if (!propDefsToDelete.isEmpty()) { log.debug("Deleting obsolete props from configDef [" + existingConfigDef + "]: " + propDefsToDelete); for (PropertyDefinition propDef : propDefsToDelete) { existingConfigDef.getPropertyDefinitions().remove(propDef.getName()); existingProperties.remove(propDef); // does not operate on original list!! } existingConfigDef = entityManager.merge(existingConfigDef); } return existingConfigDef; }
ConfigurationTemplate template = updateReport.getConfigurationDefinition().getDefaultTemplate(); Configuration templateConfiguration = template.getConfiguration(); throw new IllegalArgumentException("The property [" + propertyDef.getName() + "] marked as required in the configuration definition of [" + propertyDef.getConfigurationDefinition().getName() + "] has no attribute 'default'"); } else {
/** * This will populate the given configuration definition with a default template. * A default template will only be created if one or more properties are required * or have default values. If no property definition is required or has a default value, * the default template will remain <code>null</code> in the given config definition. * * Note that if the given configuration definition already has a default template defined * for it, this method is a no-op and will return immediately. * * @param configDef the configuration definition whose default template is to be created and set */ public static void initializeDefaultTemplate(ConfigurationDefinition configDef) { ConfigurationTemplate defaultTemplate = configDef.getDefaultTemplate(); if (defaultTemplate == null) { Configuration defaultConfig = createDefaultConfiguration(configDef); // not everything should have a default template - only stuff that has default values if (!defaultConfig.getProperties().isEmpty()) { defaultTemplate = new ConfigurationTemplate(ConfigurationTemplate.DEFAULT_TEMPLATE_NAME, ConfigurationTemplate.DEFAULT_TEMPLATE_NAME); defaultTemplate.setDefault(true); defaultTemplate.setConfiguration(defaultConfig); configDef.putTemplate(defaultTemplate); } } return; }
protected CompositeOperation updateGenerateOperationFromProperties(Configuration conf, Address address) { CompositeOperation cop = new CompositeOperation(); for (PropertyDefinition propDef : configurationDefinition.getNonGroupedProperties()) { updateProperty(conf, cop, propDef, address); for (PropertyGroupDefinition pgd : configurationDefinition.getGroupDefinitions()) { String groupName = pgd.getName(); namePropLocator = null; List<PropertyDefinition> definitions = configurationDefinition.getPropertiesInGroup(groupName); for (PropertyDefinition def : definitions) { updateProperty(conf, cop, def, address); address1.addSegment(subPath); List<PropertyDefinition> definitions = configurationDefinition.getPropertiesInGroup(groupName); for (PropertyDefinition propDef : configurationDefinition.getPropertiesInGroup(groupName)) { updateProperty(conf, cop, propDef, address);
@Override public ConfigurationDefinition getImportConfigurationDefinition() { ConfigurationDefinition def = new ConfigurationDefinition("SystemSettingsConfiguration", null); PropertyDefinitionSimple props = new PropertyDefinitionSimple( PROPERTIES_TO_IMPORT_PROPERTY, "The names of the properties that should be imported. Note that these are the INTERNAL names as used in the RHQ database." + " If you include any property that stores a password (such as CAM_LDAP_BIND_PW)," + " you need to make sure the values are OBFUSCATED. You can obtain an obfuscated value of your" + " password by running the \"rhq-encode-password.(sh|bat)\" script located in the \"bin\" directory" + " of your RHQ server installation.", true, PropertySimpleType.STRING); props.setDefaultValue(DEFAULT_IMPORTED_PROPERTIES_LIST); def.put(props); ConfigurationUtility.initializeDefaultTemplate(def); return def; }
PropertySimple propertySimple = (PropertySimple) prop; PropertyDefinitionSimple propertyDefinition = this.configurationDefinition .getPropertyDefinitionSimple(propertySimple.getName()); PropertyList propertyList = (PropertyList) prop; PropertyDefinitionList propertyDefinition = this.configurationDefinition .getPropertyDefinitionList(propertyList.getName()); PropertyMap propertyMap = (PropertyMap) prop; PropertyDefinitionMap propertyDefinition = this.configurationDefinition .getPropertyDefinitionMap(propertyMap.getName());
private boolean isStructuredAndRawSupported(int resourceId) { Resource resource = entityManager.find(Resource.class, resourceId); ConfigurationDefinition configDef = resource.getResourceType().getResourceConfigurationDefinition(); if (configDef == null) { return false; } return ConfigurationFormat.STRUCTURED_AND_RAW == configDef.getConfigurationFormat(); }
public static CtClass translateConfiguration(ClassPool cp, ConfigurationDefinition def) throws NotFoundException { if (def == null) { return CtClass.voidType; } else if (def.getPropertyDefinitionSimple("operationResult") != null) { // Its a simple type return getSimpleTypeClass(cp, def.getPropertyDefinitionSimple("operationResult")); } else { // TODO GH: Build a custom type? return cp.get(Configuration.class.getName()); } }
/** * Trigger loading of a configuration by talking to the remote resource. * @return The initialized configuration * @throws Exception If anything goes wrong. */ public Configuration loadResourceConfiguration() throws Exception { Configuration config = new Configuration(); /* * Grouped definitions get a special treatment, as they may have a special property * that will be evaluated to look at a child resource or a special attribute or such */ List<PropertyGroupDefinition> gdef = configurationDefinition.getGroupDefinitions(); for (PropertyGroupDefinition pgDef : gdef) { loadHandleGroup(config, pgDef); } /* * Now handle the non-grouped properties */ List<PropertyDefinition> nonGroupdedDefs = configurationDefinition.getNonGroupedProperties(); Operation op = new ReadResource(address); if (includeRuntime) { op.addAdditionalProperty("include-runtime", "true"); // Include runtime values for attributes } // op.addAdditionalProperty("recursive", "true"); // Also get sub-resources loadHandleProperties(config, nonGroupdedDefs, op); return config; }