Search in sources :

Example 1 with Task

use of org.infinispan.tasks.Task 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());
}
Also used : ScriptTask(org.infinispan.scripting.impl.ScriptTask) Task(org.infinispan.tasks.Task) TaskContext(org.infinispan.tasks.TaskContext) ScriptTask(org.infinispan.scripting.impl.ScriptTask) CommonsTestingUtil.loadFileAsString(org.infinispan.commons.test.CommonsTestingUtil.loadFileAsString)

Example 2 with Task

use of org.infinispan.tasks.Task in project infinispan by infinispan.

the class ScriptingTaskManagerTest method testTask.

public void testTask() throws Exception {
    ScriptingManager scriptingManager = extractGlobalComponent(cacheManager, ScriptingManager.class);
    ScriptingUtils.loadScript(scriptingManager, TEST_SCRIPT);
    String result = CompletionStages.join(taskManager.runTask(TEST_SCRIPT, new TaskContext().addParameter("a", "a")));
    assertEquals("a", result);
    List<Task> tasks = taskManager.getTasks();
    assertEquals(1, tasks.size());
    ScriptTask scriptTask = (ScriptTask) tasks.get(0);
    assertEquals("test.js", scriptTask.getName());
    assertEquals(TaskExecutionMode.ONE_NODE, scriptTask.getExecutionMode());
    assertEquals("Script", scriptTask.getType());
}
Also used : ScriptTask(org.infinispan.scripting.impl.ScriptTask) Task(org.infinispan.tasks.Task) TaskContext(org.infinispan.tasks.TaskContext) ScriptTask(org.infinispan.scripting.impl.ScriptTask)

Example 3 with Task

use of org.infinispan.tasks.Task in project infinispan by infinispan.

the class ServerTaskEngine method invokeTask.

private <T> CompletableFuture<T> invokeTask(TaskContext context, ServerTaskWrapper<T> task) {
    ServerTaskRunner runner;
    switch(task.getExecutionMode()) {
        case ONE_NODE:
            runner = localRunner;
            break;
        default:
            runner = distributedRunner;
            break;
    }
    launderParameters(context);
    MediaType requestMediaType = context.getCache().map(c -> c.getAdvancedCache().getValueDataConversion().getRequestMediaType()).orElse(MediaType.MATCH_ALL);
    context.getCache().ifPresent(c -> context.cache(c.getAdvancedCache().withMediaType(APPLICATION_OBJECT, APPLICATION_OBJECT)));
    return runner.execute(task.getName(), context).thenApply(r -> (T) scriptConversions.convertToRequestType(r, APPLICATION_OBJECT, requestMediaType));
}
Also used : AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) AuthorizationManager(org.infinispan.security.AuthorizationManager) TaskContext(org.infinispan.tasks.TaskContext) CompletableFuture(java.util.concurrent.CompletableFuture) ScriptConversions(org.infinispan.scripting.utils.ScriptConversions) ArrayList(java.util.ArrayList) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Authorizer(org.infinispan.security.impl.Authorizer) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) TaskEngine(org.infinispan.tasks.spi.TaskEngine) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) Task(org.infinispan.tasks.Task) BlockingManager(org.infinispan.util.concurrent.BlockingManager) MediaType(org.infinispan.commons.dataconversion.MediaType)

Aggregations

Task (org.infinispan.tasks.Task)3 TaskContext (org.infinispan.tasks.TaskContext)3 ScriptTask (org.infinispan.scripting.impl.ScriptTask)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 APPLICATION_OBJECT (org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT)1 CommonsTestingUtil.loadFileAsString (org.infinispan.commons.test.CommonsTestingUtil.loadFileAsString)1 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)1 SerializationContextRegistry (org.infinispan.marshall.protostream.impl.SerializationContextRegistry)1 ScriptConversions (org.infinispan.scripting.utils.ScriptConversions)1 AuthorizationManager (org.infinispan.security.AuthorizationManager)1 AuthorizationPermission (org.infinispan.security.AuthorizationPermission)1 Authorizer (org.infinispan.security.impl.Authorizer)1 TaskEngine (org.infinispan.tasks.spi.TaskEngine)1 BlockingManager (org.infinispan.util.concurrent.BlockingManager)1