Search in sources :

Example 1 with SIZE

use of org.dcache.namespace.FileAttribute.SIZE in project dcache by dCache.

the class PnfsManagerV3 method cancelUpload.

void cancelUpload(PnfsCancelUpload message) {
    Subject subject = message.getSubject();
    String explanation = message.getExplanation();
    try {
        checkRestriction(message, UPLOAD);
        Set<FileAttribute> requested = message.getRequestedAttributes();
        requested.addAll(EnumSet.of(PNFSID, NLINK, SIZE));
        Collection<FileAttributes> deletedFiles = _nameSpaceProvider.cancelUpload(subject, message.getUploadPath(), message.getPath(), requested, explanation);
        deletedFiles.stream().filter(// currently uploading
        f -> f.isUndefined(SIZE)).filter(// with no hard links
        f -> f.getNlink() == 1).map(FileAttributes::getPnfsId).forEach(id -> _cancelUploadNotificationTargets.stream().map(CellPath::new).forEach(p -> _stub.notify(p, new DoorCancelledUploadNotificationMessage(subject, id, explanation))));
        message.setDeletedFiles(deletedFiles);
        message.setSucceeded();
    } catch (CacheException e) {
        message.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Cancel upload path failed", e);
        message.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : PnfsRemoveExtendedAttributesMessage(diskCacheV111.vehicles.PnfsRemoveExtendedAttributesMessage) Arrays(java.util.Arrays) Restriction(org.dcache.auth.attributes.Restriction) Subjects(org.dcache.auth.Subjects) CellMessage(dmg.cells.nucleus.CellMessage) PermissionHandler(org.dcache.namespace.PermissionHandler) NLINK(org.dcache.namespace.FileAttribute.NLINK) UnixPermission(org.dcache.chimera.UnixPermission) Command(dmg.util.command.Command) MODIFICATION_TIME(org.dcache.namespace.FileAttribute.MODIFICATION_TIME) ACCESS_ALLOWED(org.dcache.acl.enums.AccessType.ACCESS_ALLOWED) READ_METADATA(org.dcache.auth.attributes.Activity.READ_METADATA) Map(java.util.Map) PnfsRenameMessage(diskCacheV111.vehicles.PnfsRenameMessage) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) PnfsCreateSymLinkMessage(org.dcache.vehicles.PnfsCreateSymLinkMessage) CDC(dmg.cells.nucleus.CDC) DELETE(org.dcache.auth.attributes.Activity.DELETE) PrintWriter(java.io.PrintWriter) PnfsManagerGetQuotaMessage(org.dcache.vehicles.quota.PnfsManagerGetQuotaMessage) ACCESS_TIME(org.dcache.namespace.FileAttribute.ACCESS_TIME) PnfsManagerSetQuotaMessage(org.dcache.vehicles.quota.PnfsManagerSetQuotaMessage) PNFSID(org.dcache.namespace.FileAttribute.PNFSID) MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) UPDATE_METADATA(org.dcache.auth.attributes.Activity.UPDATE_METADATA) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Executors(java.util.concurrent.Executors) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage) PnfsListExtendedAttributesMessage(diskCacheV111.vehicles.PnfsListExtendedAttributesMessage) AbstractCellComponent(dmg.cells.nucleus.AbstractCellComponent) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) UPLOAD(org.dcache.auth.attributes.Activity.UPLOAD) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) PnfsCreateUploadPath(diskCacheV111.vehicles.PnfsCreateUploadPath) LeaderLatchListener(org.apache.curator.framework.recipes.leader.LeaderLatchListener) FsPath(diskCacheV111.util.FsPath) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) ACCESS_UNDEFINED(org.dcache.acl.enums.AccessType.ACCESS_UNDEFINED) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ColumnWriter(org.dcache.util.ColumnWriter) PnfsReadExtendedAttributesMessage(diskCacheV111.vehicles.PnfsReadExtendedAttributesMessage) Strings(com.google.common.base.Strings) OWNER(org.dcache.namespace.FileAttribute.OWNER) NotDirCacheException(diskCacheV111.util.NotDirCacheException) CellStub(org.dcache.cells.CellStub) TYPE(org.dcache.namespace.FileAttribute.TYPE) PnfsListDirectoryMessage(org.dcache.vehicles.PnfsListDirectoryMessage) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileType(org.dcache.namespace.FileType) PnfsManagerRemoveQuotaMessage(org.dcache.vehicles.quota.PnfsManagerRemoveQuotaMessage) PnfsId(diskCacheV111.util.PnfsId) ROOT(org.dcache.auth.Subjects.ROOT) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) QuotaInfo(org.dcache.quota.data.QuotaInfo) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) LIST(org.dcache.auth.attributes.Activity.LIST) Futures(com.google.common.util.concurrent.Futures) CREATION_TIME(org.dcache.namespace.FileAttribute.CREATION_TIME) PnfsRemoveLabelsMessage(diskCacheV111.vehicles.PnfsRemoveLabelsMessage) TransactionException(org.springframework.transaction.TransactionException) FileAttribute(org.dcache.namespace.FileAttribute) ByteUnit(org.dcache.util.ByteUnit) PnfsMapPathMessage(diskCacheV111.vehicles.PnfsMapPathMessage) ScheduledFuture(java.util.concurrent.ScheduledFuture) SortedSet(java.util.SortedSet) AccessLatency(diskCacheV111.util.AccessLatency) ACCESS_DENIED(org.dcache.acl.enums.AccessType.ACCESS_DENIED) ChecksumType(org.dcache.util.ChecksumType) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) XATTR(org.dcache.namespace.FileAttribute.XATTR) PnfsCancelUpload(diskCacheV111.vehicles.PnfsCancelUpload) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AccessType(org.dcache.acl.enums.AccessType) Locale(java.util.Locale) RequestCounters(org.dcache.commons.stats.RequestCounters) QuotaHandler(org.dcache.chimera.quota.QuotaHandler) PnfsWriteExtendedAttributesMessage(diskCacheV111.vehicles.PnfsWriteExtendedAttributesMessage) Splitter(com.google.common.base.Splitter) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsManagerQuotaMessage(org.dcache.vehicles.quota.PnfsManagerQuotaMessage) CellMessageReceiver(dmg.cells.nucleus.CellMessageReceiver) PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) CommandException(dmg.util.CommandException) CHANGE_TIME(org.dcache.namespace.FileAttribute.CHANGE_TIME) Collection(java.util.Collection) PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) CellCommandListener(dmg.cells.nucleus.CellCommandListener) Instant(java.time.Instant) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) List(java.util.List) UOID(dmg.cells.nucleus.UOID) Activity(org.dcache.auth.attributes.Activity) Optional(java.util.Optional) MODE(org.dcache.namespace.FileAttribute.MODE) CellPath(dmg.cells.nucleus.CellPath) RetentionPolicy(diskCacheV111.util.RetentionPolicy) Argument(dmg.util.command.Argument) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CellInfoProvider(dmg.cells.nucleus.CellInfoProvider) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) PnfsDeleteEntryMessage(diskCacheV111.vehicles.PnfsDeleteEntryMessage) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PnfsMessage(diskCacheV111.vehicles.PnfsMessage) QuotaRequest(org.dcache.quota.data.QuotaRequest) CellAddressCore(dmg.cells.nucleus.CellAddressCore) StorageInfos(diskCacheV111.vehicles.StorageInfos) Message(diskCacheV111.vehicles.Message) DOWNLOAD(org.dcache.auth.attributes.Activity.DOWNLOAD) QuotaType(org.dcache.quota.data.QuotaType) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) ListHandler(org.dcache.namespace.ListHandler) MANAGE(org.dcache.auth.attributes.Activity.MANAGE) PoolFileFlushedMessage(diskCacheV111.vehicles.PoolFileFlushedMessage) TimeUtils(org.dcache.util.TimeUtils) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FireAndForgetTask(org.dcache.util.FireAndForgetTask) RequestExecutionTimeGauges(org.dcache.commons.stats.RequestExecutionTimeGauges) Subject(javax.security.auth.Subject) TabulatedRow(org.dcache.util.ColumnWriter.TabulatedRow) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TimeUnit(java.util.concurrent.TimeUnit) Checksum(org.dcache.util.Checksum) PnfsRemoveChecksumMessage(org.dcache.vehicles.PnfsRemoveChecksumMessage) DoorCancelledUploadNotificationMessage(diskCacheV111.vehicles.DoorCancelledUploadNotificationMessage) Quota(org.dcache.chimera.quota.Quota) Args(org.dcache.util.Args) Option(dmg.util.command.Option) AccessMask(org.dcache.acl.enums.AccessMask) OWNER_GROUP(org.dcache.namespace.FileAttribute.OWNER_GROUP) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage) CommandLine(dmg.util.command.CommandLine) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Required(org.springframework.beans.factory.annotation.Required) Collections(java.util.Collections) JdbcQuota(org.dcache.chimera.quota.JdbcQuota) Transactional(org.springframework.transaction.annotation.Transactional) CellPath(dmg.cells.nucleus.CellPath) DoorCancelledUploadNotificationMessage(diskCacheV111.vehicles.DoorCancelledUploadNotificationMessage) MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) Subject(javax.security.auth.Subject) FileAttribute(org.dcache.namespace.FileAttribute)

Example 2 with SIZE

use of org.dcache.namespace.FileAttribute.SIZE in project dcache by dCache.

the class Transfer method startMoverAsync.

/**
 * Creates a mover for the transfer.
 */
public ListenableFuture<Void> startMoverAsync(long timeout) {
    FileAttributes fileAttributes = getFileAttributes();
    Pool pool = getPool();
    if (fileAttributes == null || pool == null) {
        throw new IllegalStateException("Need PNFS ID, file attributes and pool before a mover can be started");
    }
    ProtocolInfo protocolInfo = getProtocolInfoForPool();
    PoolIoFileMessage message;
    if (isWrite()) {
        long allocated = _allocated;
        if (allocated == 0 && fileAttributes.isDefined(SIZE)) {
            allocated = fileAttributes.getSize();
        }
        message = new PoolAcceptFileMessage(pool.getName(), protocolInfo, fileAttributes, pool.getAssumption(), _maximumSize, allocated);
    } else {
        message = new PoolDeliverFileMessage(pool.getName(), protocolInfo, fileAttributes, pool.getAssumption());
    }
    message.setBillingPath(getBillingPath());
    message.setTransferPath(getTransferPath());
    message.setIoQueueName(getIoQueue());
    message.setInitiator(getTransaction());
    message.setId(_id);
    message.setSubject(_subject);
    /*
         * SpaceManager needs to spy mover shutdown to adjust the space reservation. for this reason we have to
         * proxy mover start messages through SpaceManager. However, reads can be sent directly to pools.
         *
         * REVISIT: this should happen only when space manager is enabled.
         */
    ListenableFuture<PoolIoFileMessage> reply = isWrite() ? _poolManager.startAsync(pool.getAddress(), message, timeout) : _poolStub.send(new CellPath(pool.getAddress()), message, timeout);
    reply = catchingAsync(reply, NoRouteToCellException.class, x -> {
        // invalidate pool selection to let the door to start over
        clearPoolSelection();
        return immediateFailedFuture(x);
    });
    setStatusUntil("Pool " + pool + ": Creating mover", reply);
    return CellStub.transformAsync(reply, msg -> {
        setMoverId(msg.getMoverId());
        return immediateFuture(null);
    });
}
Also used : CellPath(dmg.cells.nucleus.CellPath) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) DoorTransferFinishedMessage(diskCacheV111.vehicles.DoorTransferFinishedMessage) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) Pool(diskCacheV111.vehicles.Pool) Restriction(org.dcache.auth.attributes.Restriction) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) LoggerFactory(org.slf4j.LoggerFactory) RequestState(diskCacheV111.poolManager.RequestContainerV5.RequestState) PoolMoverKillMessage(diskCacheV111.vehicles.PoolMoverKillMessage) Restrictions(org.dcache.auth.attributes.Restrictions) InetAddress(java.net.InetAddress) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PnfsHandler(diskCacheV111.util.PnfsHandler) Future(java.util.concurrent.Future) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) Duration(java.time.Duration) PoolManagerStub(org.dcache.poolmanager.PoolManagerStub) CheckStagePermission(diskCacheV111.util.CheckStagePermission) IoJobInfo(diskCacheV111.vehicles.IoJobInfo) SIZE(org.dcache.namespace.FileAttribute.SIZE) ThreadFactory(java.util.concurrent.ThreadFactory) EnumSet(java.util.EnumSet) CDC(dmg.cells.nucleus.CDC) FileAttributes(org.dcache.vehicles.FileAttributes) Longs(com.google.common.primitives.Longs) PNFSID(org.dcache.namespace.FileAttribute.PNFSID) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) PoolDeliverFileMessage(diskCacheV111.vehicles.PoolDeliverFileMessage) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TimebasedCounter(dmg.util.TimebasedCounter) Executors(java.util.concurrent.Executors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) PoolMgrSelectWritePoolMsg(diskCacheV111.vehicles.PoolMgrSelectWritePoolMsg) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) CellPath(dmg.cells.nucleus.CellPath) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PoolMgrSelectPoolMsg(diskCacheV111.vehicles.PoolMgrSelectPoolMsg) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FsPath(diskCacheV111.util.FsPath) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CellAddressCore(dmg.cells.nucleus.CellAddressCore) IoDoorEntry(diskCacheV111.vehicles.IoDoorEntry) MathUtils.subWithInfinity(org.dcache.util.MathUtils.subWithInfinity) MathUtils.addWithInfinity(org.dcache.util.MathUtils.addWithInfinity) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) TYPE(org.dcache.namespace.FileAttribute.TYPE) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) Nullable(javax.annotation.Nullable) FileType(org.dcache.namespace.FileType) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) PnfsId(diskCacheV111.util.PnfsId) Logger(org.slf4j.Logger) BaseEncoding(com.google.common.io.BaseEncoding) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) REGULAR(org.dcache.namespace.FileType.REGULAR) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) IOException(java.io.IOException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) Subject(javax.security.auth.Subject) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) MDC(org.slf4j.MDC) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) AccessMask(org.dcache.acl.enums.AccessMask) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) FileAttribute(org.dcache.namespace.FileAttribute) Collections(java.util.Collections) PoolDeliverFileMessage(diskCacheV111.vehicles.PoolDeliverFileMessage) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) Pool(diskCacheV111.vehicles.Pool) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes)

Example 3 with SIZE

use of org.dcache.namespace.FileAttribute.SIZE in project dcache by dCache.

the class RemoteNameSpaceProviderTests method shouldSucceedWhenGetFileAttributesForExistingEntry.

@Test
public void shouldSucceedWhenGetFileAttributesForExistingEntry() throws Exception {
    givenSuccessfulResponse((Modifier<PnfsGetFileAttributes>) (r) -> r.setFileAttributes(fileAttributes().withSize(1234L).withType(REGULAR).build()));
    FileAttributes attributes = _namespace.getFileAttributes(ROOT, A_PNFSID, EnumSet.of(TYPE, SIZE));
    PnfsGetFileAttributes sent = getSingleSendAndWaitMessage(PnfsGetFileAttributes.class);
    assertThat(sent.getReplyRequired(), is(true));
    assertThat(sent.getSubject(), is(ROOT));
    assertThat(sent.getPnfsId(), is(A_PNFSID));
    assertThat(sent.getRequestedAttributes(), hasSize(2));
    assertThat(sent.getRequestedAttributes(), hasItem(TYPE));
    assertThat(sent.getRequestedAttributes(), hasItem(SIZE));
    assertThat(attributes.getSize(), is(1234L));
    assertThat(attributes.getFileType(), is(REGULAR));
}
Also used : FILE_NOT_FOUND(diskCacheV111.util.CacheException.FILE_NOT_FOUND) ListDirectoryHandler(org.dcache.util.list.ListDirectoryHandler) Link(diskCacheV111.namespace.NameSpaceProvider.Link) CellMessage(dmg.cells.nucleus.CellMessage) ChecksumType(org.dcache.util.ChecksumType) FILE_EXISTS(diskCacheV111.util.CacheException.FILE_EXISTS) PnfsHandler(diskCacheV111.util.PnfsHandler) BDDMockito.verify(org.mockito.BDDMockito.verify) FlagOperation(diskCacheV111.vehicles.PnfsFlagMessage.FlagOperation) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttributesBuilder.fileAttributes(org.dcache.util.FileAttributesBuilder.fileAttributes) PnfsGetParentMessage(diskCacheV111.vehicles.PnfsGetParentMessage) BDDMockito.never(org.mockito.BDDMockito.never) Collection(java.util.Collection) Range(com.google.common.collect.Range) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage) SerializationHandler(dmg.cells.nucleus.SerializationHandler) List(java.util.List) DirectoryEntry(org.dcache.util.list.DirectoryEntry) CellMessageAnswerable(dmg.cells.nucleus.CellMessageAnswerable) Matchers.is(org.hamcrest.Matchers.is) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) CellPath(dmg.cells.nucleus.CellPath) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) PnfsDeleteEntryMessage(diskCacheV111.vehicles.PnfsDeleteEntryMessage) PnfsMessage(diskCacheV111.vehicles.PnfsMessage) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) NOT_FILE(diskCacheV111.util.CacheException.NOT_FILE) HashMap(java.util.HashMap) CellEndpoint(dmg.cells.nucleus.CellEndpoint) SerializationException(dmg.cells.nucleus.SerializationException) Answer(org.mockito.stubbing.Answer) BDDMockito.any(org.mockito.BDDMockito.any) BDDMockito.anyLong(org.mockito.BDDMockito.anyLong) Lists(com.google.common.collect.Lists) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) ArgumentCaptor(org.mockito.ArgumentCaptor) TYPE(org.dcache.namespace.FileAttribute.TYPE) PnfsListDirectoryMessage(org.dcache.vehicles.PnfsListDirectoryMessage) ListHandler(org.dcache.namespace.ListHandler) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileType(org.dcache.namespace.FileType) Before(org.junit.Before) PnfsId(diskCacheV111.util.PnfsId) ROOT(org.dcache.auth.Subjects.ROOT) BDDMockito.doAnswer(org.mockito.BDDMockito.doAnswer) Executor(java.util.concurrent.Executor) REGULAR(org.dcache.namespace.FileType.REGULAR) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test) NotFileCacheException(diskCacheV111.util.NotFileCacheException) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) PnfsRemoveChecksumMessage(org.dcache.vehicles.PnfsRemoveChecksumMessage) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage) FileAttribute(org.dcache.namespace.FileAttribute) BDDMockito.mock(org.mockito.BDDMockito.mock) Collections(java.util.Collections) PnfsMapPathMessage(diskCacheV111.vehicles.PnfsMapPathMessage) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test)

Example 4 with SIZE

use of org.dcache.namespace.FileAttribute.SIZE in project dcache by dCache.

the class ChimeraNameSpaceProvider method setFileAttributes.

@Override
public FileAttributes setFileAttributes(Subject subject, PnfsId pnfsId, FileAttributes attr, Set<FileAttribute> acquire) throws CacheException {
    LOGGER.debug("File attributes update: {}", attr.getDefinedAttributes());
    try {
        ExtendedInode inode = new ExtendedInode(_fs, pnfsId, Subjects.isExemptFromNamespaceChecks(subject) ? NO_STAT : STAT);
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(inode);
            if (_permissionHandler.canSetAttributes(subject, attributes, attr) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + pnfsId);
            }
        }
        /* Update the t_inodes row first (the Stat object) to acquire a FOR UPDATE / FOR NO KEY UPDATE
             * first. If the inserts into secondary table referring t_inodes would be done first, the
             * referential integrity check would obtain a FOR SHARE / FOR KEY SHARE on the t_inodes row which
             * latter would have to be upgraded (potentially leading to deadlocks if that's not possible).
             */
        Stat stat = new Stat();
        for (FileAttribute attribute : attr.getDefinedAttributes()) {
            switch(attribute) {
                case LOCATIONS:
                    // REVISIT: may be we need an explicit indication from pool
                    if (attr.isDefined(SIZE)) {
                        stat.setState(FileState.STORED);
                    }
                    break;
                case SIZE:
                    // REVISIT: pool shouldn't update the files size on flush, but this is required due to space manager accounting
                    if (!attr.isDefined(STORAGEINFO) || !attr.getStorageInfo().isSetAddLocation()) {
                        stat.setSize(attr.getSize());
                    }
                    break;
                case MODE:
                    stat.setMode(attr.getMode());
                    break;
                case CREATION_TIME:
                    stat.setCrTime(attr.getCreationTime());
                    break;
                case CHANGE_TIME:
                    stat.setCTime(attr.getChangeTime());
                    break;
                case MODIFICATION_TIME:
                    stat.setMTime(attr.getModificationTime());
                    break;
                case ACCESS_TIME:
                    stat.setATime(attr.getAccessTime());
                    break;
                case OWNER:
                    stat.setUid(attr.getOwner());
                    break;
                case OWNER_GROUP:
                    stat.setGid(attr.getGroup());
                    break;
                case CHECKSUM:
                    break;
                case ACCESS_LATENCY:
                    stat.setAccessLatency(attr.getAccessLatency());
                    break;
                case RETENTION_POLICY:
                    stat.setRetentionPolicy(attr.getRetentionPolicy());
                    break;
                case FLAGS:
                    break;
                case ACL:
                    break;
                case STORAGEINFO:
                    _extractor.setStorageInfo(inode, attr.getStorageInfo());
                    break;
                case XATTR:
                    break;
                case LABELS:
                    break;
                default:
                    throw new UnsupportedOperationException("Attribute " + attribute + " not supported yet.");
            }
        }
        if (stat.isDefinedAny()) {
            inode.setStat(stat);
        }
        if (attr.isDefined(XATTR)) {
            Map<String, String> xattrs = attr.getXattrs();
            for (Map.Entry<String, String> e : xattrs.entrySet()) {
                _fs.setXattr(inode, e.getKey(), e.getValue().getBytes(StandardCharsets.UTF_8), SetXattrMode.EITHER);
            }
        }
        if (attr.isDefined(LABELS)) {
            for (String label : attr.getLabels()) {
                _fs.addLabel(inode, label);
            }
        }
        if (attr.isDefined(FileAttribute.LOCATIONS)) {
            for (String location : attr.getLocations()) {
                _fs.addInodeLocation(inode, StorageGenericLocation.DISK, location);
            }
        }
        if (attr.isDefined(FileAttribute.CHECKSUM)) {
            for (Checksum newChecksum : attr.getChecksums()) {
                ChecksumType type = newChecksum.getType();
                Optional<Checksum> existingChecksum = _fs.getInodeChecksums(inode).stream().filter(c -> c.getType() == type).findFirst();
                if (existingChecksum.isPresent()) {
                    Checksum existing = existingChecksum.get();
                    if (!existing.equals(newChecksum)) {
                        throw new FileCorruptedCacheException(existing, newChecksum);
                    }
                } else {
                    _fs.setInodeChecksum(inode, type.getType(), newChecksum.getValue());
                }
            }
        }
        if (attr.isDefined(FileAttribute.FLAGS)) {
            FsInode level2 = new ExtendedInode(_fs, pnfsId, NO_STAT).getLevel(2);
            ChimeraCacheInfo cacheInfo = new ChimeraCacheInfo(level2);
            for (Map.Entry<String, String> flag : attr.getFlags().entrySet()) {
                cacheInfo.getFlags().put(flag.getKey(), flag.getValue());
            }
            cacheInfo.writeCacheInfo(level2);
        }
        if (attr.isDefined(FileAttribute.ACL)) {
            ACL acl = attr.getAcl();
            _fs.setACL(inode, acl.getList());
        }
        return getFileAttributes(inode, acquire);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file or directory: " + pnfsId);
    } catch (IOException e) {
        LOGGER.error("Exception in setFileAttributes: {}", e);
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : FsInode(org.dcache.chimera.FsInode) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) Subjects(org.dcache.auth.Subjects) StorageLocatable(org.dcache.chimera.StorageLocatable) CACHECLASS(org.dcache.namespace.FileAttribute.CACHECLASS) PermissionHandler(org.dcache.namespace.PermissionHandler) NLINK(org.dcache.namespace.FileAttribute.NLINK) FileState(org.dcache.chimera.FileState) UnixPermission(org.dcache.chimera.UnixPermission) Command(dmg.util.command.Command) ACCESS_ALLOWED(org.dcache.acl.enums.AccessType.ACCESS_ALLOWED) Map(java.util.Map) StorageGenericLocation(org.dcache.chimera.StorageGenericLocation) SIZE(org.dcache.namespace.FileAttribute.SIZE) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) PNFSID(org.dcache.namespace.FileAttribute.PNFSID) Range(com.google.common.collect.Range) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) CellInfo(dmg.cells.nucleus.CellInfo) LockedCacheException(diskCacheV111.util.LockedCacheException) Set(java.util.Set) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Stream(java.util.stream.Stream) ChimeraDirectoryEntry(org.dcache.chimera.ChimeraDirectoryEntry) ACCESS_LATENCY(org.dcache.namespace.FileAttribute.ACCESS_LATENCY) Iterables(com.google.common.collect.Iterables) FsPath(diskCacheV111.util.FsPath) DirectoryStreamB(org.dcache.chimera.DirectoryStreamB) Callable(java.util.concurrent.Callable) NameSpaceProvider(diskCacheV111.namespace.NameSpaceProvider) ArrayList(java.util.ArrayList) OWNER(org.dcache.namespace.FileAttribute.OWNER) Lists(com.google.common.collect.Lists) NotDirCacheException(diskCacheV111.util.NotDirCacheException) TYPE(org.dcache.namespace.FileAttribute.TYPE) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) STAT(org.dcache.chimera.FileSystemProvider.StatCacheOption.STAT) Nullable(javax.annotation.Nullable) FileType(org.dcache.namespace.FileType) STORAGECLASS(org.dcache.namespace.FileAttribute.STORAGECLASS) PnfsId(diskCacheV111.util.PnfsId) MonitoringProxy(org.dcache.commons.stats.MonitoringProxy) LOCATIONS(org.dcache.namespace.FileAttribute.LOCATIONS) Glob(org.dcache.util.Glob) IOException(java.io.IOException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) ACE(org.dcache.acl.ACE) File(java.io.File) CREATION_TIME(org.dcache.namespace.FileAttribute.CREATION_TIME) LABELS(org.dcache.namespace.FileAttribute.LABELS) FileAttribute(org.dcache.namespace.FileAttribute) SIMPLE_TYPE(org.dcache.namespace.FileAttribute.SIMPLE_TYPE) SetXattrMode(org.dcache.chimera.FileSystemProvider.SetXattrMode) AccessLatency(diskCacheV111.util.AccessLatency) ChecksumType(org.dcache.util.ChecksumType) LoggerFactory(org.slf4j.LoggerFactory) XATTR(org.dcache.namespace.FileAttribute.XATTR) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ACL(org.dcache.acl.ACL) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Stat(org.dcache.chimera.posix.Stat) RequestCounters(org.dcache.commons.stats.RequestCounters) Method(java.lang.reflect.Method) FileAttributes(org.dcache.vehicles.FileAttributes) NoXdataChimeraException(org.dcache.chimera.NoXdataChimeraException) Collection(java.util.Collection) FileSystemProvider(org.dcache.chimera.FileSystemProvider) UUID(java.util.UUID) CellCommandListener(dmg.cells.nucleus.CellCommandListener) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CreateOption(org.dcache.namespace.CreateOption) List(java.util.List) Optional(java.util.Optional) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) MODE(org.dcache.namespace.FileAttribute.MODE) Pattern(java.util.regex.Pattern) CHECKSUM(org.dcache.namespace.FileAttribute.CHECKSUM) RetentionPolicy(diskCacheV111.util.RetentionPolicy) CellInfoProvider(dmg.cells.nucleus.CellInfoProvider) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) HashMap(java.util.HashMap) HSM(org.dcache.namespace.FileAttribute.HSM) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) RETENTION_POLICY(org.dcache.namespace.FileAttribute.RETENTION_POLICY) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) ImmutableList(com.google.common.collect.ImmutableList) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) ListHandler(org.dcache.namespace.ListHandler) Nonnull(javax.annotation.Nonnull) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) Exceptions(org.dcache.util.Exceptions) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RequestExecutionTimeGauges(org.dcache.commons.stats.RequestExecutionTimeGauges) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) Subject(javax.security.auth.Subject) NO_STAT(org.dcache.chimera.FileSystemProvider.StatCacheOption.NO_STAT) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Consumer(java.util.function.Consumer) Checksum(org.dcache.util.Checksum) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) OWNER_GROUP(org.dcache.namespace.FileAttribute.OWNER_GROUP) FLAGS(org.dcache.namespace.FileAttribute.FLAGS) Required(org.springframework.beans.factory.annotation.Required) Collections(java.util.Collections) 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) ACL(org.dcache.acl.ACL) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ChecksumType(org.dcache.util.ChecksumType) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Stat(org.dcache.chimera.posix.Stat) Checksum(org.dcache.util.Checksum) FsInode(org.dcache.chimera.FsInode) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) Map(java.util.Map) HashMap(java.util.HashMap) FileAttribute(org.dcache.namespace.FileAttribute)

Aggregations

CacheException (diskCacheV111.util.CacheException)4 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)4 PnfsId (diskCacheV111.util.PnfsId)4 Collections (java.util.Collections)4 EnumSet (java.util.EnumSet)4 List (java.util.List)4 FileAttribute (org.dcache.namespace.FileAttribute)4 SIZE (org.dcache.namespace.FileAttribute.SIZE)4 TYPE (org.dcache.namespace.FileAttribute.TYPE)4 FileType (org.dcache.namespace.FileType)4 FileAttributes (org.dcache.vehicles.FileAttributes)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 FsPath (diskCacheV111.util.FsPath)3 Lists (com.google.common.collect.Lists)2 Range (com.google.common.collect.Range)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2