Repository: incubator-hawq Updated Branches: refs/heads/master e48a07b0d -> 127cac3e2
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/Text.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/Text.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/Text.java index 82804ab..253b525 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/Text.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/Text.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.io; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.io; * under the License. */ - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -190,7 +189,8 @@ public class Text implements Writable { * MalformedInputException. * * @param string string to encode - * @param replace whether to replace malformed input with substitution character + * @param replace whether to replace malformed input with substitution + * character * @return ByteBuffer: bytes stores at ByteBuffer.array() and length is * ByteBuffer.limit() * @throws MalformedInputException if a malformed input is used http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/BridgeResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/BridgeResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/BridgeResource.java index 56f10b8..3a062c3 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/BridgeResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/BridgeResource.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.rest; * under the License. */ - import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -55,7 +54,7 @@ import org.apache.hawq.pxf.service.utilities.SecuredHDFS; @Path("/" + Version.PXF_PROTOCOL_VERSION + "/Bridge/") public class BridgeResource extends RestResource { - private static Log Log = LogFactory.getLog(BridgeResource.class); + private static final Log LOG = LogFactory.getLog(BridgeResource.class); /** * Lock is needed here in the case of a non-thread-safe plugin. Using * synchronized methods is not enough because the bridge work is called by @@ -91,7 +90,7 @@ public class BridgeResource extends RestResource { // Convert headers into a regular map Map<String, String> params = convertToCaseInsensitiveMap(headers.getRequestHeaders()); - Log.debug("started with parameters: " + params); + LOG.debug("started with parameters: " + params); ProtocolData protData = new ProtocolData(params); SecuredHDFS.verifyToken(protData, servletContext); @@ -105,7 +104,7 @@ public class BridgeResource extends RestResource { String dataDir = protData.getDataSource(); // THREAD-SAFE parameter has precedence boolean isThreadSafe = protData.isThreadSafe() && bridge.isThreadSafe(); - Log.debug("Request for " + dataDir + " will be handled " + LOG.debug("Request for " + dataDir + " will be handled " + (isThreadSafe ? "without" : "with") + " synchronization"); return readResponse(bridge, protData, isThreadSafe); @@ -136,24 +135,24 @@ public class BridgeResource extends RestResource { Writable record; DataOutputStream dos = new DataOutputStream(out); - Log.debug("Starting streaming fragment " + fragment + LOG.debug("Starting streaming fragment " + fragment + " of resource " + dataDir); while ((record = bridge.getNext()) != null) { record.write(dos); ++recordCount; } - Log.debug("Finished streaming fragment " + fragment + LOG.debug("Finished streaming fragment " + fragment + " of resource " + dataDir + ", " + recordCount + " records."); } catch (ClientAbortException e) { // Occurs whenever client (HAWQ) decides the end the // connection - Log.error("Remote connection closed by HAWQ", e); + LOG.error("Remote connection closed by HAWQ", e); } catch (Exception e) { - Log.error("Exception thrown when streaming", e); + LOG.error("Exception thrown when streaming", e); throw new IOException(e.getMessage()); } finally { - Log.debug("Stopped streaming fragment " + fragment + LOG.debug("Stopped streaming fragment " + fragment + " of resource " + dataDir + ", " + recordCount + " records."); if (!threadSafe) { @@ -172,9 +171,9 @@ public class BridgeResource extends RestResource { * @param path path for the request, used for logging. */ private void lock(String path) { - Log.trace("Locking BridgeResource for " + path); + LOG.trace("Locking BridgeResource for " + path); BRIDGE_LOCK.lock(); - Log.trace("Locked BridgeResource for " + path); + LOG.trace("Locked BridgeResource for " + path); } /** @@ -183,8 +182,8 @@ public class BridgeResource extends RestResource { * @param path path for the request, used for logging. */ private void unlock(String path) { - Log.trace("Unlocking BridgeResource for " + path); + LOG.trace("Unlocking BridgeResource for " + path); BRIDGE_LOCK.unlock(); - Log.trace("Unlocked BridgeResource for " + path); + LOG.trace("Unlocked BridgeResource for " + path); } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ClusterNodesResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ClusterNodesResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ClusterNodesResource.java index f05d200..d877590 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ClusterNodesResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ClusterNodesResource.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.rest; * under the License. */ - import org.apache.catalina.connector.ClientAbortException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -35,75 +34,84 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.IOException; -/* +/** * Class enhances the API of the HBASE rest server. * Example for querying API getClusterNodesInfo from a web client - * curl "http://localhost:50070/pxf/v2/HadoopCluster/getNodesInfo" + * <code>curl "http://localhost:51200/pxf/v2/HadoopCluster/getNodesInfo"</code> * /pxf/ is made part of the path when there is a webapp by that name in tcServer. */ @Path("/" + Version.PXF_PROTOCOL_VERSION + "/HadoopCluster/") public class ClusterNodesResource { - private Log Log; + private static final Log LOG = LogFactory.getLog(ClusterNodesResource.class); - public ClusterNodesResource() throws IOException { - Log = LogFactory.getLog(ClusterNodesResource.class); + public ClusterNodesResource() { } - - /* - * Function queries the Hadoop namenode with the getDataNodeStats API - * It gets the host's IP and REST port of every HDFS data node in the - * cluster. Then, it packs the results in JSON format and writes to the - * HTTP response stream. - * Response Examples: - * a. When there are no datanodes - getDataNodeStats returns an empty array - * {"regions":[]} - * b. When there are datanodes - * {"regions":[{"host":"1.2.3.1","port":50075},{"host":"1.2.3.2","port":50075}]} + /** + * Function queries the Hadoop namenode with the getDataNodeStats API It + * gets the host's IP and REST port of every HDFS data node in the cluster. + * Then, it packs the results in JSON format and writes to the HTTP response + * stream. Response Examples:<br> + * <ol> + * <li>When there are no datanodes - getDataNodeStats returns an empty array + * <code>{"regions":[]}</code></li> + * <li>When there are datanodes + * <code>{"regions":[{"host":"1.2.3.1","port":50075},{"host":"1.2.3.2","port" + * :50075}]}</code></li> + * </ol> + * + * @return JSON response with nodes info + * @throws Exception if failed to retrieve info */ @GET @Path("getNodesInfo") @Produces("application/json") public Response read() throws Exception { - Log.debug("getNodesInfo started"); + LOG.debug("getNodesInfo started"); StringBuilder jsonOutput = new StringBuilder("{\"regions\":["); try { - /* 1. Initialize the HADOOP client side API for a distributed file system */ + /* + * 1. Initialize the HADOOP client side API for a distributed file + * system + */ Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); DistributedFileSystem dfs = (DistributedFileSystem) fs; - /* 2. Query the namenode for the datanodes info. - * Only live nodes are returned - in accordance with the results returned by - * org.apache.hadoop.hdfs.tools.DFSAdmin#report(). - */ + /* + * 2. Query the namenode for the datanodes info. Only live nodes are + * returned - in accordance with the results returned by + * org.apache.hadoop.hdfs.tools.DFSAdmin#report(). + */ DatanodeInfo[] liveNodes = dfs.getDataNodeStats(DatanodeReportType.LIVE); - /* 3. Pack the datanodes info in a JSON text format and write it - * to the HTTP output stream. - */ + /* + * 3. Pack the datanodes info in a JSON text format and write it to + * the HTTP output stream. + */ String prefix = ""; for (DatanodeInfo node : liveNodes) { verifyNode(node); - jsonOutput.append(prefix).append(writeNode(node)); // write one node to the HTTP stream + // write one node to the HTTP stream + jsonOutput.append(prefix).append(writeNode(node)); prefix = ","; } jsonOutput.append("]}"); - Log.debug("getNodesCluster output: " + jsonOutput); + LOG.debug("getNodesCluster output: " + jsonOutput); } catch (NodeDataException e) { - Log.error("Nodes verification failed", e); + LOG.error("Nodes verification failed", e); throw e; } catch (ClientAbortException e) { - Log.error("Remote connection closed by HAWQ", e); + LOG.error("Remote connection closed by HAWQ", e); throw e; } catch (java.io.IOException e) { - Log.error("Unhandled exception thrown", e); + LOG.error("Unhandled exception thrown", e); throw e; } - return Response.ok(jsonOutput.toString(), MediaType.APPLICATION_JSON_TYPE).build(); + return Response.ok(jsonOutput.toString(), + MediaType.APPLICATION_JSON_TYPE).build(); } private class NodeDataException extends java.io.IOException { @@ -123,15 +131,18 @@ public class ClusterNodesResource { String ip = node.getIpAddr(); if (StringUtils.isEmpty(ip)) { - throw new NodeDataException("Invalid IP: " + ip + " (Node " + node + ")"); + throw new NodeDataException("Invalid IP: " + ip + " (Node " + node + + ")"); } if (port <= 0) { - throw new NodeDataException("Invalid port: " + port + " (Node " + node + ")"); + throw new NodeDataException("Invalid port: " + port + " (Node " + + node + ")"); } } String writeNode(DatanodeInfo node) throws java.io.IOException { - return "{\"host\":\"" + node.getIpAddr() + "\",\"port\":" + node.getInfoPort() + "}"; + return "{\"host\":\"" + node.getIpAddr() + "\",\"port\":" + + node.getInfoPort() + "}"; } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/FragmenterResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/FragmenterResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/FragmenterResource.java index 567c71d..aeddb04 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/FragmenterResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/FragmenterResource.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.rest; * under the License. */ - import org.apache.hawq.pxf.api.Fragment; import org.apache.hawq.pxf.api.Fragmenter; import org.apache.hawq.pxf.api.FragmentsStats; @@ -56,7 +55,7 @@ import java.util.Map; */ @Path("/" + Version.PXF_PROTOCOL_VERSION + "/Fragmenter/") public class FragmenterResource extends RestResource { - private static Log Log = LogFactory.getLog(FragmenterResource.class); + private static final Log LOG = LogFactory.getLog(FragmenterResource.class); /** * The function is called when @@ -119,8 +118,8 @@ public class FragmenterResource extends RestResource { FragmentsStats fragmentsStats = fragmenter.getFragmentsStats(); String response = FragmentsStats.dataToJSON(fragmentsStats); - if (Log.isDebugEnabled()) { - Log.debug(FragmentsStats.dataToString(fragmentsStats, path)); + if (LOG.isDebugEnabled()) { + LOG.debug(FragmentsStats.dataToString(fragmentsStats, path)); } return Response.ok(response, MediaType.APPLICATION_JSON_TYPE).build(); @@ -130,14 +129,14 @@ public class FragmenterResource extends RestResource { final HttpHeaders headers, final String path) throws Exception { - if (Log.isDebugEnabled()) { + if (LOG.isDebugEnabled()) { StringBuilder startMsg = new StringBuilder( "FRAGMENTER started for path \"" + path + "\""); for (String header : headers.getRequestHeaders().keySet()) { startMsg.append(" Header: ").append(header).append(" Value: ").append( headers.getRequestHeader(header)); } - Log.debug(startMsg); + LOG.debug(startMsg); } /* Convert headers into a case-insensitive regular map */ http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java index d3da48e..8e987f3 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/InvalidPathResource.java @@ -56,7 +56,7 @@ public class InvalidPathResource { @Context UriInfo rootUri; - private static final Log Log = LogFactory.getLog(InvalidPathResource.class); + private static final Log LOG = LogFactory.getLog(InvalidPathResource.class); // Set of retired endpoints private final ImmutableSet<String> retiredEndPoints = ImmutableSet.of( "Analyzer"); @@ -127,7 +127,7 @@ public class InvalidPathResource { String version = pathSegments.get(0).getPath(); String endPoint = (pathSegments.size() > 1) ? pathSegments.get(1).getPath() : null; - Log.debug("REST request: " + rootUri.getAbsolutePath() + ". " + + LOG.debug("REST request: " + rootUri.getAbsolutePath() + ". " + "Version " + version + ", supported version is " + Version.PXF_PROTOCOL_VERSION); if(version.equals(Version.PXF_PROTOCOL_VERSION)) { // api with correct version but incorrect path http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/MetadataResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/MetadataResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/MetadataResource.java index d6595eb..4c0f2bf 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/MetadataResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/MetadataResource.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.rest; * under the License. */ - import java.io.IOException; import javax.servlet.ServletContext; @@ -42,67 +41,72 @@ import org.apache.hawq.pxf.service.MetadataFetcherFactory; import org.apache.hawq.pxf.service.MetadataResponseFormatter; /** - * Class enhances the API of the WEBHDFS REST server. - * Returns the metadata of a given hcatalog table. - * <br> + * Class enhances the API of the WEBHDFS REST server. Returns the metadata of a + * given hcatalog table. <br> * Example for querying API FRAGMENTER from a web client:<br> - * <code>curl -i "http://localhost:51200/pxf/v13/Metadata/getTableMetadata?table=t1"</code><br> + * <code>curl -i "http://localhost:51200/pxf/v13/Metadata/getTableMetadata?table=t1"</code> + * <br> * /pxf/ is made part of the path when there is a webapp by that name in tomcat. */ @Path("/" + Version.PXF_PROTOCOL_VERSION + "/Metadata/") public class MetadataResource extends RestResource { - private Log Log; + private static final Log LOG = LogFactory.getLog(MetadataResource.class); public MetadataResource() throws IOException { - Log = LogFactory.getLog(MetadataResource.class); } /** - * This function queries the HiveMetaStore to get the given table's metadata: - * Table name, field names, field types. - * The types are converted from HCatalog types to HAWQ types. - * Supported HCatalog types: - * TINYINT, SMALLINT, INT, BIGINT, BOOLEAN, FLOAT, DOUBLE, - * STRING, BINARY, TIMESTAMP, DATE, DECIMAL, VARCHAR, CHAR. - * <br> - * Unsupported types result in an error. - * <br> + * This function queries the HiveMetaStore to get the given table's + * metadata: Table name, field names, field types. The types are converted + * from HCatalog types to HAWQ types. Supported HCatalog types: TINYINT, + * SMALLINT, INT, BIGINT, BOOLEAN, FLOAT, DOUBLE, STRING, BINARY, TIMESTAMP, + * DATE, DECIMAL, VARCHAR, CHAR. <br> + * Unsupported types result in an error. <br> * Response Examples:<br> - * For a table <code>default.t1</code> with 2 fields (a int, b float) will be returned as: - * <code>{"PXFMetadata":[{"table":{"dbName":"default","tableName":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]}</code> + * For a table <code>default.t1</code> with 2 fields (a int, b float) will + * be returned as: + * <code>{"PXFMetadata":[{"table":{"dbName":"default","tableName":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]}</code> * * @param servletContext servlet context * @param headers http headers * @param table HCatalog table name * @return JSON formatted response with metadata for given table - * @throws Exception if connection to Hcatalog failed, table didn't exist or its type or fields are not supported + * @throws Exception if connection to Hcatalog failed, table didn't exist or + * its type or fields are not supported */ @GET @Path("getTableMetadata") @Produces("application/json") public Response read(@Context final ServletContext servletContext, - @Context final HttpHeaders headers, - @QueryParam("table") final String table) throws Exception { - Log.debug("getTableMetadata started"); + @Context final HttpHeaders headers, + @QueryParam("table") final String table) + throws Exception { + LOG.debug("getTableMetadata started"); String jsonOutput; try { - // 1. start MetadataFetcher - MetadataFetcher metadataFetcher = - MetadataFetcherFactory.create("org.apache.hawq.pxf.plugins.hive.HiveMetadataFetcher"); //TODO: nhorn - 09-03-15 - pass as param + // 1. start MetadataFetcher + MetadataFetcher metadataFetcher = MetadataFetcherFactory.create("org.apache.hawq.pxf.plugins.hive.HiveMetadataFetcher"); // TODO: + // nhorn + // - + // 09-03-15 + // - + // pass + // as + // param - // 2. get Metadata - Metadata metadata = metadataFetcher.getTableMetadata(table); + // 2. get Metadata + Metadata metadata = metadataFetcher.getTableMetadata(table); - // 3. serialize to JSON - jsonOutput = MetadataResponseFormatter.formatResponseString(metadata); + // 3. serialize to JSON + jsonOutput = MetadataResponseFormatter.formatResponseString(metadata); - Log.debug("getTableMetadata output: " + jsonOutput); + LOG.debug("getTableMetadata output: " + jsonOutput); } catch (ClientAbortException e) { - Log.error("Remote connection closed by HAWQ", e); + LOG.error("Remote connection closed by HAWQ", e); throw e; } catch (java.io.IOException e) { - Log.error("Unhandled exception thrown", e); + LOG.error("Unhandled exception thrown", e); throw e; } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/RestResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/RestResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/RestResource.java index c609abb..60bb31e 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/RestResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/RestResource.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.rest; * under the License. */ - import javax.ws.rs.core.MultivaluedMap; import org.apache.commons.codec.CharEncoding; @@ -36,20 +35,23 @@ import java.util.TreeMap; */ public abstract class RestResource { - private static Log Log = LogFactory.getLog(RestResource.class); + private static final Log LOG = LogFactory.getLog(RestResource.class); /** - * Converts the request headers multivalued map to a case-insensitive regular map - * by taking only first values and storing them in a CASE_INSENSITIVE_ORDER TreeMap. - * All values are converted from ISO_8859_1 (ISO-LATIN-1) to UTF_8. + * Converts the request headers multivalued map to a case-insensitive + * regular map by taking only first values and storing them in a + * CASE_INSENSITIVE_ORDER TreeMap. All values are converted from ISO_8859_1 + * (ISO-LATIN-1) to UTF_8. * * @param requestHeaders request headers multi map. * @return a regular case-insensitive map. - * @throws UnsupportedEncodingException if the named charsets ISO_8859_1 and UTF_8 are not supported + * @throws UnsupportedEncodingException if the named charsets ISO_8859_1 and + * UTF_8 are not supported */ public Map<String, String> convertToCaseInsensitiveMap(MultivaluedMap<String, String> requestHeaders) throws UnsupportedEncodingException { - Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + Map<String, String> result = new TreeMap<>( + String.CASE_INSENSITIVE_ORDER); for (Map.Entry<String, List<String>> entry : requestHeaders.entrySet()) { String key = entry.getKey(); List<String> values = entry.getValue(); @@ -57,8 +59,9 @@ public abstract class RestResource { String value = values.get(0); if (value != null) { // converting to value UTF-8 encoding - value = new String(value.getBytes(CharEncoding.ISO_8859_1), CharEncoding.UTF_8); - Log.trace("key: " + key + ". value: " + value); + value = new String(value.getBytes(CharEncoding.ISO_8859_1), + CharEncoding.UTF_8); + LOG.trace("key: " + key + ". value: " + value); result.put(key, value.replace("\\\"", "\"")); } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ServletLifecycleListener.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ServletLifecycleListener.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ServletLifecycleListener.java index e0ea850..f7b897a 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ServletLifecycleListener.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/ServletLifecycleListener.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.rest; * 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 @@ -29,26 +29,26 @@ import javax.servlet.ServletContextEvent; import org.apache.hawq.pxf.service.utilities.Log4jConfigure; import org.apache.hawq.pxf.service.utilities.SecureLogin; -/** +/** * Listener on lifecycle events of our webapp */ public class ServletLifecycleListener implements ServletContextListener { - private static Log LOG = LogFactory.getLog(ServletContextListener.class); + private static final Log LOG = LogFactory.getLog(ServletContextListener.class); /** * Called after the webapp has been initialized. - * + * * 1. Initializes log4j. * 2. Initiates a Kerberos login when Hadoop security is on. */ @Override - public void contextInitialized(ServletContextEvent event) { + public void contextInitialized(ServletContextEvent event) { // 1. Initialize log4j: Log4jConfigure.configure(event); - + LOG.info("webapp initialized"); - + // 2. Initiate secure login SecureLogin.login(); } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java index f30e5e9..6f326d6 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/rest/VersionResource.java @@ -47,7 +47,7 @@ class Version { @Path("/ProtocolVersion") public class VersionResource { - private static final Log Log = LogFactory.getLog(VersionResource.class); + private static final Log LOG = LogFactory.getLog(VersionResource.class); public VersionResource() { } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/AnalyzeUtils.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/AnalyzeUtils.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/AnalyzeUtils.java index 67efeb4..21172c5 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/AnalyzeUtils.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/AnalyzeUtils.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.utilities; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.utilities; * under the License. */ - import java.util.ArrayList; import java.util.BitSet; import java.util.List; @@ -34,7 +33,7 @@ import org.apache.hawq.pxf.api.Fragment; */ public class AnalyzeUtils { - private static Log Log = LogFactory.getLog(AnalyzeUtils.class); + private static final Log LOG = LogFactory.getLog(AnalyzeUtils.class); /** * In case pxf_max_fragments parameter is declared, make sure not to get @@ -57,7 +56,7 @@ public class AnalyzeUtils { return fragments; } - Log.debug("fragments list has " + listSize + LOG.debug("fragments list has " + listSize + " fragments, maxFragments = " + maxSize); bitSet = generateSamplingBitSet(listSize, maxSize); @@ -88,7 +87,7 @@ public class AnalyzeUtils { } if (sampleSize >= poolSize) { - Log.debug("sampling bit map has " + poolSize + " elements (100%)"); + LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } @@ -116,7 +115,7 @@ public class AnalyzeUtils { } } - Log.debug("sampling bit map has " + chosen + " elements:" + LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Log4jConfigure.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Log4jConfigure.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Log4jConfigure.java index ecd51d9..c2ccd20 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Log4jConfigure.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Log4jConfigure.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.utilities; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.utilities; * under the License. */ - import java.io.File; import javax.servlet.ServletContext; @@ -31,35 +30,37 @@ import org.apache.log4j.PropertyConfigurator; public class Log4jConfigure { - private static Log LOG = LogFactory.getLog(Log4jConfigure.class); - + private static final Log LOG = LogFactory.getLog(Log4jConfigure.class); + /** * Initializes log4j logging for the webapp. - * - * Reads log4j properties file location from log4jConfigLocation parameter in web.xml. - * When not using aboslute path, the path starts from the webapp root directory. - * If the file can't be read, reverts to default configuration file under - * WEB-INF/classes/pxf-log4j.properties. - * + * + * Reads log4j properties file location from log4jConfigLocation parameter + * in web.xml. When not using aboslute path, the path starts from the webapp + * root directory. If the file can't be read, reverts to default + * configuration file under WEB-INF/classes/pxf-log4j.properties. + * * @param event Servlet context, used to determine webapp root directory. */ - public static void configure(ServletContextEvent event) { - - final String defaultLog4jLocation = "WEB-INF/classes/pxf-log4j.properties"; + public static void configure(ServletContextEvent event) { - ServletContext context = event.getServletContext(); + final String defaultLog4jLocation = "WEB-INF/classes/pxf-log4j.properties"; + + ServletContext context = event.getServletContext(); String log4jConfigLocation = context.getInitParameter("log4jConfigLocation"); if (!log4jConfigLocation.startsWith(File.separator)) { - log4jConfigLocation = context.getRealPath("") + File.separator + log4jConfigLocation; + log4jConfigLocation = context.getRealPath("") + File.separator + + log4jConfigLocation; } - + // revert to default properties file if file doesn't exist - File log4jConfigFile = new File (log4jConfigLocation); + File log4jConfigFile = new File(log4jConfigLocation); if (!log4jConfigFile.canRead()) { - log4jConfigLocation = context.getRealPath("") + File.separator + defaultLog4jLocation; + log4jConfigLocation = context.getRealPath("") + File.separator + + defaultLog4jLocation; } - PropertyConfigurator.configure(log4jConfigLocation); + PropertyConfigurator.configure(log4jConfigLocation); LOG.info("log4jConfigLocation = " + log4jConfigLocation); - } + } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecureLogin.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecureLogin.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecureLogin.java index 20fce7b..6ce05ed 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecureLogin.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecureLogin.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.utilities; * 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 @@ -19,42 +19,43 @@ package org.apache.hawq.pxf.service.utilities; * under the License. */ - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.SecurityUtil; -/* +/** * This class relies heavily on Hadoop API to - * - Check need for secure login in Hadoop - * - Parse and load .xml configuration file - * - Do a Kerberos login with a kaytab file - * - convert _HOST in Kerberos principal to current hostname + * <ul> + * <li>Check need for secure login in Hadoop</li> + * <li>Parse and load .xml configuration file</li> + * <li>Do a Kerberos login with a kaytab file</li> + * <li>convert _HOST in Kerberos principal to current hostname</li> + * </ul> * - * It uses Hadoop Configuration to parse XML configuration files - * It uses Hadoop Security to modify principal and perform the login + * It uses Hadoop Configuration to parse XML configuration files.<br> + * It uses Hadoop Security to modify principal and perform the login. * - * The major limitation in this class is its dependency - * on Hadoop. If Hadoop security is off, no login will be performed - * regardless of connector being used. + * The major limitation in this class is its dependency on Hadoop. If Hadoop + * security is off, no login will be performed regardless of connector being + * used. */ public class SecureLogin { - private static Log LOG = LogFactory.getLog(SecureLogin.class); - private static final String CONFIG_KEY_SERVICE_KEYTAB = "pxf.service.kerberos.keytab"; - private static final String CONFIG_KEY_SERVICE_PRINCIPAL = "pxf.service.kerberos.principal"; + private static final Log LOG = LogFactory.getLog(SecureLogin.class); + private static final String CONFIG_KEY_SERVICE_KEYTAB = "pxf.service.kerberos.keytab"; + private static final String CONFIG_KEY_SERVICE_PRINCIPAL = "pxf.service.kerberos.principal"; - public static void login() { - try { - Configuration config = new Configuration(); - config.addResource("pxf-site.xml"); + public static void login() { + try { + Configuration config = new Configuration(); + config.addResource("pxf-site.xml"); - SecurityUtil.login(config, CONFIG_KEY_SERVICE_KEYTAB, CONFIG_KEY_SERVICE_PRINCIPAL); - } catch (Exception e) - { - LOG.error("PXF service login failed"); - throw new RuntimeException(e); - } - } + SecurityUtil.login(config, CONFIG_KEY_SERVICE_KEYTAB, + CONFIG_KEY_SERVICE_PRINCIPAL); + } catch (Exception e) { + LOG.error("PXF service login failed"); + throw new RuntimeException(e); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecuredHDFS.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecuredHDFS.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecuredHDFS.java index 6917bac..f442a6d 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecuredHDFS.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/SecuredHDFS.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.utilities; * 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 @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.utilities; * under the License. */ - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; @@ -34,19 +33,21 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; -/* - * The class handles security functions for handling - * secured HDFS +/** + * The class handles security functions for handling secured HDFS */ public class SecuredHDFS { private static final Log LOG = LogFactory.getLog(SecuredHDFS.class); - /* + /** * The function will get the token information from parameters and call * SecuredHDFS to verify the token. * * All token properties will be deserialized from string to a Token object * + * @param protData input parameters + * @param context servlet context which contains the NN address + * * @throws SecurityException Thrown when authentication fails */ public static void verifyToken(ProtocolData protData, ServletContext context) { @@ -65,16 +66,16 @@ public class SecuredHDFS { } } - /* + /** * The function will verify the token with NameNode if available and will * create a UserGroupInformation. * * Code in this function is copied from JspHelper.getTokenUGI * * @param identifier Delegation token identifier - * * @param password Delegation token password - * + * @param kind the kind of token + * @param service the service for this token * @param servletContext Jetty servlet context which contains the NN address * * @throws SecurityException Thrown when authentication fails http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java index 372bcc8..8467734 100644 --- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java +++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java @@ -19,7 +19,6 @@ package org.apache.hawq.pxf.service.utilities; * under the License. */ - import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -138,11 +137,10 @@ public class Utilities { } /** - * Replaces any non-alpha-numeric character with a '.'. - * This measure is used to prevent cross-site scripting (XSS) - * when an input string might include code or script. By removing - * all special characters and returning a censured string to the user - * this threat is avoided. + * Replaces any non-alpha-numeric character with a '.'. This measure is used + * to prevent cross-site scripting (XSS) when an input string might include + * code or script. By removing all special characters and returning a + * censured string to the user this threat is avoided. * * @param input string to be masked * @return masked string http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/127cac3e/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java ---------------------------------------------------------------------- diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java index 098f29c..dcb89b8 100644 --- a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java +++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java @@ -8,9 +8,9 @@ package org.apache.hawq.pxf.service.io; * 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 @@ -46,12 +46,12 @@ public class GPDBWritableTest { DataInput inputStream; OngoingStubbing<Integer> ongoing; - Log Log; + Log LOG; @Before - public void SetupStaticLog() { - Log = mock(Log.class); - Whitebox.setInternalState(GPDBWritable.class, Log); + public void setupStaticLog() { + LOG = mock(Log.class); + Whitebox.setInternalState(GPDBWritable.class, LOG); } /* @@ -147,6 +147,6 @@ public class GPDBWritableTest { } private void verifyLog(String msg) { - Mockito.verify(Log).debug(msg); + Mockito.verify(LOG).debug(msg); } }
