You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2018/01/05 20:23:42 UTC
ambari git commit: AMBARI-22737. /events/hostcomponents topic should
react on maintenance and stale configs events. (mpapirkovskyy)
Repository: ambari
Updated Branches:
refs/heads/branch-3.0-perf d1a11a312 -> eaa7e7e9b
AMBARI-22737. /events/hostcomponents topic should react on maintenance and stale configs events. (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/eaa7e7e9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/eaa7e7e9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/eaa7e7e9
Branch: refs/heads/branch-3.0-perf
Commit: eaa7e7e9b6a38510fc5eed66c42b517703ca70b1
Parents: d1a11a3
Author: Myroslav Papirkovskyi <mp...@hortonworks.com>
Authored: Fri Jan 5 20:26:49 2018 +0200
Committer: Myroslav Papirkovskyi <mp...@hortonworks.com>
Committed: Fri Jan 5 20:40:22 2018 +0200
----------------------------------------------------------------------
.../ambari/server/agent/HeartbeatProcessor.java | 19 +-
.../ambari/server/events/AmbariEvent.java | 7 +-
.../server/events/HostComponentUpdate.java | 73 +++++--
.../server/events/StaleConfigsUpdateEvent.java | 47 ++++
.../HostComponentsUpdateListener.java | 90 ++++++++
.../listeners/hosts/HostUpdateListener.java | 2 +-
.../org/apache/ambari/server/state/Cluster.java | 6 +-
.../ambari/server/state/ConfigHelper.java | 212 +++++++++++++++++++
.../server/state/ServiceComponentHost.java | 13 +-
.../server/state/cluster/ClusterImpl.java | 86 +-------
.../svccomphost/ServiceComponentHostImpl.java | 65 ++----
.../AmbariManagementControllerTest.java | 12 +-
...hYarnCapacitySchedulerReleaseConfigTest.java | 4 +-
.../svccomphost/ServiceComponentHostTest.java | 36 ++--
14 files changed, 494 insertions(+), 178 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
index fa69727..4bc9efa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
@@ -468,6 +468,21 @@ public class HeartbeatProcessor extends AbstractService{
versionEventPublisher.publish(event);
}
+ if (!scHost.getState().equals(org.apache.ambari.server.state.State.UPGRADING) &&
+ (report.getRoleCommand().equals(RoleCommand.START.toString()) ||
+ (report.getRoleCommand().equals(RoleCommand.CUSTOM_COMMAND.toString()) &&
+ ("START".equals(report.getCustomCommand()) ||
+ "RESTART".equals(report.getCustomCommand()))))) {
+ scHost.setRestartRequired(false);
+ }
+
+ // Necessary for resetting clients stale configs after starting service
+ if ((RoleCommand.INSTALL.toString().equals(report.getRoleCommand()) ||
+ (RoleCommand.CUSTOM_COMMAND.toString().equals(report.getRoleCommand()) &&
+ "INSTALL".equals(report.getCustomCommand()))) && svcComp.isClientComponent()){
+ scHost.setRestartRequired(false);
+ }
+
if (RoleCommand.CUSTOM_COMMAND.toString().equals(report.getRoleCommand()) &&
!("START".equals(report.getCustomCommand()) ||
"STOP".equals(report.getCustomCommand()))) {
@@ -582,10 +597,6 @@ public class HeartbeatProcessor extends AbstractService{
}
}
- if (null != status.getConfigTags()) {
- scHost.updateActualConfigs(status.getConfigTags());
- }
-
Map<String, Object> extra = status.getExtra();
if (null != extra && !extra.isEmpty()) {
try {
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
index 5f410f5..c241ca0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
@@ -160,7 +160,12 @@ public abstract class AmbariEvent {
/**
* Ambari configuration changed event;
*/
- AMBARI_CONFIGURATION_CHANGED;
+ AMBARI_CONFIGURATION_CHANGED,
+
+ /**
+ * Host component's stale config status has been changed.
+ */
+ STALE_CONFIGS_UPDATE;
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdate.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdate.java b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdate.java
index e480146..eef52d4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdate.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentUpdate.java
@@ -19,34 +19,57 @@
package org.apache.ambari.server.events;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import org.apache.ambari.server.state.MaintenanceState;
import org.apache.ambari.server.state.State;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
public class HostComponentUpdate {
- private Long id;
private Long clusterId;
private String serviceName;
private String hostName;
private String componentName;
private State currentState;
private State previousState;
+ private MaintenanceState maintenanceState;
+ private Boolean staleConfigs;
- public HostComponentUpdate(HostComponentStateEntity stateEntity, State previousState) {
- this.id = stateEntity.getId();
- this.clusterId = stateEntity.getClusterId();
- this.serviceName = stateEntity.getServiceName();
- this.hostName = stateEntity.getHostEntity().getHostName();
- this.currentState = stateEntity.getCurrentState();
- this.componentName = stateEntity.getComponentName();
+ private HostComponentUpdate(Long clusterId, String serviceName, String hostName, String componentName,
+ State currentState, State previousState, MaintenanceState maintenanceState,
+ Boolean staleConfigs) {
+ this.clusterId = clusterId;
+ this.serviceName = serviceName;
+ this.hostName = hostName;
+ this.componentName = componentName;
+ this.currentState = currentState;
this.previousState = previousState;
+ this.maintenanceState = maintenanceState;
+ this.staleConfigs = staleConfigs;
+ }
+
+ public static HostComponentUpdate createHostComponentStatusUpdate(HostComponentStateEntity stateEntity, State previousState) {
+ HostComponentUpdate hostComponentUpdate = new HostComponentUpdate(stateEntity.getClusterId(),
+ stateEntity.getServiceName(), stateEntity.getHostEntity().getHostName(), stateEntity.getComponentName(),
+ stateEntity.getCurrentState(), previousState, null, null);
+ return hostComponentUpdate;
}
- public Long getId() {
- return id;
+ public static HostComponentUpdate createHostComponentMaintenanceStatusUpdate(Long clusterId, String serviceName,
+ String hostName, String componentName,
+ MaintenanceState maintenanceState) {
+ HostComponentUpdate hostComponentUpdate = new HostComponentUpdate(clusterId, serviceName, hostName,
+ componentName, null, null, maintenanceState, null);
+ return hostComponentUpdate;
}
- public void setId(Long id) {
- this.id = id;
+ public static HostComponentUpdate createHostComponentStaleConfigsStatusUpdate(Long clusterId, String serviceName,
+ String hostName, String componentName,
+ Boolean isStaleConfig) {
+ HostComponentUpdate hostComponentUpdate = new HostComponentUpdate(clusterId, serviceName, hostName,
+ componentName, null, null, null, isStaleConfig);
+ return hostComponentUpdate;
}
public Long getClusterId() {
@@ -97,6 +120,22 @@ public class HostComponentUpdate {
this.previousState = previousState;
}
+ public MaintenanceState getMaintenanceState() {
+ return maintenanceState;
+ }
+
+ public void setMaintenanceState(MaintenanceState maintenanceState) {
+ this.maintenanceState = maintenanceState;
+ }
+
+ public Boolean getStaleConfigs() {
+ return staleConfigs;
+ }
+
+ public void setStaleConfigs(Boolean staleConfigs) {
+ this.staleConfigs = staleConfigs;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -104,24 +143,26 @@ public class HostComponentUpdate {
HostComponentUpdate that = (HostComponentUpdate) o;
- if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
if (currentState != that.currentState) return false;
- return previousState == that.previousState;
+ if (previousState != that.previousState) return false;
+ if (maintenanceState != that.maintenanceState) return false;
+ return staleConfigs != null ? staleConfigs.equals(that.staleConfigs) : that.staleConfigs == null;
}
@Override
public int hashCode() {
- int result = id != null ? id.hashCode() : 0;
- result = 31 * result + (clusterId != null ? clusterId.hashCode() : 0);
+ int result = clusterId != null ? clusterId.hashCode() : 0;
result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
result = 31 * result + (previousState != null ? previousState.hashCode() : 0);
+ result = 31 * result + (maintenanceState != null ? maintenanceState.hashCode() : 0);
+ result = 31 * result + (staleConfigs != null ? staleConfigs.hashCode() : 0);
return result;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/events/StaleConfigsUpdateEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/StaleConfigsUpdateEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/StaleConfigsUpdateEvent.java
new file mode 100644
index 0000000..2e07098
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/StaleConfigsUpdateEvent.java
@@ -0,0 +1,47 @@
+/**
+ * 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.events;
+
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
+
+public class StaleConfigsUpdateEvent extends AmbariEvent {
+ private ServiceComponentHostImpl serviceComponentHost;
+ private Boolean staleConfigs;
+
+ public StaleConfigsUpdateEvent(ServiceComponentHostImpl serviceComponentHost, Boolean staleConfigs) {
+ super(AmbariEventType.STALE_CONFIGS_UPDATE);
+ this.serviceComponentHost = serviceComponentHost;
+ this.staleConfigs = staleConfigs;
+ }
+
+ public ServiceComponentHostImpl getServiceComponentHost() {
+ return serviceComponentHost;
+ }
+
+ public void setServiceComponentHost(ServiceComponentHostImpl serviceComponentHost) {
+ this.serviceComponentHost = serviceComponentHost;
+ }
+
+ public Boolean getStaleConfigs() {
+ return staleConfigs;
+ }
+
+ public void setStaleConfigs(Boolean staleConfigs) {
+ this.staleConfigs = staleConfigs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hostcomponents/HostComponentsUpdateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hostcomponents/HostComponentsUpdateListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hostcomponents/HostComponentsUpdateListener.java
new file mode 100644
index 0000000..0265118
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hostcomponents/HostComponentsUpdateListener.java
@@ -0,0 +1,90 @@
+/**
+ * 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.events.listeners.hostcomponents;
+
+import java.util.Collections;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.EagerSingleton;
+import org.apache.ambari.server.events.HostComponentUpdate;
+import org.apache.ambari.server.events.HostComponentsUpdateEvent;
+import org.apache.ambari.server.events.MaintenanceModeEvent;
+import org.apache.ambari.server.events.StaleConfigsUpdateEvent;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.ServiceComponentHost;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+@Singleton
+@EagerSingleton
+public class HostComponentsUpdateListener {
+
+ private final StateUpdateEventPublisher stateUpdateEventPublisher;
+
+ @Inject
+ private Provider<ConfigHelper> m_configHelper;
+
+ @Inject
+ public HostComponentsUpdateListener(AmbariEventPublisher ambariEventPublisher,
+ StateUpdateEventPublisher stateUpdateEventPublisher) {
+ ambariEventPublisher.register(this);
+ stateUpdateEventPublisher.register(this);
+ this.stateUpdateEventPublisher = stateUpdateEventPublisher;
+ }
+
+ @Subscribe
+ public void onMaintenanceStateUpdate(MaintenanceModeEvent event) {
+ if (event.getServiceComponentHost() != null) {
+ Long clusterId = event.getClusterId();
+ ServiceComponentHost serviceComponentHost = event.getServiceComponentHost();
+ String serviceName = serviceComponentHost.getServiceName();
+ String componentName = serviceComponentHost.getServiceComponentName();
+ String hostName = serviceComponentHost.getHostName();
+ MaintenanceState maintenanceState = serviceComponentHost.getMaintenanceState();
+ HostComponentUpdate hostComponentUpdate =
+ HostComponentUpdate.createHostComponentMaintenanceStatusUpdate(clusterId, serviceName, hostName,
+ componentName, maintenanceState);
+ HostComponentsUpdateEvent hostComponentsUpdateEvent = new HostComponentsUpdateEvent(
+ Collections.singletonList(hostComponentUpdate));
+
+ stateUpdateEventPublisher.publish(hostComponentsUpdateEvent);
+ }
+ }
+
+ @Subscribe
+ public void onStaleConfigsStateUpdate(StaleConfigsUpdateEvent staleConfigsUpdateEvent) throws AmbariException {
+ ServiceComponentHost serviceComponentHost = staleConfigsUpdateEvent.getServiceComponentHost();
+ if (staleConfigsUpdateEvent.getStaleConfigs() != null) {
+ boolean staleConfigs = staleConfigsUpdateEvent.getStaleConfigs();
+ if (m_configHelper.get().wasStaleConfigsStatusUpdated(serviceComponentHost.getClusterId(),
+ serviceComponentHost.getHost().getHostId(), serviceComponentHost.getServiceName(),
+ serviceComponentHost.getServiceComponentName(), staleConfigs)) {
+ stateUpdateEventPublisher.publish(new HostComponentsUpdateEvent(Collections.singletonList(
+ HostComponentUpdate.createHostComponentStaleConfigsStatusUpdate(serviceComponentHost.getClusterId(),
+ serviceComponentHost.getServiceName(), serviceComponentHost.getHostName(),
+ serviceComponentHost.getServiceComponentName(), staleConfigs))));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hosts/HostUpdateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hosts/HostUpdateListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hosts/HostUpdateListener.java
index 6cb831f..95e6110 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hosts/HostUpdateListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/hosts/HostUpdateListener.java
@@ -155,7 +155,7 @@ public class HostUpdateListener {
Long clusterId = event.getClusterId();
if (event.getHost() != null || event.getServiceComponentHost() != null) {
- String hostName = event.getHost().getHostName();
+ String hostName = event.getHost() == null ? event.getServiceComponentHost().getHostName() : event.getHost().getHostName();
HostUpdateEvent hostUpdateEvent = retrieveHostUpdateFromCache(clusterId, hostName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 7cc5799..d433743 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -310,7 +310,7 @@ public interface Cluster {
* @return <code>true</code> if the config was added, or <code>false</code>
* if the config is already set as the current
*/
- ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs);
+ ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs) throws AmbariException;
/**
* Adds and sets a DESIRED configuration to be applied to a cluster. There
@@ -321,10 +321,10 @@ public interface Cluster {
* @return <code>true</code> if the config was added, or <code>false</code>
* if the config is already set as the current
*/
- ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String serviceConfigVersionNote);
+ ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String serviceConfigVersionNote) throws AmbariException;
ServiceConfigVersionResponse createServiceConfigVersion(String serviceName, String user, String note,
- ConfigGroup configGroup);
+ ConfigGroup configGroup) throws AmbariException;
String getServiceForConfigTypes(Collection<String> configTypes);
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
----------------------------------------------------------------------
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 b5ade0c..9675054 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
@@ -42,13 +42,20 @@ import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
import org.apache.ambari.server.events.AgentConfigsUpdateEvent;
+import org.apache.ambari.server.events.HostComponentUpdate;
+import org.apache.ambari.server.events.HostComponentsUpdateEvent;
+import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
import org.apache.ambari.server.stack.StackDirectory;
import org.apache.ambari.server.state.PropertyInfo.PropertyType;
import org.apache.ambari.server.state.configgroup.ConfigGroup;
import org.apache.ambari.server.utils.SecretReference;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
@@ -83,6 +90,11 @@ public class ConfigHelper {
*/
private final Cache<Integer, Boolean> staleConfigsCache;
+ /**
+ * clusterId -> hostId -> serviceName -> serviceComponentName -> state map to reduce redundant updates sending.
+ */
+ private final Map<Long, Map<Long, Map<String, Map<String, Boolean>>>> stateCache = new HashMap<>();
+
private final Cache<Integer, String> refreshConfigCommandCache;
private static final Logger LOG =
@@ -127,6 +139,12 @@ public class ConfigHelper {
private Provider<AmbariManagementControllerImpl> m_ambariManagementController;
@Inject
+ private StateUpdateEventPublisher stateUpdateEventPublisher;
+
+ @Inject
+ private ServiceConfigDAO serviceConfigDAO;
+
+ @Inject
public ConfigHelper(Clusters c, AmbariMetaInfo metaInfo, Configuration configuration, ClusterDAO clusterDAO) {
clusters = c;
ambariMetaInfo = metaInfo;
@@ -1363,6 +1381,7 @@ public class ConfigHelper {
return defaultPropertiesByType;
}
+ //TODO remove after UI will start usage of stale configs flag from HostComponentState update event.
private boolean calculateIsStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs,
HostComponentDesiredStateEntity hostComponentDesiredStateEntity) throws AmbariException {
@@ -1464,6 +1483,199 @@ public class ConfigHelper {
return stale;
}
+ /**
+ * Checks configs are stale after specified config changes for service's components.
+ * @param clusterId cluster with changed config
+ * @param serviceName service for changed config
+ * @param hostNames hosts with changed config, can be null
+ * @param changedConfigs map of config types to collections of changed properties' names.
+ * @throws AmbariException
+ */
+ public void checkStaleConfigsStatusOnConfigsUpdate(Long clusterId, String serviceName, Collection<String> hostNames,
+ Map<String, Collection<String>> changedConfigs) throws AmbariException {
+ if (MapUtils.isEmpty(changedConfigs)) {
+ return;
+ }
+ Service service = clusters.getCluster(clusterId).getService(serviceName);
+ for (ServiceComponent serviceComponent : service.getServiceComponents().values()) {
+ String serviceComponentHostName = serviceComponent.getName();
+ Set<String> hosts;
+ if (CollectionUtils.isNotEmpty(hostNames)) {
+ hosts = new HashSet<>(hostNames);
+ } else {
+ hosts = serviceComponent.getServiceComponentsHosts();
+ }
+ for (ServiceComponentHost serviceComponentHost : serviceComponent.getServiceComponentHosts().values()) {
+ if (hosts.contains(serviceComponentHost.getHostName())) {
+ boolean staleConfigs = checkStaleConfigsStatusForHostComponent(serviceComponentHost,
+ changedConfigs);
+ if (wasStaleConfigsStatusUpdated(clusterId, serviceComponentHost.getHost().getHostId(),
+ serviceName, serviceComponentHostName, staleConfigs)) {
+ serviceComponentHost.setRestartRequiredWithoutEventPublishing(staleConfigs);
+ stateUpdateEventPublisher.publish(new HostComponentsUpdateEvent(Collections.singletonList(
+ HostComponentUpdate.createHostComponentStaleConfigsStatusUpdate(clusterId,
+ serviceName, serviceComponentHost.getHostName(),
+ serviceComponentHostName, staleConfigs))));
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Tries to change cached stale config with new value.
+ * @param clusterId cluster id.
+ * @param hostId host id.
+ * @param serviceName service name.
+ * @param hostComponentName component name.
+ * @param staleConfigs value to check.
+ * @return true if value from cache is different from {@param staleConfigs}.
+ */
+ public boolean wasStaleConfigsStatusUpdated(Long clusterId, Long hostId, String serviceName, String hostComponentName, Boolean staleConfigs) {
+ if (!stateCache.containsKey(clusterId)) {
+ stateCache.put(clusterId, new HashMap<>());
+ }
+ Map<Long, Map<String, Map<String, Boolean>>> hosts = stateCache.get(clusterId);
+ if (!hosts.containsKey(hostId)) {
+ hosts.put(hostId, new HashMap<>());
+ }
+ Map<String, Map<String, Boolean>> services = hosts.get(hostId);
+ if (!services.containsKey(serviceName)) {
+ services.put(serviceName, new HashMap<>());
+ }
+ Map<String, Boolean> hostComponents = services.get(serviceName);
+ if (staleConfigs.equals(hostComponents.get(hostComponentName))) {
+ return false;
+ } else {
+ hostComponents.put(hostComponentName, staleConfigs);
+ return true;
+ }
+ }
+
+ /**
+ * Checks configs are stale for specified host component.
+ * @param sch host component to check.
+ * @param changedConfigs map of config types to collections of changed properties' names.
+ * @return true if configs are stale.
+ * @throws AmbariException
+ */
+ public boolean checkStaleConfigsStatusForHostComponent(ServiceComponentHost sch,
+ Map<String, Collection<String>> changedConfigs) throws AmbariException {
+ HostComponentDesiredStateEntity hostComponentDesiredStateEntity = sch.getDesiredStateEntity();
+ if (sch.isRestartRequired(hostComponentDesiredStateEntity)) {
+ return true;
+ }
+ boolean stale = false;
+
+ Cluster cluster = clusters.getClusterById(sch.getClusterId());
+
+ StackId stackId = sch.getServiceComponent().getDesiredStackId();
+
+ StackInfo stackInfo = ambariMetaInfo.getStack(stackId);
+
+ ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
+ stackId.getStackVersion(), sch.getServiceName());
+
+ ComponentInfo componentInfo = serviceInfo.getComponentByName(sch.getServiceComponentName());
+
+ List<String> changedProperties = new LinkedList<>();
+ for (Map.Entry<String, Collection<String>> changedConfigType : changedConfigs.entrySet()) {
+ String type = changedConfigType.getKey();
+ stale |= (serviceInfo.hasConfigDependency(type) || componentInfo.hasConfigType(type));
+ if (stale) {
+ changedProperties.addAll(changedConfigType.getValue());
+ }
+ }
+
+ String refreshCommand = calculateRefreshCommand(stackInfo.getRefreshCommandConfiguration(), sch, changedProperties);
+
+ if (STALE_CONFIGS_CACHE_ENABLED) {
+ if (refreshCommand != null) {
+ int staleHash = Objects.hashCode(cluster.getDesiredConfigs().hashCode(),
+ sch.getHostName(),
+ sch.getServiceComponentName(),
+ sch.getServiceName());
+ refreshConfigCommandCache.put(staleHash, refreshCommand);
+ }
+ }
+
+ return stale;
+ }
+
+ /**
+ * Calculates config types and keys were changed during configs change.
+ * @param currentServiceConfigEntity service config entity with populated current cluster configs
+ * @param configGroupId id of config group contained changed configs. Can be null in case group is default
+ * @param clusterId cluster id
+ * @param serviceName service name configs were changed for
+ * @return map of type names to collections of properties' names were changed.
+ */
+ public Map<String, Collection<String>> getChangedConfigTypes(Cluster cluster,
+ ServiceConfigEntity currentServiceConfigEntity,
+ Long configGroupId, Long clusterId, String serviceName) {
+ ServiceConfigEntity previousServiceConfigEntity;
+ List<ClusterConfigEntity> previousConfigEntities = new ArrayList<>();
+ List<ClusterConfigEntity> currentConfigEntities = new ArrayList<>();
+ currentConfigEntities.addAll(currentServiceConfigEntity.getClusterConfigEntities());
+ // Retrieve group cluster configs
+ if (configGroupId != null) {
+ previousServiceConfigEntity =
+ serviceConfigDAO.getLastServiceConfigVersionsForGroup(configGroupId);
+ if (previousServiceConfigEntity != null) {
+ previousConfigEntities.addAll(previousServiceConfigEntity.getClusterConfigEntities());
+ }
+ }
+ // Service config with custom group contains not all config types, so it is needed
+ // to complement it with configs from default group
+ previousServiceConfigEntity =
+ serviceConfigDAO.getLastServiceConfigForServiceDefaultGroup(clusterId, serviceName);
+ if (previousServiceConfigEntity != null) {
+ for (ClusterConfigEntity clusterConfigEntity : previousServiceConfigEntity.getClusterConfigEntities()) {
+ // Add only configs not present yet
+ ClusterConfigEntity exist =
+ previousConfigEntities.stream()
+ .filter(c -> c.getType().equals(clusterConfigEntity.getType())).findAny().orElse(null);
+ if (exist == null) {
+ previousConfigEntities.add(clusterConfigEntity);
+ }
+ // Complement current custom group service config to correct comparing
+ if (configGroupId != null) {
+ exist = currentConfigEntities.stream()
+ .filter(c -> c.getType().equals(clusterConfigEntity.getType())).findAny().orElse(null);
+ if (exist == null) {
+ currentConfigEntities.add(clusterConfigEntity);
+ }
+ }
+ }
+ }
+ Map<String, String> previousConfigs = new HashMap<>();
+ Map<String, String> currentConfigs = new HashMap<>();
+
+ for (ClusterConfigEntity clusterConfigEntity : currentConfigEntities) {
+ currentConfigs.put(clusterConfigEntity.getType(), clusterConfigEntity.getTag());
+ }
+ for (ClusterConfigEntity clusterConfigEntity : previousConfigEntities) {
+ previousConfigs.put(clusterConfigEntity.getType(), clusterConfigEntity.getTag());
+ }
+
+ Map<String, Collection<String>> changedConfigs = new HashMap<>();
+ for (Map.Entry<String, String> currentConfig : currentConfigs.entrySet()) {
+ String type = currentConfig.getKey();
+ String tag = currentConfig.getValue();
+ Collection<String> changedKeys;
+ if (previousConfigs.containsKey(type)) {
+ changedKeys = findChangedKeys(cluster, type, Collections.singletonList(tag),
+ Collections.singletonList(previousConfigs.get(type)));
+ } else {
+ changedKeys = cluster.getConfig(type, tag).getProperties().keySet();
+ }
+ if (CollectionUtils.isNotEmpty(changedKeys)) {
+ changedConfigs.put(type, changedKeys);
+ }
+ }
+ return changedConfigs;
+ }
+
public String getRefreshConfigsCommand(Cluster cluster, String hostName, String serviceName, String componentName) throws AmbariException {
ServiceComponent serviceComponent = cluster.getService(serviceName).getServiceComponent(componentName);
ServiceComponentHost sch = serviceComponent.getServiceComponentHost(hostName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
index 7f1c746..1bbed00 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
@@ -156,12 +156,6 @@ public interface ServiceComponentHost {
void delete(DeleteHostComponentStatusMetaData deleteMetaData);
/**
- * Updates the tags that have been recognized by a START action.
- * @param configTags
- */
- void updateActualConfigs(Map<String, Map<String, String>> configTags);
-
- /**
* Gets the actual config tags, if known.
* @return the actual config map
*/
@@ -202,6 +196,13 @@ public interface ServiceComponentHost {
*/
void setRestartRequired(boolean restartRequired);
+ /**
+ * Set restartRequired flag for appropriate HostComponentDesiredStateEntity
+ * @param restartRequired the restartRequired flag.
+ * @return true when restartRequired flag was changed.
+ */
+ boolean setRestartRequiredWithoutEventPublishing(boolean restartRequired);
+
HostComponentDesiredStateEntity getDesiredStateEntity();
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index d3ba1d5..79ba06b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -1378,12 +1378,12 @@ public class ClusterImpl implements Cluster {
}
@Override
- public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs) {
+ public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs) throws AmbariException {
return addDesiredConfig(user, configs, null);
}
@Override
- public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String serviceConfigVersionNote) {
+ public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String serviceConfigVersionNote) throws AmbariException {
if (null == user) {
throw new NullPointerException("User must be specified.");
}
@@ -1527,7 +1527,7 @@ public class ClusterImpl implements Cluster {
@Override
public ServiceConfigVersionResponse createServiceConfigVersion(
- String serviceName, String user, String note, ConfigGroup configGroup) {
+ String serviceName, String user, String note, ConfigGroup configGroup) throws AmbariException {
// Create next service config version
ServiceConfigEntity serviceConfigEntity = new ServiceConfigEntity();
@@ -1551,7 +1551,7 @@ public class ClusterImpl implements Cluster {
List<ClusterConfigEntity> configEntities = getClusterConfigEntitiesByService(serviceName);
serviceConfigEntity.setClusterConfigEntities(configEntities);
}
- Set<String> changedConfigs = getChangedConfigTypes(serviceConfigEntity,
+ Map<String, Collection<String>> changedConfigs = configHelper.getChangedConfigTypes(this, serviceConfigEntity,
configGroup == null ? null : configGroup.getId(),
clusterId,
serviceName);
@@ -1585,7 +1585,8 @@ public class ClusterImpl implements Cluster {
serviceConfigEntity = serviceConfigDAO.merge(serviceConfigEntity);
}
stateUpdateEventPublisher.publish(new ConfigsUpdateEvent(serviceConfigEntity,
- configGroup == null ? null : configGroup.getName(), groupHostNames, changedConfigs));
+ configGroup == null ? null : configGroup.getName(), groupHostNames, changedConfigs.keySet()));
+ configHelper.checkStaleConfigsStatusOnConfigsUpdate(clusterEntity.getClusterId(), serviceName, groupHostNames, changedConfigs);
} finally {
clusterGlobalLock.writeLock().unlock();
}
@@ -1895,7 +1896,7 @@ public class ClusterImpl implements Cluster {
throw new IllegalArgumentException("Config group {} doesn't exist");
}
}
- Set<String> changedConfigs = getChangedConfigTypes(serviceConfigEntity,
+ Map<String, Collection<String>> changedConfigs = configHelper.getChangedConfigTypes(this, serviceConfigEntity,
serviceConfigEntity.getGroupId(), clusterId, serviceName);
ClusterEntity clusterEntity = getClusterEntity();
@@ -1926,13 +1927,14 @@ public class ClusterImpl implements Cluster {
stateUpdateEventPublisher.publish(new ConfigsUpdateEvent(serviceConfigEntityClone,
configGroupName,
groupHostNames,
- changedConfigs));
+ changedConfigs.keySet()));
+ configHelper.checkStaleConfigsStatusOnConfigsUpdate(clusterEntity.getClusterId(), serviceName, groupHostNames, changedConfigs);
return convertToServiceConfigVersionResponse(serviceConfigEntityClone);
}
@Transactional
- ServiceConfigVersionResponse applyConfigs(Set<Config> configs, String user, String serviceConfigVersionNote) {
+ ServiceConfigVersionResponse applyConfigs(Set<Config> configs, String user, String serviceConfigVersionNote) throws AmbariException {
List<ClusterConfigEntity> appliedConfigs = new ArrayList<>();
String serviceName = null;
@@ -1992,7 +1994,7 @@ public class ClusterImpl implements Cluster {
}
private ServiceConfigVersionResponse createServiceConfigVersion(String serviceName, String user,
- String serviceConfigVersionNote) {
+ String serviceConfigVersionNote) throws AmbariException {
//create next service config version
return createServiceConfigVersion(serviceName, user, serviceConfigVersionNote, null);
}
@@ -2796,72 +2798,6 @@ public class ClusterImpl implements Cluster {
}
/**
- * Calculates cluster config types were changed during configs change.
- * @param currentServiceConfigEntity service config entity with populated current cluster configs
- * @param configGroupId id of config group contained changed configs. Can be null in case group is default
- * @param clusterId cluster id
- * @param serviceName service name configs were changed for
- * @return set of type names of cluster configs were changed
- */
- private Set<String> getChangedConfigTypes(ServiceConfigEntity currentServiceConfigEntity,
- Long configGroupId, Long clusterId, String serviceName) {
- ServiceConfigEntity previousServiceConfigEntity;
- List<ClusterConfigEntity> previousConfigEntities = new ArrayList<>();
- List<ClusterConfigEntity> currentConfigEntities = new ArrayList<>();
- currentConfigEntities.addAll(currentServiceConfigEntity.getClusterConfigEntities());
- // Retrieve group cluster configs
- if (configGroupId != null) {
- previousServiceConfigEntity =
- serviceConfigDAO.getLastServiceConfigVersionsForGroup(configGroupId);
- if (previousServiceConfigEntity != null) {
- previousConfigEntities.addAll(previousServiceConfigEntity.getClusterConfigEntities());
- }
- }
- // Service config with custom group contains not all config types, so it is needed
- // to complement it with configs from default group
- previousServiceConfigEntity =
- serviceConfigDAO.getLastServiceConfigForServiceDefaultGroup(clusterId, serviceName);
- if (previousServiceConfigEntity != null) {
- for (ClusterConfigEntity clusterConfigEntity : previousServiceConfigEntity.getClusterConfigEntities()) {
- // Add only configs not present yet
- ClusterConfigEntity exist =
- previousConfigEntities.stream()
- .filter(c -> c.getType().equals(clusterConfigEntity.getType())).findAny().orElse(null);
- if (exist == null) {
- previousConfigEntities.add(clusterConfigEntity);
- }
- // Complement current custom group service config to correct comparing
- if (configGroupId != null) {
- exist = currentConfigEntities.stream()
- .filter(c -> c.getType().equals(clusterConfigEntity.getType())).findAny().orElse(null);
- if (exist == null) {
- currentConfigEntities.add(clusterConfigEntity);
- }
- }
- }
- }
- Map<String, String> previousConfigs = new HashMap<>();
- Map<String, String> currentConfigs = new HashMap<>();
- for (ClusterConfigEntity clusterConfigEntity : currentConfigEntities) {
- currentConfigs.put(clusterConfigEntity.getType(), clusterConfigEntity.getData());
- }
- for (ClusterConfigEntity clusterConfigEntity : previousConfigEntities) {
- previousConfigs.put(clusterConfigEntity.getType(), clusterConfigEntity.getData());
- }
- // Get diff for current and previous sets of cluster configs
- Set<Entry<String, String>> diff1 = new HashSet<>(currentConfigs.entrySet());
- Set<Entry<String, String>> diff2 = new HashSet<>(previousConfigs.entrySet());
- diff1.removeAll(previousConfigs.entrySet());
- diff2.removeAll(currentConfigs.entrySet());
- diff1.addAll(diff2);
- Set<String> changedConfigs = new HashSet<>();
- for (Entry<String, String> diff : diff1) {
- changedConfigs.add(diff.getKey());
- }
- return changedConfigs;
- }
-
- /**
* {@inheritDoc}
*/
@Override
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index ef7d471..727b3ba 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -20,11 +20,9 @@ package org.apache.ambari.server.state.svccomphost;
import java.text.MessageFormat;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -47,6 +45,7 @@ import org.apache.ambari.server.events.HostComponentsUpdateEvent;
import org.apache.ambari.server.events.MaintenanceModeEvent;
import org.apache.ambari.server.events.ServiceComponentInstalledEvent;
import org.apache.ambari.server.events.ServiceComponentUninstalledEvent;
+import org.apache.ambari.server.events.StaleConfigsUpdateEvent;
import org.apache.ambari.server.events.TopologyUpdateEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.events.publishers.StateUpdateEventPublisher;
@@ -84,7 +83,6 @@ import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.UpgradeState;
import org.apache.ambari.server.state.alert.AlertDefinitionHash;
-import org.apache.ambari.server.state.configgroup.ConfigGroup;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.fsm.SingleArcTransition;
import org.apache.ambari.server.state.fsm.StateMachine;
@@ -912,7 +910,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
stateEntity = hostComponentStateDAO.merge(stateEntity);
if (!oldState.equals(state)) {
stateUpdateEventPublisher.publish(new HostComponentsUpdateEvent(Collections.singletonList(
- new HostComponentUpdate(stateEntity, oldState))));
+ HostComponentUpdate.createHostComponentStatusUpdate(stateEntity, oldState))));
}
} else {
LOG.warn("Setting a member on an entity object that may have been "
@@ -1043,7 +1041,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
stateEntity = hostComponentStateDAO.merge(stateEntity);
if (statusUpdated) {
stateUpdateEventPublisher.publish(new HostComponentsUpdateEvent(Collections.singletonList(
- new HostComponentUpdate(stateEntity, oldState))));
+ HostComponentUpdate.createHostComponentStatusUpdate(stateEntity, oldState))));
}
// TODO Audit logs
} catch (InvalidStateTransitionException e) {
@@ -1256,6 +1254,12 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
r.setActualConfigs(actualConfigs);
r.setUpgradeState(upgradeState);
+ try {
+ r.setStaleConfig(helper.isStaleConfigs(this, desiredConfigs, hostComponentDesiredStateEntity));
+ } catch (Exception e) {
+ LOG.error("Could not determine stale config", e);
+ }
+
return r;
}
@@ -1418,47 +1422,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
}
@Override
- public void updateActualConfigs(Map<String, Map<String, String>> configTags) {
- Map<Long, ConfigGroup> configGroupMap;
- String clusterName = getClusterName();
- try {
- Cluster cluster = clusters.getCluster(clusterName);
- configGroupMap = cluster.getConfigGroups();
- } catch (AmbariException e) {
- LOG.warn("Unable to find cluster, " + clusterName);
- return;
- }
-
- LOG.debug("Updating configuration tags for {}: {}", hostName, configTags);
- final ConcurrentMap<String, HostConfig> newActualConfigs = new ConcurrentHashMap<>();
-
- for (Entry<String, Map<String, String>> entry : configTags.entrySet()) {
- String type = entry.getKey();
- Map<String, String> values = new HashMap<>(entry.getValue());
-
- String tag = values.get(ConfigHelper.CLUSTER_DEFAULT_TAG);
- values.remove(ConfigHelper.CLUSTER_DEFAULT_TAG);
-
- HostConfig hc = new HostConfig();
- hc.setDefaultVersionTag(tag);
- newActualConfigs.put(type, hc);
-
- if (!values.isEmpty()) {
- for (Entry<String, String> overrideEntry : values.entrySet()) {
- Long groupId = Long.parseLong(overrideEntry.getKey());
- hc.getConfigGroupOverrides().put(groupId, overrideEntry.getValue());
- if (!configGroupMap.containsKey(groupId)) {
- LOG.debug("Config group does not exist, id = {}", groupId);
- }
- }
- }
- }
-
- // update internal stateful collection in an "atomic" manner
- actualConfigs = newActualConfigs;
- }
-
- @Override
public Map<String, HostConfig> getActualConfigs() {
return actualConfigs;
}
@@ -1524,6 +1487,14 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
@Override
@Transactional
public void setRestartRequired(boolean restartRequired) {
+ if (setRestartRequiredWithoutEventPublishing(restartRequired)) {
+ eventPublisher.publish(new StaleConfigsUpdateEvent(this, restartRequired));
+ }
+ }
+
+ @Override
+ @Transactional
+ public boolean setRestartRequiredWithoutEventPublishing(boolean restartRequired) {
LOG.debug("Set RestartRequired on serviceName = {} componentName = {} hostName = {} to {}",
getServiceName(), getServiceComponentName(), getHostName(), restartRequired);
@@ -1531,11 +1502,13 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
if (desiredStateEntity != null) {
desiredStateEntity.setRestartRequired(restartRequired);
hostComponentDesiredStateDAO.merge(desiredStateEntity);
+ return true;
} else {
LOG.warn("Setting a member on an entity object that may have been "
+ "previously deleted, serviceName = " + getServiceName() + ", " + "componentName = "
+ getServiceComponentName() + ", hostName = " + getHostName());
}
+ return false;
}
@Transactional
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index a1f28f1..13088a4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -2545,9 +2545,9 @@ public class AmbariManagementControllerTest {
sch1.setDesiredState(State.INSTALLED);
sch1.setState(State.INSTALLING);
- sch1.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
+ /*sch1.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
put("global", new HashMap<String,String>() {{ put("tag", "version1"); }});
- }});
+ }});*/
ServiceComponentHostRequest r =
@@ -2642,11 +2642,11 @@ public class AmbariManagementControllerTest {
}};
Service s1 = clusters.getCluster(cluster1).getService(serviceName);
- s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
+ /*s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
s1.getServiceComponent(componentName2).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
s1.getServiceComponent(componentName3).getServiceComponentHost(host1).updateActualConfigs(actualConfigOld);
s1.getServiceComponent(componentName2).getServiceComponentHost(host2).updateActualConfigs(actualConfigOld);
- s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);
+ s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);*/
ServiceComponentHostRequest r =
new ServiceComponentHostRequest(cluster1, null, null, null, null);
@@ -10066,11 +10066,11 @@ public class AmbariManagementControllerTest {
};
Service s1 = clusters.getCluster(cluster1).getService(serviceName);
- s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
+ /*s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
s1.getServiceComponent(componentName2).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
s1.getServiceComponent(componentName3).getServiceComponentHost(host1).updateActualConfigs(actualConfigOld);
s1.getServiceComponent(componentName2).getServiceComponentHost(host2).updateActualConfigs(actualConfigOld);
- s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);
+ s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);*/
ServiceComponentHostRequest r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
index ef186f1..8578c23 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
@@ -257,9 +257,9 @@ public class RefreshYarnCapacitySchedulerReleaseConfigTest {
ServiceComponent rm = service.getServiceComponent(componentName);
ServiceComponentHost rmc1 = rm.getServiceComponentHost(hostname);
- rmc1.updateActualConfigs((new HashMap<String, Map<String,String>>() {{
+ /*rmc1.updateActualConfigs((new HashMap<String, Map<String,String>>() {{
put("capacity-scheduler", new HashMap<String,String>() {{ put("tag", "version1"); }});
put("hive-group", new HashMap<String,String>() {{ put("tag", "version1"); }});
- }}));
+ }}));*/
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/eaa7e7e9/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index 48864cc..9c10fef 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -562,7 +562,7 @@ public class ServiceComponentHostTest {
put(configGroup.getId().toString(), "version2"); }});
}};
- sch.updateActualConfigs(actual);
+ //sch.updateActualConfigs(actual);
Map<String, HostConfig> confirm = sch.getActualConfigs();
@@ -746,9 +746,9 @@ public class ServiceComponentHostTest {
put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version0"); }});
}};
- sch1.updateActualConfigs(actual);
+ /*sch1.updateActualConfigs(actual);
sch2.updateActualConfigs(actual);
- sch3.updateActualConfigs(actual);
+ sch3.updateActualConfigs(actual);*/
makeConfig(cluster, "foo", "version1",
new HashMap<String,String>() {{ put("a", "c"); }}, new HashMap<>());
@@ -766,12 +766,12 @@ public class ServiceComponentHostTest {
actual.put("hdfs-site", new HashMap<String, String>() {{ put ("tag", "version1"); }});
- sch1.updateActualConfigs(actual);
+ //sch1.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site up to date, only for sch1
Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
Assert.assertTrue(sch2.convertToResponse(null).isStaleConfig());
- sch2.updateActualConfigs(actual);
+ //sch2.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site up to date for both
Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
@@ -785,8 +785,8 @@ public class ServiceComponentHostTest {
Assert.assertTrue(sch2.convertToResponse(null).isStaleConfig());
actual.get("hdfs-site").put("tag", "version2");
- sch1.updateActualConfigs(actual);
- sch2.updateActualConfigs(actual);
+ /*sch1.updateActualConfigs(actual);
+ sch2.updateActualConfigs(actual);*/
//reset restartRequired flag + invalidating isStale cache
// after start/restart command execution completed
sch1.setRestartRequired(false);
@@ -814,12 +814,12 @@ public class ServiceComponentHostTest {
Assert.assertTrue(sch2.convertToResponse(null).isStaleConfig());
actual.get("hdfs-site").put(configGroup.getId().toString(), "version3");
- sch2.updateActualConfigs(actual);
+ //sch2.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site updated host to changed property
Assert.assertTrue(sch1.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
- sch1.updateActualConfigs(actual);
+ //sch1.updateActualConfigs(actual);
// HDP-x/HDFS/hdfs-site updated host to changed property
Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
@@ -834,7 +834,7 @@ public class ServiceComponentHostTest {
Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
Assert.assertTrue(sch3.convertToResponse(null).isStaleConfig());
- sch3.updateActualConfigs(actual);
+ //sch3.updateActualConfigs(actual);
Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
@@ -855,7 +855,7 @@ public class ServiceComponentHostTest {
put("tag", "version1");
}});
- sch1.updateActualConfigs(actual);
+ //sch1.updateActualConfigs(actual);
final Config c1 = configFactory.createNew(cluster, "core-site", "version2",
new HashMap<String, String>() {{ put("fs.trash.interval", "400"); }},
@@ -875,18 +875,18 @@ public class ServiceComponentHostTest {
tags.put("tag", "version1");
tags.put(id.toString(), "version2");
actual.put("core-site", tags);
- sch3.updateActualConfigs(actual);
+ //sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
cluster.deleteConfigGroup(id);
Assert.assertNull(cluster.getConfigGroups().get(id));
- sch3.updateActualConfigs(actual);
+ //sch3.updateActualConfigs(actual);
Assert.assertTrue(sch3.convertToResponse(null).isStaleConfig());
tags.remove(id.toString());
- sch3.updateActualConfigs(actual);
+ //sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
}
@@ -939,9 +939,9 @@ public class ServiceComponentHostTest {
put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
}};
- sch1.updateActualConfigs(actual);
+ /*sch1.updateActualConfigs(actual);
sch2.updateActualConfigs(actual);
- sch3.updateActualConfigs(actual);
+ sch3.updateActualConfigs(actual);*/
makeConfig(cluster, "mapred-site", "version1",
new HashMap<String,String>() {{ put("a", "c"); }},new HashMap<String, Map<String,String>>(){{
@@ -958,7 +958,7 @@ public class ServiceComponentHostTest {
put("mapred-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
}};
sch3.setRestartRequired(false);
- sch3.updateActualConfigs(actual);
+ //sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
// Now add config-attributes
@@ -1012,7 +1012,7 @@ public class ServiceComponentHostTest {
* @param tag the config tag
* @param values the values for the config
*/
- private void makeConfig(Cluster cluster, String type, String tag, Map<String, String> values, Map<String, Map<String, String>> attributes) {
+ private void makeConfig(Cluster cluster, String type, String tag, Map<String, String> values, Map<String, Map<String, String>> attributes) throws AmbariException {
Config config = configFactory.createNew(cluster, type, tag, values, attributes);
cluster.addDesiredConfig("user", Collections.singleton(config));
}