Search in sources :

Example 1 with PnfsGetCacheLocationsMessage

use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.

the class RemoteNameSpaceProviderTests method shouldSucceedWhenGetCacheLocationForFileWithTwoLocations.

@Test
public void shouldSucceedWhenGetCacheLocationForFileWithTwoLocations() throws Exception {
    givenSuccessfulResponse((Modifier<PnfsGetCacheLocationsMessage>) (r) -> r.setCacheLocations(Lists.newArrayList("pool-1", "pool-2")));
    List<String> locations = _namespace.getCacheLocation(ROOT, A_PNFSID);
    PnfsGetCacheLocationsMessage sent = getSingleSendAndWaitMessage(PnfsGetCacheLocationsMessage.class);
    assertThat(sent.getReplyRequired(), is(true));
    assertThat(sent.getSubject(), is(ROOT));
    assertThat(sent.getPnfsId(), is(A_PNFSID));
    assertThat(locations, hasSize(2));
    assertThat(locations, hasItem("pool-1"));
    assertThat(locations, hasItem("pool-2"));
}
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) PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) Test(org.junit.Test)

Example 2 with PnfsGetCacheLocationsMessage

use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.

the class LegacyAdminShell method ac_set_deletable_$_1.

public String ac_set_deletable_$_1(Args args) throws Exception {
    checkPermission("*.*.*");
    PnfsId pnfsId = new PnfsId(args.argv(0));
    StringBuilder sb = new StringBuilder();
    PnfsFlagMessage pfm = new PnfsFlagMessage(pnfsId, "d", PnfsFlagMessage.FlagOperation.SET);
    pfm.setValue("true");
    try {
        pfm = (PnfsFlagMessage) sendObject("PnfsManager", pfm);
    } catch (Exception ee) {
        sb.append("Attempt to set 'd' flag reported an Exception : ").append(ee);
        sb.append("\n");
        sb.append("Operation aborted\n");
        return sb.toString();
    }
    if (pfm.getReturnCode() != 0) {
        sb.append("set 'd' flag reported  : ").append(pfm.getErrorObject());
        return sb.toString();
    }
    sb.append("Setting 'd' succeeded\n");
    PnfsGetCacheLocationsMessage locations = new PnfsGetCacheLocationsMessage(pnfsId);
    try {
        locations = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", locations);
    } catch (Exception ee) {
        sb.append("Attempt to get cache locations reported an Exception : ").append(ee);
        sb.append("\n");
        sb.append("Operation aborted\n");
        return sb.toString();
    }
    if (locations.getReturnCode() != 0) {
        sb.append("Problem in getting cache location(s) : ").append(locations.getErrorObject());
        return sb.toString();
    }
    List<String> assumedLocations = locations.getCacheLocations();
    sb.append("Assumed cache locations : ").append(assumedLocations.toString()).append("\n");
    for (Object assumedLocation : assumedLocations) {
        String poolName = assumedLocation.toString();
        PoolModifyPersistencyMessage p = new PoolModifyPersistencyMessage(poolName, pnfsId, false);
        try {
            p = (PoolModifyPersistencyMessage) sendObject(poolName, p);
        } catch (Exception ee) {
            sb.append("Attempt to contact ").append(poolName).append(" reported an Exception : ").append(ee.toString()).append("\n").append("  Operation continues\n");
            continue;
        }
        if (locations.getReturnCode() != 0) {
            sb.append("Set 'cached' reply from ").append(poolName).append(" : ").append(p.getErrorObject()).append("\n");
        } else {
            sb.append("Set 'cached' OK for ").append(poolName).append("\n");
        }
    }
    return sb.toString();
}
Also used : PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) PoolModifyPersistencyMessage(diskCacheV111.vehicles.PoolModifyPersistencyMessage) PnfsId(diskCacheV111.util.PnfsId) AuthorizedString(dmg.util.AuthorizedString) CommandThrowableException(dmg.util.CommandThrowableException) AclException(dmg.util.AclException) CommandException(dmg.util.CommandException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundException(java.io.FileNotFoundException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CacheException(diskCacheV111.util.CacheException) CommandSyntaxException(dmg.util.CommandSyntaxException) ExecutionException(java.util.concurrent.ExecutionException) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage)

Example 3 with PnfsGetCacheLocationsMessage

use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.

the class LegacyAdminShell method uncache.

private String uncache(String destination, String target, StringBuffer sb) throws Exception {
    if ((target == null) || (target.isEmpty())) {
        target = "*";
    }
    boolean verbose = sb != null;
    PnfsId pnfsId;
    if (destination.startsWith("/pnfs")) {
        PnfsGetFileAttributes map = new PnfsGetFileAttributes(destination, EnumSet.of(FileAttribute.PNFSID));
        map.setFollowSymlink(false);
        map = (PnfsGetFileAttributes) sendObject("PnfsManager", map);
        if (map.getReturnCode() != 0) {
            Object o = map.getErrorObject();
            if (o instanceof Exception) {
                throw (Exception) o;
            } else {
                throw new Exception(o.toString());
            }
        }
        pnfsId = map.getFileAttributes().getPnfsId();
    } else {
        pnfsId = new PnfsId(destination);
    }
    checkPermission("pool.*.uncache");
    PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage(pnfsId);
    pnfsMessage = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", pnfsMessage);
    if (pnfsMessage.getReturnCode() != 0) {
        throw new FileNotFoundException(destination);
    }
    List<String> locations = pnfsMessage.getCacheLocations();
    if (verbose) {
        sb.append("Location(s) : ");
        for (Object location : locations) {
            sb.append(location.toString()).append(",");
        }
        sb.append("\n");
    }
    if (target.equals("*")) {
        if (verbose) {
            sb.append("Selection : <all>\n");
        }
    } else if (locations.contains(target)) {
        if (verbose) {
            sb.append("Selection : ").append(target).append("\n");
        }
        locations = new ArrayList<>();
        locations.add(target);
    } else {
        if (verbose) {
            sb.append("Selection : <nothing>\n");
        }
        return sb == null ? "" : sb.toString();
    }
    PoolRemoveFilesMessage remove;
    for (Object location : locations) {
        String poolName = location.toString();
        if (verbose) {
            sb.append(poolName).append(" : ");
        }
        try {
            remove = new PoolRemoveFilesMessage(poolName, pnfsId.toString());
            remove = (PoolRemoveFilesMessage) sendObject(poolName, remove);
            if (verbose) {
                int rc = remove.getReturnCode();
                if (rc != 0) {
                    Object obj = remove.getErrorObject();
                    if ((obj != null) && (obj instanceof Object[])) {
                        Object o = ((Object[]) obj)[0];
                        if (o != null) {
                            sb.append("[").append(rc).append("] Failed ").append(o.toString());
                        }
                    } else if (obj != null) {
                        sb.append("[").append(rc).append("] Failed ").append(obj.toString());
                    }
                } else {
                    sb.append("ok");
                }
            }
        } catch (Exception ee) {
            if (verbose) {
                sb.append(ee.getMessage());
            }
        }
        if (verbose) {
            sb.append("\n");
        }
    }
    return sb == null ? "" : sb.toString();
}
Also used : PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) PoolRemoveFilesMessage(diskCacheV111.vehicles.PoolRemoveFilesMessage) AuthorizedString(dmg.util.AuthorizedString) CommandThrowableException(dmg.util.CommandThrowableException) AclException(dmg.util.AclException) CommandException(dmg.util.CommandException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundException(java.io.FileNotFoundException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CacheException(diskCacheV111.util.CacheException) CommandSyntaxException(dmg.util.CommandSyntaxException) ExecutionException(java.util.concurrent.ExecutionException) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Example 4 with PnfsGetCacheLocationsMessage

use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.

the class PnfsManagerV3 method getCacheLocations.

public void getCacheLocations(PnfsGetCacheLocationsMessage pnfsMessage) {
    Subject subject = pnfsMessage.getSubject();
    try {
        checkRestriction(pnfsMessage, READ_METADATA);
        PnfsId pnfsId = populatePnfsId(pnfsMessage);
        LOGGER.info("get cache locations for {}", pnfsId);
        checkMask(pnfsMessage);
        pnfsMessage.setCacheLocations(_nameSpaceProvider.getCacheLocation(subject, pnfsId));
        pnfsMessage.setSucceeded();
    } catch (FileNotFoundCacheException fnf) {
        pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, fnf.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Exception in getCacheLocations: {}", e.toString());
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Exception in getCacheLocations", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs lookup failed");
    }
}
Also used : MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) Subject(javax.security.auth.Subject)

