Search in sources :

Example 1 with ChecksumType

use of org.dcache.util.ChecksumType in project dcache by dCache.

the class FsInode_CKSTYP method getChecksums.

private String getChecksums() {
    StringBuilder sb = new StringBuilder();
    ChecksumType[] list = ChecksumType.values();
    for (ChecksumType type : list) {
        sb.append(type.getName()).append("\n");
    }
    return sb.toString();
}
Also used : ChecksumType(org.dcache.util.ChecksumType)

Example 2 with ChecksumType

use of org.dcache.util.ChecksumType in project dcache by dCache.

the class FsInode_PSET method handleSetChecksum.

/*
     *  This method allows overwrite only with ROOT access.
     *  It also allows a non-ROOT user to set only one checksum
     *  (type, value) pair.
     */
private void handleSetChecksum() throws ChimeraFsException {
    if (_args.length != 3) {
        throw new InvalidArgumentChimeraException("incorrect number of arguments.");
    }
    Set<Checksum> checksums = _fs.getInodeChecksums(this);
    ChecksumType type = ChecksumType.getChecksumType(_args[1]);
    try {
        /*
             * The filesystem implementation does not allow
             * overwrite using the 'setInodeChecksum' method, so
             * an explicit deletion is required.
             */
        if (checksums.stream().anyMatch(c -> type.equals(c.getType()))) {
            _fs.removeInodeChecksum(this, type.getType());
        }
        Checksum cks = new Checksum(type, _args[2]);
        _fs.setInodeChecksum(this, type.getType(), cks.getValue());
    } catch (IllegalArgumentException e) {
        throw new InvalidArgumentChimeraException("Invalid checksum: " + _args[2] + "; " + e.getMessage());
    }
}
Also used : Checksum(org.dcache.util.Checksum) ChecksumType(org.dcache.util.ChecksumType)

Example 3 with ChecksumType

use of org.dcache.util.ChecksumType in project dcache by dCache.

the class ChecksumModuleV1 method enforcePostTransferPolicy.

@Override
public void enforcePostTransferPolicy(ReplicaDescriptor handle, Iterable<Checksum> actualChecksums) throws CacheException, NoSuchAlgorithmException, IOException, InterruptedException {
    Iterable<Checksum> expectedChecksums = handle.getChecksums();
    if (hasPolicy(ON_WRITE) || (hasPolicy(ENFORCE_CRC) && isEmpty(expectedChecksums) && isEmpty(actualChecksums))) {
        EnumSet<ChecksumType> types = EnumSet.copyOf(_defaultChecksumType);
        expectedChecksums.forEach(c -> types.add(c.getType()));
        actualChecksums.forEach(// REVISIT do we really need to recalculate these?
        c -> types.add(c.getType()));
        List<MessageDigest> digests = types.stream().map(ChecksumType::createMessageDigest).collect(Collectors.toList());
        try (RepositoryChannel channel = handle.createChannel()) {
            actualChecksums = computeChecksums(channel, digests);
        }
    }
    compareChecksums(expectedChecksums, actualChecksums);
    handle.addChecksums(actualChecksums);
}
Also used : RepositoryChannel(org.dcache.pool.repository.RepositoryChannel) Checksum(org.dcache.util.Checksum) MessageDigest(java.security.MessageDigest) ChecksumType(org.dcache.util.ChecksumType)

Example 4 with ChecksumType

use of org.dcache.util.ChecksumType in project dcache by dCache.

the class ChecksumModuleV1 method verifyBrokenFile.

@Override
public Set<Checksum> verifyBrokenFile(ReplicaRecord entry, Set<Checksum> expectedChecksums) throws IOException, FileCorruptedCacheException, InterruptedException {
    Set<Checksum> additionalChecksums = Collections.emptySet();
    switch(entry.getState()) {
        case FROM_CLIENT:
            EnumSet<ChecksumType> types = EnumSet.noneOf(ChecksumType.class);
            expectedChecksums.stream().forEach(c -> types.add(c.getType()));
            if (hasPolicy(ON_WRITE) || (hasPolicy(ON_TRANSFER) && hasPolicy(ENFORCE_CRC))) {
                types.addAll(_defaultChecksumType);
            }
            if (!types.isEmpty()) {
                List<MessageDigest> digests = types.stream().map(ChecksumType::createMessageDigest).collect(Collectors.toList());
                try (RepositoryChannel channel = entry.openChannel(FileStore.O_READ)) {
                    Set<Checksum> actualChecksums = computeChecksums(channel, digests);
                    compareChecksums(expectedChecksums, actualChecksums);
                    additionalChecksums = Sets.difference(actualChecksums, expectedChecksums).copyInto(new HashSet<>());
                }
            }
    }
    return additionalChecksums;
}
Also used : RepositoryChannel(org.dcache.pool.repository.RepositoryChannel) Checksum(org.dcache.util.Checksum) MessageDigest(java.security.MessageDigest) ChecksumType(org.dcache.util.ChecksumType) HashSet(java.util.HashSet)

Example 5 with ChecksumType

use of org.dcache.util.ChecksumType in project dcache by dCache.

the class AbstractFtpDoorV1 method buildChecksumList.

private static String buildChecksumList() {
    String result = "";
    int mod = 0;
    for (ChecksumType type : ChecksumType.values()) {
        result += type.getName() + ",";
        mod = 1;
    }
    return result.substring(0, result.length() - mod);
}
Also used : ChecksumType(org.dcache.util.ChecksumType) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Aggregations

ChecksumType (org.dcache.util.ChecksumType)11 Checksum (org.dcache.util.Checksum)9 CacheException (diskCacheV111.util.CacheException)3 IOException (java.io.IOException)3 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 FsPath (diskCacheV111.util.FsPath)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2 NotFileCacheException (diskCacheV111.util.NotFileCacheException)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2 CellEndpoint (dmg.cells.nucleus.CellEndpoint)2 MessageDigest (java.security.MessageDigest)2 RepositoryChannel (org.dcache.pool.repository.RepositoryChannel)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1