use of diskCacheV111.vehicles.PnfsMessage 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.PnfsMessage in project dcache by dCache.
the class PnfsManagerV3 method updateFlag.
private void updateFlag(PnfsFlagMessage pnfsMessage) {
PnfsId pnfsId = pnfsMessage.getPnfsId();
PnfsFlagMessage.FlagOperation operation = pnfsMessage.getOperation();
String flagName = pnfsMessage.getFlagName();
String value = pnfsMessage.getValue();
Subject subject = pnfsMessage.getSubject();
LOGGER.info("update flag " + operation + " flag=" + flagName + " value=" + value + " for " + pnfsId);
try {
// Note that dcap clients may bypass restrictions by not
// specifying a path when interacting via mounted namespace.
checkRestriction(pnfsMessage, UPDATE_METADATA);
if (operation == PnfsFlagMessage.FlagOperation.GET) {
pnfsMessage.setValue(updateFlag(subject, pnfsId, operation, flagName, value));
} else {
updateFlag(subject, pnfsId, operation, flagName, value);
}
} catch (FileNotFoundCacheException e) {
pnfsMessage.setFailed(e.getRc(), e.getMessage());
} catch (CacheException e) {
LOGGER.warn("Exception in updateFlag: " + e);
pnfsMessage.setFailed(e.getRc(), e.getMessage());
} catch (RuntimeException e) {
LOGGER.error("Exception in updateFlag", e);
pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
}
}
use of diskCacheV111.vehicles.PnfsMessage 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.PnfsMessage in project dcache by dCache.
the class PnfsManagerV3 method createEntry.
public void createEntry(PnfsCreateEntryMessage pnfsMessage) {
checkArgument(pnfsMessage.getFileAttributes().isDefined(TYPE));
FileAttributes assign = pnfsMessage.getFileAttributes();
FileType type = assign.removeFileType();
Subject subject = pnfsMessage.getSubject();
String path = pnfsMessage.getPnfsPath();
try {
File file = new File(path);
checkMask(subject, file.getParent(), pnfsMessage.getAccessMask());
Set<FileAttribute> requested = pnfsMessage.getAcquire();
FileAttributes attrs = null;
switch(type) {
case DIR:
LOGGER.info("create directory {}", path);
checkMkdirAllowed(pnfsMessage);
PnfsId pnfsId = _nameSpaceProvider.createDirectory(subject, path, assign);
pnfsMessage.setPnfsId(pnfsId);
// the createEntry seem to be ok.
try {
LOGGER.info("Trying to get storageInfo for {}", pnfsId);
/* If we were allowed to create the entry above, then
* we also ought to be allowed to read it here. Hence
* we use ROOT as the subject.
*/
attrs = _nameSpaceProvider.getFileAttributes(ROOT, pnfsId, requested);
} catch (CacheException e) {
LOGGER.warn("Can't determine storageInfo: {}", e.toString());
}
break;
case REGULAR:
LOGGER.info("create file {}", path);
checkRestriction(pnfsMessage, UPLOAD);
requested.add(FileAttribute.STORAGEINFO);
requested.add(FileAttribute.PNFSID);
attrs = _nameSpaceProvider.createFile(subject, path, assign, requested);
StorageInfo info = attrs.getStorageInfo();
if (info.getKey("path") == null) {
info.setKey("path", path);
}
info.setKey("uid", Integer.toString(assign.getOwnerIfPresent().orElse(-1)));
info.setKey("gid", Integer.toString(assign.getGroupIfPresent().orElse(-1)));
// REVISIT: consider removing xattr injection once pools can accept FileAttribute.XATTR
if (assign.isDefined(XATTR)) {
assign.getXattrs().forEach((k, v) -> info.setKey(STORAGE_INFO_XATTR_PREFIX + k, v));
}
pnfsMessage.setPnfsId(attrs.getPnfsId());
break;
case LINK:
checkArgument(pnfsMessage instanceof PnfsCreateSymLinkMessage);
String destination = ((PnfsCreateSymLinkMessage) pnfsMessage).getDestination();
LOGGER.info("create symlink {} to {}", path, destination);
checkRestrictionOnParent(pnfsMessage, MANAGE);
pnfsId = _nameSpaceProvider.createSymLink(subject, path, destination, assign);
pnfsMessage.setPnfsId(pnfsId);
break;
default:
throw new IllegalArgumentException("Unsupported type: " + type);
}
pnfsMessage.setFileAttributes(attrs);
pnfsMessage.setSucceeded();
} catch (CacheException e) {
pnfsMessage.setFailed(e.getRc(), e.getMessage());
} catch (RuntimeException e) {
LOGGER.error("Bug found when creating entry:", e);
pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
}
}
use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.
the class PnfsManagerV3 method postProcessFlush.
private void postProcessFlush(CellMessage envelope, PoolFileFlushedMessage pnfsMessage) {
long timeout = envelope.getAdjustedTtl() - envelope.getLocalAge();
/* Asynchronously notify flush notification targets about the flush. */
PoolFileFlushedMessage notification = new PoolFileFlushedMessage(pnfsMessage.getPoolName(), pnfsMessage.getPnfsId(), pnfsMessage.getFileAttributes());
List<ListenableFuture<PoolFileFlushedMessage>> futures = new ArrayList<>();
for (String address : _flushNotificationTargets) {
futures.add(_stub.send(new CellPath(address), notification, timeout));
}
/* Only generate positive reply if all notifications succeeded. */
Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<PoolFileFlushedMessage>>() {
@Override
public void onSuccess(List<PoolFileFlushedMessage> result) {
pnfsMessage.setSucceeded();
reply();
}
@Override
public void onFailure(Throwable t) {
pnfsMessage.setFailed(CacheException.DEFAULT_ERROR_CODE, "PNFS manager failed while notifying other " + "components about the flush: " + t.getMessage());
reply();
}
private void reply() {
envelope.revertDirection();
sendMessage(envelope);
}
});
}
Aggregations