use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.
the class ExecTest method testRemoteMapReduceWithStreams.
@Test(enabled = false, dataProvider = "CacheModeProvider", description = "Disabling this test until the distributed scripts in DIST mode are fixed - ISPN-6173")
public void testRemoteMapReduceWithStreams(CacheMode cacheMode) throws Exception {
String cacheName = "testRemoteMapReduce_Streams_dist_" + cacheMode.toString();
ConfigurationBuilder builder = getDefaultClusteredCacheConfig(cacheMode, true);
builder.encoding().key().mediaType(APPLICATION_OBJECT_TYPE);
builder.encoding().value().mediaType(APPLICATION_OBJECT_TYPE);
defineInAll(cacheName, builder);
waitForClusterToForm(cacheName);
RemoteCache<String, String> cache = clients.get(0).getCache(cacheName);
ScriptingUtils.loadData(cache, "/macbeth.txt");
ScriptingManager scriptingManager = manager(0).getGlobalComponentRegistry().getComponent(ScriptingManager.class);
loadScript("/wordCountStream_dist.js", scriptingManager, "wordCountStream_dist.js");
ArrayList<Map<String, Long>> results = cache.execute("wordCountStream_dist.js", new HashMap<String, String>());
assertEquals(2, results.size());
assertEquals(3202, results.get(0).size());
assertEquals(3202, results.get(1).size());
assertTrue(results.get(0).get("macbeth").equals(287L));
assertTrue(results.get(1).get("macbeth").equals(287L));
}
use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.
the class HotRodClientTestingUtil method withScript.
public static void withScript(EmbeddedCacheManager cm, String scriptPath, Consumer<String> f) {
ScriptingManager scriptingManager = cm.getGlobalComponentRegistry().getComponent(ScriptingManager.class);
String scriptName = scriptPath.replaceAll("\\/", "");
try {
loadScript(scriptName, scriptingManager, scriptPath);
f.accept(scriptName);
} finally {
scriptingManager.removeScript(scriptName);
}
}
use of org.infinispan.scripting.ScriptingManager in project infinispan by infinispan.
the class TasksResource method createScriptTask.
private CompletionStage<RestResponse> createScriptTask(RestRequest request) {
String taskName = request.variables().get("taskName");
EmbeddedCacheManager cacheManager = invocationHelper.getRestCacheManager().getInstance().withSubject(request.getSubject());
ScriptingManager scriptingManager = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(ScriptingManager.class);
NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
ContentSource contents = request.contents();
byte[] bytes = contents.rawContent();
MediaType sourceType = request.contentType() == null ? APPLICATION_JAVASCRIPT : request.contentType();
String script = StandardConversions.convertTextToObject(bytes, sourceType);
return CompletableFuture.supplyAsync(() -> {
Subject.doAs(request.getSubject(), (PrivilegedAction<Void>) () -> {
scriptingManager.addScript(taskName, script);
return null;
});
return builder.build();
}, invocationHelper.getExecutor());
}
Aggregations