From a714c20dfd96b379b35a30b3eb5b23f8fad928c7 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Fri, 6 Sep 2024 13:33:08 -0500 Subject: [PATCH] Implement #7623 --- .../dcache/resilience/TestSelectionUnit.java | 5 +++ ...rGetPoolsBySourcePoolPoolGroupMessage.java | 19 +++++++++++ .../poolManager/PoolManagerV5.java | 20 ++++++++++++ .../poolManager/PoolSelectionUnit.java | 2 ++ .../poolManager/PoolSelectionUnitV2.java | 19 +++++++++++ .../pool/migration/MigrationModule.java | 9 ++++-- .../PoolListBySourcePoolPoolGroup.java | 32 +++++++++++++++++++ 7 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsBySourcePoolPoolGroupMessage.java create mode 100644 modules/dcache/src/main/java/org/dcache/pool/migration/PoolListBySourcePoolPoolGroup.java 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 ed4e71ca2e5..f1d633482c8 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,6 +169,11 @@ public Collection getPoolsByPoolGroup(String poolGroup) return psu.getPoolsByPoolGroup(poolGroup); } + @Override + public Collection getPoolsBySourcePoolPoolGroup(String sourcePool) throws NoSuchElementException { + return psu.getPoolsBySourcePoolPoolGroup(sourcePool); + } + @Override public String getProtocolUnit(String protocolUnitName) { return psu.getProtocolUnit(protocolUnitName); diff --git a/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsBySourcePoolPoolGroupMessage.java b/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsBySourcePoolPoolGroupMessage.java new file mode 100644 index 00000000000..391369ebe60 --- /dev/null +++ b/modules/dcache-vehicles/src/main/java/diskCacheV111/vehicles/PoolManagerGetPoolsBySourcePoolPoolGroupMessage.java @@ -0,0 +1,19 @@ +package diskCacheV111.vehicles; + +import static java.util.Objects.requireNonNull; + +public class PoolManagerGetPoolsBySourcePoolPoolGroupMessage + extends PoolManagerGetPoolsMessage { + + private static final long serialVersionUID = 4423670920097918847L; + + private final String _sourcePool; + + public PoolManagerGetPoolsBySourcePoolPoolGroupMessage(String sourcePool) { + _sourcePool = requireNonNull(sourcePool); + } + + public String getSourcePool() { + return _sourcePool; + } +} diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java index 33441a26888..56df36c2277 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java @@ -18,6 +18,7 @@ import diskCacheV111.vehicles.PoolManagerGetPoolsByLinkMessage; import diskCacheV111.vehicles.PoolManagerGetPoolsByNameMessage; import diskCacheV111.vehicles.PoolManagerGetPoolsByPoolGroupMessage; +import diskCacheV111.vehicles.PoolManagerGetPoolsBySourcePoolPoolGroupMessage; import diskCacheV111.vehicles.PoolManagerPoolInformation; import diskCacheV111.vehicles.PoolManagerPoolModeMessage; import diskCacheV111.vehicles.PoolManagerPoolUpMessage; @@ -524,6 +525,25 @@ private void getPoolInformation( return msg; } + public PoolManagerGetPoolsBySourcePoolPoolGroupMessage + messageArrived(PoolManagerGetPoolsBySourcePoolPoolGroupMessage msg) { + try { + List pools = new ArrayList<>(); + List offlinePools = new ArrayList<>(); + getPoolInformation(_selectionUnit.getPoolsBySourcePoolPoolGroup(msg.getSourcePool()), pools, + offlinePools); + msg.setPools(pools); + msg.setOfflinePools(offlinePools); + msg.setSucceeded(); + } catch (NoSuchElementException e) { + Collection empty = + Collections.emptyList(); + msg.setPools(empty); + msg.setSucceeded(); + } + return msg; + } + public PoolManagerGetPoolsByPoolGroupMessage messageArrived(PoolManagerGetPoolsByPoolGroupMessage msg) { try { diff --git a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java index 1280678984c..b72ce07fe9d 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnit.java @@ -282,6 +282,8 @@ boolean updatePool(String poolName, CellAddressCore address, String canonicalHos Collection getPoolsByPoolGroup(String poolGroup) throws NoSuchElementException; + Collection getPoolsBySourcePoolPoolGroup(String sourcePool) 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 1f45cc8cea5..4229c0f949f 100644 --- a/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java +++ b/modules/dcache/src/main/java/diskCacheV111/poolManager/PoolSelectionUnitV2.java @@ -2622,6 +2622,25 @@ public Collection getPoolsByPoolGroup(String poolGroup) return new ArrayList<>(group._poolList.values()); } + @Override + public Collection getPoolsBySourcePoolPoolGroup(String sourcePool) + throws NoSuchElementException { + Collection groups; + try { + groups = getPoolGroupsOfPool(sourcePool); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("No pool group for nonexistent source pool: " + sourcePool); + } + + if (groups.isEmpty()) { + throw new NoSuchElementException("No pool group for source pool: " + sourcePool); + } else if (groups.size() > 1) { + throw new NoSuchElementException("No unique pool group for source pool: " + sourcePool); + } + + 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/MigrationModule.java b/modules/dcache/src/main/java/org/dcache/pool/migration/MigrationModule.java index 7f6ff57045c..08ec19c3657 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/migration/MigrationModule.java +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/MigrationModule.java @@ -487,7 +487,7 @@ public class MigrationCopyCommand implements Callable { @Option(name = "target", values = {"pool", "pgroup", "link", "hsm"}, category = "Target options", usage = "Determines the interpretation of the target names.") - String target = "pool"; + String target = null; @Option(name = "meta-only", category = "Target options", @@ -545,7 +545,12 @@ public class MigrationCopyCommand implements Callable { private RefreshablePoolList createPoolList(String type, List targets) { CellStub poolManager = _context.getPoolManagerStub(); - + if (type == null) { + type = "pgroup"; + if (targets.isEmpty()) { + return new PoolListBySourcePoolPoolGroup(poolManager, _context.getPoolName()); + } + } switch (type) { case "pool": return new PoolListByNames(poolManager, targets); diff --git a/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListBySourcePoolPoolGroup.java b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListBySourcePoolPoolGroup.java new file mode 100644 index 00000000000..133e9ffeb8b --- /dev/null +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolListBySourcePoolPoolGroup.java @@ -0,0 +1,32 @@ +package org.dcache.pool.migration; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.MoreExecutors; +import diskCacheV111.vehicles.PoolManagerGetPoolsBySourcePoolPoolGroupMessage; +import org.dcache.cells.CellStub; + +class PoolListBySourcePoolPoolGroup + extends PoolListFromPoolManager { + + private final CellStub _poolManager; + private final String _sourcePool; + + public PoolListBySourcePoolPoolGroup(CellStub poolManager, String sourcePool) { + _poolManager = requireNonNull(poolManager); + _sourcePool = requireNonNull(sourcePool); + } + + @Override + public void refresh() { + CellStub.addCallback( + _poolManager.send(new PoolManagerGetPoolsBySourcePoolPoolGroupMessage(_sourcePool)), + this, MoreExecutors.directExecutor()); + } + + @Override + public String toString() { + return String.format("source pool %s, %d pools", + _sourcePool, _pools.size()); + } +}