@Test public void testReadResourceManagerHA() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(false); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); Config config1 = createNiceMock(Config.class); Config config2 = createNiceMock(Config.class); Map<String, String> map = new HashMap<>(); map.put("yarn.http.policy", "HTTPS_ONLY"); map.put("yarn.resourcemanager.ha.rm-ids", "rm1,rm2"); map.put("yarn.resourcemanager.hostname.rm1", "lc6402.ambari.apache.org"); map.put("yarn.resourcemanager.hostname.rm2", "lc6403.ambari.apache.org"); map.put("yarn.resourcemanager.webapp.address.rm1", "lc6402.ambari.apache.org:8099"); map.put("yarn.resourcemanager.webapp.address.rm2", "lc6403.ambari.apache.org:8099"); map.put("yarn.resourcemanager.webapp.https.address.rm1", "lc6402.ambari.apache.org:8066"); map.put("yarn.resourcemanager.webapp.https.address.rm2", "lc6403.ambari.apache.org:8066"); expect(clusters.getCluster("testCluster")).andReturn(cluster); expect(cluster.getDesiredConfigByType("yarn-site")).andReturn(config1).anyTimes(); expect(cluster.getDesiredConfigByType("core-site")).andReturn(config2).anyTimes(); expect(config1.getProperties()).andReturn(map).anyTimes(); expect(config2.getProperties()).andReturn(new HashMap<String, String>()).anyTimes(); replay(clusters, cluster, config1, config2); HttpPropertyProvider propProvider = new HttpPropertyProvider( streamProvider, clusters, PROPERTY_ID_CLUSTER_NAME, PROPERTY_ID_HOST_NAME, PROPERTY_ID_COMPONENT_NAME, HTTP_PROPERTY_REQUESTS); Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(PROPERTY_ID_HOST_NAME, "lc6402.ambari.apache.org"); resource.setProperty(PROPERTY_ID_CLUSTER_NAME, "testCluster"); resource.setProperty(PROPERTY_ID_COMPONENT_NAME, "RESOURCEMANAGER"); Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet()); propProvider.populateResources(Collections.singleton(resource), request, null); Assert.assertTrue(resource.getPropertiesMap().get("HostRoles").get("ha_state").equals("ACTIVE")); Assert.assertTrue(streamProvider.getLastSpec().equals("https: "/ws/v1/cluster/info")); }
@Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<String> ids = getRequestPropertyIds(request, predicate); if (ids.size() == 0) { return resources; } for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); String hostName = (String) resource.getPropertyValue(hostNamePropertyId); String componentName = (String) resource.getPropertyValue(componentNamePropertyId); if (clusterName != null && hostName != null && componentName != null && httpPropertyRequests.containsKey(componentName)) { try { Cluster cluster = clusters.getCluster(clusterName); List<HttpPropertyRequest> httpPropertyRequestList = httpPropertyRequests.get(componentName); for (HttpPropertyRequest httpPropertyRequest : httpPropertyRequestList) { populateResource(httpPropertyRequest, resource, cluster, hostName); } } catch (AmbariException e) { String msg = String.format("Could not load cluster with name %s.", clusterName); LOG.debug(msg, e); throw new SystemException(msg, e); } } } return resources; }
HttpPropertyProvider extends BaseProvider implements PropertyProvider { @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<String> ids = getRequestPropertyIds(request, predicate); if (ids.size() == 0) { return resources; } for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); String hostName = (String) resource.getPropertyValue(hostNamePropertyId); String componentName = (String) resource.getPropertyValue(componentNamePropertyId); if (clusterName != null && hostName != null && componentName != null && httpPropertyRequests.containsKey(componentName)) { try { Cluster cluster = clusters.getCluster(clusterName); List<HttpPropertyRequest> httpPropertyRequestList = httpPropertyRequests.get(componentName); for (HttpPropertyRequest httpPropertyRequest : httpPropertyRequestList) { populateResource(httpPropertyRequest, resource, cluster, hostName); } } catch (AmbariException e) { String msg = String.format("Could not load cluster with name %s.", clusterName); LOG.debug(msg, e); throw new SystemException(msg, e); } } } return resources; } }
HttpPropertyProvider extends BaseProvider implements PropertyProvider { @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<String> ids = getRequestPropertyIds(request, predicate); if (ids.size() == 0) { return resources; } for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); String hostName = (String) resource.getPropertyValue(hostNamePropertyId); String componentName = (String) resource.getPropertyValue(componentNamePropertyId); if (clusterName != null && hostName != null && componentName != null && httpPropertyRequests.containsKey(componentName)) { try { Cluster cluster = clusters.getCluster(clusterName); List<HttpPropertyRequest> httpPropertyRequestList = httpPropertyRequests.get(componentName); for (HttpPropertyRequest httpPropertyRequest : httpPropertyRequestList) { populateResource(httpPropertyRequest, resource, cluster, hostName); } } catch (AmbariException e) { String msg = String.format("Could not load cluster with name %s.", clusterName); LOG.debug(msg, e); throw new SystemException(msg, e); } } } return resources; } HttpPropertyProvider(
      StreamProvider stream,
      Clusters clusters,
      String clusterNamePropertyId,
      String hostNamePropertyId,
      String componentNamePropertyId,
      Map<String, List<HttpPropertyRequest>> httpPropertyRequests); }
