From eafa09c2474bfea355d1762bac4d97ed3e54d9ed Mon Sep 17 00:00:00 2001 From: Chris Green Date: Tue, 17 Sep 2024 17:02:54 -0500 Subject: [PATCH] Move check of number of pool groups returned from server to client Per https://rb.dcache.org/r/14316/#comment29381 N.B. The MigrationModule itself appears to have no access to the `poolList` upon job completion to verify its parameters, so the size check on the map is currently implemented in `PoolListByPoolGroupOfPool.success()`. Please advise if this is incorrect. --- .../dcache/resilience/TestSelectionUnit.java | 5 -- ...nagerGetPoolsByPoolGroupOfPoolMessage.java | 29 ++++++++++- .../poolManager/PoolManagerV5.java | 29 +++++------ .../poolManager/PoolSelectionUnit.java | 2 - .../poolManager/PoolSelectionUnitV2.java | 19 ------- .../migration/PoolListByPoolGroupOfPool.java | 50 ++++++++++++++++++- 6 files changed, 88 insertions(+), 46 deletions(-) diff --git a/modules/dcache-resilience/src/test/java/org/dcache/resilience/TestSelectionUnit.java b/modules/dcache-resilience/src/test/java/org/dcache/resilience/TestSelectionUnit.java index 9b7467d96f9..ed4e71ca2e5 100644 --- a/modules/dcache-resilience/src/test/java/org/dcache/resilience/TestSelectionUnit.java +++ b/modules/dcache-resilience/src/test/java/org/dcache/resilience/TestSelectionUnit.java @@ -169,11 +169,6 @@ public Collection getPoolsByPoolGroup(String poolGroup) return psu.getPoolsByPoolGroup(poolGroup); } - @Override - public Collection getPoolsByPoolGroupOfPool(String poolName) throws NoSuchElementException { - return psu.getPoolsByPoolGroupOfPool(poolName); - } - @Override public String getProtocolUnit(String protocolUnitName) { return psu.getProtocolUnit(protocolUnitName); diff --git a/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsByPoolGroupOfPoolMessage.java b/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsByPoolGroupOfPoolMessage.java index 337e5f232a1..86475c02120 100644 --- a/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsByPoolGroupOfPoolMessage.java +++ b/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsByPoolGroupOfPoolMessage.java @@ -1,19 +1,44 @@ package diskCacheV111.vehicles; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import static java.util.Objects.requireNonNull; public class PoolManagerGetPoolsByPoolGroupOfPoolMessage - extends PoolManagerGetPoolsMessage { + extends Message { - private static final long serialVersionUID = 4423670920097918847L; + private static final long serialVersionUID = -4022990392097610436L; private final String _poolName; + private Map> _poolsMap; + private Collection _offlinePools; public PoolManagerGetPoolsByPoolGroupOfPoolMessage(String poolName) { + super(true); _poolName = requireNonNull(poolName); } public String getPoolName() { return _poolName; } + + public void setPoolsMap(Map> poolsMap) { + _poolsMap = new HashMap<>(poolsMap); + } + + public void setOfflinePools(Collection _offlinePools) { + this._offlinePools = _offlinePools; + } + + public Map> getPoolsMap() { + return _poolsMap; + } + + public Collection getOfflinePools() { + return (_offlinePools == null) ? Collections.emptyList() : _offlinePools; + } } diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java index efa379e9a61..80bc72b3f28 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java @@ -39,15 +39,7 @@ import dmg.cells.nucleus.DelayedReply; import java.io.PrintWriter; import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.StringTokenizer; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -528,17 +520,22 @@ private void getPoolInformation( public PoolManagerGetPoolsByPoolGroupOfPoolMessage messageArrived(PoolManagerGetPoolsByPoolGroupOfPoolMessage msg) { try { - List pools = new ArrayList<>(); + Collection poolGroups = + _selectionUnit.getPoolGroupsOfPool(msg.getPoolName()); + Map> poolsMap = new HashMap<>(); List offlinePools = new ArrayList<>(); - getPoolInformation(_selectionUnit.getPoolsByPoolGroupOfPool(msg.getPoolName()), pools, - offlinePools); - msg.setPools(pools); + for (PoolSelectionUnit.SelectionPoolGroup poolGroup : poolGroups) { + List pools = new ArrayList<>(); + getPoolInformation(_selectionUnit.getPoolsByPoolGroup(poolGroup.getName()), + pools, offlinePools); + poolsMap.put(poolGroup.getName(), pools); + } + msg.setPoolsMap(poolsMap); msg.setOfflinePools(offlinePools); msg.setSucceeded(); } catch (NoSuchElementException e) { - Collection empty = - Collections.emptyList(); - msg.setPools(empty); + Map> empty = new HashMap<>(); + msg.setPoolsMap(empty); msg.setSucceeded(); } return msg; diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java index a5d670e2c7d..1280678984c 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java @@ -282,8 +282,6 @@ boolean updatePool(String poolName, CellAddressCore address, String canonicalHos Collection getPoolsByPoolGroup(String poolGroup) throws NoSuchElementException; - Collection getPoolsByPoolGroupOfPool(String poolName) throws NoSuchElementException; - Collection getAllDefinedPools(boolean enabledOnly); Collection getPoolGroupsOfPool(String PoolName); diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java index 7888fbbfb45..1f45cc8cea5 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java @@ -2622,25 +2622,6 @@ public Collection getPoolsByPoolGroup(String poolGroup) return new ArrayList<>(group._poolList.values()); } - @Override - public Collection getPoolsByPoolGroupOfPool(String poolName) - throws NoSuchElementException { - Collection groups; - try { - groups = getPoolGroupsOfPool(poolName); - } catch (NoSuchElementException e) { - throw new NoSuchElementException("No pool group for nonexistent pool: " + poolName); - } - - if (groups.isEmpty()) { - throw new NoSuchElementException("No pool group for pool: " + poolName); - } else if (groups.size() > 1) { - throw new NoSuchElementException("No unique pool group for pool: " + poolName); - } - - return new ArrayList<>(groups.iterator().next().getPools()); - } - @Override public Collection getAllDefinedPools(boolean enabledOnly) { List pools = new ArrayList<>(_pools.size()); diff --git a/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListByPoolGroupOfPool.java b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListByPoolGroupOfPool.java index 5a6454e3aef..09f6a2c0482 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListByPoolGroupOfPool.java +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListByPoolGroupOfPool.java @@ -2,21 +2,55 @@ import static java.util.Objects.requireNonNull; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.MoreExecutors; +import diskCacheV111.vehicles.Pool; import diskCacheV111.vehicles.PoolManagerGetPoolsByPoolGroupOfPoolMessage; +import diskCacheV111.vehicles.PoolManagerPoolInformation; +import org.dcache.cells.AbstractMessageCallback; import org.dcache.cells.CellStub; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; class PoolListByPoolGroupOfPool - extends PoolListFromPoolManager { + extends AbstractMessageCallback + implements RefreshablePoolList { + + private static final Logger LOGGER = + LoggerFactory.getLogger(PoolListByPoolGroupOfPool.class); private final CellStub _poolManager; private final String _poolName; + private ImmutableMap> _poolsMap; + private ImmutableList _offlinePools = ImmutableList.of(); + + private boolean _isValid; public PoolListByPoolGroupOfPool(CellStub poolManager, String poolName) { _poolManager = requireNonNull(poolManager); _poolName = requireNonNull(poolName); } + @Override + public synchronized boolean isValid() { + return _isValid; + } + + @Override + public ImmutableList getOfflinePools() { + return _offlinePools; + } + + @Override + public ImmutableList getPools() { + return _poolsMap.isEmpty() ? + ImmutableList.of() : + ImmutableList.copyOf(_poolsMap.values().iterator().next()); + } + @Override public void refresh() { CellStub.addCallback( @@ -27,6 +61,18 @@ public void refresh() { @Override public String toString() { return String.format("source pool %s, %d pools", - _poolName, _pools.size()); + _poolName, getPools().size()); + } + + @Override + public void success(PoolManagerGetPoolsByPoolGroupOfPoolMessage message) { + _poolsMap = ImmutableMap.copyOf(message.getPoolsMap()); + _offlinePools = ImmutableList.copyOf(message.getOfflinePools()); + _isValid = (_poolsMap.size() == 1); + } + + @Override + public void failure(int rc, Object error) { + LOGGER.error("Failed to query pool manager ({})", error); } }