This is an automated email from the ASF dual-hosted git repository.
mpapirkovskyy pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new bde5e12 AMBARI-24974. Sometimes Task Log is not refreshed in UI after
operation completes. (#2747)
bde5e12 is described below
commit bde5e12fbff3343e4b2775e8df32c0c397b89c48
Author: Myroslav Papirkovskyi <[email protected]>
AuthorDate: Mon Dec 31 14:47:04 2018 +0200
AMBARI-24974. Sometimes Task Log is not refreshed in UI after operation
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)
---
.../server/api/stomp/NamedTasksSubscriptions.java | 26 +++++++++++-----------
.../api/stomp/NamedTasksSubscriptionsTest.java | 8 ++++---
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptions.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptions.java
index 2787dcc..09acdf3 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptions.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptions.java
@@ -20,14 +20,14 @@ package org.apache.ambari.server.api.stomp;
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 class NamedTasksSubscriptions {
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);
}
}
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptionsTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptionsTest.java
index 2046ed5..2107c41 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptionsTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/api/stomp/NamedTasksSubscriptionsTest.java
@@ -22,11 +22,11 @@ import static org.easymock.EasyMock.expect;
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 class NamedTasksSubscriptionsTest {
@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