|
@@ -25,15 +25,12 @@ import static org.easymock.EasyMock.replay;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
|
|
|
-import org.apache.ambari.server.configuration.ComponentSSLConfigurationTest;
|
|
|
import org.apache.ambari.server.controller.spi.Request;
|
|
|
import org.apache.ambari.server.controller.spi.Resource;
|
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
@@ -43,12 +40,7 @@ import org.apache.ambari.server.state.Clusters;
|
|
|
import org.apache.ambari.server.state.Config;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
-import org.junit.runner.RunWith;
|
|
|
-import org.junit.runners.Parameterized;
|
|
|
|
|
|
-import com.google.inject.Injector;
|
|
|
-
|
|
|
-@RunWith(Parameterized.class)
|
|
|
public class HttpPropertyProviderTest {
|
|
|
private static final String PROPERTY_ID_CLUSTER_NAME = PropertyHelper.getPropertyId("HostRoles", "cluster_name");
|
|
|
private static final String PROPERTY_ID_HOST_NAME = PropertyHelper.getPropertyId("HostRoles", "host_name");
|
|
@@ -57,26 +49,14 @@ public class HttpPropertyProviderTest {
|
|
|
private static final String PROPERTY_ID_STALE_CONFIGS = PropertyHelper.getPropertyId(
|
|
|
"HostRoles", "stale_configs");
|
|
|
|
|
|
- private ComponentSSLConfiguration configuration;
|
|
|
-
|
|
|
- @Parameterized.Parameters
|
|
|
- public static Collection<Object[]> configs() {
|
|
|
- ComponentSSLConfiguration configuration1 = ComponentSSLConfigurationTest.getConfiguration(
|
|
|
- "tspath", "tspass", "tstype", false);
|
|
|
-
|
|
|
- ComponentSSLConfiguration configuration2 = ComponentSSLConfigurationTest.getConfiguration(
|
|
|
- "tspath", "tspass", "tstype", true);
|
|
|
-
|
|
|
- ComponentSSLConfiguration configuration3 = ComponentSSLConfigurationTest.getConfiguration(
|
|
|
- "tspath", "tspass", "tstype", false);
|
|
|
-
|
|
|
- return Arrays.asList(new Object[][] { { configuration1 },
|
|
|
- { configuration2 }, { configuration3 } });
|
|
|
- }
|
|
|
+ private static final Map<String, List<HttpPropertyProvider.HttpPropertyRequest>> HTTP_PROPERTY_REQUESTS = new HashMap<>();
|
|
|
|
|
|
+ static {
|
|
|
+ HTTP_PROPERTY_REQUESTS.put("RESOURCEMANAGER",
|
|
|
+ Collections.<HttpPropertyProvider.HttpPropertyRequest>singletonList(new ResourceManagerHttpPropertyRequest()));
|
|
|
|
|
|
- public HttpPropertyProviderTest(ComponentSSLConfiguration configuration) {
|
|
|
- this.configuration = configuration;
|
|
|
+ HTTP_PROPERTY_REQUESTS.put("ATLAS_SERVER",
|
|
|
+ Collections.<HttpPropertyProvider.HttpPropertyRequest>singletonList(new AtlasServerHttpPropertyRequest()));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -85,29 +65,28 @@ public class HttpPropertyProviderTest {
|
|
|
TestStreamProvider streamProvider = new TestStreamProvider(false);
|
|
|
Clusters clusters = createNiceMock(Clusters.class);
|
|
|
Cluster cluster = createNiceMock(Cluster.class);
|
|
|
- Injector injector = createNiceMock(Injector.class);
|
|
|
Config config1 = createNiceMock(Config.class);
|
|
|
Config config2 = createNiceMock(Config.class);
|
|
|
|
|
|
- Map<String, String> map = new HashMap<String, String>();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("yarn.http.policy", "HTTPS_ONLY");
|
|
|
map.put("yarn.resourcemanager.webapp.https.address", "ec2-54-234-33-50.compute-1.amazonaws.com:8999");
|
|
|
map.put("yarn.resourcemanager.webapp.address", "ec2-54-234-33-50.compute-1.amazonaws.com:8088");
|
|
|
|
|
|
- expect(injector.getInstance(Clusters.class)).andReturn(clusters);
|
|
|
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(injector, clusters, cluster, config1, config2);
|
|
|
+ replay(clusters, cluster, config1, config2);
|
|
|
|
|
|
- HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
|
|
|
- streamProvider, configuration, injector,
|
|
|
+ HttpPropertyProvider propProvider = new HttpPropertyProvider(
|
|
|
+ streamProvider, clusters,
|
|
|
PROPERTY_ID_CLUSTER_NAME,
|
|
|
PROPERTY_ID_HOST_NAME,
|
|
|
- PROPERTY_ID_COMPONENT_NAME);
|
|
|
+ PROPERTY_ID_COMPONENT_NAME,
|
|
|
+ HTTP_PROPERTY_REQUESTS);
|
|
|
|
|
|
Resource resource = new ResourceImpl(Resource.Type.HostComponent);
|
|
|
|
|
@@ -130,11 +109,10 @@ public class HttpPropertyProviderTest {
|
|
|
TestStreamProvider streamProvider = new TestStreamProvider(false);
|
|
|
Clusters clusters = createNiceMock(Clusters.class);
|
|
|
Cluster cluster = createNiceMock(Cluster.class);
|
|
|
- Injector injector = createNiceMock(Injector.class);
|
|
|
Config config1 = createNiceMock(Config.class);
|
|
|
Config config2 = createNiceMock(Config.class);
|
|
|
|
|
|
- Map<String, String> map = new HashMap<String, String>();
|
|
|
+ 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");
|
|
@@ -144,20 +122,20 @@ public class HttpPropertyProviderTest {
|
|
|
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(injector.getInstance(Clusters.class)).andReturn(clusters);
|
|
|
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(injector, clusters, cluster, config1, config2);
|
|
|
+ replay(clusters, cluster, config1, config2);
|
|
|
|
|
|
- HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
|
|
|
- streamProvider, configuration, injector,
|
|
|
+ HttpPropertyProvider propProvider = new HttpPropertyProvider(
|
|
|
+ streamProvider, clusters,
|
|
|
PROPERTY_ID_CLUSTER_NAME,
|
|
|
PROPERTY_ID_HOST_NAME,
|
|
|
- PROPERTY_ID_COMPONENT_NAME);
|
|
|
+ PROPERTY_ID_COMPONENT_NAME,
|
|
|
+ HTTP_PROPERTY_REQUESTS);
|
|
|
|
|
|
Resource resource = new ResourceImpl(Resource.Type.HostComponent);
|
|
|
|
|
@@ -174,6 +152,85 @@ public class HttpPropertyProviderTest {
|
|
|
"/ws/v1/cluster/info"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testPopulateResources_atlasServer() throws Exception {
|
|
|
+
|
|
|
+ TestStreamProvider streamProvider = new TestStreamProvider("{\"Status\":\"ACTIVE\"}", false);
|
|
|
+ Clusters clusters = createNiceMock(Clusters.class);
|
|
|
+ Cluster cluster = createNiceMock(Cluster.class);
|
|
|
+ Config config1 = createNiceMock(Config.class);
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("atlas.enableTLS", "false");
|
|
|
+ map.put("atlas.server.http.port", "21000");
|
|
|
+
|
|
|
+ expect(clusters.getCluster("testCluster")).andReturn(cluster);
|
|
|
+ expect(cluster.getDesiredConfigByType("application-properties")).andReturn(config1).anyTimes();
|
|
|
+ expect(config1.getProperties()).andReturn(map).anyTimes();
|
|
|
+
|
|
|
+ replay(clusters, cluster, config1);
|
|
|
+
|
|
|
+ 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_CLUSTER_NAME, "testCluster");
|
|
|
+ resource.setProperty(PROPERTY_ID_HOST_NAME, "ec2-54-234-33-50.compute-1.amazonaws.com");
|
|
|
+ resource.setProperty(PROPERTY_ID_COMPONENT_NAME, "ATLAS_SERVER");
|
|
|
+
|
|
|
+ Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
|
|
|
+
|
|
|
+ propProvider.populateResources(Collections.singleton(resource), request, null);
|
|
|
+
|
|
|
+ Assert.assertEquals("ACTIVE", resource.getPropertiesMap().get("HostRoles").get("ha_state"));
|
|
|
+ Assert.assertEquals("http://ec2-54-234-33-50.compute-1.amazonaws.com:21000/api/atlas/admin/status",
|
|
|
+ streamProvider.getLastSpec());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testPopulateResources_atlasServer_https() throws Exception {
|
|
|
+
|
|
|
+ TestStreamProvider streamProvider = new TestStreamProvider("{\"Status\":\"ACTIVE\"}", false);
|
|
|
+ Clusters clusters = createNiceMock(Clusters.class);
|
|
|
+ Cluster cluster = createNiceMock(Cluster.class);
|
|
|
+ Config config1 = createNiceMock(Config.class);
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("atlas.enableTLS", "true");
|
|
|
+ map.put("atlas.server.https.port", "21443");
|
|
|
+
|
|
|
+ expect(clusters.getCluster("testCluster")).andReturn(cluster);
|
|
|
+ expect(cluster.getDesiredConfigByType("application-properties")).andReturn(config1).anyTimes();
|
|
|
+ expect(config1.getProperties()).andReturn(map).anyTimes();
|
|
|
+
|
|
|
+ replay(clusters, cluster, config1);
|
|
|
+
|
|
|
+ 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_CLUSTER_NAME, "testCluster");
|
|
|
+ resource.setProperty(PROPERTY_ID_HOST_NAME, "ec2-54-234-33-50.compute-1.amazonaws.com");
|
|
|
+ resource.setProperty(PROPERTY_ID_COMPONENT_NAME, "ATLAS_SERVER");
|
|
|
+
|
|
|
+ Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
|
|
|
+
|
|
|
+ propProvider.populateResources(Collections.singleton(resource), request, null);
|
|
|
+
|
|
|
+ Assert.assertEquals("ACTIVE", resource.getPropertiesMap().get("HostRoles").get("ha_state"));
|
|
|
+ Assert.assertEquals("https://ec2-54-234-33-50.compute-1.amazonaws.com:21443/api/atlas/admin/status",
|
|
|
+ streamProvider.getLastSpec());
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testReadGangliaServer() throws Exception {
|
|
@@ -186,13 +243,14 @@ public class HttpPropertyProviderTest {
|
|
|
|
|
|
private Resource doPopulate(String componentName,
|
|
|
Set<String> requestProperties, StreamProvider streamProvider) throws Exception {
|
|
|
- Injector injector = createNiceMock(Injector.class);
|
|
|
+ Clusters clusters = createNiceMock(Clusters.class);
|
|
|
|
|
|
- HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
|
|
|
- streamProvider, configuration, injector,
|
|
|
+ HttpPropertyProvider propProvider = new HttpPropertyProvider(
|
|
|
+ streamProvider, clusters,
|
|
|
PROPERTY_ID_CLUSTER_NAME,
|
|
|
PROPERTY_ID_HOST_NAME,
|
|
|
- PROPERTY_ID_COMPONENT_NAME);
|
|
|
+ PROPERTY_ID_COMPONENT_NAME,
|
|
|
+ HTTP_PROPERTY_REQUESTS);
|
|
|
|
|
|
Resource resource = new ResourceImpl(Resource.Type.HostComponent);
|
|
|
|
|
@@ -211,11 +269,18 @@ public class HttpPropertyProviderTest {
|
|
|
private boolean throwError = false;
|
|
|
private String lastSpec = null;
|
|
|
private boolean isLastSpecUpdated;
|
|
|
+ private String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],\"clusterInfo\": {\"haState\": \"ACTIVE\"},"
|
|
|
+ + " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
|
|
|
|
|
|
private TestStreamProvider(boolean throwErr) {
|
|
|
throwError = throwErr;
|
|
|
}
|
|
|
|
|
|
+ private TestStreamProvider(String responseStr, boolean throwErr) {
|
|
|
+ this.responseStr = responseStr;
|
|
|
+ throwError = throwErr;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public InputStream readFrom(String spec) throws IOException {
|
|
|
if (!isLastSpecUpdated) {
|
|
@@ -228,9 +293,8 @@ public class HttpPropertyProviderTest {
|
|
|
throw new IOException("Fake error");
|
|
|
}
|
|
|
|
|
|
- String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],\"clusterInfo\": {\"haState\": \"ACTIVE\"},"
|
|
|
- + " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
|
|
|
- return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
|
|
|
+
|
|
|
+ return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
|
|
|
}
|
|
|
|
|
|
public String getLastSpec() {
|