public static void checkPath(String keystoreFilePath, String fileNameLogOnly) { if (keystoreFilePath == null || keystoreFilePath.length() == 0) { throw new ElasticsearchException("Empty file path for "+fileNameLogOnly); } if (Files.isDirectory(Paths.get(keystoreFilePath), LinkOption.NOFOLLOW_LINKS)) { throw new ElasticsearchException("Is a directory: " + keystoreFilePath+" Expected a file for "+fileNameLogOnly); } if(!Files.isReadable(Paths.get(keystoreFilePath))) { throw new ElasticsearchException("Unable to read " + keystoreFilePath + " ("+Paths.get(keystoreFilePath)+"). Please make sure this files exists and is readable regarding to permissions. Property: "+fileNameLogOnly); } }
private Resolved(final Set<String> aliases, final Set<String> indices, final Set<String> allIndices, final Set<String> types) { super(); this.aliases = aliases; this.indices = indices; this.allIndices = allIndices; this.types = types; if(!aliases.isEmpty() || !indices.isEmpty() || !allIndices.isEmpty()) { if(types.isEmpty()) { throw new ElasticsearchException("Empty types for nonempty inidices or aliases"); } } }
public static String serializeObject(final Serializable object) { if (object == null) { throw new IllegalArgumentException("object must not be null"); } try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(object); final byte[] bytes = bos.toByteArray(); return BaseEncoding.base64().encode(bytes); } catch (final Exception e) { throw new ElasticsearchException(e.toString()); } }
private DB getAdminDb() { DB adminDb = clusterClient.getDB(MongoDBRiver.MONGODB_ADMIN_DATABASE); if (adminDb == null) { throw new ElasticsearchException( String.format("Could not get %s database from MongoDB", MongoDBRiver.MONGODB_ADMIN_DATABASE)); } return adminDb; }
private DB getConfigDb() { DB configDb = clusterClient.getDB(MongoDBRiver.MONGODB_CONFIG_DATABASE); if (configDb == null) { throw new ElasticsearchException( String.format("Could not get %s database from MongoDB", MongoDBRiver.MONGODB_CONFIG_DATABASE)); } return configDb; }
@SuppressWarnings("unchecked") public static <T> T instantiateAAA(final String clazz, final Settings settings, final Path configPath, final boolean checkEnterprise) { if (checkEnterprise && enterpriseModulesDisabled()) { throw new ElasticsearchException("Can not load '{}' because enterprise modules are disabled", clazz); } try { final Class<?> clazz0 = Class.forName(clazz); final T ret = (T) clazz0.getConstructor(Settings.class, Path.class).newInstance(settings, configPath); addLoadedModule(clazz0); return ret; } catch (final Throwable e) { log.warn("Unable to enable '{}' due to {}", clazz, e.toString()); if(log.isDebugEnabled()) { log.debug("Stacktrace: ",e); } throw new ElasticsearchException(e); } }
public static Serializable deserializeObject(final String string) { if (string == null) { throw new IllegalArgumentException("string must not be null"); } SafeObjectInputStream in = null; try { final byte[] userr = BaseEncoding.base64().decode(string); final ByteArrayInputStream bis = new ByteArrayInputStream(userr); //NOSONAR in = new SafeObjectInputStream(bis); //NOSONAR return (Serializable) in.readObject(); } catch (final Exception e) { throw new ElasticsearchException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } }
log.debug("Exception parsing certificate using {}", e, this.getClass()); throw new ElasticsearchException(e);
throw new ElasticsearchException(ConfigConstants.SEARCHGUARD_COMPLIANCE_SALT+" must at least contain 16 bytes");
@Test public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() { EsClient esClientMock = mock(EsClient.class); EsIndexesSection underTest = new EsIndexesSection(esClientMock); when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message"))); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThatAttributeIs(section, "Error", "some cause message"); } }
@Test public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() { EsClient esClientMock = mock(EsClient.class); EsStateSection underTest = new EsStateSection(esClientMock); when(esClientMock.prepareClusterStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message"))); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThatAttributeIs(section, "State", "some cause message"); } }
throw new ElasticsearchException(e);
@Override public void run() { try { Files.deleteIfExists(path); } catch (IOException e) { throw new ElasticsearchException("Failed to delete pid file " + path, e); } } });
} else { log.error("Request has no proper remote address {}", originalRemoteAddress); transportChannel.sendResponse(new ElasticsearchException("Request has no proper remote address")); return;
private Class<? extends Plugin> loadPluginClass(String className, ClassLoader loader) { try { return loader.loadClass(className).asSubclass(Plugin.class); } catch (ClassNotFoundException e) { throw new ElasticsearchException("Could not find plugin class [" + className + "]", e); } }
public ShapeBuilder getShapeAt(int i) { if (i >= this.shapes.size() || i < 0) { throw new ElasticsearchException("GeometryCollection contains " + this.shapes.size() + " shapes. + " + "No shape found at index " + i); } return this.shapes.get(i); }
/** Return the score of the current document. */ public double getScore() { // TODO: remove leniency when painless does not implement SearchScript for executable script cases if (scorer == null) { return 0.0d; } try { return scorer.score(); } catch (IOException e) { throw new ElasticsearchException("couldn't lookup score", e); } }
/** sets the last observed state to the currently applied cluster state and returns it */ public ClusterState setAndGetObservedState() { if (observingContext.get() != null) { throw new ElasticsearchException("cannot set current cluster state while waiting for a cluster state change"); } ClusterState clusterState = clusterApplierService.state(); lastObservedState.set(new StoredState(clusterState)); return clusterState; }
protected int numDimensions() { if (isEmpty()) { throw new ElasticsearchException("attempting to get number of dimensions on an empty coordinate node"); } if (coordinate != null) { return Double.isNaN(coordinate.z) ? 2 : 3; } return children.get(0).numDimensions(); }
/** Add an incoming, not yet committed cluster state */ public synchronized void addPending(ClusterState state) { pendingStates.add(new ClusterStateContext(state)); if (pendingStates.size() > maxQueueSize) { ClusterStateContext context = pendingStates.remove(0); logger.warn("dropping pending state [{}]. more than [{}] pending states.", context, maxQueueSize); if (context.committed()) { context.listener.onNewClusterStateFailed(new ElasticsearchException("too many pending states ([{}] pending)", maxQueueSize)); } } }