Skip to content
Permalink
Browse files
AMBARI-24974. Sometimes Task Log is not refreshed in UI after operati…
…on completes. (#2747)

* AMBARI-24974. Sometimes Task Log is not refreshed in UI after operation completes. (mpapirkovskyy)

* AMBARI-24974. Sometimes Task Log is not refreshed in UI after operation completes. (mpapirkovskyy)
  • Loading branch information
mpapirkovskyy committed Dec 31, 2018
1 parent 5c73593 commit bde5e12fbff3343e4b2775e8df32c0c397b89c48
Showing 2 changed files with 18 additions and 16 deletions.
@@ -20,14 +20,14 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.ambari.server.events.listeners.tasks.TaskStatusListener;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -40,7 +40,7 @@ public class NamedTasksSubscriptions {
private static Logger LOG = LoggerFactory.getLogger(NamedTasksSubscriptions.class);

private ConcurrentHashMap<String, List<SubscriptionId>> taskIds = new ConcurrentHashMap<>();
private final Pattern pattern = Pattern.compile("^/events/tasks/(\\d*)$");
private final String subscriptionPrefix = "/events/tasks/";
private final Lock taskIdsLock = new ReentrantLock();

private Provider<TaskStatusListener> taskStatusListenerProvider;
@@ -116,22 +116,22 @@ public void removeSession(String sessionId) {
taskIds.remove(sessionId);
LOG.info(String.format("Task subscriptions were removed for sessionId = %s", sessionId));
} finally {
taskIdsLock.unlock();
taskIdsLock.unlock();
}
}

public Long matchDestination(String destination) {
Matcher m = pattern.matcher(destination);
if (m.matches()) {
return Long.parseLong(m.group(1));
}
return null;
public Optional<Long> matchDestination(String destination) {
Optional<Long> taskIdOpt = Optional.of(StringUtils.substringAfter(destination, subscriptionPrefix))
.filter(StringUtils::isNotEmpty)
.filter(StringUtils::isNumeric)
.map(Long::parseLong);
return taskIdOpt;
}

public void addDestination(String sessionId, String destination, String id) {
Long taskId = matchDestination(destination);
if (taskId != null) {
addTaskId(sessionId, taskId, id);
Optional<Long> taskIdOpt = matchDestination(destination);
if (taskIdOpt.isPresent()) {
addTaskId(sessionId, taskIdOpt.get(), id);
}
}

@@ -22,11 +22,11 @@
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
@@ -74,8 +74,10 @@ public void setupTest() {

@Test
public void testMatching() {
assertEquals(1L, tasksSubscriptions.matchDestination("/events/tasks/1").longValue());
assertNull(tasksSubscriptions.matchDestination("/events/topologies"));
Optional<Long> taskIdOpt = tasksSubscriptions.matchDestination("/events/tasks/1");
assertTrue(taskIdOpt.isPresent());
assertEquals(1L, taskIdOpt.get().longValue());
assertFalse(tasksSubscriptions.matchDestination("/events/topologies").isPresent());
}

@Test

0 comments on commit bde5e12

Please sign in to comment.