Skip to content

Commit

Permalink
Implement #6723
Browse files Browse the repository at this point in the history
  • Loading branch information
greenc-FNAL committed Sep 6, 2024
1 parent d74fd8a commit 369f3dc
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public Collection<SelectionPool> getPoolsByPoolGroup(String poolGroup)
return psu.getPoolsByPoolGroup(poolGroup);
}

@Override
public Collection<SelectionPool> getPoolsBySourcePoolPoolGroup(String sourcePool) throws NoSuchElementException {
return psu.getPoolsBySourcePoolPoolGroup(sourcePool);
}

@Override
public String getProtocolUnit(String protocolUnitName) {
return psu.getProtocolUnit(protocolUnitName);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -524,6 +525,25 @@ private void getPoolInformation(
return msg;
}

public PoolManagerGetPoolsBySourcePoolPoolGroupMessage
messageArrived(PoolManagerGetPoolsBySourcePoolPoolGroupMessage msg) {
try {
List<PoolManagerPoolInformation> pools = new ArrayList<>();
List<String> offlinePools = new ArrayList<>();
getPoolInformation(_selectionUnit.getPoolsBySourcePoolPoolGroup(msg.getSourcePool()), pools,
offlinePools);
msg.setPools(pools);
msg.setOfflinePools(offlinePools);
msg.setSucceeded();
} catch (NoSuchElementException e) {
Collection<PoolManagerPoolInformation> empty =
Collections.emptyList();
msg.setPools(empty);
msg.setSucceeded();
}
return msg;
}

public PoolManagerGetPoolsByPoolGroupMessage
messageArrived(PoolManagerGetPoolsByPoolGroupMessage msg) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ boolean updatePool(String poolName, CellAddressCore address, String canonicalHos

Collection<SelectionPool> getPoolsByPoolGroup(String poolGroup) throws NoSuchElementException;

Collection<SelectionPool> getPoolsBySourcePoolPoolGroup(String sourcePool) throws NoSuchElementException;

Collection<SelectionPool> getAllDefinedPools(boolean enabledOnly);

Collection<SelectionPoolGroup> getPoolGroupsOfPool(String PoolName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,25 @@ public Collection<SelectionPool> getPoolsByPoolGroup(String poolGroup)
return new ArrayList<>(group._poolList.values());
}

@Override
public Collection<SelectionPool> getPoolsBySourcePoolPoolGroup(String sourcePool)
throws NoSuchElementException {
Collection<SelectionPoolGroup> 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<SelectionPool> getAllDefinedPools(boolean enabledOnly) {
List<SelectionPool> pools = new ArrayList<>(_pools.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public class MigrationCopyCommand implements Callable<String> {
@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",
Expand Down Expand Up @@ -545,7 +545,12 @@ public class MigrationCopyCommand implements Callable<String> {

private RefreshablePoolList createPoolList(String type, List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 369f3dc

Please sign in to comment.