Skip to content

Commit

Permalink
ISPN-11042 TaskResource should not display internal tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Fernandes committed Dec 5, 2019
1 parent 530e064 commit 6db9fd9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Expand Up @@ -54,7 +54,7 @@ private CompletionStage<RestResponse> listTasks(RestRequest request) {
TaskManager taskManager = SecurityActions.getGlobalComponentRegistry(cacheManager).getComponent(TaskManager.class);
NettyRestResponse.Builder builder = new NettyRestResponse.Builder();
try {
List<Task> tasks = taskManager.getTasks();
List<Task> tasks = taskManager.getUserTasks();
byte[] resultBytes = invocationHelper.getMapper().writeValueAsBytes(tasks);
builder.contentType(APPLICATION_JSON_TYPE).entity(resultBytes);
} catch (JsonProcessingException e) {
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static org.infinispan.server.security.Common.HTTP_PROTOCOLS;
import static org.infinispan.server.security.Common.sync;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -20,6 +21,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.JsonNode;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;

/**
* @author Tristan Tarrant &lt;tristan@infinispan.org&gt;
Expand Down Expand Up @@ -68,4 +71,17 @@ public void testRestOperations() {
assertEquals(404, response.getStatus());
assertEquals(protocol, response.getProtocol());
}

@Test
public void taskFilter() throws Exception {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.protocol(protocol);
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();

RestResponse tasks = sync(client.tasks().list());
ObjectMapper mapper = new ObjectMapper();
JsonNode taskListNode = mapper.readTree(tasks.getBody());

taskListNode.forEach(n -> assertFalse(n.get("name").asText().startsWith("@@")));
}
}
Expand Up @@ -42,6 +42,12 @@ public interface TaskManager {
*/
List<Task> getTasks();

/**
*
* @return Retrieves the list of all available tasks, excluding administrative tasks with names starting with '@@'
*/
List<Task> getUserTasks();

/**
* Registers a new {@link TaskEngine}
*
Expand Down
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

import javax.security.auth.Subject;

Expand Down Expand Up @@ -128,4 +129,10 @@ public List<Task> getTasks() {
return tasks;
}

@Override
public List<Task> getUserTasks() {
return engines.stream().flatMap(engine -> engine.getTasks().stream())
.filter(t -> !t.getName().startsWith("@@"))
.collect(Collectors.toList());
}
}

0 comments on commit 6db9fd9

Please sign in to comment.