use of java.nio.file.Path in project crate by crate.
the class TransportSQLActionClassLifecycleTest method testCopyToDirectoryOnPartitionedTableWithoutPartitionClause.
@Test
// COPY has no rowcount
@UseJdbc(0)
public void testCopyToDirectoryOnPartitionedTableWithoutPartitionClause() throws Exception {
String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
SQLResponse response = execute("copy parted to DIRECTORY ?", $(uriTemplate));
assertThat(response.rowCount(), is(4L));
List<String> lines = new ArrayList<>(4);
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json");
for (Path entry : stream) {
lines.addAll(Files.readAllLines(entry, StandardCharsets.UTF_8));
}
assertThat(lines.size(), is(4));
for (String line : lines) {
// date column included in output
if (!line.contains("1388534400000")) {
assertTrue(line.contains("1391212800000"));
}
assertThat(line, startsWith("{"));
assertThat(line, endsWith("}"));
}
}
use of java.nio.file.Path in project crate by crate.
the class BlobContainer method createSubDirectories.
/**
* All files are saved into a sub-folder
* that is named after the first two characters of the file's sha1 hash
* pre create these folders so that a .exists() check can be saved on each put request.
*
* @param parentDir
*/
private void createSubDirectories(Path parentDir) throws IOException {
for (int i = 0; i < SUB_DIRS.length; i++) {
Path subDir = parentDir.resolve(SUB_DIRS[i]);
subDirs[i] = subDir.toFile();
Files.createDirectories(subDir);
}
}
use of java.nio.file.Path in project crate by crate.
the class PluginLoader method findImplementations.
private Collection<Class<? extends Plugin>> findImplementations() {
if (!isAccessibleDirectory(pluginsPath, logger)) {
return Collections.emptyList();
}
File[] plugins = pluginsPath.toFile().listFiles();
if (plugins == null) {
return Collections.emptyList();
}
Collection<Class<? extends Plugin>> allImplementations = new ArrayList<>();
for (File plugin : plugins) {
if (!plugin.canRead()) {
logger.debug("[{}] is not readable.", plugin.getAbsolutePath());
continue;
}
// check if its an elasticsearch plugin
Path esDescriptorFile = plugin.toPath().resolve(PluginInfo.ES_PLUGIN_PROPERTIES);
try {
if (esDescriptorFile.toFile().exists()) {
continue;
}
} catch (Exception e) {
// ignore
}
List<URL> pluginUrls = new ArrayList<>();
logger.trace("--- adding plugin [{}]", plugin.getAbsolutePath());
try {
URL pluginURL = plugin.toURI().toURL();
// jar-hell check the plugin against the parent classloader
try {
checkJarHell(pluginURL);
} catch (Exception e) {
String msg = String.format(Locale.ENGLISH, "failed to load plugin %s due to jar hell", pluginURL);
logger.error(msg, e);
throw new RuntimeException(msg, e);
}
pluginUrls.add(pluginURL);
if (!plugin.isFile()) {
// gather files to add
List<File> libFiles = Lists.newArrayList();
File[] pluginFiles = plugin.listFiles();
if (pluginFiles != null) {
libFiles.addAll(Arrays.asList(pluginFiles));
}
File libLocation = new File(plugin, "lib");
if (libLocation.exists() && libLocation.isDirectory()) {
File[] pluginLibFiles = libLocation.listFiles();
if (pluginLibFiles != null) {
libFiles.addAll(Arrays.asList(pluginLibFiles));
}
}
// if there are jars in it, add it as well
for (File libFile : libFiles) {
if (!(libFile.getName().endsWith(".jar") || libFile.getName().endsWith(".zip"))) {
continue;
}
URL libURL = libFile.toURI().toURL();
// jar-hell check the plugin lib against the parent classloader
try {
checkJarHell(libURL);
pluginUrls.add(libURL);
} catch (Exception e) {
String msg = String.format(Locale.ENGLISH, "Library %s of plugin %s already loaded", libURL, pluginURL);
logger.error(msg, e);
throw new RuntimeException(msg, e);
}
}
}
} catch (MalformedURLException e) {
String msg = String.format(Locale.ENGLISH, "failed to add plugin [%s]", plugin);
logger.error(msg, e);
throw new RuntimeException(msg, e);
}
Collection<Class<? extends Plugin>> implementations = findImplementations(pluginUrls);
if (implementations == null || implementations.isEmpty()) {
String msg = String.format(Locale.ENGLISH, "Path [%s] does not contain a valid Crate or Elasticsearch plugin", plugin.getAbsolutePath());
RuntimeException e = new RuntimeException(msg);
logger.error(msg, e);
throw e;
}
jarsToLoad.addAll(pluginUrls);
allImplementations.addAll(implementations);
}
return allImplementations;
}
use of java.nio.file.Path in project crate by crate.
the class CrateSettingsPreparer method prepareEnvironment.
/**
* ES_COPY_OF: core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java
* This is a copy of {@link InternalSettingsPreparer#prepareEnvironment(Settings, Terminal)}
* <p>
* with the addition of the "applyCrateDefaults" call.
*/
public static Environment prepareEnvironment(Settings input, Terminal terminal) {
// just create enough settings to build the environment, to get the config dir
Settings.Builder output = settingsBuilder();
InternalSettingsPreparer.initializeSettings(output, input, true);
Environment environment = new Environment(output.build());
Path path = environment.configFile().resolve("crate.yml");
if (Files.exists(path)) {
output.loadFromPath(path);
}
// re-initialize settings now that the config file has been loaded
// TODO: only re-initialize if a config file was actually loaded
InternalSettingsPreparer.initializeSettings(output, input, false);
InternalSettingsPreparer.finalizeSettings(output, terminal, environment.configFile());
validateKnownSettings(output);
applyCrateDefaults(output);
environment = new Environment(output.build());
// we put back the path.logs so we can use it in the logging configuration file
output.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString()));
return new Environment(output.build());
}
use of java.nio.file.Path in project crate by crate.
the class BlobPathITest method testDataIsStoredInGlobalBlobPath.
@Test
public void testDataIsStoredInGlobalBlobPath() throws Exception {
launchNodeAndInitClient(configureGlobalBlobPath());
Settings indexSettings = oneShardAndZeroReplicas();
blobAdminClient.createBlobTable("test", indexSettings).get();
client.put("test", "abcdefg");
String digest = "2fb5e13419fc89246865e7a324f476ec624e8740";
try (Stream<Path> files = Files.walk(globalBlobPath)) {
assertThat(files.anyMatch(i -> digest.equals(i.getFileName().toString())), is(true));
}
}
Aggregations