Example usage for org.apache.commons.vfs2.provider GenericFileName getHostName

List of usage examples for org.apache.commons.vfs2.provider GenericFileName getHostName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.provider GenericFileName getHostName.

Prototype

public String getHostName() 

Source Link

Document

Returns the host name part of this name.

Usage

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GridFTPClientWrapper.java

/**
 * Instantiates a new grid ftp client wrapper.
 * //w  w w .  j  av  a2 s.co m
 * @param root the root
 * @param fileSystemOptions the file system options
 * 
 * @throws ServerException the server exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public GridFTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions)
        throws ServerException, IOException {
    super(root.getHostName(), root.getPort());
    this.root = root;
    this.fileSystemOptions = fileSystemOptions;
    getGridFtpClient(); // fail-fast
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileSystem.java

/**
 * Creates an FTP client to use.//w  ww .  j av  a2 s. c om
 * 
 * @return the client
 * 
 * @throws FileSystemException the file system exception
 */
public GridFTPClient getClient() throws FileSystemException {
    synchronized (idleClientSync) {
        if (idleClient == null) {
            final GenericFileName rootName = (GenericFileName) getRoot().getName();

            LOG.debug("Creating connection to GSIFTP Host: " + rootName.getHostName() + " Port:"
                    + rootName.getPort() + " User:" + rootName.getUserName() + " Path: " + rootName.getPath());

            return GsiFtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
                    rootName.getUserName(), rootName.getPassword(),
                    // rootName.getPath(),
                    getFileSystemOptions());
        } else {
            final GridFTPClient client = idleClient;
            idleClient = null;
            return client;
        }
    }
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GridFTPClientWrapper.java

/**
 * Creates the client./*from  w  w w .jav a  2  s. c  o m*/
 * 
 * @return the grid ftp client
 * 
 * @throws FileSystemException the file system exception
 */
protected GridFTPClient createClient() throws FileSystemException {
    final GenericFileName rootName = getRoot();

    UserAuthenticationData authData = null;
    try {
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions,
                GsiFtpFileProvider.AUTHENTICATOR_TYPES);

        String username = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                UserAuthenticatorUtils.toChar(rootName.getUserName())).toString();
        String password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                UserAuthenticatorUtils.toChar(rootName.getPassword())).toString();
        return GsiFtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), username,
                password, getFileSystemOptions());
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }
}

From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileProvider.java

@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    GenericFileName genericFileName = (GenericFileName) name.getRoot();
    String hostName = genericFileName.getHostName();
    int port = genericFileName.getPort();
    // TODO: load from metastore
    NamedCluster namedCluster = namedClusterService.getClusterTemplate();
    namedCluster.setHdfsHost(hostName);/*from  w  w w. j  a  va  2 s  .  c o m*/
    if (port > 0) {
        namedCluster.setHdfsPort(String.valueOf(port));
    } else {
        namedCluster.setHdfsPort("");
    }
    namedCluster.setMapr(MAPRFS.equals(name.getScheme()));
    try {
        return new HDFSFileSystem(name, fileSystemOptions, hadoopFileSystemLocator
                .getHadoopFilesystem(namedCluster, URI.create(name.getURI() == null ? "" : name.getURI())));
    } catch (ClusterInitializationException e) {
        throw new FileSystemException(e);
    }
}

From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileProviderTest.java

@Test
public void testDoCreateFileSystemNoPort() throws FileSystemException, ClusterInitializationException {
    String testHostname = "testHostname";
    FileName fileName = mock(FileName.class);
    GenericFileName genericFileName = mock(GenericFileName.class);
    when(fileName.getURI()).thenReturn("");
    when(fileName.getRoot()).thenReturn(genericFileName);
    when(genericFileName.getHostName()).thenReturn(testHostname);
    when(genericFileName.getPort()).thenReturn(-1);
    assertTrue(hdfsFileProvider.doCreateFileSystem(fileName, null) instanceof HDFSFileSystem);
    verify(hadoopFileSystemLocator).getHadoopFilesystem(namedCluster, URI.create(""));
    verify(namedCluster).setHdfsHost(testHostname);
    verify(namedCluster).setHdfsPort("");
}

