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/07/23 22:22:24 UTC
[1/3] git commit: AMBARI-2711 - Get call on host resource at
api/v1/hosts/(hostname) returns empty response
Updated Branches:
refs/heads/trunk 0368796c5 -> aa31e2ccb
AMBARI-2711 - Get call on host resource at api/v1/hosts/(hostname) returns empty response
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/6e2fa034
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/6e2fa034
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/6e2fa034
Branch: refs/heads/trunk
Commit: 6e2fa0343ae507e7f776da39c321ab18024957c9
Parents: e163b0e
Author: tbeerbower <tb...@hortonworks.com>
Authored: Tue Jul 23 13:00:00 2013 -0400
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jul 23 16:10:48 2013 -0400
----------------------------------------------------------------------
.../internal/AbstractProviderModule.java | 41 +++++++++++++-------
.../internal/VersioningPropertyProvider.java | 24 ++++++++----
.../VersioningPropertyProviderTest.java | 17 +++++++-
3 files changed, 57 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/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 1a93737..77556f0 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
@@ -530,14 +530,16 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+ AbstractPropertyProvider lastProvider = null;
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
- providers.put(version, new JMXPropertyProvider(PropertyHelper.getJMXPropertyIds(type, version), streamProvider,
- jmxHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId, statePropertyId, healthyStates));
+ lastProvider = new JMXPropertyProvider(PropertyHelper.getJMXPropertyIds(type, version), streamProvider,
+ jmxHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId, statePropertyId, healthyStates);
+ providers.put(version, lastProvider);
}
- return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+ return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
/**
@@ -551,14 +553,16 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+ AbstractPropertyProvider lastProvider = null;
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
- providers.put(version, new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- configuration, hostProvider, clusterNamePropertyId));
+ lastProvider = new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
+ configuration, hostProvider, clusterNamePropertyId);
+ providers.put(version, lastProvider);
}
- return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+ return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
/**
@@ -573,14 +577,16 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+ AbstractPropertyProvider lastProvider = null;
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
- providers.put(version, new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId));
+ lastProvider = new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
+ configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId);
+ providers.put(version, lastProvider);
}
- return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+ return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
/**
@@ -595,14 +601,17 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+ AbstractPropertyProvider lastProvider = null;
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
+ lastProvider =
+ new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version),
+ streamProvider, configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId);
- providers.put(version, new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId));
+ providers.put(version, lastProvider);
}
- return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+ return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
/**
@@ -618,13 +627,15 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+ AbstractPropertyProvider lastProvider = null;
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
- providers.put(version, new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId));
+ lastProvider = new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
+ configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId);
+ providers.put(version, lastProvider);
}
- return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+ return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
index 9c94ece..b1b1d5c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
@@ -38,6 +38,7 @@ public class VersioningPropertyProvider extends BaseProvider implements Property
private final Map<String, PropertyHelper.MetricsVersion> clusterVersions;
private final Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers;
+ private final AbstractPropertyProvider defaultProvider;
private final String clusterNamePropertyId;
/**
@@ -45,11 +46,13 @@ public class VersioningPropertyProvider extends BaseProvider implements Property
*/
public VersioningPropertyProvider(Map<String, PropertyHelper.MetricsVersion> clusterVersions,
Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers,
+ AbstractPropertyProvider defaultProvider,
String clusterNamePropertyId) {
super(getComponentMetrics(providers));
this.clusterVersions = clusterVersions;
this.providers = providers;
+ this.defaultProvider = defaultProvider;
this.clusterNamePropertyId = clusterNamePropertyId;
}
@@ -77,18 +80,23 @@ public class VersioningPropertyProvider extends BaseProvider implements Property
// give each set of resources to the underlying provider that matches the
// metrics version of the associated cluster
for (Map.Entry<String, Set<Resource>> entry : resourcesByCluster.entrySet()) {
- String clusterName = entry.getKey();
- Set<Resource> resourceSet = entry.getValue();
+ String clusterName = entry.getKey();
+ Set<Resource> resourceSet = entry.getValue();
+ AbstractPropertyProvider provider = null;
- PropertyHelper.MetricsVersion version = clusterVersions.get(clusterName);
+ if (clusterName == null) {
+ provider = defaultProvider;
+ } else {
+ PropertyHelper.MetricsVersion version = clusterVersions.get(clusterName);
- if (version != null) {
-
- AbstractPropertyProvider provider = providers.get(version);
- if (provider != null) {
- keepers.addAll(provider.populateResources(resourceSet, request, predicate));
+ if (version != null) {
+ provider = providers.get(version);
}
}
+
+ if (provider != null) {
+ keepers.addAll(provider.populateResources(resourceSet, request, predicate));
+ }
}
return keepers;
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
index b881c41..1db4e0b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
@@ -69,8 +69,9 @@ public class VersioningPropertyProviderTest {
providers.put(PropertyHelper.MetricsVersion.HDP2, propertyProvider2);
-
- VersioningPropertyProvider provider = new VersioningPropertyProvider(clusterVersionsMap, providers, PropertyHelper.getPropertyId("HostRoles", "cluster_name"));
+ // set propertyProvider2 as the default provider
+ VersioningPropertyProvider provider = new VersioningPropertyProvider(clusterVersionsMap, providers,
+ propertyProvider2, PropertyHelper.getPropertyId("HostRoles", "cluster_name"));
Request request = PropertyHelper.getReadRequest();
@@ -106,6 +107,18 @@ public class VersioningPropertyProviderTest {
Assert.assertEquals(resource1, propertyProvider1.getResource());
Assert.assertEquals(resource2, propertyProvider2.getResource());
+
+
+ // test resource with no associated cluster ... should go to default provider2
+ propertyProvider1.setResource(null);
+ propertyProvider2.setResource(null);
+
+ Resource resource3 = new ResourceImpl(Resource.Type.HostComponent);
+
+ provider.populateResources(Collections.singleton(resource3), request, null);
+
+ Assert.assertNull(propertyProvider1.getResource());
+ Assert.assertEquals(resource3, propertyProvider2.getResource());
}
private class TestJMXPropertyProvider extends JMXPropertyProvider {
[2/3] git commit: AMBARI-2691 - Need https support for ganglia/nagios
to be able to have https support throughout the stack.
Posted by tb...@apache.org.
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/e163b0e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/e163b0e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/e163b0e5
Branch: refs/heads/trunk
Commit: e163b0e5dd5d1109a69c06febc40752db5074d26
Parents: fa0fc4a
Author: tbeerbower <tb...@hortonworks.com>
Authored: Thu Jul 18 22:45:59 2013 -0400
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jul 23 16:10:48 2013 -0400
----------------------------------------------------------------------
ambari-server/sbin/ambari-server | 8 ++
.../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 | 21 ++-
.../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, 651 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e163b0e5/ambari-server/sbin/ambari-server
----------------------------------------------------------------------
diff --git a/ambari-server/sbin/ambari-server b/ambari-server/sbin/ambari-server
index 0da6550..76eabc5 100644
--- a/ambari-server/sbin/ambari-server
+++ b/ambari-server/sbin/ambari-server
@@ -110,6 +110,14 @@ 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]"
exit 1
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e163b0e5/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/e163b0e5/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 7e780f6..a6d03b5 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
@@ -179,6 +179,8 @@ public class Configuration {
public static final String JAVAX_SSL_TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword";
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";
public static final String SRVR_TWO_WAY_SSL_PORT_DEFAULT = "8441";
@@ -362,9 +364,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/e163b0e5/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 a04ab61..18345fc 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;
@@ -446,6 +447,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/e163b0e5/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/e163b0e5/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/e163b0e5/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/e163b0e5/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/e163b0e5/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/e163b0e5/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 923fca9..1a93737 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;
@@ -257,14 +258,17 @@ 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(createGangliaReportPropertyProvider(
type,
streamProvider,
+ ComponentSSLConfiguration.instance(),
this,
PropertyHelper.getPropertyId("Clusters", "cluster_name")));
break;
@@ -272,6 +276,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(createGangliaHostPropertyProvider(
type,
streamProvider,
+ ComponentSSLConfiguration.instance(),
this,
PropertyHelper.getPropertyId("Hosts", "cluster_name"),
PropertyHelper.getPropertyId("Hosts", "host_name")
@@ -291,6 +296,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(createGangliaComponentPropertyProvider(
type,
streamProvider,
+ ComponentSSLConfiguration.instance(),
this,
PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
@@ -309,6 +315,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
providers.add(createGangliaHostComponentPropertyProvider(
type,
streamProvider,
+ ComponentSSLConfiguration.instance(),
this,
PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
PropertyHelper.getPropertyId("HostRoles", "host_name"),
@@ -537,6 +544,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
* Create the Ganglia report property provider for the given type.
*/
private PropertyProvider createGangliaReportPropertyProvider( Resource.Type type, StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId) {
updateClusterVersion();
@@ -547,7 +555,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
providers.put(version, new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- hostProvider, clusterNamePropertyId));
+ configuration, hostProvider, clusterNamePropertyId));
}
return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
@@ -557,6 +565,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
* Create the Ganglia host property provider for the given type.
*/
private PropertyProvider createGangliaHostPropertyProvider( Resource.Type type, StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String hostNamePropertyId) {
@@ -568,7 +577,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
providers.put(version, new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- hostProvider, clusterNamePropertyId, hostNamePropertyId));
+ configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId));
}
return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
@@ -578,6 +587,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
* Create the Ganglia component property provider for the given type.
*/
private PropertyProvider createGangliaComponentPropertyProvider( Resource.Type type, StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String componentNamePropertyId) {
@@ -589,7 +599,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
providers.put(version, new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- hostProvider, clusterNamePropertyId, componentNamePropertyId));
+ configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId));
}
return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
@@ -599,6 +609,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
* Create the Ganglia host component property provider for the given type.
*/
private PropertyProvider createGangliaHostComponentPropertyProvider( Resource.Type type, StreamProvider streamProvider,
+ ComponentSSLConfiguration configuration,
GangliaHostProvider hostProvider,
String clusterNamePropertyId,
String hostNamePropertyId,
@@ -611,7 +622,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values()) {
providers.put(version, new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type, version), streamProvider,
- hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId));
+ configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId));
}
return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e163b0e5/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/e163b0e5/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/e163b0e5/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/e163b0e5/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 ad2aba2..b3ddf40 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"
@@ -636,6 +646,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]
@@ -2592,6 +2605,10 @@ def encrypt_password(alias, password):
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:
@@ -3048,6 +3065,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)
@@ -3460,7 +3596,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/e163b0e5/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/e163b0e5/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 7fbb1a2..7f57827 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;
@@ -26,7 +28,11 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.controller.utilities.PropertyHelper.MetricsVersion;
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;
@@ -36,6 +42,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");
@@ -49,6 +56,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");
@@ -57,6 +88,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, PropertyHelper.MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -75,8 +107,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));
@@ -111,8 +145,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));
@@ -130,6 +166,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.Host, PropertyHelper.MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID
@@ -156,8 +193,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());
@@ -173,6 +212,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.Host, PropertyHelper.MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID
@@ -193,8 +233,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());
}
@@ -207,6 +248,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -225,8 +267,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));
@@ -240,6 +283,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -262,8 +306,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));
@@ -278,6 +323,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -294,8 +340,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));
@@ -309,6 +356,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -327,8 +375,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));
@@ -342,6 +391,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -360,8 +410,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));
@@ -375,6 +426,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -393,8 +445,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));
@@ -408,6 +461,7 @@ public class GangliaPropertyProviderTest {
GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(
PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent, MetricsVersion.HDP1),
streamProvider,
+ configuration,
hostProvider,
CLUSTER_NAME_PROPERTY_ID,
HOST_NAME_PROPERTY_ID,
@@ -426,8 +480,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/e163b0e5/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 358e0a5..243e630 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, PropertyHelper.MetricsVersion.HDP1),
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/e163b0e5/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;
+ }
}
}
[3/3] git commit: Merge branch 'trunk' of
https://git-wip-us.apache.org/repos/asf/incubator-ambari into trunk
Posted by tb...@apache.org.
Merge branch 'trunk' of https://git-wip-us.apache.org/repos/asf/incubator-ambari into trunk
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/aa31e2cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/aa31e2cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/aa31e2cc
Branch: refs/heads/trunk
Commit: aa31e2ccb5bd6ef63b01a3fc7acc561dd4a430a5
Parents: 6e2fa03 0368796
Author: tbeerbower <tb...@hortonworks.com>
Authored: Tue Jul 23 16:20:23 2013 -0400
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jul 23 16:20:23 2013 -0400
----------------------------------------------------------------------
ambari-web/app/views/common/chart/linear_time.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------