This is the xpack side of elastic/elasticsearch#24627


Original commit: elastic/x-pack-elasticsearch@4d1c745d74
This commit is contained in:
Ryan Ernst 2017-05-17 14:42:46 -07:00 committed by GitHub
parent 0059180d78
commit f7705eac86
17 changed files with 16 additions and 54 deletions

View File

@ -72,7 +72,7 @@ file:
--------------------------------------------------
"condition" : {
"script" : {
"file" : "my_script"
"id" : "my_script"
}
}
--------------------------------------------------
@ -84,7 +84,7 @@ script language and parameters:
--------------------------------------------------
"condition" : {
"script" : {
"file" : "my_script",
"id" : "my_script",
"lang" : "javascript",
"params" : {
"result" : true

View File

@ -116,7 +116,7 @@ you can then reference it by name in the watch condition.
--------------------------------------------------
"condition" : {
"script" : {
"file" : "threshold_hits",
"id" : "threshold_hits",
"params" : {
"threshold" : 0 <1>
}
@ -181,7 +181,7 @@ PUT _xpack/watcher/watch/rss_watch
},
"condition" : {
"script" : {
"file" : "threshold_hits",
"id" : "threshold_hits",
"params" : {
"threshold" : 0
}
@ -204,7 +204,7 @@ PUT _xpack/watcher/watch/rss_watch
}
--------------------------------------------------
// CONSOLE
// TEST[s/"file" : "threshold_hits"/"inline": "return ctx.payload.hits.total > params.threshold"/]
// TEST[s/"id" : "threshold_hits"/"inline": "return ctx.payload.hits.total > params.threshold"/]
<1> Replace `<username>@<domainname>` with your email address to receive
notifications.

View File

@ -458,7 +458,7 @@ references the script file `threshold_hits.painless`:
--------------------------------------------------
"condition" : {
"script" : {
"file" : "threshold_hits",
"id" : "threshold_hits",
"params" : {
"threshold" : 0
}

View File

@ -38,11 +38,6 @@ public class LatchScriptEngine implements ScriptEngine {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String scriptName, String scriptSource, Map<String, String> params) {
return scriptSource;

View File

@ -38,11 +38,6 @@ public class MockMustacheScriptEngine extends MockScriptEngine {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String name, String script, Map<String, String> params) {
if (script.contains("{{") && script.contains("}}")) {

View File

@ -102,9 +102,6 @@ public class TextTemplateTests extends ESTestCase {
case INLINE:
builder.field("inline", template.getTemplate());
break;
case FILE:
builder.field("file", template.getTemplate());
break;
case STORED:
builder.field("stored", template.getTemplate());
}

View File

@ -38,11 +38,6 @@ public class MockPainlessScriptEngine extends MockScriptEngine {
return NAME;
}
@Override
public String getExtension() {
return NAME;
}
@Override
public Object compile(String name, String script, Map<String, String> params) {
// We always return the script's source as it is

View File

@ -92,11 +92,8 @@ public class ScriptConditionTests extends ESTestCase {
ScriptContextRegistry contextRegistry = new ScriptContextRegistry(singleton(new ScriptContext.Plugin("xpack", "watch")));
ScriptSettings scriptSettings = new ScriptSettings(registry, contextRegistry);
Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.build();
scriptService = new ScriptService(settings, new Environment(settings), null, registry, contextRegistry, scriptSettings);
scriptService = new ScriptService(Settings.EMPTY, registry, contextRegistry, scriptSettings);
ClusterState.Builder clusterState = new ClusterState.Builder(new ClusterName("_name"));
clusterState.metaData(MetaData.builder().putCustom(ScriptMetaData.TYPE, new ScriptMetaData.Builder(null).build()));
ClusterState cs = clusterState.build();
@ -152,7 +149,7 @@ public class ScriptConditionTests extends ESTestCase {
fail("expected a condition exception trying to parse an invalid condition XContent");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(),
containsString("must specify either code for an [inline] script or an id for a [stored] script or [file] script"));
containsString("must specify either code for an [inline] script or an id for a [stored] script"));
}
}
@ -165,10 +162,6 @@ public class ScriptConditionTests extends ESTestCase {
expectedException = ResourceNotFoundException.class;
script = "nonExisting_script";
break;
case FILE:
expectedException = IllegalArgumentException.class;
script = "nonExisting_script";
break;
default:
expectedException = GeneralScriptException.class;
script = "foo = = 1";
@ -228,9 +221,6 @@ public class ScriptConditionTests extends ESTestCase {
case INLINE:
builder.field("inline", script);
break;
case FILE:
builder.field("file", script);
break;
case STORED:
builder.field("stored", script);
break;

View File

@ -24,7 +24,7 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase {
}
public void testFromXContentWithTemplateCustomLang() throws IOException {
String source = "{\"template\":{\"file\":\"custom-script\", \"lang\":\"painful\",\"params\":{\"bar\":\"baz\"}}}";
String source = "{\"template\":{\"inline\":\"custom-script\", \"lang\":\"painful\",\"params\":{\"bar\":\"baz\"}}}";
assertTemplate(source, "custom-script", "painful", singletonMap("bar", "baz"));
}

View File

@ -248,8 +248,7 @@ public final class WatcherTestUtils {
ScriptEngineRegistry scriptEngineRegistry =
new ScriptEngineRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
return new ScriptService(settings, new Environment(settings), new ResourceWatcherService(settings, tp),
scriptEngineRegistry, scriptContextRegistry, scriptSettings);
return new ScriptService(settings, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
}
public static SearchType getRandomSupportedSearchType() {

View File

@ -192,7 +192,7 @@ public class SearchTransformTests extends ESIntegTestCase {
builder.field("search_type", searchType.name());
}
if (templateName != null) {
TextTemplate template = new TextTemplate(templateName, null, ScriptType.FILE, null);
TextTemplate template = new TextTemplate(templateName, null, ScriptType.INLINE, null);
builder.field("template", template);
}
@ -228,7 +228,7 @@ public class SearchTransformTests extends ESIntegTestCase {
}
if (templateName != null) {
assertThat(executable.transform().getRequest().getTemplate(),
equalTo(new Script(ScriptType.FILE, "mustache", "template1", Collections.emptyMap())));
equalTo(new Script(ScriptType.INLINE, "mustache", "template1", Collections.emptyMap())));
}
assertThat(executable.transform().getRequest().getSearchSource().utf8ToString(), equalTo("{\"query\":{\"match_all\":{}}}"));
assertThat(executable.transform().getTimeout(), equalTo(readTimeout));

View File

@ -130,7 +130,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
if (randomBoolean()) {
logger.info("testing script transform with an inline script");
script = mockScript("['key3' : ctx.payload.key1 + ctx.payload.key2]");
} else if (randomBoolean()) {
} else {
logger.info("testing script transform with an indexed script");
assertAcked(client().admin().cluster().preparePutStoredScript()
.setId("my-script")
@ -138,9 +138,6 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
.setContent(new BytesArray("{\"script\" : \"['key3' : ctx.payload.key1 + ctx.payload.key2]\"}"), XContentType.JSON)
.get());
script = new Script(ScriptType.STORED, "mockscript", "my-script", Collections.emptyMap());
} else {
logger.info("testing script transform with a file script");
script = new Script(ScriptType.FILE, "mockscript", "my-script", Collections.emptyMap());
}
// put a watch that has watch level transform:

View File

@ -213,7 +213,6 @@ public class ScriptTransformTests extends ESTestCase {
static String scriptTypeField(ScriptType type) {
switch (type) {
case INLINE: return "inline";
case FILE: return "file";
case STORED: return "stored";
default:
throw illegalArgument("unsupported script type [{}]", type);

View File

@ -11,7 +11,6 @@ integTestCluster {
plugin ':x-pack-elasticsearch:plugin'
setting 'xpack.watcher.enabled', 'false'
setting 'xpack.monitoring.enabled', 'false'
setting 'path.scripts', "${project.buildDir}/resources/test/templates"
setupCommand 'setupDummyUser',
'bin/x-pack/users', 'useradd', 'test_admin', '-p', 'changeme', '-r', 'superuser'
waitCondition = { node, ant ->

View File

@ -111,7 +111,7 @@ setup:
"privileges": ["all"],
"query" : {
"template" : {
"file" : "query"
"id" : "query"
}
}
}

View File

@ -111,7 +111,7 @@ setup:
"privileges": ["all"],
"query" : {
"template" : {
"file" : "query"
"id" : "query"
}
}
}

View File

@ -41,17 +41,13 @@ public class WatcherTemplateIT extends ESTestCase {
@Before
public void init() throws Exception {
Settings setting = Settings.builder().put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, true).build();
Environment environment = Mockito.mock(Environment.class);
ResourceWatcherService resourceWatcherService = Mockito.mock(ResourceWatcherService.class);
ScriptContextRegistry registry = new ScriptContextRegistry(Collections.singletonList(new ScriptContext.Plugin("xpack", "watch")));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(
Collections.singleton(new MustacheScriptEngine())
);
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry);
ScriptService scriptService = new ScriptService(setting, environment, resourceWatcherService, scriptEngineRegistry,
registry, scriptSettings);
ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptEngineRegistry, registry, scriptSettings);
engine = new TextTemplateEngine(Settings.EMPTY, scriptService);
}