Merge branch 'master' into trash_context_and_headers

if (name == 'expamle-fixtures') return
This commit is contained in:
Simon Willnauer 2016-01-27 16:33:50 +01:00
commit 7ff99eb89d
78 changed files with 1332 additions and 694 deletions

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.MapperService;
@ -40,30 +41,30 @@ public final class AutoCreateIndex {
private final String[] matches;
private final String[] matches2;
private final IndexNameExpressionResolver resolver;
public static final Setting<AutoCreate> AUTO_CREATE_INDEX_SETTING = new Setting<>("action.auto_create_index", "true", AutoCreate::new, false, Setting.Scope.CLUSTER);
@Inject
public AutoCreateIndex(Settings settings, IndexNameExpressionResolver resolver) {
this.resolver = resolver;
dynamicMappingDisabled = !MapperService.INDEX_MAPPER_DYNAMIC_SETTING.get(settings);
String value = settings.get("action.auto_create_index");
if (value == null || Booleans.isExplicitTrue(value)) {
final AutoCreate autoCreate = AUTO_CREATE_INDEX_SETTING.get(settings);
if (autoCreate.autoCreateIndex) {
needToCheck = true;
globallyDisabled = false;
matches = null;
matches2 = null;
} else if (Booleans.isExplicitFalse(value)) {
matches = autoCreate.indices;
if (matches != null) {
matches2 = new String[matches.length];
for (int i = 0; i < matches.length; i++) {
matches2[i] = matches[i].substring(1);
}
} else {
matches2 = null;
}
} else {
needToCheck = false;
globallyDisabled = true;
matches = null;
matches2 = null;
} else {
needToCheck = true;
globallyDisabled = false;
matches = Strings.commaDelimitedListToStringArray(value);
matches2 = new String[matches.length];
for (int i = 0; i < matches.length; i++) {
matches2[i] = matches[i].substring(1);
}
}
}
@ -110,4 +111,32 @@ public final class AutoCreateIndex {
}
return false;
}
public static class AutoCreate {
private final boolean autoCreateIndex;
private final String[] indices;
public AutoCreate(String value) {
boolean autoCreateIndex;
String[] indices = null;
try {
autoCreateIndex = Booleans.parseBooleanExact(value);
} catch (IllegalArgumentException ex) {
try {
indices = Strings.commaDelimitedListToStringArray(value);
for (String string : indices) {
if (string == null || string.length() == 0) {
throw new IllegalArgumentException("Can't parse [" + value + "] for setting [action.auto_create_index] must be either [true, false, or a comma seperated list of index patterns]");
}
}
autoCreateIndex = true;
} catch (IllegalArgumentException ex1) {
ex1.addSuppressed(ex);
throw ex1;
}
}
this.indices = indices;
this.autoCreateIndex = autoCreateIndex;
}
}
}

View File

@ -23,6 +23,7 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -36,22 +37,19 @@ import java.util.function.Supplier;
public abstract class TransportMasterNodeReadAction<Request extends MasterNodeReadRequest<Request>, Response extends ActionResponse>
extends TransportMasterNodeAction<Request, Response> {
public static final String FORCE_LOCAL_SETTING = "action.master.force_local";
public static final Setting<Boolean> FORCE_LOCAL_SETTING = Setting.boolSetting("action.master.force_local", false, false, Setting.Scope.CLUSTER);
private Boolean forceLocal;
private final boolean forceLocal;
protected TransportMasterNodeReadAction(Settings settings, String actionName, TransportService transportService,
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, Supplier<Request> request) {
super(settings, actionName, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,request);
this.forceLocal = settings.getAsBoolean(FORCE_LOCAL_SETTING, null);
this.forceLocal = FORCE_LOCAL_SETTING.get(settings);
}
@Override
protected final boolean localExecute(Request request) {
if (forceLocal != null) {
return forceLocal;
}
return request.local();
return forceLocal || request.local();
}
}

View File

@ -55,17 +55,6 @@ import org.elasticsearch.action.indexedscripts.get.GetIndexedScriptResponse;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequestBuilder;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptResponse;
import org.elasticsearch.action.ingest.DeletePipelineRequest;
import org.elasticsearch.action.ingest.DeletePipelineRequestBuilder;
import org.elasticsearch.action.ingest.GetPipelineRequest;
import org.elasticsearch.action.ingest.GetPipelineRequestBuilder;
import org.elasticsearch.action.ingest.GetPipelineResponse;
import org.elasticsearch.action.ingest.PutPipelineRequest;
import org.elasticsearch.action.ingest.PutPipelineRequestBuilder;
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
import org.elasticsearch.action.ingest.SimulatePipelineRequestBuilder;
import org.elasticsearch.action.ingest.SimulatePipelineResponse;
import org.elasticsearch.action.ingest.WritePipelineResponse;
import org.elasticsearch.action.percolate.MultiPercolateRequest;
import org.elasticsearch.action.percolate.MultiPercolateRequestBuilder;
import org.elasticsearch.action.percolate.MultiPercolateResponse;
@ -96,7 +85,6 @@ import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateRequestBuilder;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.settings.Settings;
@ -609,66 +597,6 @@ public interface Client extends ElasticsearchClient, Releasable {
void fieldStats(FieldStatsRequest request, ActionListener<FieldStatsResponse> listener);
/**
* Stores an ingest pipeline
*/
void putPipeline(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener);
/**
* Stores an ingest pipeline
*/
ActionFuture<WritePipelineResponse> putPipeline(PutPipelineRequest request);
/**
* Stores an ingest pipeline
*/
PutPipelineRequestBuilder preparePutPipeline(String id, BytesReference source);
/**
* Deletes a stored ingest pipeline
*/
void deletePipeline(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener);
/**
* Deletes a stored ingest pipeline
*/
ActionFuture<WritePipelineResponse> deletePipeline(DeletePipelineRequest request);
/**
* Deletes a stored ingest pipeline
*/
DeletePipelineRequestBuilder prepareDeletePipeline();
/**
* Returns a stored ingest pipeline
*/
void getPipeline(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener);
/**
* Returns a stored ingest pipeline
*/
ActionFuture<GetPipelineResponse> getPipeline(GetPipelineRequest request);
/**
* Returns a stored ingest pipeline
*/
GetPipelineRequestBuilder prepareGetPipeline(String... ids);
/**
* Simulates an ingest pipeline
*/
void simulatePipeline(SimulatePipelineRequest request, ActionListener<SimulatePipelineResponse> listener);
/**
* Simulates an ingest pipeline
*/
ActionFuture<SimulatePipelineResponse> simulatePipeline(SimulatePipelineRequest request);
/**
* Simulates an ingest pipeline
*/
SimulatePipelineRequestBuilder prepareSimulatePipeline(BytesReference source);
/**
* Returns this clients settings
*/

View File

@ -84,6 +84,18 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse;
import org.elasticsearch.action.admin.cluster.validate.template.RenderSearchTemplateRequest;
import org.elasticsearch.action.admin.cluster.validate.template.RenderSearchTemplateRequestBuilder;
import org.elasticsearch.action.admin.cluster.validate.template.RenderSearchTemplateResponse;
import org.elasticsearch.action.ingest.DeletePipelineRequest;
import org.elasticsearch.action.ingest.DeletePipelineRequestBuilder;
import org.elasticsearch.action.ingest.GetPipelineRequest;
import org.elasticsearch.action.ingest.GetPipelineRequestBuilder;
import org.elasticsearch.action.ingest.GetPipelineResponse;
import org.elasticsearch.action.ingest.PutPipelineRequest;
import org.elasticsearch.action.ingest.PutPipelineRequestBuilder;
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
import org.elasticsearch.action.ingest.SimulatePipelineRequestBuilder;
import org.elasticsearch.action.ingest.SimulatePipelineResponse;
import org.elasticsearch.action.ingest.WritePipelineResponse;
import org.elasticsearch.common.bytes.BytesReference;
/**
* Administrative actions/operations against indices.
@ -474,4 +486,64 @@ public interface ClusterAdminClient extends ElasticsearchClient {
* Return the rendered search request for a given search template.
*/
RenderSearchTemplateRequestBuilder prepareRenderSearchTemplate();
/**
* Stores an ingest pipeline
*/
void putPipeline(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener);
/**
* Stores an ingest pipeline
*/
ActionFuture<WritePipelineResponse> putPipeline(PutPipelineRequest request);
/**
* Stores an ingest pipeline
*/
PutPipelineRequestBuilder preparePutPipeline(String id, BytesReference source);
/**
* Deletes a stored ingest pipeline
*/
void deletePipeline(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener);
/**
* Deletes a stored ingest pipeline
*/
ActionFuture<WritePipelineResponse> deletePipeline(DeletePipelineRequest request);
/**
* Deletes a stored ingest pipeline
*/
DeletePipelineRequestBuilder prepareDeletePipeline();
/**
* Returns a stored ingest pipeline
*/
void getPipeline(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener);
/**
* Returns a stored ingest pipeline
*/
ActionFuture<GetPipelineResponse> getPipeline(GetPipelineRequest request);
/**
* Returns a stored ingest pipeline
*/
GetPipelineRequestBuilder prepareGetPipeline(String... ids);
/**
* Simulates an ingest pipeline
*/
void simulatePipeline(SimulatePipelineRequest request, ActionListener<SimulatePipelineResponse> listener);
/**
* Simulates an ingest pipeline
*/
ActionFuture<SimulatePipelineResponse> simulatePipeline(SimulatePipelineRequest request);
/**
* Simulates an ingest pipeline
*/
SimulatePipelineRequestBuilder prepareSimulatePipeline(BytesReference source);
}

View File

