public boolean isManuallyAddedServer() { return pluginConfiguration.get("manuallyAdded") != null; }
private void showConfig(Configuration config, String[] tokens) { if (tokens==null || tokens.length<2) { for (Property p : config.getProperties()) { System.out.println(p); } } else { String pList = tokens[1]; String[] props = pList.split(","); for (String propName : props) { Property p = config.get(propName); if (p==null) System.err.println("Property " + propName + " not found"); else System.out.println(p); } } }
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); } }
operation.addAdditionalProperty("entries", jndiNames); if (type.equals("jms-queue")) { PropertySimple ps = (PropertySimple) parameters.get("durable"); if (ps != null) { boolean durable = Boolean.parseBoolean(ps.getStringValue());
Property templateProperty = templateConfiguration.get(propertyDef.getName()); if (templateProperty == null) { throw new IllegalArgumentException("The property [" + propertyDef.getName() String propertyValue = pluginConfiguration.getSimpleValue(propertyDef.getName(), null); if (propertyValue == null) { Property templateProperty = templateConfiguration.get(propertyDef.getName()); pluginConfiguration.put(templateProperty.deepCopy(false)); modified = true;
List<String> toRemove = new ArrayList<String>(); for (String name : exNames) { Property prop = newConf.get(name); if (prop instanceof PropertySimple) { PropertySimple ps = newConf.getSimple(name); if (ps != null) { Property eprop = existConf.get(name); if (eprop instanceof PropertySimple) { PropertySimple exps = existConf.getSimple(name); Property prop = newConf.get(name); if (prop instanceof PropertySimple) { PropertySimple ps = newConf.getSimple(name);
private Configuration mergeExistingResourcePluginConfiguration(Resource resource, Configuration pluginConfig) { // If there is no update necessary just return the current plugin config of the existing resource Configuration result = resource.getPluginConfiguration(); ConfigurationDefinition configDef = resource.getResourceType().getPluginConfigurationDefinition(); if (null == configDef) { return result; } Configuration existingPluginConfig = resource.getPluginConfiguration().deepCopy(false); Configuration defaultPluginConfig = ConfigurationUtility.createDefaultConfiguration(configDef); boolean configChanged = false; // for each property, update the existing plugin config if discovery has set a non-default value for (String propertyName : pluginConfig.getAllProperties().keySet()) { Property discoveredProp = pluginConfig.get(propertyName); Property defaultProp = defaultPluginConfig.get(propertyName); if (!discoveredProp.equals(defaultProp)) { if (log.isDebugEnabled()) { log.debug("Discovery reported a new version of " + resource + ". Updating value of config property" + " from [" + existingPluginConfig.get(propertyName) + "] to [" + discoveredProp + "]."); } existingPluginConfig.put(discoveredProp); configChanged = true; } } if (configChanged) { result = mergeExistingResourcePluginConfigurationOnServer(resource, existingPluginConfig); } return result; }
/** * Check that the passed configuration is valid wrt the passed definition * @param configuration A Configuration to check * @param definition A Definition to check the Configuration against * @return List of validation failure messages. List is empty if no errors were found. */ public static List<String> checkConfigurationWrtDefinition(Configuration configuration, ConfigurationDefinition definition) { List<String> messages = new ArrayList<String>(); if (configuration==null) { messages.add("Configuration is null"); } if (definition==null) { messages.add("Definition is null"); } if (configuration==null || definition==null) { return messages; } // Basic validation is done, now have a look at the properties for (PropertyDefinition propDef : definition.getPropertyDefinitions().values()) { String name = propDef.getName(); Property property = configuration.get(name); checkProperty(messages, propDef, property); } return messages; }
@Override public OperationResult invokeOperation(final String name, final Configuration parameters) throws InterruptedException, Exception { if (OPERATION_RESET.equals(name)) { final Service service = getService(); final Application application = getApplication(); if ((service != null) && (application != null)) { final String serviceName = service.getName().toString(); final String applicationName = application.getName().toString(); execute(new ResetServiceMetrics(applicationName, serviceName), Void.class); clearServiceMetrics(); } } else if (OPERATION_SET_THROTTLING.equals(name)) { final PropertySimple enabled = (PropertySimple) parameters.get(OPERATION_PARAMETER_ENABLED); final PropertySimple maxRequests = (PropertySimple) parameters.get(OPERATION_PARAMETER_MAX_REQUESTS); final Service service = getService(); final Application application = getApplication(); if ((service != null) && (application != null)) { final String serviceName = service.getName().toString(); final String applicationName = application.getName().toString(); execute(new UpdateThrottling(applicationName, serviceName, (enabled != null ? enabled.getBooleanValue() : null), (maxRequests != null ? maxRequests.getIntegerValue() : null)), Void.class); clearApplications(); } } else if (LOG.isDebugEnabled()) { LOG.warn("Unknown Service operation " + name); } return null; }
@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(); }
/** * 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."); } } } }
@Override public CreateResourceReport createResource(CreateResourceReport report) { if (report.getResourceConfiguration().get(TYPE_CONFIGURATION) != null) { PropertySimple typeProperty = (PropertySimple) configuration.get(TYPE_CONFIGURATION); configuration.remove(TYPE_CONFIGURATION); report.getPluginConfiguration().put(new PropertySimple("path", typeProperty.getStringValue())); } else if (report.getResourceConfiguration().get(NAME_CONFIGURATION) != null) { PropertySimple nameProperty = (PropertySimple) configuration.get(NAME_CONFIGURATION); configuration.remove(NAME_CONFIGURATION); report.setUserSpecifiedResourceName(nameProperty.getStringValue());