You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by di...@apache.org on 2013/09/12 03:56:13 UTC
git commit: 8525 ambari server should use https instead of http to
talk to ssl enabled hadoop
Updated Branches:
refs/heads/trunk 5da35605b -> 60be849a3
8525 ambari server should use https instead of http to talk to ssl enabled hadoop
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/60be849a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/60be849a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/60be849a
Branch: refs/heads/trunk
Commit: 60be849a322cdd47a10b7a4d6d8d7177ace2bf75
Parents: 5da3560
Author: Dilli Dorai Arumugam <da...@hortonworks.com>
Authored: Thu Sep 5 16:50:58 2013 -0700
Committer: Dilli Dorai Arumugam <da...@hortonworks.com>
Committed: Wed Sep 11 18:56:02 2013 -0700
----------------------------------------------------------------------
.../internal/AbstractProviderModule.java | 50 +++++++++++++++++++-
.../controller/internal/URLStreamProvider.java | 14 ++++--
.../server/controller/jmx/JMXHostProvider.java | 15 ++++++
.../controller/jmx/JMXPropertyProvider.java | 38 ++++++++++++---
.../internal/JMXHostProviderTest.java | 6 +++
.../controller/jmx/JMXPropertyProviderTest.java | 5 ++
6 files changed, 115 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/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 0caf9bc..e0bf0df 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
@@ -71,12 +71,16 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
HashMap<Service.Type, Map<String, String>>();
private static final Map<String, Service.Type> componentServiceMap = new
HashMap<String, Service.Type>();
-
+
+ private static final Map<String, Map<String, String>> jmxDesiredProperties = new HashMap<String, Map<String,String>>();
+ private volatile Map<String, String> clusterCoreSiteConfigVersionMap = new HashMap<String, String>();
+ private volatile Map<String, String> clusterJmxProtocolMap = new HashMap<String, String>();
+
static {
serviceConfigTypes.put(Service.Type.HDFS, "hdfs-site");
serviceConfigTypes.put(Service.Type.MAPREDUCE, "mapred-site");
serviceConfigTypes.put(Service.Type.HBASE, "hbase-site");
-
+
componentServiceMap.put("NAMENODE", Service.Type.HDFS);
componentServiceMap.put("DATANODE", Service.Type.HDFS);
componentServiceMap.put("JOBTRACKER", Service.Type.MAPREDUCE);
@@ -94,6 +98,10 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
initPropMap = new HashMap<String, String>();
initPropMap.put("HBASE_MASTER", "hbase.master.info.port");
serviceDesiredProperties.put(Service.Type.HBASE, initPropMap);
+
+ initPropMap = new HashMap<String, String>();
+ initPropMap.put("NAMENODE", "hadoop.ssl.enabled");
+ jmxDesiredProperties.put("NAMENODE", initPropMap);
}
/**
@@ -709,4 +717,42 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
}
+
+ @Override
+ public String getJMXProtocol(String clusterName, String componentName) {
+ String jmxProtocolString = clusterJmxProtocolMap.get(clusterName);
+ try {
+ String newCoreSiteConfigVersion = getDesiredConfigVersion(clusterName, "core-site");
+ String cachedCoreSiteConfigVersion = clusterCoreSiteConfigVersionMap.get(clusterName);
+ if (!newCoreSiteConfigVersion.equals(cachedCoreSiteConfigVersion)) {
+ clusterCoreSiteConfigVersionMap.put(clusterName, newCoreSiteConfigVersion);
+
+ // Getting protocolMap for NAMENODE as it is the same property hadoop.ssl.enabled for all components
+ Map<String, String> protocolMap = getDesiredConfigMap(
+ clusterName,
+ newCoreSiteConfigVersion, "core-site",
+ jmxDesiredProperties.get("NAMENODE"));
+ jmxProtocolString = getJMXProtocolString(protocolMap.get("NAMENODE"), componentName);
+ clusterJmxProtocolMap.put(clusterName, jmxProtocolString);
+ }
+
+ } catch (Exception e) {
+ LOG.error("Exception while detecting JMX protocol for component: " +
+ componentName, e);
+ LOG.error("Defaulting to HTTP protocol for component: " +
+ componentName);
+ jmxProtocolString = "http";
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("JMXProtocol = " + jmxProtocolString + ", for clusterName=" + clusterName +
+ ", componentName = " + componentName);
+ }
+ return jmxProtocolString;
+ }
+
+ private String getJMXProtocolString(String value, String componentName) {
+ return Boolean.valueOf(value) ? "https" : "http";
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/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 1bce033..c6a267f 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
@@ -68,15 +68,19 @@ public class URLStreamProvider implements StreamProvider {
this.connTimeout = connectionTimeout;
this.readTimeout = readTimeout;
- this.path = path;
- this.password = password;
- this.type = type;
+ this.path = path; // truststroe path
+ this.password = password; // truststore password
+ this.type = type; // truststroe type
appCookieManager = new AppCookieManager();
}
@Override
public InputStream readFrom(String spec) throws IOException {
-
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("readFrom spec:" + spec);
+ }
+
HttpURLConnection connection = spec.startsWith("https") ?
(HttpURLConnection)getSSLConnection(spec)
: (HttpURLConnection)getConnection(spec);
@@ -161,7 +165,7 @@ public class URLStreamProvider implements StreamProvider {
.openConnection());
connection.setSSLSocketFactory(sslSocketFactory);
-
+
return connection;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
index b14733f..142740c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
@@ -17,7 +17,9 @@
*/
package org.apache.ambari.server.controller.jmx;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
/**
* Provider of JMX host information.
@@ -49,4 +51,17 @@ public interface JMXHostProvider {
*/
public String getPort(String clusterName, String componentName)
throws SystemException;
+
+ /**
+ * Get the protocol for the specified cluster name and component.
+ *
+ * @param clusterName the cluster name
+ * @param componentName the component name
+ *
+ * @return the JMX protocol for the specified cluster name and component, one of http or https
+ *
+ */
+ public String getJMXProtocol(String clusterName, String componentName) ;
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
index dca738a..468e338 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
@@ -40,10 +40,12 @@ import java.util.regex.Pattern;
import org.apache.ambari.server.controller.internal.AbstractPropertyProvider;
import org.apache.ambari.server.controller.internal.PropertyInfo;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
import org.apache.ambari.server.controller.utilities.StreamProvider;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
@@ -166,8 +168,7 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
this.statePropertyId = statePropertyId;
this.healthyStates = healthyStates;
}
-
-
+
// ----- PropertyProvider --------------------------------------------------
@Override
@@ -225,16 +226,29 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
/**
* Get the spec to locate the JMX stream from the given host and port
*
+ ** @param protocol the protocol, one of http or https
* @param hostName the host name
* @param port the port
*
* @return the spec
*/
- protected String getSpec(String hostName, String port) {
- return "http://" + hostName + ":" + port + "/jmx";
+ protected String getSpec(String protocol, String hostName, String port) {
+ return protocol + "://" + hostName + ":" + port + "/jmx";
}
/**
+ * Get the spec to locate the JMX stream from the given host and port
+ *
+ * @param hostName the host name
+ * @param port the port
+ *
+ * @return the spec
+ */
+ protected String getSpec(String hostName, String port) {
+ return getSpec("http", hostName, port);
+ }
+
+ /**
* Get a callable that can be used to populate the given resource.
*
* @param resource the resource to be populated
@@ -298,9 +312,15 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
throw new SystemException(
"Unable to get JMX metrics. No host name for " + componentName, null);
}
+
+ String protocol = getJMXProtocol(clusterName, componentName);
+ if (protocol == null) {
+ throw new SystemException(
+ "Unable to get JMX metrics. No protocol name for " + componentName, null);
+ }
try {
- InputStream in = streamProvider.readFrom(getSpec(hostName, port));
+ InputStream in = streamProvider.readFrom(getSpec(protocol, hostName, port));
try {
JMXMetricHolder metricHolder = objectReader.readValue(in);
@@ -410,6 +430,11 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
return port == null ? DEFAULT_JMX_PORTS.get(componentName) : port;
}
+ private String getJMXProtocol(String clusterName, String componentName) {
+ String protocol = jmxHostProvider.getJMXProtocol(clusterName, componentName);
+ return protocol;
+ }
+
private String getHost(Resource resource, String clusterName, String componentName) throws SystemException {
return hostNamePropertyId == null ?
jmxHostProvider.getHostName(clusterName, componentName) :
@@ -466,5 +491,6 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
throw (SystemException) throwable;
}
throw new SystemException (msg, throwable);
- }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
index 527ccb5..35469cc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
@@ -303,5 +303,11 @@ public class JMXHostProviderTest {
return configResourceProvider;
return null;
}
+
+ @Override
+ public String getJMXProtocol(String clusterName, String componentName) {
+ return "http";
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/60be849a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
index 81ffb49..6aafd98 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
@@ -813,5 +813,10 @@ public class JMXPropertyProviderTest {
return null;
}
+ @Override
+ public String getJMXProtocol(String clusterName, String componentName) {
+ return "http";
+ }
+
}
}