From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileProviderTest.java

@Test
public void testDoCreateFileSystemPort() throws FileSystemException, ClusterInitializationException {
    String testHostname = "testHostname";
    FileName fileName = mock(FileName.class);
    GenericFileName genericFileName = mock(GenericFileName.class);
    when(fileName.getURI()).thenReturn("");
    when(fileName.getRoot()).thenReturn(genericFileName);
    when(genericFileName.getHostName()).thenReturn(testHostname);
    when(genericFileName.getPort()).thenReturn(111);
    assertTrue(hdfsFileProvider.doCreateFileSystem(fileName, null) instanceof HDFSFileSystem);
    verify(hadoopFileSystemLocator).getHadoopFilesystem(namedCluster, URI.create(""));
    verify(namedCluster).setHdfsHost(testHostname);
    verify(namedCluster).setHdfsPort("111");
}

From source file:org.pentaho.big.data.impl.vfs.hdfs.nc.NamedClusterProvider.java

@Override
protected FileSystem doCreateFileSystem(FileName name, FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    GenericFileName genericFileName = (GenericFileName) name.getRoot();
    String clusterName = genericFileName.getHostName();
    String path = genericFileName.getPath();
    NamedCluster namedCluster = getNamedClusterByName(clusterName, fileSystemOptions);
    try {/* w  w w .jav a  2  s.c  o  m*/
        if (namedCluster == null) {
            namedCluster = namedClusterService.getClusterTemplate();
        }
        String generatedUrl = namedCluster.processURLsubstitution(path == null ? "" : path,
                getMetastore(clusterName, fileSystemOptions), new Variables());
        URI uri = URI.create(generatedUrl);

        return new NamedClusterFileSystem(name, uri, fileSystemOptions,
                hadoopFileSystemLocator.getHadoopFilesystem(namedCluster, uri));
    } catch (ClusterInitializationException e) {
        throw new FileSystemException(e);
    }
}

From source file:org.pentaho.di.core.vfs.SftpFileSystemWindows.java

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() }
 *
 *//*w w w.j  a va2 s  . co m*/
private void ensureSession() throws FileSystemException {
    if (this.session == null || !this.session.isConnected()) {
        this.doCloseCommunicationLink();
        UserAuthenticationData authData = null;

        Session session;
        try {
            GenericFileName e = (GenericFileName) this.getRootName();
            authData = UserAuthenticatorUtils.authenticate(this.getFileSystemOptions(),
                    SftpFileProvider.AUTHENTICATOR_TYPES);
            session = SftpClientFactory.createConnection(e.getHostName(), e.getPort(),
                    UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                            UserAuthenticatorUtils.toChar(e.getUserName())),
                    UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                            UserAuthenticatorUtils.toChar(e.getPassword())),
                    this.getFileSystemOptions());
        } catch (Exception var7) {
            throw new FileSystemException("vfs.provider.sftp/connect.error", this.getRootName(), var7);
        } finally {
            UserAuthenticatorUtils.cleanup(authData);
        }

        this.session = session;
    }

}

From source file:org.pentaho.reporting.libraries.pensol.PentahoSolutionFileProvider.java

private FileSystem createWebFileSystem(final LayeredFileName genericRootName,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final GenericFileName outerName = (GenericFileName) genericRootName.getOuterName();
    String scheme = outerName.getScheme();
    String hostName = outerName.getHostName();
    int port = outerName.getPort();
    String userName = outerName.getUserName();
    String password = outerName.getPassword();

    HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
    if (!StringUtil.isEmpty(hostName)) {
        clientBuilder.setProxy(hostName, port, scheme);
    }/*from  w  w  w . j a v a  2s . c o m*/
    if (!StringUtil.isEmpty(userName)) {
        clientBuilder.setCredentials(userName, password);
    }
    final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder();
    final int timeOut = configBuilder.getTimeOut(fileSystemOptions);
    clientBuilder.setSocketTimeout(Math.max(0, timeOut));

    return new WebSolutionFileSystem(genericRootName, fileSystemOptions,
            new LocalFileModel(outerName.getURI(), clientBuilder, userName, password, hostName, port));
}