Skip to content

Commit

Permalink
libs: Update to Spring Framework 4.2
Browse files Browse the repository at this point in the history
Motivation:

Keep up to date with third party libraries.

Modification:

Property evaluation in UniversalSpringCell had to be adjusted due to API
changes. While at it, I fixed a number of undocumented or unnamed beans and
also updated the AlarmEnabledDataSource class to expose its delegate for easy
inspection in the admin shell.

Result:

Spring Framework 4.2.1

'bean properties' now exposes the delegate data source as
'data-source.delegate'.

Target: trunk
Require-notes: no
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: https://rb.dcache.org/r/8524/
  • Loading branch information
gbehrmann committed Sep 9, 2015
1 parent ce37d36 commit ccfe23d
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*/
package org.dcache.db;

import com.google.common.collect.ForwardingObject;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
Expand All @@ -83,8 +84,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*
* @author arossi
*/
public class AlarmEnabledDataSource implements DataSource, Closeable {

public class AlarmEnabledDataSource extends ForwardingObject implements DataSource, Closeable
{
private static final org.slf4j.Logger LOGGER =
LoggerFactory.getLogger(DataSource.class);

Expand All @@ -105,37 +106,49 @@ public AlarmEnabledDataSource(String url,
this.delegate = checkNotNull(delegate);
}

/** Accessor for admin shell. */
public DataSource getDelegate()
{
return delegate();
}

@Override
protected DataSource delegate()
{
return delegate;
}

@Override
public PrintWriter getLogWriter() throws SQLException {
return delegate.getLogWriter();
return delegate().getLogWriter();
}

@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(delegate)) {
return (T) delegate;
if (iface.isInstance(delegate())) {
return (T) delegate();
}
return delegate.unwrap(iface);
return delegate().unwrap(iface);
}

@Override
public void setLogWriter(PrintWriter out) throws SQLException {
delegate.setLogWriter(out);
delegate().setLogWriter(out);
}

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface.isInstance(delegate)) {
if (iface.isInstance(delegate())) {
return true;
}
return delegate.isWrapperFor(iface);
return delegate().isWrapperFor(iface);
}

