Search in sources :

Example 1 with FileSystemMasterClient

use of alluxio.client.file.FileSystemMasterClient in project alluxio by Alluxio.

the class MasterClientAuthenticationIntegrationTest method customAuthenticationDenyConnect.

@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_AUTHENTICATION_TYPE, "CUSTOM", PropertyKey.Name.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, NameMatchAuthenticationProvider.FULL_CLASS_NAME, PropertyKey.Name.SECURITY_LOGIN_USERNAME, "alluxio" })
public void customAuthenticationDenyConnect() throws Exception {
    mThrown.expect(ConnectionFailedException.class);
    try (FileSystemMasterClient masterClient = FileSystemMasterClient.Factory.create(mLocalAlluxioClusterResource.get().getMaster().getAddress())) {
        Assert.assertFalse(masterClient.isConnected());
        // Using no-alluxio as loginUser to connect to Master, the IOException will be thrown
        LoginUserTestUtils.resetLoginUser("no-alluxio");
        masterClient.connect();
    }
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) Test(org.junit.Test)

Example 2 with FileSystemMasterClient

use of alluxio.client.file.FileSystemMasterClient in project alluxio by Alluxio.

the class FileSystemMasterClientIntegrationTest method openClose.

@Test
public void openClose() throws AlluxioException, IOException {
    FileSystemMasterClient fsMasterClient = FileSystemMasterClient.Factory.create(mLocalAlluxioClusterResource.get().getMaster().getAddress());
    AlluxioURI file = new AlluxioURI("/file");
    Assert.assertFalse(fsMasterClient.isConnected());
    fsMasterClient.connect();
    Assert.assertTrue(fsMasterClient.isConnected());
    fsMasterClient.createFile(file, CreateFileOptions.defaults());
    Assert.assertNotNull(fsMasterClient.getStatus(file));
    fsMasterClient.disconnect();
    Assert.assertFalse(fsMasterClient.isConnected());
    fsMasterClient.connect();
    Assert.assertTrue(fsMasterClient.isConnected());
    Assert.assertNotNull(fsMasterClient.getStatus(file));
    fsMasterClient.close();
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 3 with FileSystemMasterClient

use of alluxio.client.file.FileSystemMasterClient in project alluxio by Alluxio.

the class FileSystemMasterClientIntegrationTest method getFileInfoReturnsOnError.

@Test(timeout = 3000, expected = AlluxioException.class)
public void getFileInfoReturnsOnError() throws IOException, AlluxioException {
    // This test was created to show that an infinite loop occurs.
    // The timeout will protect against this, and the change was to throw a IOException
    // in the cases we don't want to disconnect from master
    FileSystemMasterClient fsMasterClient = FileSystemMasterClient.Factory.create(mLocalAlluxioClusterResource.get().getMaster().getAddress());
    fsMasterClient.getStatus(new AlluxioURI("/doesNotExist"));
    fsMasterClient.close();
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 4 with FileSystemMasterClient

use of alluxio.client.file.FileSystemMasterClient in project alluxio by Alluxio.

the class AbstractFileSystem method initializeInternal.

/**
   * Initializes the default contexts if the master address specified in the URI is different
   * from the default one.
   *
   * @param uri the uri
   * @param conf the hadoop conf
   * @throws IOException if it fails to initialize
   */
void initializeInternal(URI uri, org.apache.hadoop.conf.Configuration conf) throws IOException {
    // Load Alluxio configuration if any and merge to the one in Alluxio file system. These
    // modifications to ClientContext are global, affecting all Alluxio clients in this JVM.
    // We assume here that all clients use the same configuration.
    ConfUtils.mergeHadoopConfiguration(conf);
    Configuration.set(PropertyKey.ZOOKEEPER_ENABLED, isZookeeperMode());
    if (!Configuration.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) {
        Configuration.set(PropertyKey.MASTER_HOSTNAME, uri.getHost());
        Configuration.set(PropertyKey.MASTER_RPC_PORT, uri.getPort());
    }
    // These must be reset to pick up the change to the master address.
    // TODO(andrew): We should reset key value system in this situation - see ALLUXIO-1706.
    LineageContext.INSTANCE.reset();
    FileSystemContext.INSTANCE.reset();
    // Try to connect to master, if it fails, the provided uri is invalid.
    FileSystemMasterClient client = FileSystemContext.INSTANCE.acquireMasterClient();
    try {
        client.connect();
    // Connected, initialize.
    } catch (ConnectionFailedException | IOException e) {
        LOG.error("Failed to connect to the provided master address {}: {}.", uri.toString(), e.toString());
        throw new IOException(e);
    } finally {
        FileSystemContext.INSTANCE.releaseMasterClient(client);
    }
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) IOException(java.io.IOException) ConnectionFailedException(alluxio.exception.ConnectionFailedException)

Example 5 with FileSystemMasterClient

use of alluxio.client.file.FileSystemMasterClient in project alluxio by Alluxio.

the class MasterClientAuthenticationIntegrationTest method authenticationOperationTest.

/**
   * Tests Alluxio client connects or disconnects to the Master. When the client connects
   * successfully to the Master, it can successfully create file or not.
   *
   * @param filename the name of the file
   * @throws Exception if a {@link FileSystemMasterClient} operation fails
   */
private void authenticationOperationTest(String filename) throws Exception {
    FileSystemMasterClient masterClient = FileSystemMasterClient.Factory.create(mLocalAlluxioClusterResource.get().getMaster().getAddress());
    Assert.assertFalse(masterClient.isConnected());
    masterClient.connect();
    Assert.assertTrue(masterClient.isConnected());
    masterClient.createFile(new AlluxioURI(filename), CreateFileOptions.defaults());
    Assert.assertNotNull(masterClient.getStatus(new AlluxioURI(filename)));
    masterClient.disconnect();
    masterClient.close();
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileSystemMasterClient (alluxio.client.file.FileSystemMasterClient)7 AlluxioURI (alluxio.AlluxioURI)5 Test (org.junit.Test)4 FileSystemContext (alluxio.client.file.FileSystemContext)2 URIStatus (alluxio.client.file.URIStatus)1 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 FileInfo (alluxio.wire.FileInfo)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1