Search in sources :

Example 26 with FileSystemContext

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

the class FuseShellTest method before.

@Before
public void before() throws Exception {
    mConf.set(PropertyKey.USER_METADATA_CACHE_ENABLED, true);
    ClientContext clientContext = ClientContext.create(mConf);
    FileSystemContext fileContext = PowerMockito.mock(FileSystemContext.class);
    mFileSystemMasterClient = new GetStatusFileSystemMasterClient();
    when(fileContext.acquireMasterClientResource()).thenReturn(new CloseableResource<FileSystemMasterClient>(mFileSystemMasterClient) {

        @Override
        public void closeResource() {
        // Noop.
        }
    });
    when(fileContext.getClientContext()).thenReturn(clientContext);
    when(fileContext.getClusterConf()).thenReturn(mConf);
    when(fileContext.getPathConf(any())).thenReturn(mConf);
    when(fileContext.getUriValidationEnabled()).thenReturn(true);
    mFileSystem = new MetadataCachingBaseFileSystem(fileContext);
    mFuseShell = new FuseShell(mFileSystem, mConf);
    mFileStatusMap = new HashMap<>();
    mFileStatusMap.put(FILE, FILE_STATUS);
    mFileStatusMap.put(DIR, DIR_STATUS);
    // Here metadata cache will have two contents.
    mFileSystem.getStatus(FILE);
    mFileSystem.getStatus(DIR);
    // Remove from map, so the result will get from cache.
    mFileStatusMap.remove(FILE);
    mFileStatusMap.remove(DIR);
}
Also used : FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) MetadataCachingBaseFileSystem(alluxio.client.file.MetadataCachingBaseFileSystem) ClientContext(alluxio.ClientContext) FuseShell(alluxio.cli.FuseShell) FileSystemContext(alluxio.client.file.FileSystemContext) Before(org.junit.Before)

Example 27 with FileSystemContext

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

the class LogLevelTest method parseWorkerTargets.

@Test
public void parseWorkerTargets() throws Exception {
    CommandLine mockCommandLine = mock(CommandLine.class);
    String[] mockArgs = new String[] { "--target", "workers" };
    when(mockCommandLine.getArgs()).thenReturn(mockArgs);
    when(mockCommandLine.hasOption(LogLevel.TARGET_OPTION_NAME)).thenReturn(true);
    when(mockCommandLine.getOptionValue(LogLevel.TARGET_OPTION_NAME)).thenReturn(mockArgs[1]);
    // Prepare a list of workers
    List<BlockWorkerInfo> workers = new ArrayList<>();
    workers.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("workers-1").setWebPort(WORKER_WEB_PORT), 0, 0));
    workers.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("workers-2").setWebPort(WORKER_WEB_PORT), 0, 0));
    PowerMockito.mockStatic(FileSystemContext.class);
    FileSystemContext mockFsContext = mock(FileSystemContext.class);
    when(mockFsContext.getCachedWorkers()).thenReturn(workers);
    when(FileSystemContext.create(any(ClientContext.class))).thenReturn(mockFsContext);
    List<LogLevel.TargetInfo> targets = LogLevel.parseOptTarget(mockCommandLine, mConf);
    assertEquals(2, targets.size());
    assertEquals(new LogLevel.TargetInfo("workers-1", WORKER_WEB_PORT, "worker"), targets.get(0));
    assertEquals(new LogLevel.TargetInfo("workers-2", WORKER_WEB_PORT, "worker"), targets.get(1));
}
Also used : ClientContext(alluxio.ClientContext) ArrayList(java.util.ArrayList) CommandLine(org.apache.commons.cli.CommandLine) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileSystemContext(alluxio.client.file.FileSystemContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with FileSystemContext

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

the class ClearCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    Option[] options = cl.getOptions();
    // No options or only --parallelism: clear master + workers metrics
    // with --master: clear master metrics
    // with --workers <hostnames>: clear worker metrics
    boolean clearWorkers = options.length == 0 || cl.hasOption(WORKERS_OPTION_NAME) || (options.length == 1 && cl.hasOption(PARALLELISM_OPTION_NAME));
    boolean clearMaster = options.length == 0 || cl.hasOption(MASTER_OPTION_NAME) || (options.length == 1 && cl.hasOption(PARALLELISM_OPTION_NAME));
    // Clear worker metrics
    if (clearWorkers) {
        int globalParallelism = FileSystemShellUtils.getIntArg(cl, PARALLELISM_OPTION, DEFAULT_PARALLELISM);
        try (FileSystemContext context = FileSystemContext.create(mAlluxioConf)) {
            List<WorkerNetAddress> addressList = context.getCachedWorkers().stream().map(BlockWorkerInfo::getNetAddress).collect(Collectors.toList());
            if (cl.hasOption(WORKERS_OPTION_NAME)) {
                String workersValue = cl.getOptionValue(WORKERS_OPTION_NAME);
                Set<String> workersRequired = new HashSet<>(Arrays.asList(workersValue.split(",")));
                List<WorkerNetAddress> workersToClear = new ArrayList<>();
                for (WorkerNetAddress worker : addressList) {
                    if (workersRequired.contains(worker.getHost())) {
                        workersToClear.add(worker);
                        workersRequired.remove(worker.getHost());
                    }
                }
                if (workersRequired.size() != 0) {
                    System.out.printf("Cannot find workers of hostnames %s%n", String.join(",", workersRequired));
                    System.out.printf("Valid workers include %s%n", addressListToString(addressList));
                    return -1;
                }
                if (!clearWorkers(workersToClear, context, globalParallelism)) {
                    System.out.printf("Failed to clear metrics of workers %s%n", addressListToString(workersToClear));
                    return -1;
                }
            } else {
                if (!clearWorkers(addressList, context, globalParallelism)) {
                    System.out.printf("Failed to clear metrics of workers %s%n", addressListToString(addressList));
                    return -1;
                }
            }
        }
    }
    // Clear master metrics
    if (clearMaster) {
        // may be flaky during metrics clearance
        try {
            mMetricsClient.clearMetrics();
            System.out.printf("Successfully cleared metrics of Alluxio leading master.%n");
        } catch (Exception e) {
            System.out.println("Fatal error: " + e);
            return -1;
        }
    }
    return 0;
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArrayList(java.util.ArrayList) FileSystemContext(alluxio.client.file.FileSystemContext) Option(org.apache.commons.cli.Option) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

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