use of org.infinispan.tasks.TaskContext in project infinispan by infinispan.
the class DistributedServerTask method prepareContext.
private TaskContext prepareContext(EmbeddedCacheManager embeddedCacheManager, Cache<Object, Object> cache, Marshaller marshaller) {
TaskContext context = new TaskContext();
context.cacheManager(embeddedCacheManager);
Map<String, String> params = parameters.stream().collect(Collectors.toMap(p -> p.key, p -> p.value));
context.parameters(params);
MediaType type = MediaType.APPLICATION_OBJECT;
if (cache != null)
context.cache(cache.getAdvancedCache().withMediaType(type, type));
if (marshaller != null)
context.marshaller(marshaller);
return context;
}
use of org.infinispan.tasks.TaskContext in project infinispan by infinispan.
the class TaskRequestProcessor method exec.
public void exec(HotRodHeader header, Subject subject, String taskName, Map<String, byte[]> taskParams) {
TaskContext taskContext = new TaskContext().parameters(taskParams).subject(subject);
if (!header.cacheName.isEmpty() || server.hasDefaultCache()) {
AdvancedCache<byte[], byte[]> cache = server.cache(server.getCacheInfo(header), header, subject);
taskContext.cache(cache);
}
taskManager.runTask(taskName, taskContext).whenComplete((result, throwable) -> handleExec(header, result, throwable));
}
use of org.infinispan.tasks.TaskContext in project infinispan by infinispan.
the class SecureScriptingTaskManagerTest method testTask.
public void testTask() throws Exception {
Security.doAs(PHEIDIPPIDES, new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
String result = CompletionStages.join(taskManager.runTask(SCRIPT_NAME, new TaskContext().addParameter("a", "a")));
assertEquals("a", result);
return null;
}
});
List<Task> tasks = taskManager.getTasks();
assertEquals(1, tasks.size());
ScriptTask scriptTask = (ScriptTask) tasks.get(0);
assertEquals(SCRIPT_NAME, scriptTask.getName());
assertEquals(TaskExecutionMode.ONE_NODE, scriptTask.getExecutionMode());
assertEquals("Script", scriptTask.getType());
}
use of org.infinispan.tasks.TaskContext in project infinispan by infinispan.
the class SecureScriptingTest method testSimpleScriptWithEXECPermissionsRightRole.
public void testSimpleScriptWithEXECPermissionsRightRole() throws Exception {
String result = Security.doAs(PHEIDIPPIDES, (PrivilegedExceptionAction<String>) () -> CompletionStages.join(scriptingManager.runScript("testRole.js", new TaskContext().addParameter("a", "a"))));
assertEquals("a", result);
}
use of org.infinispan.tasks.TaskContext in project infinispan by infinispan.
the class SecureScriptingTest method testSimpleScriptWithEXECPermissionsWrongRole.
@Test(expectedExceptions = PrivilegedActionException.class)
public void testSimpleScriptWithEXECPermissionsWrongRole() throws Exception {
String result = Security.doAs(RUNNER, (PrivilegedExceptionAction<String>) () -> CompletionStages.join(scriptingManager.runScript("testRole.js", new TaskContext().addParameter("a", "a"))));
assertEquals("a", result);
}
Aggregations