diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 8d34f4e..1d5b504 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -2193,6 +2193,21 @@ public static String getClusterId(Configuration conf) { return clusterId; } + public static String getClasspath(Configuration conf) { + StringBuilder classPathEnv = new StringBuilder(ApplicationConstants. + Environment.CLASSPATH.$$()) + .append(ApplicationConstants.CLASS_PATH_SEPARATOR).append("./*"); + for (String c : conf.getStrings( + YarnConfiguration.YARN_APPLICATION_CLASSPATH, + YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH)) { + classPathEnv.append(ApplicationConstants.CLASS_PATH_SEPARATOR); + classPathEnv.append(c.trim()); + } + classPathEnv.append(ApplicationConstants.CLASS_PATH_SEPARATOR).append( + "./log4j.properties"); + return classPathEnv.toString(); + } + /* For debugging. mp configurations to system output as XML format. */ public static void main(String[] args) throws Exception { new YarnConfiguration(new Configuration()).writeXml(System.out); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java index a0a6bda..5d873ed 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java @@ -151,6 +151,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SystemPropertyInfo; import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.AdHocLogDumper; @@ -1802,6 +1803,14 @@ public CancelDelegationTokenResponse run() throws IOException, return Response.status(Status.OK).build(); } + @GET + @Path("/system-properties") + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public SystemPropertyInfo getSystemProperties() { + init(); + return new SystemPropertyInfo(this.rm.getConfig()); + } + private Token extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/SystemPropertyInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/SystemPropertyInfo.java new file mode 100644 index 0000000..24fb74b --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/SystemPropertyInfo.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.yarn.server.resourcemanager.webapp.dao; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.conf.YarnConfiguration; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class SystemPropertyInfo { + + public String classPath; + + public SystemPropertyInfo() { + }// JAXB needs this + + public SystemPropertyInfo(Configuration config) { + this.classPath = YarnConfiguration.getClasspath(config); + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java index 530c06f..bf5fb26 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServices.java @@ -727,4 +727,47 @@ private void checkSchedulerLogFileAndCleanup() { assertTrue("scheduler log file doesn't exist", logFile.exists()); FileUtils.deleteQuietly(logFile); } + + @Test + public void testSystemProperties() throws JSONException { + WebResource r = resource(); + ClientResponse response = r.path("ws").path("v1").path("cluster") + .path("system-properties").accept(MediaType.APPLICATION_JSON) + .get(ClientResponse.class); + String responseString = response.getEntity(String.class); + assertEquals(responseString, MediaType.APPLICATION_JSON_TYPE, response.getType()); + JSONObject json = new JSONObject(responseString); + verifySystemProperties(json); + } + + private void verifySystemProperties(JSONObject json) throws JSONException { + assertEquals("incorrect number of elements", 1, json.length()); + String classPath = YarnConfiguration.getClasspath(rm.getConfig()); + assertEquals("classpath doesn't match", json.getString("classPath"), classPath); + } + + @Test + public void testSystemPropertiesXML() throws Exception { + WebResource r = resource(); + ClientResponse response = r.path("ws").path("v1").path("cluster") + .path("system-properties").accept(MediaType.APPLICATION_XML) + .get(ClientResponse.class); + String responseString = response.getEntity(String.class); + assertEquals(responseString, MediaType.APPLICATION_XML_TYPE, response.getType()); + verifySystemPropertiesXML(responseString); + } + + private void verifySystemPropertiesXML(String xml) throws Exception { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(xml)); + Document dom = db.parse(is); + NodeList nodes = dom.getElementsByTagName("systemPropertyInfo"); + assertEquals("incorrect number of elements", 1, nodes.getLength()); + Element element = (Element)nodes.item(0); + String classPath = YarnConfiguration.getClasspath(rm.getConfig()); + assertEquals("classpath doesn't match", + WebServicesTestUtils.getXmlString(element, "classPath"), classPath); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md index 53df195..5f67833 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md @@ -32,7 +32,7 @@ ResourceManager REST API's. * [Cluster Application Queue API](#Cluster_Application_Queue_API) * [Cluster Application Priority API](#Cluster_Application_Priority_API) * [Cluster Delegation Tokens API](#Cluster_Delegation_Tokens_API) - +* [Cluster System Properties API](#Cluster_System_Properties_API) Overview -------- @@ -3104,3 +3104,73 @@ Once setup, delegation tokens can be fetched using the web services listed above { "state":"KILLED" } + +Cluster System Properties API +----------------------------- + +With System Properties API, you can get YARN system properties which are useful for building client applications. + +### URI + + * http:///ws/v1/cluster/system-properties + +### HTTP Operations Supported + + * GET + +### Query Parameters Supported + + None + +### Elements of the *systemPropertyInfo* object + +| Item | Data Type | Description | +|:---- |:---- |:---- | +| classPath | string | The YARN classpath | + +### Response Examples + +**JSON response** + +HTTP Request: + + GET http:///ws/v1/cluster/system-properties + +Response Header: + + HTTP/1.1 200 OK + Content-Type: application/json + Transfer-Encoding: chunked + Server: Jetty(6.1.26) + +Response Body: + +```json +{ + "classPath": "{{CLASSPATH}}./*{{HADOOP_CONF_DIR}}{{HADOOP_COMMON_HOME}}/share/hadoop/common/*{{HADOOP_COMMON_HOME}}/share/hadoop/common/lib/*{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/*{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/lib/*{{HADOOP_YARN_HOME}}/share/hadoop/yarn/*{{HADOOP_YARN_HOME}}/share/hadoop/yarn/lib/*./log4j.properties" +} +``` + +**XML response** + +HTTP Request: + + Accept: application/xml + GET http:///ws/v1/cluster/system-properties + +Response Header: + + HTTP/1.1 200 OK + Content-Type: application/xml + Content-Length: 243 + Server: Jetty(6.1.26) + +Response Body: + +```xml + + +{{CLASSPATH}}./*{{HADOOP_CONF_DIR}}{{HADOOP_COMMON_HOME}}/share/hadoop/common/*{{HADOOP_COMMON_HOME}}/share/hadoop/common/lib/*{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/*{{HADOOP_HDFS_HOME}}/share/hadoop/hdfs/lib/*{{HADOOP_YARN_HOME}}/share/hadoop/yarn/*{{HADOOP_YARN_HOME}}/share/hadoop/yarn/lib/*./log4j.properties + + +``` \ No newline at end of file