@Override protected void shouldTryRemote(final ResourceStoreRequest request) throws IllegalOperationException, ItemNotFoundException { // do super first super.shouldTryRemote(request); // if here, super did not throw any exception, so let's continue // apply autorouting filter to "normal" requests only, not hidden (which is meta or plain // hidden) final RepositoryItemUid uid = createUid(request.getRequestPath()); if (!uid.getBooleanAttributeValue(IsHiddenAttribute.class)) { // but filter it only if request is not marked as NFS if (!request.getRequestContext().containsKey(Manager.ROUTING_REQUEST_NFS_FLAG_KEY)) { final boolean proxyFilterAllowed = getProxyRequestFilter().allowed(this, request); if (!proxyFilterAllowed) { throw new ItemNotFoundException( ItemNotFoundException.reasonFor( request, this, "Automatic routing filter rejected remote request for path %s from %s", request.getRequestPath(), this)); } } } }
@Override protected StorageItem doRetrieveItem(ResourceStoreRequest request) throws IllegalOperationException, ItemNotFoundException, StorageException { try { // local always wins return super.doRetrieveItem(request); } catch (ItemNotFoundException ignored) { // ignored } boolean hasRequestAuthorizedFlag = request.getRequestContext().containsKey(AccessManager.REQUEST_AUTHORIZED); if (!hasRequestAuthorizedFlag) { request.getRequestContext().put(AccessManager.REQUEST_AUTHORIZED, Boolean.TRUE); } final HashMap<Repository, Throwable> memberThrowables = new HashMap<Repository, Throwable>(); try { RepositoryItemUid uid = createUid(request.getRequestPath()); final boolean isRequestGroupLocalOnly = request.isRequestGroupLocalOnly() || uid.getBooleanAttributeValue(IsGroupLocalOnlyAttribute.class); if (!isRequestGroupLocalOnly) { if (USE_CHARGER_FOR_GROUP_REQUESTS) { List<Callable<StorageItem>> callables = new ArrayList<Callable<StorageItem>>(); for (Repository repository : getRequestRepositories(request)) { if (!request.getProcessedRepositories().contains(repository.getId())) { callables.add(new GroupItemRetrieveCallable(getLogger(), repository, request, this)); } else { if (getLogger().isDebugEnabled()) { getLogger() .debug( String.format( "Repository %s member of group %s was already processed during this request! Skipping it from processing. Request: %s", RepositoryStringUtils.getHumanizedNameString(repository), RepositoryStringUtils.getHumanizedNameString(this), request.toString())); } } } try { List<StorageItem> items = chargerHolder .getCharger() .submit(callables, new FirstArrivedInOrderChargeStrategy<StorageItem>(), this) .getResult(); if (items.size() > 0) { return items.get(0); } } catch (RejectedExecutionException e) { // this will not happen } catch (Exception e) { // will not happen, see GroupItemRetrieveCallable class' javadoc, it supresses all of // them // to make compiler happy throw new LocalStorageException("Ouch!", e); } } else { for (Repository repo : getRequestRepositories(request)) { if (!request.getProcessedRepositories().contains(repo.getId())) { try { StorageItem item = repo.retrieveItem(request); if (item instanceof StorageCollectionItem) { item = new DefaultStorageCollectionItem(this, request, true, false); } return item; } catch (IllegalOperationException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } catch (ItemNotFoundException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } catch (StorageException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } catch (AccessDeniedException e) { // cannot happen, since we add/check for AccessManager.REQUEST_AUTHORIZED flag // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } } else { if (getLogger().isDebugEnabled()) { getLogger() .debug( String.format( "Repository %s member of group %s was already processed during this request! Skipping it from processing. Request: %s", RepositoryStringUtils.getHumanizedNameString(repo), RepositoryStringUtils.getHumanizedNameString(this), request.toString())); } } } } } if (!isRequestGroupLocalOnly) { throw new GroupItemNotFoundException(request, this, memberThrowables); } else { throw new GroupItemNotFoundException( reasonFor( request, this, "The %s not found in local storage of group repository %s (no member processing happened).", request.getRequestPath(), this), memberThrowables); } } finally { if (!hasRequestAuthorizedFlag) { request.getRequestContext().remove(AccessManager.REQUEST_AUTHORIZED); } } }
public List<StorageItem> doRetrieveItems(ResourceStoreRequest request) throws GroupItemNotFoundException, StorageException { ArrayList<StorageItem> items = new ArrayList<StorageItem>(); RepositoryItemUid uid = createUid(request.getRequestPath()); final boolean isRequestGroupLocalOnly = request.isRequestGroupLocalOnly() || uid.getBooleanAttributeValue(IsGroupLocalOnlyAttribute.class); final HashMap<Repository, Throwable> memberThrowables = new HashMap<Repository, Throwable>(); if (!isRequestGroupLocalOnly) { if (USE_CHARGER_FOR_GROUP_REQUESTS) { List<Callable<StorageItem>> callables = new ArrayList<Callable<StorageItem>>(); for (Repository repository : getRequestRepositories(request)) { if (!request.getProcessedRepositories().contains(repository.getId())) { callables.add(new ItemRetrieveCallable(getLogger(), repository, request)); } else { if (getLogger().isDebugEnabled()) { getLogger() .debug( String.format( "Repository %s member of group %s was already processed during this request! Skipping it from processing. Request: %s", RepositoryStringUtils.getHumanizedNameString(repository), RepositoryStringUtils.getHumanizedNameString(this), request.toString())); } } } try { return chargerHolder .getCharger() .submit(callables, new AllArrivedChargeStrategy<StorageItem>(), this) .getResult(); } catch (RejectedExecutionException e) { // this will not happen } catch (StorageException e) { throw e; } catch (Exception e) { // will not happen, ItemRetrieveCallable supresses all except StorageException! // just to make compiler happy throw new LocalStorageException("Ouch!", e); } } else { for (Repository repository : getRequestRepositories(request)) { if (!request.getProcessedRepositories().contains(repository.getId())) { try { StorageItem item = repository.retrieveItem(false, request); items.add(item); } catch (ItemNotFoundException e) { // ignored, but bookkeeping happens now memberThrowables.put(repository, e); } catch (RepositoryNotAvailableException e) { if (getLogger().isDebugEnabled()) { getLogger() .debug( RepositoryStringUtils.getFormattedMessage( "Member repository %s is not available, request failed.", e.getRepository())); } // ignored, but bookkeeping happens now memberThrowables.put(repository, e); } catch (StorageException e) { throw e; } catch (IllegalOperationException e) { getLogger().warn("Member repository request failed", e); // ignored, but bookkeeping happens now memberThrowables.put(repository, e); } } else { if (getLogger().isDebugEnabled()) { getLogger() .debug( String.format( "Repository %s member of group %s was already processed during this request! Skipping it from processing. Request: %s", RepositoryStringUtils.getHumanizedNameString(repository), RepositoryStringUtils.getHumanizedNameString(this), request.toString())); } } } } } if (items.isEmpty()) { if (!isRequestGroupLocalOnly) { throw new GroupItemNotFoundException(request, this, memberThrowables); } else { throw new GroupItemNotFoundException( reasonFor( request, this, "The %s not found in local storage of group repository %s (no member processing happened).", request.getRequestPath(), this), memberThrowables); } } return items; }
@Override protected Collection<StorageItem> doListItems(ResourceStoreRequest request) throws ItemNotFoundException, StorageException { HashSet<String> names = new HashSet<String>(); ArrayList<StorageItem> result = new ArrayList<StorageItem>(); boolean found = false; try { addItems(names, result, getLocalStorage().listItems(this, request)); found = true; } catch (ItemNotFoundException ignored) { // ignored } RepositoryItemUid uid = createUid(request.getRequestPath()); final boolean isRequestGroupLocalOnly = request.isRequestGroupLocalOnly() || uid.getBooleanAttributeValue(IsGroupLocalOnlyAttribute.class); final HashMap<Repository, Throwable> memberThrowables = new HashMap<Repository, Throwable>(); if (!isRequestGroupLocalOnly) { for (Repository repo : getMemberRepositories()) { if (!request.getProcessedRepositories().contains(repo.getId())) { try { addItems(names, result, repo.list(false, request)); found = true; } catch (ItemNotFoundException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } catch (IllegalOperationException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } catch (StorageException e) { // ignored, but bookkeeping happens now memberThrowables.put(repo, e); } } else { if (getLogger().isDebugEnabled()) { getLogger() .debug( String.format( "Repository %s member of group %s was already processed during this request! Skipping it from processing. Request: %s", RepositoryStringUtils.getHumanizedNameString(repo), RepositoryStringUtils.getHumanizedNameString(this), request.toString())); } } } } if (!found) { if (!isRequestGroupLocalOnly) { throw new GroupItemNotFoundException(request, this, memberThrowables); } else { throw new GroupItemNotFoundException( reasonFor( request, this, "The %s not found in local storage of group repository %s (no member processing happened).", request.getRequestPath(), this), memberThrowables); } } return result; }