Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 loadPluginConfigDef(resourceTypeName, 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 findJBossServers() {
- criteria = new ResourceCriteria();
- criteria.addFilterResourceTypeName('JBossAS Server');
- criteria.addFilterPluginName('JBossAS');
- criteria.fetchPluginConfiguration(true);
- criteria.strict = true;
- return ResourceManager.findResourcesByCriteria(criteria);
- }
- function findAgents() {
- criteria = new ResourceCriteria();
- criteria.addFilterResourceTypeName('RHQ Agent');
- criteria.addFilterPluginName('RHQAgent');
- criteria.fetchPluginConfiguration(true);
- criteria.strict = true;
- return ResourceManager.findResourcesByCriteria(criteria);
- }
- 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;
- }
- function flattenPropertyDefs(configDef) {
- var propertyDefs = java.util.HashMap();
- iterate(configDef.propertyDefinitions.values(), function(propertyDef) {
- if (propertyDef instanceof PropertyDefinitionSimple) {
- propertyDefs.put(propertyDef.name, propertyDef);
- }
- else if (propertyDef instanceof PropertyDefinitionMap) {
- propertyDefs.putAll(flattenPropertyDefinitionMap(propertyDef));
- }
- else if (propertyDef instanceof PropertyDefinitionList) {
- propertyDefs.putAll(flattenPropertyDefinitionList(propertyDef));
- }
- });
- return propertyDefs
- }
- function flattenPropertyDefinitionMap(propertyDefMap) {
- var propertyDefs = java.util.HashMap();
- iterate(propertyDefMap.propertyDefinitions.values(), function(propertyDef) {
- if (propertyDef instanceof PropertyDefinitionSimple) {
- propertyDefs.put(propertyDef.name, propertyDef);
- }
- else if (propertyDef instanceof PropertyDefinitionMap) {
- propertyDefs.putAll(flattenPropertyDefinitionMap(propertyDef));
- }
- else if (propertyDef instanceof PropertyDefinitionList) {
- propertyDefs.putAll(flattenPropertyDefinitionList(propertyDef));
- }
- });
- return propertyDefs;
- }
- function flattenPropertyDefinitionList(propertyDefList) {
- var propertyDefs = java.util.HashMap();
- if (propertyDefList.memberDefinition instanceof PropertyDefinitionSimple) {
- propertyDefs.put(propertyDefList.memberDefinition.name);
- }
- else if (propertyDefList.memberDefinition instanceof PropertyDefinitionMap) {
- propertyDefs.putAll(flattenPropertyDefinitionMap(propertyDefList.memberDefinition));
- }
- else if (propertyDefList.memberDefinition instanceof PropertyDefinitionList) {
- propertyDefs.putAll(flattenPropertyDefinitionList(propertyDefList.memberDefinition));
- }
- return propertyDefs;
- }
- function isRequiredJBossSnapshotProperty(property) {
- return jbossSnapshotPropertyDefs.containsKey(property.name);
- }
- function isRequiredAgentSnapshotProperty(property) {
- return agentSnapshotPropertyDefs.containsKey(property.name);
- }
- function loadJBossSnapshotPropertyDefs() {
- var snapshotPropertyDefs = java.util.HashMap();
- var propertyDefs = flattenPropertyDefs(jbossPluginConfigDef);
- snapshotPropertyDefs.put('snapshotConfigEnabled', propertyDefs.get('snapshotConfigEnabled'));
- snapshotPropertyDefs.put('snapshotConfigDirectory', propertyDefs.get('snapshotConfigDirectory'));
- snapshotPropertyDefs.put('snapshotConfigRecursive', propertyDefs.get('snapshotConfigRecursive'));
- snapshotPropertyDefs.put('snapshotLogEnabled', propertyDefs.get('snapshotLogEnabled'));
- snapshotPropertyDefs.put('snapshotLogDirectory', propertyDefs.get('snapshotLogDirectory'));
- snapshotPropertyDefs.put('snapshotLogRecursive', propertyDefs.get('snapshotLogRecursive'));
- snapshotPropertyDefs.put('snapshotDataEnabled', propertyDefs.get('snapshotDataEnabled'));
- snapshotPropertyDefs.put('snapshotDataDirectory', propertyDefs.get('snapshotDataDirectory'));
- snapshotPropertyDefs.put('snapshotDataRecursive', propertyDefs.get('snapshotDataRecursive'));
- snapshotPropertyDefs.put('snapshotAdditionalFilesEnabled', propertyDefs.get('snapshotAdditionalFilesEnabled'));
- snapshotPropertyDefs.put('snapshotAdditionalFilesDirectory', propertyDefs.get('snapshotAdditionalFilesDirectory'));
- snapshotPropertyDefs.put('snapshotAdditionalFilesRegex', propertyDefs.get('snapshotAdditionalFilesRegex'));
- snapshotPropertyDefs.put('snapshotAdditionalFilesRecursive', propertyDefs.get('snapshotAdditionalFilesRecursive'));
- return snapshotPropertyDefs;
- }
- function loadAgentSnapshotPropertyDefs() {
- var snapshotPropertyDefs = new java.util.HashMap();
- var propertyDefs = flattenPropertyDefs(agentPluginConfigDef);
- snapshotPropertyDefs.put('snapshotConfigEnabled', propertyDefs.get('snapshotConfigEnabled'));
- snapshotPropertyDefs.put('snapshotLogEnabled', propertyDefs.get('snapshotLogEnabled'));
- snapshotPropertyDefs.put('snapshotDataEnabled', propertyDefs.get('snapshotDataEnabled'));
- return snapshotPropertyDefs;
- }
- function resetPluginConfigProps(resources, snapshotPropertyDefs) {
- iterate(resources, function(resource) {
- var simpleProperties = flattenProperties(resource.pluginConfiguration);
- var snapshotProperties = filter(simpleProperties, function(property) {
- return snapshotPropertyDefs.containsKey(property.name);
- });
- iterate(snapshotProperties, function(property) {
- var propertyDef = snapshotPropertyDefs.get(property.name);
- if (propertyDef.defaultValue == null) {
- println("Warning: default for " + propertyDef.name + " is null");
- }
- property.stringValue = propertyDef.defaultValue;
- });
- ConfigurationManager.updatePluginConfiguration(resource.id, resource.pluginConfiguration);
- });
- }
- //////////////
- // main //
- //////////////
- jbossResourceTypeName = 'JBossAS Server';
- jbossPluginName = 'JBossAS';
- agentResourceTypeName = 'RHQ Agent';
- agentPluginName = 'RHQAgent';
- jbossPluginConfigDef = loadPluginConfigDef(jbossResourceTypeName, jbossPluginName);
- jbossSnapshotPropertyDefs = loadJBossSnapshotPropertyDefs();
- agentPluginConfigDef = loadPluginConfigDef(agentResourceTypeName, agentPluginName);
- agentSnapshotPropertyDefs = loadAgentSnapshotPropertyDefs(agentPluginConfigDef);
- resetPluginConfigProps(findJBossServers(), jbossSnapshotPropertyDefs);
- resetPluginConfigProps(findAgents(), agentSnapshotPropertyDefs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement