Search in sources :

Example 1 with Space

use of diskCacheV111.services.space.Space in project dcache by dCache.

the class NFSv41Door method getDeviceInfo.

// NFSv41DeviceManager interface
/*
    	The most important calls is LAYOUTGET, OPEN, CLOSE, LAYOUTRETURN
    	The READ, WRITE and  COMMIT goes to storage device.

    	We assume the following mapping between nfs and dcache:

    	     NFS     |  dCache
    	_____________|________________________________________
    	LAYOUTGET    : get pool, bind the answer to the client
    	OPEN         : send IO request to the pool
    	CLOSE        : sent end-of-IO to the pool, LAYOUTRECALL
    	LAYOUTRETURN : unbind pool from client

     */
@Override
public device_addr4 getDeviceInfo(CompoundContext context, GETDEVICEINFO4args args) throws ChimeraNFSException {
    layouttype4 layoutType = layouttype4.valueOf(args.gdia_layout_type);
    LayoutDriver layoutDriver = getLayoutDriver(layoutType);
    PoolDS ds = _poolDeviceMap.getByDeviceId(args.gdia_device_id);
    if (ds == null) {
        return null;
    }
    // limit addresses returned to client to the same 'type' as clients own address
    // NOTICE: according to rfc1918 we allow access to private networks from public ip address
    // Site must take care that private IP space is not visible to site external clients.
    InetAddress clientAddress = context.getRemoteSocketAddress().getAddress();
    InetSocketAddress[] usableAddresses = Stream.of(ds.getDeviceAddr()).filter(a -> !a.getAddress().isLoopbackAddress() || clientAddress.isLoopbackAddress()).filter(a -> !a.getAddress().isLinkLocalAddress() || clientAddress.isLinkLocalAddress()).filter(a -> clientAddress.getAddress().length >= a.getAddress().getAddress().length).toArray(InetSocketAddress[]::new);
    return layoutDriver.getDeviceAddress(usableAddresses);
}
Also used : org.dcache.nfs.v4.xdr.layouttype4(org.dcache.nfs.v4.xdr.layouttype4) CreateMode(org.apache.zookeeper.CreateMode) DoorTransferFinishedMessage(diskCacheV111.vehicles.DoorTransferFinishedMessage) Arrays(java.util.Arrays) GssSessionManager(org.dcache.oncrpc4j.rpc.gss.GssSessionManager) FsInode(org.dcache.chimera.FsInode) Pool(diskCacheV111.vehicles.Pool) Subjects(org.dcache.auth.Subjects) ZonedDateTime(java.time.ZonedDateTime) org.dcache.nfs.v4.ff.flex_files_prot(org.dcache.nfs.v4.ff.flex_files_prot) LAYOUTCOMMIT4args(org.dcache.nfs.v4.xdr.LAYOUTCOMMIT4args) NFS4Client(org.dcache.nfs.v4.NFS4Client) DoorValidateMoverMessage(org.dcache.vehicles.DoorValidateMoverMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) NfsServerV3(org.dcache.nfs.v3.NfsServerV3) PoolMoverKillMessage(diskCacheV111.vehicles.PoolMoverKillMessage) Restrictions(org.dcache.auth.attributes.Restrictions) Command(dmg.util.command.Command) InetAddress(java.net.InetAddress) PnfsHandler(diskCacheV111.util.PnfsHandler) NFS4ProtocolInfo(org.dcache.chimera.nfsv41.mover.NFS4ProtocolInfo) Stat(org.dcache.nfs.vfs.Stat) LayoutUnavailableException(org.dcache.nfs.status.LayoutUnavailableException) Map(java.util.Map) EventNotifier(diskCacheV111.namespace.EventNotifier) LayoutDriver(org.dcache.nfs.v4.LayoutDriver) CDC(dmg.cells.nucleus.CDC) PrintWriter(java.io.PrintWriter) NFSv4Defaults(org.dcache.nfs.v4.NFSv4Defaults) NfsProxyIoFactory(org.dcache.chimera.nfsv41.door.proxy.NfsProxyIoFactory) org.dcache.nfs.v4.xdr.deviceid4(org.dcache.nfs.v4.xdr.deviceid4) EnumMap(java.util.EnumMap) Set(java.util.Set) GuardedBy(javax.annotation.concurrent.GuardedBy) org.dcache.nfs.v4.xdr.layout4(org.dcache.nfs.v4.xdr.layout4) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) ClientCB(org.dcache.nfs.v4.ClientCB) Stream(java.util.stream.Stream) LAYOUTGET4args(org.dcache.nfs.v4.xdr.LAYOUTGET4args) AbstractCellComponent(dmg.cells.nucleus.AbstractCellComponent) LoginBrokerPublisher(dmg.cells.services.login.LoginBrokerPublisher) org.dcache.nfs.v3.xdr.nfs3_prot(org.dcache.nfs.v3.xdr.nfs3_prot) AlarmMarkerFactory(org.dcache.alarms.AlarmMarkerFactory) org.dcache.nfs.v4.ff.ff_layoutreturn4(org.dcache.nfs.v4.ff.ff_layoutreturn4) PredefinedAlarm(org.dcache.alarms.PredefinedAlarm) FsInodeType(org.dcache.chimera.FsInodeType) Callable(java.util.concurrent.Callable) IoDoorInfo(diskCacheV111.vehicles.IoDoorInfo) OptionalLong(java.util.OptionalLong) CellStub(org.dcache.cells.CellStub) TransferRetryPolicy.alwaysRetry(org.dcache.util.TransferRetryPolicy.alwaysRetry) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) org.dcache.nfs.v4.xdr.layoutiomode4(org.dcache.nfs.v4.xdr.layoutiomode4) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PermException(org.dcache.nfs.status.PermException) PnfsId(diskCacheV111.util.PnfsId) BaseEncoding(com.google.common.io.BaseEncoding) PoolPassiveIoFileMessage(diskCacheV111.vehicles.PoolPassiveIoFileMessage) DelayException(org.dcache.nfs.status.DelayException) Glob(org.dcache.util.Glob) IOException(java.io.IOException) NFSv41DeviceManager(org.dcache.nfs.v4.NFSv41DeviceManager) ExecutionException(java.util.concurrent.ExecutionException) org.dcache.nfs.v4.xdr.nfs_fh4(org.dcache.nfs.v4.xdr.nfs_fh4) NDC(org.dcache.util.NDC) Layout(org.dcache.nfs.v4.Layout) FileAttribute(org.dcache.namespace.FileAttribute) TransferRetryPolicy(org.dcache.util.TransferRetryPolicy) LAYOUTERROR4args(org.dcache.nfs.v4.xdr.LAYOUTERROR4args) ProxyIoFactory(org.dcache.chimera.nfsv41.door.proxy.ProxyIoFactory) ByteUnit(org.dcache.util.ByteUnit) VirtualFileSystem(org.dcache.nfs.vfs.VirtualFileSystem) Assumptions(org.dcache.pool.assumption.Assumptions) Stateids(org.dcache.nfs.v4.Stateids) org.dcache.nfs.v4.xdr.clientid4(org.dcache.nfs.v4.xdr.clientid4) Transfer(org.dcache.util.Transfer) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) InterProcessSemaphoreMutex(org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex) org.dcache.nfs.v4.xdr.layoutreturn_type4(org.dcache.nfs.v4.xdr.layoutreturn_type4) ZKPaths(org.apache.curator.utils.ZKPaths) NFSv41Session(org.dcache.nfs.v4.NFSv41Session) org.dcache.nfs.v4.xdr.length4(org.dcache.nfs.v4.xdr.length4) org.dcache.nfs.v4.xdr.offset4(org.dcache.nfs.v4.xdr.offset4) PoolStatusChangedMessage(diskCacheV111.vehicles.PoolStatusChangedMessage) PoolManagerStub(org.dcache.poolmanager.PoolManagerStub) VfsCache(org.dcache.nfs.vfs.VfsCache) org.dcache.nfs.v4.xdr.stateid4(org.dcache.nfs.v4.xdr.stateid4) NoMatchingLayoutException(org.dcache.nfs.status.NoMatchingLayoutException) FileAttributes(org.dcache.vehicles.FileAttributes) CellMessageReceiver(dmg.cells.nucleus.CellMessageReceiver) CommandException(dmg.util.CommandException) Predicate(java.util.function.Predicate) org.dcache.nfs.v3.xdr.mount_prot(org.dcache.nfs.v3.xdr.mount_prot) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InetAddressMatcher(org.dcache.nfs.InetAddressMatcher) GETDEVICEINFO4args(org.dcache.nfs.v4.xdr.GETDEVICEINFO4args) CellCommandListener(dmg.cells.nucleus.CellCommandListener) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NFSv4StateHandler(org.dcache.nfs.v4.NFSv4StateHandler) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) JdbcFs(org.dcache.chimera.JdbcFs) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) org.dcache.nfs.v4.ff.ff_ioerr4(org.dcache.nfs.v4.ff.ff_ioerr4) UnknownLayoutTypeException(org.dcache.nfs.status.UnknownLayoutTypeException) CompoundContext(org.dcache.nfs.v4.CompoundContext) NFS4State(org.dcache.nfs.v4.NFS4State) org.dcache.nfs.v4.xdr.nfs_opnum4(org.dcache.nfs.v4.xdr.nfs_opnum4) Optional(java.util.Optional) DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) ChimeraFsException(org.dcache.chimera.ChimeraFsException) CellPath(dmg.cells.nucleus.CellPath) StaleException(org.dcache.nfs.status.StaleException) NfsV41FileLayoutDriver(org.dcache.nfs.v4.NfsV41FileLayoutDriver) Argument(dmg.util.command.Argument) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CellInfoProvider(dmg.cells.nucleus.CellInfoProvider) org.dcache.nfs.v4.xdr.device_error4(org.dcache.nfs.v4.xdr.device_error4) ExceptionUtils.asNfsException(org.dcache.chimera.nfsv41.door.ExceptionUtils.asNfsException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VfsCacheConfig(org.dcache.nfs.vfs.VfsCacheConfig) CellAddressCore(dmg.cells.nucleus.CellAddressCore) IoDoorEntry(diskCacheV111.vehicles.IoDoorEntry) BadStateidException(org.dcache.nfs.status.BadStateidException) AtomicReference(java.util.concurrent.atomic.AtomicReference) NfsIoException(org.dcache.nfs.status.NfsIoException) FlexFileLayoutDriver(org.dcache.nfs.v4.FlexFileLayoutDriver) LoginManagerChildrenInfo(dmg.cells.services.login.LoginManagerChildrenInfo) org.dcache.nfs.nfsstat(org.dcache.nfs.nfsstat) CacheException(diskCacheV111.util.CacheException) ChimeraNFSException(org.dcache.nfs.ChimeraNFSException) KafkaTemplate(org.springframework.kafka.core.KafkaTemplate) LAYOUTRETURN4args(org.dcache.nfs.v4.xdr.LAYOUTRETURN4args) CDCScheduledExecutorServiceDecorator(org.dcache.util.CDCScheduledExecutorServiceDecorator) org.dcache.nfs.v4.xdr.utf8str_mixed(org.dcache.nfs.v4.xdr.utf8str_mixed) ExportFile(org.dcache.nfs.ExportFile) BadLayoutException(org.dcache.nfs.status.BadLayoutException) OncRpcSvcBuilder(org.dcache.oncrpc4j.rpc.OncRpcSvcBuilder) ExecutorService(java.util.concurrent.ExecutorService) Inode(org.dcache.nfs.vfs.Inode) CuratorFrameworkAware(org.dcache.cells.CuratorFrameworkAware) ClientRecoveryStore(org.dcache.nfs.v4.ClientRecoveryStore) Logger(org.slf4j.Logger) FireAndForgetTask(org.dcache.util.FireAndForgetTask) RedirectedTransfer(org.dcache.util.RedirectedTransfer) StatsDecoratedOperationExecutor(org.dcache.chimera.nfsv41.common.StatsDecoratedOperationExecutor) LAYOUTSTATS4args(org.dcache.nfs.v4.xdr.LAYOUTSTATS4args) RequestExecutionTimeGauges(org.dcache.commons.stats.RequestExecutionTimeGauges) MountServer(org.dcache.nfs.v3.MountServer) CostException(org.dcache.poolmanager.CostException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) Subject(javax.security.auth.Subject) OncRpcProgram(org.dcache.oncrpc4j.rpc.OncRpcProgram) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) org.dcache.nfs.v4.xdr.nfs4_prot(org.dcache.nfs.v4.xdr.nfs4_prot) Collectors.toList(java.util.stream.Collectors.toList) org.dcache.nfs.v4.xdr.device_addr4(org.dcache.nfs.v4.xdr.device_addr4) PoolMonitor(org.dcache.poolmanager.PoolMonitor) OncRpcSvc(org.dcache.oncrpc4j.rpc.OncRpcSvc) CommandException.checkCommand(dmg.util.CommandException.checkCommand) Option(dmg.util.command.Option) DateTimeFormatter(java.time.format.DateTimeFormatter) ServerFaultException(org.dcache.nfs.status.ServerFaultException) GETDEVICELIST4args(org.dcache.nfs.v4.xdr.GETDEVICELIST4args) org.dcache.nfs.v4.xdr.layouttype4(org.dcache.nfs.v4.xdr.layouttype4) Required(org.springframework.beans.factory.annotation.Required) FsExport(org.dcache.nfs.FsExport) Collections(java.util.Collections) LayoutTryLaterException(org.dcache.nfs.status.LayoutTryLaterException) NFSServerV41(org.dcache.nfs.v4.NFSServerV41) InetSocketAddress(java.net.InetSocketAddress) LayoutDriver(org.dcache.nfs.v4.LayoutDriver) NfsV41FileLayoutDriver(org.dcache.nfs.v4.NfsV41FileLayoutDriver) FlexFileLayoutDriver(org.dcache.nfs.v4.FlexFileLayoutDriver) InetAddress(java.net.InetAddress)

Example 2 with Space

use of diskCacheV111.services.space.Space in project dcache by dCache.

the class ConsistentReplicaStore method get.

/**
 * Retrieves a CacheRepositoryEntry from the wrapped meta data store. If the entry is missing or
 * fails consistency checks, the entry is reconstructed with information from PNFS.
 */
@Override
public ReplicaRecord get(PnfsId id) throws IllegalArgumentException, CacheException {
    ReplicaRecord entry = _replicaStore.get(id);
    if (entry != null && isBroken(entry)) {
        LOGGER.warn("Recovering {}...", id);
        try {
            /* It is safe to remove FROM_STORE/FROM_POOL replicas: We have
                 * another copy anyway. Files in REMOVED or DESTROYED
                 * were about to be deleted, so we can finish the job.
                 */
            switch(entry.getState()) {
                case FROM_POOL:
                case FROM_STORE:
                case REMOVED:
                case DESTROYED:
                    _replicaStore.remove(id);
                    _pnfsHandler.clearCacheLocation(id);
                    LOGGER.info("Recovering: Removed {} because it was not fully staged.", id);
                    return null;
            }
            entry = rebuildEntry(entry);
        } catch (IOException e) {
            throw new DiskErrorCacheException("I/O error in healer: " + messageOrClassName(e), e);
        } catch (FileNotFoundCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {} because name space entry was deleted.", id);
            return null;
        } catch (FileIsNewCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {}: {}", id, e.getMessage());
            return null;
        } catch (TimeoutCacheException e) {
            throw e;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new CacheException("Pool is shutting down", e);
        } catch (CacheException | NoSuchAlgorithmException e) {
            entry.update("Failed to recover replica: " + e.getMessage(), r -> r.setState(ReplicaState.BROKEN));
            LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.BROKEN_FILE, id.toString(), _poolName), "Marked {} bad: {}.", id, e.getMessage());
        }
    }
    return entry;
}
Also used : AlarmMarkerFactory(org.dcache.alarms.AlarmMarkerFactory) ReplicaStatePolicy(org.dcache.pool.classic.ReplicaStatePolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessLatency(diskCacheV111.util.AccessLatency) PredefinedAlarm(org.dcache.alarms.PredefinedAlarm) LoggerFactory(org.slf4j.LoggerFactory) Exceptions.messageOrClassName(org.dcache.util.Exceptions.messageOrClassName) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) RETENTION_POLICY(org.dcache.namespace.FileAttribute.RETENTION_POLICY) PnfsHandler(diskCacheV111.util.PnfsHandler) CacheException(diskCacheV111.util.CacheException) Iterables.concat(com.google.common.collect.Iterables.concat) SIZE(org.dcache.namespace.FileAttribute.SIZE) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) EnumSet(java.util.EnumSet) ChecksumModule(org.dcache.pool.classic.ChecksumModule) FileAttributes(org.dcache.vehicles.FileAttributes) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) PnfsId(diskCacheV111.util.PnfsId) Logger(org.slf4j.Logger) OpenOption(java.nio.file.OpenOption) LOCATIONS(org.dcache.namespace.FileAttribute.LOCATIONS) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Checksum(org.dcache.util.Checksum) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) FileAttribute(org.dcache.namespace.FileAttribute) Collections(java.util.Collections) ACCESS_LATENCY(org.dcache.namespace.FileAttribute.ACCESS_LATENCY) CHECKSUM(org.dcache.namespace.FileAttribute.CHECKSUM) RetentionPolicy(diskCacheV111.util.RetentionPolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 3 with Space

use of diskCacheV111.services.space.Space in project dcache by dCache.

the class ConsistentReplicaStoreTest method shouldDeleteBrokenReplicasWithNoNameSpaceEntry.

@Test
public void shouldDeleteBrokenReplicasWithNoNameSpaceEntry() throws Exception {
    // Given a replica with no meta data
    givenStoreHasFileOfSize(PNFSID, 17);
    // and given the name space entry does not exist
    given(_pnfs.getFileAttributes(eq(PNFSID), Mockito.anySet())).willThrow(new FileNotFoundCacheException("No such file"));
    // when reading the meta data record
    ReplicaRecord record = _consistentReplicaStore.get(PNFSID);
    // then recovery is attempted
    verify(_pnfs).getFileAttributes(eq(PNFSID), Mockito.anySet());
    // but nothing is returned
    assertThat(record, is(nullValue()));
    // and the replica is deleted
    assertThat(_replicaStore.get(PNFSID), is(nullValue()));
    assertThat(_fileStore.contains(PNFSID), is(false));
    // and the name space entry is not touched
    verify(_pnfs, never()).setFileAttributes(eq(PNFSID), Mockito.any(FileAttributes.class));
}
Also used : FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) Test(org.junit.Test)

Example 4 with Space

use of diskCacheV111.services.space.Space in project dcache by dCache.

the class ChimeraNameSpaceProvider method createUploadPath.

@Override
public FsPath createUploadPath(Subject subject, FsPath path, FsPath rootPath, Long size, AccessLatency al, RetentionPolicy rp, String spaceToken, Set<CreateOption> options) throws CacheException {
    checkState(_uploadDirectory != null, "Upload directory is not configured.");
    try {
        /* Parent directory must exist.
             */
        ExtendedInode parentOfPath = options.contains(CreateOption.CREATE_PARENTS) ? installDirectory(subject, path.parent(), INHERIT_MODE) : lookupDirectory(subject, path.parent());
        FileAttributes attributesOfParent = !Subjects.isExemptFromNamespaceChecks(subject) ? getFileAttributesForPermissionHandler(parentOfPath) : null;
        /* File must not exist unless overwrite is enabled.
             */
        try {
            ExtendedInode inodeOfPath = parentOfPath.inodeOf(path.name(), STAT);
            if (!options.contains(CreateOption.OVERWRITE_EXISTING) || (inodeOfPath.statCache().getMode() & UnixPermission.S_TYPE) != UnixPermission.S_IFREG) {
                throw new FileExistsCacheException("File exists: " + path);
            }
            /* User must be authorized to delete existing file.
                 */
            if (!Subjects.isExemptFromNamespaceChecks(subject)) {
                FileAttributes attributesOfPath = getFileAttributesForPermissionHandler(inodeOfPath);
                if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfPath) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied: " + path);
                }
            }
        } catch (FileNotFoundChimeraFsException ignored) {
        }
        /* User must be authorized to create file.
             */
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            if (_permissionHandler.canCreateFile(subject, attributesOfParent) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        /* Attributes are inherited from real parent directory.
             */
        int mode = parentOfPath.statCache().getMode() & UnixPermission.S_PERMS;
        int gid;
        if ((mode & UnixPermission.S_ISGID) != 0) {
            gid = parentOfPath.statCache().getGid();
        } else if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            gid = parentOfPath.statCache().getGid();
        } else {
            gid = Ints.checkedCast(Subjects.getPrimaryGid(subject));
        }
        int uid;
        if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            uid = parentOfPath.statCache().getUid();
        } else {
            uid = Ints.checkedCast(Subjects.getUid(subject));
        }
        /* ACLs are copied from real parent to the temporary upload directory
             * such that the upload is allowed (in case write permissions rely
             * on ACLs) and such that the file will inherit the correct ACLs.
             */
        List<ACE> acl = _fs.getACL(parentOfPath);
        /* The temporary upload directory has the same tags as the real parent,
             * except target file specific properties are stored as tags local to
             * the upload directory.
             */
        Map<String, byte[]> tags = Maps.newHashMap(parentOfPath.getTags());
        if (spaceToken != null) {
            tags.put(TAG_WRITE_TOKEN, spaceToken.getBytes(UTF_8));
            /* If client provides space token to upload to, the access latency and
                 * retention policy tags of the upload directory must be disregarded.
                 */
            tags.remove(TAG_ACCESS_LATENCY);
            tags.remove(TAG_RETENTION_POLICY);
        }
        if (al != null) {
            tags.put(TAG_ACCESS_LATENCY, al.toString().getBytes(UTF_8));
        }
        if (rp != null) {
            tags.put(TAG_RETENTION_POLICY, rp.toString().getBytes(UTF_8));
        }
        if (size != null) {
            tags.put(TAG_EXPECTED_SIZE, size.toString().getBytes(UTF_8));
        }
        tags.put(TAG_PATH, path.toString().getBytes(UTF_8));
        /* Upload directory may optionally be relative to the user's root path. Whether
             * that's the case depends on if the configured upload directory is an absolute
             * or relative path.
             */
        FsPath uploadDirectory = rootPath.resolve(_uploadDirectory);
        if (_uploadSubDirectory != null) {
            uploadDirectory = uploadDirectory.chroot(String.format(_uploadSubDirectory, threadId.get()));
        }
        /* Upload directory must exist and have the right permissions.
             */
        ExtendedInode inodeOfUploadDir = installSystemDirectory(uploadDirectory, 0711, Collections.emptyList(), Collections.emptyMap());
        if (inodeOfUploadDir.statCache().getUid() != 0) {
            LOGGER.error("Owner must be root: {}", uploadDirectory);
            throw new CacheException("Owner must be root: " + uploadDirectory);
        }
        if ((inodeOfUploadDir.statCache().getMode() & UnixPermission.S_PERMS) != 0711) {
            LOGGER.error("File mode must be 0711: {}", uploadDirectory);
            throw new CacheException("File mode must be 0711: " + uploadDirectory);
        }
        /* Use cryptographically strong pseudo random UUID to create temporary upload directory.
             */
        UUID uuid = UUID.randomUUID();
        _fs.mkdir(inodeOfUploadDir, uuid.toString(), uid, gid, mode, acl, tags);
        return uploadDirectory.child(uuid.toString()).child(path.name());
    } catch (ChimeraFsException e) {
        LOGGER.error("Problem with database: {}", e.getMessage());
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : ACE(org.dcache.acl.ACE) 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) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) UUID(java.util.UUID) FileAttributes(org.dcache.vehicles.FileAttributes) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath)

