Skip to content

Commit

Permalink
gplazma: grid add interface to abstract SourceBackedPredicateMap
Browse files Browse the repository at this point in the history
Motivation:

The SourceBackedPredicateMap provides a concrete implementation of
access to (key-predicate,value) pairs.  However, to support new
approaches, it would be useful to allow alternative implementations of
this behaviour.

Modification:

Add an interface to abstract away concrete implementation.

Result:

No user- or admin observable changes.  Code is more flexible, in
preparation for future changes.

Target: master
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/13663/
Acked-by: Tigran Mkrtchyan
  • Loading branch information
paulmillar committed Sep 22, 2022
1 parent 9c91096 commit c5de48f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
Expand Up @@ -62,7 +62,7 @@ enum PrincipalType {UID, GID, LOGIN, USER, GROUP}
private final ImmutableList<PrincipalType> _uidOrder;
private final ImmutableList<PrincipalType> _gidOrder;

private final SourceBackedPredicateMap<String, UserAuthzInformation> _map;
private final PredicateMap<String, UserAuthzInformation> _map;

public AuthzDbPlugin(Properties properties) throws IOException {
String path = properties.getProperty(AUTHZDB);
Expand All @@ -84,7 +84,7 @@ public AuthzDbPlugin(Properties properties) throws IOException {
*
* @param map map of usernames to user information (e.q. uid/gid)
*/
AuthzDbPlugin(SourceBackedPredicateMap<String, UserAuthzInformation> map,
AuthzDbPlugin(PredicateMap<String, UserAuthzInformation> map,
ImmutableList<PrincipalType> uidOrder,
ImmutableList<PrincipalType> gidOrder) {
_map = map;
Expand Down
@@ -0,0 +1,36 @@
/* dCache - http://www.dcache.org/
*
* Copyright (C) 2022 Deutsches Elektronen-Synchrotron
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.dcache.gplazma.plugins;

import java.util.List;

/**
* Handle a list of items where each item is a key-predicate,value pair. Each
* key-predicate may be matched against some key.
* @param <K> The type of the keys.
* @param <V> The type of the values.
*/
public interface PredicateMap<K, V> {

/**
* Provide a list of items that match the supplied key.
* @param key the key to search for matching items.
* @return A list of values that match the supplied key.
*/
List<V> getValuesForPredicatesMatching(K key);
}
Expand Up @@ -18,7 +18,7 @@
* @param <TValue> type of values
* @author karsten
*/
class SourceBackedPredicateMap<TKey, TValue> {
class SourceBackedPredicateMap<TKey, TValue> implements PredicateMap<TKey, TValue> {

private static final Logger _log = LoggerFactory.getLogger(SourceBackedPredicateMap.class);

Expand All @@ -38,6 +38,7 @@ protected SourceBackedPredicateMap(LineSource source,
* @param key Key to be used to find corresponding values
* @return Collection of matching values
*/
@Override
public synchronized List<TValue> getValuesForPredicatesMatching(TKey key) {

if (_source.hasChanged()) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ public class VoRoleMapPlugin implements GPlazmaMappingPlugin {
private static final String VOROLEMAP =
"gplazma.vorolemap.file";

private final SourceBackedPredicateMap<NameRolePair, String> _map;
private final PredicateMap<NameRolePair, String> _map;

public VoRoleMapPlugin(Properties properties) throws IOException {
String path = properties.getProperty(VOROLEMAP);
Expand All @@ -51,7 +51,7 @@ public VoRoleMapPlugin(Properties properties) throws IOException {
*
* @param map map of dnfqans to usernames
*/
VoRoleMapPlugin(SourceBackedPredicateMap<NameRolePair, String> map) {
VoRoleMapPlugin(PredicateMap<NameRolePair, String> map) {
_map = map;
}

Expand Down
Expand Up @@ -36,13 +36,11 @@ public class AuthzDbPluginTest {
private final static URL TEST_FIXTURE =
Resources.getResource("org/dcache/gplazma/plugins/authzdb.fixture");

private SourceBackedPredicateMap<String, UserAuthzInformation> testFixture;
private PredicateMap<String, UserAuthzInformation> testFixture;

@Before
public void setup()
throws IOException {
testFixture =
new SourceBackedPredicateMap<>(new MemoryLineSource(
public void setup() throws IOException {
testFixture = new SourceBackedPredicateMap<>(new MemoryLineSource(
Resources.readLines(TEST_FIXTURE, Charset.defaultCharset())),
new AuthzMapLineParser());
}
Expand Down
Expand Up @@ -24,8 +24,7 @@ public class CachedAuthzMapTest {
private final static URL TEST_FIXTURE =
Resources.getResource("org/dcache/gplazma/plugins/authzdb-parser.fixture");

private SourceBackedPredicateMap<String, UserAuthzInformation>
loadFixture(URL fixture)
private PredicateMap<String, UserAuthzInformation> loadFixture(URL fixture)
throws IOException {
return new SourceBackedPredicateMap<>(
new MemoryLineSource(Resources.readLines(fixture, Charset.defaultCharset())),
Expand Down
Expand Up @@ -31,8 +31,7 @@ public class CachedVOMapTest {
private final static URL TEST_FIXTURE_NDGF =
Resources.getResource("org/dcache/gplazma/plugins/vorolemap-ndgf.fixture");

private SourceBackedPredicateMap<NameRolePair, String>
loadFixture(URL fixture)
private PredicateMap<NameRolePair, String> loadFixture(URL fixture)
throws IOException {
return new SourceBackedPredicateMap<>(
new MemoryLineSource(Resources.readLines(fixture, Charset.defaultCharset())),
Expand Down
Expand Up @@ -348,7 +348,7 @@ private void whenMapPluginCalledWith(Set<Principal> principals) throws Authentic

VOMapLineParser parser = new VOMapLineParser();

SourceBackedPredicateMap<NameRolePair, String> map =
PredicateMap<NameRolePair, String> map =
new SourceBackedPredicateMap<>(_source,
parser);

Expand Down

0 comments on commit c5de48f

Please sign in to comment.