use of java.nio.file.Path in project elasticsearch by elastic.
the class FileBasedUnicastHostsProviderTests method setupAndRunHostProvider.
// sets up the config dir, writes to the unicast hosts file in the config dir,
// and then runs the file-based unicast host provider to get the list of discovery nodes
private List<DiscoveryNode> setupAndRunHostProvider(final List<String> hostEntries) throws IOException {
final Path homeDir = createTempDir();
final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir).build();
final Path configDir = homeDir.resolve("config").resolve("discovery-file");
Files.createDirectories(configDir);
final Path unicastHostsPath = configDir.resolve(UNICAST_HOSTS_FILE);
try (BufferedWriter writer = Files.newBufferedWriter(unicastHostsPath)) {
writer.write(String.join("\n", hostEntries));
}
return new FileBasedUnicastHostsProvider(settings, transportService, executorService).buildDynamicNodes();
}
use of java.nio.file.Path in project elasticsearch by elastic.
the class GeoIpProcessorFactoryTests method testLazyLoading.
public void testLazyLoading() throws Exception {
Path configDir = createTempDir();
Path geoIpConfigDir = configDir.resolve("ingest-geoip");
Files.createDirectories(geoIpConfigDir);
Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-City.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-City.mmdb.gz"));
Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-Country.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-Country.mmdb.gz"));
// Loading another database reader instances, because otherwise we can't test lazy loading as the the
// database readers used at class level are reused between tests. (we want to keep that otherwise running this
// test will take roughly 4 times more time)
Map<String, DatabaseReaderLazyLoader> databaseReaders = IngestGeoIpPlugin.loadDatabaseReaders(geoIpConfigDir, NoCache.getInstance());
GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders);
for (DatabaseReaderLazyLoader lazyLoader : databaseReaders.values()) {
assertNull(lazyLoader.databaseReader.get());
}
Map<String, Object> config = new HashMap<>();
config.put("field", "_field");
config.put("database_file", "GeoLite2-City.mmdb.gz");
factory.create(null, "_tag", config);
config = new HashMap<>();
config.put("field", "_field");
config.put("database_file", "GeoLite2-Country.mmdb.gz");
factory.create(null, "_tag", config);
for (DatabaseReaderLazyLoader lazyLoader : databaseReaders.values()) {
assertNotNull(lazyLoader.databaseReader.get());
}
}
use of java.nio.file.Path in project elasticsearch by elastic.
the class EvilSecurityTests method testEnsureSymlink.
public void testEnsureSymlink() throws IOException {
Path p = createTempDir();
Path exists = p.resolve("exists");
Files.createDirectory(exists);
// symlink
Path linkExists = p.resolve("linkExists");
try {
Files.createSymbolicLink(linkExists, exists);
} catch (UnsupportedOperationException | IOException e) {
assumeNoException("test requires filesystem that supports symbolic links", e);
} catch (SecurityException e) {
assumeNoException("test cannot create symbolic links with security manager enabled", e);
}
Security.ensureDirectoryExists(linkExists);
Files.createTempFile(linkExists, null, null);
}
use of java.nio.file.Path in project che by eclipse.
the class LocalWorkspaceFolderPathProviderTest method throwsExceptionIfFileIsFoundByWorkspacesRootPath.
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Workspace folder '.*' is not directory. Check .* configuration property")
public void throwsExceptionIfFileIsFoundByWorkspacesRootPath() throws Exception {
Path tempFile = Files.createTempFile(getClass().getSimpleName(), null);
LocalWorkspaceFolderPathProvider provider = new LocalWorkspaceFolderPathProvider(tempFile.toString(), null, null, workspaceManagerProvider, true, false);
provider.init();
}
use of java.nio.file.Path in project che by eclipse.
the class InstallExtension method main.
public static void main(String[] args) throws IOException {
for (String arg : args) {
if (arg.startsWith(EXT_DIR_PARAMETER)) {
extDirPath = Paths.get(arg.substring(EXT_DIR_PARAMETER.length()));
} else if (arg.startsWith(EXT_RESOURCES_DIR_PARAMETER)) {
final Path extResourcesDirPath = Paths.get(arg.substring(EXT_RESOURCES_DIR_PARAMETER.length()));
final String tempDirName = "temp";
extResourcesWorkDirPath = extResourcesDirPath.resolve(tempDirName);
// delete working directory from previous build if it exist
IoUtil.deleteRecursive(extResourcesWorkDirPath.toFile());
Files.createDirectory(extResourcesWorkDirPath);
IoUtil.copy(extResourcesDirPath.toFile(), extResourcesWorkDirPath.toFile(), new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !(tempDirName.equals(name));
}
});
} else {
System.err.println("Unknown flag: " + arg);
System.exit(1);
}
}
List<Extension> extensions = findExtensionsByPath(extDirPath);
for (Extension extension : extensions) {
final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile();
final Model model = Model.readFrom(pom);
model.dependencies().add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion));
model.writeTo(pom);
// Add GWT module if there is one
if (extension.gwtModuleName != null) {
final Path ideGwtXmlPath = IoUtil.findFile(IDE_GWT_XML_FILE_NAME, extResourcesWorkDirPath.toFile()).toPath();
GwtXmlUtils.inheritGwtModule(ideGwtXmlPath, extension.gwtModuleName);
}
}
}
Aggregations