Example 5 with PnfsGetCacheLocationsMessage

use of diskCacheV111.vehicles.PnfsGetCacheLocationsMessage in project dcache by dCache.

the class PnfsHandler method getCacheLocationsByPath.

public List<String> getCacheLocationsByPath(String fileName) throws CacheException {
    PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage();
    pnfsMessage.setPnfsPath(fileName);
    pnfsMessage = request(pnfsMessage);
    List<String> assumedLocations = pnfsMessage.getCacheLocations();
    if (assumedLocations == null) {
        return Collections.emptyList();
    } else {
        return assumedLocations;
    }
}
Also used : PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage)

Aggregations

PnfsGetCacheLocationsMessage (diskCacheV111.vehicles.PnfsGetCacheLocationsMessage)10 PnfsId (diskCacheV111.util.PnfsId)7 CacheException (diskCacheV111.util.CacheException)6 SerializationException (dmg.cells.nucleus.SerializationException)5 CellEndpoint (dmg.cells.nucleus.CellEndpoint)4 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)4 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)3 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)3 PnfsClearCacheLocationMessage (diskCacheV111.vehicles.PnfsClearCacheLocationMessage)3 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)3 PnfsFlagMessage (diskCacheV111.vehicles.PnfsFlagMessage)3 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)3 AclException (dmg.util.AclException)3 AuthorizedString (dmg.util.AuthorizedString)3 CommandException (dmg.util.CommandException)3 CommandExitException (dmg.util.CommandExitException)3 CommandSyntaxException (dmg.util.CommandSyntaxException)3 Test (org.junit.Test)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2