etc/cli-scripts/reset_apache_props.js | 102 ++++++++++
etc/cli-scripts/reset_conn_props.js | 287 -----------------------------
etc/cli-scripts/reset_jboss_agent_props.js | 110 +++++++++++
3 files changed, 212 insertions(+), 287 deletions(-)
New commits:
commit cc33d336fa0e253f16ff2669375b840b5b32fc96
Merge: cd68889... 724682f...
Author: John Sanda <jsanda(a)redhat.com>
Date: Mon Aug 2 13:17:29 2010 -0400
Merge branch 'master' of
ssh://git.fedorahosted.org/git/rhq/rhq
commit cd688890537687233af414fbdf785707a98f8718
Author: John Sanda <jsanda(a)redhat.com>
Date: Mon Aug 2 13:11:39 2010 -0400
Cleaning up logic in script for resetting connection properties, adding script for
apache
I have renamed reset_conn_props.js to reset_jboss_agent_prop.js. Most of the logic in
that script has been removed. There was logic for retrieving default values from the
default template; however, I discovered through further testing that the snapshot
report
properties do not even exist in the default template when upgrading 2.2.0 -->
2.3.1.
Consequently, I need to simply hard code the properties that need to be added to the
plugin
configurations.
Adding a similar script for apache to handle properties added in the 2.4.0 release.
diff --git a/etc/cli-scripts/reset_apache_props.js
b/etc/cli-scripts/reset_apache_props.js
new file mode 100644
index 0000000..becdc50
--- /dev/null
+++ b/etc/cli-scripts/reset_apache_props.js
@@ -0,0 +1,102 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/**
+ * This CLI script resets/restores apache connection properties that are not set to
their
+ * default values during plugin upgrade. This script is only intended to be run once. If
+ * run subsequent times, the script will reset these properties to their defaults,
+ * overriding whatever the current values might be.
+ */
+
+
+function iterate(iterable, callback) {
+ var iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ callback(iterator.next());
+ }
+}
+
+function filter(iterable, predicate) {
+ var matches = java.util.ArrayList();
+ iterate(iterable, function(obj) {
+ if (predicate(obj)) {
+ matches.add(obj);
+ }
+ });
+ return matches;
+}
+
+function log(msg) {
+ println("DEBUG " + msg);
+}
+
+function loadPluginConfiguration(resource) {
+ log("Loading plugin configuration for " + resource);
+ return ConfigurationManager.getPluginConfiguration(resource.id);
+}
+
+function findResourcesByTypeAndPlugin(resourceType, plugin) {
+ var criteria = ResourceCriteria();
+ criteria.addFilterResourceTypeName(resourceType);
+ criteria.addFilterPluginName(plugin);
+ criteria.fetchResourceType(true);
+ criteria.fetchPluginConfiguration(true);
+ criteria.caseSensitive = true;
+ criteria.strict = true;
+
+ var resources = ResourceManager.findResourcesByCriteria(criteria);
+
+ log("Found " + resources.size() + " " + resourceType + "
resources ");
+
+ iterate(resources, function(resource) {
+ resource.pluginConfiguration = loadPluginConfiguration(resource);
+ });
+
+ return resources;
+}
+
+function updatePluginConfigs(resources, applyDefaults) {
+ iterate(resources, function(resource) {
+ log("Preparing to update plugin configuration for " + resource)
+ applyDefaults(resource.pluginConfiguration);
+ ConfigurationManager.updatePluginConfiguration(resource.id,
resource.pluginConfiguration);
+ log("Updated plugin configuration for " + resource);
+ });
+}
+
+functionr resetApachePluginConfigProps() {
+ var resourceTypeName = 'Apache HTTP Server';
+ var pluginName = 'Apache';
+ var servers = findResourcesByTypeAndPlugin(resourceTypeName, pluginName);
+
+ updatePluginConfigs(servers, function(pluginConfig) {
+ pluginConfig.put(PropertySimple('augeasEnabled', 'no'));
+ pluginConfig.put(PropertySimple('configurationFilesInclusionPatterns',
'/etc/httpd/conf/httpd.conf'));
+ pluginConfig.put(PropertySimple('vhostCreationPolicy',
'vhost-per-file'));
+ });
+}
+
+//////////////
+// main //
+//////////////
+resetApachePluginConfigProps();
diff --git a/etc/cli-scripts/reset_conn_props.js b/etc/cli-scripts/reset_conn_props.js
deleted file mode 100644
index 274bc5c..0000000
--- a/etc/cli-scripts/reset_conn_props.js
+++ /dev/null
@@ -1,287 +0,0 @@
-/**
- * This is a CLI script to be used for
https://bugzilla.redhat.com/show_bug.cgi?id=573034.
- * The script resets the snapshot report plugin configuration properties for JBoss
servers
- * and agents to their default values. This is a one-off script intended only to be run
- * once to assign values to required plugin properties that are unset.
- *
- * NOTE: This script can probably be refactored and generalized a bit to support
- * resetting any specified plugin configuration properties to their default values.
- * And specifying candidate properties could be done via a callback function to
- * allow for arbitrarily complex logic in determining the properties.
- */
-
-function iterate(iterable, callback) {
- var iterator = iterable.iterator();
- while (iterator.hasNext()) {
- callback(iterator.next());
- }
-}
-
-function filter(iterable, predicate) {
- var matches = java.util.ArrayList();
- iterate(iterable, function(obj) {
- if (predicate(obj)) {
- matches.add(obj);
- }
- });
- return matches;
-}
-
-function log(msg) {
- println("DEBUG " + msg);
-}
-
-function loadPluginConfiguration(resource) {
- log("Loading plugin configuration for " + resource);
- return ConfigurationManager.getPluginConfiguration(resource.id);
-}
-
-function loadPluginConfigDef(resourceTypeName, pluginName) {
- log("Loading plugin configuration definition for [resourceType=" +
resourceTypeName + ", plugin=" +
- pluginName + "]");
- var resourceType =
ResourceTypeManager.getResourceTypeByNameAndPlugin(resourceTypeName,
- pluginName);
-
- if (resourceType == null) {
- throw "Failed to find resource type '" + resourceTypeName +
"'";
- }
-
- configDef =
ConfigurationManager.getPluginConfigurationDefinitionForResourceType(resourceType.id);
-
- if (configDef == null) {
- throw "Failed to load plugin configuration for [resourceType=" +
resourceTypeName +
- ", plugin=" + pluginName + "]";
- }
-
- return configDef;
-}
-
-function findResourcesByTypeAndPlugin(resourceType, plugin) {
- var criteria = ResourceCriteria();
- criteria.addFilterResourceTypeName(resourceType);
- criteria.addFilterPluginName(plugin);
- criteria.fetchResourceType(true);
- criteria.fetchPluginConfiguration(true);
- criteria.caseSensitive = true;
- criteria.strict = true;
-
- var resources = ResourceManager.findResourcesByCriteria(criteria);
-
- log("Found " + resources.size() + " " + resourceType + "
resources ");
-
- iterate(resources, function(resource) {
- resource.pluginConfiguration = loadPluginConfiguration(resource);
- });
-
- return resources;
-}
-
-/**
- * This function takes a Configuration object and "flattens" its properties
into a list of
- * all simple (i.e., PropertySimple) objects contained in the configuration. This
includes
- * nested properties. The properties are returned as a java.util.List.
- *
- * param: configuration The Configuration object from which the property list will be
built
- *
- * return: A List object of all PropertySimple objects, including those nested in
complex
- * properties
- */
-function flattenProperties(configuration) {
- var simpleProperties = java.util.ArrayList();
-
- iterate(configuration.map.values(), function(property) {
- if (property instanceof PropertySimple) {
- simpleProperties.add(property);
- }
- else if (property instanceof PropertyList) {
- simpleProperties.addAll(flattenPropertyList(property));
- }
- });
-
- return simpleProperties;
-}
-
-function flattenPropertyList(propertyList) {
- var simpleProperties = java.util.ArrayList();
-
- iterate(propertyList.list, function(property) {
- if (property instanceof PropertySimple) {
- simpleProperty.add(property);
- }
- else if (property instanceof PropertyMap) {
- simpleProperties.addAll(flattenPropertyMap(property));
- }
- else if (property instanceof PropertyList) {
- simpleProperties.addAll(flattenPropertyList(property));
- }
- });
-
- return simpleProperties;
-}
-
-function flattenPropertyMap(propertyMap) {
- var simpleProperties = java.util.ArrayList();
-
- iterate(propertyMap.map.values(), function(property) {
- if (property instanceof PropertySimple) {
- simpleProperties.add(property);
- }
- else if (property instanceof PropertyMap) {
- simpleProperties.addAll(flattenPropertyMap(property));
- }
- else if (property instanceof PropertyList) {
- simpleProperties.addAll(flattPropertyList(property));
- }
- });
-
- return simpleProperties;
-}
-
-/**
- * Loads the specified default plugin properties for a given plugin configuration
definition.
- * The defaults are stored in and retrieved from the default template of the plugin
- * configuration.
- *
- * param: pluginConfigDef A ConfigurationDefinition object which is the plugin config
def
- * from which to retrieve the defaults
- *
- * param: defaultPropertyNames A java.util.Collection of the property names to include
- *
- * return: A java.util.Map of the default properties. Property names as strings are
mapped
- * to the PropertySimple objects.
- */
-function loadSnapshotDefaults(pluginConfigDef, defaultPropertyNames) {
- var snapshotDefaultsMap = java.util.HashMap();
- var defaults = flattenProperties(pluginConfigDef.defaultTemplate.configuration);
-
- var isSnapshotProperty = function(property) {
- return defaultPropertyNames.contains(property.name);
- }
-
- var snapshotDefaults = filter(defaults, isSnapshotProperty);
-
- iterate(snapshotDefaults, function(property) {
- snapshotDefaultsMap.put(property.name, property);
- });
-
- return snapshotDefaultsMap;
-}
-
-function getJBossSnapshotPropertyNames() {
- var set = java.util.HashSet();
- set.add('snapshotConfigEnabled');
- set.add('snapshotConfigDirectory');
- set.add('snapshotConfigRecursive');
- set.add('snapshotLogEnabled');
- set.add('snapshotLogDirectory');
- set.add('snapshotLogRecursive');
- set.add('snapshotDataEnabled');
- set.add('snapshotDataDirectory');
- set.add('snapshotDataRecursive');
- set.add('snapshotAdditionalFilesEnabled');
- set.add('snapshotAdditionalFilesDirectory');
- set.add('snapshotAdditionalFilesRecursive');
-
- return set;
-}
-
-function getAgentSnapshotPropertyNames() {
- var set = java.util.HashSet();
- set.add('snapshotConfigEnabled');
- set.add('snapshotLogEnabled');
- set.add('snapshotDataEnabled');
-
- return set;
-}
-
-/**
- * Resets the values of specified plugin configuration properties back to their default
values.
- * The configuration is modified locally, in memory and then a request is sent to
- * ConfigurationManager.
- *
- * param: resources The resources whose plugin configurations are to be updated. This is
- * expected to be a java.util.Collection.
- *
- * param: snapshotDefaults: The names of the plugin configuration properties to reset.
This
- * is expected to be a java.util.Collection.
- */
-function resetPluginConfigPropsFromTemplate(pluginConfigDef, resources, snapshotDefaults)
{
- iterate(resources, function(resource) {
- log("Preparing to reset plugin configuration properties for " + resource);
- var simpleProperties = flattenProperties(resource.pluginConfiguration);
- var snapshotProperties = filter(simpleProperties, function(property) {
- return snapshotDefaults.containsKey(property.name);
- });
-
- iterate(snapshotProperties, function(property) {
- var defaultProperty = snapshotDefaults.get(property.name);
- property.stringValue = defaultProperty.stringValue;
- log("Set property " + property.name + " to " +
property.stringValue);
- });
-
- ConfigurationManager.updatePluginConfiguration(resource.id,
resource.pluginConfiguration);
- log("Updated plugin configuration for " + resource);
- });
-}
-
-function resetPluginConfigProps(resources, applyDefaults) {
- iterate(resources, function(resource) {
- applyDefaults(resource.pluginConfiguration);
- ConfigurationManager.updatePluginConfiguration(resource.id,
resource.pluginConfiguration);
- log("Updated plugin configuration for " + resource);
- });
-}
-
-function resetJBossPluginConfigProps() {
- var jbossResourceTypeName = 'JBossAS Server';
- var jbossPluginName = 'JBossAS';
- var jbossServers = findResourcesByTypeAndPlugin(jbossResourceTypeName,
jbossPluginName);
- var jbossPluginConfigDef = loadPluginConfigDef(jbossResourceTypeName,
jbossPluginName);
-
- //resetPluginConfigProps(jbossServers, loadSnapshotDefaults(jbossPluginConfigDef,
- // getJBossSnapshotPropertyNames()));
-
- resetPluginConfigProps(jbossServers, function(pluginConfig) {
- pluginConfig.put(PropertySimple('snapshotConfigEnabled', true));
- pluginConfig.put(PropertySimple('snapshotConfigDirectory',
'config'));
- pluginConfig.put(PropertySimple('snapshotConfigRecursive', true));
- pluginConfig.put(PropertySimple('snapshotLogEnabled', true));
- pluginConfig.put(PropertySimple('snapshotLogDirectory', 'log'));
- pluginConfig.put(PropertySimple('snapshotLogRecursive', false));
- pluginConfig.put(PropertySimple('snapshotDataEnabled', false));
- pluginConfig.put(PropertySimple('snapshotDataDirectory', 'data'));
- pluginConfig.put(PropertySimple('snapshotDataRecursive', true));
-
- var propertyMap = PropertyMap('snapshotAdditionalFilesMap');
- propertyMap.put(PropertySimple('snapshotAdditionalFilesEnabled', true));
- propertyMap.put(PropertySimple('snapshotAdditionalFilesDirectory',
''));
- propertyMap.put(PropertySimple('snapshotAdditionalFilesRecursive', true));
-
- var propertyList = PropertyList('snapshotAdditionalFilesList');
- propertyList.list.add(propertyMap);
-
- pluginConfig.put(propertyList);
- });
-}
-
-function resetAgentPluginConfigProps() {
- var agentResourceTypeName = 'RHQ Agent';
- var agentPluginName = 'RHQAgent';
- var agents = findResourcesByTypeAndPlugin(agentResourceTypeName, agentPluginName);
- var agentPluginConfigDef = loadPluginConfigDef(agentResourceTypeName,
agentPluginName);
-
- //resetPluginConfigProps(agents, loadSnapshotDefaults(agentPluginConfigDef,
- // getAgentSnapshotPropertyNames()));
-
- resetPluginConfigProps(agents, function(pluginConfig) {
- pluginConfig.put(PropertySimple('snapshotConfigEnabled', true));
- pluginConfig.put(PropertySimple('snapshotLogEnabled', true));
- pluginConfig.put(PropertySimple('snapshotDataEnabled', true));
- });
-}
-
-//////////////
-// main //
-//////////////
-resetJBossPluginConfigProps();
-resetAgentPluginConfigProps();
diff --git a/etc/cli-scripts/reset_jboss_agent_props.js
b/etc/cli-scripts/reset_jboss_agent_props.js
new file mode 100644
index 0000000..51fdb99
--- /dev/null
+++ b/etc/cli-scripts/reset_jboss_agent_props.js
@@ -0,0 +1,110 @@
+/**
+ * This is a CLI script to be used for
https://bugzilla.redhat.com/show_bug.cgi?id=573034.
+ * The script resets/restores the snapshot report plugin configuration properties for
JBoss servers
+ * and agents to their default values. This is a one-off script intended only to be run
+ * once to assign values to required plugin properties that are unset. Running it
subsequent times
+ * cause the current connection settings for the snapshot report properties to be
overridden and
+ * reset to their default vales
+ */
+
+function iterate(iterable, callback) {
+ var iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ callback(iterator.next());
+ }
+}
+
+function filter(iterable, predicate) {
+ var matches = java.util.ArrayList();
+ iterate(iterable, function(obj) {
+ if (predicate(obj)) {
+ matches.add(obj);
+ }
+ });
+ return matches;
+}
+
+function log(msg) {
+ println("DEBUG " + msg);
+}
+
+function loadPluginConfiguration(resource) {
+ log("Loading plugin configuration for " + resource);
+ return ConfigurationManager.getPluginConfiguration(resource.id);
+}
+
+function findResourcesByTypeAndPlugin(resourceType, plugin) {
+ var criteria = ResourceCriteria();
+ criteria.addFilterResourceTypeName(resourceType);
+ criteria.addFilterPluginName(plugin);
+ criteria.fetchResourceType(true);
+ criteria.fetchPluginConfiguration(true);
+ criteria.caseSensitive = true;
+ criteria.strict = true;
+
+ var resources = ResourceManager.findResourcesByCriteria(criteria);
+
+ log("Found " + resources.size() + " " + resourceType + "
resources ");
+
+ iterate(resources, function(resource) {
+ resource.pluginConfiguration = loadPluginConfiguration(resource);
+ });
+
+ return resources;
+}
+
+function updatePluginConfigs(resources, applyDefaults) {
+ iterate(resources, function(resource) {
+ log("Preparing to update plugin configuration for " + resource)
+ applyDefaults(resource.pluginConfiguration);
+ ConfigurationManager.updatePluginConfiguration(resource.id,
resource.pluginConfiguration);
+ log("Updated plugin configuration for " + resource);
+ });
+}
+
+function resetJBossPluginConfigProps() {
+ var jbossResourceTypeName = 'JBossAS Server';
+ var jbossPluginName = 'JBossAS';
+ var jbossServers = findResourcesByTypeAndPlugin(jbossResourceTypeName,
jbossPluginName);
+
+ updatePluginConfigs(jbossServers, function(pluginConfig) {
+ pluginConfig.put(PropertySimple('snapshotConfigEnabled', true));
+ pluginConfig.put(PropertySimple('snapshotConfigDirectory',
'config'));
+ pluginConfig.put(PropertySimple('snapshotConfigRecursive', true));
+ pluginConfig.put(PropertySimple('snapshotLogEnabled', true));
+ pluginConfig.put(PropertySimple('snapshotLogDirectory', 'log'));
+ pluginConfig.put(PropertySimple('snapshotLogRecursive', false));
+ pluginConfig.put(PropertySimple('snapshotDataEnabled', false));
+ pluginConfig.put(PropertySimple('snapshotDataDirectory', 'data'));
+ pluginConfig.put(PropertySimple('snapshotDataRecursive', true));
+
+ var propertyMap = PropertyMap('snapshotAdditionalFilesMap');
+ propertyMap.put(PropertySimple('snapshotAdditionalFilesEnabled', true));
+ propertyMap.put(PropertySimple('snapshotAdditionalFilesDirectory',
''));
+ propertyMap.put(PropertySimple('snapshotAdditionalFilesRecursive', true));
+
+ var propertyList = PropertyList('snapshotAdditionalFilesList');
+ propertyList.list.add(propertyMap);
+
+ pluginConfig.put(propertyList);
+ });
+}
+
+function resetAgentPluginConfigProps() {
+ var agentResourceTypeName = 'RHQ Agent';
+ var agentPluginName = 'RHQAgent';
+ var agents = findResourcesByTypeAndPlugin(agentResourceTypeName, agentPluginName);
+
+ updatePluginConfigs(agents, function(pluginConfig) {
+ pluginConfig.put(PropertySimple('snapshotConfigEnabled', true));
+ pluginConfig.put(PropertySimple('snapshotLogEnabled', true));
+ pluginConfig.put(PropertySimple('snapshotDataEnabled', true));
+ });
+}
+
+//////////////
+// main //
+//////////////
+exec -f
+resetJBossPluginConfigProps();
+resetAgentPluginConfigProps();