Search in sources :

Example 16 with FileSystemContext

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

the class AbstractFileSystemTest method verifyBlockLocations.

void verifyBlockLocations(List<WorkerNetAddress> blockWorkers, List<String> ufsLocations, List<WorkerNetAddress> allWorkers, List<WorkerNetAddress> expectedWorkers) throws Exception {
    FileBlockInfo blockInfo = new FileBlockInfo().setBlockInfo(new BlockInfo().setLocations(blockWorkers.stream().map(addr -> new alluxio.wire.BlockLocation().setWorkerAddress(addr)).collect(toList()))).setUfsLocations(ufsLocations);
    FileInfo fileInfo = new FileInfo().setLastModificationTimeMs(111L).setLastAccessTimeMs(123L).setFolder(false).setOwner("user1").setGroup("group1").setMode(00755).setFileBlockInfos(Arrays.asList(blockInfo));
    Path path = new Path("/dir/file");
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    AlluxioBlockStore blockStore = mock(AlluxioBlockStore.class);
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    PowerMockito.when(AlluxioBlockStore.create(any(FileSystemContext.class))).thenReturn(blockStore);
    FileSystemContext fsContext = mock(FileSystemContext.class);
    when(fsContext.getClientContext()).thenReturn(ClientContext.create(mConfiguration));
    when(fsContext.getClusterConf()).thenReturn(mConfiguration);
    when(fsContext.getPathConf(any(AlluxioURI.class))).thenReturn(mConfiguration);
    alluxio.client.file.FileSystem fs = alluxio.client.file.FileSystem.Factory.create(fsContext);
    alluxio.client.file.FileSystem spyFs = spy(fs);
    doReturn(new URIStatus(fileInfo)).when(spyFs).getStatus(uri);
    List<BlockWorkerInfo> eligibleWorkerInfos = allWorkers.stream().map(worker -> new BlockWorkerInfo(worker, 0, 0)).collect(toList());
    when(fsContext.getCachedWorkers()).thenReturn(eligibleWorkerInfos);
    List<HostAndPort> expectedWorkerNames = expectedWorkers.stream().map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort())).collect(toList());
    FileSystem alluxioHadoopFs = new FileSystem(spyFs);
    FileStatus file = new FileStatus(0, false, 0, 0, 0, 0, null, null, null, path);
    long start = 0;
    long len = 100;
    BlockLocation[] locations = alluxioHadoopFs.getFileBlockLocations(file, start, len);
    assertEquals(1, locations.length);
    Collections.sort(expectedWorkerNames, (x, y) -> x.toString().compareTo(y.toString()));
    String[] actualNames = locations[0].getNames();
    String[] actualHosts = locations[0].getHosts();
    Arrays.sort(actualNames);
    Arrays.sort(actualHosts);
    assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::toString).toArray(), actualNames);
    assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::getHost).toArray(), actualHosts);
    alluxioHadoopFs.close();
}
Also used : Path(org.apache.hadoop.fs.Path) Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) BlockLocation(org.apache.hadoop.fs.BlockLocation) LoggerFactory(org.slf4j.LoggerFactory) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) FileStatus(org.apache.hadoop.fs.FileStatus) PropertyKey(alluxio.conf.PropertyKey) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ClientContext(alluxio.ClientContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertThrows(org.junit.Assert.assertThrows) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ConfigurationRule(alluxio.ConfigurationRule) Constants(alluxio.Constants) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Before(org.junit.Before) Logger(org.slf4j.Logger) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigurationUtils(alluxio.util.ConfigurationUtils) HostAndPort(com.google.common.net.HostAndPort) Collectors.toList(java.util.stream.Collectors.toList) URIStatus(alluxio.client.file.URIStatus) FileSystemContext(alluxio.client.file.FileSystemContext) FileInfo(alluxio.wire.FileInfo) Closeable(java.io.Closeable) SystemPropertyRule(alluxio.SystemPropertyRule) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileStatus(org.apache.hadoop.fs.FileStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(org.apache.hadoop.fs.BlockLocation) URIStatus(alluxio.client.file.URIStatus) HostAndPort(com.google.common.net.HostAndPort) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) AlluxioURI(alluxio.AlluxioURI)

Example 17 with FileSystemContext

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

the class TestRunner method runTests.

/**
 * Runs combinations of tests of operation, read and write type.
 *
 * @return the number of failed tests
 */
private int runTests() throws Exception {
    mDirectory = PathUtils.concatPath(mDirectory, TEST_DIRECTORY_NAME);
    AlluxioURI testDir = new AlluxioURI(mDirectory);
    FileSystemContext fsContext = FileSystemContext.create(new InstancedConfiguration(ConfigurationUtils.defaults()));
    FileSystem fs = FileSystem.Factory.create(fsContext);
    if (fs.exists(testDir)) {
        fs.delete(testDir, DeletePOptions.newBuilder().setRecursive(true).setUnchecked(true).build());
    }
    int failed = 0;
    List<ReadType> readTypes = mReadType == null ? READ_TYPES : Lists.newArrayList(ReadType.valueOf(mReadType));
    List<WriteType> writeTypes = mWriteType == null ? WRITE_TYPES : Lists.newArrayList(WriteType.valueOf(mWriteType));
    List<OperationType> operations = mOperation == null ? Lists.newArrayList(OperationType.values()) : Lists.newArrayList(OperationType.valueOf(mOperation));
    for (ReadType readType : readTypes) {
        for (WriteType writeType : writeTypes) {
            for (OperationType opType : operations) {
                System.out.println(String.format("runTest --operation %s --readType %s --writeType %s", opType, readType, writeType));
                failed += runTest(opType, readType, writeType, fsContext);
            }
        }
    }
    if (failed > 0) {
        System.out.println("Number of failed tests: " + failed);
    }
    return failed;
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) ReadType(alluxio.client.ReadType) WriteType(alluxio.client.WriteType) FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioURI(alluxio.AlluxioURI)

Example 18 with FileSystemContext

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

the class ImpersonationIntegrationTest method checkCreateFile.

private void checkCreateFile(Subject subject, String expectedUser) throws Exception {
    FileSystemContext context = FileSystemContext.create(subject, ServerConfiguration.global());
    FileSystem fs = mLocalAlluxioClusterResource.get().getClient(context);
    fs.createFile(new AlluxioURI("/impersonation-test")).close();
    List<URIStatus> listing = fs.listStatus(new AlluxioURI("/"));
    Assert.assertEquals(1, listing.size());
    URIStatus status = listing.get(0);
    Assert.assertEquals(expectedUser, status.getOwner());
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 19 with FileSystemContext

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

the class ImpersonationIntegrationTest method impersonationNotUsed.

@Test
@LocalAlluxioClusterResource.Config(confParams = { IMPERSONATION_GROUPS_CONFIG, "*" })
public void impersonationNotUsed() throws Exception {
    ServerConfiguration.set(PropertyKey.SECURITY_LOGIN_IMPERSONATION_USERNAME, Constants.IMPERSONATION_NONE);
    FileSystemContext context = FileSystemContext.create(createHdfsSubject(), ServerConfiguration.global());
    FileSystem fs = mLocalAlluxioClusterResource.get().getClient(context);
    fs.createFile(new AlluxioURI("/impersonation-test")).close();
    List<URIStatus> listing = fs.listStatus(new AlluxioURI("/"));
    Assert.assertEquals(1, listing.size());
    URIStatus status = listing.get(0);
    Assert.assertNotEquals(IMPERSONATION_USER, status.getOwner());
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 20 with FileSystemContext

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

the class PathConfigurationIntegrationTest method before.

@Before
public void before() throws Exception {
    FileSystemContext metaCtx = FileSystemContext.create(ServerConfiguration.global());
    mMetaConfig = new RetryHandlingMetaMasterConfigClient(MasterClientContext.newBuilder(metaCtx.getClientContext()).build());
    setPathConfigurations(mMetaConfig);
    FileSystemContext fsCtx = FileSystemContext.create(ServerConfiguration.global());
    fsCtx.getClientContext().loadConf(fsCtx.getMasterAddress(), true, true);
    mFileSystem = mLocalAlluxioClusterResource.get().getClient(fsCtx);
    mWriteThrough = CreateFilePOptions.newBuilder().setRecursive(true).setWriteType(WritePType.THROUGH).build();
}
Also used : FileSystemContext(alluxio.client.file.FileSystemContext) RetryHandlingMetaMasterConfigClient(alluxio.client.meta.RetryHandlingMetaMasterConfigClient) Before(org.junit.Before)

Aggregations

FileSystemContext (alluxio.client.file.FileSystemContext)28 AlluxioURI (alluxio.AlluxioURI)11 Test (org.junit.Test)9 URIStatus (alluxio.client.file.URIStatus)8 InstancedConfiguration (alluxio.conf.InstancedConfiguration)8 FileSystem (alluxio.client.file.FileSystem)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)7 IOException (java.io.IOException)7 Before (org.junit.Before)7 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)5 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)5 FileSystemMasterClient (alluxio.client.file.FileSystemMasterClient)5 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)5 BlockInfo (alluxio.wire.BlockInfo)5 FileBlockInfo (alluxio.wire.FileBlockInfo)5 ClientContext (alluxio.ClientContext)4 InStreamOptions (alluxio.client.file.options.InStreamOptions)4 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)4 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4