Java Code Examples for org.apache.lucene.util.Constants#WINDOWS
The following examples show how to use
org.apache.lucene.util.Constants#WINDOWS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Environment.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Returns true if the path is writable. * Acts just like {@link Files#isWritable(Path)}, except won't * falsely return false for paths on SUBST'd drive letters * See https://bugs.openjdk.java.net/browse/JDK-8034057 * Note this will set the file modification time (to its already-set value) * to test access. */ @SuppressForbidden(reason = "works around https://bugs.openjdk.java.net/browse/JDK-8034057") public static boolean isWritable(Path path) throws IOException { boolean v = Files.isWritable(path); if (v || Constants.WINDOWS == false) { return v; } // isWritable returned false on windows, the hack begins!!!!!! // resetting the modification time is the least destructive/simplest // way to check for both files and directories, and fails early just // in getting the current value if file doesn't exist, etc try { Files.setLastModifiedTime(path, Files.getLastModifiedTime(path)); return true; } catch (Throwable e) { return false; } }
Example 2
Source File: TransportSQLActionClassLifecycleTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testArithmeticFunctions() throws Exception { execute("select ((2 * 4 - 2 + 1) / 2) % 3 from sys.cluster"); assertThat(response.cols()[0], is("0")); assertThat(response.rows()[0][0], is(0)); execute("select ((2 * 4.0 - 2 + 1) / 2) % 3 from sys.cluster"); assertThat(response.rows()[0][0], is(0.5)); execute("select ? + 2 from sys.cluster", $(1)); assertThat(response.rows()[0][0], is(3)); if (!Constants.WINDOWS) { response = execute("select load['1'] + load['5'], load['1'], load['5'] from sys.nodes limit 1"); assertEquals(response.rows()[0][0], (Double) response.rows()[0][1] + (Double) response.rows()[0][2]); } }
Example 3
Source File: FsDirectoryService.java From Elasticsearch with Apache License 2.0 | 6 votes |
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException { final String storeType = indexSettings.get(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.DEFAULT.getSettingsKey()); if (IndexStoreModule.Type.FS.match(storeType) || IndexStoreModule.Type.DEFAULT.match(storeType)) { final FSDirectory open = FSDirectory.open(location, lockFactory); // use lucene defaults if (open instanceof MMapDirectory && Constants.WINDOWS == false) { return newDefaultDir(location, (MMapDirectory) open, lockFactory); } return open; } else if (IndexStoreModule.Type.SIMPLEFS.match(storeType)) { return new SimpleFSDirectory(location, lockFactory); } else if (IndexStoreModule.Type.NIOFS.match(storeType)) { return new NIOFSDirectory(location, lockFactory); } else if (IndexStoreModule.Type.MMAPFS.match(storeType)) { return new MMapDirectory(location, lockFactory); } throw new IllegalArgumentException("No directory found for type [" + storeType + "]"); }
Example 4
Source File: ImpersonationUtil.java From lucene-solr with Apache License 2.0 | 6 votes |
static String getUsersFirstGroup() throws Exception { String group = "*"; // accept any group if a group can't be found if (!Constants.WINDOWS) { // does not work on Windows! org.apache.hadoop.security.Groups hGroups = new org.apache.hadoop.security.Groups(new Configuration()); try { List<String> g = hGroups.getGroups(System.getProperty("user.name")); if (g != null && g.size() > 0) { group = g.get(0); } } catch (NullPointerException npe) { // if user/group doesn't exist on test box } } return group; }
Example 5
Source File: Seccomp.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Attempt to drop the capability to execute for the process. * <p> * This is best effort and OS and architecture dependent. It may throw any Throwable. * @return 0 if we can do this for application threads, 1 for the entire process */ static int init(Path tmpFile) throws Throwable { if (Constants.LINUX) { return linuxImpl(); } else if (Constants.MAC_OS_X) { // try to enable both mechanisms if possible bsdImpl(); macImpl(tmpFile); return 1; } else if (Constants.SUN_OS) { solarisImpl(); return 1; } else if (Constants.FREE_BSD || OPENBSD) { bsdImpl(); return 1; } else if (Constants.WINDOWS) { windowsImpl(); return 1; } else { throw new UnsupportedOperationException("syscall filtering not supported for OS: '" + Constants.OS_NAME + "'"); } }
Example 6
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
/** Returns true if user is root, false if not, or if we don't know */ static boolean definitelyRunningAsRoot() { if (Constants.WINDOWS) { return false; // don't know } try { return JNACLibrary.geteuid() == 0; } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it return false; } }
Example 7
Source File: IndexModule.java From crate with Apache License 2.0 | 5 votes |
public static Type defaultStoreType(final boolean allowMmap) { if (allowMmap && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { return Type.HYBRIDFS; } else if (Constants.WINDOWS) { return Type.SIMPLEFS; } else { return Type.NIOFS; } }
Example 8
Source File: JNANatives.java From crate with Apache License 2.0 | 5 votes |
static void addConsoleCtrlHandler(ConsoleCtrlHandler handler) { // The console Ctrl handler is necessary on Windows platforms only. if (Constants.WINDOWS) { try { boolean result = JNAKernel32Library.getInstance().addConsoleCtrlHandler(handler); if (result) { LOGGER.debug("console ctrl handler correctly set"); } else { LOGGER.warn("unknown error {} when adding console ctrl handler", Native.getLastError()); } } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it } } }
Example 9
Source File: MMapDirectory.java From lucene-solr with Apache License 2.0 | 5 votes |
private IOException convertMapFailedIOException(IOException ioe, String resourceDescription, int bufSize) { final String originalMessage; final Throwable originalCause; if (ioe.getCause() instanceof OutOfMemoryError) { // nested OOM confuses users, because it's "incorrect", just print a plain message: originalMessage = "Map failed"; originalCause = null; } else { originalMessage = ioe.getMessage(); originalCause = ioe.getCause(); } final String moreInfo; if (!Constants.JRE_IS_64BIT) { moreInfo = "MMapDirectory should only be used on 64bit platforms, because the address space on 32bit operating systems is too small. "; } else if (Constants.WINDOWS) { moreInfo = "Windows is unfortunately very limited on virtual address space. If your index size is several hundred Gigabytes, consider changing to Linux. "; } else if (Constants.LINUX) { moreInfo = "Please review 'ulimit -v', 'ulimit -m' (both should return 'unlimited'), and 'sysctl vm.max_map_count'. "; } else { moreInfo = "Please review 'ulimit -v', 'ulimit -m' (both should return 'unlimited'). "; } final IOException newIoe = new IOException(String.format(Locale.ENGLISH, "%s: %s [this may be caused by lack of enough unfragmented virtual address space "+ "or too restrictive virtual memory limits enforced by the operating system, "+ "preventing us to map a chunk of %d bytes. %sMore information: "+ "http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html]", originalMessage, resourceDescription, bufSize, moreInfo), originalCause); newIoe.setStackTrace(ioe.getStackTrace()); return newIoe; }
Example 10
Source File: IndexFileDeleter.java From lucene-solr with Apache License 2.0 | 5 votes |
private void deleteFile(String fileName) throws IOException { try { directory.deleteFile(fileName); } catch (NoSuchFileException | FileNotFoundException e) { if (Constants.WINDOWS) { // TODO: can we remove this OS-specific hacky logic? If windows deleteFile is buggy, we should instead contain this workaround in // a WindowsFSDirectory ... // LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, where we already // deleted it once, yet it still shows up in directory listings, and if you try to delete it again you'll hit NSFE/FNFE: } else { throw e; } } }
Example 11
Source File: Seccomp.java From Elasticsearch with Apache License 2.0 | 5 votes |
static void windowsImpl() { if (!Constants.WINDOWS) { throw new IllegalStateException("bug: should not be trying to initialize ActiveProcessLimit for an unsupported OS"); } JNAKernel32Library lib = JNAKernel32Library.getInstance(); // create a new Job Pointer job = lib.CreateJobObjectW(null, null); if (job == null) { throw new UnsupportedOperationException("CreateJobObject: " + Native.getLastError()); } try { // retrieve the current basic limits of the job int clazz = JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION_CLASS; JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION limits = new JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION(); limits.write(); if (!lib.QueryInformationJobObject(job, clazz, limits.getPointer(), limits.size(), null)) { throw new UnsupportedOperationException("QueryInformationJobObject: " + Native.getLastError()); } limits.read(); // modify the number of active processes to be 1 (exactly the one process we will add to the job). limits.ActiveProcessLimit = 1; limits.LimitFlags = JNAKernel32Library.JOB_OBJECT_LIMIT_ACTIVE_PROCESS; limits.write(); if (!lib.SetInformationJobObject(job, clazz, limits.getPointer(), limits.size())) { throw new UnsupportedOperationException("SetInformationJobObject: " + Native.getLastError()); } // assign ourselves to the job if (!lib.AssignProcessToJobObject(job, lib.GetCurrentProcess())) { throw new UnsupportedOperationException("AssignProcessToJobObject: " + Native.getLastError()); } } finally { lib.CloseHandle(job); } logger.debug("Windows ActiveProcessLimit initialization successful"); }
Example 12
Source File: JNANatives.java From Elasticsearch with Apache License 2.0 | 5 votes |
static void addConsoleCtrlHandler(ConsoleCtrlHandler handler) { // The console Ctrl handler is necessary on Windows platforms only. if (Constants.WINDOWS) { try { boolean result = JNAKernel32Library.getInstance().addConsoleCtrlHandler(handler); if (result) { logger.debug("console ctrl handler correctly set"); } else { logger.warn("unknown error " + Native.getLastError() + " when adding console ctrl handler:"); } } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it } } }
Example 13
Source File: JNANatives.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** Returns true if user is root, false if not, or if we don't know */ static boolean definitelyRunningAsRoot() { if (Constants.WINDOWS) { return false; // don't know } try { return JNACLibrary.geteuid() == 0; } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it return false; } }
Example 14
Source File: IndexStoreTests.java From crate with Apache License 2.0 | 4 votes |
private void doTestStoreDirectory(Index index, Path tempDir, String typeSettingValue, IndexModule.Type type) throws IOException { Settings.Builder settingsBuilder = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT); if (typeSettingValue != null) { settingsBuilder.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), typeSettingValue); } Settings settings = settingsBuilder.build(); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); FsDirectoryService service = new FsDirectoryService( indexSettings, new ShardPath(false, tempDir, tempDir, new ShardId(index, 0))); try (Directory directory = service.newFSDirectory(tempDir, NoLockFactory.INSTANCE)) { switch (type) { case HYBRIDFS: assertHybridDirectory(directory); break; case NIOFS: assertTrue(type + " " + directory.toString(), directory instanceof NIOFSDirectory); break; case MMAPFS: assertTrue(type + " " + directory.toString(), directory instanceof MMapDirectory); break; case SIMPLEFS: assertTrue(type + " " + directory.toString(), directory instanceof SimpleFSDirectory); break; case FS: if (Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) { assertHybridDirectory(directory); } else if (Constants.WINDOWS) { assertTrue(directory.toString(), directory instanceof SimpleFSDirectory); } else { assertTrue(directory.toString(), directory instanceof NIOFSDirectory); } break; default: fail(); } } }
Example 15
Source File: Bootstrap.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** initialize native resources */ public static void initializeNatives(Path tmpFile, boolean mlockAll, boolean seccomp, boolean ctrlHandler) { final ESLogger logger = Loggers.getLogger(Bootstrap.class); // check if the user is running as root, and bail if (Natives.definitelyRunningAsRoot()) { if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) { logger.warn("running as ROOT user. this is a bad idea!"); } else { throw new RuntimeException("don't run elasticsearch as root."); } } // enable secure computing mode if (seccomp) { Natives.trySeccomp(tmpFile); } // mlockall if requested if (mlockAll) { if (Constants.WINDOWS) { Natives.tryVirtualLock(); } else { Natives.tryMlockall(); } } // listener for windows close event if (ctrlHandler) { Natives.addConsoleCtrlHandler(new ConsoleCtrlHandler() { @Override public boolean handle(int code) { if (CTRL_CLOSE_EVENT == code) { logger.info("running graceful exit on windows"); Bootstrap.stop(); return true; } return false; } }); } // force remainder of JNA to be loaded (if available). try { JNAKernel32Library.getInstance(); } catch (Throwable ignored) { // we've already logged this. } // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); }
Example 16
Source File: TestSimPolicyCloud.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testDataProvider() throws IOException, SolrServerException, KeeperException, InterruptedException { SolrClient solrClient = cluster.simGetSolrClient(); CollectionAdminRequest.createCollectionWithImplicitRouter("policiesTest", "conf", "shard1", 2) .process(solrClient); CloudUtil.waitForState(cluster, "Timeout waiting for collection to become active", "policiesTest", CloudUtil.clusterShape(1, 2, false, true)); DocCollection rulesCollection = getCollectionState("policiesTest"); Map<String, Object> val = cluster.getNodeStateProvider().getNodeValues(rulesCollection.getReplicas().get(0).getNodeName(), Arrays.asList( "freedisk", "cores", "heapUsage", "sysLoadAvg")); assertNotNull(val.get("freedisk")); assertNotNull(val.get("heapUsage")); assertNotNull(val.get("sysLoadAvg")); assertTrue(((Number) val.get("cores")).intValue() > 0); assertTrue("freedisk value is " + ((Number) val.get("freedisk")).doubleValue(), Double.compare(((Number) val.get("freedisk")).doubleValue(), 0.0d) > 0); assertTrue("heapUsage value is " + ((Number) val.get("heapUsage")).doubleValue(), Double.compare(((Number) val.get("heapUsage")).doubleValue(), 0.0d) > 0); if (!Constants.WINDOWS) { // the system load average metrics is not available on windows platform assertTrue("sysLoadAvg value is " + ((Number) val.get("sysLoadAvg")).doubleValue(), Double.compare(((Number) val.get("sysLoadAvg")).doubleValue(), 0.0d) > 0); } // simulator doesn't have Overseer, so just pick a random node String overseerNode = cluster.getSimClusterStateProvider().simGetRandomNode(); solrClient.request(CollectionAdminRequest.addRole(overseerNode, "overseer")); for (int i = 0; i < 10; i++) { Map<String, Object> data = Utils.getJson(cluster.getDistribStateManager(), ZkStateReader.ROLES); if (i >= 9 && data.isEmpty()) { throw new RuntimeException("NO overseer node created"); } cluster.getTimeSource().sleep(100); } val = cluster.getNodeStateProvider().getNodeValues(overseerNode, Arrays.asList( "nodeRole", "ip_1", "ip_2", "ip_3", "ip_4", "sysprop.java.version", "sysprop.java.vendor")); assertEquals("overseer", val.get("nodeRole")); assertNotNull(val.get("ip_1")); assertNotNull(val.get("ip_2")); assertNotNull(val.get("ip_3")); assertNotNull(val.get("ip_4")); assertNotNull(val.get("sysprop.java.version")); assertNotNull(val.get("sysprop.java.vendor")); }
Example 17
Source File: TestPolicyCloud.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testDataProvider() throws Exception { final String collectionName = "data_provider"; CollectionAdminRequest.createCollectionWithImplicitRouter(collectionName, "conf", "shard1", 2) .process(cluster.getSolrClient()); cluster.waitForActiveCollection(collectionName, 1, 2); DocCollection rulesCollection = getCollectionState(collectionName); try (SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()), cluster.getSolrClient())) { Map<String, Object> val = cloudManager.getNodeStateProvider().getNodeValues(rulesCollection.getReplicas().get(0).getNodeName(), Arrays.asList( "freedisk", "cores", "host", "heapUsage", "sysLoadAvg")); assertNotNull(val.get("freedisk")); assertNotNull(val.get("host")); assertNotNull(val.get("heapUsage")); assertNotNull(val.get("sysLoadAvg")); assertTrue(((Number) val.get("cores")).intValue() > 0); assertTrue("freedisk value is " + ((Number) val.get("freedisk")).doubleValue(), Double.compare(((Number) val.get("freedisk")).doubleValue(), 0.0d) > 0); assertTrue("heapUsage value is " + ((Number) val.get("heapUsage")).doubleValue(), Double.compare(((Number) val.get("heapUsage")).doubleValue(), 0.0d) > 0); if (!Constants.WINDOWS) { // the system load average metrics is not available on windows platform assertTrue("sysLoadAvg value is " + ((Number) val.get("sysLoadAvg")).doubleValue(), Double.compare(((Number) val.get("sysLoadAvg")).doubleValue(), 0.0d) > 0); } String overseerNode = OverseerTaskProcessor.getLeaderNode(cluster.getZkClient()); cluster.getSolrClient().request(CollectionAdminRequest.addRole(overseerNode, "overseer")); for (int i = 0; i < 10; i++) { Map<String, Object> data = Utils.getJson(cluster.getZkClient(), ZkStateReader.ROLES, true); if (i >= 9 && data.isEmpty()) { throw new RuntimeException("NO overseer node created"); } Thread.sleep(100); } val = cloudManager.getNodeStateProvider().getNodeValues(overseerNode, Arrays.asList( "nodeRole", "ip_1", "ip_2", "ip_3", "ip_4", "sysprop.java.version", "sysprop.java.vendor")); assertEquals("overseer", val.get("nodeRole")); assertNotNull(val.get("ip_1")); assertNotNull(val.get("ip_2")); assertNotNull(val.get("ip_3")); assertNotNull(val.get("ip_4")); assertNotNull(val.get("sysprop.java.version")); assertNotNull(val.get("sysprop.java.vendor")); } }
Example 18
Source File: NetworkUtils.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** Returns system default for SO_REUSEADDR */ public static boolean defaultReuseAddress() { return Constants.WINDOWS ? false : true; }
Example 19
Source File: NetworkUtils.java From crate with Apache License 2.0 | 4 votes |
/** Returns system default for SO_REUSEADDR */ public static boolean defaultReuseAddress() { return Constants.WINDOWS ? false : true; }
Example 20
Source File: BootstrapProxy.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** initialize native resources */ public static void initializeNatives(Path tmpFile, boolean mlockAll, boolean seccomp, boolean ctrlHandler) { final ESLogger logger = Loggers.getLogger(Bootstrap.class); // check if the user is running as root, and bail if (Natives.definitelyRunningAsRoot()) { if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) { logger.warn("running as ROOT user. this is a bad idea!"); } else { throw new RuntimeException("don't run elasticsearch as root."); } } // enable secure computing mode if (seccomp) { Natives.trySeccomp(tmpFile); } // mlockall if requested if (mlockAll) { if (Constants.WINDOWS) { Natives.tryVirtualLock(); } else { Natives.tryMlockall(); } } // listener for windows close event if (ctrlHandler) { Natives.addConsoleCtrlHandler(new ConsoleCtrlHandler() { @Override public boolean handle(int code) { if (CTRL_CLOSE_EVENT == code) { logger.info("running graceful exit on windows"); Bootstrap.stop(); return true; } return false; } }); } // force remainder of JNA to be loaded (if available). try { JNAKernel32Library.getInstance(); } catch (Throwable ignored) { // we've already logged this. } // init lucene random seed. it will use /dev/urandom where available: StringHelper.randomId(); }