@ -805,66 +805,6 @@ public abstract class AbstractClient extends AbstractComponent implements Client
return new FieldStatsRequestBuilder(this, FieldStatsAction.INSTANCE);
}
@Override
public void putPipeline(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener) {
execute(PutPipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<WritePipelineResponse> putPipeline(PutPipelineRequest request) {
return execute(PutPipelineAction.INSTANCE, request);
}
@Override
public PutPipelineRequestBuilder preparePutPipeline(String id, BytesReference source) {
return new PutPipelineRequestBuilder(this, PutPipelineAction.INSTANCE, id, source);
}
@Override
public void deletePipeline(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener) {
execute(DeletePipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<WritePipelineResponse> deletePipeline(DeletePipelineRequest request) {
return execute(DeletePipelineAction.INSTANCE, request);
}
@Override
public DeletePipelineRequestBuilder prepareDeletePipeline() {
return new DeletePipelineRequestBuilder(this, DeletePipelineAction.INSTANCE);
}
@Override
public void getPipeline(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener) {
execute(GetPipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<GetPipelineResponse> getPipeline(GetPipelineRequest request) {
return execute(GetPipelineAction.INSTANCE, request);
}
@Override
public GetPipelineRequestBuilder prepareGetPipeline(String... ids) {
return new GetPipelineRequestBuilder(this, GetPipelineAction.INSTANCE, ids);
}
@Override
public void simulatePipeline(SimulatePipelineRequest request, ActionListener<SimulatePipelineResponse> listener) {
execute(SimulatePipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<SimulatePipelineResponse> simulatePipeline(SimulatePipelineRequest request) {
return execute(SimulatePipelineAction.INSTANCE, request);
}
@Override
public SimulatePipelineRequestBuilder prepareSimulatePipeline(BytesReference source) {
return new SimulatePipelineRequestBuilder(this, SimulatePipelineAction.INSTANCE, source);
}
static class Admin implements AdminClient {
private final ClusterAdmin clusterAdmin;
@ -1244,6 +1184,66 @@ public abstract class AbstractClient extends AbstractComponent implements Client
public RenderSearchTemplateRequestBuilder prepareRenderSearchTemplate() {
return new RenderSearchTemplateRequestBuilder(this, RenderSearchTemplateAction.INSTANCE);
}
@Override
public void putPipeline(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener) {
execute(PutPipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<WritePipelineResponse> putPipeline(PutPipelineRequest request) {
return execute(PutPipelineAction.INSTANCE, request);
}
@Override
public PutPipelineRequestBuilder preparePutPipeline(String id, BytesReference source) {
return new PutPipelineRequestBuilder(this, PutPipelineAction.INSTANCE, id, source);
}
@Override
public void deletePipeline(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener) {
execute(DeletePipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<WritePipelineResponse> deletePipeline(DeletePipelineRequest request) {
return execute(DeletePipelineAction.INSTANCE, request);
}
@Override
public DeletePipelineRequestBuilder prepareDeletePipeline() {
return new DeletePipelineRequestBuilder(this, DeletePipelineAction.INSTANCE);
}
@Override
public void getPipeline(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener) {
execute(GetPipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<GetPipelineResponse> getPipeline(GetPipelineRequest request) {
return execute(GetPipelineAction.INSTANCE, request);
}
@Override
public GetPipelineRequestBuilder prepareGetPipeline(String... ids) {
return new GetPipelineRequestBuilder(this, GetPipelineAction.INSTANCE, ids);
}
@Override
public void simulatePipeline(SimulatePipelineRequest request, ActionListener<SimulatePipelineResponse> listener) {
execute(SimulatePipelineAction.INSTANCE, request, listener);
}
@Override
public ActionFuture<SimulatePipelineResponse> simulatePipeline(SimulatePipelineRequest request) {
return execute(SimulatePipelineAction.INSTANCE, request);
}
@Override
public SimulatePipelineRequestBuilder prepareSimulatePipeline(BytesReference source) {
return new SimulatePipelineRequestBuilder(this, SimulatePipelineAction.INSTANCE, source);
}
}
static class IndicesAdmin implements IndicesAdminClient {

View File

@ -19,7 +19,9 @@
package org.elasticsearch.common.settings;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.support.AutoCreateIndex;
import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
import org.elasticsearch.client.transport.TransportClientNodesService;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.InternalClusterInfoService;
@ -55,6 +57,7 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.store.IndexStoreConfig;
import org.elasticsearch.indices.analysis.HunspellService;
import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService;
import org.elasticsearch.indices.cache.query.IndicesQueryCache;
import org.elasticsearch.indices.cache.request.IndicesRequestCache;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.recovery.RecoverySettings;
@ -138,6 +141,8 @@ public final class ClusterSettings extends AbstractScopedSettings {
FsRepository.REPOSITORIES_LOCATION_SETTING,
IndexStoreConfig.INDICES_STORE_THROTTLE_TYPE_SETTING,
IndexStoreConfig.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING,
IndicesQueryCache.INDICES_CACHE_QUERY_SIZE_SETTING,
IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING,
IndicesTTLService.INDICES_TTL_INTERVAL_SETTING,
MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING,
MetaData.SETTING_READ_ONLY_SETTING,
@ -261,6 +266,8 @@ public final class ClusterSettings extends AbstractScopedSettings {
URLRepository.REPOSITORIES_LIST_DIRECTORIES_SETTING,
URLRepository.REPOSITORIES_URL_SETTING,
URLRepository.SUPPORTED_PROTOCOLS_SETTING,
TransportMasterNodeReadAction.FORCE_LOCAL_SETTING,
AutoCreateIndex.AUTO_CREATE_INDEX_SETTING,
ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING,
EsExecutors.PROCESSORS_SETTING)));
}

View File

@ -108,7 +108,7 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
private final IndexingSlowLog slowLog;
private final IndexingOperationListener[] listeners;
private volatile AsyncRefreshTask refreshTask;
private final AsyncTranslogFSync fsyncTask;
private volatile AsyncTranslogFSync fsyncTask;
private final SearchSlowLog searchSlowLog;
public IndexService(IndexSettings indexSettings, NodeEnvironment nodeEnv,
@ -147,13 +147,9 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
this.listeners[0] = slowLog;
System.arraycopy(listenersIn, 0, this.listeners, 1, listenersIn.length);
// kick off async ops for the first shard in this index
if (this.indexSettings.getTranslogSyncInterval().millis() != 0) {
this.fsyncTask = new AsyncTranslogFSync(this);
} else {
this.fsyncTask = null;
}
this.refreshTask = new AsyncRefreshTask(this);
searchSlowLog = new SearchSlowLog(indexSettings);
rescheduleFsyncTask(indexSettings.getTranslogDurability());
}
public int numberOfShards() {
@ -565,6 +561,7 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
}
public synchronized void updateMetaData(final IndexMetaData metadata) {
final Translog.Durability oldTranslogDurability = indexSettings.getTranslogDurability();
if (indexSettings.updateIndexMetaData(metadata)) {
for (final IndexShard shard : this.shards.values()) {
try {
@ -576,6 +573,20 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
if (refreshTask.getInterval().equals(indexSettings.getRefreshInterval()) == false) {
rescheduleRefreshTasks();
}
final Translog.Durability durability = indexSettings.getTranslogDurability();
if (durability != oldTranslogDurability) {
rescheduleFsyncTask(durability);
}
}
}
private void rescheduleFsyncTask(Translog.Durability durability) {
try {
if (fsyncTask != null) {
fsyncTask.close();
}
} finally {
fsyncTask = durability == Translog.Durability.REQUEST ? null : new AsyncTranslogFSync(this);
}
}

View File

@ -55,7 +55,7 @@ public final class IndexSettings {
public static final Setting<Boolean> QUERY_STRING_ANALYZE_WILDCARD = Setting.boolSetting("indices.query.query_string.analyze_wildcard", false, false, Setting.Scope.CLUSTER);
public static final Setting<Boolean> QUERY_STRING_ALLOW_LEADING_WILDCARD = Setting.boolSetting("indices.query.query_string.allowLeadingWildcard", true, false, Setting.Scope.CLUSTER);
public static final Setting<Boolean> ALLOW_UNMAPPED = Setting.boolSetting("index.query.parse.allow_unmapped_fields", true, false, Setting.Scope.INDEX);
public static final Setting<TimeValue> INDEX_TRANSLOG_SYNC_INTERVAL_SETTING = Setting.timeSetting("index.translog.sync_interval", TimeValue.timeValueSeconds(5), false, Setting.Scope.INDEX);
public static final Setting<TimeValue> INDEX_TRANSLOG_SYNC_INTERVAL_SETTING = Setting.timeSetting("index.translog.sync_interval", TimeValue.timeValueSeconds(5), TimeValue.timeValueMillis(100), false, Setting.Scope.INDEX);
public static final Setting<Translog.Durability> INDEX_TRANSLOG_DURABILITY_SETTING = new Setting<>("index.translog.durability", Translog.Durability.REQUEST.name(), (value) -> Translog.Durability.valueOf(value.toUpperCase(Locale.ROOT)), true, Setting.Scope.INDEX);
public static final Setting<Boolean> INDEX_WARMER_ENABLED_SETTING = Setting.boolSetting("index.warmer.enabled", true, true, Setting.Scope.INDEX);
public static final Setting<Boolean> INDEX_TTL_DISABLE_PURGE_SETTING = Setting.boolSetting("index.ttl.disable_purge", false, true, Setting.Scope.INDEX);

View File

@ -22,7 +22,6 @@ package org.elasticsearch.index.cache.query.index;
import org.apache.lucene.search.QueryCachingPolicy;
import org.apache.lucene.search.Weight;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.cache.query.QueryCache;
@ -36,7 +35,6 @@ public class IndexQueryCache extends AbstractIndexComponent implements QueryCach
final IndicesQueryCache indicesQueryCache;
@Inject
public IndexQueryCache(IndexSettings indexSettings, IndicesQueryCache indicesQueryCache) {
super(indexSettings);
this.indicesQueryCache = indicesQueryCache;

View File

@ -31,7 +31,6 @@ import org.elasticsearch.index.cache.query.QueryCache;
*/
public class NoneQueryCache extends AbstractIndexComponent implements QueryCache {
@Inject
public NoneQueryCache(IndexSettings indexSettings) {
super(indexSettings);
logger.debug("Using no query cache");

View File

@ -429,9 +429,6 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
try (ReleasableLock lock = readLock.acquire()) {
ensureOpen();
Location location = current.add(bytes);
if (config.isSyncOnEachOperation()) {
current.sync();
}
assert assertBytesAtLocation(location, bytes);
return location;
}

View File

@ -65,13 +65,6 @@ public final class TranslogConfig {
this.bigArrays = bigArrays;
}
/**
* Returns <code>true</code> iff each low level operation shoudl be fsynced
*/
public boolean isSyncOnEachOperation() {
return indexSettings.getTranslogSyncInterval().millis() == 0;
}
/**
* Returns the index indexSettings
*/

View File

@ -32,9 +32,10 @@ import org.apache.lucene.search.Weight;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.ShardCoreKeyMap;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Scope;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.MemorySizeValue;
import org.elasticsearch.index.cache.query.QueryCacheStats;
import org.elasticsearch.index.shard.ShardId;
@ -48,10 +49,10 @@ import java.util.concurrent.ConcurrentHashMap;
public class IndicesQueryCache extends AbstractComponent implements QueryCache, Closeable {
public static final String INDICES_CACHE_QUERY_SIZE = "indices.queries.cache.size";
@Deprecated
public static final String DEPRECATED_INDICES_CACHE_QUERY_SIZE = "indices.cache.filter.size";
public static final String INDICES_CACHE_QUERY_COUNT = "indices.queries.cache.count";
public static final Setting<ByteSizeValue> INDICES_CACHE_QUERY_SIZE_SETTING = Setting.byteSizeSetting(
"indices.queries.cache.size", "10%", false, Scope.CLUSTER);
public static final Setting<Integer> INDICES_CACHE_QUERY_COUNT_SETTING = Setting.intSetting(
"indices.queries.cache.count", 10000, 1, false, Scope.CLUSTER);
private final LRUQueryCache cache;
private final ShardCoreKeyMap shardKeyMap = new ShardCoreKeyMap();
@ -66,21 +67,10 @@ public class IndicesQueryCache extends AbstractComponent implements QueryCache,
@Inject
public IndicesQueryCache(Settings settings) {
super(settings);
String sizeString = settings.get(INDICES_CACHE_QUERY_SIZE);
if (sizeString == null) {
sizeString = settings.get(DEPRECATED_INDICES_CACHE_QUERY_SIZE);
if (sizeString != null) {
deprecationLogger.deprecated("The [" + DEPRECATED_INDICES_CACHE_QUERY_SIZE
+ "] settings is now deprecated, use [" + INDICES_CACHE_QUERY_SIZE + "] instead");
}
}
if (sizeString == null) {
sizeString = "10%";
}
final ByteSizeValue size = MemorySizeValue.parseBytesSizeValueOrHeapRatio(sizeString, INDICES_CACHE_QUERY_SIZE);
final int count = settings.getAsInt(INDICES_CACHE_QUERY_COUNT, 1000);
logger.debug("using [node] query cache with size [{}], actual_size [{}], max filter count [{}]",
sizeString, size, count);
final ByteSizeValue size = INDICES_CACHE_QUERY_SIZE_SETTING.get(settings);
final int count = INDICES_CACHE_QUERY_COUNT_SETTING.get(settings);
logger.debug("using [node] query cache with size [{}] max filter count [{}]",
size, count);
cache = new LRUQueryCache(count, size.bytes()) {
private Stats getStats(Object coreKey) {

View File

@ -188,11 +188,12 @@ public class Node implements Releasable {
modules.add(pluginModule);
}
modules.add(new PluginsModule(pluginsService));
modules.add(new SettingsModule(this.settings, settingsFilter));
SettingsModule settingsModule = new SettingsModule(this.settings, settingsFilter);
modules.add(settingsModule);
modules.add(new EnvironmentModule(environment));
modules.add(new NodeModule(this, monitorService));
modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry));
modules.add(new ScriptModule(this.settings));
modules.add(new ScriptModule(settingsModule));
modules.add(new NodeEnvironmentModule(nodeEnvironment));
modules.add(new ClusterNameModule(this.settings));
modules.add(new ThreadPoolModule(threadPool));

View File

@ -42,6 +42,6 @@ public class RestDeletePipelineAction extends BaseRestHandler {
DeletePipelineRequest request = new DeletePipelineRequest(restRequest.param("id"));
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
client.deletePipeline(request, new AcknowledgedRestListener<>(channel));
client.admin().cluster().deletePipeline(request, new AcknowledgedRestListener<>(channel));
}
}

View File

@ -42,6 +42,6 @@ public class RestGetPipelineAction extends BaseRestHandler {
protected void handleRequest(RestRequest restRequest, RestChannel channel, Client client) throws Exception {
GetPipelineRequest request = new GetPipelineRequest(Strings.splitStringByCommaToArray(restRequest.param("id")));
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
client.getPipeline(request, new RestStatusToXContentListener<>(channel));
client.admin().cluster().getPipeline(request, new RestStatusToXContentListener<>(channel));
}
}

View File

@ -43,6 +43,6 @@ public class RestPutPipelineAction extends BaseRestHandler {
PutPipelineRequest request = new PutPipelineRequest(restRequest.param("id"), RestActions.getRestContent(restRequest));
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
client.putPipeline(request, new AcknowledgedRestListener<>(channel));
client.admin().cluster().putPipeline(request, new AcknowledgedRestListener<>(channel));
}
}

View File

@ -46,6 +46,6 @@ public class RestSimulatePipelineAction extends BaseRestHandler {
SimulatePipelineRequest request = new SimulatePipelineRequest(RestActions.getRestContent(restRequest));
request.setId(restRequest.param("id"));
request.setVerbose(restRequest.paramAsBoolean("verbose", false));
client.simulatePipeline(request, new RestToXContentListener<>(channel));
client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
}

View File

@ -27,6 +27,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
@ -38,6 +40,8 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri
public static final String NAME = "native";
public static final List<String> TYPES = Collections.singletonList(NAME);
private final Map<String, NativeScriptFactory> scripts;
@Inject
@ -47,17 +51,17 @@ public class NativeScriptEngineService extends AbstractComponent implements Scri
}
@Override
public String[] types() {
return new String[]{NAME};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[0];
public List<String> getExtensions() {
return Collections.emptyList();
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.script;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class ScriptEngineRegistry {
private final Map<Class<? extends ScriptEngineService>, List<String>> registeredScriptEngineServices;
private final Map<String, Class<? extends ScriptEngineService>> registeredLanguages;
public ScriptEngineRegistry(Iterable<ScriptEngineRegistration> registrations) {
Objects.requireNonNull(registrations);
Map<Class<? extends ScriptEngineService>, List<String>> registeredScriptEngineServices = new HashMap<>();
Map<String, Class<? extends ScriptEngineService>> registeredLanguages = new HashMap<>();
for (ScriptEngineRegistration registration : registrations) {
List<String> languages =
registeredScriptEngineServices.putIfAbsent(registration.getScriptEngineService(), Collections.unmodifiableList(registration.getScriptEngineLanguages()));
if (languages != null) {
throw new IllegalArgumentException("script engine service [" + registration.getScriptEngineService() + "] already registered for languages [" + String.join(",", languages) + "]");
}
for (String language : registration.getScriptEngineLanguages()) {
Class<? extends ScriptEngineService> scriptEngineServiceClazz =
registeredLanguages.putIfAbsent(language, registration.getScriptEngineService());
if (scriptEngineServiceClazz != null) {
throw new IllegalArgumentException("scripting language [" + language + "] already registered for script engine service [" + scriptEngineServiceClazz.getCanonicalName() + "]");
}
}
}
this.registeredScriptEngineServices = Collections.unmodifiableMap(registeredScriptEngineServices);
this.registeredLanguages = Collections.unmodifiableMap(registeredLanguages);
}
Iterable<Class<? extends ScriptEngineService>> getRegisteredScriptEngineServices() {
return registeredScriptEngineServices.keySet();
}
List<String> getLanguages(Class<? extends ScriptEngineService> scriptEngineService) {
Objects.requireNonNull(scriptEngineService);
return registeredScriptEngineServices.get(scriptEngineService);
}
Map<String, Class<? extends ScriptEngineService>> getRegisteredLanguages() {
return registeredLanguages;
}
public static class ScriptEngineRegistration {
private final Class<? extends ScriptEngineService> scriptEngineService;
private final List<String> scriptEngineLanguages;
public ScriptEngineRegistration(Class<? extends ScriptEngineService> scriptEngineService, List<String> scriptEngineLanguages) {
Objects.requireNonNull(scriptEngineService);
Objects.requireNonNull(scriptEngineLanguages);
if (scriptEngineLanguages.isEmpty()) {
throw new IllegalArgumentException("languages for script engine service [" + scriptEngineService.getCanonicalName() + "] should be non-empty");
}
this.scriptEngineService = scriptEngineService;
this.scriptEngineLanguages = scriptEngineLanguages;
}
Class<? extends ScriptEngineService> getScriptEngineService() {
return scriptEngineService;
}
List<String> getScriptEngineLanguages() {
return scriptEngineLanguages;
}
}
}

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.Closeable;
import java.util.List;
import java.util.Map;
/**
@ -30,11 +31,11 @@ import java.util.Map;
*/
public interface ScriptEngineService extends Closeable {
String[] types();
List<String> getTypes();
String[] extensions();
List<String> getExtensions();
boolean sandboxed();
boolean isSandboxed();
Object compile(String script, Map<String, String> params);

View File

@ -19,37 +19,48 @@
package org.elasticsearch.script;
import org.elasticsearch.common.Booleans;
import java.util.Locale;
import java.util.HashMap;
import java.util.Map;
/**
* Mode for a specific script, used for script settings.
* Defines whether a certain script or catefory of scripts can be executed or not, or whether it can
* Defines whether a certain script or category of scripts can be executed or not, or whether it can
* only be executed by a sandboxed scripting language.
*/
enum ScriptMode {
ON,
OFF,
SANDBOX;
ON("true"),
OFF("false"),
SANDBOX("sandbox");
static ScriptMode parse(String input) {
input = input.toLowerCase(Locale.ROOT);
if (Booleans.isExplicitTrue(input)) {
return ON;
}
if (Booleans.isExplicitFalse(input)) {
return OFF;
}
if (SANDBOX.toString().equals(input)) {
return SANDBOX;
}
throw new IllegalArgumentException("script mode [" + input + "] not supported");
private final String mode;
ScriptMode(String mode) {
this.mode = mode;
}
private static final Map<String, ScriptMode> SCRIPT_MODES;
static {
SCRIPT_MODES = new HashMap<>();
for (ScriptMode scriptMode : ScriptMode.values()) {
SCRIPT_MODES.put(scriptMode.mode, scriptMode);
}
}
static ScriptMode parse(String input) {
ScriptMode scriptMode = SCRIPT_MODES.get(input);
if (scriptMode == null) {
throw new IllegalArgumentException("script mode [" + input + "] not supported");
}
return scriptMode;
}
public String getMode() {
return mode;
}
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
return mode;
}
}

View File

@ -19,127 +19,32 @@
package org.elasticsearch.script;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.ScriptService.ScriptType;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static java.util.Collections.unmodifiableMap;
/**
* Holds the {@link org.elasticsearch.script.ScriptMode}s for each of the different scripting languages available,
* each script source and each scripted operation.
*/
public class ScriptModes {
static final String SCRIPT_SETTINGS_PREFIX = "script.";
static final String ENGINE_SETTINGS_PREFIX = "script.engine";
private static final String SCRIPT_SETTINGS_PREFIX = "script";
private static final String ENGINE_SETTINGS_PREFIX = "script.engine";
final Map<String, ScriptMode> scriptModes;
ScriptModes(Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Settings settings) {
//filter out the native engine as we don't want to apply fine grained settings to it.
//native scripts are always on as they are static by definition.
Map<String, ScriptEngineService> filteredEngines = new HashMap<>(scriptEngines);
filteredEngines.remove(NativeScriptEngineService.NAME);
this.scriptModes = buildScriptModeSettingsMap(settings, filteredEngines, scriptContextRegistry);
}
private static Map<String, ScriptMode> buildScriptModeSettingsMap(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry) {
HashMap<String, ScriptMode> scriptModesMap = new HashMap<>();
//file scripts are enabled by default, for any language
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptContextRegistry, ScriptType.FILE, ScriptMode.ON, scriptModesMap);
//indexed scripts are enabled by default only for sandboxed languages
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptContextRegistry, ScriptType.INDEXED, ScriptMode.SANDBOX, scriptModesMap);
//dynamic scripts are enabled by default only for sandboxed languages
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptContextRegistry, ScriptType.INLINE, ScriptMode.SANDBOX, scriptModesMap);
processSourceBasedGlobalSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
processOperationBasedGlobalSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
processEngineSpecificSettings(settings, scriptEngines, scriptContextRegistry, scriptModesMap);
return unmodifiableMap(scriptModesMap);
}
private static void processSourceBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Map<String, ScriptMode> scriptModes) {
//read custom source based settings for all operations (e.g. script.indexed: on)
for (ScriptType scriptType : ScriptType.values()) {
String scriptTypeSetting = settings.get(SCRIPT_SETTINGS_PREFIX + scriptType);
if (Strings.hasLength(scriptTypeSetting)) {
ScriptMode scriptTypeMode = ScriptMode.parse(scriptTypeSetting);
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptContextRegistry, scriptType, scriptTypeMode, scriptModes);
}
ScriptModes(ScriptSettings scriptSettings, Settings settings) {
HashMap<String, ScriptMode> scriptModes = new HashMap<>();
for (Setting<ScriptMode> scriptModeSetting : scriptSettings.getScriptLanguageSettings()) {
scriptModes.put(scriptModeSetting.getKey(), scriptModeSetting.get(settings));
}
}
private static void processOperationBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Map<String, ScriptMode> scriptModes) {
//read custom op based settings for all sources (e.g. script.aggs: off)
//op based settings take precedence over source based settings, hence they get expanded later
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
ScriptMode scriptMode = getScriptContextMode(settings, SCRIPT_SETTINGS_PREFIX, scriptContext);
if (scriptMode != null) {
addGlobalScriptContextModes(scriptEngines.keySet(), scriptContext, scriptMode, scriptModes);
}
}
}
private static void processEngineSpecificSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Map<String, ScriptMode> scriptModes) {
Map<String, Settings> langGroupedSettings = settings.getGroups(ENGINE_SETTINGS_PREFIX, true);
for (Map.Entry<String, Settings> langSettings : langGroupedSettings.entrySet()) {
//read engine specific settings that refer to a non existing script lang will be ignored
ScriptEngineService scriptEngineService = scriptEngines.get(langSettings.getKey());
if (scriptEngineService != null) {
for (ScriptType scriptType : ScriptType.values()) {
String scriptTypePrefix = scriptType + ".";
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
ScriptMode scriptMode = getScriptContextMode(langSettings.getValue(), scriptTypePrefix, scriptContext);
if (scriptMode != null) {
addScriptMode(scriptEngineService, scriptType, scriptContext, scriptMode, scriptModes);
}
}
}
}
}
}
private static ScriptMode getScriptContextMode(Settings settings, String prefix, ScriptContext scriptContext) {
String settingValue = settings.get(prefix + scriptContext.getKey());
if (Strings.hasLength(settingValue)) {
return ScriptMode.parse(settingValue);
}
return null;
}
private static void addGlobalScriptTypeModes(Set<String> langs, ScriptContextRegistry scriptContextRegistry, ScriptType scriptType, ScriptMode scriptMode, Map<String, ScriptMode> scriptModes) {
for (String lang : langs) {
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
addScriptMode(lang, scriptType, scriptContext, scriptMode, scriptModes);
}
}
}
private static void addGlobalScriptContextModes(Set<String> langs, ScriptContext scriptContext, ScriptMode scriptMode, Map<String, ScriptMode> scriptModes) {
for (String lang : langs) {
for (ScriptType scriptType : ScriptType.values()) {
addScriptMode(lang, scriptType, scriptContext, scriptMode, scriptModes);
}
}
}
private static void addScriptMode(ScriptEngineService scriptEngineService, ScriptType scriptType, ScriptContext scriptContext,
ScriptMode scriptMode, Map<String, ScriptMode> scriptModes) {
//expand the lang specific settings to all of the different names given to each scripting language
for (String scriptEngineName : scriptEngineService.types()) {
addScriptMode(scriptEngineName, scriptType, scriptContext, scriptMode, scriptModes);
}
}
private static void addScriptMode(String lang, ScriptType scriptType, ScriptContext scriptContext, ScriptMode scriptMode, Map<String, ScriptMode> scriptModes) {
scriptModes.put(ENGINE_SETTINGS_PREFIX + "." + lang + "." + scriptType + "." + scriptContext.getKey(), scriptMode);
this.scriptModes = Collections.unmodifiableMap(scriptModes);
}
/**
@ -156,13 +61,25 @@ public class ScriptModes {
if (NativeScriptEngineService.NAME.equals(lang)) {
return ScriptMode.ON;
}
ScriptMode scriptMode = scriptModes.get(ENGINE_SETTINGS_PREFIX + "." + lang + "." + scriptType + "." + scriptContext.getKey());
ScriptMode scriptMode = scriptModes.get(getKey(lang, scriptType, scriptContext));
if (scriptMode == null) {
throw new IllegalArgumentException("script mode not found for lang [" + lang + "], script_type [" + scriptType + "], operation [" + scriptContext.getKey() + "]");
}
return scriptMode;
}
static String operationKey(ScriptContext scriptContext) {
return SCRIPT_SETTINGS_PREFIX + "." + scriptContext.getKey();
}
static String sourceKey(ScriptType scriptType) {
return SCRIPT_SETTINGS_PREFIX + "." + scriptType.getScriptType();
}
static String getKey(String lang, ScriptType scriptType, ScriptContext scriptContext) {
return ENGINE_SETTINGS_PREFIX + "." + lang + "." + scriptType + "." + scriptContext.getKey();
}
@Override
public String toString() {
//order settings by key before printing them out, for readability

View File

@ -22,12 +22,14 @@ package org.elasticsearch.script;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.SettingsModule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* An {@link org.elasticsearch.common.inject.Module} which manages {@link ScriptEngineService}s, as well
@ -35,20 +37,25 @@ import java.util.Map;
*/
public class ScriptModule extends AbstractModule {
private final Settings settings;
private final SettingsModule settingsModule;
private final List<Class<? extends ScriptEngineService>> scriptEngines = new ArrayList<>();
private final List<ScriptEngineRegistry.ScriptEngineRegistration> scriptEngineRegistrations = new ArrayList<>();
{
scriptEngineRegistrations.add(new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, NativeScriptEngineService.TYPES));
}
private final Map<String, Class<? extends NativeScriptFactory>> scripts = new HashMap<>();
private final List<ScriptContext.Plugin> customScriptContexts = new ArrayList<>();
public ScriptModule(Settings settings) {
this.settings = settings;
public ScriptModule(SettingsModule settingsModule) {
this.settingsModule = settingsModule;
}
public void addScriptEngine(Class<? extends ScriptEngineService> scriptEngine) {
scriptEngines.add(scriptEngine);
public void addScriptEngine(ScriptEngineRegistry.ScriptEngineRegistration scriptEngineRegistration) {
Objects.requireNonNull(scriptEngineRegistration);
scriptEngineRegistrations.add(scriptEngineRegistration);
}
public void registerScript(String name, Class<? extends NativeScriptFactory> script) {
@ -74,11 +81,23 @@ public class ScriptModule extends AbstractModule {
Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
multibinder.addBinding().to(NativeScriptEngineService.class);
for (Class<? extends ScriptEngineService> scriptEngine : scriptEngines) {
multibinder.addBinding().to(scriptEngine).asEagerSingleton();
for (ScriptEngineRegistry.ScriptEngineRegistration scriptEngineRegistration : scriptEngineRegistrations) {
multibinder.addBinding().to(scriptEngineRegistration.getScriptEngineService()).asEagerSingleton();
}
bind(ScriptContextRegistry.class).toInstance(new ScriptContextRegistry(customScriptContexts));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts);
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngineRegistrations);
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptSettings.getScriptTypeSettings().forEach(settingsModule::registerSetting);
scriptSettings.getScriptContextSettings().forEach(settingsModule::registerSetting);
scriptSettings.getScriptLanguageSettings().forEach(settingsModule::registerSetting);
settingsModule.registerSetting(scriptSettings.getDefaultScriptLanguageSetting());
bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry);
bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry);
bind(ScriptSettings.class).toInstance(scriptSettings);
bind(ScriptService.class).asEagerSingleton();
}
}

View File

@ -71,6 +71,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
@ -83,12 +84,10 @@ public class ScriptService extends AbstractComponent implements Closeable {
static final String DISABLE_DYNAMIC_SCRIPTING_SETTING = "script.disable_dynamic";
public static final String DEFAULT_SCRIPTING_LANGUAGE_SETTING = "script.default_lang";
public static final Setting<Integer> SCRIPT_CACHE_SIZE_SETTING = Setting.intSetting("script.cache.max_size", 100, 0, false, Setting.Scope.CLUSTER);
public static final String SCRIPT_CACHE_EXPIRE_SETTING = "script.cache.expire";
public static final Setting<TimeValue> SCRIPT_CACHE_EXPIRE_SETTING = Setting.positiveTimeSetting("script.cache.expire", TimeValue.timeValueMillis(0), false, Setting.Scope.CLUSTER);
public static final String SCRIPT_INDEX = ".scripts";
public static final String DEFAULT_LANG = "groovy";
public static final String SCRIPT_AUTO_RELOAD_ENABLED_SETTING = "script.auto_reload_enabled";
public static final Setting<Boolean> SCRIPT_AUTO_RELOAD_ENABLED_SETTING = Setting.boolSetting("script.auto_reload_enabled", true, false, Setting.Scope.CLUSTER);
private final String defaultLang;
@ -137,45 +136,50 @@ public class ScriptService extends AbstractComponent implements Closeable {
@Inject
public ScriptService(Settings settings, Environment env, Set<ScriptEngineService> scriptEngines,
ResourceWatcherService resourceWatcherService, ScriptContextRegistry scriptContextRegistry) throws IOException {
ResourceWatcherService resourceWatcherService, ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry, ScriptSettings scriptSettings) throws IOException {
super(settings);
Objects.requireNonNull(scriptEngineRegistry);
Objects.requireNonNull(scriptContextRegistry);
Objects.requireNonNull(scriptSettings);
this.parseFieldMatcher = new ParseFieldMatcher(settings);
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
throw new IllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml");
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: true` and `script.indexed: true` in elasticsearch.yml");
}
this.scriptEngines = scriptEngines;
this.scriptContextRegistry = scriptContextRegistry;
int cacheMaxSize = SCRIPT_CACHE_SIZE_SETTING.get(settings);
TimeValue cacheExpire = settings.getAsTime(SCRIPT_CACHE_EXPIRE_SETTING, null);
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);
this.defaultLang = settings.get(DEFAULT_SCRIPTING_LANGUAGE_SETTING, DEFAULT_LANG);
this.defaultLang = scriptSettings.getDefaultScriptLanguageSetting().get(settings);
CacheBuilder<CacheKey, CompiledScript> cacheBuilder = CacheBuilder.builder();
if (cacheMaxSize >= 0) {
cacheBuilder.setMaximumWeight(cacheMaxSize);
}
if (cacheExpire != null) {
TimeValue cacheExpire = SCRIPT_CACHE_EXPIRE_SETTING.get(settings);
if (cacheExpire.getNanos() != 0) {
cacheBuilder.setExpireAfterAccess(cacheExpire.nanos());
}
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);
this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();
Map<String, ScriptEngineService> enginesByLangBuilder = new HashMap<>();
Map<String, ScriptEngineService> enginesByExtBuilder = new HashMap<>();
for (ScriptEngineService scriptEngine : scriptEngines) {
for (String type : scriptEngine.types()) {
enginesByLangBuilder.put(type, scriptEngine);
for (String language : scriptEngineRegistry.getLanguages(scriptEngine.getClass())) {
enginesByLangBuilder.put(language, scriptEngine);
}
for (String ext : scriptEngine.extensions()) {
for (String ext : scriptEngine.getExtensions()) {
enginesByExtBuilder.put(ext, scriptEngine);
}
}
this.scriptEnginesByLang = unmodifiableMap(enginesByLangBuilder);
this.scriptEnginesByExt = unmodifiableMap(enginesByExtBuilder);
this.scriptModes = new ScriptModes(this.scriptEnginesByLang, scriptContextRegistry, settings);
this.scriptModes = new ScriptModes(scriptSettings, settings);
// add file watcher for static scripts
scriptsDirectory = env.scriptsFile();
@ -185,7 +189,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
FileWatcher fileWatcher = new FileWatcher(scriptsDirectory);
fileWatcher.addListener(new ScriptChangesListener());
if (settings.getAsBoolean(SCRIPT_AUTO_RELOAD_ENABLED_SETTING, true)) {
if (SCRIPT_AUTO_RELOAD_ENABLED_SETTING.get(settings)) {
// automatic reload is enabled - register scripts
resourceWatcherService.add(fileWatcher);
} else {
@ -475,7 +479,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
case OFF:
return false;
case SANDBOX:
return scriptEngineService.sandboxed();
return scriptEngineService.isSandboxed();
default:
throw new IllegalArgumentException("script mode [" + mode + "] not supported");
}
@ -534,12 +538,12 @@ public class ScriptService extends AbstractComponent implements Closeable {
try {
//we don't know yet what the script will be used for, but if all of the operations for this lang
// with file scripts are disabled, it makes no sense to even compile it and cache it.
if (isAnyScriptContextEnabled(engineService.types()[0], engineService, ScriptType.FILE)) {
if (isAnyScriptContextEnabled(engineService.getTypes().get(0), engineService, ScriptType.FILE)) {
logger.info("compiling script file [{}]", file.toAbsolutePath());
try(InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) {
String script = Streams.copyToString(reader);
CacheKey cacheKey = new CacheKey(engineService, scriptNameExt.v1(), null, Collections.emptyMap());
staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.types()[0], engineService.compile(script, Collections.emptyMap())));
staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.getTypes().get(0), engineService.compile(script, Collections.emptyMap())));
scriptMetrics.onCompilation();
}
} else {
@ -581,14 +585,16 @@ public class ScriptService extends AbstractComponent implements Closeable {
* - loaded from an index
* - loaded from file
*/
public static enum ScriptType {
public enum ScriptType {
INLINE(0, "inline"),
INDEXED(1, "id"),
FILE(2, "file");
INLINE(0, "inline", "inline", ScriptMode.SANDBOX),
INDEXED(1, "id", "indexed", ScriptMode.SANDBOX),
FILE(2, "file", "file", ScriptMode.ON);
private final int val;
private final ParseField parseField;
private final String scriptType;
private final ScriptMode defaultScriptMode;
public static ScriptType readFrom(StreamInput in) throws IOException {
int scriptTypeVal = in.readVInt();
@ -609,19 +615,30 @@ public class ScriptService extends AbstractComponent implements Closeable {
}
}
private ScriptType(int val, String name) {
ScriptType(int val, String name, String scriptType, ScriptMode defaultScriptMode) {
this.val = val;
this.parseField = new ParseField(name);
this.scriptType = scriptType;
this.defaultScriptMode = defaultScriptMode;
}
public ParseField getParseField() {
return parseField;
}
public ScriptMode getDefaultScriptMode() {
return defaultScriptMode;
}
public String getScriptType() {
return scriptType;
}
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}
private static final class CacheKey {
@ -631,7 +648,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
final Map<String, String> params;
private CacheKey(final ScriptEngineService service, final String name, final String code, final Map<String, String> params) {
this.lang = service.types()[0];
this.lang = service.getTypes().get(0);
this.name = name;
this.code = code;
this.params = params;

View File

@ -0,0 +1,165 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.script;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ScriptSettings {
public final static String DEFAULT_LANG = "groovy";
private final static Map<ScriptService.ScriptType, Setting<ScriptMode>> SCRIPT_TYPE_SETTING_MAP;
static {
Map<ScriptService.ScriptType, Setting<ScriptMode>> scriptTypeSettingMap = new HashMap<>();
for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) {
scriptTypeSettingMap.put(scriptType, new Setting<>(
ScriptModes.sourceKey(scriptType),
scriptType.getDefaultScriptMode().getMode(),
ScriptMode::parse,
false,
Setting.Scope.CLUSTER));
}
SCRIPT_TYPE_SETTING_MAP = Collections.unmodifiableMap(scriptTypeSettingMap);
}
private final Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap;
private final List<Setting<ScriptMode>> scriptLanguageSettings;
private final Setting<String> defaultScriptLanguageSetting;
public ScriptSettings(ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) {
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap = contextSettings(scriptContextRegistry);
this.scriptContextSettingMap = Collections.unmodifiableMap(scriptContextSettingMap);
List<Setting<ScriptMode>> scriptLanguageSettings = languageSettings(SCRIPT_TYPE_SETTING_MAP, scriptContextSettingMap, scriptEngineRegistry, scriptContextRegistry);
this.scriptLanguageSettings = Collections.unmodifiableList(scriptLanguageSettings);
this.defaultScriptLanguageSetting = new Setting<>("script.default_lang", DEFAULT_LANG, setting -> {
if (!"groovy".equals(setting) && !scriptEngineRegistry.getRegisteredLanguages().containsKey(setting)) {
throw new IllegalArgumentException("unregistered default language [" + setting + "]");
}
return setting;
}, false, Setting.Scope.CLUSTER);
}
private static Map<ScriptContext, Setting<ScriptMode>> contextSettings(ScriptContextRegistry scriptContextRegistry) {
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap = new HashMap<>();
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
scriptContextSettingMap.put(scriptContext, new Setting<>(
ScriptModes.operationKey(scriptContext),
ScriptMode.OFF.getMode(),
ScriptMode::parse,
false,
Setting.Scope.CLUSTER
));
}
return scriptContextSettingMap;
}
private static List<Setting<ScriptMode>> languageSettings(
Map<ScriptService.ScriptType, Setting<ScriptMode>> scriptTypeSettingMap,
Map<ScriptContext, Setting<ScriptMode>> scriptContextSettingMap,
ScriptEngineRegistry scriptEngineRegistry,
ScriptContextRegistry scriptContextRegistry) {
List<Setting<ScriptMode>> scriptModeSettings = new ArrayList<>();
for (Class<? extends ScriptEngineService> scriptEngineService : scriptEngineRegistry.getRegisteredScriptEngineServices()) {
List<String> languages = scriptEngineRegistry.getLanguages(scriptEngineService);
for (String language : languages) {
if (NativeScriptEngineService.TYPES.contains(language)) {
// native scripts are always enabled, and their settings can not be changed
continue;
}
for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) {
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
Function<Settings, String> defaultSetting = settings -> {
// fallback logic for script mode settings
// the first fallback is other types registered by the same script engine service
// e.g., "py.inline.aggs" is in the settings but a script with lang "python" is executed
Map<String, List<String>> languageSettings =
languages
.stream()
.map(lang -> Tuple.tuple(lang, settings.get(ScriptModes.getKey(lang, scriptType, scriptContext))))
.filter(tuple -> tuple.v2() != null)
.collect(Collectors.groupingBy(Tuple::v2, Collectors.mapping(Tuple::v1, Collectors.toList())));
if (!languageSettings.isEmpty()) {
if (languageSettings.size() > 1) {
throw new IllegalArgumentException("conflicting settings [" + languageSettings.toString() + "] for language [" + language + "]");
}
return languageSettings.keySet().iterator().next();
}
// the next fallback is global operation-based settings (e.g., "script.aggs: false")
Setting<ScriptMode> setting = scriptContextSettingMap.get(scriptContext);
if (setting.exists(settings)) {
return setting.get(settings).getMode();
}
// the next fallback is global source-based settings (e.g., "script.inline: false")
Setting<ScriptMode> scriptTypeSetting = scriptTypeSettingMap.get(scriptType);
if (scriptTypeSetting.exists(settings)) {
return scriptTypeSetting.get(settings).getMode();
}
// the final fallback is the default for the type
return scriptType.getDefaultScriptMode().toString();
};
Setting<ScriptMode> setting =
new Setting<>(
ScriptModes.getKey(language, scriptType, scriptContext),
defaultSetting,
ScriptMode::parse,
false,
Setting.Scope.CLUSTER);
scriptModeSettings.add(setting);
}
}
}
}
return scriptModeSettings;
}
public Iterable<Setting<ScriptMode>> getScriptTypeSettings() {
return Collections.unmodifiableCollection(SCRIPT_TYPE_SETTING_MAP.values());
}
public Iterable<Setting<ScriptMode>> getScriptContextSettings() {
return Collections.unmodifiableCollection(scriptContextSettingMap.values());
}
public Iterable<Setting<ScriptMode>> getScriptLanguageSettings() {
return scriptLanguageSettings;
}
public Setting<String> getDefaultScriptLanguageSetting() {
return defaultScriptLanguageSetting;
}
}

View File

@ -107,7 +107,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
if (sb.get("cluster.name") == null) {
sb.put("cluster.name", "tribe_" + Strings.randomBase64UUID()); // make sure it won't join other tribe nodes in the same JVM
}
sb.put(TransportMasterNodeReadAction.FORCE_LOCAL_SETTING, true);
sb.put(TransportMasterNodeReadAction.FORCE_LOCAL_SETTING.getKey(), true);
return sb.build();
}
@ -135,6 +135,9 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
Settings.Builder sb = Settings.builder().put(entry.getValue());
sb.put("name", settings.get("name") + "/" + entry.getKey());
sb.put(Environment.PATH_HOME_SETTING.getKey(), Environment.PATH_HOME_SETTING.get(settings)); // pass through ES home dir
if (Environment.PATH_CONF_SETTING.exists(settings)) {
sb.put(Environment.PATH_CONF_SETTING.getKey(), Environment.PATH_CONF_SETTING.get(settings));
}
sb.put(TRIBE_NAME, entry.getKey());
if (sb.get("http.enabled") == null) {
sb.put("http.enabled", false);

View File

@ -0,0 +1,80 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.support;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
public class AutoCreateIndexTests extends ESTestCase {
public void testBasic() {
{
AutoCreateIndex autoCreateIndex = new AutoCreateIndex(Settings.EMPTY, new IndexNameExpressionResolver(Settings.EMPTY));
ClusterState cs = buildClusterState("foo");
assertFalse("already exists", autoCreateIndex.shouldAutoCreate("foo", cs));
assertTrue(autoCreateIndex.shouldAutoCreate("foobar", cs));
}
{
AutoCreateIndex autoCreateIndex = new AutoCreateIndex(Settings.builder().put("action.auto_create_index", "-foo,+b*").build(), new IndexNameExpressionResolver(Settings.EMPTY));
ClusterState cs = buildClusterState("foobar", "baz");
assertFalse(autoCreateIndex.shouldAutoCreate("foo", cs));
assertTrue(autoCreateIndex.shouldAutoCreate("bar", cs));
assertFalse("already exists", autoCreateIndex.shouldAutoCreate("baz", cs));
}
{
AutoCreateIndex autoCreateIndex = new AutoCreateIndex(Settings.builder().put("action.auto_create_index", "-foo,+b*").put("index.mapper.dynamic", false).build(), new IndexNameExpressionResolver(Settings.EMPTY));
ClusterState cs = buildClusterState("foobar", "baz");
assertFalse(autoCreateIndex.shouldAutoCreate("foo", cs));
assertFalse(autoCreateIndex.shouldAutoCreate("bar", cs));
assertFalse("already exists", autoCreateIndex.shouldAutoCreate("baz", cs));
}
{
AutoCreateIndex autoCreateIndex = new AutoCreateIndex(Settings.builder().put("action.auto_create_index", false).put("index.mapper.dynamic", false).build(), new IndexNameExpressionResolver(Settings.EMPTY));
ClusterState cs = buildClusterState("foobar", "baz");
assertFalse(autoCreateIndex.shouldAutoCreate("foo", cs));
assertFalse(autoCreateIndex.shouldAutoCreate("bar", cs));
assertFalse("already exists", autoCreateIndex.shouldAutoCreate("baz", cs));
}
}
public void testParseFailed() {
try {
new AutoCreateIndex(Settings.builder().put("action.auto_create_index", ",,,").build(), new IndexNameExpressionResolver(Settings.EMPTY));
}catch (IllegalArgumentException ex) {
assertEquals("Can't parse [,,,] for setting [action.auto_create_index] must be either [true, false, or a comma seperated list of index patterns]", ex.getMessage());
}
}
public ClusterState buildClusterState(String... indices) {
MetaData.Builder metaData = MetaData.builder();
for (String index : indices) {
metaData.put(IndexMetaData.builder(index).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1));
}
return ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).build();
}
}

View File

@ -18,15 +18,6 @@
*/
package org.elasticsearch.index;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.apache.lucene.index.AssertingDirectoryReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInvertState;
@ -70,7 +61,9 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCacheListener;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
@ -78,6 +71,14 @@ import org.elasticsearch.test.engine.MockEngineFactory;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import static java.util.Collections.emptyMap;
public class IndexModuleTests extends ESTestCase {
@ -106,9 +107,12 @@ public class IndexModuleTests extends ESTestCase {
PageCacheRecycler recycler = new PageCacheRecycler(settings, threadPool);
BigArrays bigArrays = new BigArrays(recycler, circuitBreakerService);
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndicesFieldDataCacheListener(circuitBreakerService), threadPool);
Set<ScriptEngineService> scriptEngines = new HashSet<>();
Set<ScriptEngineService> scriptEngines = Collections.emptySet();
scriptEngines.addAll(Arrays.asList(scriptEngineServices));
ScriptService scriptService = new ScriptService(settings, environment, scriptEngines, new ResourceWatcherService(settings, threadPool), new ScriptContextRegistry(Collections.emptyList()));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.emptyList());
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService = new ScriptService(settings, environment, scriptEngines, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry, scriptContextRegistry, scriptSettings);
IndicesQueriesRegistry indicesQueriesRegistry = new IndicesQueriesRegistry(settings, emptyMap());
return new NodeServicesProvider(threadPool, indicesQueryCache, null, warmer, bigArrays, client, scriptService, indicesQueriesRegistry, indicesFieldDataCache, circuitBreakerService);
}

View File

@ -39,6 +39,7 @@ import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -264,7 +265,7 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
}
public void testFsyncTaskIsRunning() throws IOException {
IndexService indexService = createIndex("test", Settings.EMPTY);
IndexService indexService = createIndex("test", Settings.builder().put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC).build());
IndexService.AsyncTranslogFSync fsyncTask = indexService.getFsyncTask();
assertNotNull(fsyncTask);
assertEquals(5000, fsyncTask.getInterval().millis());
@ -274,6 +275,9 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
indexService.close("simon says", false);
assertFalse(fsyncTask.isScheduled());
assertTrue(fsyncTask.isClosed());
indexService = createIndex("test1", Settings.EMPTY);
assertNull(indexService.getFsyncTask());
}
public void testRefreshActuallyWorks() throws Exception {
@ -307,7 +311,7 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
public void testAsyncFsyncActuallyWorks() throws Exception {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "10ms") // very often :)
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "100ms") // very often :)
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)
.build();
IndexService indexService = createIndex("test", settings);
@ -320,11 +324,43 @@ public class IndexServiceTests extends ESSingleNodeTestCase {
});
}
public void testNoFsyncTaskIfDisabled() {
public void testRescheduleAsyncFsync() throws Exception {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "100ms") // very often :)
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)
.build();
IndexService indexService = createIndex("test", settings);
ensureGreen("test");
assertNull(indexService.getFsyncTask());
IndexMetaData metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)).build();
indexService.updateMetaData(metaData);
assertNotNull(indexService.getFsyncTask());
assertTrue(indexService.getRefreshTask().mustReschedule());
client().prepareIndex("test", "test", "1").setSource("{\"foo\": \"bar\"}").get();
IndexShard shard = indexService.getShard(0);
assertBusy(() -> {
assertFalse(shard.getTranslog().syncNeeded());
});
metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)).build();
indexService.updateMetaData(metaData);
assertNull(indexService.getFsyncTask());
metaData = IndexMetaData.builder(indexService.getMetaData()).settings(Settings.builder().put(indexService.getMetaData().getSettings()).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)).build();
indexService.updateMetaData(metaData);
assertNotNull(indexService.getFsyncTask());
}
public void testIllegalFsyncInterval() {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "0ms") // disable
.build();
IndexService indexService = createIndex("test", settings);
assertNull(indexService.getFsyncTask());
try {
createIndex("test", settings);
fail();
} catch (IllegalArgumentException ex) {
assertEquals("Failed to parse value [0ms] for setting [index.translog.sync_interval] must be >= 100ms", ex.getMessage());
}
}
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.index.query;
import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
@ -88,7 +87,9 @@ import org.elasticsearch.script.MockScriptEngine;
import org.elasticsearch.script.Script.ScriptParseException;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchModule;
@ -187,7 +188,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
Settings settings = Settings.settingsBuilder()
.put("name", AbstractQueryTestCase.class.toString())
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
.build();
Settings indexSettings = Settings.settingsBuilder()
.put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
@ -214,13 +215,13 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
bindMapperExtension();
}
},
new ScriptModule(settings) {
new ScriptModule(settingsModule) {
@Override
protected void configure() {
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
// no file watching, so we don't need a ResourceWatcherService
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
.build();
MockScriptEngine mockScriptEngine = new MockScriptEngine();
Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
@ -228,9 +229,14 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
Set<ScriptEngineService> engines = new HashSet<>();
engines.add(mockScriptEngine);
List<ScriptContext.Plugin> customContexts = new ArrayList<>();
bind(ScriptContextRegistry.class).toInstance(new ScriptContextRegistry(customContexts));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES)));
bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry);
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry);
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
bind(ScriptSettings.class).toInstance(scriptSettings);
try {
ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, new ScriptContextRegistry(customContexts));
ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
bind(ScriptService.class).toInstance(scriptService);
} catch(IOException e) {
throw new IllegalStateException("error while binding ScriptService", e);

View File

@ -1393,7 +1393,6 @@ public class TranslogTests extends ESTestCase {
Path tempDir = createTempDir();
final FailSwitch fail = new FailSwitch();
TranslogConfig config = getTranslogConfig(tempDir);
assumeFalse("this won't work if we sync on any op", config.isSyncOnEachOperation());
Translog translog = getFailableTranslog(fail, config, false, true);
LineFileDocs lineFileDocs = new LineFileDocs(random()); // writes pretty big docs so we cross buffer boarders regularly
translog.add(new Translog.Index("test", "1", lineFileDocs.nextDoc().toString().getBytes(Charset.forName("UTF-8"))));

View File

@ -92,7 +92,7 @@ public class IndicesQueryCacheTests extends ESTestCase {
s.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
Settings settings = Settings.builder()
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT, 10)
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)
.build();
IndicesQueryCache cache = new IndicesQueryCache(settings);
s.setQueryCache(cache);
@ -172,7 +172,7 @@ public class IndicesQueryCacheTests extends ESTestCase {
s2.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
Settings settings = Settings.builder()
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT, 10)
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)
.build();
IndicesQueryCache cache = new IndicesQueryCache(settings);
s1.setQueryCache(cache);
@ -297,7 +297,7 @@ public class IndicesQueryCacheTests extends ESTestCase {
s2.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
Settings settings = Settings.builder()
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT, 10)
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)
.build();
IndicesQueryCache cache = new IndicesQueryCache(settings);
s1.setQueryCache(cache);

View File

@ -77,9 +77,9 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject()
.endArray()
.endObject().bytes();
client().preparePutPipeline("_id", pipelineSource)
client().admin().cluster().preparePutPipeline("_id", pipelineSource)
.get();
GetPipelineResponse getResponse = client().prepareGetPipeline("_id")
GetPipelineResponse getResponse = client().admin().cluster().prepareGetPipeline("_id")
.get();
assertThat(getResponse.isFound(), is(true));
assertThat(getResponse.pipelines().size(), equalTo(1));
@ -100,12 +100,12 @@ public class IngestClientIT extends ESIntegTestCase {
.endObject().bytes();
SimulatePipelineResponse response;
if (randomBoolean()) {
response = client().prepareSimulatePipeline(bytes)
response = client().admin().cluster().prepareSimulatePipeline(bytes)
.setId("_id").get();
} else {
SimulatePipelineRequest request = new SimulatePipelineRequest(bytes);
request.setId("_id");
response = client().simulatePipeline(request).get();
response = client().admin().cluster().simulatePipeline(request).get();
}
assertThat(response.isVerbose(), equalTo(false));
assertThat(response.getPipelineId(), equalTo("_id"));
@ -134,7 +134,7 @@ public class IngestClientIT extends ESIntegTestCase {
.endArray()
.endObject().bytes();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source);
client().putPipeline(putPipelineRequest).get();
client().admin().cluster().putPipeline(putPipelineRequest).get();
int numRequests = scaledRandomIntBetween(32, 128);
BulkRequest bulkRequest = new BulkRequest();
@ -170,10 +170,10 @@ public class IngestClientIT extends ESIntegTestCase {
.endArray()
.endObject().bytes();
PutPipelineRequest putPipelineRequest = new PutPipelineRequest("_id", source);
client().putPipeline(putPipelineRequest).get();
client().admin().cluster().putPipeline(putPipelineRequest).get();
GetPipelineRequest getPipelineRequest = new GetPipelineRequest("_id");
GetPipelineResponse getResponse = client().getPipeline(getPipelineRequest).get();
GetPipelineResponse getResponse = client().admin().cluster().getPipeline(getPipelineRequest).get();
assertThat(getResponse.isFound(), is(true));
assertThat(getResponse.pipelines().size(), equalTo(1));
assertThat(getResponse.pipelines().get(0).getId(), equalTo("_id"));
@ -192,10 +192,10 @@ public class IngestClientIT extends ESIntegTestCase {
assertThat(doc.get("processed"), equalTo(true));
DeletePipelineRequest deletePipelineRequest = new DeletePipelineRequest("_id");
WritePipelineResponse response = client().deletePipeline(deletePipelineRequest).get();
WritePipelineResponse response = client().admin().cluster().deletePipeline(deletePipelineRequest).get();
assertThat(response.isAcknowledged(), is(true));
getResponse = client().prepareGetPipeline("_id").get();
getResponse = client().admin().cluster().prepareGetPipeline("_id").get();
assertThat(getResponse.isFound(), is(false));
assertThat(getResponse.pipelines().size(), equalTo(0));
}

View File

@ -40,16 +40,19 @@ public class FileScriptTests extends ESTestCase {
settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), homeDir)
// no file watching, so we don't need a ResourceWatcherService
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
.put(settings)
.build();
Set<ScriptEngineService> engines = new HashSet<>(Collections.singletonList(new MockScriptEngine()));
return new ScriptService(settings, new Environment(settings), engines, null, new ScriptContextRegistry(Collections.emptyList()));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
return new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
}
public void testFileScriptFound() throws Exception {
Settings settings = Settings.builder()
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", false).build();
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false").build();
ScriptService scriptService = makeScriptService(settings);
Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null);
assertNotNull(scriptService.compile(script, ScriptContext.Standard.SEARCH, Collections.emptyMap()));
@ -57,11 +60,11 @@ public class FileScriptTests extends ESTestCase {
public void testAllOpsDisabled() throws Exception {
Settings settings = Settings.builder()
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", false)
.put("script.engine." + MockScriptEngine.NAME + ".file.search", false)
.put("script.engine." + MockScriptEngine.NAME + ".file.mapping", false)
.put("script.engine." + MockScriptEngine.NAME + ".file.update", false)
.put("script.engine." + MockScriptEngine.NAME + ".file.ingest", false).build();
.put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.search", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.mapping", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.update", "false")
.put("script.engine." + MockScriptEngine.NAME + ".file.ingest", "false").build();
ScriptService scriptService = makeScriptService(settings);
Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null);
for (ScriptContext context : ScriptContext.Standard.values()) {

View File

@ -50,7 +50,8 @@ public class NativeScriptTests extends ESTestCase {
.put("name", "testNativeScript")
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.build();
ScriptModule scriptModule = new ScriptModule(settings);
SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings));
ScriptModule scriptModule = new ScriptModule(settingsModule);
scriptModule.registerScript("my", MyNativeScriptFactory.class);
Injector injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)),
@ -70,10 +71,10 @@ public class NativeScriptTests extends ESTestCase {
Settings.Builder builder = Settings.settingsBuilder();
if (randomBoolean()) {
ScriptType scriptType = randomFrom(ScriptType.values());
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptType, randomFrom(ScriptMode.values()));
builder.put("script" + "." + scriptType.getScriptType(), randomFrom(ScriptMode.values()));
} else {
String scriptContext = randomFrom(ScriptContext.Standard.values()).getKey();
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptContext, randomFrom(ScriptMode.values()));
ScriptContext scriptContext = randomFrom(ScriptContext.Standard.values());
builder.put("script" + "." + scriptContext.getKey(), randomFrom(ScriptMode.values()));
}
Settings settings = builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
Environment environment = new Environment(settings);
@ -81,8 +82,10 @@ public class NativeScriptTests extends ESTestCase {
Map<String, NativeScriptFactory> nativeScriptFactoryMap = new HashMap<>();
nativeScriptFactoryMap.put("my", new MyNativeScriptFactory());
Set<ScriptEngineService> scriptEngineServices = singleton(new NativeScriptEngineService(settings, nativeScriptFactoryMap));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList<ScriptContext.Plugin>());
ScriptService scriptService = new ScriptService(settings, environment, scriptEngineServices, resourceWatcherService, scriptContextRegistry);
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, NativeScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(new ArrayList<>());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService = new ScriptService(settings, environment, scriptEngineServices, resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
for (ScriptContext scriptContext : scriptContextRegistry.scriptContexts()) {
assertThat(scriptService.compile(new Script("my", ScriptType.INLINE, NativeScriptEngineService.NAME, null), scriptContext,

View File

@ -39,16 +39,20 @@ public class ScriptContextTests extends ESTestCase {
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
// no file watching, so we don't need a ResourceWatcherService
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
.put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", false)
.put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", false)
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "off")
.put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "false")
.put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "false")
.build();
Set<ScriptEngineService> engines = new HashSet<>(Collections.singletonList(new MockScriptEngine()));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES)));
List<ScriptContext.Plugin> customContexts = Arrays.asList(
new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"),
new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"),
new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
return new ScriptService(settings, new Environment(settings), engines, null, new ScriptContextRegistry(customContexts));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
return new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
}
public void testCustomGlobalScriptContextSettings() throws Exception {

View File

@ -27,9 +27,11 @@ import org.elasticsearch.test.ESTestCase;
import org.junit.After;
import org.junit.Before;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -45,9 +47,10 @@ public class ScriptModesTests extends ESTestCase {
private static final Set<String> ALL_LANGS = unmodifiableSet(
newHashSet("custom", "test"));
static final String[] ENABLE_VALUES = new String[]{"on", "true", "yes", "1"};
static final String[] DISABLE_VALUES = new String[]{"off", "false", "no", "0"};
static final String[] ENABLE_VALUES = new String[]{"true"};
static final String[] DISABLE_VALUES = new String[]{"false"};
ScriptSettings scriptSettings;
ScriptContextRegistry scriptContextRegistry;
private ScriptContext[] scriptContexts;
private Map<String, ScriptEngineService> scriptEngines;
@ -74,6 +77,10 @@ public class ScriptModesTests extends ESTestCase {
//add the native engine just to make sure it gets filtered out
new NativeScriptEngineService(Settings.EMPTY, Collections.<String, NativeScriptFactory>emptyMap()),
new CustomScriptEngineService()));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Arrays.asList(
new ScriptEngineRegistry.ScriptEngineRegistration(NativeScriptEngineService.class, NativeScriptEngineService.TYPES),
new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.TYPES)));
scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
checkedSettings = new HashSet<>();
assertAllSettingsWereChecked = true;
assertScriptModesNonNull = true;
@ -100,14 +107,14 @@ public class ScriptModesTests extends ESTestCase {
}
public void testDefaultSettings() {
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, Settings.EMPTY);
this.scriptModes = new ScriptModes(scriptSettings, Settings.EMPTY);
assertScriptModesAllOps(ScriptMode.ON, ALL_LANGS, ScriptType.FILE);
assertScriptModesAllOps(ScriptMode.SANDBOX, ALL_LANGS, ScriptType.INDEXED, ScriptType.INLINE);
}
public void testMissingSetting() {
assertAllSettingsWereChecked = false;
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, Settings.EMPTY);
this.scriptModes = new ScriptModes(scriptSettings, Settings.EMPTY);
try {
scriptModes.getScriptMode("non_existing", randomFrom(ScriptType.values()), randomFrom(scriptContexts));
fail("Expected IllegalArgumentException");
@ -130,9 +137,9 @@ public class ScriptModesTests extends ESTestCase {
ScriptType[] randomScriptTypes = randomScriptTypesSet.toArray(new ScriptType[randomScriptTypesSet.size()]);
Settings.Builder builder = Settings.builder();
for (int i = 0; i < randomInt; i++) {
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + randomScriptTypes[i], randomScriptModes[i]);
builder.put("script" + "." + randomScriptTypes[i].getScriptType(), randomScriptModes[i]);
}
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build());
this.scriptModes = new ScriptModes(scriptSettings, builder.build());
for (int i = 0; i < randomInt; i++) {
assertScriptModesAllOps(randomScriptModes[i], ALL_LANGS, randomScriptTypes[i]);
@ -162,9 +169,9 @@ public class ScriptModesTests extends ESTestCase {
ScriptContext[] randomScriptContexts = randomScriptContextsSet.toArray(new ScriptContext[randomScriptContextsSet.size()]);
Settings.Builder builder = Settings.builder();
for (int i = 0; i < randomInt; i++) {
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + randomScriptContexts[i].getKey(), randomScriptModes[i]);
builder.put("script" + "." + randomScriptContexts[i].getKey(), randomScriptModes[i]);
}
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build());
this.scriptModes = new ScriptModes(scriptSettings, builder.build());
for (int i = 0; i < randomInt; i++) {
assertScriptModesAllTypes(randomScriptModes[i], ALL_LANGS, randomScriptContexts[i]);
@ -177,10 +184,10 @@ public class ScriptModesTests extends ESTestCase {
public void testConflictingScriptTypeAndOpGenericSettings() {
ScriptContext scriptContext = randomFrom(scriptContexts);
Settings.Builder builder = Settings.builder().put(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptContext.getKey(), randomFrom(DISABLE_VALUES))
.put("script.indexed", randomFrom(ENABLE_VALUES)).put("script.inline", ScriptMode.SANDBOX);
Settings.Builder builder = Settings.builder().put("script" + "." + scriptContext.getKey(), randomFrom(DISABLE_VALUES))
.put("script.indexed", randomFrom(ENABLE_VALUES)).put("script.inline", "sandbox");
//operations generic settings have precedence over script type generic settings
this.scriptModes = new ScriptModes(scriptEngines, scriptContextRegistry, builder.build());
this.scriptModes = new ScriptModes(scriptSettings, builder.build());
assertScriptModesAllTypes(ScriptMode.OFF, ALL_LANGS, scriptContext);
ScriptContext[] complementOf = complementOf(scriptContext);
assertScriptModes(ScriptMode.ON, ALL_LANGS, new ScriptType[]{ScriptType.FILE, ScriptType.INDEXED}, complementOf);
@ -220,14 +227,10 @@ public class ScriptModesTests extends ESTestCase {
return copy.values().toArray(new ScriptContext[copy.size()]);
}
private static String specificEngineOpSettings(String lang, ScriptType scriptType, ScriptContext scriptContext) {
return ScriptModes.ENGINE_SETTINGS_PREFIX + "." + lang + "." + scriptType + "." + scriptContext.getKey();
}
static Map<String, ScriptEngineService> buildScriptEnginesByLangMap(Set<ScriptEngineService> scriptEngines) {
Map<String, ScriptEngineService> builder = new HashMap<>();
for (ScriptEngineService scriptEngine : scriptEngines) {
for (String type : scriptEngine.types()) {
for (String type : scriptEngine.getTypes()) {
builder.put(type, scriptEngine);
}
}
@ -235,18 +238,21 @@ public class ScriptModesTests extends ESTestCase {
}
private static class CustomScriptEngineService implements ScriptEngineService {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("custom", "test"));
@Override
public String[] types() {
return new String[]{"custom", "test"};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[0];
public List<String> getExtensions() {
return Collections.singletonList(TYPES.get(0));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -31,8 +31,10 @@ import org.junit.Before;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
@ -47,7 +49,9 @@ public class ScriptServiceTests extends ESTestCase {
private ResourceWatcherService resourceWatcherService;
private ScriptEngineService scriptEngineService;
private Map<String, ScriptEngineService> scriptEnginesByLangMap;
private ScriptEngineRegistry scriptEngineRegistry;
private ScriptContextRegistry scriptContextRegistry;
private ScriptSettings scriptSettings;
private ScriptContext[] scriptContexts;
private ScriptService scriptService;
private Path scriptsFilePath;
@ -87,7 +91,9 @@ public class ScriptServiceTests extends ESTestCase {
String context = plugin + "_" + operation;
contexts.put(context, new ScriptContext.Plugin(plugin, operation));
}
scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(TestEngineService.class, TestEngineService.TYPES)));
scriptContextRegistry = new ScriptContextRegistry(contexts.values());
scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptContexts = scriptContextRegistry.scriptContexts().toArray(new ScriptContext[scriptContextRegistry.scriptContexts().size()]);
logger.info("--> setup script service");
scriptsFilePath = genericConfigFolder.resolve("scripts");
@ -97,7 +103,7 @@ public class ScriptServiceTests extends ESTestCase {
private void buildScriptService(Settings additionalSettings) throws IOException {
Settings finalSettings = Settings.builder().put(baseSettings).put(additionalSettings).build();
Environment environment = new Environment(finalSettings);
scriptService = new ScriptService(finalSettings, environment, Collections.singleton(scriptEngineService), resourceWatcherService, scriptContextRegistry) {
scriptService = new ScriptService(finalSettings, environment, Collections.singleton(scriptEngineService), resourceWatcherService, scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
@Override
String getScriptFromIndex(String scriptLang, String id) {
//mock the script that gets retrieved from an index
@ -180,10 +186,10 @@ public class ScriptServiceTests extends ESTestCase {
builder.put("script.file", randomFrom(ScriptModesTests.ENABLE_VALUES));
}
if (rarely()) {
builder.put("script.indexed", ScriptMode.SANDBOX);
builder.put("script.indexed", "sandbox");
}
if (rarely()) {
builder.put("script.inline", ScriptMode.SANDBOX);
builder.put("script.inline", "sandbox");
}
buildScriptService(builder.build());
createFileScripts("groovy", "mustache", "test");
@ -208,11 +214,11 @@ public class ScriptServiceTests extends ESTestCase {
scriptSourceSettings.put(scriptType, randomFrom(ScriptMode.values()));
}
int numScriptContextSettings = randomIntBetween(0, this.scriptContextRegistry.scriptContexts().size());
Map<String, ScriptMode> scriptContextSettings = new HashMap<>();
Map<ScriptContext, ScriptMode> scriptContextSettings = new HashMap<>();
for (int i = 0; i < numScriptContextSettings; i++) {
String scriptContext;
ScriptContext scriptContext;
do {
scriptContext = randomFrom(this.scriptContexts).getKey();
scriptContext = randomFrom(this.scriptContexts);
} while (scriptContextSettings.containsKey(scriptContext));
scriptContextSettings.put(scriptContext, randomFrom(ScriptMode.values()));
}
@ -223,7 +229,7 @@ public class ScriptServiceTests extends ESTestCase {
do {
ScriptType scriptType = randomFrom(ScriptType.values());
ScriptContext scriptContext = randomFrom(this.scriptContexts);
settingKey = scriptEngineService.types()[0] + "." + scriptType + "." + scriptContext.getKey();
settingKey = scriptEngineService.getTypes().get(0) + "." + scriptType + "." + scriptContext.getKey();
} while (engineSettings.containsKey(settingKey));
engineSettings.put(settingKey, randomFrom(ScriptMode.values()));
}
@ -232,26 +238,27 @@ public class ScriptServiceTests extends ESTestCase {
for (Map.Entry<ScriptType, ScriptMode> entry : scriptSourceSettings.entrySet()) {
switch (entry.getValue()) {
case ON:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), randomFrom(ScriptModesTests.ENABLE_VALUES));
builder.put("script" + "." + entry.getKey().getScriptType(), "true");
break;
case OFF:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), randomFrom(ScriptModesTests.DISABLE_VALUES));
builder.put("script" + "." + entry.getKey().getScriptType(), "false");
break;
case SANDBOX:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), ScriptMode.SANDBOX);
builder.put("script" + "." + entry.getKey().getScriptType(), "sandbox");
break;
}
}
for (Map.Entry<String, ScriptMode> entry : scriptContextSettings.entrySet()) {
for (Map.Entry<ScriptContext, ScriptMode> entry : scriptContextSettings.entrySet()) {
switch (entry.getValue()) {
case ON:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), randomFrom(ScriptModesTests.ENABLE_VALUES));
builder.put("script" + "." + entry.getKey().getKey(), "true");
break;
case OFF:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), randomFrom(ScriptModesTests.DISABLE_VALUES));
builder.put("script" + "." + entry.getKey().getKey(), "false");
break;
case SANDBOX:
builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + entry.getKey(), ScriptMode.SANDBOX);
builder.put("script" + "." + entry.getKey().getKey(), "sandbox");
break;
}
}
@ -260,16 +267,16 @@ public class ScriptServiceTests extends ESTestCase {
String part1 = entry.getKey().substring(0, delimiter);
String part2 = entry.getKey().substring(delimiter + 1);
String lang = randomFrom(scriptEnginesByLangMap.get(part1).types());
String lang = randomFrom(scriptEnginesByLangMap.get(part1).getTypes());
switch (entry.getValue()) {
case ON:
builder.put(ScriptModes.ENGINE_SETTINGS_PREFIX + "." + lang + "." + part2, randomFrom(ScriptModesTests.ENABLE_VALUES));
builder.put("script.engine" + "." + lang + "." + part2, "true");
break;
case OFF:
builder.put(ScriptModes.ENGINE_SETTINGS_PREFIX + "." + lang + "." + part2, randomFrom(ScriptModesTests.DISABLE_VALUES));
builder.put("script.engine" + "." + lang + "." + part2, "false");
break;
case SANDBOX:
builder.put(ScriptModes.ENGINE_SETTINGS_PREFIX + "." + lang + "." + part2, ScriptMode.SANDBOX);
builder.put("script.engine" + "." + lang + "." + part2, "sandbox");
break;
}
}
@ -283,9 +290,9 @@ public class ScriptServiceTests extends ESTestCase {
String script = scriptType == ScriptType.FILE ? "file_script" : "script";
for (ScriptContext scriptContext : this.scriptContexts) {
//fallback mechanism: 1) engine specific settings 2) op based settings 3) source based settings
ScriptMode scriptMode = engineSettings.get(scriptEngineService.types()[0] + "." + scriptType + "." + scriptContext.getKey());
ScriptMode scriptMode = engineSettings.get(scriptEngineService.getTypes().get(0) + "." + scriptType + "." + scriptContext.getKey());
if (scriptMode == null) {
scriptMode = scriptContextSettings.get(scriptContext.getKey());
scriptMode = scriptContextSettings.get(scriptContext);
}
if (scriptMode == null) {
scriptMode = scriptSourceSettings.get(scriptType);
@ -294,19 +301,19 @@ public class ScriptServiceTests extends ESTestCase {
scriptMode = DEFAULT_SCRIPT_MODES.get(scriptType);
}
for (String lang : scriptEngineService.types()) {
for (String lang : scriptEngineService.getTypes()) {
switch (scriptMode) {
case ON:
assertCompileAccepted(lang, script, scriptType, scriptContext);
assertCompileAccepted(lang, script, scriptType, scriptContext);
break;
case OFF:
assertCompileRejected(lang, script, scriptType, scriptContext);
assertCompileRejected(lang, script, scriptType, scriptContext);
break;
case SANDBOX:
if (scriptEngineService.sandboxed()) {
assertCompileAccepted(lang, script, scriptType, scriptContext);
if (scriptEngineService.isSandboxed()) {
assertCompileAccepted(lang, script, scriptType, scriptContext);
} else {
assertCompileRejected(lang, script, scriptType, scriptContext);
assertCompileRejected(lang, script, scriptType, scriptContext);
}
break;
}
@ -324,7 +331,7 @@ public class ScriptServiceTests extends ESTestCase {
unknownContext = randomAsciiOfLength(randomIntBetween(1, 30));
} while(scriptContextRegistry.isSupportedContext(new ScriptContext.Plugin(pluginName, unknownContext)));
for (String type : scriptEngineService.types()) {
for (String type : scriptEngineService.getTypes()) {
try {
scriptService.compile(new Script("test", randomFrom(ScriptType.values()), type, null), new ScriptContext.Plugin(
pluginName, unknownContext), Collections.emptyMap());
@ -395,6 +402,15 @@ public class ScriptServiceTests extends ESTestCase {
assertEquals(1L, scriptService.stats().getCacheEvictions());
}
public void testDefaultLanguage() throws IOException {
Settings.Builder builder = Settings.builder();
builder.put("script.default_lang", "test");
buildScriptService(builder.build());
CompiledScript script =
scriptService.compile(new Script("1 + 1", ScriptType.INLINE, null, null), randomFrom(scriptContexts), Collections.emptyMap());
assertEquals(script.lang(), "test");
}
private void createFileScripts(String... langs) throws IOException {
for (String lang : langs) {
Path scriptPath = scriptsFilePath.resolve("file_script." + lang);
@ -418,18 +434,22 @@ public class ScriptServiceTests extends ESTestCase {
public static class TestEngineService implements ScriptEngineService {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("test", "test2"));
public static final List<String> EXTENSIONS = Collections.unmodifiableList(Arrays.asList("test", "tst"));
@Override
public String[] types() {
return new String[] {"test", "test2"};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[] {"test", "tst"};
public List<String> getExtensions() {
return EXTENSIONS;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -0,0 +1,144 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.script;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.test.ESTestCase;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
public class ScriptSettingsTests extends ESTestCase {
public void testConflictingModesForLanguage() {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService.ScriptType scriptType = randomFrom(ScriptService.ScriptType.values());
ScriptContext scriptContext = randomFrom(ScriptContext.Standard.values());
Settings settings =
Settings
.builder()
.put(ScriptModes.getKey("test1", scriptType, scriptContext), "off")
.put(ScriptModes.getKey("test2", scriptType, scriptContext), "on")
.build();
boolean sawConflictingSettings = false;
for (Setting<ScriptMode> scriptModeSetting : scriptSettings.getScriptLanguageSettings()) {
if (scriptModeSetting.getKey().startsWith(ScriptModes.getKey("test3", scriptType, scriptContext))) {
try {
scriptModeSetting.get(settings);
fail("should have seen conflicting settings");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), anyOf(containsString("conflicting settings [{off=[test1], on=[test2]}] for language [test3]"), containsString("conflicting settings [{on=[test2], on=[test1]}] for language [test3]")));
sawConflictingSettings = true;
}
}
}
assertTrue(sawConflictingSettings);
}
public void testDefaultLanguageIsGroovy() {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
assertThat(scriptSettings.getDefaultScriptLanguageSetting().get(Settings.EMPTY), equalTo("groovy"));
}
public void testCustomDefaultLanguage() {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
String defaultLanguage = randomFrom(CustomScriptEngineService.TYPES);
Settings settings = Settings.builder().put("script.default_lang", defaultLanguage).build();
assertThat(scriptSettings.getDefaultScriptLanguageSetting().get(settings), equalTo(defaultLanguage));
}
public void testInvalidDefaultLanguage() {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(CustomScriptEngineService.class, CustomScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
Settings settings = Settings.builder().put("script.default_lang", "C++").build();
try {
scriptSettings.getDefaultScriptLanguageSetting().get(settings);
fail("should have seen unregistered default language");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("unregistered default language [C++]"));
}
}
private static class CustomScriptEngineService implements ScriptEngineService {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("test1", "test2", "test3"));
@Override
public List<String> getTypes() {
return TYPES;
}
@Override
public List<String> getExtensions() {
return Collections.singletonList(TYPES.get(0));
}
@Override
public boolean isSandboxed() {
return false;
}
@Override
public Object compile(String script, Map<String, String> params) {
return null;
}
@Override
public ExecutableScript executable(CompiledScript compiledScript, @Nullable Map<String, Object> vars) {
return null;
}
@Override
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
return null;
}
@Override
public void close() {
}
@Override
public void scriptRemoved(@Nullable CompiledScript script) {
}
}
}

View File

@ -33,6 +33,7 @@ import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService.ScriptType;
@ -55,6 +56,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -1397,7 +1399,7 @@ public class DateHistogramIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ExtractFieldScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.TYPES));
}
}
@ -1409,22 +1411,24 @@ public class DateHistogramIT extends ESIntegTestCase {
public static final String NAME = "extract_field";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -1517,7 +1521,7 @@ public class DateHistogramIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(FieldValueScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.TYPES));
}
}
@ -1529,22 +1533,24 @@ public class DateHistogramIT extends ESIntegTestCase {
public static final String NAME = "field_value";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -26,6 +26,7 @@ import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService.ScriptType;
@ -332,7 +333,7 @@ public class AvgIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ExtractFieldScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.TYPES));
}
}
@ -344,22 +345,24 @@ public class AvgIT extends AbstractNumericTestCase {
public static final String NAME = "extract_field";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -462,7 +465,7 @@ public class AvgIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(FieldValueScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.TYPES));
}
}
@ -474,22 +477,24 @@ public class AvgIT extends AbstractNumericTestCase {
public static final String NAME = "field_value";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -26,6 +26,7 @@ import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService.ScriptType;
@ -40,6 +41,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -326,7 +328,7 @@ public class SumIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ExtractFieldScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractFieldScriptEngine.class, ExtractFieldScriptEngine.TYPES));
}
}
@ -339,22 +341,24 @@ public class SumIT extends AbstractNumericTestCase {
public static final String NAME = "extract_field";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -458,7 +462,7 @@ public class SumIT extends AbstractNumericTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(FieldValueScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.TYPES));
}
}
@ -471,22 +475,24 @@ public class SumIT extends AbstractNumericTestCase {
public static final String NAME = "field_value";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -26,6 +26,7 @@ import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService.ScriptType;
@ -40,6 +41,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -221,7 +223,7 @@ public class ValueCountIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(FieldValueScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldValueScriptEngine.class, FieldValueScriptEngine.TYPES));
}
}
@ -233,22 +235,24 @@ public class ValueCountIT extends ESIntegTestCase {
public static final String NAME = "field_value";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -104,7 +104,7 @@ public class FunctionScoreBackwardCompatibilityIT extends ESBackcompatTestCase {
@Override
protected Settings commonNodeSettings(int nodeOrdinal) {
return Settings.builder().put(super.commonNodeSettings(nodeOrdinal))
.put("script.inline", "on").build();
.put("script.inline", "true").build();
}
private void checkFunctionScoreStillWorks(String... ids) throws ExecutionException, InterruptedException, IOException {

View File

@ -51,9 +51,8 @@ public class SearchAfterIT extends ESIntegTestCase {
private static final int NUM_DOCS = 100;
public void testsShouldFail() throws Exception {
client().admin().indices().prepareCreate("test").execute().actionGet();
client().prepareIndex("test", "type1", "0").setSource("field1", 0, "field2", "toto").execute().actionGet();
refresh();
createIndex("test");
indexRandom(true, client().prepareIndex("test", "type1", "0").setSource("field1", 0, "field2", "toto"));
try {
client().prepareSearch("test")

View File

@ -90,7 +90,7 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("script.indexed", "on")
.put("script.indexed", "true")
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -41,6 +41,7 @@ import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
@ -92,7 +93,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(PutFieldValuesScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PutFieldValuesScriptEngine.class, PutFieldValuesScriptEngine.TYPES));
}
}
@ -101,22 +102,24 @@ public class UpdateIT extends ESIntegTestCase {
public static final String NAME = "put_values";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -184,7 +187,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(FieldIncrementScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(FieldIncrementScriptEngine.class, FieldIncrementScriptEngine.TYPES));
}
}
@ -193,22 +196,24 @@ public class UpdateIT extends ESIntegTestCase {
public static final String NAME = "field_inc";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -269,7 +274,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ScriptedUpsertScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ScriptedUpsertScriptEngine.class, ScriptedUpsertScriptEngine.TYPES));
}
}
@ -278,22 +283,24 @@ public class UpdateIT extends ESIntegTestCase {
public static final String NAME = "scripted_upsert";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}
@ -354,7 +361,7 @@ public class UpdateIT extends ESIntegTestCase {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ExtractContextInSourceScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExtractContextInSourceScriptEngine.class, ExtractContextInSourceScriptEngine.TYPES));
}
}
@ -363,22 +370,24 @@ public class UpdateIT extends ESIntegTestCase {
public static final String NAME = "extract_ctx";
public static final List<String> TYPES = Collections.singletonList(NAME);
@Override
public void close() throws IOException {
}
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -194,7 +194,7 @@ def smoke_test_release(release, files, expected_hash, plugins):
headers = {}
print(' Starting elasticsearch deamon from [%s]' % os.path.join(tmp_dir, 'elasticsearch-%s' % release))
try:
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.script.inline=on -Des.script.indexed=on -Des.repositories.url.allowed_urls=http://snapshot.test* %s -Des.pidfile=%s'
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.script.inline=true -Des.script.indexed=true -Des.repositories.url.allowed_urls=http://snapshot.test* %s -Des.pidfile=%s'
% (java_exe(), es_run_path, '-d', os.path.join(tmp_dir, 'elasticsearch-%s' % (release), 'es-smoke.pid')))
conn = HTTPConnection(host='127.0.0.1', port=9200, timeout=20)
if not wait_for_node_startup(header=headers):

View File

@ -88,13 +88,15 @@ You must enclose date math index name expressions within angle brackets. For exa
[source,js]
----------------------------------------------------------------------
curl -XGET 'localhost:9200/<logstash-{now/d-2d}>/_search' {
curl -XGET 'localhost:9200/<logstash-{now%2Fd-2d}>/_search' {
"query" : {
...
}
}
----------------------------------------------------------------------
NOTE: The `/` used for date rounding must be url encoded as `%2F` in any url.
The following example shows different forms of date math index names and the final index names
they resolve to given the current time is 22rd March 2024 noon utc.
@ -119,7 +121,7 @@ three days, assuming the indices use the default Logstash index name format,
[source,js]
----------------------------------------------------------------------
curl -XGET 'localhost:9200/<logstash-{now/d-2d}>,<logstash-{now/d-1d}>,<logstash-{now/d}>/_search' {
curl -XGET 'localhost:9200/<logstash-{now%2Fd-2d}>,<logstash-{now%2Fd-1d}>,<logstash-{now%2Fd}>/_search' {
"query" : {
...
}

View File

@ -37,8 +37,8 @@ The data in the transaction log is only persisted to disk when the translog is
++fsync++ed and committed. In the event of hardware failure, any data written
since the previous translog commit will be lost.
By default, Elasticsearch ++fsync++s and commits the translog every 5 seconds
and at the end of every <<docs-index_,index>>, <<docs-delete,delete>>,
By default, Elasticsearch ++fsync++s and commits the translog every 5 seconds if `index.translog.durability` is set
to `async` or if set to `request` (default) at the end of every <<docs-index_,index>>, <<docs-delete,delete>>,
<<docs-update,update>>, or <<docs-bulk,bulk>> request. In fact, Elasticsearch
will only report success of an index, delete, update, or bulk request to the
client after the transaction log has been successfully ++fsync++ed and committed
@ -50,7 +50,7 @@ control the behaviour of the transaction log:
`index.translog.sync_interval`::
How often the translog is ++fsync++ed to disk and committed, regardless of
write operations. Defaults to `5s`.
write operations. Defaults to `5s`. Values less than `100ms` are not allowed.
`index.translog.durability`::
+

View File

@ -17,6 +17,7 @@ your application to Elasticsearch 3.0.
* <<breaking_30_allocation>>
* <<breaking_30_percolator>>
* <<breaking_30_packaging>>
* <<breaking_30_scripting>>
[[breaking_30_search_changes]]
=== Warmers
@ -232,6 +233,10 @@ The `index.translog.flush_threshold_ops` setting is not supported anymore. In or
growth use `index.translog.flush_threshold_size` instead. Changing the translog type with `index.translog.fs.type` is not supported
anymore, the `buffered` implementation is now the only available option and uses a fixed `8kb` buffer.
The translog by default is fsynced on a request basis such that the ability to fsync on every operation is not necessary anymore. In-fact it can
be a performance bottleneck and it's trappy since it enabled by a special value set on `index.translog.sync_interval`. `index.translog.sync_interval`
now doesn't accept a value less than `100ms` which prevents fsyncing too often if async durability is enabled. The special value `0` is not supported anymore.
==== Request Cache Settings
The deprecated settings `index.cache.query.enable` and `indices.cache.query.size` have been removed and are replaced with
@ -684,3 +689,15 @@ and these error messages would be lost to the nether. The default has
changed to now route standard output to the journal and standard error
to inherit this setting (these are the defaults for systemd). These
settings can be modified by editing the elasticsearch.service file.
[[breaking_30_scripting]]
=== Scripting
==== Script mode settings
Previously script mode settings (e.g., "script.inline: true",
"script.engine.groovy.inline.aggs: false", etc.) accepted the values
`on`, `true`, `1`, and `yes` for enabling a scripting mode, and the
values `off`, `false`, `0`, and `no` for disabling a scripting mode.
The variants `on`, `1`, and `yes ` for enabling and `off`, `0`,
and `no` for disabling are no longer supported.

View File

@ -244,8 +244,8 @@ every script engine, through the following settings that need to be added to the
[source,yaml]
-----------------------------------
script.inline: on
script.indexed: on
script.inline: true
script.indexed: true
-----------------------------------
@ -261,8 +261,8 @@ script settings:
[cols="<,<",options="header",]
|=======================================================================
|Value |Description
| `off` |scripting is turned off completely, in the context of the setting being set.
| `on` |scripting is turned on, in the context of the setting being set.
| `false` |scripting is turned off completely, in the context of the setting being set.
| `true` |scripting is turned on, in the context of the setting being set.
| `sandbox` |scripts may be executed only for languages that are sandboxed
|=======================================================================
@ -272,7 +272,7 @@ The default values are the following:
-----------------------------------
script.inline: sandbox
script.indexed: sandbox
script.file: on
script.file: true
-----------------------------------
@ -305,8 +305,8 @@ and plugins execution though, as the above defaults still get applied.
[source,yaml]
-----------------------------------
script.update: off
script.mapping: off
script.update: false
script.mapping: false
-----------------------------------
@ -317,21 +317,21 @@ precedence over any other generic settings.
[source,yaml]
-----------------------------------
script.engine.groovy.file.aggs: on
script.engine.groovy.file.mapping: on
script.engine.groovy.file.search: on
script.engine.groovy.file.update: on
script.engine.groovy.file.plugin: on
script.engine.groovy.indexed.aggs: on
script.engine.groovy.indexed.mapping: off
script.engine.groovy.indexed.search: on
script.engine.groovy.indexed.update: off
script.engine.groovy.indexed.plugin: off
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.mapping: off
script.engine.groovy.inline.search: off
script.engine.groovy.inline.update: off
script.engine.groovy.inline.plugin: off
script.engine.groovy.file.aggs: true
script.engine.groovy.file.mapping: true
script.engine.groovy.file.search: true
script.engine.groovy.file.update: true
script.engine.groovy.file.plugin: true
script.engine.groovy.indexed.aggs: true
script.engine.groovy.indexed.mapping: false
script.engine.groovy.indexed.search: true
script.engine.groovy.indexed.update: false
script.engine.groovy.indexed.plugin: false
script.engine.groovy.inline.aggs: true
script.engine.groovy.inline.mapping: false
script.engine.groovy.inline.search: false
script.engine.groovy.inline.update: false
script.engine.groovy.inline.plugin: false
-----------------------------------

View File

@ -20,10 +20,11 @@
package org.elasticsearch.script.expression;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
public class ExpressionPlugin extends Plugin {
@Override
public String name() {
return "lang-expression";
@ -35,6 +36,6 @@ public class ExpressionPlugin extends Plugin {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(ExpressionScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(ExpressionScriptEngineService.class, ExpressionScriptEngineService.TYPES));
}
}

View File

@ -50,6 +50,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
@ -60,6 +62,8 @@ public class ExpressionScriptEngineService extends AbstractComponent implements
public static final String NAME = "expression";
public static final List<String> TYPES = Collections.singletonList(NAME);
protected static final String GET_YEAR_METHOD = "getYear";
protected static final String GET_MONTH_METHOD = "getMonth";
protected static final String GET_DAY_OF_MONTH_METHOD = "getDayOfMonth";
@ -80,17 +84,17 @@ public class ExpressionScriptEngineService extends AbstractComponent implements
}
@Override
public String[] types() {
return new String[]{NAME};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[]{NAME};
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -39,10 +39,9 @@ public class IndexedExpressionTests extends ESIntegTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
builder.put("script.engine.expression.indexed.update", "off");
builder.put("script.engine.expression.indexed.search", "off");
builder.put("script.engine.expression.indexed.aggs", "off");
builder.put("script.engine.expression.indexed.mapping", "off");
builder.put("script.engine.expression.indexed.update", "false");
builder.put("script.engine.expression.indexed.search", "false");
builder.put("script.engine.expression.indexed.mapping", "false");
return builder.build();
}

View File

@ -28,8 +28,8 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.script.groovy;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
public class GroovyPlugin extends Plugin {
@ -35,6 +36,6 @@ public class GroovyPlugin extends Plugin {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(GroovyScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(GroovyScriptEngineService.class, GroovyScriptEngineService.TYPES));
}
}

View File

@ -19,15 +19,10 @@
package org.elasticsearch.script.groovy;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
import groovy.lang.Script;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Scorer;
import org.codehaus.groovy.ast.ClassCodeExpressionTransformer;
@ -60,10 +55,16 @@ import org.elasticsearch.script.SearchScript;
import org.elasticsearch.search.lookup.LeafSearchLookup;
import org.elasticsearch.search.lookup.SearchLookup;
import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
import groovy.lang.Script;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides the infrastructure for Groovy as a scripting language for Elasticsearch
@ -74,6 +75,8 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
* The name of the scripting engine/language.
*/
public static final String NAME = "groovy";
public static final List<String> TYPES = Collections.singletonList(NAME);
/**
* The name of the Groovy compiler setting to use associated with activating <code>invokedynamic</code> support.
*/
@ -158,17 +161,17 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
}
@Override
public String[] types() {
return new String[]{NAME};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[]{NAME};
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -60,14 +60,13 @@ public class IndexedScriptTests extends ESIntegTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
builder.put("script.engine.groovy.indexed.update", "off");
builder.put("script.engine.groovy.indexed.search", "on");
builder.put("script.engine.groovy.indexed.aggs", "on");
builder.put("script.engine.groovy.inline.aggs", "off");
builder.put("script.engine.expression.indexed.update", "off");
builder.put("script.engine.expression.indexed.search", "off");
builder.put("script.engine.expression.indexed.aggs", "off");
builder.put("script.engine.expression.indexed.mapping", "off");
builder.put("script.engine.groovy.indexed.update", "false");
builder.put("script.engine.groovy.indexed.search", "true");
builder.put("script.engine.groovy.indexed.aggs", "true");
builder.put("script.engine.groovy.inline.aggs", "false");
builder.put("script.engine.expression.indexed.update", "false");
builder.put("script.engine.expression.indexed.search", "false");
builder.put("script.engine.expression.indexed.mapping", "false");
return builder.build();
}

View File

@ -28,7 +28,7 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.script.mustache;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
public class MustachePlugin extends Plugin {
@ -35,6 +36,6 @@ public class MustachePlugin extends Plugin {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(MustacheScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES));
}
}

View File

@ -18,13 +18,8 @@
*/
package org.elasticsearch.script.mustache;
import java.lang.ref.SoftReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.io.Reader;
import java.util.Map;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.AbstractComponent;
@ -40,8 +35,13 @@ import org.elasticsearch.script.ScriptException;
import org.elasticsearch.script.SearchScript;
import org.elasticsearch.search.lookup.SearchLookup;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.DefaultMustacheFactory;
import java.io.Reader;
import java.lang.ref.SoftReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Main entry point handling template registration, compilation and
@ -54,6 +54,9 @@ import com.github.mustachejava.DefaultMustacheFactory;
public final class MustacheScriptEngineService extends AbstractComponent implements ScriptEngineService {
public static final String NAME = "mustache";
public static final List<String> TYPES = Collections.singletonList(NAME);
static final String CONTENT_TYPE_PARAM = "content_type";
static final String JSON_CONTENT_TYPE = "application/json";
static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain";
@ -109,17 +112,17 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
}
@Override
public String[] types() {
return new String[] {NAME};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[] {NAME};
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -18,10 +18,6 @@
*/
package org.elasticsearch.messy.tests;
import java.io.IOException;
import java.lang.reflect.Proxy;
import java.util.Collections;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Accountable;
@ -62,6 +58,7 @@ import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
@ -74,6 +71,10 @@ import org.elasticsearch.threadpool.ThreadPoolModule;
import org.junit.After;
import org.junit.Before;
import java.io.IOException;
import java.lang.reflect.Proxy;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
/**
@ -100,10 +101,10 @@ public class TemplateQueryParserTests extends ESTestCase {
});
Index index = new Index("test");
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, settings);
ScriptModule scriptModule = new ScriptModule(settings);
// TODO: make this use a mock engine instead of mustache and it will no longer be messy!
scriptModule.addScriptEngine(MustacheScriptEngineService.class);
SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings));
ScriptModule scriptModule = new ScriptModule(settingsModule);
// TODO: make this use a mock engine instead of mustache and it will no longer be messy!
scriptModule.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES));
settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED);
injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)),

View File

@ -28,7 +28,7 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.plugin.javascript;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.javascript.JavaScriptScriptEngineService;
@ -44,6 +45,6 @@ public class JavaScriptPlugin extends Plugin {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(JavaScriptScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(JavaScriptScriptEngineService.class, JavaScriptScriptEngineService.TYPES));
}
}

View File

@ -19,18 +19,6 @@
package org.elasticsearch.script.javascript;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Scorer;
import org.elasticsearch.SpecialPermission;
@ -61,11 +49,27 @@ import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.SecurityController;
import org.mozilla.javascript.WrapFactory;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
/**
*
*/
public class JavaScriptScriptEngineService extends AbstractComponent implements ScriptEngineService {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("js", "javascript"));
private final AtomicLong counter = new AtomicLong();
private static WrapFactory wrapFactory = new CustomWrapFactory();
@ -155,17 +159,17 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements
}
@Override
public String[] types() {
return new String[]{"js", "javascript"};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[]{"js"};
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("js"));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.plan.a;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
public final class PlanAPlugin extends Plugin {
@ -35,6 +36,6 @@ public final class PlanAPlugin extends Plugin {
}
public void onModule(final ScriptModule module) {
module.addScriptEngine(PlanAScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PlanAScriptEngineService.class, PlanAScriptEngineService.TYPES));
}
}

View File

@ -37,7 +37,9 @@ import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -50,6 +52,8 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
*/
public static final String NAME = "plan-a";
public static final List<String> TYPES = Collections.singletonList(NAME);
/**
* Default compiler settings to be used.
*/
@ -97,8 +101,8 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always contains only the single name of the language.
*/
@Override
public String[] types() {
return new String[] { NAME };
public List<String> getTypes() {
return TYPES;
}
/**
@ -106,8 +110,8 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always contains only the single extension of the language.
*/
@Override
public String[] extensions() {
return new String[] { NAME };
public List<String> getExtensions() {
return TYPES;
}
/**
@ -115,7 +119,7 @@ public class PlanAScriptEngineService extends AbstractComponent implements Scrip
* @return Always true as the engine should be secure at runtime.
*/
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -28,8 +28,8 @@ dependencies {
integTest {
cluster {
systemProperty 'es.script.inline', 'on'
systemProperty 'es.script.indexed', 'on'
systemProperty 'es.script.inline', 'true'
systemProperty 'es.script.indexed', 'true'
}
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.plugin.python;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.python.PythonScriptEngineService;
@ -39,6 +40,6 @@ public class PythonPlugin extends Plugin {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(PythonScriptEngineService.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(PythonScriptEngineService.class, PythonScriptEngineService.TYPES));
}
}

View File

@ -47,6 +47,9 @@ import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
@ -55,6 +58,8 @@ import java.util.Map;
//TODO we can optimize the case for Map<String, Object> similar to PyStringMap
public class PythonScriptEngineService extends AbstractComponent implements ScriptEngineService {
public static final List<String> TYPES = Collections.unmodifiableList(Arrays.asList("py", "python"));
private final PythonInterpreter interp;
@Inject
@ -91,17 +96,17 @@ public class PythonScriptEngineService extends AbstractComponent implements Scri
}
@Override
public String[] types() {
return new String[]{"python", "py"};
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return new String[]{"py"};
public List<String> getExtensions() {
return Collections.unmodifiableList(Arrays.asList("py"));
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return false;
}

View File

@ -91,7 +91,7 @@ public class TribeUnitTests extends ESTestCase {
System.setProperty("es.tribe.t2.discovery.id.seed", Long.toString(random().nextLong()));
try {
assertTribeNodeSuccesfullyCreated(Settings.EMPTY);
assertTribeNodeSuccessfullyCreated(Settings.EMPTY);
} finally {
System.clearProperty("es.cluster.name");
System.clearProperty("es.tribe.t1.cluster.name");
@ -108,10 +108,10 @@ public class TribeUnitTests extends ESTestCase {
.put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true)
.put(Environment.PATH_CONF_SETTING.getKey(), pathConf)
.build();
assertTribeNodeSuccesfullyCreated(settings);
assertTribeNodeSuccessfullyCreated(settings);
}
private static void assertTribeNodeSuccesfullyCreated(Settings extraSettings) throws Exception {
private static void assertTribeNodeSuccessfullyCreated(Settings extraSettings) throws Exception {
//tribe node doesn't need the node.mode setting, as it's forced local internally anyways. The tribe clients do need it to make sure
//they can find their corresponding tribes using the proper transport
Settings settings = Settings.builder().put("http.enabled", false).put("node.name", "tribe_node")

View File

@ -21,10 +21,11 @@ package org.elasticsearch.ingest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.ingest.InternalTemplateService;
import org.elasticsearch.ingest.core.TemplateService;
import org.elasticsearch.script.ScriptContextRegistry;
import org.elasticsearch.script.ScriptEngineRegistry;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptSettings;
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
@ -39,13 +40,15 @@ public abstract class AbstractMustacheTests extends ESTestCase {
public void init() throws Exception {
Settings settings = Settings.builder()
.put("path.home", createTempDir())
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, false)
.put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
.build();
MustacheScriptEngineService mustache = new MustacheScriptEngineService(settings);
ScriptContextRegistry registry = new ScriptContextRegistry(Collections.emptyList());
ScriptService scriptService = new ScriptService(
settings, new Environment(settings), Collections.singleton(mustache), null, registry
);
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES)));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService =
new ScriptService(settings, new Environment(settings), Collections.singleton(mustache), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
templateService = new InternalTemplateService(scriptService);
}

View File

@ -26,14 +26,19 @@ import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* A dummy script engine used for testing. Scripts must be a number. Running the script
*/
public class MockScriptEngine implements ScriptEngineService {
public static final String NAME = "mockscript";
public static final List<String> TYPES = Collections.singletonList(NAME);
public static class TestPlugin extends Plugin {
public TestPlugin() {
@ -50,23 +55,23 @@ public class MockScriptEngine implements ScriptEngineService {
}
public void onModule(ScriptModule module) {
module.addScriptEngine(MockScriptEngine.class);
module.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES));
}
}
@Override
public String[] types() {
return new String[]{ NAME };
public List<String> getTypes() {
return TYPES;
}
@Override
public String[] extensions() {
return types();
public List<String> getExtensions() {
return TYPES;
}
@Override
public boolean sandboxed() {
public boolean isSandboxed() {
return true;
}

View File

@ -527,11 +527,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
}
if (random.nextBoolean()) {
if (rarely(random)) {
builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), 0); // 0 has special meaning to sync each op
} else {
builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), RandomInts.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
}
builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), RandomInts.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
}
return builder;
@ -1682,8 +1678,8 @@ public abstract class ESIntegTestCase extends ESTestCase {
// from failing on nodes without enough disk space
.put(DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b")
.put(DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b")
.put("script.indexed", "on")
.put("script.inline", "on")
.put("script.indexed", "true")
.put("script.inline", "true")
// wait short time for other active shards before actually deleting, default 30s not needed in tests
.put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT.getKey(), new TimeValue(1, TimeUnit.SECONDS));
return builder.build();

View File

@ -166,8 +166,8 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
.put("node.name", nodeName())
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("script.inline", "on")
.put("script.indexed", "on")
.put("script.inline", "true")
.put("script.indexed", "true")
.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created
.put("http.enabled", false)
.put(Node.NODE_LOCAL_SETTING.getKey(), true)

View File

@ -451,7 +451,7 @@ public final class InternalTestCluster extends TestCluster {
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), RandomInts.randomIntBetween(random, 0, 2000));
}
if (random.nextBoolean()) {
builder.put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING, TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 750, 10000000)));
builder.put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getKey(), TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 750, 10000000)));
}
// always default delayed allocation to 0 to make sure we have tests are not delayed