Repository: ambari Updated Branches: refs/heads/trunk ae1a98198 -> 82c13df40
AMBARI-18907: Auto-start should respect maintenance mode on hosts and services Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/82c13df4 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/82c13df4 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/82c13df4 Branch: refs/heads/trunk Commit: 82c13df406b3e4d28e2b6242d29113fa96f015fe Parents: ae1a981 Author: Nahappan Somasundaram <nsomasunda...@hortonworks.com> Authored: Wed Nov 16 14:30:37 2016 -0800 Committer: Nahappan Somasundaram <nsomasunda...@hortonworks.com> Committed: Wed Nov 16 17:34:58 2016 -0800 ---------------------------------------------------------------------- .../server/agent/RecoveryConfigHelper.java | 71 +++++++++++++++++--- .../server/events/MaintenanceModeEvent.java | 30 +++++++-- .../ambari/server/state/host/HostImpl.java | 2 +- .../AlertMaintenanceModeListenerTest.java | 2 +- 4 files changed, 89 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/82c13df4/ambari-server/src/main/java/org/apache/ambari/server/agent/RecoveryConfigHelper.java ---------------------------------------------------------------------- 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 7d6a7f5..9d5bae7d 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 @@ -35,7 +35,9 @@ import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; +import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.MaintenanceState; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.ServiceComponentHost; import org.apache.commons.lang.StringUtils; @@ -160,7 +162,7 @@ public class RecoveryConfigHelper { } /** - * Maintenance mode of a service component host changed. + * Maintenance mode of a host, service or service component host changed. * @param event * @throws AmbariException */ @@ -168,10 +170,44 @@ public class RecoveryConfigHelper { @AllowConcurrentEvents public void handleMaintenanceModeEvent(MaintenanceModeEvent event) throws AmbariException { - ServiceComponentHost sch = event.getServiceComponentHost(); + if (event.getHost() != null) { + /* + * If any one component in the host is recovery enabled, + * invalidate the host timestamp. + */ + Cluster cluster = clusters.getCluster(event.getClusterId()); + if (cluster == null) { + return; + } + + Host host = event.getHost(); + List<ServiceComponentHost> scHosts = cluster.getServiceComponentHosts(host.getHostName()); + for (ServiceComponentHost sch : scHosts) { + if (sch.isRecoveryEnabled()) { + invalidateRecoveryTimestamp(sch.getClusterName(), sch.getHostName()); + break; + } + } + } + else if (event.getService() != null) { + /** + * Simply invalidate all the hosts in the cluster. + * The recovery config will be sent to all the hosts + * even if some of the hosts do not have components + * in recovery mode. + * Looping through all the hosts and its components + * to determine which host to send the recovery config + * may not be efficient. + */ + Service service = event.getService(); + invalidateRecoveryTimestamp(service.getCluster().getClusterName(), null); + } + else if (event.getServiceComponentHost() != null) { + ServiceComponentHost sch = event.getServiceComponentHost(); - if (sch != null && sch.isRecoveryEnabled()) { - invalidateRecoveryTimestamp(sch.getClusterName(), sch.getHostName()); + if (sch.isRecoveryEnabled()) { + invalidateRecoveryTimestamp(sch.getClusterName(), sch.getHostName()); + } } } @@ -281,14 +317,31 @@ public class RecoveryConfigHelper { * maintenance mode. * @return */ - private List<String> getEnabledComponents(String hostname) { + private List<String> getEnabledComponents(String hostname) throws AmbariException { List<String> enabledComponents = new ArrayList<>(); - if (cluster != null) { - List<ServiceComponentHost> scHosts = cluster.getServiceComponentHosts(hostname); + if (cluster == null) { + return enabledComponents; + } + + Host host = clusters.getHost(hostname); + if (host == null) { + return enabledComponents; + } + + // if host is in maintenance mode then ignore all the components for auto start + if (host.getMaintenanceState(cluster.getClusterId()) == MaintenanceState.ON) { + return enabledComponents; + } + + List<ServiceComponentHost> scHosts = cluster.getServiceComponentHosts(hostname); + + for (ServiceComponentHost sch : scHosts) { + if (sch.isRecoveryEnabled()) { + Service service = cluster.getService(sch.getServiceName()); - for (ServiceComponentHost sch : scHosts) { - if (sch.isRecoveryEnabled()) { + // service should not be in maintenance mode + if (service.getMaintenanceState() == MaintenanceState.OFF) { // Keep the components that are not in maintenance mode. if (sch.getMaintenanceState() == MaintenanceState.OFF) { enabledComponents.add(sch.getServiceComponentName()); http://git-wip-us.apache.org/repos/asf/ambari/blob/82c13df4/ambari-server/src/main/java/org/apache/ambari/server/events/MaintenanceModeEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/MaintenanceModeEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/MaintenanceModeEvent.java index 43b3f79..3d0b6ac 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/MaintenanceModeEvent.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/MaintenanceModeEvent.java @@ -55,6 +55,11 @@ public class MaintenanceModeEvent extends AmbariEvent { private final ServiceComponentHost m_serviceComponentHost; /** + * The cluster to which the host, service or component belongs to. + */ + private final long m_clusterId; + + /** * Constructor. * * @param state @@ -63,7 +68,7 @@ public class MaintenanceModeEvent extends AmbariEvent { * the service that changed maintenance state (not {@code null})). */ public MaintenanceModeEvent(MaintenanceState state, Service service) { - this(state, service, null, null); + this(state, service.getClusterId(), service, null, null); } /** @@ -71,11 +76,13 @@ public class MaintenanceModeEvent extends AmbariEvent { * * @param state * the new state (not {@code null}). + * @param clusterId + * the cluster to which the host belongs to (not {@code -1}). * @param host * the host that changed maintenance state (not {@code null})). */ - public MaintenanceModeEvent(MaintenanceState state, Host host) { - this(state, null, host, null); + public MaintenanceModeEvent(MaintenanceState state, long clusterId, Host host) { + this(state, clusterId, null, host, null); } /** @@ -88,7 +95,7 @@ public class MaintenanceModeEvent extends AmbariEvent { */ public MaintenanceModeEvent(MaintenanceState state, ServiceComponentHost serviceComponentHost) { - this(state, null, null, serviceComponentHost); + this(state, serviceComponentHost.getClusterId(), null, null, serviceComponentHost); } /** @@ -96,6 +103,8 @@ public class MaintenanceModeEvent extends AmbariEvent { * * @param state * the new state (not {@code null}). + * @param clusterId + * the cluster to which the host, service or component belongs to. * @param service * the service that changed maintenance state, or {@code null}. * @param host @@ -103,10 +112,11 @@ public class MaintenanceModeEvent extends AmbariEvent { * @param serviceComponentHost * the component that changed maintenance state, or {@code null}. */ - private MaintenanceModeEvent(MaintenanceState state, Service service, + private MaintenanceModeEvent(MaintenanceState state, long clusterId, Service service, Host host, ServiceComponentHost serviceComponentHost) { super(AmbariEventType.MAINTENANCE_MODE); m_state = state; + m_clusterId = clusterId; m_service = service; m_host = host; m_serviceComponentHost = serviceComponentHost; @@ -152,6 +162,16 @@ public class MaintenanceModeEvent extends AmbariEvent { } /** + * Gets the cluster id for the host, service or component + * that had the direct maintenance mode event,. + * + * @return the cluster id + */ + public long getClusterId() { + return m_clusterId; + } + + /** * {@inheritDoc} */ @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/82c13df4/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java index e66759e..dd5e635 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java @@ -1120,7 +1120,7 @@ public class HostImpl implements Host { hostStateDAO.merge(hostStateEntity); // broadcast the maintenance mode change - MaintenanceModeEvent event = new MaintenanceModeEvent(state, this); + MaintenanceModeEvent event = new MaintenanceModeEvent(state, clusterId, this); eventPublisher.publish(event); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/82c13df4/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java index 7757cdf..7de9823 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java @@ -104,7 +104,7 @@ public class AlertMaintenanceModeListenerTest { EasyMock.replay(hostAlert, serviceAlert, componentAlert, host, m_alertsDAO); - MaintenanceModeEvent hostEvent = new MaintenanceModeEvent(MaintenanceState.ON, host); + MaintenanceModeEvent hostEvent = new MaintenanceModeEvent(MaintenanceState.ON, 1 /* cluster id */, host); m_eventPublisher.publish(hostEvent); EasyMock.verify(hostAlert, serviceAlert, componentAlert, host, m_alertsDAO);