Search in sources :

Example 11 with UfsManager

use of alluxio.underfs.UfsManager in project alluxio by Alluxio.

the class UfsFallbackBlockWriteHandlerTest method before.

@Before
public void before() throws Exception {
    mFile = mTestFolder.newFile();
    mOutputStream = new FileOutputStream(mFile);
    mBlockStore = new TieredBlockStore();
    mBlockWorker = new MockBlockWorker();
    UnderFileSystem mockUfs = Mockito.mock(UnderFileSystem.class);
    UfsManager ufsManager = Mockito.mock(UfsManager.class);
    UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> mockUfs, AlluxioURI.EMPTY_URI);
    Mockito.when(ufsManager.get(Mockito.anyLong())).thenReturn(ufsClient);
    Mockito.when(mockUfs.createNonexistingFile(Mockito.anyString(), Mockito.any(CreateOptions.class))).thenReturn(mOutputStream).thenReturn(new FileOutputStream(mFile, true));
    mResponseObserver = Mockito.mock(StreamObserver.class);
    mWriteHandler = new UfsFallbackBlockWriteHandler(mBlockWorker, ufsManager, mResponseObserver, mUserInfo, false);
    setupResponseTrigger();
    // create a partial block in block store first
    mBlockStore.createBlock(TEST_SESSION_ID, TEST_BLOCK_ID, AllocateOptions.forCreate(CHUNK_SIZE, BlockStoreLocation.anyDirInTier(Constants.MEDIUM_MEM)));
    BlockWriter writer = mBlockStore.getBlockWriter(TEST_SESSION_ID, TEST_BLOCK_ID);
    DataBuffer buffer = newDataBuffer(PARTIAL_WRITTEN);
    mPartialChecksum = getChecksum(buffer);
    writer.append((ByteBuf) buffer.getNettyOutput());
    writer.close();
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) UfsManager(alluxio.underfs.UfsManager) FileOutputStream(java.io.FileOutputStream) BlockWriter(alluxio.worker.block.io.BlockWriter) UnderFileSystem(alluxio.underfs.UnderFileSystem) TieredBlockStore(alluxio.worker.block.TieredBlockStore) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer) Before(org.junit.Before)

Example 12 with UfsManager

use of alluxio.underfs.UfsManager in project alluxio by Alluxio.

the class CacheRequestManagerTest method before.

/**
 * Sets up all dependencies before a test runs.
 */
@Before
public void before() throws IOException {
    BlockMasterClient blockMasterClient = mock(BlockMasterClient.class);
    BlockMasterClientPool blockMasterClientPool = spy(new BlockMasterClientPool());
    when(blockMasterClientPool.createNewResource()).thenReturn(blockMasterClient);
    TieredBlockStore blockStore = new TieredBlockStore();
    FileSystemMasterClient fileSystemMasterClient = mock(FileSystemMasterClient.class);
    Sessions sessions = mock(Sessions.class);
    // Connect to the real UFS for testing
    UfsManager ufsManager = mock(UfsManager.class);
    mRootUfs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
    UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> UnderFileSystem.Factory.create(mRootUfs, UnderFileSystemConfiguration.defaults(ServerConfiguration.global())), new AlluxioURI(mRootUfs));
    when(ufsManager.get(anyLong())).thenReturn(ufsClient);
    mBlockWorker = spy(new DefaultBlockWorker(blockMasterClientPool, fileSystemMasterClient, sessions, blockStore, ufsManager));
    FileSystemContext context = mock(FileSystemContext.class);
    mCacheRequestManager = spy(new CacheRequestManager(GrpcExecutors.CACHE_MANAGER_EXECUTOR, mBlockWorker, context));
    // Write an actual file to UFS
    String testFilePath = File.createTempFile("temp", null, new File(mRootUfs)).getAbsolutePath();
    byte[] buffer = BufferUtils.getIncreasingByteArray(CHUNK_SIZE);
    BufferUtils.writeBufferToFile(testFilePath, buffer);
    // create options
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE);
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setUfsPath(testFilePath).setBlockIds(Collections.singletonList(BLOCK_ID)).setLength(CHUNK_SIZE).setBlockSizeBytes(CHUNK_SIZE).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    OpenFilePOptions readOptions = FileSystemOptions.openFileDefaults(mConf);
    InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, mConf);
    mOpenUfsBlockOptions = options.getOpenUfsBlockOptions(BLOCK_ID);
}
Also used : UfsManager(alluxio.underfs.UfsManager) Sessions(alluxio.Sessions) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) InStreamOptions(alluxio.client.file.options.InStreamOptions) FileSystemMasterClient(alluxio.worker.file.FileSystemMasterClient) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) FileSystemContext(alluxio.client.file.FileSystemContext) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 13 with UfsManager

