You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2013/08/08 20:23:35 UTC
git commit: AMBARI-2691 - Need https support for ganglia/nagios to be
able to have https support throughout the stack.
Updated Branches:
refs/heads/branch-1.2.5 b990601dc -> 94ee6f921
AMBARI-2691 - Need https support for ganglia/nagios to be able to have https support throughout the stack.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/94ee6f92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/94ee6f92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/94ee6f92
Branch: refs/heads/branch-1.2.5
Commit: 94ee6f921c917e7d0ed854b81522c65438e1d774
Parents: b990601
Author: tbeerbower <tb...@hortonworks.com>
Authored: Thu Aug 8 14:22:16 2013 -0400
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Thu Aug 8 14:22:16 2013 -0400
----------------------------------------------------------------------
ambari-server/sbin/ambari-server | 10 +-
.../ComponentSSLConfiguration.java | 113 +++++++++++++++
.../server/configuration/Configuration.java | 13 +-
.../ambari/server/controller/AmbariServer.java | 2 +
.../GangliaComponentPropertyProvider.java | 4 +-
.../GangliaHostComponentPropertyProvider.java | 4 +-
.../ganglia/GangliaHostPropertyProvider.java | 5 +-
.../ganglia/GangliaPropertyProvider.java | 14 +-
.../ganglia/GangliaReportPropertyProvider.java | 14 +-
.../internal/AbstractProviderModule.java | 10 +-
.../internal/HostComponentResourceProvider.java | 11 +-
.../internal/HttpProxyPropertyProvider.java | 23 ++-
.../controller/internal/URLStreamProvider.java | 68 ++++++++-
ambari-server/src/main/python/ambari-server.py | 142 ++++++++++++++++++-
.../ComponentSSLConfigurationTest.java | 70 +++++++++
.../ganglia/GangliaPropertyProviderTest.java | 99 ++++++++++---
.../GangliaReportPropertyProviderTest.java | 36 ++++-
.../internal/HttpPropertyProviderTest.java | 67 +++++++--
18 files changed, 645 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/sbin/ambari-server
----------------------------------------------------------------------
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index 0da6550..a3533e2 100644
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -110,8 +110,16 @@ case "$1" in
echo -e "Setting up HTTPS properties..."
$PYTHON /usr/sbin/ambari-server.py $@
;;
+ setup-ganglia-https)
+ echo -e "Setting up HTTPS properties for Ganglia..."
+ $PYTHON /usr/sbin/ambari-server.py $@
+ ;;
+ setup-nagios-https)
+ echo -e "Setting up HTTPS properties for Nagios..."
+ $PYTHON /usr/sbin/ambari-server.py $@
+ ;;
*)
- echo "Usage: /usr/sbin/ambari-server {start|stop|restart|setup|upgrade|status|upgradestack|setup-ldap|setup-https|encrypt-passwords} [options]"
+ echo "Usage: /usr/sbin/ambari-server {start|stop|restart|setup|upgrade|status|upgradestack|setup-ldap|setup-https|setup-ganglia_https|setup-nagios_https|encrypt-passwords} [options]"
exit 1
esac
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/configuration/ComponentSSLConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/ComponentSSLConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/ComponentSSLConfiguration.java
new file mode 100644
index 0000000..fe5e249
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/ComponentSSLConfiguration.java
@@ -0,0 +1,113 @@
+package org.apache.ambari.server.configuration;
+
+/**
+ * Configuration for SSL on components (Ganglia & Nagios).
+ */
+public class ComponentSSLConfiguration {
+
+ /**
+ * Configuration
+ */
+ private String truststorePath;
+ private String truststorePassword;
+ private String truststoreType;
+ private boolean gangliaSSL;
+ private boolean nagiosSSL;
+
+ /**
+ * The singleton.
+ */
+ private static ComponentSSLConfiguration singleton = new ComponentSSLConfiguration();
+
+
+ // ----- Constructors ------------------------------------------------------
+
+ /**
+ * Singleton constructor.
+ */
+ protected ComponentSSLConfiguration() {
+ }
+
+
+ // ----- ComponentSSLConfiguration -----------------------------------------
+
+ /**
+ * Initialize with the given configuration.
+ *
+ * @param configuration the configuration
+ */
+ public void init(Configuration configuration) {
+ truststorePath = configuration.getProperty(Configuration.SSL_TRUSTSTORE_PATH_KEY);
+ truststorePassword = getPassword(configuration);
+ truststoreType = configuration.getProperty(Configuration.SSL_TRUSTSTORE_TYPE_KEY);
+ gangliaSSL = Boolean.parseBoolean(configuration.getProperty(Configuration.GANGLIA_HTTPS_KEY));
+ nagiosSSL = Boolean.parseBoolean(configuration.getProperty(Configuration.NAGIOS_HTTPS_KEY));
+ }
+
+
+ // ----- accessors ---------------------------------------------------------
+
+ /**
+ * Get the truststore path.
+ *
+ * @return the truststore path
+ */
+ public String getTruststorePath() {
+ return truststorePath;
+ }
+
+ /**
+ * Get the truststore password.
+ *
+ * @return the truststore password
+ */
+ public String getTruststorePassword() {
+ return truststorePassword;
+ }
+
+ /**
+ * Get the truststore type.
+ *
+ * @return the truststore type; may be null
+ */
+ public String getTruststoreType() {
+ return truststoreType;
+ }
+
+ /**
+ * Indicates whether or not Ganglia is setup for SSL.
+ *
+ * @return true if Ganglia is setup for SSL
+ */
+ public boolean isGangliaSSL() {
+ return gangliaSSL;
+ }
+
+ /**
+ * Indicates whether or not Nagios is setup for SSL.
+ *
+ * @return true if Nagios is setup for SSL
+ */
+ public boolean isNagiosSSL() {
+ return nagiosSSL;
+ }
+
+ /**
+ * Get the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static ComponentSSLConfiguration instance() {
+ return singleton;
+ }
+
+
+ // -----helper methods -----------------------------------------------------
+
+ private String getPassword(Configuration configuration) {
+ String rawPassword = configuration.getProperty(Configuration.SSL_TRUSTSTORE_PASSWORD_KEY);
+ String password = configuration.readPasswordFromStore(rawPassword);
+
+ return password == null ? rawPassword : password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 42b603d..62fa07b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -175,6 +175,8 @@ public class Configuration {
public static final String JAVAX_SSL_TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType";
+ public static final String GANGLIA_HTTPS_KEY = "ganglia.https";
+ public static final String NAGIOS_HTTPS_KEY = "nagios.https";
private static final String SRVR_TWO_WAY_SSL_DEFAULT = "false";
private static final String SRVR_KSTR_DIR_DEFAULT = ".";
public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
@@ -350,9 +352,18 @@ public class Configuration {
}
/**
+ * Get the property value for the given key.
+ *
+ * @return the property value
+ */
+ public String getProperty(String key) {
+ return properties.getProperty(key);
+ }
+
+ /**
* Loads trusted certificates store properties
*/
- void loadSSLParams(){
+ protected void loadSSLParams(){
if (properties.getProperty(SSL_TRUSTSTORE_PATH_KEY) != null) {
System.setProperty(JAVAX_SSL_TRUSTSTORE, properties.getProperty(SSL_TRUSTSTORE_PATH_KEY));
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 0ade157..11e4a5a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -38,6 +38,7 @@ import org.apache.ambari.server.api.services.PersistKeyValueImpl;
import org.apache.ambari.server.api.services.PersistKeyValueService;
import org.apache.ambari.server.bootstrap.BootStrapImpl;
import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.PersistenceType;
import org.apache.ambari.server.orm.dao.MetainfoDAO;
@@ -448,6 +449,7 @@ public class AmbariServer {
server = injector.getInstance(AmbariServer.class);
CertificateManager certMan = injector.getInstance(CertificateManager.class);
certMan.initRootCert();
+ ComponentSSLConfiguration.instance().init(server.configs);
if (server != null) {
server.run();
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java
index c7df3ac..c9bdf6a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller.ganglia;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.StreamProvider;
@@ -36,11 +37,12 @@ public class GangliaComponentPropertyProvider extends GangliaPropertyProvider {
public GangliaComponentPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics,
StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String componentNamePropertyId) {
- super(componentMetrics, streamProvider, hostProvider,
+ super(componentMetrics, streamProvider, configuration, hostProvider,
clusterNamePropertyId, null, componentNamePropertyId);
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java
index b8484fd..5964e6c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller.ganglia;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.StreamProvider;
@@ -36,12 +37,13 @@ public class GangliaHostComponentPropertyProvider extends GangliaPropertyProvide
public GangliaHostComponentPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String hostNamePropertyId,
String componentNamePropertyId) {
- super(componentPropertyInfoMap, streamProvider, hostProvider,
+ super(componentPropertyInfoMap, streamProvider, configuration, hostProvider,
clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId);
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java
index 2720e14..2c11d66 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java
@@ -18,11 +18,11 @@
package org.apache.ambari.server.controller.ganglia;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.StreamProvider;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -50,11 +50,12 @@ public class GangliaHostPropertyProvider extends GangliaPropertyProvider{
public GangliaHostPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String hostNamePropertyId) {
- super(componentPropertyInfoMap, streamProvider, hostProvider,
+ super(componentPropertyInfoMap, streamProvider, configuration, hostProvider,
clusterNamePropertyId, hostNamePropertyId, null);
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
index 68bdcc7..7db539f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
@@ -19,6 +19,7 @@
package org.apache.ambari.server.controller.ganglia;
import org.apache.ambari.server.controller.internal.AbstractPropertyProvider;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.spi.*;
import org.apache.ambari.server.controller.utilities.StreamProvider;
@@ -47,6 +48,8 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
private final String componentNamePropertyId;
+ private final ComponentSSLConfiguration configuration;
+
/**
* Map of Ganglia cluster names keyed by component type.
*/
@@ -73,6 +76,7 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
public GangliaPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String hostNamePropertyId,
@@ -81,6 +85,7 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
super(componentPropertyInfoMap);
this.streamProvider = streamProvider;
+ this.configuration = configuration;
this.hostProvider = hostProvider;
this.clusterNamePropertyId = clusterNamePropertyId;
this.hostNamePropertyId = hostNamePropertyId;
@@ -264,8 +269,13 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
StringBuilder sb = new StringBuilder();
- sb.append("http://").
- append(hostProvider.getGangliaCollectorHostName(clusterName)).
+ if (configuration.isGangliaSSL()) {
+ sb.append("https://");
+ } else {
+ sb.append("http://");
+ }
+
+ sb.append(hostProvider.getGangliaCollectorHostName(clusterName)).
append("/cgi-bin/rrd.py?c=").
append(clusters);
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java
index 22ed775..35b156c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java
@@ -19,6 +19,7 @@
package org.apache.ambari.server.controller.ganglia;
import org.apache.ambari.server.controller.internal.AbstractPropertyProvider;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.spi.*;
import org.apache.ambari.server.controller.utilities.StreamProvider;
@@ -46,6 +47,8 @@ public class GangliaReportPropertyProvider extends AbstractPropertyProvider {
private final String clusterNamePropertyId;
+ private final ComponentSSLConfiguration configuration;
+
// ----- Constants --------------------------------------------------------
@@ -57,6 +60,7 @@ public class GangliaReportPropertyProvider extends AbstractPropertyProvider {
public GangliaReportPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap,
StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId) {
super(componentPropertyInfoMap);
@@ -64,6 +68,7 @@ public class GangliaReportPropertyProvider extends AbstractPropertyProvider {
this.streamProvider = streamProvider;
this.hostProvider = hostProvider;
this.clusterNamePropertyId = clusterNamePropertyId;
+ this.configuration = configuration;
}
@@ -213,8 +218,13 @@ public class GangliaReportPropertyProvider extends AbstractPropertyProvider {
StringBuilder sb = new StringBuilder();
- sb.append("http://").
- append(hostProvider.getGangliaCollectorHostName(clusterName)).
+ if (configuration.isGangliaSSL()) {
+ sb.append("https://");
+ } else {
+ sb.append("http://");
+ }
+
+ sb.append(hostProvider.getGangliaCollectorHostName(clusterName)).
append("/ganglia/graph.php?g=").
append(report).
append("&json=1");
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/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 34d3a26..49634e3 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
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller.internal;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.AmbariServer;
import org.apache.ambari.server.controller.ganglia.GangliaComponentPropertyProvider;
import org.apache.ambari.server.controller.ganglia.GangliaHostComponentPropertyProvider;
@@ -246,14 +247,18 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
List<PropertyProvider> providers = new LinkedList<PropertyProvider>();
+ ComponentSSLConfiguration configuration = ComponentSSLConfiguration.instance();
+
URLStreamProvider streamProvider = new URLStreamProvider(
- PROPERTY_REQUEST_CONNECT_TIMEOUT, PROPERTY_REQUEST_READ_TIMEOUT);
+ PROPERTY_REQUEST_CONNECT_TIMEOUT, PROPERTY_REQUEST_READ_TIMEOUT,
+ configuration.getTruststorePath(), configuration.getTruststorePassword(), configuration.getTruststoreType());
switch (type){
case Cluster :
providers.add(new GangliaReportPropertyProvider(
PropertyHelper.getGangliaPropertyIds(type),
streamProvider,
+ configuration,
this,
PropertyHelper.getPropertyId("Clusters", "cluster_name")));
break;
@@ -261,6 +266,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(new GangliaHostPropertyProvider(
PropertyHelper.getGangliaPropertyIds(type),
streamProvider,
+ configuration,
this,
PropertyHelper.getPropertyId("Hosts", "cluster_name"),
PropertyHelper.getPropertyId("Hosts", "host_name")
@@ -280,6 +286,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(new GangliaComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(type),
streamProvider,
+ configuration,
this,
PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
@@ -298,6 +305,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(type),
streamProvider,
+ configuration,
this,
PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
PropertyHelper.getPropertyId("HostRoles", "host_name"),
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index 23d753a..f9dd801 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.controller.internal;
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.ServiceComponentHostRequest;
@@ -73,12 +74,16 @@ class HostComponentResourceProvider extends AbstractControllerResourceProvider {
private static final int HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT = 10000;
static {
+ ComponentSSLConfiguration configuration = ComponentSSLConfiguration.instance();
+ URLStreamProvider streamProvider = new URLStreamProvider(
+ HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT,
+ HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT,
+ configuration.getTruststorePath(), configuration.getTruststorePassword(), configuration.getTruststoreType());
+
HOST_COMPONENT_PROPERTIES_PROVIDER.put(
"NAGIOS_SERVER",
new HttpProxyPropertyProvider(
- new URLStreamProvider(
- HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT,
- HOST_COMPONENT_HTTP_PROPERTY_REQUEST_READ_TIMEOUT),
+ streamProvider, configuration,
PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
PropertyHelper.getPropertyId("HostRoles", "host_name"),
PropertyHelper.getPropertyId("HostRoles", "component_name")));
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
index 1f62312..99ccfc6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.PropertyProvider;
import org.apache.ambari.server.controller.spi.Request;
@@ -49,13 +50,15 @@ public class HttpProxyPropertyProvider extends BaseProvider implements PropertyP
private static final Map<String, String> URL_TEMPLATES = new HashMap<String, String>();
private static final Map<String, String> MAPPINGS = new HashMap<String, String>();
-
+
static {
URL_TEMPLATES.put("NAGIOS_SERVER", "http://%s/ambarinagios/nagios/nagios_alerts.php?q1=alerts&alert_type=all");
MAPPINGS.put("NAGIOS_SERVER", PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
}
-
+
+ private final ComponentSSLConfiguration configuration;
+
private StreamProvider streamProvider = null;
// !!! not yet used, but make consistent
private String clusterNamePropertyId = null;
@@ -64,12 +67,14 @@ public class HttpProxyPropertyProvider extends BaseProvider implements PropertyP
public HttpProxyPropertyProvider(
StreamProvider stream,
+ ComponentSSLConfiguration configuration,
String clusterNamePropertyId,
String hostNamePropertyId,
String componentNamePropertyId) {
super(new HashSet<String>(MAPPINGS.values()));
this.streamProvider = stream;
+ this.configuration = configuration;
this.clusterNamePropertyId = clusterNamePropertyId;
this.hostNamePropertyId = hostNamePropertyId;
this.componentNamePropertyId = componentNamePropertyId;
@@ -97,7 +102,7 @@ public class HttpProxyPropertyProvider extends BaseProvider implements PropertyP
MAPPINGS.containsKey(componentName.toString()) &&
URL_TEMPLATES.containsKey(componentName.toString())) {
- String template = URL_TEMPLATES.get(componentName.toString());
+ String template = getTemplate(componentName.toString());
String propertyId = MAPPINGS.get(componentName.toString());
String url = String.format(template, hostName);
@@ -108,6 +113,18 @@ public class HttpProxyPropertyProvider extends BaseProvider implements PropertyP
return resources;
}
+ private String getTemplate(String key) {
+
+ String template = URL_TEMPLATES.get(key);
+
+ if (key.equals("NAGIOS_SERVER")) {
+ if (configuration.isNagiosSSL()) {
+ template = template.replace("http", "https");
+ }
+ }
+ return template;
+ }
+
private void getHttpResponse(Resource r, String url, String propertyIdToSet) throws SystemException {
InputStream in = null;
try {
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
index 20b31ad..b7d972e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
@@ -18,13 +18,21 @@
package org.apache.ambari.server.controller.internal;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.security.KeyStore;
import org.apache.ambari.server.controller.utilities.StreamProvider;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+
/**
* URL based implementation of a stream provider.
*/
@@ -32,21 +40,31 @@ public class URLStreamProvider implements StreamProvider {
private final int connTimeout;
private final int readTimeout;
+ private final String path;
+ private final String password;
+ private final String type;
+ private volatile SSLSocketFactory sslSocketFactory = null;
/**
* Provide the connection timeout for the underlying connection.
*
- * @param connectionTimeout time, in milliseconds, to attempt a connection
- * @param readTimeout
+ * @param connectionTimeout time, in milliseconds, to attempt a connection
+ * @param readTimeout the read timeout in milliseconds
*/
- public URLStreamProvider(int connectionTimeout, int readTimeout) {
+ public URLStreamProvider(int connectionTimeout, int readTimeout,
+ String path, String password, String type) {
this.connTimeout = connectionTimeout;
this.readTimeout = readTimeout;
+ this.path = path;
+ this.password = password;
+ this.type = type;
}
@Override
public InputStream readFrom(String spec) throws IOException {
- URLConnection connection = new URL(spec).openConnection();
+
+ URLConnection connection = spec.startsWith("https") ?
+ getSSLConnection(spec) : getConnection(spec);
connection.setConnectTimeout(connTimeout);
connection.setReadTimeout(readTimeout);
@@ -54,4 +72,46 @@ public class URLStreamProvider implements StreamProvider {
return connection.getInputStream();
}
+
+
+ // ----- helper methods ----------------------------------------------------
+
+ // Get a connection
+ private URLConnection getConnection(String spec) throws IOException {
+ return new URL(spec).openConnection();
+ }
+
+ // Get an ssl connection
+ private HttpsURLConnection getSSLConnection(String spec) throws IOException {
+
+ if (sslSocketFactory == null) {
+ synchronized (this) {
+ if (sslSocketFactory == null) {
+ try {
+ FileInputStream in = new FileInputStream(new File(path));
+ KeyStore store = KeyStore.getInstance(type == null ? KeyStore.getDefaultType() : type);
+
+ store.load(in, password.toCharArray());
+ in.close();
+
+ TrustManagerFactory tmf =
+ TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+
+ tmf.init(store);
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(null, tmf.getTrustManagers(), null);
+
+ sslSocketFactory = context.getSocketFactory();
+ } catch (Exception e) {
+ throw new IOException("Can't get connection.", e);
+ }
+ }
+ }
+ }
+ HttpsURLConnection connection = (HttpsURLConnection)(new URL(spec).openConnection());
+
+ connection.setSSLSocketFactory(sslSocketFactory);
+
+ return connection;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index d6057dd..0eb4f4a 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -58,6 +58,8 @@ UPDATE_METAINFO_ACTION = "update-metainfo"
STATUS_ACTION = "status"
SETUP_HTTPS_ACTION = "setup-https"
LDAP_SETUP_ACTION = "setup-ldap"
+SETUP_GANGLIA_HTTPS_ACTION = "setup-ganglia-https"
+SETUP_NAGIOS_HTTPS_ACTION = "setup-nagios-https"
ENCRYPT_PASSWORDS_ACTION = "encrypt-passwords"
# selinux commands
@@ -100,6 +102,11 @@ EXPRT_KSTR_CMD = "openssl pkcs12 -export -in '{0}' -inkey '{1}' -certfile '{0}'
CHANGE_KEY_PWD_CND = 'openssl rsa -in {0} -des3 -out {0}.secured -passout pass:{1}'
GET_CRT_INFO_CMD = 'openssl x509 -dates -subject -in {0}'
+#keytool commands
+KEYTOOL_IMPORT_CERT_CMD="{0}" + os.sep + "bin" + os.sep + "keytool -import -alias '{1}' -storetype '{2}' -file '{3}' -storepass '{4}' -noprompt"
+KEYTOOL_DELETE_CERT_CMD="{0}" + os.sep + "bin" + os.sep + "keytool -delete -alias '{1}' -storepass '{2}' -noprompt"
+KEYTOOL_KEYSTORE=" -keystore '{0}'"
+
# constants
STACK_NAME_VER_SEP = "-"
JAVA_SHARE_PATH="/usr/share/java"
@@ -180,6 +187,9 @@ SSL_KEY_PASSWORD_LENGTH = 50
DEFAULT_SSL_API_PORT = 8443
SSL_DATE_FORMAT = '%b %d %H:%M:%S %Y GMT'
+GANGLIA_HTTPS = 'ganglia.https'
+NAGIOS_HTTPS = 'nagios.https'
+
JDBC_RCA_PASSWORD_ALIAS = "ambari.db.password"
CLIENT_SECURITY_KEY = "client.security"
@@ -630,6 +640,9 @@ def adjust_directory_permissions(ambari_user):
credStoreFile = get_credential_store_location(properties)
if os.path.exists(credStoreFile):
NR_ADJUST_OWNERSHIP_LIST.append((credStoreFile, "600", "{0}", "{0}", False))
+ trust_store_location = properties[SSL_TRUSTSTORE_PATH_PROPERTY]
+ if trust_store_location:
+ NR_ADJUST_OWNERSHIP_LIST.append((trust_store_location, "600", "{0}", "{0}", False))
print "Adjusting ambari-server permissions and ownership..."
for pack in NR_ADJUST_OWNERSHIP_LIST:
file = pack[0]
@@ -2599,6 +2612,10 @@ def decrypt_password_for_alias(alias):
if properties == -1:
raise FatalException(1, None)
+ return get_encrypted_password(alias, password, properties)
+
+def get_encrypted_password(alias, password, properties):
+
isSecure = get_is_secure(properties)
(isPersisted, masterKeyFile) = get_is_persisted(properties)
if isSecure:
@@ -3033,6 +3050,125 @@ def is_server_runing():
return False, None
+def setup_component_https(component, command, property, alias):
+
+ if not SILENT:
+
+ jdk_path = find_jdk()
+ if jdk_path is None:
+ err = "No JDK found, please run the \"ambari-server setup\" " \
+ "command to install a JDK automatically or install any " \
+ "JDK manually to " + JDK_INSTALL_DIR
+ raise FatalException(1, err)
+
+ properties = get_ambari_properties()
+
+ use_https = properties.get_property(property) in ['true']
+
+ if use_https:
+ if get_YN_input("Do you want to disable HTTPS for " + component + " [y/n] (n)? ", False):
+
+ truststore_path = get_truststore_path(properties)
+ truststore_password = get_truststore_password(properties)
+
+ run_component_https_cmd(get_delete_cert_command(jdk_path, alias, truststore_path, truststore_password))
+
+ properties.process_pair(property, "false")
+
+ else:
+ return
+ else:
+ if get_YN_input("Do you want to configure HTTPS for " + component + " [y/n] (y)? ", True):
+
+ truststore_type = get_truststore_type(properties)
+ truststore_path = get_truststore_path(properties)
+ truststore_password = get_truststore_password(properties)
+
+ run_os_command(get_delete_cert_command(jdk_path, alias, truststore_path, truststore_password))
+
+ import_cert_path = get_validated_filepath_input(\
+ "Enter path to " + component + " Certificate: ",\
+ "Certificate not found")
+
+ run_component_https_cmd(get_import_cert_command(jdk_path, alias, truststore_type, import_cert_path, truststore_path, truststore_password))
+
+ properties.process_pair(property, "true")
+
+ else:
+ return
+
+ conf_file = find_properties_file()
+ f = open(conf_file, 'w')
+ properties.store(f, "Changed by 'ambari-server " + command + "' command")
+
+ else:
+ print command + " is not enabled in silent mode."
+
+def get_truststore_type(properties):
+
+ truststore_type = properties.get_property(SSL_TRUSTSTORE_TYPE_PROPERTY)
+ if not truststore_type:
+ SSL_TRUSTSTORE_TYPE_DEFAULT = get_value_from_properties(properties, SSL_TRUSTSTORE_TYPE_PROPERTY, "jks")
+
+ truststore_type = get_validated_string_input(
+ "TrustStore type [jks/jceks/pkcs12] {0}:".format(get_prompt_default(SSL_TRUSTSTORE_TYPE_DEFAULT)),
+ SSL_TRUSTSTORE_TYPE_DEFAULT,
+ "^(jks|jceks|pkcs12)?$", "Wrong type", False)
+
+ if truststore_type:
+ properties.process_pair(SSL_TRUSTSTORE_TYPE_PROPERTY, truststore_type)
+
+ return truststore_type
+
+def get_truststore_path(properties):
+
+ truststore_path = properties.get_property(SSL_TRUSTSTORE_PATH_PROPERTY)
+ if not truststore_path:
+ SSL_TRUSTSTORE_PATH_DEFAULT = get_value_from_properties(properties, SSL_TRUSTSTORE_PATH_PROPERTY)
+
+ while not truststore_path:
+ truststore_path = get_validated_string_input(
+ "Path to TrustStore file {0}:".format(get_prompt_default(SSL_TRUSTSTORE_PATH_DEFAULT)),
+ SSL_TRUSTSTORE_PATH_DEFAULT,
+ ".*", False, False)
+
+ if truststore_path:
+ properties.process_pair(SSL_TRUSTSTORE_PATH_PROPERTY, truststore_path)
+
+ return truststore_path
+
+def get_truststore_password(properties):
+ truststore_password = properties.get_property(SSL_TRUSTSTORE_PASSWORD_PROPERTY)
+ if truststore_password:
+ truststore_password = decrypt_password_for_alias(SSL_TRUSTSTORE_PASSWORD_ALIAS)
+ else:
+ truststore_password = read_password("", ".*", "Password for TrustStore:", "Invalid characters in password")
+ if truststore_password:
+ properties.process_pair(SECURITY_IS_ENCRYPTION_ENABLED, "true")
+ encrypted_password = get_encrypted_password(SSL_TRUSTSTORE_PASSWORD_ALIAS, truststore_password, properties)
+ properties.process_pair(SSL_TRUSTSTORE_PASSWORD_PROPERTY, encrypted_password)
+
+ return truststore_password
+
+def run_component_https_cmd(cmd):
+ retcode, out, err = run_os_command(cmd)
+
+ if not retcode == 0:
+ err = 'Error occured during truststore setup ! :' + out + " : " + err
+ raise FatalException(1, err)
+
+def get_delete_cert_command(jdk_path, alias, truststore_path, truststore_password):
+ cmd = KEYTOOL_DELETE_CERT_CMD.format(jdk_path, alias, truststore_password)
+ if truststore_path:
+ cmd += KEYTOOL_KEYSTORE.format(truststore_path)
+ return cmd
+
+def get_import_cert_command(jdk_path, alias, truststore_type, import_cert_path, truststore_path, truststore_password):
+ cmd = KEYTOOL_IMPORT_CERT_CMD.format(jdk_path, alias, truststore_type, import_cert_path, truststore_password)
+ if truststore_path:
+ cmd += KEYTOOL_KEYSTORE.format(truststore_path)
+ return cmd
+
def import_cert_and_key_action(security_server_keys_dir, properties):
if import_cert_and_key(security_server_keys_dir):
properties.process_pair(SSL_SERVER_CERT_NAME, SSL_CERT_FILE_NAME)
@@ -3422,7 +3558,11 @@ def main():
elif action == UPDATE_METAINFO_ACTION:
update_metainfo(options)
elif action == SETUP_HTTPS_ACTION:
- setup_https(options)
+ setup_https(options)
+ elif action == SETUP_GANGLIA_HTTPS_ACTION:
+ setup_component_https("Ganglia", "setup-ganglia-https", GANGLIA_HTTPS, "ganglia_cert")
+ elif action == SETUP_NAGIOS_HTTPS_ACTION:
+ setup_component_https("Nagios", "setup-nagios-https", NAGIOS_HTTPS, "nagios_cert")
else:
parser.error("Invalid action")
except FatalException as e:
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/test/java/org/apache/ambari/server/configuration/ComponentSSLConfigurationTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ComponentSSLConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ComponentSSLConfigurationTest.java
new file mode 100644
index 0000000..e8f8b17
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ComponentSSLConfigurationTest.java
@@ -0,0 +1,70 @@
+package org.apache.ambari.server.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Properties;
+
+/**
+ * ComponentSSLConfiguration tests.
+ */
+public class ComponentSSLConfigurationTest {
+
+ public static ComponentSSLConfiguration getConfiguration(String path, String pass, String type, boolean gangliaSSL, boolean nagiosSSL) {
+ Properties ambariProperties = new Properties();
+ ambariProperties.setProperty(Configuration.SSL_TRUSTSTORE_PATH_KEY, path);
+ ambariProperties.setProperty(Configuration.SSL_TRUSTSTORE_PASSWORD_KEY, pass);
+ ambariProperties.setProperty(Configuration.SSL_TRUSTSTORE_TYPE_KEY, type);
+ ambariProperties.setProperty(Configuration.GANGLIA_HTTPS_KEY, Boolean.toString(gangliaSSL));
+ ambariProperties.setProperty(Configuration.NAGIOS_HTTPS_KEY, Boolean.toString(nagiosSSL));
+
+ Configuration configuration = new TestConfiguration(ambariProperties);
+
+ ComponentSSLConfiguration sslConfiguration = new ComponentSSLConfiguration();
+
+ sslConfiguration.init(configuration);
+
+ return sslConfiguration;
+ }
+
+ @Test
+ public void testGetTruststorePath() throws Exception {
+ ComponentSSLConfiguration sslConfiguration = getConfiguration("tspath", "tspass", "tstype", true, false);
+ Assert.assertEquals("tspath", sslConfiguration.getTruststorePath());
+ }
+
+ @Test
+ public void testGetTruststorePassword() throws Exception {
+ ComponentSSLConfiguration sslConfiguration = getConfiguration("tspath", "tspass", "tstype", true, false);
+ Assert.assertEquals("tspass", sslConfiguration.getTruststorePassword());
+ }
+
+ @Test
+ public void testGetTruststoreType() throws Exception {
+ ComponentSSLConfiguration sslConfiguration = getConfiguration("tspath", "tspass", "tstype", true, false);
+ Assert.assertEquals("tstype", sslConfiguration.getTruststoreType());
+ }
+
+ @Test
+ public void testIsGangliaSSL() throws Exception {
+ ComponentSSLConfiguration sslConfiguration = getConfiguration("tspath", "tspass", "tstype", true, false);
+ Assert.assertTrue(sslConfiguration.isGangliaSSL());
+ }
+
+ @Test
+ public void testIsNagiosSSL() throws Exception {
+ ComponentSSLConfiguration sslConfiguration = getConfiguration("tspath", "tspass", "tstype", true, false);
+ Assert.assertFalse(sslConfiguration.isNagiosSSL());
+ }
+
+ private static class TestConfiguration extends Configuration {
+
+ private TestConfiguration(Properties properties) {
+ super(properties);
+ }
+
+ @Override
+ protected void loadSSLParams() {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
index f0ceeb0..55182bb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
@@ -17,6 +17,8 @@
*/
package org.apache.ambari.server.controller.ganglia;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.configuration.ComponentSSLConfigurationTest;
import org.apache.ambari.server.controller.internal.ResourceImpl;
import org.apache.ambari.server.controller.internal.TemporalInfoImpl;
import org.apache.ambari.server.controller.spi.Request;
@@ -25,7 +27,11 @@ import org.apache.ambari.server.controller.spi.TemporalInfo;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -35,6 +41,7 @@ import java.util.Set;
/**
* Test the Ganglia property provider.
*/
+@RunWith(Parameterized.class)
public class GangliaPropertyProviderTest {
private static final String PROPERTY_ID = PropertyHelper.getPropertyId("metrics/jvm", "gcCount");
@@ -48,6 +55,30 @@ public class GangliaPropertyProviderTest {
private static final String HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name");
private static final String COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
+ private ComponentSSLConfiguration configuration;
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> configs() {
+ ComponentSSLConfiguration configuration1 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, false);
+
+ ComponentSSLConfiguration configuration2 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", true, false);
+
+ ComponentSSLConfiguration configuration3 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, true);
+
+ return Arrays.asList(new Object[][]{
+ {configuration1},
+ {configuration2},
+ {configuration3}
+ });
+ }
+
+ public GangliaPropertyProviderTest(ComponentSSLConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
@Test
public void testPopulateResources() throws Exception {
TestStreamProvider streamProvider = new TestStreamProvider("temporal_ganglia_data.txt");
@@ -56,6 +87,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -74,8 +106,10 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=jvm.metrics.gcCount&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=jvm.metrics.gcCount&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(3, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(PROPERTY_ID));
@@ -110,8 +144,10 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=mapred.shuffleOutput.shuffle_output_bytes,mapred.shuffleOutput.shuffle_success_outputs,mapred.shuffleOutput.shuffle_failed_outputs,mapred.shuffleOutput.shuffle_exceptions_caught&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=mapred.shuffleOutput.shuffle_output_bytes,mapred.shuffleOutput.shuffle_success_outputs,mapred.shuffleOutput.shuffle_failed_outputs,mapred.shuffleOutput.shuffle_exceptions_caught&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
+
Assert.assertEquals(6, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(shuffle_exceptions_caught));
@@ -129,6 +165,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.Host),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID
@@ -155,8 +192,10 @@ public class GangliaPropertyProviderTest {
Request request = PropertyHelper.getReadRequest(Collections.singleton(PROPERTY_ID), temporalInfoMap);
Assert.assertEquals(3, propertyProvider.populateResources(resources, request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPResourceManager,HDPSlaves,HDPHistoryServer,HDPNameNode&h=domU-12-31-39-0E-34-E3.compute-1.internal,domU-12-31-39-0E-34-E1.compute-1.internal,domU-12-31-39-0E-34-E2.compute-1.internal&m=jvm.metrics.gcCount&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPResourceManager,HDPSlaves,HDPHistoryServer,HDPNameNode&h=domU-12-31-39-0E-34-E3.compute-1.internal,domU-12-31-39-0E-34-E1.compute-1.internal,domU-12-31-39-0E-34-E2.compute-1.internal&m=jvm.metrics.gcCount&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
for (Resource res : resources) {
Assert.assertEquals(2, PropertyHelper.getProperties(res).size());
@@ -172,6 +211,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.Host),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID
@@ -192,8 +232,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(150, propertyProvider.populateResources(resources, request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPResourceManager,HDPSlaves,HDPHistoryServer,HDPNameNode&m=jvm.metrics.gcCount&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPResourceManager,HDPSlaves,HDPHistoryServer,HDPNameNode&m=jvm.metrics.gcCount&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
}
@@ -206,6 +247,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -224,8 +266,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(3, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
@@ -239,6 +282,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -261,8 +305,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&e=now&pt=true",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&e=now&pt=true";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(22, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(PROPERTY_ID2));
@@ -277,6 +322,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -293,8 +339,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&e=now&pt=true",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&e=now&pt=true";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(33, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
@@ -308,6 +355,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -326,8 +374,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(21, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
@@ -341,6 +390,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -359,8 +409,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(21, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
@@ -374,6 +425,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -392,8 +444,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(11, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
@@ -407,6 +460,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -425,8 +479,9 @@ public class GangliaPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") +
+ "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&s=10&e=20&r=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(11, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java
index d8642fc..7a9d7b3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java
@@ -17,6 +17,8 @@
*/
package org.apache.ambari.server.controller.ganglia;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.configuration.ComponentSSLConfigurationTest;
import org.apache.ambari.server.controller.internal.ResourceImpl;
import org.apache.ambari.server.controller.internal.TemporalInfoImpl;
import org.apache.ambari.server.controller.spi.Request;
@@ -25,7 +27,11 @@ import org.apache.ambari.server.controller.spi.TemporalInfo;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -33,11 +39,36 @@ import java.util.Map;
/**
* Test the Ganglia report property provider.
*/
+@RunWith(Parameterized.class)
public class GangliaReportPropertyProviderTest {
private static final String PROPERTY_ID = PropertyHelper.getPropertyId("metrics/load", "Procs");
private static final String CLUSTER_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "cluster_name");
+ private ComponentSSLConfiguration configuration;
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> configs() {
+ ComponentSSLConfiguration configuration1 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, false);
+
+ ComponentSSLConfiguration configuration2 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", true, false);
+
+ ComponentSSLConfiguration configuration3 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, true);
+
+ return Arrays.asList(new Object[][]{
+ {configuration1},
+ {configuration2},
+ {configuration3}
+ });
+ }
+
+ public GangliaReportPropertyProviderTest(ComponentSSLConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
@Test
public void testPopulateResources() throws Exception {
@@ -47,6 +78,7 @@ public class GangliaReportPropertyProviderTest {
GangliaReportPropertyProvider propertyProvider = new GangliaReportPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.Cluster),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID);
@@ -61,8 +93,8 @@ public class GangliaReportPropertyProviderTest {
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
- Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/ganglia/graph.php?g=load_report&json=1",
- streamProvider.getLastSpec());
+ String expected = (configuration.isGangliaSSL() ? "https" : "http") + "://domU-12-31-39-0E-34-E1.compute-1.internal/ganglia/graph.php?g=load_report&json=1";
+ Assert.assertEquals(expected, streamProvider.getLastSpec());
Assert.assertEquals(2, PropertyHelper.getProperties(resource).size());
Assert.assertNotNull(resource.getPropertyValue(PROPERTY_ID));
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/94ee6f92/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
index ecf3070..378b603 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
@@ -21,19 +21,26 @@ package org.apache.ambari.server.controller.internal;
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.HashSet;
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;
import org.apache.ambari.server.controller.utilities.StreamProvider;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+@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");
@@ -41,13 +48,42 @@ public class HttpPropertyProviderTest {
private static final String PROPERTY_ID_NAGIOS_ALERTS = PropertyHelper.getPropertyId("HostRoles", "nagios_alerts");
+ private ComponentSSLConfiguration configuration;
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> configs() {
+ ComponentSSLConfiguration configuration1 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, false);
+
+ ComponentSSLConfiguration configuration2 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", true, false);
+
+ ComponentSSLConfiguration configuration3 =
+ ComponentSSLConfigurationTest.getConfiguration("tspath", "tspass", "tstype", false, true);
+
+ return Arrays.asList(new Object[][]{
+ {configuration1},
+ {configuration2},
+ {configuration3}
+ });
+ }
+
+
+ public HttpPropertyProviderTest(ComponentSSLConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
@Test
public void testReadNagiosServer() throws Exception {
- Resource resource = doPopulate("NAGIOS_SERVER", Collections.<String>emptySet());
+ TestStreamProvider streamProvider = new TestStreamProvider(false);
+
+ Resource resource = doPopulate("NAGIOS_SERVER", Collections.<String>emptySet(), streamProvider);
Assert.assertNotNull("Expected non-null for 'nagios_alerts'",
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
+
+ Assert.assertEquals(configuration.isNagiosSSL(), streamProvider.getLastSpec().startsWith("https"));
}
@Test
@@ -57,7 +93,7 @@ public class HttpPropertyProviderTest {
propertyIds.add(PropertyHelper.getPropertyId("HostRoles", "state"));
propertyIds.add(PROPERTY_ID_COMPONENT_NAME);
- Resource resource = doPopulate("NAGIOS_SERVER", propertyIds);
+ Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, new TestStreamProvider(false));
Assert.assertNull("Expected null for 'nagios_alerts'",
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
@@ -70,7 +106,7 @@ public class HttpPropertyProviderTest {
propertyIds.add(PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
propertyIds.add(PROPERTY_ID_COMPONENT_NAME);
- Resource resource = doPopulate("NAGIOS_SERVER", propertyIds);
+ Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, new TestStreamProvider(false));
Assert.assertNotNull("Expected non-null for 'nagios_alerts'",
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
@@ -83,7 +119,7 @@ public class HttpPropertyProviderTest {
propertyIds.add(PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
propertyIds.add(PROPERTY_ID_COMPONENT_NAME);
- Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, true);
+ Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, new TestStreamProvider(true));
Assert.assertNull("Expected null for 'nagios_alerts'",
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
@@ -96,7 +132,7 @@ public class HttpPropertyProviderTest {
Set<String> propertyIds = new HashSet<String>();
propertyIds.add(PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
propertyIds.add(PROPERTY_ID_COMPONENT_NAME);
- Resource resource = doPopulate("NAGIOS_SERVER", propertyIds);
+ Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, new TestStreamProvider(false));
Object propertyValue = resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS);
Assert.assertNotNull("Expected non-null for 'nagios_alerts'", propertyValue);
@@ -125,7 +161,7 @@ public class HttpPropertyProviderTest {
@Test
public void testReadGangliaServer() throws Exception {
- Resource resource = doPopulate("GANGLIA_SERVER", Collections.<String>emptySet());
+ Resource resource = doPopulate("GANGLIA_SERVER", Collections.<String>emptySet(), new TestStreamProvider(false));
// !!! GANGLIA_SERVER has no current http lookup
Assert.assertNull("Expected null, was: " +
@@ -133,15 +169,11 @@ public class HttpPropertyProviderTest {
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
}
- private Resource doPopulate(String componentName, Set<String> requestProperties) throws Exception {
- return doPopulate(componentName, requestProperties, false);
- }
-
private Resource doPopulate(String componentName,
- Set<String> requestProperties, boolean throwException) throws Exception {
-
+ Set<String> requestProperties, StreamProvider streamProvider) throws Exception {
+
HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
- new TestStreamProvider(throwException),
+ streamProvider, configuration,
PROPERTY_ID_CLUSTER_NAME,
PROPERTY_ID_HOST_NAME,
PROPERTY_ID_COMPONENT_NAME);
@@ -160,13 +192,16 @@ public class HttpPropertyProviderTest {
private static class TestStreamProvider implements StreamProvider {
private boolean throwError = false;
-
+ private String lastSpec = null;
+
private TestStreamProvider(boolean throwErr) {
throwError = throwErr;
}
@Override
public InputStream readFrom(String spec) throws IOException {
+ lastSpec = spec;
+
if (throwError) {
throw new IOException("Fake error");
}
@@ -175,6 +210,10 @@ public class HttpPropertyProviderTest {
+ " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
}
+
+ public String getLastSpec() {
+ return lastSpec;
+ }
}
}