Repository: ambari Updated Branches: refs/heads/trunk a10e3887c -> a5291abd9
Revert "AMBARI-21898. Property provider in-memory maps are refreshed too slowly after config updates. (swagle)" This reverts commit 8cb942393ce15efb5f6fbc9f594287c30971c296. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a5291abd Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a5291abd Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a5291abd Branch: refs/heads/trunk Commit: a5291abd9717aa0c97562c264effc1d330a4e129 Parents: a10e388 Author: Jonathan Hurley <[email protected]> Authored: Thu Sep 7 12:25:06 2017 -0400 Committer: Jonathan Hurley <[email protected]> Committed: Thu Sep 7 12:34:55 2017 -0400 ---------------------------------------------------------------------- .../internal/AbstractProviderModule.java | 93 ++++++++++++-------- .../org/apache/ambari/server/state/Cluster.java | 5 -- .../server/state/cluster/ClusterImpl.java | 13 +-- 3 files changed, 60 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a5291abd/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 e0df487..77549f5 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; @@ -247,8 +244,6 @@ public abstract class AbstractProviderModule implements ProviderModule, @Inject protected AmbariEventPublisher eventPublisher; - @Inject - private Clusters clusters; /** * The map of host components. @@ -263,7 +258,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; @@ -521,19 +517,16 @@ public abstract class AbstractProviderModule implements ProviderModule, @Override public String getPort(String clusterName, String componentName, String hostName, boolean httpsEnabled) throws SystemException { // Parent map need not be synchronized - ConcurrentMap<String, ConcurrentMap<String, String>> clusterJmxPorts; - // Still need double check to ensure single init - if (!jmxPortMap.containsKey(clusterName)) { + ConcurrentMap<String, ConcurrentMap<String, String>> clusterJmxPorts = jmxPortMap.get(clusterName); + if (clusterJmxPorts == null) { synchronized (jmxPortMap) { - if (!jmxPortMap.containsKey(clusterName)) { + clusterJmxPorts = jmxPortMap.get(clusterName); + if (clusterJmxPorts == null) { clusterJmxPorts = new ConcurrentHashMap<>(); jmxPortMap.put(clusterName, clusterJmxPorts); } } } - - clusterJmxPorts = jmxPortMap.get(clusterName); - Service.Type service = componentServiceMap.get(componentName); if (service != null) { @@ -865,34 +858,49 @@ public abstract class AbstractProviderModule implements ProviderModule, } } - // TODO: Fix for multi-service feature support (trunk) - // Called from a synchornized block ! private void initProviderMaps() throws SystemException { + ResourceProvider provider = getResourceProvider(Resource.Type.Cluster); - jmxPortMap.clear(); - clusterHostComponentMap = new HashMap<>(); - clusterGangliaCollectorMap = new HashMap<>(); + Set<String> propertyIds = new HashSet<>(); + propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID); - Map<String, Cluster> clusterMap = clusters.getClusters(); - if (MapUtils.isEmpty(clusterMap)) { - return; - } + Map<String, String> requestInfoProperties = new HashMap<>(); + requestInfoProperties.put(ClusterResourceProvider.GET_IGNORE_PERMISSIONS_PROPERTY_ID, "true"); - for (Cluster cluster : clusterMap.values()) { - String clusterName = cluster.getClusterName(); + Request request = PropertyHelper.getReadRequest(propertyIds, + requestInfoProperties, null, null, null); - Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName); - if (hostComponentMap == null) { - hostComponentMap = new HashMap<>(); - clusterHostComponentMap.put(clusterName, hostComponentMap); - } + try { + jmxPortMap.clear(); + Set<Resource> clusters = provider.getResources(request, null); + + clusterHostComponentMap = new HashMap<>(); + clusterGangliaCollectorMap = new HashMap<>(); + + for (Resource cluster : clusters) { + + String clusterName = (String) cluster.getPropertyValue(CLUSTER_NAME_PROPERTY_ID); - List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(); + // initialize the host component map and Ganglia server from the known hosts components... + provider = getResourceProvider(Resource.Type.HostComponent); - if (!CollectionUtils.isEmpty(serviceComponentHosts)) { - for (ServiceComponentHost sch : serviceComponentHosts) { - String componentName = sch.getServiceComponentName(); - String hostName = sch.getHostName(); + 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<>(); + 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); @@ -902,11 +910,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/a5291abd/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 90dd611..9597ba1 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/a5291abd/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 8f1a882..3953184 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 @@ -554,17 +554,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
