use of java.nio.file.Files in project alluxio by Alluxio.
the class ProcessLauncherTest method testCreateProcwithMock.
void testCreateProcwithMock(Process mockedProcess) throws Exception {
InstancedConfiguration conf = getTestConfig();
conf.set(PropertyKey.HOME, "/path/to/non/existent/directory");
try (MockedStatic<Files> files = Mockito.mockStatic(Files.class)) {
files.when(() -> Files.exists(ArgumentMatchers.any())).thenReturn(true);
ProcessLauncher l = new ProcessLauncher(getTestConfig());
try (MockedStatic<Runtime> runtimeMock = Mockito.mockStatic(Runtime.class)) {
Runtime mockedRuntime = mock(Runtime.class);
runtimeMock.when(Runtime::getRuntime).thenReturn(mockedRuntime);
for (AlluxioNodeType t : AlluxioNodeType.values()) {
doReturn(mockedProcess).when(mockedRuntime).exec(ArgumentMatchers.any(String.class));
l.start(t);
verify(mockedRuntime).exec(ArgumentMatchers.contains("alluxio-start.sh " + t.toString().toLowerCase()));
}
}
}
}
use of java.nio.file.Files in project alluxio by Alluxio.
the class AgentManagerService method listCatalogs.
@Override
public void listCatalogs(alluxio.hub.proto.AgentListCatalogRequest request, io.grpc.stub.StreamObserver<alluxio.hub.proto.AgentListCatalogResponse> responseObserver) {
RpcUtils.call(LOG, () -> {
AgentListCatalogResponse.Builder res = AgentListCatalogResponse.newBuilder();
Path searchPath = Paths.get(request.getConfDir(), "catalog");
if (!Files.isDirectory(searchPath)) {
return res.build();
}
Files.list(searchPath).filter(Files::isReadable).filter(Files::isRegularFile).filter(p -> Optional.ofNullable(p.getFileName()).map(Objects::toString).orElse("").endsWith(".properties")).map(p -> {
String filename = Optional.ofNullable(p.getFileName()).map(Objects::toString).orElse("");
String name = Optional.ofNullable(p.getFileName()).map(Objects::toString).orElse("").substring(0, filename.indexOf(".properties"));
try {
Properties catalogProps = new Properties();
try (Reader reader = Files.newBufferedReader(p)) {
catalogProps.load(reader);
}
String metastoreUri = catalogProps.getProperty("hive.metastore.uri");
if (metastoreUri == null) {
// not a hive metastore.
return null;
}
return PrestoCatalogListing.newBuilder().setCatalogName(name).setHiveMetastoreUri(metastoreUri).build();
} catch (IOException e) {
LOG.warn("Failed to presto catalog file read file {}", p);
return null;
}
}).filter(Objects::nonNull).forEach(res::addCatalog);
return res.build();
}, "listCatalogs", "current catalogs in the presto configuration directory", responseObserver);
}
use of java.nio.file.Files in project RecurrentComplex by Ivorforce.
the class CommandSanity method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
boolean sane = true;
if (RecurrentComplex.isLite()) {
commandSender.sendMessage(new TextComponentString("Recurrent Complex is in lightweight mode!"));
}
if (StructureRegistry.INSTANCE.ids().isEmpty()) {
commandSender.sendMessage(new TextComponentString("No registered structures!"));
sane = false;
}
if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
sane = false;
}
for (ModContainer mod : Loader.instance().getModList()) {
String domain = mod.getModId();
Path path = null;
try {
path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
if (path != null && !Files.isReadable(path)) {
commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
sane = false;
}
} catch (RCFiles.ResourceLocationLoadException e) {
RecurrentComplex.logger.error(e);
commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
sane = false;
} finally {
if (path != null)
RCFiles.closeQuietly(path.getFileSystem());
}
}
if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
sane = false;
}
if (!parameters.has("short")) {
sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
sane &= addGenericStructureLog(commandSender, (s, structure) -> !structure.metadata.authors.isEmpty(), "No author");
sane &= addGenericStructureLog(commandSender, (s, structure) -> structure.transformer.getTransformers().stream().allMatch(t -> t.id().length() > 0), "Transformer has empty ID");
sane &= addGenerationLog(commandSender, GenerationType.class, (structure, gen) -> gen.id().length() > 0, "Generation type has empty ID");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
}
if (sane && !parameters.has("silent"))
commandSender.sendMessage(new TextComponentString("No problems identified!"));
}
use of java.nio.file.Files in project ignite by apache.
the class CdcMain method consumeWalSegmentsUntilStopped.
/**
* Waits and consumes new WAL segments until stopped.
*/
public void consumeWalSegmentsUntilStopped() {
try {
Set<Path> seen = new HashSet<>();
AtomicLong lastSgmnt = new AtomicLong(-1);
while (!stopped) {
try (Stream<Path> cdcFiles = Files.walk(cdcDir, 1)) {
Set<Path> exists = new HashSet<>();
cdcFiles.peek(// Store files that exists in cdc dir.
exists::add).filter(p -> WAL_SEGMENT_FILE_FILTER.accept(p.toFile()) && !seen.contains(p)).peek(// Adds to seen.
seen::add).sorted(// Sort by segment index.
Comparator.comparingLong(this::segmentIndex)).peek(p -> {
long nextSgmnt = segmentIndex(p);
assert lastSgmnt.get() == -1 || nextSgmnt - lastSgmnt.get() == 1;
lastSgmnt.set(nextSgmnt);
}).forEach(// Consuming segments.
this::consumeSegment);
// Clean up seen set.
seen.removeIf(p -> !exists.contains(p));
}
if (!stopped)
U.sleep(cdcCfg.getCheckFrequency());
}
} catch (IOException | IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
use of java.nio.file.Files in project ignite by apache.
the class GridCommandHandlerTest method testDiagnosticPageLocksTracker.
/**
* Test execution of --diagnostic command.
*
* @throws Exception if failed.
*/
@Test
public void testDiagnosticPageLocksTracker() throws Exception {
Ignite ignite = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node0/dump"));
startGrid(1, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node1/dump"));
startGrid(2, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node2/dump"));
startGrid(3, (UnaryOperator<IgniteConfiguration>) cfg -> cfg.setConsistentId("node3/dump"));
Collection<ClusterNode> nodes = ignite.cluster().nodes();
List<ClusterNode> nodes0 = new ArrayList<>(nodes);
ClusterNode node0 = nodes0.get(0);
ClusterNode node1 = nodes0.get(1);
ClusterNode node2 = nodes0.get(2);
ClusterNode node3 = nodes0.get(3);
ignite.cluster().active(true);
assertEquals(EXIT_CODE_OK, execute("--diagnostic"));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "help"));
// Dump locks only on connected node to default path.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump"));
// Check file dump in default path.
checkNumberFiles(defaultDiagnosticDir, 1);
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log"));
// Dump locks only on connected node to specific path.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath()));
// Check file dump in specific path.
checkNumberFiles(customDiagnosticDir, 1);
// Dump locks only all nodes.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--all"));
// Current cluster 4 nodes -> 4 files + 1 from previous operation.
checkNumberFiles(defaultDiagnosticDir, 5);
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log", "--all"));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath(), "--all"));
// Current cluster 4 nodes -> 4 files + 1 from previous operation.
checkNumberFiles(customDiagnosticDir, 5);
// Dump locks only 2 nodes use nodeIds as arg.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--nodes", node0.id().toString() + "," + node2.id().toString()));
// Dump locks only for 2 nodes -> 2 files + 5 from previous operation.
checkNumberFiles(defaultDiagnosticDir, 7);
// Dump locks only for 2 nodes use constIds as arg.
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--nodes", node0.consistentId().toString() + "," + node2.consistentId().toString()));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump_log", "--nodes", node1.id().toString() + "," + node3.id().toString()));
assertEquals(EXIT_CODE_OK, execute("--diagnostic", "pageLocks", "dump", "--path", customDiagnosticDir.getAbsolutePath(), "--nodes", node1.consistentId().toString() + "," + node3.consistentId().toString()));
// Dump locks only for 2 nodes -> 2 files + 5 from previous operation.
checkNumberFiles(customDiagnosticDir, 7);
}
Aggregations