Repository: ambari Updated Branches: refs/heads/branch-2.6 3471d44b4 -> 196e6ed04
Revert "AMBARI-21898. Property provider in-memory maps are refreshed too slowly after config updates. (swagle)" This reverts commit 854d7000f3bfd2c1e237ee29e46c0bdd95356bee. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/196e6ed0 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/196e6ed0 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/196e6ed0 Branch: refs/heads/branch-2.6 Commit: 196e6ed048cd35bd3e30d8b8c7c1e4bce9c96297 Parents: 3471d44 Author: Jonathan Hurley <[email protected]> Authored: Thu Sep 7 12:24:47 2017 -0400 Committer: Jonathan Hurley <[email protected]> Committed: Thu Sep 7 12:35:19 2017 -0400 ---------------------------------------------------------------------- .../internal/AbstractProviderModule.java | 100 ++++++++++++------- .../org/apache/ambari/server/state/Cluster.java | 5 - .../server/state/cluster/ClusterImpl.java | 13 +-- 3 files changed, 64 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/196e6ed0/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java index 3b2187e..5fc4c31 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java @@ -67,9 +67,6 @@ import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponentHost; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -246,8 +243,6 @@ public abstract class AbstractProviderModule implements ProviderModule, @Inject protected AmbariEventPublisher eventPublisher; - @Inject - private Clusters clusters; /** * The map of host components. @@ -262,7 +257,8 @@ public abstract class AbstractProviderModule implements ProviderModule, /** * JMX ports read from the configs */ - private final Map<String, ConcurrentMap<String, ConcurrentMap<String, String>>> jmxPortMap = new ConcurrentHashMap<>(1); + private final Map<String, ConcurrentMap<String, ConcurrentMap<String, String>> >jmxPortMap = + Collections.synchronizedMap(new HashMap<String, ConcurrentMap<String, ConcurrentMap<String, String>>>()); private volatile boolean initialized = false; @@ -519,19 +515,17 @@ public abstract class AbstractProviderModule implements ProviderModule, @Override public String getPort(String clusterName, String componentName, String hostName, boolean httpsEnabled) throws SystemException { - ConcurrentMap<String, ConcurrentMap<String, String>> clusterJmxPorts; - // Still need double check to ensure single init - if (!jmxPortMap.containsKey(clusterName)) { + // Parent map need not be synchronized + ConcurrentMap<String, ConcurrentMap<String, String>> clusterJmxPorts = jmxPortMap.get(clusterName); + if (clusterJmxPorts == null) { synchronized (jmxPortMap) { - if (!jmxPortMap.containsKey(clusterName)) { - clusterJmxPorts = new ConcurrentHashMap<>(); + clusterJmxPorts = jmxPortMap.get(clusterName); + if (clusterJmxPorts == null) { + clusterJmxPorts = new ConcurrentHashMap<String, ConcurrentMap<String, String>>(); jmxPortMap.put(clusterName, clusterJmxPorts); } } } - - clusterJmxPorts = jmxPortMap.get(clusterName); - Service.Type service = componentServiceMap.get(componentName); if (service != null) { @@ -857,40 +851,55 @@ public abstract class AbstractProviderModule implements ProviderModule, if (initialized) { synchronized (this) { if (initialized) { - LOG.info("Resetting property provider maps to reflect changes in " + - "cluster state"); initialized = false; } } } } - // TODO: Fix for multi-service feature support (trunk) - // Called from a synchornized block ! private void initProviderMaps() throws SystemException { - jmxPortMap.clear(); - clusterHostComponentMap = new HashMap<>(); - clusterGangliaCollectorMap = new HashMap<>(); + ResourceProvider provider = getResourceProvider(Resource.Type.Cluster); - Map<String, Cluster> clusterMap = clusters.getClusters(); - if (MapUtils.isEmpty(clusterMap)) { - return; - } + Set<String> propertyIds = new HashSet<String>(); + propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID); - for (Cluster cluster : clusterMap.values()) { - String clusterName = cluster.getClusterName(); - Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName); + Map<String, String> requestInfoProperties = new HashMap<String, String>(); + requestInfoProperties.put(ClusterResourceProvider.GET_IGNORE_PERMISSIONS_PROPERTY_ID, "true"); - if (hostComponentMap == null) { - hostComponentMap = new HashMap<>(); - clusterHostComponentMap.put(clusterName, hostComponentMap); - } + Request request = PropertyHelper.getReadRequest(propertyIds, + requestInfoProperties, null, null, null); + + try { + jmxPortMap.clear(); + Set<Resource> clusters = provider.getResources(request, null); + + clusterHostComponentMap = new HashMap<String, Map<String, String>>(); + clusterGangliaCollectorMap = new HashMap<String, String>(); + + for (Resource cluster : clusters) { + + String clusterName = (String) cluster.getPropertyValue(CLUSTER_NAME_PROPERTY_ID); - List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(); - if (!CollectionUtils.isEmpty(serviceComponentHosts)) { - for (ServiceComponentHost sch : serviceComponentHosts) { - String componentName = sch.getServiceComponentName(); - String hostName = sch.getHostName(); + // initialize the host component map and Ganglia server from the known hosts components... + provider = getResourceProvider(Resource.Type.HostComponent); + + request = PropertyHelper.getReadRequest(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, + HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID); + + Predicate predicate = new PredicateBuilder().property(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID). + equals(clusterName).toPredicate(); + + Set<Resource> hostComponents = provider.getResources(request, predicate); + Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName); + + if (hostComponentMap == null) { + hostComponentMap = new HashMap<String, String>(); + clusterHostComponentMap.put(clusterName, hostComponentMap); + } + + for (Resource hostComponent : hostComponents) { + String componentName = (String) hostComponent.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID); + String hostName = (String) hostComponent.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID); hostComponentMap.put(componentName, hostName); @@ -900,11 +909,26 @@ public abstract class AbstractProviderModule implements ProviderModule, } if (componentName.equals(METRIC_SERVER)) { // If current collector host is null or if the host or the host component not live - // Update clusterMetricCollectorMap. + // Update clusterMetricCollectorMap. metricsCollectorHAManager.addCollectorHost(clusterName, hostName); } } } + } catch (UnsupportedPropertyException e) { + if (LOG.isErrorEnabled()) { + LOG.error("Caught UnsupportedPropertyException while trying to get the host mappings.", e); + } + throw new SystemException("An exception occurred while initializing the host mappings: " + e, e); + } catch (NoSuchResourceException e) { + if (LOG.isErrorEnabled()) { + LOG.error("Caught NoSuchResourceException exception while trying to get the host mappings.", e); + } + throw new SystemException("An exception occurred while initializing the host mappings: " + e, e); + } catch (NoSuchParentResourceException e) { + if (LOG.isErrorEnabled()) { + LOG.error("Caught NoSuchParentResourceException exception while trying to get the host mappings.", e); + } + throw new SystemException("An exception occurred while initializing the host mappings: " + e, e); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/196e6ed0/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 15efcd2..ee18fdf 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 @@ -119,11 +119,6 @@ public interface Cluster { List<ServiceComponentHost> getServiceComponentHosts(String serviceName, String componentName); /** - * Get all ServiceComponentHosts for this cluster. - */ - List<ServiceComponentHost> getServiceComponentHosts(); - - /** * Get all hosts associated with this cluster. * * @return collection of hosts that are associated with this cluster http://git-wip-us.apache.org/repos/asf/ambari/blob/196e6ed0/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 951edce..2f858b8 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 @@ -558,17 +558,8 @@ public class ClusterImpl implements Cluster { throw new ServiceComponentHostNotFoundException(getClusterName(), serviceName, serviceComponentName, hostname); } - return serviceComponentHosts.get(serviceName).get(serviceComponentName).get(hostname); - } - - public List<ServiceComponentHost> getServiceComponentHosts() { - List<ServiceComponentHost> serviceComponentHosts = new ArrayList<>(); - if (!serviceComponentHostsByHost.isEmpty()) { - for (List<ServiceComponentHost> schList : serviceComponentHostsByHost.values()) { - serviceComponentHosts.addAll(schList); - } - } - return Collections.unmodifiableList(serviceComponentHosts); + return serviceComponentHosts.get(serviceName).get(serviceComponentName).get( + hostname); } @Override
