use of diskCacheV111.util.FsPath in project dcache by dCache.
the class DcacheResourceFactory method makeDirectory.
/**
* Create a new directory.
*/
public DcacheDirectoryResource makeDirectory(FileAttributes parent, FsPath path) throws CacheException {
PnfsHandler pnfs = new PnfsHandler(_pnfs, getSubject(), getRestriction());
PnfsCreateEntryMessage reply = pnfs.createPnfsDirectory(path.toString(), REQUIRED_ATTRIBUTES);
return new DcacheDirectoryResource(this, path, reply.getFileAttributes());
}
use of diskCacheV111.util.FsPath in project dcache by dCache.
the class HttpPoolRequestHandler method open.
/**
* Get the mover channel for a certain HTTP request. The mover channel is identified by UUID
* generated upon mover start and sent back to the door as a part of the address info.
*
* @param request HttpRequest that was sent by the client
* @param exclusive True if the mover channel exclusively is to be opened in exclusive mode.
* False if the mover channel can be shared with other requests.
* @return Mover channel for specified UUID
* @throws IllegalArgumentException Request did not include UUID or no mover channel found for
* UUID in the request
*/
private NettyTransferService<HttpProtocolInfo>.NettyMoverChannel open(HttpRequest request, boolean exclusive) throws IllegalArgumentException, URISyntaxException, Redirect {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
Map<String, List<String>> params = queryStringDecoder.parameters();
if (!params.containsKey(HttpTransferService.UUID_QUERY_PARAM)) {
if (!request.getUri().equals("/favicon.ico")) {
LOGGER.error("Received request without UUID in the query " + "string. Request-URI was {}", request.getUri());
}
throw new IllegalArgumentException("Query string does not include any UUID.");
}
List<String> uuidList = params.get(HttpTransferService.UUID_QUERY_PARAM);
if (uuidList.isEmpty()) {
throw new IllegalArgumentException("UUID parameter does not include any value.");
}
UUID uuid = UUID.fromString(uuidList.get(0));
NettyTransferService<HttpProtocolInfo>.NettyMoverChannel file = _server.openFile(uuid, exclusive);
if (file == null) {
Optional<URI> referrer = buildReferrer(request, params);
if (referrer.isPresent()) {
throw new Redirect(referrer.get(), "Request is no longer valid");
}
throw new IllegalArgumentException("Request is no longer valid. " + "Please resubmit to door.");
}
URI uri = new URI(request.getUri());
FsPath requestedFile = FsPath.create(uri.getPath());
FsPath transferFile = FsPath.create(file.getProtocolInfo().getPath());
if (!requestedFile.equals(transferFile)) {
LOGGER.warn("Received an illegal request for file {}, while serving {}", requestedFile, transferFile);
throw new IllegalArgumentException("The file you specified does " + "not match the UUID you specified!");
}
_files.add(file);
return file;
}
use of diskCacheV111.util.FsPath in project dcache by dCache.
the class MonitoringNameSpaceProviderTest method shouldNotifyOnCommitUpload.
@Test
public void shouldNotifyOnCommitUpload() throws Exception {
PnfsId parent = new PnfsId("000000000000000000000000000000000001");
PnfsId target = new PnfsId("000000000000000000000000000000000002");
FsPath uploadPath = FsPath.create("/uploads/1/update-1/file-1");
FsPath targetPath = FsPath.create("/data/file-1");
given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "file-1"));
given(inner.commitUpload(any(), eq(uploadPath), eq(targetPath), any(), any())).willReturn(FileAttributes.of().accessTime(42L).pnfsId(target).build());
FileAttributes result = monitor.commitUpload(TEST_USER, uploadPath, targetPath, EnumSet.noneOf(CreateOption.class), EnumSet.of(FileAttribute.ACCESS_TIME));
verify(inner).commitUpload(eq(TEST_USER), eq(uploadPath), eq(targetPath), eq(EnumSet.noneOf(CreateOption.class)), (Set<FileAttribute>) argThat(hasItem(FileAttribute.ACCESS_TIME)));
assertThat(result.getAccessTime(), is(equalTo(42L)));
verify(receiver).notifyMovedEvent(eq(EventType.IN_MOVED_TO), eq(parent), eq("file-1"), argThat(not(emptyOrNullString())), eq(FileType.REGULAR));
}
use of diskCacheV111.util.FsPath in project dcache by dCache.
the class MonitoringNameSpaceProviderTest method shouldNotNotifyOnUnsuccessfulCommitUpload.
@Test
public void shouldNotNotifyOnUnsuccessfulCommitUpload() throws Exception {
PnfsId parent = new PnfsId("000000000000000000000000000000000001");
PnfsId target = new PnfsId("000000000000000000000000000000000002");
FsPath uploadPath = FsPath.create("/uploads/1/update-1/file-1");
FsPath targetPath = FsPath.create("/data/file-1");
given(inner.find(any(), eq(target))).willReturn(singleLink(parent, "file-1"));
given(inner.commitUpload(any(), eq(uploadPath), eq(targetPath), any(), any())).willThrow(CacheException.class);
try {
monitor.commitUpload(TEST_USER, uploadPath, targetPath, EnumSet.noneOf(CreateOption.class), EnumSet.of(FileAttribute.ACCESS_TIME));
fail("commitUpload unexpectedly succeeded");
} catch (CacheException e) {
}
verify(receiver, never()).notifyChildEvent(any(), any(), any(), any());
verify(receiver, never()).notifySelfEvent(any(), any(), any());
verify(receiver, never()).notifyMovedEvent(any(), any(), any(), any(), any());
}
use of diskCacheV111.util.FsPath in project dcache by dCache.
the class ChimeraNameSpaceProvider method cancelUpload.
@Override
public Collection<FileAttributes> cancelUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<FileAttribute> requested, String explanation) throws CacheException {
List<FileAttributes> deleted = new ArrayList();
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* Temporary upload directory must exist.
*/
ExtendedInode uploadDirInode;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryDir, e);
}
/* Delete temporary upload directory and any files in it.
*/
String name = temporaryPath.parent().name();
removeRecursively(uploadDirInode, name, uploadDirInode.inodeOf(name, STAT), i -> {
try {
if (i.getFileType() == FileType.REGULAR) {
deleted.add(getFileAttributes(i, requested));
}
} catch (CacheException | ChimeraFsException e) {
LOGGER.info("Unable to identify deleted file for upload cancellation: {}", e.toString());
}
});
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
return deleted;
}
Aggregations