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); } }
private List<String> getPropertyNames(ConfigurationDefinition definition) { // the facet that this ConfigurationDefinition came from was null if (definition == null) { return Collections.emptyList(); } // the facet that this ConfigurationDefinition came from was empty Map<String, PropertyDefinition> definitions = definition.getPropertyDefinitions(); if (definitions == null) { return Collections.emptyList(); } Set<String> uniqueNames = definitions.keySet(); List<String> propertyNames = new ArrayList<String>(uniqueNames); Collections.sort(propertyNames); return propertyNames; }
private static void addRepresentation(ConfigurationDefinition cd, StringBuilder bld) { if (cd == null) { bld.append("null"); } else { addRepresentation(cd.getPropertyDefinitions(), bld); } }
public void applyGroupConfiguration() { if (this.members.isEmpty()) return; Map<String, PropertyDefinition> childPropertyDefinitions = this.configurationDefinition .getPropertyDefinitions(); List<AbstractPropertyMap> sourceParentPropertyMaps = new ArrayList<AbstractPropertyMap>(); for (ConfigurationSetMember member : this.members) sourceParentPropertyMaps.add(member.getConfiguration()); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) mergeProperty(childPropertyDefinition, sourceParentPropertyMaps, this.groupConfiguration); }
/** * Mask the values of all simple properties of type PASSWORD in the configuration. The properties are masked by * calling {@link PropertySimple#mask()}. The configuration does not need to be normalized; that is, properties * defined by the configuration definition do not need to exist in the configuration. * * @param configuration the configuration to be masked * @param configurationDefinition the configuration definition corresponding to the specified configuration; this is * used to determine which properties to mask - all simple properties of type * PASSWORD at any level within the configuration are masked */ public static void maskConfiguration(@NotNull Configuration configuration, @NotNull ConfigurationDefinition configurationDefinition) { if (configurationDefinition == null) { return; } Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions(); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) { maskProperty(childPropertyDefinition, configuration); } }
/** * @param def * @return Map of propertyName to types for the config def * @throws NotFoundException */ public static LinkedHashMap<String, CtClass> translateParameters(ClassPool cp, ConfigurationDefinition def) throws NotFoundException { LinkedHashMap<String, CtClass> result = new LinkedHashMap<String, CtClass>(); if (def == null || def.getPropertyDefinitions() == null) { return result; } for (PropertyDefinition pd : def.getPropertyDefinitions().values()) { if (pd instanceof PropertyDefinitionSimple) { PropertyDefinitionSimple simple = (PropertyDefinitionSimple) pd; String name = pd.getName(); CtClass paramType = getSimpleTypeClass(cp, simple); result.put(name, paramType); } } return result; }
public void calculateGroupConfiguration() { this.groupConfiguration.getMap().clear(); if (this.members.isEmpty()) return; Map<String, PropertyDefinition> childPropertyDefinitions = this.configurationDefinition .getPropertyDefinitions(); List<AbstractPropertyMap> sourceParentPropertyMaps = new ArrayList<AbstractPropertyMap>(); for (ConfigurationSetMember member : this.members) sourceParentPropertyMaps.add(member.getConfiguration()); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) calculateGroupProperty(childPropertyDefinition, sourceParentPropertyMaps, this.groupConfiguration); }
public static void obfuscatePasswords(ConfigurationDefinition definition, Configuration config) { if (config == null || config.getMap().isEmpty()) { return; } if (definition == null || definition.getPropertyDefinitions().isEmpty()) { return; } List<PropertySimple> replacementCandidates = new ArrayList<PropertySimple>(); for(PropertyDefinition def : definition.getPropertyDefinitions().values()) { Property prop = config.get(def.getName()); propertySwitch(def, prop, replacementCandidates); } for(PropertySimple prop : replacementCandidates) { replace(prop); } }
/** * Given a configuration definition, this will build and return a "default configuration" that * can be validated with the definition. All required properties are set and all properties * that define a default value are also set. If a required property does not have a default * value defined in the definition, the property value will be set to <code>null</code>. * * Use this to help create the definition's default template. * * @param configurationDefinition the configuration definition whose default configuration is to be created * @return configuration the default configuration */ public static Configuration createDefaultConfiguration(ConfigurationDefinition configurationDefinition) { if (configurationDefinition == null) { throw new IllegalArgumentException("configurationDefinition == null"); } Configuration defaultConfig = new Configuration(); Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions(); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) { createDefaultProperty(childPropertyDefinition, defaultConfig); } return defaultConfig; }
public Configuration loadResourceConfiguration(AugeasNode startNode, ConfigurationDefinition resourceConfigDef) throws AugeasRhqException { Configuration resourceConfig = new Configuration(); Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values(); for (PropertyDefinition propDef : propDefs) { resourceConfig.put(loadProperty(propDef, startNode)); } return resourceConfig; }
public void updateResourceConfiguration(AugeasNode node, ConfigurationDefinition resourceConfigDef, Configuration resourceConfig) throws AugeasRhqException { Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values(); PropertyMap startProp = new PropertyMap(); for (Property property : resourceConfig.getProperties()) startProp.put(property); for (PropertyDefinition propDef : propDefs) { updateProperty(propDef, startProp, node, 0); } }
public static PropertyDefinition getPropertyDefinitionForProperty(Property property, ConfigurationDefinition configurationDefinition) { LinkedList<Property> propertyHierarchy = getPropertyHierarchy(property); Property topLevelProperty = propertyHierarchy.get(0); PropertyDefinition propertyDefinition = configurationDefinition.getPropertyDefinitions().get(topLevelProperty.getName()); for (int i = 1; i < propertyHierarchy.size(); i++) { Property subProperty = propertyHierarchy.get(i); if (propertyDefinition instanceof PropertyDefinitionMap) { propertyDefinition = ((PropertyDefinitionMap)propertyDefinition).get(subProperty.getName()); } else if (propertyDefinition instanceof PropertyDefinitionList) { propertyDefinition = ((PropertyDefinitionList)propertyDefinition).getMemberDefinition(); } } return propertyDefinition; }
private void ensureDisplayNameIsSet(RecipeParseResults recipeParseResults) { if (recipeParseResults != null && recipeParseResults.getConfigurationDefinition() != null) { ConfigurationDefinition configDef = recipeParseResults.getConfigurationDefinition(); for (PropertyDefinition propDef : configDef.getPropertyDefinitions().values()) { if (propDef instanceof PropertyDefinitionSimple) { if (propDef.getDisplayName() == null) { propDef.setDisplayName(propDef.getName()); } } } } return; } }
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; }
protected void updateStructuredConfiguration(Configuration config) throws Exception { abortIfAugeasNotAvailable(); //augeas was initialized in abortIfAugeasNotAvailable try { ConfigurationDefinition resourceConfigDef = this.resourceContext.getResourceType() .getResourceConfigurationDefinition(); Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values(); for (PropertyDefinition propDef : propDefs) { setNode(propDef, config, this.augeas, this.resourceConfigRootNode); } // Write the updated tree out to the config file. saveConfigurationFiles(); } finally { close(); } }
@Override public void updateResourceConfiguration(ConfigurationUpdateReport report) { Configuration config = report.getConfiguration(); ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition(); boolean processIdUuid = Boolean.valueOf(config.getSimpleValue("process-id-uuid")); if (processIdUuid == true) { //Do not even send the updates for [process-id-socket-binding] because the AS7 will //undefine it during the next reload/restart. //Also, sending null for [process-id-socket-binding] with [process-id-uuid] == true causes //a validation error on the server. configDef.getPropertyDefinitions().remove("process-id-socket-binding"); config.remove("process-id-socket-binding"); } ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(configDef, getASConnection(), address); delegate.updateResourceConfiguration(report); } }
@Override public void updateResourceConfiguration(ConfigurationUpdateReport report) { Configuration config = report.getConfiguration(); ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition(); if (!(context.getParentResourceComponent() instanceof StandaloneASComponent)) { // TODO what about managed servers configDef.getPropertyDefinitions().remove("port-offset"); config.remove("port-offset"); } ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(configDef, getASConnection(), address); delegate.updateResourceConfiguration(report); } }
/** * Get a copy of this {@link ConfigurationDefinition}. The property definitions will be returned in * a new Map, which can be safely manipulated without affecting the original Map. It is not a deep copy, it * is backed by the same {@link #PropertyDefinition} objects as the original and changes to the Map entries will * modify the originals. The templates Map is treated the same way. The id is not copied. * * @return the copy */ public ConfigurationDefinition copy() { ConfigurationDefinition copy = new ConfigurationDefinition(this.getName(), this.getDescription()); copy.setPropertyDefinitions(this.getPropertyDefinitions()); copy.setConfigurationFormat(this.getConfigurationFormat()); copy.templates = new LinkedHashMap<String, ConfigurationTemplate>(this.getTemplates()); return copy; }
/** * checks if plugin configuration has set all required properties * @param plugin * @throws PluginConfigurationRequiredException if plugin is missing required configuration * @throws Exception in case of any other error */ private void checkForRequiredConfiguration(ServerPlugin plugin) throws Exception { ConfigurationDefinition configDef = getServerPluginConfigurationDefinition(new PluginKey(plugin)); Configuration configuration = plugin.getPluginConfiguration(); for (PropertyDefinition propDef : configDef.getPropertyDefinitions().values()) { if (propDef.isRequired() && propDef instanceof PropertyDefinitionSimple) { Property prop = configuration.get(propDef.getName()); PropertySimple simple = (PropertySimple) prop; if (simple == null || simple.getStringValue() == null || "".equals(simple.getStringValue())) { throw new PluginConfigurationRequiredException("Plugin [" + plugin.getDisplayName() + "] could not be enabled, because some required configuration fields are not set."); } } } }
/** * This default setup of configuration properties can map to mbean attributes * * @return the configuration of the component */ public Configuration loadResourceConfiguration() { Configuration configuration = new Configuration(); ConfigurationDefinition configurationDefinition = this.resourceContext.getResourceType() .getResourceConfigurationDefinition(); for (PropertyDefinition property : configurationDefinition.getPropertyDefinitions().values()) { if (property instanceof PropertyDefinitionSimple) { EmsAttribute attribute = getEmsBean().getAttribute(property.getName()); if (attribute != null) { configuration.put(new PropertySimple(property.getName(), attribute.refresh())); } } } return configuration; }