use of alluxio.underfs.UfsManager in project alluxio by Alluxio.

the class UfsConfigurationJournalTest method testOptionsPersisted.

@Test
public void testOptionsPersisted() throws Exception {
    // Set ufs specific options and other mount flags
    AlluxioURI mountPoint = new AlluxioURI("/mnt");
    ImmutableMap<String, String> options = ImmutableMap.of("k1", "v1", "k2", "v2");
    mFs.mount(mountPoint, new AlluxioURI(LOCAL_UFS_PATH), MountPOptions.newBuilder().putAllProperties(options).setReadOnly(true).setShared(true).build());
    // Get mount id
    MountTable mountTable = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mMountTable");
    long mountId = mountTable.resolve(mountPoint).getMountId();
    // Restart masters
    mLocalAlluxioClusterResource.get().restartMasters();
    // Checks all options and flags are persisted after restart
    UfsManager ufsManager = Whitebox.getInternalState(mLocalAlluxioClusterResource.get().getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class), "mUfsManager");
    try (CloseableResource<UnderFileSystem> resource = ufsManager.get(mountId).acquireUfsResource()) {
        UnderFileSystemConfiguration ufsConf = Whitebox.getInternalState(resource.get(), "mConf");
        assertEquals(ufsConf.getMountSpecificConf().size(), options.size());
        for (Map.Entry<String, String> entry : options.entrySet()) {
            assertEquals(entry.getValue(), ufsConf.getMountSpecificConf().get(entry.getKey()));
        }
        assertTrue(ufsConf.isReadOnly());
        assertTrue(ufsConf.isShared());
    }
}
Also used : UfsManager(alluxio.underfs.UfsManager) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) FileSystemMaster(alluxio.master.file.FileSystemMaster) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

UfsManager (alluxio.underfs.UfsManager)13 Before (org.junit.Before)9 MountInfo (alluxio.master.file.meta.options.MountInfo)6 AlluxioURI (alluxio.AlluxioURI)5 MountTable (alluxio.master.file.meta.MountTable)5 MasterRegistry (alluxio.master.MasterRegistry)4 BlockMasterFactory (alluxio.master.block.BlockMasterFactory)4 InodeDirectoryIdGenerator (alluxio.master.file.meta.InodeDirectoryIdGenerator)4 InodeLockManager (alluxio.master.file.meta.InodeLockManager)4 InodeTree (alluxio.master.file.meta.InodeTree)4 MetricsMasterFactory (alluxio.master.metrics.MetricsMasterFactory)4 UnderFileSystem (alluxio.underfs.UnderFileSystem)4 Sessions (alluxio.Sessions)3 CoreMasterContext (alluxio.master.CoreMasterContext)3 BlockMaster (alluxio.master.block.BlockMaster)3 FileInfo (alluxio.wire.FileInfo)3 TieredBlockStore (alluxio.worker.block.TieredBlockStore)3 FileSystemMasterClient (alluxio.worker.file.FileSystemMasterClient)3 FileSystemContext (alluxio.client.file.FileSystemContext)2 URIStatus (alluxio.client.file.URIStatus)2