agave-systems/systems-core/src/main/java/org/iplantc/service/transfer/sftp/SftpRelay.java
/**
     * Internal method to fetch and cache metadata for a remote file/folder.
     * This speeds up most operations as the logic of this adaptor heavily
     * relies on explicit metadata checking for each operation.
     *
     * @param resolvedPath
     * @return
     * @throws FileNotFoundException
     * @throws RemoteDataException
     */
Internal method to fetch and cache metadata for a remote file/folder.
This speeds up most operations as the logic of this adaptor heavily
relies on explicit metadata checking for each operation.

@param resolvedPath
@return
@throws FileNotFoundException
@throws RemoteDataException
Internal method to fetch and cache metadata for a remote file / folder . This speeds up most operations as the logic of this adaptor heavily relies on explicit metadata checking for each operation . @param resolvedPath @return @throws FileNotFoundException @throws RemoteDataException
protected RemoteFileInfo stat(String resolvedPath) throws FileNotFoundException, RemoteDataException {
        try {
            SftpRelayGrpc.SftpRelayBlockingStub grpcClient = getGrpcClient();
            RemoteSystemConfig remoteSystemConfig = getRemoteSystemConfig();
            SrvStatRequest srvStatRequest = SrvStatRequest.newBuilder()
                    .setSystemConfig(remoteSystemConfig)
                    .setRemotePath(resolvedPath)
                    .build();
            FileInfoResponse fileInfoResponse = grpcClient.stat(srvStatRequest);
            if (StringUtils.isNotBlank(fileInfoResponse.getError())) {
                String errorMessage = fileInfoResponse.getError();
                if (errorMessage.contains("does not exist") || errorMessage.contains("no such file or directory")) {
                    throw new FileNotFoundException(errorMessage);
                } else {
                    throw new RemoteDataException(errorMessage);
                }
            } else {
                RemoteFileInfo grpcFileInfo = new RemoteFileInfo(fileInfoResponse.getRemoteFileInfo());
                grpcFileInfo.setOwner(username);
                fileInfoCache.put(resolvedPath, grpcFileInfo);
                return grpcFileInfo;
            }
        } catch (FileNotFoundException | RemoteDataException e) {
            fileInfoCache.remove(resolvedPath);
            throw e;
        } catch (Throwable e) {
            fileInfoCache.remove(resolvedPath);
            throw new RemoteDataException("Unknown error calling stat on the relay server");
        }
    }
protected RemoteFileInfo stat ( String resolvedPath ) throws FileNotFoundException , RemoteDataException { try { SftpRelayGrpc . SftpRelayBlockingStub grpcClient = getGrpcClient ( ) ; RemoteSystemConfig remoteSystemConfig = getRemoteSystemConfig ( ) ; SrvStatRequest srvStatRequest = SrvStatRequest . newBuilder ( ) . setSystemConfig ( remoteSystemConfig ) . setRemotePath ( resolvedPath ) . build ( ) ; FileInfoResponse fileInfoResponse = grpcClient . stat ( srvStatRequest ) ; if ( StringUtils . isNotBlank ( fileInfoResponse . getError ( ) ) ) { String errorMessage = fileInfoResponse . getError ( ) ; if ( errorMessage . contains ( "does not exist" ) || errorMessage . contains ( "no such file or directory" ) ) { throw new FileNotFoundException ( errorMessage ) ; } else { throw new RemoteDataException ( errorMessage ) ; } } else { RemoteFileInfo grpcFileInfo = new RemoteFileInfo ( fileInfoResponse . getRemoteFileInfo ( ) ) ; grpcFileInfo . setOwner ( username ) ; fileInfoCache . put ( resolvedPath , grpcFileInfo ) ; return grpcFileInfo ; } } catch ( FileNotFoundException | RemoteDataException e ) { fileInfoCache . remove ( resolvedPath ) ; throw e ; } catch ( Throwable e ) { fileInfoCache . remove ( resolvedPath ) ; throw new RemoteDataException ( "Unknown error calling stat on the relay server" ) ; } }
Internal method to fetch and cache metadata for a remote file/folder.
Internal method to fetch and cache metadata for a remote file / folder .
//create a SrvStatRequest // call the gRPC and get back a SrvPutResponse //#********************************************************************************** // this has to be valid or the whole relay is busted //                grpcFileInfo.setName(fileInfoResponse.getRemoteFileInfo().getName()); //                grpcFileInfo.setFileType(fileInfoResponse.getRemoteFileInfo().getIsDirectory() ? //                        RemoteFileInfo.DIRECTORY_TYPE : RemoteFileInfo.FILE_TYPE); //                grpcFileInfo.setSize(fileInfoResponse.getRemoteFileInfo().getSize()); //                grpcFileInfo.setLastModified(Date.from(Instant.ofEpochSecond(fileInfoResponse.getRemoteFileInfo().getLastUpdated()))); //                grpcFileInfo.setOwner(username); //                grpcFileInfo.updateMode(fileInfoResponse.getRemoteFileInfo().getMode());