modules/core/dbutils/pom.xml | 2 modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 15 + modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceComponent.java | 35 +++ modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceDiscoveryComponent.java | 63 ++++++ modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java | 36 ++- modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java | 28 +- modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml | 99 +++++++++- 7 files changed, 245 insertions(+), 33 deletions(-)
New commits: commit c6706aed03df889e23102ea254b2d342141d8b9b Author: Jay Shaughnessy jshaughn@redhat.com Date: Mon Jan 9 15:45:21 2012 -0500
[Bug 772742 - DB upgrade gives "All Resources Role" an unintended permission] Fix the upgrade step that grants the bad permission. And add a new step to revoke it if it exists.
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml index 3350cdd..c18ffe1 100644 --- a/modules/core/dbutils/pom.xml +++ b/modules/core/dbutils/pom.xml @@ -15,7 +15,7 @@ <description>Database schema setup, upgrade and other utilities</description>
<properties> - <db.schema.version>2.117</db.schema.version> + <db.schema.version>2.118</db.schema.version> <rhq.ds.type-mapping>${rhq.test.ds.type-mapping}</rhq.ds.type-mapping> <rhq.ds.db-name>${rhq.test.ds.db-name}</rhq.ds.db-name> <rhq.ds.connection-url>${rhq.test.ds.connection-url}</rhq.ds.connection-url> diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml index 24c536d..c9b0bea 100644 --- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml +++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml @@ -3370,12 +3370,12 @@ </statement> </schema-directSQL>
- <!-- Now add modify the permissions to give all the roles with MANAGE_INVENTORY - the new MANAGE_REPOSITORIES privilege so that people's privs remain unchanged. --> + <!-- Now modify the permissions to give all the roles with MANAGE_INVENTORY, except for + all-resources-role, the new MANAGE_REPOSITORIES privilege so that privs remain unchanged. --> <schema-directSQL> <statement> INSERT INTO RHQ_PERMISSION (role_id, operation) - SELECT role_id, 15 FROM RHQ_PERMISSION WHERE operation = 1 + SELECT role_id, 15 FROM RHQ_PERMISSION WHERE operation = 1 AND NOT role_id = 2 </statement> </schema-directSQL> </schemaSpec> @@ -3831,6 +3831,15 @@ <!-- Remove an unwanted null consraint --> <schema-alterColumn table="RHQ_DRIFT_CHANGE_SET" column="DRIFT_DEFINITION_ID" nullable="TRUE" /> </schemaSpec> + + <schemaSpec version="2.118"> + <!-- Correct an earlier upgrade issue where 'All Resources Role' was granted MANAGE_REPOSITORIES. --> + <schema-directSQL> + <statement> + DELETE FROM RHQ_PERMISSION WHERE role_id = 2 AND operation = 15 + </statement> + </schema-directSQL> + </schemaSpec>
</dbupgrade> </target>
commit da342ac1a965e70e78eb088328fa3c0bdbbdbca7 Author: Jay Shaughnessy jshaughn@redhat.com Date: Mon Jan 9 15:34:07 2012 -0500
Fix an NPE issue generated for unavailable TC webapp resources. Also, tune down logging in general for unavailable TC server resources to help reduce noise in the agent log file. And get rid of a few compile warnings.
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java index bc843ef..98f861b 100644 --- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java +++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerComponent.java @@ -23,7 +23,6 @@ package org.jboss.on.plugins.tomcat;
import java.io.File; -import java.sql.SQLException; import java.util.Properties; import java.util.Set;
@@ -124,7 +123,7 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM */ private TomcatServerOperationsDelegate operationsDelegate;
- private ResourceContext resourceContext; + private ResourceContext<T> resourceContext;
// JMXComponent Implementation --------------------------------------------
@@ -134,7 +133,9 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM try { emsConnection = loadConnection(); } catch (Exception e) { - log.error("Component attempting to access a connection that could not be loaded"); + if (log.isTraceEnabled()) { + log.debug("Component attempting to access a connection that could not be loaded:" + e.getMessage()); + } }
return emsConnection; @@ -232,6 +233,7 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM if (log.isDebugEnabled()) log.debug("Successfully made connection to the Tomcat Server for resource [" + this.resourceContext.getResourceKey() + "]"); + } catch (Exception e) {
// The connection will be established even in the case that the principal cannot be authenticated, @@ -239,8 +241,9 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM // the connection is established. If we get to this point that an exception was thrown, close any // connection that was made and null it out so we can try to establish it again. if (this.connection != null) { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Connection created but an exception was thrown. Closing the connection.", e); + } try { this.connection.close(); } catch (Exception e2) { @@ -250,19 +253,21 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM }
// Since the connection is attempted each time it's used, failure to connect could result in log - // file spamming. Log it once for every 10 consecutive times it's encountered. - if (consecutiveConnectionErrors % 10 == 0) { - log.warn( - "Could not establish connection to the Tomcat instance [" + (consecutiveConnectionErrors + 1) - + "] times for resource [" + resourceContext.getResourceKey() + "]", e); + // file spamming. Log a warning only one time outside of debug mode, and throttle even in debug + // mode (once for every 10 connect errors). + if (0 == consecutiveConnectionErrors) { + log.warn("Could not connect to the Tomcat instance for resource [" + + resourceContext.getResourceKey() + "] (enable debug logging for more info): " + + e.getMessage()); }
- if (log.isDebugEnabled()) + if (log.isDebugEnabled() && (consecutiveConnectionErrors % 10 == 0)) { log.debug( - "Could not connect to the Tomcat instance for resource [" + resourceContext.getResourceKey() - + "]", e); + "Could not establish connection to the Tomcat instance [" + (consecutiveConnectionErrors + 1) + + "] times for resource [" + resourceContext.getResourceKey() + "]", e); + }
- consecutiveConnectionErrors++; + ++consecutiveConnectionErrors;
throw e; } @@ -293,7 +298,8 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM } }
- public void start(ResourceContext context) throws SQLException { + @Override + public void start(ResourceContext<T> context) throws InvalidPluginConfigurationException, Exception { this.resourceContext = context; this.operationsDelegate = new TomcatServerOperationsDelegate(this, resourceContext.getSystemInformation());
@@ -360,7 +366,7 @@ public class TomcatServerComponent<T extends ResourceComponent<?>> implements JM } }
- ResourceContext getResourceContext() { + ResourceContext<T> getResourceContext() { return this.resourceContext; }
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java index 9ecc0d7..d1c0f59 100644 --- a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java +++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatWarComponent.java @@ -349,13 +349,13 @@ public class TomcatWarComponent extends MBeanResourceComponent<TomcatVHostCompon throw new IllegalStateException("Could not find MBean for WAR '" + getApplicationName() + "'."); }
- EmsOperation mbeanOperation = this.webModuleMBean.getOperation(name); + // NOTE: None of the supported operations have any parameters or return values, which makes our job easier. + EmsOperation mbeanOperation = this.webModuleMBean.getOperation(name, new Class[0]); if (mbeanOperation == null) { throw new IllegalStateException("Operation [" + name + "] not found on bean [" + this.webModuleMBean.getBeanName() + "]"); }
- // NOTE: None of the supported operations have any parameters or return values, which makes our job easier. Object[] paramValues = new Object[0]; mbeanOperation.invoke(paramValues);
@@ -417,12 +417,15 @@ public class TomcatWarComponent extends MBeanResourceComponent<TomcatVHostCompon String webModuleMBeanName = getWebModuleMBeanName(); EmsBean result = null;
- if (webModuleMBeanName != null) { - ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(webModuleMBeanName); - List<EmsBean> mBeans = getEmsConnection().queryBeans(queryUtility.getTranslatedQuery()); - // There should only be one mBean for this match. - if (mBeans.size() == 1) { - result = mBeans.get(0); + if (null != webModuleMBeanName) { + EmsConnection conn = getEmsConnection(); + if (null != conn) { + ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(webModuleMBeanName); + List<EmsBean> mBeans = conn.queryBeans(queryUtility.getTranslatedQuery()); + // There should only be one mBean for this match. + if (mBeans.size() == 1) { + result = mBeans.get(0); + } } }
@@ -449,8 +452,8 @@ public class TomcatWarComponent extends MBeanResourceComponent<TomcatVHostCompon private List<EmsBean> getVHosts() { EmsConnection emsConnection = getEmsConnection(); String query = QUERY_TEMPLATE_HOST; - query = query.replace("%PATH%", getResourceContext().getPluginConfiguration().getSimpleValue( - PROPERTY_CONTEXT_ROOT, "")); + query = query.replace("%PATH%", + getResourceContext().getPluginConfiguration().getSimpleValue(PROPERTY_CONTEXT_ROOT, "")); ObjectNameQueryUtility queryUtil = new ObjectNameQueryUtility(query); List<EmsBean> mBeans = emsConnection.queryBeans(queryUtil.getTranslatedQuery()); return mBeans; @@ -741,9 +744,8 @@ public class TomcatWarComponent extends MBeanResourceComponent<TomcatVHostCompon
File file = new File(fileName); if (!file.exists()) { - log - .warn("Could not delete web application files (perhaps removed manually?). Proceeding with resource removal for: " - + fileName); + log.warn("Could not delete web application files (perhaps removed manually?). Proceeding with resource removal for: " + + fileName); } else { deleteApp(pluginConfiguration, file, false, true); }
commit 791205857b2e3550e51ea1e101b8a4704ebfad33 Author: Jay Shaughnessy jshaughn@redhat.com Date: Mon Jan 9 15:32:22 2012 -0500
[Bug 703562 - Tomcat plugin missing support for JNDI configured Datasources] Added support for Datasources. Tomcat allows DS Resource declaration at the global/host/app level. A global DS is available to all apps, a host DS is available to all apps for that host, and then at the app level, just the declaring app. As such Tomcat creates DS Mbeans at the app level, one for each DS available to the app. This structure is reflected in the updated Tomcat resource hierarchy. Although there is seeming redundancy for global amd host level datasources, it seems to best reflect the TC intents, and also the underlying mbeans.
For more on configuring datasources see: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceComponent.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceComponent.java new file mode 100644 index 0000000..df74483 --- /dev/null +++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceComponent.java @@ -0,0 +1,35 @@ +/* + * RHQ Management Platform + * Copyright (C) 2012 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 as published by + * the Free Software Foundation version 2 of the License. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.jboss.on.plugins.tomcat; + +import org.rhq.plugins.jmx.MBeanResourceComponent; + +/** + * Handle generic information about an application cache + * + * @author Jay Shaughnessy + * + */ +public class TomcatDatasourceComponent extends MBeanResourceComponent<TomcatWarComponent> { + + public static final String PROPERTY_HOST = "host"; + public static final String PROPERTY_PATH = "path"; + +} diff --git a/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceDiscoveryComponent.java b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceDiscoveryComponent.java new file mode 100644 index 0000000..4749544 --- /dev/null +++ b/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatDatasourceDiscoveryComponent.java @@ -0,0 +1,63 @@ +/* + * RHQ Management Platform + * Copyright (C) 2012 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 as published by + * the Free Software Foundation version 2 of the License. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.jboss.on.plugins.tomcat; + +import java.util.Set; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails; +import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext; +import org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent; + +/** + * Discover Application Datasource + * + * @author Jay Shaughnessy + */ +public class TomcatDatasourceDiscoveryComponent extends MBeanResourceDiscoveryComponent<TomcatWarComponent> { + + @Override + public Set<DiscoveredResourceDetails> discoverResources( + ResourceDiscoveryContext<TomcatWarComponent> discoveryContext) { + + Configuration defaultPluginConfig = discoveryContext.getDefaultPluginConfiguration(); + String objectNameTemplate = defaultPluginConfig.getSimple(PROPERTY_OBJECT_NAME).getStringValue(); + String host = discoveryContext.getParentResourceContext().getPluginConfiguration() + .getSimpleValue(TomcatWarComponent.PROPERTY_VHOST, null); + String path = discoveryContext.getParentResourceContext().getPluginConfiguration() + .getSimpleValue(TomcatWarComponent.PROPERTY_CONTEXT_ROOT, null); + objectNameTemplate = objectNameTemplate.replace("%host%", host); + objectNameTemplate = objectNameTemplate.replace("%path%", path); + defaultPluginConfig.put(new PropertySimple(PROPERTY_OBJECT_NAME, objectNameTemplate)); + + Set<DiscoveredResourceDetails> resources = super.performDiscovery(defaultPluginConfig, + discoveryContext.getParentResourceComponent(), discoveryContext.getResourceType()); + + for (DiscoveredResourceDetails detail : resources) { + Configuration pluginConfiguration = detail.getPluginConfiguration(); + pluginConfiguration.put(new PropertySimple(TomcatDatasourceComponent.PROPERTY_HOST, host)); + pluginConfiguration.put(new PropertySimple(TomcatDatasourceComponent.PROPERTY_PATH, path)); + String resourceName = detail.getResourceName(); + detail.setResourceName(resourceName); + } + return resources; + } +} diff --git a/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml index a5277a8..e86f1d5 100644 --- a/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/tomcat/src/main/resources/META-INF/rhq-plugin.xml @@ -576,7 +576,103 @@ description="Pathname to a scratch directory to be provided by this Context for temporary read-write use by servlets within the associated web application. This directory will be made visible to servlets in the web application by a servlet context attribute (of type java.io.File) named javax.servlet.context.tempdir as described in the Servlet Specification. If not specified, a suitable directory underneath $CATALINA_BASE/work will be provided." required="false" /> </c:group> - </resource-configuration> + </resource-configuration> + + <service + name="Tomcat Datasource" + discovery="TomcatDatasourceDiscoveryComponent" + class="TomcatDatasourceComponent" + description="A Tomcat Application (WAR) Datasource" + singleton="false"> + + <plugin-configuration> + <c:group name="General"> + <c:simple-property + name="objectName" + readOnly="true" + default="Catalina:type=DataSource,path=%path%,host=%host%,class=javax.sql.DataSource,name=%name%" /> + </c:group> + + <c:group + name="Advanced" + hiddenByDefault="true"> + <c:simple-property + name="name" + type="string" + readOnly="true" + description="The virtual host" /> + <c:simple-property + name="host" + description="The datasource host" + readOnly="true" /> + <c:simple-property + name="path" + description="The datasource application path" + readOnly="true" /> + <c:simple-property + name="nameTemplate" + default="{name}" /> + <c:simple-property + name="descriptionTemplate" + default="Tomcat Web Application Datasource" + readOnly="true" /> + </c:group> + </plugin-configuration> + + <metric + property="numActive" + displayType="summary" + description="Number of active connections in the pool" /> + <metric + property="numIdle" + displayType="summary" + description="Number of idle connections in the pool" /> + + <resource-configuration> + <c:group name="Attributes"> + <c:simple-property + name="initialSize" + type="integer" + description="The initial number of connections that are created when the pool is started. Default is 0." /> + <c:simple-property + name="maxActive" + type="integer" + description="The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit. Default is 8." /> + <c:simple-property + name="maxIdle" + type="integer" + description="The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit. Default is 8." /> + <c:simple-property + name="minIdle" + type="integer" + description="The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none. Default is 0." /> + <c:simple-property + name="maxWait" + type="integer" + description="The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely. Default is indefinitely." /> + <c:simple-property + name="poolPreparedStatements" + type="boolean" + description="Enable prepared statement pooling for this pool. Default is false." /> + <c:simple-property + name="maxOpenPreparedStatements" + type="integer" + description="The maximum number of open statements that can be allocated from the statement pool at the same time, or zero for no limit. Default is unlimited." /> + <c:simple-property + name="removeAbandoned" + type="boolean" + description="Flag to remove abandoned connections if they exceed the removeAbandonedTimout. If set to true a connection is considered abandoned and eligible for removal if it has been idle longer than the removeAbandonedTimeout. Setting this to true can recover db connections from poorly written applications which fail to close a connection. Default is false." /> + <c:simple-property + name="removeAbandonedTimeout" + type="integer" + description="Timeout in seconds before an abandoned connection can be removed. Default is 300." /> + <c:simple-property + name="logAbandoned" + type="boolean" + description="Flag to log stack traces for application code which abandoned a Statement or Connection. Logging of abandoned Statements and Connections adds overhead for every Connection open or new Statement because a stack trace has to be generated. Default is false." /> + </c:group> + </resource-configuration> + </service>
<service name="Tomcat Cache" @@ -630,6 +726,7 @@ property="cacheMaxSize" description="Maximum number of cache entries" /> </service> + </service>
</service>
rhq-commits@lists.fedorahosted.org