use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.
the class RemoteNameSpaceProviderTests method shouldSucceedWhenGetCacheLocationForFileWithTwoLocations.
@Test
public void shouldSucceedWhenGetCacheLocationForFileWithTwoLocations() throws Exception {
givenSuccessfulResponse((Modifier<PnfsGetCacheLocationsMessage>) (r) -> r.setCacheLocations(Lists.newArrayList("pool-1", "pool-2")));
List<String> locations = _namespace.getCacheLocation(ROOT, A_PNFSID);
PnfsGetCacheLocationsMessage sent = getSingleSendAndWaitMessage(PnfsGetCacheLocationsMessage.class);
assertThat(sent.getReplyRequired(), is(true));
assertThat(sent.getSubject(), is(ROOT));
assertThat(sent.getPnfsId(), is(A_PNFSID));
assertThat(locations, hasSize(2));
assertThat(locations, hasItem("pool-1"));
assertThat(locations, hasItem("pool-2"));
}
use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.
the class LegacyAdminShell method ac_set_deletable_$_1.
public String ac_set_deletable_$_1(Args args) throws Exception {
checkPermission("*.*.*");
PnfsId pnfsId = new PnfsId(args.argv(0));
StringBuilder sb = new StringBuilder();
PnfsFlagMessage pfm = new PnfsFlagMessage(pnfsId, "d", PnfsFlagMessage.FlagOperation.SET);
pfm.setValue("true");
try {
pfm = (PnfsFlagMessage) sendObject("PnfsManager", pfm);
} catch (Exception ee) {
sb.append("Attempt to set 'd' flag reported an Exception : ").append(ee);
sb.append("\n");
sb.append("Operation aborted\n");
return sb.toString();
}
if (pfm.getReturnCode() != 0) {
sb.append("set 'd' flag reported : ").append(pfm.getErrorObject());
return sb.toString();
}
sb.append("Setting 'd' succeeded\n");
PnfsGetCacheLocationsMessage locations = new PnfsGetCacheLocationsMessage(pnfsId);
try {
locations = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", locations);
} catch (Exception ee) {
sb.append("Attempt to get cache locations reported an Exception : ").append(ee);
sb.append("\n");
sb.append("Operation aborted\n");
return sb.toString();
}
if (locations.getReturnCode() != 0) {
sb.append("Problem in getting cache location(s) : ").append(locations.getErrorObject());
return sb.toString();
}
List<String> assumedLocations = locations.getCacheLocations();
sb.append("Assumed cache locations : ").append(assumedLocations.toString()).append("\n");
for (Object assumedLocation : assumedLocations) {
String poolName = assumedLocation.toString();
PoolModifyPersistencyMessage p = new PoolModifyPersistencyMessage(poolName, pnfsId, false);
try {
p = (PoolModifyPersistencyMessage) sendObject(poolName, p);
} catch (Exception ee) {
sb.append("Attempt to contact ").append(poolName).append(" reported an Exception : ").append(ee.toString()).append("\n").append(" Operation continues\n");
continue;
}
if (locations.getReturnCode() != 0) {
sb.append("Set 'cached' reply from ").append(poolName).append(" : ").append(p.getErrorObject()).append("\n");
} else {
sb.append("Set 'cached' OK for ").append(poolName).append("\n");
}
}
return sb.toString();
}
use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.
the class LegacyAdminShell method uncache.
private String uncache(String destination, String target, StringBuffer sb) throws Exception {
if ((target == null) || (target.isEmpty())) {
target = "*";
}
boolean verbose = sb != null;
PnfsId pnfsId;
if (destination.startsWith("/pnfs")) {
PnfsGetFileAttributes map = new PnfsGetFileAttributes(destination, EnumSet.of(FileAttribute.PNFSID));
map.setFollowSymlink(false);
map = (PnfsGetFileAttributes) sendObject("PnfsManager", map);
if (map.getReturnCode() != 0) {
Object o = map.getErrorObject();
if (o instanceof Exception) {
throw (Exception) o;
} else {
throw new Exception(o.toString());
}
}
pnfsId = map.getFileAttributes().getPnfsId();
} else {
pnfsId = new PnfsId(destination);
}
checkPermission("pool.*.uncache");
PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage(pnfsId);
pnfsMessage = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", pnfsMessage);
if (pnfsMessage.getReturnCode() != 0) {
throw new FileNotFoundException(destination);
}
List<String> locations = pnfsMessage.getCacheLocations();
if (verbose) {
sb.append("Location(s) : ");
for (Object location : locations) {
sb.append(location.toString()).append(",");
}
sb.append("\n");
}
if (target.equals("*")) {
if (verbose) {
sb.append("Selection : <all>\n");
}
} else if (locations.contains(target)) {
if (verbose) {
sb.append("Selection : ").append(target).append("\n");
}
locations = new ArrayList<>();
locations.add(target);
} else {
if (verbose) {
sb.append("Selection : <nothing>\n");
}
return sb == null ? "" : sb.toString();
}
PoolRemoveFilesMessage remove;
for (Object location : locations) {
String poolName = location.toString();
if (verbose) {
sb.append(poolName).append(" : ");
}
try {
remove = new PoolRemoveFilesMessage(poolName, pnfsId.toString());
remove = (PoolRemoveFilesMessage) sendObject(poolName, remove);
if (verbose) {
int rc = remove.getReturnCode();
if (rc != 0) {
Object obj = remove.getErrorObject();
if ((obj != null) && (obj instanceof Object[])) {
Object o = ((Object[]) obj)[0];
if (o != null) {
sb.append("[").append(rc).append("] Failed ").append(o.toString());
}
} else if (obj != null) {
sb.append("[").append(rc).append("] Failed ").append(obj.toString());
}
} else {
sb.append("ok");
}
}
} catch (Exception ee) {
if (verbose) {
sb.append(ee.getMessage());
}
}
if (verbose) {
sb.append("\n");
}
}
return sb == null ? "" : sb.toString();
}
use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.
the class PnfsManagerV3 method getCacheLocations.
public void getCacheLocations(PnfsGetCacheLocationsMessage pnfsMessage) {
Subject subject = pnfsMessage.getSubject();
try {
checkRestriction(pnfsMessage, READ_METADATA);
PnfsId pnfsId = populatePnfsId(pnfsMessage);
LOGGER.info("get cache locations for {}", pnfsId);
checkMask(pnfsMessage);
pnfsMessage.setCacheLocations(_nameSpaceProvider.getCacheLocation(subject, pnfsId));
pnfsMessage.setSucceeded();
} catch (FileNotFoundCacheException fnf) {
pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, fnf.getMessage());
} catch (CacheException e) {
LOGGER.warn("Exception in getCacheLocations: {}", e.toString());
pnfsMessage.setFailed(e.getRc(), e.getMessage());
} catch (RuntimeException e) {
LOGGER.error("Exception in getCacheLocations", e);
pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs lookup failed");
}
}
use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.
the class PnfsHandler method getCacheLocationsByPath.
public List<String> getCacheLocationsByPath(String fileName) throws CacheException {
PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage();
pnfsMessage.setPnfsPath(fileName);
pnfsMessage = request(pnfsMessage);
List<String> assumedLocations = pnfsMessage.getCacheLocations();
if (assumedLocations == null) {
return Collections.emptyList();
} else {
return assumedLocations;
}
}
Aggregations