Search in sources :

Example 16 with FsPath

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());
}
Also used : PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) PnfsHandler(diskCacheV111.util.PnfsHandler)

Example 17 with FsPath

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;
}
Also used : NettyTransferService(org.dcache.pool.movers.NettyTransferService) StringMarkup.quotedString(org.dcache.util.StringMarkup.quotedString) URI(java.net.URI) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) UUID(java.util.UUID) FsPath(diskCacheV111.util.FsPath)

Example 18 with FsPath

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));
}
Also used : PnfsId(diskCacheV111.util.PnfsId) CreateOption(org.dcache.namespace.CreateOption) FileAttributes(org.dcache.vehicles.FileAttributes) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 19 with FsPath

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());
}
Also used : CacheException(diskCacheV111.util.CacheException) PnfsId(diskCacheV111.util.PnfsId) CreateOption(org.dcache.namespace.CreateOption) FsPath(diskCacheV111.util.FsPath) Test(org.junit.Test)

Example 20 with FsPath

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;
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) ArrayList(java.util.ArrayList) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FsPath(diskCacheV111.util.FsPath)

Aggregations

FsPath (diskCacheV111.util.FsPath)98 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)66 CacheException (diskCacheV111.util.CacheException)63 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)56 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)43 NotDirCacheException (diskCacheV111.util.NotDirCacheException)42 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)39 FileAttributes (org.dcache.vehicles.FileAttributes)32 PnfsHandler (diskCacheV111.util.PnfsHandler)26 NotFileCacheException (diskCacheV111.util.NotFileCacheException)25 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)23 FileAttribute (org.dcache.namespace.FileAttribute)22 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)21 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)20 Subject (javax.security.auth.Subject)17 Restriction (org.dcache.auth.attributes.Restriction)17 Test (org.junit.Test)17 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)15 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)14 SRMException (org.dcache.srm.SRMException)14