Services { public String getTimelineServerUrl() { String url = context.getCluster() != null ? getATSUrlFromCluster() : getATSUrlFromCustom(); return removeTrailingSlash(url); } Services(AmbariApi ambariApi, ViewContext context); String getRMUrl(); String getWebHCatURL(); String getTimelineServerUrl(); String getYARNProtocol(); static String addProtocolIfMissing(String url, String protocol); static boolean hasProtocol(String[] urls); static boolean hasProtocol(String url); String getHadoopHttpWebAuthType(); String getTimelineServerAuthType(); static final String HTTPS_ONLY; static final String HTTP_ONLY; static final String YARN_SITE; static final String YARN_HTTP_POLICY; static final String YARN_RESOURCEMANAGER_HA_ENABLED; static final String RM_INFO_API_ENDPOINT; static final String TIMELINE_AUTH_TYPE_PROP_KEY; static final String HADOOP_HTTP_AUTH_TYPE_KEY; }
@Test(expected = AmbariApiException.class) public void shouldCheckForEmptyATSUrlInCustomConfig() { ViewContext viewContext = getViewContext(new HashMap<String, String>()); AmbariApi ambariApi = createNiceMock(AmbariApi.class); expect(ambariApi.isClusterAssociated()).andReturn(false); replay(viewContext); Services services = new Services(ambariApi, viewContext); services.getTimelineServerUrl(); }
@Test public void shouldReturnATSUrlConfiguredInCustomMode() throws Exception { Map<String, String> map = new HashMap<>(); map.put("yarn.ats.url", HTTP_RM_URL1); ViewContext viewContext = getViewContext(map); AmbariApi ambariApi = createNiceMock(AmbariApi.class); expect(ambariApi.isClusterAssociated()).andReturn(false); replay(viewContext); Services services = new Services(ambariApi, viewContext); assertEquals(HTTP_RM_URL1, services.getTimelineServerUrl()); }
@Test(expected = AmbariApiException.class) public void shouldThrowExceptionIfNoProtocolInCustomMode() { Map<String, String> map = new HashMap<>(); map.put("yarn.ats.url", RM_URL1_HOST_PORT); ViewContext viewContext = getViewContext(map); AmbariApi ambariApi = createNiceMock(AmbariApi.class); expect(ambariApi.isClusterAssociated()).andReturn(false); replay(viewContext); Services services = new Services(ambariApi, viewContext); services.getTimelineServerUrl(); }
@Test public void shouldReturnATSUrlFromYarnSiteInClusteredMode() throws Exception { ViewContext viewContext = getViewContext(new HashMap<String, String>()); AmbariApi ambariApi = createNiceMock(AmbariApi.class); Cluster cluster = createNiceMock(Cluster.class); Services services = new Services(ambariApi, viewContext); expect(ambariApi.isClusterAssociated()).andReturn(true).anyTimes(); setClusterExpectation(cluster, "HTTP_ONLY"); expect(viewContext.getCluster()).andReturn(cluster).anyTimes(); replayAll(); assertEquals(HTTP_RM_URL1, services.getTimelineServerUrl()); reset(cluster); setClusterExpectation(cluster, "HTTPS_ONLY"); replay(cluster); assertEquals(HTTPS_RM_URL2, services.getTimelineServerUrl()); }