HttpPropertyProvider extends BaseProvider implements PropertyProvider { @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<String> ids = getRequestPropertyIds(request, predicate); if (ids.size() == 0) { return resources; } for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); String hostName = (String) resource.getPropertyValue(hostNamePropertyId); String componentName = (String) resource.getPropertyValue(componentNamePropertyId); if (clusterName != null && hostName != null && componentName != null && httpPropertyRequests.containsKey(componentName)) { try { Cluster cluster = clusters.getCluster(clusterName); List<HttpPropertyRequest> httpPropertyRequestList = httpPropertyRequests.get(componentName); for (HttpPropertyRequest httpPropertyRequest : httpPropertyRequestList) { populateResource(httpPropertyRequest, resource, cluster, hostName); } } catch (AmbariException e) { String msg = String.format("Could not load cluster with name %s.", clusterName); LOG.debug(msg, e); throw new SystemException(msg, e); } } } return resources; } HttpPropertyProvider(
      StreamProvider stream,
      Clusters clusters,
      String clusterNamePropertyId,
      String hostNamePropertyId,
      String componentNamePropertyId,
      Map<String, List<HttpPropertyRequest>> httpPropertyRequests); @Override Set<Resource> populateResources(Set<Resource> resources,
                                         Request request, Predicate predicate); }
HttpPropertyProvider extends BaseProvider implements PropertyProvider { @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Set<String> ids = getRequestPropertyIds(request, predicate); if (ids.size() == 0) { return resources; } for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); String hostName = (String) resource.getPropertyValue(hostNamePropertyId); String componentName = (String) resource.getPropertyValue(componentNamePropertyId); if (clusterName != null && hostName != null && componentName != null && httpPropertyRequests.containsKey(componentName)) { try { Cluster cluster = clusters.getCluster(clusterName); List<HttpPropertyRequest> httpPropertyRequestList = httpPropertyRequests.get(componentName); for (HttpPropertyRequest httpPropertyRequest : httpPropertyRequestList) { populateResource(httpPropertyRequest, resource, cluster, hostName); } } catch (AmbariException e) { String msg = String.format("Could not load cluster with name %s.", clusterName); LOG.debug(msg, e); throw new SystemException(msg, e); } } } return resources; } HttpPropertyProvider(
      StreamProvider stream,
      Clusters clusters,
      String clusterNamePropertyId,
      String hostNamePropertyId,
      String componentNamePropertyId,
      Map<String, List<HttpPropertyRequest>> httpPropertyRequests); @Override Set<Resource> populateResources(Set<Resource> resources,
                                         Request request, Predicate predicate);  }