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);
}
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));
}
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;
}
Aggregations