Example 5 with Space

use of diskCacheV111.services.space.Space in project dcache by dCache.

the class CostModuleTest method buildPoolUpMessageWithCost.

/**
 * Create a pool-up message for a pool with the given space parameters
 *
 * @param poolName       name of the pool
 * @param totalSpace     total capacity of the pool in Gigabytes
 * @param freeSpace      space not yet used in Gigabytes
 * @param preciousSpace  space used by files marked precious in Gigabytes
 * @param removableSpace space used by files that are removable in Gigabytes
 * @return
 */
private static PoolManagerPoolUpMessage buildPoolUpMessageWithCost(String poolName, long totalSpace, long freeSpace, long preciousSpace, long removableSpace) {
    PoolV2Mode poolMode = new PoolV2Mode(PoolV2Mode.ENABLED);
    PoolCostInfo poolCost = new PoolCostInfo(poolName, IoQueueManager.DEFAULT_QUEUE);
    poolCost.setSpaceUsage(GiB.toBytes(totalSpace), GiB.toBytes(freeSpace), GiB.toBytes(preciousSpace), GiB.toBytes(removableSpace));
    long serialId = System.currentTimeMillis();
    return new PoolManagerPoolUpMessage(poolName, serialId, poolMode, poolCost);
}
Also used : PoolManagerPoolUpMessage(diskCacheV111.vehicles.PoolManagerPoolUpMessage) PoolV2Mode(diskCacheV111.pools.PoolV2Mode) PoolCostInfo(diskCacheV111.pools.PoolCostInfo)

Aggregations

CacheException (diskCacheV111.util.CacheException)27 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)22 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)21 FileAttributes (org.dcache.vehicles.FileAttributes)20 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)17 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)17 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)17 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)16 NotDirCacheException (diskCacheV111.util.NotDirCacheException)15 SRMException (org.dcache.srm.SRMException)13 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)13 FsPath (diskCacheV111.util.FsPath)12 PnfsId (diskCacheV111.util.PnfsId)12 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)11 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)11 PnfsHandler (diskCacheV111.util.PnfsHandler)10 PoolCostInfo (diskCacheV111.pools.PoolCostInfo)8 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)8 ArrayList (java.util.ArrayList)7 Subject (javax.security.auth.Subject)7