-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
srm: allow sites to configure additional TExtraInfo for srmPing respo…
…nses An SRM server's response to a ping request allows the server to send an arbitrary list of key-value pairs back to the client. Currently, dCache SRM is hard-coded to provide two such key-value pairs: the implementation name ('dCache') and the dCache version. This patch allows an admin to configure any number of additional key-value pairs. This is achieved by the admin configuring dCache properties that have a specific prefix. This prefix is stripped and the resulting key-value pairs are added to the SRM ping response. The motivation is that we want to allow dCache to advertise admin-configurable hints to SRM clients. The most immediate one being to allow dCache to suggest how many concurrent bring-online requests a particular dCache instance can sustain. As a consequence of this design, the patch introduces generic support for prefix-based configuration. This may be used in other places; for example, when allowing admins to configure third-party libraries (e.g., Hikari). Known limitations of this patch: a. the "prefix" annotation (introduced to suppress info messages about non-system properties) and prefix used by ConfigurationMapFactoryBean are only "conincidentally" the same: any mismatch will not be detected. b. the prefix checking in ConfigurationProperties has terrible performance as the number of prefixes increases much beyond 1. This should be revisited if the prefix idea is reused elsewhere. c. the patch deliberately avoids using Java 8 constructs. This is because we may want to back-port this to supported branches. Target: master Requires-book: yes Requires-notes: yes Patch: https://rb.dcache.org/r/7591/ Acked-by: Gerd Behrmann Acked-by: Dmitry Litvintsev
- Loading branch information
1 parent
e128bd2
commit a90c4dc
Showing
11 changed files
with
242 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
modules/dcache/src/main/java/org/dcache/util/ConfigurationMapFactoryBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.dcache.util; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.springframework.beans.factory.FactoryBean; | ||
import org.springframework.beans.factory.annotation.Required; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import java.util.Map; | ||
|
||
import dmg.cells.nucleus.EnvironmentAware; | ||
import dmg.util.Formats; | ||
import dmg.util.Replaceable; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* The ConfigurationMapFactoryBean builds a Map from some (possibly empty) | ||
* subset of dCache configuration. The Bean takes a String prefix as an | ||
* argument. All configuration properties with a key that starts with this | ||
* prefix are used to build the map, all others are ignored. The map entries | ||
* are created by removing the prefix from matching property keys to form the | ||
* map-entry's key. The corresponding map-entry's value is the property value. | ||
*/ | ||
public class ConfigurationMapFactoryBean implements EnvironmentAware, | ||
FactoryBean<ImmutableMap<String,String>> | ||
{ | ||
private String _prefix; | ||
private Map<String,Object> _environment; | ||
private ImmutableMap<String,String> _object; | ||
|
||
@Override | ||
public void setEnvironment(Map<String, Object> environment) | ||
{ | ||
_environment = environment; | ||
} | ||
|
||
@Required | ||
public void setPrefix(String value) | ||
{ | ||
_prefix = checkNotNull(value) + ConfigurationProperties.PREFIX_SEPARATOR; | ||
} | ||
|
||
@PostConstruct | ||
private void buildMap() | ||
{ | ||
ImmutableMap.Builder<String,String> builder = ImmutableMap.builder(); | ||
|
||
Replaceable replaceable = new Replaceable() { | ||
@Override | ||
public String getReplacement(String name) | ||
{ | ||
Object value = _environment.get(name); | ||
return (value == null) ? null : value.toString().trim(); | ||
} | ||
}; | ||
|
||
int prefixLength = _prefix.length(); | ||
for (Map.Entry<String,Object> item : _environment.entrySet()) { | ||
String name = item.getKey(); | ||
if (item.getValue() instanceof String && name.startsWith(_prefix)) { | ||
String value = (String) item.getValue(); | ||
String key = name.substring(prefixLength); | ||
if (!key.isEmpty()) { | ||
builder.put(key, Formats.replaceKeywords(value, replaceable)); | ||
} | ||
} | ||
} | ||
|
||
_object = builder.build(); | ||
} | ||
|
||
@Override | ||
public ImmutableMap<String, String> getObject() throws Exception | ||
{ | ||
return _object; | ||
} | ||
|
||
@Override | ||
public Class<?> getObjectType() | ||
{ | ||
return ImmutableMap.class; | ||
} | ||
|
||
@Override | ||
public boolean isSingleton() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.