@Override
public Connection getConnection() throws SQLException {
try {
return delegate.getConnection();
return delegate().getConnection();
} catch (SQLException sql) {
LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.DB_CONNECTION_FAILURE,
url,
Expand All @@ -148,15 +161,15 @@ public Connection getConnection() throws SQLException {

@Override
public void setLoginTimeout(int seconds) throws SQLException {
delegate.setLoginTimeout(seconds);
delegate().setLoginTimeout(seconds);
}

@Override
public Connection getConnection(String username, String password)
throws SQLException {

try {
return delegate.getConnection(username, password);
return delegate().getConnection(username, password);
} catch (SQLException sql) {
LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.DB_CONNECTION_FAILURE,
url,
Expand All @@ -169,18 +182,18 @@ public Connection getConnection(String username, String password)

@Override
public int getLoginTimeout() throws SQLException {
return delegate.getLoginTimeout();
return delegate().getLoginTimeout();
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return delegate.getParentLogger();
return delegate().getParentLogger();
}

@Override
public void close() throws IOException {
if (delegate instanceof Closeable) {
((Closeable) delegate).close();
if (delegate() instanceof Closeable) {
((Closeable) delegate()).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</bean>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
<property name="excludedDestinations" value="${pnfsmanager.destination.cache-notification}"/>
</bean>

Expand All @@ -38,13 +39,12 @@
<property name="flushNotificationTarget" value="${pnfsmanager.destination.flush-notification}"/>
</bean>

<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource">
<description>Connection pool decorator</description>
<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Database connection pool</description>
<constructor-arg value="${pnfsmanager.db.url}"/>
<constructor-arg value="JdbcFs"/>
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<description>Database connection pool</description>
<bean class="com.zaxxer.hikari.HikariDataSource">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<property name="jdbcUrl" value="${pnfsmanager.db.url}"/>
Expand All @@ -65,7 +65,8 @@
<property name="dataSource" ref="data-source"/>
</bean>

<bean class="org.dcache.util.aspects.PerInstanceAnnotationTransactionBeanPostProcessor">
<bean id="tx-annotation-processor" class="org.dcache.util.aspects.PerInstanceAnnotationTransactionBeanPostProcessor">
<description>Annotated transaction demarcation processor</description>
<property name="transactionManager" ref="tx-manager"/>
</bean>

Expand All @@ -77,6 +78,7 @@
</bean>

<bean id="file-system" class="org.dcache.chimera.JdbcFs" depends-on="liquibase">
<description>Chimera</description>
<constructor-arg ref="data-source"/>
<constructor-arg ref="tx-manager"/>
<constructor-arg value="${pnfsmanager.db.dialect}"/>
Expand All @@ -101,7 +103,7 @@
</bean>

<bean id="acl-admin" class="org.dcache.acl.AclAdmin">
<description>Provides commands for manipulating ACLs</description>
<description>ACL command line</description>
<property name="nameSpaceProvider" ref="name-space-provider"/>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<context:property-placeholder/>
<context:annotation-config/>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver"/>
<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
</bean>

<bean id="info" class="org.dcache.services.info.InfoProvider">
<description>support for CLI</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<context:property-placeholder/>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
<property name="excludedDestinations" value="${nfs.loginbroker.update-topic}"/>
</bean>

Expand Down Expand Up @@ -58,12 +59,11 @@
</bean>

<bean id="dataSource" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<description>Database connection pool</description>
<constructor-arg value="${nfs.db.url}"/>
<constructor-arg value="DCacheAwareJdbcFs"/>
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<description>Database connection pool</description>
<bean class="com.zaxxer.hikari.HikariDataSource">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<property name="jdbcUrl" value="${nfs.db.url}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<context:property-placeholder/>
<context:annotation-config/>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver"/>
<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
</bean>

<bean id="executor"
class="java.util.concurrent.Executors"
Expand Down Expand Up @@ -46,7 +48,7 @@


<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<description>Database connection pool</description>
<constructor-arg value="${spacemanager.db.url}"/>
<constructor-arg value="SpaceManager"/>
<constructor-arg>
Expand Down Expand Up @@ -78,8 +80,9 @@
<property name="dataSource" ref="data-source"/>
</bean>

<bean class="org.dcache.util.aspects.PerInstanceAnnotationTransactionBeanPostProcessor">
<property name="transactionManager" ref="tx-manager"/>
<bean id="tx-annotation-processor" class="org.dcache.util.aspects.PerInstanceAnnotationTransactionBeanPostProcessor">
<description>Annotated transaction demarcation processor</description>
<property name="transactionManager" ref="tx-manager"/>
</bean>

<bean id="authz-policy" class="diskCacheV111.services.space.SimpleSpaceManagerAuthorizationPolicy"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
-->

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
<property name="excludedDestinations"
value="${srm.loginbroker.update-topic},${srm.credential-service.topic}"/>
</bean>
Expand Down Expand Up @@ -641,12 +642,11 @@
-->

<bean id="data-source" class="org.dcache.db.AlarmEnabledDataSource" destroy-method="close">
<description>Connection pool decorator</description>
<description>Database connection pool</description>
<constructor-arg value="${srm.db.url}"/>
<constructor-arg value="Srm"/>
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariDataSource">
<description>Database connection pool</description>
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<property name="jdbcUrl" value="${srm.db.url}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</bean>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
<property name="excludedDestinations" value="${webdav.loginbroker.update-topic},${webdav.credential-service.topic}"/>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
</bean>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<property name="excludedDestinations" value="${xrootd.loginbroker.update-topic}"/>
<description>Undeliverable message logger</description>
<property name="excludedDestinations" value="${xrootd.loginbroker.update-topic}"/>
</bean>

<bean id="pool-stub" class="org.dcache.cells.CellStub">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.AbstractNestablePropertyAccessor;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
Expand Down Expand Up @@ -55,7 +56,6 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

import diskCacheV111.util.CacheException;

Expand Down Expand Up @@ -673,7 +673,7 @@ public class BeanPropertiesCommand implements Callable<String>
String name;

@Override
public String call()
public String call() throws InvalidPropertyException
{
Object o = getBeanProperty(name);
if (o != null) {
Expand All @@ -682,10 +682,14 @@ public String call()
for (PropertyDescriptor p : bean.getPropertyDescriptors()) {
String property = p.getName();
if (bean.isReadableProperty(property)) {
Object value = bean.getPropertyValue(property);
s.append(property).append('=').append(org.dcache.commons.util.Strings.toString(value));
if (!bean.isWritableProperty(property)) {
s.append(" [read-only]");
s.append(property).append('=');
try {
s.append(org.dcache.commons.util.Strings.toString(bean.getPropertyValue(property)));
if (!bean.isWritableProperty(property)) {
s.append(" [read-only]");
}
} catch (InvalidPropertyException e) {
s.append(" [invalid]");
}
s.append('\n');
}
Expand All @@ -703,7 +707,7 @@ public class BeanPropertyCommand implements Callable<String>
String name;

@Override
public String call()
public String call() throws InvalidPropertyException
{
Object o = getBeanProperty(name);
return (o != null) ? org.dcache.commons.util.Strings.toMultilineString(o) : ("No such property: " + name);
Expand Down Expand Up @@ -1095,7 +1099,7 @@ private RestrictedBeanWrapper(Object object, String nestedPath, Object rootObjec
}

@Override
protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath)
protected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath)
{
int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath);
if (pos > -1) {
Expand All @@ -1104,15 +1108,19 @@ protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath)
throw new NotReadablePropertyException(getRootClass(), nestedProperty);
}
}
return super.getBeanWrapperForPropertyPath(propertyPath);
return super.getPropertyAccessorForPropertyPath(propertyPath);
}

@Override
public boolean isReadableProperty(String propertyName)
{
if (isAllowedName(propertyName)) {
PropertyDescriptor pd = getPropertyDescriptorInternal(propertyName);
if (pd == null || pd.getReadMethod() != null && !pd.isHidden() && isAllowedType(pd.getPropertyType())) {
try {
PropertyDescriptor pd = getPropertyDescriptor(propertyName);
if (pd.getReadMethod() != null && !pd.isHidden() && isAllowedType(pd.getPropertyType())) {
return true;
}
} catch (InvalidPropertyException e) {
try {
Object value = super.getPropertyValue(propertyName);
if (value == null || isAllowedType(value.getClass())) {
Expand Down Expand Up @@ -1146,7 +1154,7 @@ public Object getPropertyValue(String propertyName) throws BeansException
}

@Override
protected BeanWrapperImpl newNestedBeanWrapper(Object object, String nestedPath) {
protected BeanWrapperImpl newNestedPropertyAccessor(Object object, String nestedPath) {
return new RestrictedBeanWrapper(object, nestedPath, this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<context:annotation-config/>

<bean id="noroutetocell" class="org.dcache.cells.LogNoRouteToCellExceptionReceiver">
<description>Undeliverable message logger</description>
<property name="excludedDestinations" value="${poolmanager.destination.pool-status}"/>
</bean>

Expand Down
Loading

0 comments on commit ccfe23d

Please sign in to comment.