You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chukwa.apache.org by ey...@apache.org on 2014/07/19 10:06:34 UTC
svn commit: r1611856 [1/2] - in /chukwa/trunk: ./
src/main/java/org/apache/hadoop/chukwa/datacollection/agent/
src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/
src/main/resources/ src/main/webapps/ src/site/
src/test/java/org/apache/ha...
Author: eyang
Date: Sat Jul 19 08:06:33 2014
New Revision: 1611856
URL: http://svn.apache.org/r1611856
Log:
CHUKWA-718. Updated Chukwa Agent REST API document and generation method. (Eric Yang)
Added:
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorAveragedRate.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorConfig.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorInfo.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorList.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/ContextProvider.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/Examples.java
chukwa/trunk/src/main/resources/
chukwa/trunk/src/main/resources/agent-rest.xml
chukwa/trunk/src/main/resources/application-grammars.xml
chukwa/trunk/src/main/webapps/
chukwa/trunk/src/main/webapps/wadl.xsl
Modified:
chukwa/trunk/CHANGES.txt
chukwa/trunk/pom.xml
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java
chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorController.java
chukwa/trunk/src/site/site.xml
chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/TestAddAdaptor.java
chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/rest/TestAdaptorController.java
Modified: chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/chukwa/trunk/CHANGES.txt?rev=1611856&r1=1611855&r2=1611856&view=diff
==============================================================================
--- chukwa/trunk/CHANGES.txt (original)
+++ chukwa/trunk/CHANGES.txt Sat Jul 19 08:06:33 2014
@@ -34,6 +34,8 @@ Release 0.6 - Unreleased
IMPROVEMENTS
+ CHUKWA-718. Updated Chukwa Agent REST API document and generation method. (Eric Yang)
+
CHUKWA-710. Set TCP socket reuse option for server sockets. (Shreyas Subramanya)
CHUKWA-698. Update RAT plugin to 0.10 release and fixed missing license header. (Eric Yang)
Modified: chukwa/trunk/pom.xml
URL: http://svn.apache.org/viewvc/chukwa/trunk/pom.xml?rev=1611856&r1=1611855&r2=1611856&view=diff
==============================================================================
--- chukwa/trunk/pom.xml (original)
+++ chukwa/trunk/pom.xml Sat Jul 19 08:06:33 2014
@@ -354,18 +354,6 @@
</resource>
</resources>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-site-plugin</artifactId>
- <version>3.0</version>
- <dependencies>
- <dependency><!-- add support for ssh/scp -->
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ssh</artifactId>
- <version>1.0</version>
- </dependency>
- </dependencies>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
@@ -543,7 +531,7 @@
</goals>
<configuration>
<skip>false</skip>
- <argLine>-Xmx1024m -Dtest.build.data=${test.build.data}</argLine>
+ <argLine>-Xmx1024m</argLine>
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
<forkMode>pertest</forkMode>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
@@ -556,6 +544,7 @@
<exclude>**/*$*</exclude>
</excludes>
<systemPropertyVariables>
+ <test.build.data>${project.build.directory}/test/var</test.build.data>
<CHUKWA_LOG_DIR>${project.build.directory}/test/var/log</CHUKWA_LOG_DIR>
<CHUKWA_CONF_DIR>${project.build.directory}/test/conf</CHUKWA_CONF_DIR>
<CHUKWA_DATA_DIR>${project.build.directory}/test/var</CHUKWA_DATA_DIR>
@@ -707,6 +696,7 @@
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/site" />
+ <mkdir dir="${basedir}/target/site/apidocs"/>
<exec executable="perl" input="CHANGES.txt" output="${project.build.directory}/site/changes.html" failonerror="true">
<arg value="src/site/resources/scripts/changes2html.pl" />
</exec>
@@ -1064,6 +1054,149 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>docs</id>
+ <activation>
+ <file>
+ <exists>/usr/bin/xsltproc</exists>
+ </file>
+ </activation>
+ <build>
+ <plugins>
+ <!-- Generate HTML version of REST API document -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.0</version>
+ <dependencies>
+ <dependency><!-- add support for ssh/scp -->
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>agent-public-api</id>
+ <goals>
+ <goal>javadoc</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <verbose>false</verbose>
+ <show>public</show>
+ <subpackages>org.apache.hadoop.chukwa.datacollection.agent.rest</subpackages>
+ <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDocletJSON</doclet>
+ <!-- <docletPath>${path.separator}${project.build.outputDirectory}</docletPath> -->
+ <docletArtifacts>
+ <docletArtifact>
+ <groupId>com.atlassian.plugins.rest</groupId>
+ <artifactId>atlassian-rest-doclet</artifactId>
+ <version>2.8.0-m3</version>
+ </docletArtifact>
+ </docletArtifacts>
+ <useStandardDocletOptions>false</useStandardDocletOptions>
+ <additionalparam>-output ${project.build.outputDirectory}/agent-rest.xml</additionalparam>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>maven-wadl-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>generate</id>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <phase>compile</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <wadlFile>${project.build.outputDirectory}/application.wadl</wadlFile>
+ <formatWadlFile>true</formatWadlFile>
+ <baseUri>http://[host]:[port]/rest/v2</baseUri>
+ <packagesResourceConfig>
+ <param>org.apache.hadoop.chukwa.datacollection.agent.rest</param>
+ </packagesResourceConfig>
+ <wadlGenerators>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc</className>
+ <properties>
+ <property>
+ <name>applicationDocsFile</name>
+ <value>${basedir}/src/main/resources/agent-rest.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
+ <properties>
+ <property>
+ <name>grammarsFile</name>
+ <value>${basedir}/src/main/resources/application-grammars.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ <wadlGeneratorDescription>
+ <className>com.sun.jersey.server.wadl.generators.resourcedoc.WadlGeneratorResourceDocSupport</className>
+ <properties>
+ <property>
+ <name>resourceDocFile</name>
+ <value>${project.build.outputDirectory}/agent-rest.xml</value>
+ </property>
+ </properties>
+ </wadlGeneratorDescription>
+ </wadlGenerators>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>exec-xsltproc: target/application.html</id>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <executable>xsltproc</executable>
+ <commandlineArgs>-o ${project.build.directory}/site/apidocs/agent-rest.html src/main/webapps/wadl.xsl target/classes/application.wadl</commandlineArgs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>maven-wadl-plugin</artifactId>
+ <version>1.8</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>wadl-resourcedoc-doclet</artifactId>
+ <version>1.8</version>
+ </dependency>
+ </dependencies>
+ </profile>
</profiles>
<repositories>
@@ -1079,6 +1212,10 @@
<id>Apache</id>
<url>http://repo.maven.apache.org/maven2/</url>
</repository>
+ <repository>
+ <id>opencast</id>
+ <url>http://repository.opencastproject.org/nexus/content/repositories/public/</url>
+ </repository>
</repositories>
<dependencyManagement>
@@ -1146,6 +1283,34 @@
<report>javadoc</report>
</reports>
</reportSet>
+<!-- <reportSet>
+ <id>restdoc</id>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <verbose>false</verbose>
+ <show>public</show>
+ <subpackages>org.apache.hadoop.chukwa.datacollection.agent.rest</subpackages>
+ <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDoclet</doclet>
+ <docletPath>${path.separator}${project.build.outputDirectory}</docletPath>
+ <docletArtifacts>
+ <docletArtifact>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>wadl-resourcedoc-doclet</artifactId>
+ <version>1.8</version>
+ </docletArtifact>
+ <docletArtifact>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.6.1</version>
+ </docletArtifact>
+ </docletArtifacts>
+ <useStandardDocletOptions>false</useStandardDocletOptions>
+ <additionalparam>-output ${project.build.outputDirectory}/agent-rest.xml</additionalparam>
+ </configuration>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet> -->
</reportSets>
</plugin>
</plugins>
Modified: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java?rev=1611856&r1=1611855&r2=1611856&view=diff
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java (original)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java Sat Jul 19 08:06:33 2014
@@ -365,7 +365,7 @@ public class ChukwaAgent implements Adap
jaxRsPackages.toString());
// Create the server context and add the servlet
- Context root = new Context(jettyServer, "/rest/v1", Context.SESSIONS);
+ Context root = new Context(jettyServer, "/rest/v2", Context.SESSIONS);
root.setAttribute("ChukwaAgent", this);
root.addServlet(servletHolder, "/*");
root.setAllowNullPathInfo(false);
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorAveragedRate.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorAveragedRate.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorAveragedRate.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorAveragedRate.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,58 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class AdaptorAveragedRate {
+ private double rate;
+ private long unit;
+
+ public AdaptorAveragedRate() {
+ rate = 0;
+ unit = 0;
+ }
+
+ public AdaptorAveragedRate(long unit, double rate) {
+ this.unit = unit;
+ this.rate = rate;
+ }
+
+ @XmlAttribute
+ public double getRate() {
+ return rate;
+ }
+
+ public void setRate(double rate) {
+ this.rate = rate;
+ }
+
+ @XmlAttribute
+ public long getIntervalInSeconds() {
+ return unit;
+ }
+
+ public void setIntervalInSeconds(long unit) {
+ this.unit = unit;
+ }
+}
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorConfig.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorConfig.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorConfig.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorConfig.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,82 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAccessType;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class AdaptorConfig {
+ private String id;
+ private String dataType;
+ private String adaptorClass;
+ private String adaptorParams;
+ private long offset;
+
+ public AdaptorConfig() {
+ }
+
+ @XmlElement
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @XmlElement
+ public String getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(String dataType) {
+ this.dataType = dataType;
+ }
+
+ @XmlElement
+ public String getAdaptorClass() {
+ return adaptorClass;
+ }
+
+ public void setAdaptorClass(String adaptorClass) {
+ this.adaptorClass = adaptorClass;
+ }
+
+ @XmlElement
+ public String getAdaptorParams() {
+ return adaptorParams;
+ }
+
+ public void setAdaptorParams(String adaptorParams) {
+ this.adaptorParams = adaptorParams;
+ }
+
+ @XmlElement
+ public long getOffset() {
+ return offset;
+ }
+
+ public void setOffset(long offset) {
+ this.offset = offset;
+ }
+}
Modified: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorController.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorController.java?rev=1611856&r1=1611855&r2=1611856&view=diff
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorController.java (original)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorController.java Sat Jul 19 08:06:33 2014
@@ -36,38 +36,20 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
+
import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
/**
* JAX-RS controller to handle all HTTP request to the Agent that deal with adaptors.
- *
- * To return all adaptors:
- * GET /rest/v1/adaptor
- * Optional QS params: viewType=text|xml (default=xml)
- *
- * To return a single adaptor:
- * GET /rest/v1/adaptor/[adaptorId]
- * Optional QS params: viewType=text|xml (default=xml)
- *
- * To remove an adaptor:
- * DELETE /rest/v1/adaptor/[adaptorId]
- *
- * To add an adaptor:
- * POST /rest/v1/adaptor
- * Content-Type: application/json
- * Optional QS params: viewType=text|xml (default=xml)
- *
- * { "DataType" : "foo",
- * "AdaptorClass" : "FooAdaptor",
- * "AdaptorParams" : "params",
- * "Offset" : "0" }
- * The first 3 params above are the only required ones.
*/
@Path("/adaptor")
public class AdaptorController {
@@ -82,68 +64,55 @@ public class AdaptorController {
}
/**
- * Adds an adaptor to the agent and returns the adaptor info.
- * @param context servletContext
- * @param viewType type of view to return (text|xml)
- * @param postBody JSON post body
- * @return Response object
+ * Adds an adaptor to the agent and returns the adaptor info
+ *
+ * @request.representation.example {@link Examples#CREATE_ADAPTOR_SAMPLE}
+ * @response.representation.200.doc Adaptor has been registered
+ * @response.representation.200.mediaType application/json
+ * @response.representation.200.example {@link Examples#ADAPTOR_STATUS_SAMPLE}
+ * @response.representation.400.doc Error in register adaptor
+ * @response.representation.400.mediaType text/plain
+ * @response.representation.400.example Bad Request
*/
@POST
- @Consumes("application/json")
- @Produces({"text/xml","text/plain"})
- public Response addAdaptor(@Context ServletContext context,
- @QueryParam("viewType") String viewType,
- String postBody) {
- ChukwaAgent agent = (ChukwaAgent)context.getAttribute("ChukwaAgent");
-
- if (postBody == null) return badRequestResponse("Empty POST body.");
-
- // parse the json.
- StringBuilder addCommand = new StringBuilder("add ");
- try {
- JSONObject reqJson = new JSONObject(postBody);
-
- String dataType = reqJson.getString("DataType");
- //TODO: figure out how to set this per-adaptor
- //String cluster = reqJson.getString("Cluster");
- String adaptorClass = reqJson.getString("AdaptorClass");
-
- String adaptorParams = fetchOptionalString(reqJson, "AdaptorParams");
- long offset = fetchOptionalLong(reqJson, "Offset", 0);
-
- addCommand.append(adaptorClass).append(' ');
- addCommand.append(dataType);
- if (adaptorParams != null)
- addCommand.append(' ').append(adaptorParams);
- addCommand.append(' ').append(offset);
-
- } catch (JSONException e) {
- return badRequestResponse("Invalid JSON passed: '" + postBody + "', error: " + e.getMessage());
+ @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
+ public Response addAdaptor(AdaptorConfig ac) {
+ ChukwaAgent agent = ChukwaAgent.getAgent();
+ if (ac.getAdaptorClass() == null ||
+ ac.getDataType() == null) {
+ return badRequestResponse("Bad adaptor config.");
}
+
+ StringBuilder addCommand = new StringBuilder("add ");
+ addCommand.append(ac.getAdaptorClass()).append(' ');
+ addCommand.append(ac.getDataType());
+ if (ac.getAdaptorParams() != null)
+ addCommand.append(' ').append(ac.getAdaptorParams());
+ addCommand.append(' ').append(ac.getOffset());
// add the adaptor
try {
String adaptorId = agent.processAddCommandE(addCommand.toString());
-
- return doGetAdaptor(agent, adaptorId, viewType);
+ return doGetAdaptor(adaptorId);
} catch (AdaptorException e) {
- return badRequestResponse("Could not add adaptor for postBody: '" + postBody +
+ return badRequestResponse("Could not add adaptor for data type: '" + ac.getDataType() +
"', error: " + e.getMessage());
}
}
/**
* Remove an adaptor from the agent
- * @param context ServletContext
+ *
* @param adaptorId id of adaptor to remove.
- * @return Response object
+ * @response.representation.200.doc Delete adaptor by id
+ * @response.representation.200.mediaType text/plain
*/
@DELETE
@Path("/{adaptorId}")
- @Produces({"text/plain"})
- public Response removeAdaptor(@Context ServletContext context,
- @PathParam("adaptorId") String adaptorId) {
- ChukwaAgent agent = (ChukwaAgent)context.getAttribute("ChukwaAgent");
+ @Produces({MediaType.TEXT_PLAIN})
+ public Response removeAdaptor(@PathParam("adaptorId") String adaptorId) {
+ ChukwaAgent agent = ChukwaAgent.getAgent();
// validate that we have an adaptorId
if (adaptorId == null) {
@@ -162,305 +131,105 @@ public class AdaptorController {
/**
* Get all adaptors
- * @param context ServletContext
- * @param viewType type of view to return (text|xml)
- * @return Response object
+ *
+ * @response.representation.200.doc List all configured adaptors
+ * @response.representation.200.mediaType application/json
+ * @response.representation.200.example {@link Examples#ADAPTOR_LIST_SAMPLE}
*/
@GET
- @Produces({"text/xml", "text/plain"})
- public Response getAdaptors(@Context ServletContext context,
- @QueryParam("viewType") String viewType) {
- ChukwaAgent agent = (ChukwaAgent)context.getAttribute("ChukwaAgent");
- return doGetAdaptor(agent, null, viewType);
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getAdaptors() {
+ return doGetAdaptors();
}
/**
* Get a single adaptor
- * @param context ServletContext
- * @param viewType type of view to return (text|xml)
+ *
* @param adaptorId id of the adaptor to return
- * @return Response object
+ * @response.representation.200.doc Adaptor status and data transfer rate in 1, 5, 10 minutes averages
+ * @response.representation.200.mediaType application/json
+ * @response.representation.200.example {@link Examples#ADAPTOR_STATUS_SAMPLE}
*/
@GET
@Path("/{adaptorId}")
- @Produces({"text/xml","text/plain"})
- public Response getAdaptor(@Context ServletContext context,
- @QueryParam("viewType") String viewType,
- @PathParam("adaptorId") String adaptorId) {
- ChukwaAgent agent = (ChukwaAgent)context.getAttribute("ChukwaAgent");
- return doGetAdaptor(agent, adaptorId, viewType);
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public Response getAdaptor(@PathParam("adaptorId") String adaptorId) {
+ return doGetAdaptor(adaptorId);
}
/**
- * Handles the common rendering logic of checking for view type and returning
- * a Response with one or all adaptors.
+ * Handles a single adaptor request for rendering data model output.
+ *
* @return Response object
*/
- private Response doGetAdaptor(ChukwaAgent agent, String adaptorId, String viewType) {
- if ("text".equals(viewType)) {
- return textResponse(buildAdaptorText(agent, adaptorId));
- }
- else if ("xml".equals(viewType) || viewType == null) {
- return xmlResponse(buildAdaptorXML(agent, adaptorId));
- }
- else {
- return badRequestResponse("Invalid viewType: " + viewType);
- }
+ private Response doGetAdaptor(String adaptorId) {
+ return Response.ok(buildAdaptor(adaptorId)).build();
}
/**
- * Renders info for one or all adaptors in XML.
+ * Rendering data model output for all adaptors
+ *
+ * @return Response object
*/
- protected String buildAdaptorXML(ChukwaAgent agent, String adaptorId) {
-
- StringBuilder out = new StringBuilder(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-
- appendStartTag(out, "Response");
-
- if (adaptorId == null) {
- Map<String, String> adaptorMap = agent.getAdaptorList();
- appendStartTag(out, "Adaptors", "total", adaptorMap.size());
-
- for (String name : adaptorMap.keySet()) {
- Adaptor adaptor = agent.getAdaptor(name);
- appendAdaptorXML(out, agent, adaptor);
- }
-
- appendEndTag(out, "Adaptors");
- }
- else {
- Adaptor adaptor = agent.getAdaptor(adaptorId);
- if (adaptor != null) {
- appendAdaptorXML(out, agent, adaptor);
- }
- else {
- appendElement(out, "Error", "Invalid adaptor id: " + adaptorId);
- }
- }
-
- appendEndTag(out, "Response");
-
- return out.toString();
+ private Response doGetAdaptors() {
+ return Response.ok(buildAdaptors()).build();
}
-
+
/**
- * Renders info for one or all adaptors in plain text (YAML).
+ * Renders info for one adaptor.
*/
- protected String buildAdaptorText(ChukwaAgent agent, String adaptorId) {
- StringBuilder out = new StringBuilder();
-
- Map<String, String> adaptorMap = agent.getAdaptorList();
- int indent = 0;
-
- if (adaptorId == null) {
- appendNvp(out, indent, "adaptor_count", adaptorMap.size());
- appendNvp(out, indent, "adaptors", "");
-
- indent += 4;
- for(String name : adaptorMap.keySet()) {
- Adaptor adaptor = agent.getAdaptor(name);
- appendAdaptorText(out, indent, agent, adaptor);
- }
- }
- else {
- Adaptor adaptor = agent.getAdaptor(adaptorId);
- if (adaptor != null) {
- appendNvp(out, indent, "adaptor", "");
- indent += 4;
- appendAdaptorText(out, indent, agent, adaptor);
- }
- else {
- appendNvp(out, indent, "error_message", "Invalid adaptor id: " + adaptorId, true);
- }
- }
-
- return out.toString();
- }
-
- private void appendAdaptorText(StringBuilder out, int indent,
- ChukwaAgent agent, Adaptor adaptor) {
- appendNvp(out, indent, "- adaptor_id", agent.offset(adaptor).adaptorID());
- appendNvp(out, indent, "data_type", adaptor.getType());
- appendNvp(out, indent, "offset", agent.offset(adaptor).offset());
- appendNvp(out, indent, "adaptor_class", adaptor.getClass().getName());
- appendNvp(out, indent, "adaptor_params", adaptor.getCurrentStatus(), true);
-
- OffsetStatsManager adaptorStats = agent.getAdaptorStatsManager();
-
- appendNvp(out, indent, "average_rates", "");
- indent += 4;
- appendNvp(out, indent, "- rate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 60)));
- appendNvp(out, indent, "interval", "60");
- appendNvp(out, indent, "- rate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 300)));
- appendNvp(out, indent, "interval", "300");
- appendNvp(out, indent, "- rate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 600)));
- appendNvp(out, indent, "interval", "600");
- indent -= 4;
- }
-
- private void appendAdaptorXML(StringBuilder out,
- ChukwaAgent agent, Adaptor adaptor) {
- appendStartTag(out, "Adaptor",
- "id", agent.offset(adaptor).adaptorID(),
- "dataType", adaptor.getType(),
- "offset", agent.offset(adaptor).offset());
-
- appendElement(out, "AdaptorClass", adaptor.getClass().getName());
- appendElement(out, "AdaptorParams", adaptor.getCurrentStatus());
-
+ protected AdaptorInfo buildAdaptor(String adaptorId) {
+ ChukwaAgent agent = ChukwaAgent.getAgent();
+ Adaptor adaptor = agent.getAdaptor(adaptorId);
OffsetStatsManager adaptorStats = agent.getAdaptorStatsManager();
- appendElement(out, "AverageRate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 60)),
- "intervalSeconds", "60");
- appendElement(out, "AverageRate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 300)),
- "intervalSeconds", "300");
- appendElement(out, "AverageRate",
- DECIMAL_FORMAT.format(adaptorStats.calcAverageRate(adaptor, 600)),
- "intervalSeconds", "600");
-
- appendEndTag(out, "Adaptor");
- }
-
- // *** static helper methods below. could be moved into a util class ***
-
- // * response handling *
-
- private static Response textResponse(Object content) {
- return Response.ok(content, MediaType.TEXT_PLAIN).build();
- }
-
- private static Response xmlResponse(String content) {
- return Response.ok(content, MediaType.TEXT_XML).build();
- }
-
- private static Response badRequestResponse(String content) {
- return Response.status(HttpServletResponse.SC_BAD_REQUEST)
- .entity(content).build();
- }
-
- // * json handling *
-
- private static String fetchOptionalString(JSONObject json, String name) {
- try {
- return json.getString(name);
- } catch (JSONException e) {
- log.debug(ExceptionUtil.getStackTrace(e));
- }
- return null;
- }
-
- private static long fetchOptionalLong(JSONObject json, String name, long defaultLong) {
- try {
- return json.getLong(name);
- } catch (JSONException e) {
- return defaultLong;
- }
- }
-
- // * plain text response handling *
-
- /**
- * Helper for appending name/value pairs to the ServletOutputStream in the
- * format [name]: [value]
- */
- protected static void appendNvp(StringBuilder out,
- String name, Object value) {
- appendNvp(out, 0, name, value, false);
- }
-
- /**
- * Helper for appending name/value pairs to the ServletOutputStream in the
- * format [name]: [value] with indent number of spaces prepended.
- */
- protected static void appendNvp(StringBuilder out, int indent,
- String name, Object value) {
- appendNvp(out, indent, name, value, false);
- }
-
- /**
- * Helper for appending name/value pairs to the ServletOutputStream in the
- * format [name]: [value] with indent number of spaces prepended. Set
- * stringLiteral=true if the value might contain special YAML characters.
- */
- protected static void appendNvp(StringBuilder out, int indent,
- String name, Object value,
- boolean stringLiteral) {
-
- if (name.startsWith("- ") && indent > 1) indent -= 2;
-
- indent(out, indent);
- out.append(name);
- out.append(": ");
-
- if (stringLiteral) {
- out.append('|').append('\n');
- indent(out, indent + 2);
- }
-
- if (value != null)
- out.append(value.toString()).append('\n');
- }
-
- /**
- * Helper to insert a number of spaces into the output stream.
- */
- protected static void indent(StringBuilder out, int indent) {
- for (int i = 0; i < indent; i++) {
- out.append(' ');
- }
+ AdaptorInfo info = new AdaptorInfo();
+ info.setId(adaptorId);
+ info.setDataType(adaptor.getType());
+ info.setAdaptorClass(adaptor.getClass().getName());
+ String[] status = adaptor.getCurrentStatus().split(" ",2);
+ info.setAdaptorParams(status[1]);
+ List<AdaptorAveragedRate> rates = new ArrayList<AdaptorAveragedRate>();
+ rates.add(new AdaptorAveragedRate(60, adaptorStats.calcAverageRate(adaptor, 60)));
+ rates.add(new AdaptorAveragedRate(300, adaptorStats.calcAverageRate(adaptor, 300)));
+ rates.add(new AdaptorAveragedRate(600, adaptorStats.calcAverageRate(adaptor, 600)));
+ info.setAdaptorRates(rates);
+ return info;
}
-
- // * XML text response handling *
-
+
/**
- * XML helper to append a Element start tag. Optionally a number of attributeNvps
- * can be passed, which will be inserted as XML atrribute names and values,
- * alternating between names and values.
+ * Renders info for all adaptors.
*/
- protected static void appendStartTag(StringBuilder out,
- String name,
- Object... attributeNvps) {
- out.append("<");
- out.append(name);
- for(int i = 0; i < attributeNvps.length - 1; i = i + 2) {
- out.append(" ");
- out.append(attributeNvps[i].toString());
- out.append("=\"");
- if (attributeNvps[i + 1] != null)
- out.append(StringEscapeUtils.escapeXml(attributeNvps[i + 1].toString()));
- out.append("\"");
+ protected AdaptorList buildAdaptors() {
+ ChukwaAgent agent = ChukwaAgent.getAgent();
+ Map<String, String> adaptorMap = agent.getAdaptorList();
+ AdaptorList list = new AdaptorList();
+ for(String name : adaptorMap.keySet()) {
+ Adaptor adaptor = agent.getAdaptor(name);
+ OffsetStatsManager adaptorStats = agent.getAdaptorStatsManager();
+
+ AdaptorInfo info = new AdaptorInfo();
+ info.setId(name);
+ info.setDataType(adaptor.getType());
+ info.setAdaptorClass(adaptor.getClass().getName());
+ String[] status = adaptor.getCurrentStatus().split(" ",2);
+ info.setAdaptorParams(status[1]);
+ List<AdaptorAveragedRate> rates = new ArrayList<AdaptorAveragedRate>();
+ rates.add(new AdaptorAveragedRate(60, adaptorStats.calcAverageRate(adaptor, 60)));
+ rates.add(new AdaptorAveragedRate(300, adaptorStats.calcAverageRate(adaptor, 300)));
+ rates.add(new AdaptorAveragedRate(600, adaptorStats.calcAverageRate(adaptor, 600)));
+ info.setAdaptorRates(rates);
+ list.add(info);
}
- out.append(">");
- }
-
- /**
- * XML helper to append a Element end tag.
- */
- protected static void appendEndTag(StringBuilder out,
- String name) {
- out.append("</");
- out.append(name);
- out.append(">");
+ return list;
}
/**
- * XML helper to append an Element and it's child text value. Optionally a
- * number of attributeNvps can be passed, which will be inserted as XML
- * atrribute names and values, alternating between names and values.
+ * Renders bad request response.
*/
- protected static void appendElement(StringBuilder out,
- String name, Object value,
- Object... attributeNvps) {
- appendStartTag(out, name, attributeNvps);
- if (value != null)
- out.append(StringEscapeUtils.escapeXml(value.toString()));
- appendEndTag(out, name);
+ private static Response badRequestResponse(String content) {
+ return Response.status(HttpServletResponse.SC_BAD_REQUEST)
+ .entity(content).build();
}
}
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorInfo.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorInfo.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorInfo.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorInfo.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,40 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class AdaptorInfo extends AdaptorConfig {
+ private List<AdaptorAveragedRate> rates;
+
+ @XmlElement
+ public List<AdaptorAveragedRate> getAdaptorRates() {
+ return rates;
+ }
+
+ public void setAdaptorRates(List<AdaptorAveragedRate> rates) {
+ this.rates = rates;
+ }
+}
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorList.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorList.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorList.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/AdaptorList.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class AdaptorList {
+ private List<AdaptorInfo> adaptorInfo;
+
+ @XmlElement
+ public List<AdaptorInfo> getAdaptorInfo() {
+ return this.adaptorInfo;
+ }
+
+ public void setAdaptorInfo(List<AdaptorInfo> adaptorInfo) {
+ this.adaptorInfo = adaptorInfo;
+ }
+
+ public void add(AdaptorInfo adaptorInfo) {
+ if(this.adaptorInfo == null) {
+ this.adaptorInfo = new ArrayList<AdaptorInfo>();
+ }
+ this.adaptorInfo.add(adaptorInfo);
+ }
+
+ @XmlElement
+ public int getAdaptorCount() {
+ int count = 0;
+ if(this.adaptorInfo != null) {
+ count = this.adaptorInfo.size();
+ }
+ return count;
+ }
+}
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/ContextProvider.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/ContextProvider.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/ContextProvider.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/ContextProvider.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.api.json.JSONJAXBContext;
+
+@Provider
+public class ContextProvider implements ContextResolver<JAXBContext> {
+
+ private final JAXBContext context;
+ private Class<?>[] types = { };
+ /*private Class<?>[] types = {
+ AgentController.class,
+ };*/
+
+ public ContextProvider() throws JAXBException {
+ this.context = new JSONJAXBContext(JSONConfiguration.natural().build(),
+ types);
+ }
+
+ public JAXBContext getContext(Class<?> objectType) {
+ for (Class<?> type : types) {
+ if (type.equals(objectType))
+ return context;
+ }
+ return null;
+ }
+}
Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/Examples.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/Examples.java?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/Examples.java (added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/rest/Examples.java Sat Jul 19 08:06:33 2014
@@ -0,0 +1,86 @@
+/*
+ * 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.chukwa.datacollection.agent.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Examples {
+ public static final AdaptorConfig CREATE_ADAPTOR_SAMPLE = new AdaptorConfig();
+ public static final AdaptorInfo ADAPTOR_STATUS_SAMPLE = new AdaptorInfo();
+ public static final List<AdaptorAveragedRate> ADAPTOR_RATES = new ArrayList<AdaptorAveragedRate>();
+ public static final AdaptorAveragedRate ADAPTOR_RATE_SAMPLE_PER_MINUTE = new AdaptorAveragedRate();
+ public static final AdaptorAveragedRate ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE = new AdaptorAveragedRate();
+ public static final AdaptorAveragedRate ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE = new AdaptorAveragedRate();
+
+ public static final AdaptorInfo SYS_ADAPTOR_STATUS_SAMPLE = new AdaptorInfo();
+ public static final List<AdaptorAveragedRate> SYS_ADAPTOR_RATES = new ArrayList<AdaptorAveragedRate>();
+ public static final AdaptorAveragedRate SYS_ADAPTOR_RATE_SAMPLE_PER_MINUTE = new AdaptorAveragedRate();
+ public static final AdaptorAveragedRate SYS_ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE = new AdaptorAveragedRate();
+ public static final AdaptorAveragedRate SYS_ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE = new AdaptorAveragedRate();
+
+ public static final AdaptorList ADAPTOR_LIST_SAMPLE = new AdaptorList();
+
+ static {
+ // Create adaptor Sample
+ CREATE_ADAPTOR_SAMPLE.setDataType("JobSummary");
+ CREATE_ADAPTOR_SAMPLE.setAdaptorClass("org.apache.hadoop.chukwa.datacollection.adaptor.SocketAdaptor");
+ CREATE_ADAPTOR_SAMPLE.setAdaptorParams("9098");
+ CREATE_ADAPTOR_SAMPLE.setOffset(0);
+
+ // Adaptor Status Sample
+ ADAPTOR_RATE_SAMPLE_PER_MINUTE.setRate(100.123);
+ ADAPTOR_RATE_SAMPLE_PER_MINUTE.setIntervalInSeconds(60);
+ ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE.setRate(100.123);
+ ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE.setIntervalInSeconds(300);
+ ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE.setRate(100.123);
+ ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE.setIntervalInSeconds(600);
+ ADAPTOR_RATES.add(ADAPTOR_RATE_SAMPLE_PER_MINUTE);
+ ADAPTOR_RATES.add(ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE);
+ ADAPTOR_RATES.add(ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE);
+ ADAPTOR_STATUS_SAMPLE.setId("adaptor_93df4746476c9a4b624f6755b122f9dc");
+ ADAPTOR_STATUS_SAMPLE.setDataType("JobSummary");
+ ADAPTOR_STATUS_SAMPLE.setAdaptorClass("org.apache.hadoop.chukwa.datacollection.adaptor.SocketAdaptor");
+ ADAPTOR_STATUS_SAMPLE.setAdaptorParams("9098");
+ ADAPTOR_STATUS_SAMPLE.setOffset(1680);
+ ADAPTOR_STATUS_SAMPLE.setAdaptorRates(ADAPTOR_RATES);
+
+ // System Adaptor Sample
+ SYS_ADAPTOR_RATE_SAMPLE_PER_MINUTE.setRate(9.09);
+ SYS_ADAPTOR_RATE_SAMPLE_PER_MINUTE.setIntervalInSeconds(60);
+ SYS_ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE.setRate(7.55);
+ SYS_ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE.setIntervalInSeconds(300);
+ SYS_ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE.setRate(6.44);
+ SYS_ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE.setIntervalInSeconds(600);
+ SYS_ADAPTOR_RATES.add(SYS_ADAPTOR_RATE_SAMPLE_PER_MINUTE);
+ SYS_ADAPTOR_RATES.add(SYS_ADAPTOR_RATE_SAMPLE_PER_FIVE_MINUTE);
+ SYS_ADAPTOR_RATES.add(SYS_ADAPTOR_RATE_SAMPLE_PER_TEN_MINUTE);
+ SYS_ADAPTOR_STATUS_SAMPLE.setId("adaptor_c79bf882974a14286cffe29d3d4cf0d6");
+ SYS_ADAPTOR_STATUS_SAMPLE.setDataType("SystemMetrics");
+ SYS_ADAPTOR_STATUS_SAMPLE.setAdaptorClass("org.apache.hadoop.chukwa.datacollection.adaptor.sigar.SystemMetrics");
+ SYS_ADAPTOR_STATUS_SAMPLE.setAdaptorParams("5");
+ SYS_ADAPTOR_STATUS_SAMPLE.setOffset(5678);
+ SYS_ADAPTOR_STATUS_SAMPLE.setAdaptorRates(SYS_ADAPTOR_RATES);
+
+ // List of Adaptors Sample
+ List<AdaptorInfo> list = new ArrayList<AdaptorInfo>();
+ list.add(ADAPTOR_STATUS_SAMPLE);
+ list.add(SYS_ADAPTOR_STATUS_SAMPLE);
+ ADAPTOR_LIST_SAMPLE.setAdaptorInfo(list);
+ }
+}
Added: chukwa/trunk/src/main/resources/agent-rest.xml
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/resources/agent-rest.xml?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/resources/agent-rest.xml (added)
+++ chukwa/trunk/src/main/resources/agent-rest.xml Sat Jul 19 08:06:33 2014
@@ -0,0 +1,51 @@
+<!--
+
+ 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.
+
+-->
+
+<applicationDocs targetNamespace="http://research.sun.com/wadl/2006/10">
+
+<doc xml:lang="en" title="Chukwa Agent REST API">
+
+<p>
+ Chukwa Agent provides REST interfaces that allow management of
+ data stream movement. The primary resources are:
+
+ <ul>
+ <li>Adaptor resource - the registration, querying, and deletion of
+ Chukwa Adaptors.</li>
+
+ <li>Pipeline resource - the configuration of data destination. (TBD)</li>
+ </ul>
+
+</p><br/>
+<p>
+ The resources and the entities that are passed to them are defined
+ using JAXB and are represented in either XML or JSON formats
+ depending on the ContentType and Accept HTTP headers. The definition
+ of the types is given in the
+ <a href="org/apache/hadoop/chukwa/datacollection/agent/rest/package-summary.html">JavaDoc</a>.
+</p><br/>
+<p>
+ Typical usage would be to create a new adaptor from a pre-defined
+ one and change the necessary configuration parameters. Then configure
+ parser to process the data stream.
+</p>
+</doc>
+
+</applicationDocs>
Added: chukwa/trunk/src/main/resources/application-grammars.xml
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/resources/application-grammars.xml?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/resources/application-grammars.xml (added)
+++ chukwa/trunk/src/main/resources/application-grammars.xml Sat Jul 19 08:06:33 2014
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ 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.
+-->
+<grammars xmlns="http://research.sun.com/wadl/2006/10"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xi="http://www.w3.org/1999/XML/xinclude">
+ <include href="agent-schema.xsd" />
+</grammars>
Added: chukwa/trunk/src/main/webapps/wadl.xsl
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/webapps/wadl.xsl?rev=1611856&view=auto
==============================================================================
--- chukwa/trunk/src/main/webapps/wadl.xsl (added)
+++ chukwa/trunk/src/main/webapps/wadl.xsl Sat Jul 19 08:06:33 2014
@@ -0,0 +1,709 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
+ xmlns:wadl="http://research.sun.com/wadl/2006/10"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+>
+
+<!-- Global variables -->
+<xsl:variable name="g_resourcesBase" select="wadl:application/wadl:resources/@base"/>
+
+<!-- Template for top-level doc element -->
+<xsl:template match="wadl:application">
+ <html>
+ <head>
+ <xsl:call-template name="getStyle"/>
+ <title><xsl:call-template name="getTitle"/></title>
+ </head>
+ <body>
+ <h1><xsl:call-template name="getTitle"/></h1>
+ <xsl:call-template name="getDoc">
+ <xsl:with-param name="base" select="$g_resourcesBase"/>
+ </xsl:call-template>
+
+ <!-- Summary -->
+ <h2>Summary</h2>
+ <table>
+ <tr>
+ <th>Resource</th>
+ <th>Method</th>
+ <th>Description</th>
+ </tr>
+ <xsl:for-each select="wadl:resources/wadl:resource">
+ <xsl:call-template name="processResourceSummary">
+ <xsl:with-param name="resourceBase" select="$g_resourcesBase"/>
+ <xsl:with-param name="resourcePath" select="@path"/>
+ <xsl:with-param name="lastResource" select="position() = last()"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </table>
+ <p></p>
+
+ <!-- Grammars -->
+ <xsl:if test="wadl:grammars/wadl:include">
+ <h2>Grammars</h2>
+ <p>
+ <xsl:for-each select="wadl:grammars/wadl:include">
+ <xsl:variable name="href" select="@href"/>
+ <a href="{$href}"><xsl:value-of select="$href"/></a>
+ <xsl:if test="position() != last()"><br/></xsl:if> <!-- Add a spacer -->
+ </xsl:for-each>
+ </p>
+ </xsl:if>
+
+ <!-- Detail -->
+ <h2>Resources</h2>
+ <xsl:for-each select="wadl:resources">
+ <xsl:call-template name="getDoc">
+ <xsl:with-param name="base" select="$g_resourcesBase"/>
+ </xsl:call-template>
+ <br/>
+ </xsl:for-each>
+
+ <xsl:for-each select="wadl:resources/wadl:resource">
+ <xsl:call-template name="processResourceDetail">
+ <xsl:with-param name="resourceBase" select="$g_resourcesBase"/>
+ <xsl:with-param name="resourcePath" select="@path"/>
+ </xsl:call-template>
+ </xsl:for-each>
+
+ </body>
+ </html>
+</xsl:template>
+
+<!-- Supporting templates (functions) -->
+
+<xsl:template name="processResourceSummary">
+ <xsl:param name="resourceBase"/>
+ <xsl:param name="resourcePath"/>
+ <xsl:param name="lastResource"/>
+
+ <xsl:if test="wadl:method">
+ <tr>
+ <!-- Resource -->
+ <td class="summary">
+ <xsl:variable name="id"><xsl:call-template name="getId"/></xsl:variable>
+ <a href="#{$id}">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ <xsl:with-param name="path" select="$resourcePath"/>
+ </xsl:call-template>
+ </a>
+ </td>
+ <!-- Method -->
+ <td class="summary">
+ <xsl:for-each select="wadl:method">
+ <xsl:variable name="name" select="@name"/>
+ <xsl:variable name="id2"><xsl:call-template name="getId"/></xsl:variable>
+ <a href="#{$id2}"><xsl:value-of select="$name"/></a>
+ <xsl:for-each select="wadl:doc"><br/></xsl:for-each>
+ <xsl:if test="position() != last()"><br/></xsl:if> <!-- Add a spacer -->
+ </xsl:for-each>
+ <br/>
+ </td>
+ <!-- Description -->
+ <td class="summary">
+ <xsl:for-each select="wadl:method">
+ <xsl:call-template name="getDoc">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ </xsl:call-template>
+ <br/>
+ <xsl:if test="position() != last()"><br/></xsl:if> <!-- Add a spacer -->
+ </xsl:for-each>
+ </td>
+ </tr>
+ <!-- Add separator if not the last resource -->
+ <xsl:if test="wadl:method and not($lastResource)">
+ <tr><td class="summarySeparator"></td><td class="summarySeparator"/><td class="summarySeparator"/></tr>
+ </xsl:if>
+ </xsl:if> <!-- wadl:method -->
+
+ <!-- Call recursively for child resources -->
+ <xsl:for-each select="wadl:resource">
+ <xsl:variable name="base">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ <xsl:with-param name="path" select="$resourcePath"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:call-template name="processResourceSummary">
+ <xsl:with-param name="resourceBase" select="$base"/>
+ <xsl:with-param name="resourcePath" select="@path"/>
+ <xsl:with-param name="lastResource" select="$lastResource and position() = last()"/>
+ </xsl:call-template>
+ </xsl:for-each>
+
+</xsl:template>
+
+<xsl:template name="processResourceDetail">
+ <xsl:param name="resourceBase"/>
+ <xsl:param name="resourcePath"/>
+
+ <xsl:if test="wadl:method">
+ <h3>
+ <xsl:variable name="id"><xsl:call-template name="getId"/></xsl:variable>
+ <a name="{$id}">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ <xsl:with-param name="path" select="$resourcePath"/>
+ </xsl:call-template>
+ </a>
+ </h3>
+ <p>
+ <xsl:call-template name="getDoc">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ </xsl:call-template>
+ </p>
+
+ <h5>Methods</h5>
+
+ <div class="methods">
+ <xsl:for-each select="wadl:method">
+ <div class="method">
+ <table class="methodNameTable">
+ <tr>
+ <td class="methodNameTd" style="font-weight: bold">
+ <xsl:variable name="name" select="@name"/>
+ <xsl:variable name="id2"><xsl:call-template name="getId"/></xsl:variable>
+ <a name="{$id2}"><xsl:value-of select="$name"/></a>
+ </td>
+ <td class="methodNameTd" style="text-align: right">
+ <xsl:if test="@id">
+ <xsl:value-of select="@id"/>()
+ </xsl:if>
+ </td>
+ </tr>
+ </table>
+ <p>
+ <xsl:call-template name="getDoc">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ </xsl:call-template>
+ </p>
+
+ <!-- Request -->
+ <h6>request</h6>
+ <div style="margin-left: 2em"> <!-- left indent -->
+ <xsl:choose>
+ <xsl:when test="wadl:request">
+ <xsl:for-each select="wadl:request">
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'template'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'matrix'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'header'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'query'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getRepresentations"/>
+ </xsl:for-each> <!-- wadl:request -->
+ </xsl:when>
+
+ <xsl:when test="not(wadl:request) and (ancestor::wadl:*/wadl:param)">
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'template'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'matrix'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'header'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getParamBlock">
+ <xsl:with-param name="style" select="'query'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getRepresentations"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ unspecified
+ </xsl:otherwise>
+ </xsl:choose>
+ </div> <!-- left indent for request -->
+
+ <!-- Response -->
+ <h6>responses</h6>
+ <xsl:choose>
+ <xsl:when test="wadl:response">
+ <xsl:for-each select="wadl:response">
+ <!-- Get response headers/representations -->
+ <xsl:if test="wadl:param or wadl:representation">
+ <div style="margin-left: 2em"> <!-- left indent -->
+ <xsl:if test="wadl:param">
+ <div class="h7">headers</div>
+ <table>
+ <xsl:for-each select="wadl:param[@style='header']">
+ <xsl:call-template name="getParams"/>
+ </xsl:for-each>
+ </table>
+ </xsl:if>
+
+ <xsl:call-template name="getRepresentations"/>
+ </div>
+ </xsl:if>
+ </xsl:for-each> <!-- wadl:response -->
+ </xsl:when>
+ <xsl:otherwise>
+ unspecified
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </div> <!-- class=method -->
+ </xsl:for-each> <!-- wadl:method -->
+ </div> <!-- class=methods -->
+
+ </xsl:if> <!-- wadl:method -->
+
+ <!-- Call recursively for child resources -->
+ <xsl:for-each select="wadl:resource">
+ <xsl:variable name="base">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$resourceBase"/>
+ <xsl:with-param name="path" select="$resourcePath"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:call-template name="processResourceDetail">
+ <xsl:with-param name="resourceBase" select="$base"/>
+ <xsl:with-param name="resourcePath" select="@path"/>
+ </xsl:call-template>
+ </xsl:for-each> <!-- wadl:resource -->
+</xsl:template>
+
+<xsl:template name="getFullResourcePath">
+ <xsl:param name="base"/>
+ <xsl:param name="path"/>
+ <xsl:choose>
+ <xsl:when test="substring($base, string-length($base)) = '/'">
+ <xsl:value-of select="$base"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat($base, '/')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:choose>
+ <xsl:when test="starts-with($path, '/')">
+ <xsl:value-of select="substring($path, 2)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$path"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="getDoc">
+ <xsl:param name="base"/>
+ <xsl:for-each select="wadl:doc">
+ <xsl:if test="position() > 1"><br/></xsl:if>
+ <xsl:if test="@title and local-name(..) != 'application'">
+ <xsl:value-of select="@title"/>:
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="@title = 'Example'">
+ <xsl:variable name="url">
+ <xsl:choose>
+ <xsl:when test="string-length($base) > 0">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$base"/>
+ <xsl:with-param name="path" select="text()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="text()"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <a href="{$url}"><xsl:value-of select="$url"/></a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="node()" mode="copy"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="getDocInReversed">
+ <xsl:param name="base"/>
+ <xsl:choose>
+ <xsl:when test="@mediaType = 'application/json'">
+ <xsl:for-each select="wadl:doc">
+ <xsl:sort select="position()" data-type="number" order="descending"/>
+ <xsl:if test="position() > 1"><br/></xsl:if>
+ <xsl:if test="@title and local-name(..) != 'application'">
+ <xsl:value-of select="@title"/>:
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="@title = 'Example'">
+ <xsl:variable name="url">
+ <xsl:choose>
+ <xsl:when test="string-length($base) > 0">
+ <xsl:call-template name="getFullResourcePath">
+ <xsl:with-param name="base" select="$base"/>
+ <xsl:with-param name="path" select="text()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="text()"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <a href="{$url}"><xsl:value-of select="$url"/></a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="node()" mode="copy"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ Example for <xsl:value-of select="@mediaType"/> is available in /rest/v2/application.wadl
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="a" mode="copy">
+ <xsl:variable name="href" select="@href"/>
+ <a href="{$href}"><xsl:apply-templates select="node()" mode="copy"/></a>
+</xsl:template>
+
+<xsl:template match="b" mode="copy">
+ <b><xsl:apply-templates select="node()" mode="copy"/></b>
+</xsl:template>
+
+<xsl:template match="br" mode="copy">
+ <br><xsl:apply-templates select="node()" mode="copy"/></br>
+</xsl:template>
+
+<xsl:template match="p" mode="copy">
+ <p><xsl:apply-templates select="node()" mode="copy"/></p>
+</xsl:template>
+
+<xsl:template match="ul" mode="copy">
+ <ul><xsl:apply-templates select="node()" mode="copy"/></ul>
+</xsl:template>
+
+<xsl:template match="li" mode="copy">
+ <li><xsl:apply-templates select="node()" mode="copy"/></li>
+</xsl:template>
+
+<xsl:template match="html:*" mode="copy">
+ <!-- remove the prefix on HTML elements -->
+ <xsl:element name="{local-name()}">
+ <xsl:for-each select="@*">
+ <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
+ </xsl:for-each>
+ <xsl:apply-templates select="node()" mode="copy"/>
+ </xsl:element>
+</xsl:template>
+
+<xsl:template name="getId">
+ <xsl:choose>
+ <xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
+ <xsl:otherwise><xsl:value-of select="generate-id()"/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="getParamBlock">
+ <xsl:param name="style"/>
+ <xsl:if test="ancestor-or-self::wadl:*/wadl:param[@style=$style]">
+ <div class="h7">
+ <xsl:choose>
+ <xsl:when test="$style = 'template'">path</xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$style"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ parameters</div>
+ <table>
+ <xsl:for-each select="ancestor-or-self::wadl:*/wadl:param[@style=$style]">
+ <xsl:call-template name="getParams"/>
+ </xsl:for-each>
+ </table>
+ <p/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="getParams">
+ <tr>
+ <td><strong><xsl:value-of select="@name"/></strong></td>
+ <td>
+ <xsl:if test="not(@type)">
+ unspecified type
+ </xsl:if>
+ <xsl:call-template name="getParamType">
+ <xsl:with-param name="qname" select="@type"/>
+ </xsl:call-template>
+ <xsl:if test="@required = 'true'"><br/>(required)</xsl:if>
+ <xsl:if test="@repeating = 'true'"><br/>(repeating)</xsl:if>
+ <xsl:if test="@default"><br/>default: <tt><xsl:value-of select="@default"/></tt></xsl:if>
+ <xsl:if test="@fixed"><br/>fixed: <tt><xsl:value-of select="@fixed"/></tt></xsl:if>
+ <xsl:if test="wadl:option">
+ <br/>options:
+ <xsl:for-each select="wadl:option">
+ <xsl:choose>
+ <xsl:when test="@mediaType">
+ <br/><tt><xsl:value-of select="@value"/> (<xsl:value-of select="@mediaType"/>)</tt>
+ </xsl:when>
+ <xsl:otherwise>
+ <tt><xsl:value-of select="@value"/></tt>
+ <xsl:if test="position() != last()">, </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:if>
+ </td>
+ <xsl:if test="wadl:doc">
+ <td><xsl:value-of select="wadl:doc"/></td>
+ </xsl:if>
+ </tr>
+</xsl:template>
+
+<xsl:template name="getParamType">
+ <xsl:param name="qname"/>
+ <xsl:variable name="prefix" select="substring-before($qname,':')"/>
+ <xsl:variable name="ns-uri" select="./namespace::*[name()=$prefix]"/>
+ <xsl:variable name="localname" select="substring-after($qname, ':')"/>
+ <xsl:choose>
+ <xsl:when test="$ns-uri='http://www.w3.org/2001/XMLSchema' or $ns-uri='http://www.w3.org/2001/XMLSchema-instance'">
+ <a href="http://www.w3.org/TR/xmlschema-2/#{$localname}"><xsl:value-of select="$localname"/></a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$qname"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="getRepresentations">
+ <xsl:if test="wadl:representation">
+ <div class="h7">representations</div>
+ <table width="95%">
+ <xsl:for-each select="wadl:representation">
+ <tr>
+ <xsl:choose>
+ <!-- Display HTTP Status Code for response -->
+ <xsl:when test="@status">
+ <td width="10%">
+ Status: <xsl:value-of select="@status"/>
+ </td>
+ <td width="90%">Content-Type: <xsl:value-of select="@mediaType"/></td>
+ </xsl:when>
+ <!-- Display Content-Type only for request -->
+ <xsl:otherwise>
+ <td colspan="2">
+ Content-Type: <xsl:value-of select="@mediaType"/>
+ </td>
+ </xsl:otherwise>
+ </xsl:choose>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <xsl:call-template name="getDocInReversed">
+ <xsl:with-param name="base" select="''"/>
+ </xsl:call-template>
+ </td>
+<!-- <xsl:choose>
+ <xsl:when test="@mediaType='application/json'">
+ <xsl:if test="wadl:doc">
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <td colspan="2">
+ Example for <xsl:value-of select="@mediaType"/> is available in
+ /rest/v2/application.wadl
+ </td>
+ </xsl:otherwise>
+ </xsl:choose> -->
+ <xsl:if test="@href or @element">
+ <td>
+ <xsl:variable name="href" select="@href"/>
+ <xsl:choose>
+ <xsl:when test="@href">
+ <a href="{$href}"><xsl:value-of select="@element"/></a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@element"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </td>
+ </xsl:if>
+ </tr>
+ <xsl:call-template name="getRepresentationParamBlock">
+ <xsl:with-param name="style" select="'template'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getRepresentationParamBlock">
+ <xsl:with-param name="style" select="'matrix'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getRepresentationParamBlock">
+ <xsl:with-param name="style" select="'header'"/>
+ </xsl:call-template>
+
+ <xsl:call-template name="getRepresentationParamBlock">
+ <xsl:with-param name="style" select="'query'"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </table>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="getRepresentationParamBlock">
+ <xsl:param name="style"/>
+ <xsl:if test="wadl:param[@style=$style]">
+ <tr>
+ <td style="padding: 0em, 0em, 0em, 2em">
+ <div class="h7"><xsl:value-of select="$style"/> params</div>
+ <table>
+ <xsl:for-each select="wadl:param[@style=$style]">
+ <xsl:call-template name="getParams"/>
+ </xsl:for-each>
+ </table>
+ <p/>
+ </td>
+ </tr>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="getStyle">
+ <style type="text/css">
+ body {
+ font-family: sans-serif;
+ font-size: 0.85em;
+ margin: 2em 2em;
+ color: #404040;
+ }
+ a {
+ color: #0069d6;
+ }
+ .methods {
+ margin-left: 2em;
+ margin-bottom: 2em;
+ }
+ .method {
+ background-color: #f5f5f5;
+ border: 1px solid rgba(0,0,0,0.05);
+ padding: .5em;
+ margin-bottom: 1em;
+ width: 95%
+ }
+ .methodNameTable {
+ width: 100%;
+ border: 0px;
+ font-size: 1.4em;
+ }
+ .methodNameTd {
+ background-color: #f5f5f5;
+ }
+ h1 {
+ font-size: 2m;
+ margin-bottom: 0em;
+ }
+ h2 {
+ border-bottom: 1px solid black;
+ margin-top: 1.5em;
+ margin-bottom: 0.5em;
+ font-size: 1.5em;
+ }
+ h3 {
+ color: #0069d6;
+ font-size: 1.35em;
+ margin-top: .5em;
+ margin-bottom: 0em;
+ }
+ h5 {
+ font-size: 1.2em;
+ color: #99a;
+ margin: 0.5em 0em 0.25em 0em;
+ }
+ h6 {
+ color: #404040;
+ font-size: 1em;
+ margin: 1em 0em 0em 0em;
+ }
+ .h7 {
+ margin-top: .75em;
+ font-size: 1em;
+ font-weight: bold;
+ font-style: italic;
+ color: #0069d6;
+ }
+ .h8 {
+ margin-top: .75em;
+ font-size: 1em;
+ font-weight: bold;
+ font-style: italic;
+ color: black;
+ }
+ tt {
+ font-size: 1em;
+ }
+ table {
+ border-collapse: collapse;
+ margin-bottom: 0.5em;
+ border: 1px solid rgba(0,0,0,0.05);
+ }
+ th {
+ text-align: left;
+ font-weight: normal;
+ font-size: 1em;
+ color: black;
+ background-color: #f5f5f5;
+ padding: 3px 6px;
+ border: 1px solid rgba(0,0,0,0.05);
+ }
+ td {
+ padding: 3px 6px;
+ vertical-align: top;
+ background-color: #f5f5f5;
+ font-size: 0.85em;
+ border: 1px solid rgba(0,0,0,0.05);
+ }
+ p {
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ td.summary {
+ background-color: #f5f5f5;
+ }
+ td.summarySeparator {
+ padding: 1px;
+ }
+ </style>
+</xsl:template>
+
+<xsl:template name="getTitle">
+ <xsl:choose>
+ <xsl:when test="wadl:doc/@title">
+ <xsl:value-of select="wadl:doc/@title"/>
+ </xsl:when>
+ <xsl:otherwise>
+ Web Application
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
Modified: chukwa/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/site/site.xml?rev=1611856&r1=1611855&r2=1611856&view=diff
==============================================================================
--- chukwa/trunk/src/site/site.xml (original)
+++ chukwa/trunk/src/site/site.xml Sat Jul 19 08:06:33 2014
@@ -49,8 +49,10 @@
</item>
<item name="Architecture" href="design.html"/>
<item name="Chukwa Storage Layout" href="dataflow.html"/>
- <item name="Programming Guide" href="programming.html"/>
- <item name="API Docs" href="apidocs/index.html"/>
+ <item name="Programming Guide" href="programming.html">
+ <item name="Agent REST API" href="apidocs/agent-rest.html"/>
+ <item name="Javadocs" href="apidocs/index.html"/>
+ </item>
<item name="Wiki" href="http://wiki.apache.org/hadoop/Chukwa/"/>
<item name="FAQ" href="http://wiki.apache.org/hadoop/Chukwa/FAQ"/>
</menu>
@@ -58,8 +60,8 @@
<menu name="Miscellaneous">
<item name="Release Notes" href="releasenotes.html"/>
<item name="Change Log" href="changes.html"/>
-<!-- <item name="Find Bugs Report" href="findbugs.html"/>
- <item name="PMD Report" href="pmd.html"/> -->
+ <item name="Find Bugs Report" href="findbugs.html"/>
+ <item name="PMD Report" href="pmd.html"/>
</menu>
</body>