You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by av...@apache.org on 2018/06/22 20:35:53 UTC
[ambari] branch trunk updated: Revert "AMBARI-24147. Make STOMP
updates immutable. (#1584)" (#1606)
This is an automated email from the ASF dual-hosted git repository.
avijayan 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 2357dd2 Revert "AMBARI-24147. Make STOMP updates immutable. (#1584)" (#1606)
2357dd2 is described below
commit 2357dd2537e246c858c599332e7b3830d0701610
Author: aonishuk <ao...@hortonworks.com>
AuthorDate: Fri Jun 22 23:35:51 2018 +0300
Revert "AMBARI-24147. Make STOMP updates immutable. (#1584)" (#1606)
This reverts commit c492689e54a5258a7464584965e443fc430bb017.
---
.../ambari/server/AmbariRuntimeException.java | 28 -----
.../ambari/server/agent/RecoveryConfigHelper.java | 2 +-
.../server/agent/stomp/AgentConfigsHolder.java | 7 +-
.../server/agent/stomp/AgentHostDataHolder.java | 74 +++++--------
.../server/agent/stomp/AlertDefinitionsHolder.java | 40 ++-----
.../server/agent/stomp/HostLevelParamsHolder.java | 75 ++++---------
.../server/agent/stomp/dto/AlertCluster.java | 45 +++-----
.../server/agent/stomp/dto/ClusterConfigs.java | 7 ++
.../agent/stomp/dto/HostLevelParamsCluster.java | 8 ++
.../server/agent/stomp/dto/HostRepositories.java | 8 ++
.../controller/internal/HostResourceProvider.java | 5 +-
.../ambari/server/events/AgentActionEvent.java | 6 +-
.../server/events/AgentConfigsUpdateEvent.java | 11 +-
.../server/events/ExecutionCommandEvent.java | 19 +++-
.../server/events/HostLevelParamsUpdateEvent.java | 17 +--
.../events/publishers/AgentCommandsPublisher.java | 8 +-
.../apache/ambari/server/state/ConfigHelper.java | 3 +-
.../ambari/server/agent/HeartbeatTestHelper.java | 5 +-
.../server/agent/stomp/AgentDataHolderTest.java | 10 +-
.../agent/stomp/AlertDefinitionsHolderTest.java | 121 ---------------------
.../agent/stomp/HostLevelParamsHolderTest.java | 118 --------------------
.../AmbariCustomCommandExecutionHelperTest.java | 4 +-
.../ambari/server/state/UpgradeHelperTest.java | 2 +-
23 files changed, 154 insertions(+), 469 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/AmbariRuntimeException.java b/ambari-server/src/main/java/org/apache/ambari/server/AmbariRuntimeException.java
deleted file mode 100644
index c6a20eb..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariRuntimeException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server;
-
-/**
- * Ambari unchecked exception.
- */
-public class AmbariRuntimeException extends RuntimeException {
- public AmbariRuntimeException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/RecoveryConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/RecoveryConfigHelper.java
index 239e8c1..75a88af 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/RecoveryConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/RecoveryConfigHelper.java
@@ -100,7 +100,7 @@ public class RecoveryConfigHelper {
}
AutoStartConfig autoStartConfig = new AutoStartConfig(clusterName);
-
+
RecoveryConfig recoveryConfig = new RecoveryConfig(autoStartConfig.getEnabledComponents(hostname));
return recoveryConfig;
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentConfigsHolder.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentConfigsHolder.java
index 958f36d..44a6e7f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentConfigsHolder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentConfigsHolder.java
@@ -58,9 +58,9 @@ public class AgentConfigsHolder extends AgentHostDataHolder<AgentConfigsUpdateEv
return configHelper.getHostActualConfigsExcludeCluster(hostId, clusterId);
}
- @Override
- protected AgentConfigsUpdateEvent handleUpdate(AgentConfigsUpdateEvent current, AgentConfigsUpdateEvent update) throws AmbariException {
- return update;
+ protected boolean handleUpdate(AgentConfigsUpdateEvent update) throws AmbariException {
+ setData(update, update.getHostId());
+ return true;
}
public void updateData(Long clusterId, List<Long> hostIds) throws AmbariException {
@@ -75,6 +75,7 @@ public class AgentConfigsHolder extends AgentHostDataHolder<AgentConfigsUpdateEv
for (Long hostId : hostIds) {
AgentConfigsUpdateEvent agentConfigsUpdateEvent = configHelper.getHostActualConfigs(hostId);
+ agentConfigsUpdateEvent.setHostId(hostId);
updateData(agentConfigsUpdateEvent);
}
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentHostDataHolder.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentHostDataHolder.java
index af4ebee..79c9751 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentHostDataHolder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AgentHostDataHolder.java
@@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.AmbariRuntimeException;
import org.apache.ambari.server.agent.stomp.dto.Hashable;
import org.apache.ambari.server.events.STOMPEvent;
import org.apache.ambari.server.events.STOMPHostEvent;
@@ -43,10 +42,10 @@ public abstract class AgentHostDataHolder<T extends STOMPHostEvent & Hashable> e
@Inject
private STOMPUpdatePublisher STOMPUpdatePublisher;
- private final ConcurrentHashMap<Long, T> data = new ConcurrentHashMap<>();
+ private final Map<Long, T> data = new ConcurrentHashMap<>();
protected abstract T getCurrentData(Long hostId) throws AmbariException;
- protected abstract T handleUpdate(T current, T update) throws AmbariException;
+ protected abstract boolean handleUpdate(T update) throws AmbariException;
public T getUpdateIfChanged(String agentHash, Long hostId) throws AmbariException {
T hostData = initializeDataIfNeeded(hostId, true);
@@ -54,23 +53,21 @@ public abstract class AgentHostDataHolder<T extends STOMPHostEvent & Hashable> e
}
public T initializeDataIfNeeded(Long hostId, boolean regenerateHash) throws AmbariException {
- try {
- return data.computeIfAbsent(hostId, id -> initializeData(hostId, regenerateHash));
- } catch (AmbariRuntimeException e) {
- throw new AmbariException(e.getMessage(), e);
- }
- }
-
- private T initializeData(Long hostId, boolean regenerateHash) {
- T hostData;
- try {
- hostData = getCurrentData(hostId);
- } catch (AmbariException e) {
- LOG.error("Error during retrieving initial value for host: {} and class {}", hostId, getClass().getName(), e);
- throw new AmbariRuntimeException("Error during retrieving initial value for host: " + hostId + " and class: " + getClass().getName(), e);
- }
- if (regenerateHash) {
- regenerateDataIdentifiers(hostData);
+ T hostData = data.get(hostId);
+ if (hostData == null) {
+ updateLock.lock();
+ try {
+ hostData = data.get(hostId);
+ if (hostData == null) {
+ hostData = getCurrentData(hostId);
+ if (regenerateHash) {
+ regenerateDataIdentifiers(hostData);
+ }
+ data.put(hostId, hostData);
+ }
+ } finally {
+ updateLock.unlock();
+ }
}
return hostData;
}
@@ -80,34 +77,21 @@ public abstract class AgentHostDataHolder<T extends STOMPHostEvent & Hashable> e
* event to listeners.
*/
public void updateData(T update) throws AmbariException {
+ //TODO need optimization for perf cluster
+ updateLock.lock();
try {
- data.compute(update.getHostId(), (id, current) -> {
- if (current == null) {
- current = initializeData(id, true);
- }
- T updated;
- try {
- updated = handleUpdate(current, update);
- } catch (AmbariException e) {
- LOG.error("Error during handling update for host: {} and class {}", id, getClass().getName(), e);
- throw new AmbariRuntimeException("Error during handling update for host: " + id + " and class: " + getClass().getName(), e);
+ initializeDataIfNeeded(update.getHostId(), true);
+ if (handleUpdate(update)) {
+ T hostData = getData(update.getHostId());
+ regenerateDataIdentifiers(hostData);
+ setIdentifiersToEventUpdate(update, hostData);
+ if (update.getType().equals(STOMPEvent.Type.AGENT_CONFIGS)) {
+ LOG.info("Configs update with hash {} will be sent to host {}", update.getHash(), hostData.getHostId());
}
- if (updated == null) {
- return current;
- } else {
- regenerateDataIdentifiers(updated);
- setIdentifiersToEventUpdate(update, updated);
- return updated;
- }
- });
- } catch(AmbariRuntimeException e) {
- throw new AmbariException(e.getMessage(), e);
- }
- if (isIdentifierValid(update)) {
- if (update.getType().equals(STOMPEvent.Type.AGENT_CONFIGS)) {
- LOG.info("Configs update with hash {} will be sent to host {}", update.getHash(), update.getHostId());
+ STOMPUpdatePublisher.publish(update);
}
- STOMPUpdatePublisher.publish(update);
+ } finally {
+ updateLock.unlock();
}
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolder.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolder.java
index 308ec84..1080905 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolder.java
@@ -108,17 +108,15 @@ public class AlertDefinitionsHolder extends AgentHostDataHolder<AlertDefinitions
}
@Override
- protected AlertDefinitionsAgentUpdateEvent handleUpdate(AlertDefinitionsAgentUpdateEvent current, AlertDefinitionsAgentUpdateEvent update) throws AmbariException {
+ protected boolean handleUpdate(AlertDefinitionsAgentUpdateEvent update) throws AmbariException {
Map<Long, AlertCluster> updateClusters = update.getClusters();
if (updateClusters.isEmpty()) {
- return null;
+ return false;
}
- AlertDefinitionsAgentUpdateEvent result = null;
Long hostId = update.getHostId();
boolean changed = false;
- Map<Long, AlertCluster> existingClusters = current.getClusters();
- Map<Long, AlertCluster> mergedClusters = new HashMap<>();
+ Map<Long, AlertCluster> existingClusters = getData(hostId).getClusters();
switch (update.getEventType()) {
case UPDATE:
@@ -126,27 +124,12 @@ public class AlertDefinitionsHolder extends AgentHostDataHolder<AlertDefinitions
if (!existingClusters.keySet().containsAll(updateClusters.keySet())) {
LOG.info("Unknown clusters in update, perhaps cluster was removed previously");
}
- for (Map.Entry<Long, AlertCluster> e : existingClusters.entrySet()) {
- Long clusterId = e.getKey();
- if (!updateClusters.containsKey(clusterId)) {
- mergedClusters.put(clusterId, e.getValue());
- }
- }
for (Map.Entry<Long, AlertCluster> e : updateClusters.entrySet()) {
- Long clusterId = e.getKey();
- if (existingClusters.containsKey(clusterId)) {
- if (update.getEventType().equals(DELETE) && CollectionUtils.isEmpty(e.getValue().getAlertDefinitions())) {
- changed = true;
- } else {
- AlertCluster mergedCluster = existingClusters.get(e.getKey()).handleUpdate(update.getEventType(), e.getValue());
- if (mergedCluster != null) {
- mergedClusters.put(clusterId, mergedCluster);
- changed = true;
- }
- }
- } else {
- mergedClusters.put(clusterId, e.getValue());
+ if (update.getEventType().equals(DELETE) && CollectionUtils.isEmpty(e.getValue().getAlertDefinitions())) {
+ existingClusters.remove(e.getKey());
changed = true;
+ } else {
+ changed |= existingClusters.get(e.getKey()).handleUpdate(update.getEventType(), e.getValue());
}
}
LOG.debug("Handled {} of alerts for {} cluster(s) on host with id {}, changed = {}", update.getEventType(), updateClusters.size(), hostId, changed);
@@ -156,8 +139,7 @@ public class AlertDefinitionsHolder extends AgentHostDataHolder<AlertDefinitions
if (!Sets.intersection(existingClusters.keySet(), updateClusters.keySet()).isEmpty()) {
throw new AmbariException("Existing clusters in create");
}
- mergedClusters.putAll(existingClusters);
- mergedClusters.putAll(updateClusters);
+ existingClusters.putAll(updateClusters);
LOG.debug("Handled {} of alerts for {} cluster(s)", update.getEventType(), updateClusters.size());
changed = true;
}
@@ -166,10 +148,8 @@ public class AlertDefinitionsHolder extends AgentHostDataHolder<AlertDefinitions
LOG.warn("Unhandled event type {}", update.getEventType());
break;
}
- if (changed) {
- result = new AlertDefinitionsAgentUpdateEvent(CREATE, mergedClusters, current.getHostName(), hostId);
- }
- return result;
+
+ return changed;
}
@Subscribe
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
index b309bbb..3c44f57 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolder.java
@@ -17,17 +17,12 @@
*/
package org.apache.ambari.server.agent.stomp;
-import java.util.HashMap;
import java.util.Map;
-import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.agent.CommandRepository;
-import org.apache.ambari.server.agent.RecoveryConfig;
import org.apache.ambari.server.agent.RecoveryConfigHelper;
import org.apache.ambari.server.agent.stomp.dto.HostLevelParamsCluster;
-import org.apache.ambari.server.agent.stomp.dto.HostRepositories;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.events.ClusterComponentsRepoChangedEvent;
import org.apache.ambari.server.events.HostLevelParamsUpdateEvent;
@@ -81,72 +76,42 @@ public class HostLevelParamsHolder extends AgentHostDataHolder<HostLevelParamsUp
hostLevelParamsClusters.put(Long.toString(cl.getClusterId()),
hostLevelParamsCluster);
}
- HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(hostId, hostLevelParamsClusters);
+ HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(hostLevelParamsClusters);
+ hostLevelParamsUpdateEvent.setHostId(hostId);
return hostLevelParamsUpdateEvent;
}
- @Override
- protected HostLevelParamsUpdateEvent handleUpdate(HostLevelParamsUpdateEvent current, HostLevelParamsUpdateEvent update) {
- HostLevelParamsUpdateEvent result = null;
+ protected boolean handleUpdate(HostLevelParamsUpdateEvent update) {
boolean changed = false;
- Map<String, HostLevelParamsCluster> mergedClusters = new HashMap<>();
if (MapUtils.isNotEmpty(update.getHostLevelParamsClusters())) {
- // put from current all clusters absent in update
- for (Map.Entry<String, HostLevelParamsCluster> hostLevelParamsClusterEntry : current.getHostLevelParamsClusters().entrySet()) {
- String clusterId = hostLevelParamsClusterEntry.getKey();
- if (!update.getHostLevelParamsClusters().containsKey(clusterId)) {
- mergedClusters.put(clusterId, hostLevelParamsClusterEntry.getValue());
- }
- }
- // process clusters from update
+ Long hostId = update.getHostId();
for (Map.Entry<String, HostLevelParamsCluster> hostLevelParamsClusterEntry : update.getHostLevelParamsClusters().entrySet()) {
+ HostLevelParamsCluster updatedCluster = hostLevelParamsClusterEntry.getValue();
String clusterId = hostLevelParamsClusterEntry.getKey();
- if (current.getHostLevelParamsClusters().containsKey(clusterId)) {
- boolean clusterChanged = false;
- HostLevelParamsCluster updatedCluster = hostLevelParamsClusterEntry.getValue();
- HostLevelParamsCluster currentCluster = current.getHostLevelParamsClusters().get(clusterId);
- RecoveryConfig mergedRecoveryConfig;
- SortedMap<Long, CommandRepository> mergedRepositories;
- SortedMap<String, Long> mergedComponentRepos;
- if (!currentCluster.getRecoveryConfig().equals(updatedCluster.getRecoveryConfig())) {
- mergedRecoveryConfig = updatedCluster.getRecoveryConfig();
- clusterChanged = true;
- } else {
- mergedRecoveryConfig = currentCluster.getRecoveryConfig();
+ Map<String, HostLevelParamsCluster> clusters = getData().get(hostId).getHostLevelParamsClusters();
+ if (clusters.containsKey(clusterId)) {
+ HostLevelParamsCluster cluster = clusters.get(clusterId);
+ if (!cluster.getRecoveryConfig().equals(updatedCluster.getRecoveryConfig())) {
+ cluster.setRecoveryConfig(updatedCluster.getRecoveryConfig());
+ changed = true;
}
- if (!currentCluster.getHostRepositories().getRepositories()
+ if (!cluster.getHostRepositories().getRepositories()
.equals(updatedCluster.getHostRepositories().getRepositories())) {
- mergedRepositories = updatedCluster.getHostRepositories().getRepositories();
- clusterChanged = true;
- } else {
- mergedRepositories = currentCluster.getHostRepositories().getRepositories();
+ cluster.getHostRepositories().setRepositories(updatedCluster.getHostRepositories().getRepositories());
+ changed = true;
}
- if (!currentCluster.getHostRepositories().getComponentRepos()
+ if (!cluster.getHostRepositories().getComponentRepos()
.equals(updatedCluster.getHostRepositories().getComponentRepos())) {
- mergedComponentRepos = updatedCluster.getHostRepositories().getComponentRepos();
- clusterChanged = true;
- } else {
- mergedComponentRepos = currentCluster.getHostRepositories().getComponentRepos();
- }
- if (clusterChanged) {
- HostLevelParamsCluster mergedCluster = new HostLevelParamsCluster(
- new HostRepositories(mergedRepositories, mergedComponentRepos),
- mergedRecoveryConfig);
- mergedClusters.put(clusterId, mergedCluster);
+ cluster.getHostRepositories().setComponentRepos(updatedCluster.getHostRepositories().getComponentRepos());
changed = true;
- } else {
- mergedClusters.put(clusterId, hostLevelParamsClusterEntry.getValue());
}
} else {
- mergedClusters.put(clusterId, hostLevelParamsClusterEntry.getValue());
+ clusters.put(clusterId, updatedCluster);
changed = true;
}
}
}
- if (changed) {
- result = new HostLevelParamsUpdateEvent(current.getHostId(), mergedClusters);
- }
- return result;
+ return changed;
}
@Override
@@ -172,11 +137,11 @@ public class HostLevelParamsHolder extends AgentHostDataHolder<HostLevelParamsUp
}
private void updateDataOfHost(long clusterId, Cluster cluster, Host host) throws AmbariException {
- HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(host.getHostId(),
- Long.toString(clusterId),
+ HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(Long.toString(clusterId),
new HostLevelParamsCluster(
m_ambariManagementController.get().retrieveHostRepositories(cluster, host),
recoveryConfigHelper.getRecoveryConfig(cluster.getClusterName(), host.getHostName())));
+ hostLevelParamsUpdateEvent.setHostId(host.getHostId());
updateData(hostLevelParamsUpdateEvent);
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertCluster.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertCluster.java
index e4a4234..ac34d4a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertCluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/AlertCluster.java
@@ -79,58 +79,41 @@ public class AlertCluster {
return hostName;
}
- public AlertCluster handleUpdate(AlertDefinitionEventType eventType, AlertCluster update) {
+ public boolean handleUpdate(AlertDefinitionEventType eventType, AlertCluster update) {
boolean changed = false;
- AlertCluster mergedCluster = null;
- Map<Long, AlertDefinition> mergedDefinitions = new HashMap<>();
- Integer mergedStaleIntervalMultiplier = null;
switch (eventType) {
case CREATE:
// FIXME should clear map first?
case UPDATE:
- for (Map.Entry<Long, AlertDefinition> alertDefinitionEntry : alertDefinitions.entrySet()) {
- Long definitionId = alertDefinitionEntry.getKey();
- if (!update.alertDefinitions.containsKey(definitionId)) {
- mergedDefinitions.put(definitionId, alertDefinitionEntry.getValue());
- } else {
- AlertDefinition newDefinition = update.alertDefinitions.get(definitionId);
- AlertDefinition oldDefinition = alertDefinitionEntry.getValue();
- if (!oldDefinition.deeplyEquals(newDefinition)) {
- changed = true;
- }
- mergedDefinitions.put(definitionId, oldDefinition);
+ changed = !alertDefinitions.keySet().containsAll(update.alertDefinitions.keySet());
+ if (changed) {
+ alertDefinitions.putAll(update.alertDefinitions);
+ } else {
+ for (Map.Entry<Long, AlertDefinition> e : update.alertDefinitions.entrySet()) {
+ Long definitionId = e.getKey();
+ AlertDefinition newDefinition = e.getValue();
+ AlertDefinition oldDefinition = alertDefinitions.put(definitionId, newDefinition);
+ changed = changed || !oldDefinition.deeplyEquals(newDefinition);
}
}
if (update.getStaleIntervalMultiplier() != null
&& !update.getStaleIntervalMultiplier().equals(staleIntervalMultiplier)) {
- mergedStaleIntervalMultiplier = update.getStaleIntervalMultiplier();
+ staleIntervalMultiplier = update.getStaleIntervalMultiplier();
changed = true;
- } else {
- mergedStaleIntervalMultiplier = staleIntervalMultiplier;
}
LOG.debug("Handled {} of {} alerts, changed = {}", eventType, update.alertDefinitions.size(), changed);
break;
case DELETE:
- for (Map.Entry<Long, AlertDefinition> alertDefinitionEntry : alertDefinitions.entrySet()) {
- Long definitionId = alertDefinitionEntry.getKey();
- if (!update.alertDefinitions.containsKey(definitionId)) {
- mergedDefinitions.put(definitionId, alertDefinitionEntry.getValue());
- } else {
- changed = true;
- }
- }
- mergedStaleIntervalMultiplier = staleIntervalMultiplier;
+ changed = alertDefinitions.keySet().removeAll(update.alertDefinitions.keySet());
LOG.debug("Handled {} of {} alerts", eventType, update.alertDefinitions.size());
break;
default:
LOG.warn("Unhandled event type {}", eventType);
break;
}
- if (changed) {
- mergedCluster = new AlertCluster(mergedDefinitions, hostName, mergedStaleIntervalMultiplier);
- }
- return mergedCluster;
+
+ return changed;
}
public static AlertCluster emptyAlertCluster() {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/ClusterConfigs.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/ClusterConfigs.java
index 296fb2f..13c1f55 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/ClusterConfigs.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/ClusterConfigs.java
@@ -36,11 +36,18 @@ public class ClusterConfigs {
return configurations;
}
+ public void setConfigurations(SortedMap<String, SortedMap<String, String>> configurations) {
+ this.configurations = configurations;
+ }
public SortedMap<String, SortedMap<String, SortedMap<String, String>>> getConfigurationAttributes() {
return configurationAttributes;
}
+ public void setConfigurationAttributes(SortedMap<String, SortedMap<String, SortedMap<String, String>>> configurationAttributes) {
+ this.configurationAttributes = configurationAttributes;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostLevelParamsCluster.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostLevelParamsCluster.java
index dfbc6f7..5ca72e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostLevelParamsCluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostLevelParamsCluster.java
@@ -41,7 +41,15 @@ public class HostLevelParamsCluster {
return hostRepositories;
}
+ public void setHostRepositories(HostRepositories hostRepositories) {
+ this.hostRepositories = hostRepositories;
+ }
+
public RecoveryConfig getRecoveryConfig() {
return recoveryConfig;
}
+
+ public void setRecoveryConfig(RecoveryConfig recoveryConfig) {
+ this.recoveryConfig = recoveryConfig;
+ }
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostRepositories.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostRepositories.java
index bc3018e..1e63812 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostRepositories.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/dto/HostRepositories.java
@@ -44,7 +44,15 @@ public class HostRepositories {
return repositories;
}
+ public void setRepositories(SortedMap<Long, CommandRepository> repositories) {
+ this.repositories = repositories;
+ }
+
public SortedMap<String, Long> getComponentRepos() {
return componentRepos;
}
+
+ public void setComponentRepos(SortedMap<String, Long> componentRepos) {
+ this.componentRepos = componentRepos;
+ }
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 3045bfa..8d787f5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -565,13 +565,12 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
addedHost.getHostName(),
addedHost.getRackInfo(),
addedHost.getIPv4()));
- HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(addedHost.getHostId(),
- clusterId,
- new HostLevelParamsCluster(
+ HostLevelParamsUpdateEvent hostLevelParamsUpdateEvent = new HostLevelParamsUpdateEvent(clusterId, new HostLevelParamsCluster(
getManagementController().retrieveHostRepositories(cl, addedHost),
recoveryConfigHelper.getRecoveryConfig(cl.getClusterName(),
addedHost.getHostName())
));
+ hostLevelParamsUpdateEvent.setHostId(addedHost.getHostId());
hostLevelParamsUpdateEvents.add(hostLevelParamsUpdateEvent);
}
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AgentActionEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AgentActionEvent.java
index ea86efd..e8352cf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/AgentActionEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AgentActionEvent.java
@@ -29,7 +29,7 @@ public class AgentActionEvent extends STOMPHostEvent {
/**
* Host id with agent action commands will be send to.
*/
- private final Long hostId;
+ private Long hostId;
@JsonProperty("actionName")
private AgentAction agentAction;
@@ -40,6 +40,10 @@ public class AgentActionEvent extends STOMPHostEvent {
this.hostId = hostId;
}
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
+ }
+
@Override
public Long getHostId() {
return hostId;
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AgentConfigsUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AgentConfigsUpdateEvent.java
index 6ded338..797b739 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/AgentConfigsUpdateEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AgentConfigsUpdateEvent.java
@@ -44,7 +44,7 @@ public class AgentConfigsUpdateEvent extends STOMPHostEvent implements Hashable
/**
* Host identifier.
*/
- private final Long hostId;
+ private Long hostId;
/**
* Configs grouped by cluster id as keys.
@@ -52,9 +52,8 @@ public class AgentConfigsUpdateEvent extends STOMPHostEvent implements Hashable
@JsonProperty("clusters")
private final SortedMap<String, ClusterConfigs> clustersConfigs;
- public AgentConfigsUpdateEvent(Long hostId, SortedMap<String, ClusterConfigs> clustersConfigs) {
+ public AgentConfigsUpdateEvent(SortedMap<String, ClusterConfigs> clustersConfigs) {
super(Type.AGENT_CONFIGS);
- this.hostId = hostId;
this.clustersConfigs = clustersConfigs;
this.timestamp = System.currentTimeMillis();
}
@@ -76,6 +75,10 @@ public class AgentConfigsUpdateEvent extends STOMPHostEvent implements Hashable
this.timestamp = timestamp;
}
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
+ }
+
@Override
public Long getHostId() {
return hostId;
@@ -86,7 +89,7 @@ public class AgentConfigsUpdateEvent extends STOMPHostEvent implements Hashable
}
public static AgentConfigsUpdateEvent emptyUpdate() {
- return new AgentConfigsUpdateEvent(null, null);
+ return new AgentConfigsUpdateEvent(null);
}
@Override
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/ExecutionCommandEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/ExecutionCommandEvent.java
index 80439f3..1c0238b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/ExecutionCommandEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/ExecutionCommandEvent.java
@@ -33,7 +33,7 @@ public class ExecutionCommandEvent extends STOMPHostEvent {
/**
* Host id with agent execution commands will be send to.
*/
- private final Long hostId;
+ private Long hostId;
/**
*
@@ -47,11 +47,8 @@ public class ExecutionCommandEvent extends STOMPHostEvent {
@JsonProperty("clusters")
private TreeMap<String, ExecutionCommandsCluster> clusters;
- public ExecutionCommandEvent(Long hostId, Long requiredConfigTimestamp,
- TreeMap<String, ExecutionCommandsCluster> clusters) {
+ public ExecutionCommandEvent(TreeMap<String, ExecutionCommandsCluster> clusters) {
super(Type.COMMAND);
- this.hostId = hostId;
- this.requiredConfigTimestamp = requiredConfigTimestamp;
this.clusters = clusters;
}
@@ -59,6 +56,10 @@ public class ExecutionCommandEvent extends STOMPHostEvent {
return clusters;
}
+ public void setClusters(TreeMap<String, ExecutionCommandsCluster> clusters) {
+ this.clusters = clusters;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -77,6 +78,10 @@ public class ExecutionCommandEvent extends STOMPHostEvent {
return result;
}
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
+ }
+
@Override
public Long getHostId() {
return hostId;
@@ -85,4 +90,8 @@ public class ExecutionCommandEvent extends STOMPHostEvent {
public Long getRequiredConfigTimestamp() {
return requiredConfigTimestamp;
}
+
+ public void setRequiredConfigTimestamp(Long requiredConfigTimestamp) {
+ this.requiredConfigTimestamp = requiredConfigTimestamp;
+ }
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/HostLevelParamsUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/HostLevelParamsUpdateEvent.java
index 95b5d6b..facce46 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/HostLevelParamsUpdateEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/HostLevelParamsUpdateEvent.java
@@ -42,7 +42,7 @@ public class HostLevelParamsUpdateEvent extends STOMPHostEvent implements Hashab
/**
* Host identifier.
*/
- private final Long hostId;
+ private Long hostId;
/**
* Host level parameters by clusters.
@@ -50,14 +50,13 @@ public class HostLevelParamsUpdateEvent extends STOMPHostEvent implements Hashab
@JsonProperty("clusters")
private final Map<String, HostLevelParamsCluster> hostLevelParamsClusters;
- public HostLevelParamsUpdateEvent(Long hostId, Map<String, HostLevelParamsCluster> hostLevelParamsClusters) {
+ public HostLevelParamsUpdateEvent(Map<String, HostLevelParamsCluster> hostLevelParamsClusters) {
super(Type.HOSTLEVELPARAMS);
- this.hostId = hostId;
this.hostLevelParamsClusters = hostLevelParamsClusters;
}
- public HostLevelParamsUpdateEvent(Long hostId, String clusterId, HostLevelParamsCluster hostLevelParamsCluster) {
- this(hostId, Collections.singletonMap(clusterId, hostLevelParamsCluster));
+ public HostLevelParamsUpdateEvent(String clusterId, HostLevelParamsCluster hostLevelParamsCluster) {
+ this(Collections.singletonMap(clusterId, hostLevelParamsCluster));
}
@Override
@@ -71,7 +70,11 @@ public class HostLevelParamsUpdateEvent extends STOMPHostEvent implements Hashab
}
public static HostLevelParamsUpdateEvent emptyUpdate() {
- return new HostLevelParamsUpdateEvent(null, null);
+ return new HostLevelParamsUpdateEvent(null);
+ }
+
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
}
@Override
@@ -80,7 +83,7 @@ public class HostLevelParamsUpdateEvent extends STOMPHostEvent implements Hashab
}
public Map<String, HostLevelParamsCluster> getHostLevelParamsClusters() {
- return Collections.unmodifiableMap(hostLevelParamsClusters);
+ return hostLevelParamsClusters;
}
@Override
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java b/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
index f12a20f..c4fb497 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/publishers/AgentCommandsPublisher.java
@@ -89,10 +89,10 @@ public class AgentCommandsPublisher {
}
for (Map.Entry<Long, TreeMap<String, ExecutionCommandsCluster>> hostEntry : executionCommandsClusters.entrySet()) {
Long hostId = hostEntry.getKey();
- ExecutionCommandEvent executionCommandEvent = new ExecutionCommandEvent(hostId,
- agentConfigsHolder
- .initializeDataIfNeeded(hostId, true).getTimestamp(),
- hostEntry.getValue());
+ ExecutionCommandEvent executionCommandEvent = new ExecutionCommandEvent(hostEntry.getValue());
+ executionCommandEvent.setHostId(hostId);
+ executionCommandEvent.setRequiredConfigTimestamp(agentConfigsHolder
+ .initializeDataIfNeeded(hostId, true).getTimestamp());
STOMPUpdatePublisher.publish(executionCommandEvent);
}
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index ba8c3d6..5d30436 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -2067,7 +2067,8 @@ public class ConfigHelper {
new ClusterConfigs(configurationsTreeMap, configurationAttributesTreeMap));
}
- AgentConfigsUpdateEvent agentConfigsUpdateEvent = new AgentConfigsUpdateEvent(hostId, clustersConfigs);
+ AgentConfigsUpdateEvent agentConfigsUpdateEvent = new AgentConfigsUpdateEvent(clustersConfigs);
+ agentConfigsUpdateEvent.setHostId(hostId);
return agentConfigsUpdateEvent;
}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
index fd6fc02..193f024 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
@@ -44,7 +44,6 @@ import org.apache.ambari.server.actionmanager.Request;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.events.publishers.STOMPUpdatePublisher;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
import org.apache.ambari.server.orm.dao.ClusterDAO;
@@ -66,7 +65,6 @@ import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.cluster.ClustersImpl;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
-import org.easymock.EasyMock;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -119,7 +117,6 @@ public class HeartbeatTestHelper {
@Override
protected void configure() {
super.configure();
- binder().bind(STOMPUpdatePublisher.class).toInstance(EasyMock.createNiceMock(STOMPUpdatePublisher.class));
}
};
}
@@ -187,7 +184,7 @@ public class HeartbeatTestHelper {
// forcefully will refresh the internal state so that any tests which
// incorrect use Clusters after calling this won't be affected
Clusters clusters = injector.getInstance(Clusters.class);
- Method method = ClustersImpl.class.getDeclaredMethod("safelyLoadClustersAndHosts");
+ Method method = ClustersImpl.class.getDeclaredMethod("loadClustersAndHosts");
method.setAccessible(true);
method.invoke(clusters);
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AgentDataHolderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AgentDataHolderTest.java
index d5ba86f..bb5c988 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AgentDataHolderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AgentDataHolderTest.java
@@ -35,31 +35,31 @@ public class AgentDataHolderTest {
AmbariEventPublisher ambariEventPublisher = createNiceMock(AmbariEventPublisher.class);
AgentConfigsHolder agentConfigsHolder = new AgentConfigsHolder(ambariEventPublisher);
- AgentConfigsUpdateEvent event1 = new AgentConfigsUpdateEvent(null, null);
+ AgentConfigsUpdateEvent event1 = new AgentConfigsUpdateEvent(null);
event1.setHash("01");
event1.setTimestamp(1L);
String eventHash1 = agentConfigsHolder.getHash(event1);
// difference in hash only
- AgentConfigsUpdateEvent event2 = new AgentConfigsUpdateEvent(null, null);
+ AgentConfigsUpdateEvent event2 = new AgentConfigsUpdateEvent(null);
event2.setHash("02");
event2.setTimestamp(1L);
String eventHash2 = agentConfigsHolder.getHash(event2);
// difference in timestamp only
- AgentConfigsUpdateEvent event3 = new AgentConfigsUpdateEvent(null, null);
+ AgentConfigsUpdateEvent event3 = new AgentConfigsUpdateEvent(null);
event3.setHash("01");
event3.setTimestamp(2L);
String eventHash3 = agentConfigsHolder.getHash(event3);
// difference in both hash and timestamp
- AgentConfigsUpdateEvent event4 = new AgentConfigsUpdateEvent(null, null);
+ AgentConfigsUpdateEvent event4 = new AgentConfigsUpdateEvent(null);
event4.setHash("02");
event4.setTimestamp(2L);
String eventHash4 = agentConfigsHolder.getHash(event4);
// hash and timestamp are the same, changes in body
- AgentConfigsUpdateEvent event5 = new AgentConfigsUpdateEvent(null, MapUtils.EMPTY_SORTED_MAP);
+ AgentConfigsUpdateEvent event5 = new AgentConfigsUpdateEvent(MapUtils.EMPTY_SORTED_MAP);
event5.setHash("01");
event5.setTimestamp(1L);
String eventHash5 = agentConfigsHolder.getHash(event5);
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolderTest.java
deleted file mode 100644
index 67fbbf3..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/AlertDefinitionsHolderTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.agent.stomp;
-
-import static org.easymock.EasyMock.createNiceMock;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.agent.stomp.dto.AlertCluster;
-import org.apache.ambari.server.events.AlertDefinitionEventType;
-import org.apache.ambari.server.events.AlertDefinitionsAgentUpdateEvent;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-import org.junit.Test;
-
-public class AlertDefinitionsHolderTest {
- private final Long HOST_ID = 1L;
-
- @Test
- public void testHandleUpdateEmptyCurrent() throws AmbariException {
- AlertDefinitionsAgentUpdateEvent current = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.CREATE,
- Collections.emptyMap(), "host1", HOST_ID);
- Map<Long, AlertCluster> clusters = new HashMap<>();
- AlertCluster cluster = AlertCluster.emptyAlertCluster();
- clusters.put(1L, cluster);
- AlertDefinitionsAgentUpdateEvent update = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.UPDATE,
- clusters, "host1", HOST_ID);
-
- AlertDefinitionsHolder alertDefinitionsHolder = new AlertDefinitionsHolder(createNiceMock(AmbariEventPublisher.class));
- AlertDefinitionsAgentUpdateEvent result = alertDefinitionsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(AlertDefinitionEventType.CREATE, result.getEventType());
- assertEquals(result.getClusters(), update.getClusters());
- }
-
- @Test
- public void testHandleUpdateEmptyUpdate() throws AmbariException {
- Map<Long, AlertCluster> clusters = new HashMap<>();
- AlertCluster cluster = AlertCluster.emptyAlertCluster();
- clusters.put(1L, cluster);
- AlertDefinitionsAgentUpdateEvent current = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.CREATE,
- clusters, "host1", HOST_ID);
- AlertDefinitionsAgentUpdateEvent update = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.UPDATE,
- Collections.emptyMap(), "host1", HOST_ID);
-
- AlertDefinitionsHolder alertDefinitionsHolder = new AlertDefinitionsHolder(createNiceMock(AmbariEventPublisher.class));
- AlertDefinitionsAgentUpdateEvent result = alertDefinitionsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(result, null);
- }
-
- @Test
- public void testHandleUpdateNoChanges() throws AmbariException {
- Map<Long, AlertCluster> currentClusters = new HashMap<>();
- AlertCluster currentCluster = new AlertCluster(Collections.emptyMap(), "host1");
- currentClusters.put(1L, currentCluster);
- AlertDefinitionsAgentUpdateEvent current = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.CREATE,
- currentClusters, "host1", HOST_ID);
-
- Map<Long, AlertCluster> updateClusters = new HashMap<>();
- AlertCluster updateCluster = new AlertCluster(Collections.emptyMap(), "host1");
- updateClusters.put(1L, updateCluster);
- AlertDefinitionsAgentUpdateEvent update = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.UPDATE,
- updateClusters, "host1", HOST_ID);
-
- AlertDefinitionsHolder alertDefinitionsHolder = new AlertDefinitionsHolder(createNiceMock(AmbariEventPublisher.class));
- AlertDefinitionsAgentUpdateEvent result = alertDefinitionsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(result, null);
- }
-
- @Test
- public void testHandleUpdateOnChanges() throws AmbariException {
- Map<Long, AlertCluster> currentClusters = new HashMap<>();
- AlertCluster currentCluster = new AlertCluster(Collections.emptyMap(), "host1");
- currentClusters.put(1L, currentCluster);
- AlertDefinitionsAgentUpdateEvent current = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.CREATE,
- currentClusters, "host1", HOST_ID);
-
- Map<Long, AlertCluster> updateClusters = new HashMap<>();
- AlertCluster updateCluster = new AlertCluster(Collections.emptyMap(), "host1");
- updateClusters.put(2L, updateCluster);
- AlertDefinitionsAgentUpdateEvent update = new AlertDefinitionsAgentUpdateEvent(AlertDefinitionEventType.UPDATE,
- updateClusters, "host1", HOST_ID);
-
- AlertDefinitionsHolder alertDefinitionsHolder = new AlertDefinitionsHolder(createNiceMock(AmbariEventPublisher.class));
- AlertDefinitionsAgentUpdateEvent result = alertDefinitionsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(2, result.getClusters().size());
- assertTrue(result.getClusters().containsKey(1L));
- assertTrue(result.getClusters().containsKey(2L));
- }
-}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolderTest.java
deleted file mode 100644
index 4fef7fe..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/stomp/HostLevelParamsHolderTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.agent.stomp;
-
-import static org.easymock.EasyMock.createNiceMock;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.ambari.server.agent.RecoveryConfig;
-import org.apache.ambari.server.agent.stomp.dto.HostLevelParamsCluster;
-import org.apache.ambari.server.agent.stomp.dto.HostRepositories;
-import org.apache.ambari.server.events.HostLevelParamsUpdateEvent;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-import org.junit.Test;
-
-public class HostLevelParamsHolderTest {
- private final Long HOST_ID = 1L;
-
- @Test
- public void testHandleUpdateEmptyCurrent() {
- HostLevelParamsUpdateEvent current = new HostLevelParamsUpdateEvent(HOST_ID, Collections.emptyMap());
- Map<String, HostLevelParamsCluster> clusters = new HashMap<>();
- HostRepositories hostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster cluster = new HostLevelParamsCluster(hostRepositories, new RecoveryConfig(null));
- clusters.put("1", cluster);
- HostLevelParamsUpdateEvent update = new HostLevelParamsUpdateEvent(HOST_ID, clusters);
-
- HostLevelParamsHolder levelParamsHolder = new HostLevelParamsHolder(createNiceMock(AmbariEventPublisher.class));
- HostLevelParamsUpdateEvent result = levelParamsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(result, update);
- }
-
- @Test
- public void testHandleUpdateEmptyUpdate() {
- Map<String, HostLevelParamsCluster> clusters = new HashMap<>();
- HostRepositories hostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster cluster = new HostLevelParamsCluster(hostRepositories, new RecoveryConfig(null));
- clusters.put("1", cluster);
- HostLevelParamsUpdateEvent current = new HostLevelParamsUpdateEvent(HOST_ID, clusters);
- HostLevelParamsUpdateEvent update = new HostLevelParamsUpdateEvent(HOST_ID, Collections.emptyMap());
-
- HostLevelParamsHolder levelParamsHolder = new HostLevelParamsHolder(createNiceMock(AmbariEventPublisher.class));
- HostLevelParamsUpdateEvent result = levelParamsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(result, null);
- }
-
- @Test
- public void testHandleUpdateNoChanges() {
- Map<String, HostLevelParamsCluster> currentClusters = new HashMap<>();
- HostRepositories currentHostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster currentCluster = new HostLevelParamsCluster(currentHostRepositories, new RecoveryConfig(null));
- currentClusters.put("1", currentCluster);
- HostLevelParamsUpdateEvent current = new HostLevelParamsUpdateEvent(HOST_ID, currentClusters);
-
- Map<String, HostLevelParamsCluster> updateClusters = new HashMap<>();
- HostRepositories updateHostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster updateCluster = new HostLevelParamsCluster(updateHostRepositories, new RecoveryConfig(null));
- updateClusters.put("1", updateCluster);
- HostLevelParamsUpdateEvent update = new HostLevelParamsUpdateEvent(HOST_ID, updateClusters);
-
- HostLevelParamsHolder levelParamsHolder = new HostLevelParamsHolder(createNiceMock(AmbariEventPublisher.class));
- HostLevelParamsUpdateEvent result = levelParamsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(result, null);
- }
-
- @Test
- public void testHandleUpdateOnChanges() {
- Map<String, HostLevelParamsCluster> currentClusters = new HashMap<>();
- HostRepositories currentHostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster currentCluster = new HostLevelParamsCluster(currentHostRepositories, new RecoveryConfig(null));
- currentClusters.put("1", currentCluster);
- HostLevelParamsUpdateEvent current = new HostLevelParamsUpdateEvent(HOST_ID, currentClusters);
-
- Map<String, HostLevelParamsCluster> updateClusters = new HashMap<>();
- HostRepositories updateHostRepositories = new HostRepositories(Collections.emptySortedMap(), Collections.emptySortedMap());
- HostLevelParamsCluster updateCluster = new HostLevelParamsCluster(updateHostRepositories, new RecoveryConfig(null));
- updateClusters.put("2", updateCluster);
- HostLevelParamsUpdateEvent update = new HostLevelParamsUpdateEvent(HOST_ID, updateClusters);
-
- HostLevelParamsHolder levelParamsHolder = new HostLevelParamsHolder(createNiceMock(AmbariEventPublisher.class));
- HostLevelParamsUpdateEvent result = levelParamsHolder.handleUpdate(current, update);
-
- assertFalse(result == update);
- assertFalse(result == current);
- assertEquals(2, result.getHostLevelParamsClusters().size());
- assertTrue(result.getHostLevelParamsClusters().containsKey("1"));
- assertTrue(result.getHostLevelParamsClusters().containsKey("2"));
- }
-}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 528e589..3533a7d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -147,7 +147,7 @@ public class AmbariCustomCommandExecutionHelperTest {
EasyMock.anyObject(Map.class))).andReturn(Collections.EMPTY_SET);
EasyMock.expect(configHelper.getHostActualConfigs(EasyMock.anyLong())).andReturn(
- new AgentConfigsUpdateEvent(null, new TreeMap<>())).anyTimes();
+ new AgentConfigsUpdateEvent(new TreeMap<>())).anyTimes();
EasyMock.replay(configHelper);
@@ -544,7 +544,7 @@ public class AmbariCustomCommandExecutionHelperTest {
AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
EasyMock.expect(configHelper.getHostActualConfigs(EasyMock.anyLong())).andReturn(
- new AgentConfigsUpdateEvent(null, new TreeMap<>())).anyTimes();
+ new AgentConfigsUpdateEvent(new TreeMap<>())).anyTimes();
EasyMock.replay(configHelper);
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index 2d2d4fb..2cc2010 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -154,7 +154,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
expect(m_configHelper.getEffectiveDesiredTags(
EasyMock.anyObject(Cluster.class), EasyMock.anyObject(String.class))).andReturn(new HashMap<>()).anyTimes();
expect(m_configHelper.getHostActualConfigs(
- EasyMock.anyLong())).andReturn(new AgentConfigsUpdateEvent(null, Collections.emptySortedMap())).anyTimes();
+ EasyMock.anyLong())).andReturn(new AgentConfigsUpdateEvent(Collections.emptySortedMap())).anyTimes();
expect(m_configHelper.getChangedConfigTypes(anyObject(Cluster.class), anyObject(ServiceConfigEntity.class),
anyLong(), anyLong(), anyString())).andReturn(Collections.emptyMap()).anyTimes();
}