You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2015/08/11 14:21:02 UTC
[39/50] [abbrv] incubator-lens git commit: LENS-634 : Enable CLI to
give file name suggestions
LENS-634 : Enable CLI to give file name suggestions
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/e35b1065
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/e35b1065
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/e35b1065
Branch: refs/heads/current-release-line
Commit: e35b10652c39031c47644545ee4e2a653a4a3629
Parents: e5a0ff1
Author: Yash Sharma <ya...@gmail.com>
Authored: Thu Aug 6 18:13:41 2015 +0530
Committer: Rajat Khandelwal <pr...@apache.org>
Committed: Thu Aug 6 18:13:41 2015 +0530
----------------------------------------------------------------------
.../main/java/org/apache/lens/api/LensConf.java | 10 ++
.../org/apache/lens/api/util/PathValidator.java | 139 +++++++++++++++++++
.../org/apache/lens/api/TestPathValidator.java | 137 ++++++++++++++++++
.../lens/cli/commands/BaseLensCommand.java | 47 ++++---
.../lens/cli/commands/LensCRUDCommand.java | 11 +-
.../cli/commands/LensConnectionCommands.java | 17 ++-
.../lens/cli/commands/LensCubeCommands.java | 7 +-
.../cli/commands/LensDimensionCommands.java | 7 +-
.../commands/LensDimensionTableCommands.java | 12 +-
.../lens/cli/commands/LensFactCommands.java | 12 +-
.../lens/cli/commands/LensQueryCommands.java | 15 +-
.../lens/cli/commands/LensStorageCommands.java | 7 +-
.../cli/commands/PhysicalTableCrudCommand.java | 16 ++-
.../apache/lens/cli/TestLensCubeCommands.java | 4 +-
.../lens/cli/TestLensDatabaseCommands.java | 3 +-
.../lens/cli/TestLensDimensionCommands.java | 4 +-
.../cli/TestLensDimensionTableCommands.java | 21 +--
.../apache/lens/cli/TestLensFactCommands.java | 16 +--
.../TestLensFactCommandsWithMissingWeight.java | 4 +-
.../apache/lens/cli/TestLensQueryCommands.java | 8 +-
.../lens/cli/TestLensStorageCommands.java | 4 +-
.../java/org/apache/lens/client/LensClient.java | 8 +-
.../org/apache/lens/server/BaseLensService.java | 34 +++++
.../server/query/QueryExecutionServiceImpl.java | 5 +-
.../apache/lens/server/util/ScannedPaths.java | 1 +
src/site/apt/user/cli.apt | 4 +-
26 files changed, 449 insertions(+), 104 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-api/src/main/java/org/apache/lens/api/LensConf.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/LensConf.java b/lens-api/src/main/java/org/apache/lens/api/LensConf.java
index 1f02431..3b1ad87 100644
--- a/lens-api/src/main/java/org/apache/lens/api/LensConf.java
+++ b/lens-api/src/main/java/org/apache/lens/api/LensConf.java
@@ -62,4 +62,14 @@ public class LensConf implements Serializable {
public void addProperty(String key, String value) {
properties.put(key, value);
}
+
+ /**
+ * Adds Map of properties.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void addProperties(Map<String, String> props) {
+ properties.putAll(props);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-api/src/main/java/org/apache/lens/api/util/PathValidator.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/util/PathValidator.java b/lens-api/src/main/java/org/apache/lens/api/util/PathValidator.java
new file mode 100644
index 0000000..4025f5f
--- /dev/null
+++ b/lens-api/src/main/java/org/apache/lens/api/util/PathValidator.java
@@ -0,0 +1,139 @@
+/**
+ * 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.lens.api.util;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.lens.api.LensConf;
+
+/**
+ * The Path validator utility class takes in the malformatted paths
+ * and converts to the appropriate valid path.
+ * It also takes in custom properties for special handling of URI's.
+ */
+public class PathValidator {
+ private LensConf config;
+
+ public static final String PATH_PREFIX = "filesystem.prefix.";
+
+ public PathValidator(LensConf config) {
+ createDefaultUriProperties();
+ this.config.addProperties(config.getProperties());
+ }
+
+ private void createDefaultUriProperties() {
+ config = new LensConf();
+ config.addProperty(PATH_PREFIX + "hdfs", "://");
+ config.addProperty(PATH_PREFIX + "s3", "://");
+ config.addProperty(PATH_PREFIX + "s3n", "://");
+ }
+
+ /**
+ * Converts the input path to appropriate File/URI path.
+ * Also removes erroneously appended prefix for URI's.
+ * Takes additional properties for special URI handling.
+ *
+ * @param path
+ * @param shouldBeDirectory
+ * @param shouldExist
+ * @return
+ */
+ public String getValidPath(File path, boolean shouldBeDirectory,
+ boolean shouldExist) {
+ /** For URI located file paths **/
+ /* Cli prefixes the local path before file:/ if provided path does not start with ~/ or / */
+ if (path.getPath().indexOf(":/") > 0) {
+ return removePrefixBeforeURI(path.getPath());
+ }
+
+ /** For filesystem file paths **/
+ if (shouldExist && !path.exists()) {
+ throw new RuntimeException("Path " + path + " doesn't exist.");
+ }
+ if (shouldBeDirectory && !path.isDirectory()) {
+ throw new RuntimeException("Path " + path + " is not a directory");
+ }
+ if (!shouldBeDirectory && path.isDirectory()) {
+ throw new RuntimeException("Path " + path + " is a directory");
+ }
+ return path.getAbsolutePath();
+ }
+
+ /**
+ * The CLI erroneously appends absolute path for URI's.
+ * It also replaces the double slashes to single slashes.
+ * Eg. /home/some/path/file:/home/git/incubator-lens/target/tempdata_*.txt
+ *
+ * This Util method removes the erroneously appended absolute path for URI's.
+ * And appends :/// for the URI's.
+ * Paths with hdfs/s3/s3n are appended with double slashes ://
+ *
+ * Any new URI's have to be handled appropriately
+ *
+ * @param path
+ * @return
+ */
+ public String removePrefixBeforeURI(String path) {
+ /**
+ * For uniformity, Replaces all multiple slashes to single slash.
+ * This is how the CLI forwards the path.
+ * Any URI scheme with multiple slashes has to be handled appropriately.
+ **/
+ path = path.replaceAll("/+", "/");
+ path = path.replaceAll("/$", "");
+ if (path.startsWith("~")) {
+ path = path.replaceFirst("~", System.getProperty("user.home"));
+ }
+
+ /** For URI located file paths **/
+ /* Cli prefixes the local path before URI if provided path does not start with ~/ or / */
+ String projectDir = Paths.get("").toAbsolutePath().toString();
+ int indexOfUriInit = path.indexOf(":/");
+ int currDirLen = projectDir.length();
+ String escapedSlashes = ":///";
+
+ /**
+ * Special case - hdfs/s3/s3n need double escape :// instead of :///
+ * Currently add handling only for hdfs/s3/s3n uri's. Open to identify corner cases.
+ * Can be extended to handle other uri patterns.
+ */
+ Pattern pattern = Pattern.compile("^(.*):/.*");
+ Matcher match = pattern.matcher(path);
+ if (match.find() && config.getProperties().get(PATH_PREFIX + match.group(1)) != null) {
+ escapedSlashes = config.getProperties().get(PATH_PREFIX + match.group(1));
+ }
+
+ /** Remove the prefix **/
+ if (path.startsWith(projectDir) && indexOfUriInit != -1) {
+ path = path.substring(currDirLen + 1, path.length());
+ }
+
+ /** Properly format the URI **/
+ indexOfUriInit = path.indexOf(":/");
+ if (indexOfUriInit != -1 && !path.contains(":///")) {
+ path = path.substring(0, indexOfUriInit)
+ + escapedSlashes
+ + path.substring(indexOfUriInit + 2);
+ }
+ return path;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-api/src/test/java/org/apache/lens/api/TestPathValidator.java
----------------------------------------------------------------------
diff --git a/lens-api/src/test/java/org/apache/lens/api/TestPathValidator.java b/lens-api/src/test/java/org/apache/lens/api/TestPathValidator.java
new file mode 100644
index 0000000..bb9ee9f
--- /dev/null
+++ b/lens-api/src/test/java/org/apache/lens/api/TestPathValidator.java
@@ -0,0 +1,137 @@
+/**
+ * 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.lens.api;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.lens.api.util.PathValidator;
+
+import org.junit.After;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class TestPathValidator {
+ private String[] inputPaths = {
+ "/tmp/lens/server",
+ "file:///tmp/lens/server",
+ "file:////tmp/lens/server",
+ "hdfs:/tmp/lens/server",
+ "hdfs:///tmp/lens/server",
+ "~/tmp/lens/server",
+ };
+
+ private String [] validPaths = {
+ "/tmp/lens/server",
+ "file:///tmp/lens/server",
+ "file:///tmp/lens/server",
+ "hdfs://tmp/lens/server",
+ "hdfs://tmp/lens/server",
+ System.getProperty("user.home") + "/tmp/lens/server",
+ };
+
+ private static final String PROJECT_DIR = new File("").getAbsolutePath();
+ private static final String EXISTING_PATH = PROJECT_DIR + "/target/tmp/lens/server";
+ private static final String NON_EXISTING_PATH = PROJECT_DIR + "/target/tmp/lens/dir";
+
+ private static final File EXISTING_FILE = new File(EXISTING_PATH);
+ private static final File NON_EXISTING_FILE = new File(NON_EXISTING_PATH);
+
+
+ @BeforeTest
+ public void beforeTest() {
+ cleanupFiles();
+ }
+
+ @After
+ public void after() {
+ cleanupFiles();
+ }
+
+ private void cleanupFiles() {
+ try {
+ if (EXISTING_FILE.exists()) {
+ EXISTING_FILE.delete();
+ }
+ if (NON_EXISTING_FILE.exists()) {
+ NON_EXISTING_FILE.delete();
+ }
+ } catch (Exception ex) {
+ Assert.fail("Unable to delete file.", ex);
+ }
+ }
+
+ @Test
+ public void testExistingFileWithoutChecks() {
+ cleanupFiles();
+ /** Test: without checks **/
+ PathValidator validator = new PathValidator(new LensConf());
+ Assert.assertEquals(validator.getValidPath(EXISTING_FILE, false, false), EXISTING_PATH);
+ }
+
+ @Test
+ public void testExistingFileShouldExist() throws IOException{
+ PathValidator validator = new PathValidator(new LensConf());
+ /** Test: file should exist **/
+ if (!EXISTING_FILE.exists()) {
+ EXISTING_FILE.getParentFile().mkdirs();
+ EXISTING_FILE.createNewFile();
+ }
+ Assert.assertEquals(validator.getValidPath(EXISTING_FILE, false, true), EXISTING_PATH);
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testNonExistingFileShouldHadExisted() {
+ /** Test: non existing file should had existed **/
+ /* Should throw RuntimeException */
+ PathValidator validator = new PathValidator(new LensConf());
+ validator.getValidPath(NON_EXISTING_FILE, true, true);
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testNonExistingFileShouldHadBeenDir() {
+ /** Test: non existing file should had been dir **/
+ /* Should throw RuntimeException */
+ PathValidator validator = new PathValidator(new LensConf());
+ validator.getValidPath(NON_EXISTING_FILE, true, false);
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testDirShouldHadBeenFile() {
+ /** Test: dir should had been file **/
+ if (!NON_EXISTING_FILE.exists()) {
+ NON_EXISTING_FILE.mkdirs();
+ }
+ /* Should throw RuntimeException */
+ PathValidator validator = new PathValidator(new LensConf());
+ validator.getValidPath(NON_EXISTING_FILE, false, false);
+ }
+
+ @Test
+ public void testRemovePrefixBeforeURI() {
+ PathValidator validator = new PathValidator(new LensConf());
+ for (int index = 0; index < inputPaths.length; index++) {
+ Assert.assertEquals(
+ validator.removePrefixBeforeURI(inputPaths[index]),
+ validPaths[index],
+ "Test failed for input " + inputPaths[index] + " [index:" + index + "]");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
index bdfae24..6437725 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java
@@ -22,13 +22,12 @@ import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-
import java.util.Date;
+import org.apache.lens.api.util.PathValidator;
import org.apache.lens.client.LensClient;
import org.apache.lens.client.LensClientSingletonWrapper;
-
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.impl.Indenter;
@@ -143,25 +142,6 @@ public class BaseLensCommand implements ExecutionProcessor {
.replaceAll("]", "\n").replaceAll(",", "").replaceAll("\"", "").replaceAll("\n\n", "\n");
}
- public static String getValidPath(String path, boolean shouldBeDirectory, boolean shouldExist) {
- path = path.replaceAll("/$", "");
- if (path.startsWith("~")) {
- path = path.replaceFirst("~", System.getProperty("user.home"));
- }
- File f = new File(path);
- if (shouldExist && !f.exists()) {
- throw new RuntimeException("Path " + path + " doesn't exist.");
- }
- if (shouldBeDirectory && !f.isDirectory()) {
- throw new RuntimeException("Path " + path + " is not a directory");
- }
- if (!shouldBeDirectory && f.isDirectory()) {
- throw new RuntimeException("Path " + path + " is a directory");
- }
- return f.getAbsolutePath();
- }
-
-
/**
* This Code piece allows lens cli to be able to parse list arguments. It can already parse keyword args.
* More details at https://github.com/spring-projects/spring-shell/issues/72
@@ -189,4 +169,29 @@ public class BaseLensCommand implements ExecutionProcessor {
@Override
public void afterThrowingInvocation(ParseResult parseResult, Throwable throwable) {
}
+
+ /**
+ * Method that uses PathValidator to get appropriate path.
+ *
+ * @param path
+ * @param shouldBeDirectory
+ * @param shouldExist
+ * @return
+ */
+ public String getValidPath(File path, boolean shouldBeDirectory, boolean shouldExist) {
+ PathValidator pathValidator = getClient().getPathValidator();
+ return pathValidator.getValidPath(path, shouldBeDirectory, shouldExist);
+ }
+
+ /**
+ * Method to remove unrequired prefix from path.
+ *
+ * @param path
+ * @return
+ */
+ public String removePrefixBeforeURI(String path) {
+ PathValidator pathValidator = getClient().getPathValidator();
+ return pathValidator.removePrefixBeforeURI(path);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCRUDCommand.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCRUDCommand.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCRUDCommand.java
index 9cb7d69..a0c05b4 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCRUDCommand.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCRUDCommand.java
@@ -18,6 +18,7 @@
*/
package org.apache.lens.cli.commands;
+import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -37,8 +38,9 @@ public abstract class LensCRUDCommand<T> extends BaseLensCommand {
return Joiner.on("\n").join(all);
}
- public String create(String path, boolean ignoreIfExists) {
- return doCreate(getValidPath(path, false, true), ignoreIfExists).getStatus().toString().toLowerCase();
+ public String create(File path, boolean ignoreIfExists) {
+ return doCreate(getValidPath(path, false, true), ignoreIfExists)
+ .getStatus().toString().toLowerCase();
}
public String describe(String name) {
@@ -49,8 +51,9 @@ public abstract class LensCRUDCommand<T> extends BaseLensCommand {
}
}
- public String update(String entity, String path) {
- return doUpdate(entity, getValidPath(path, false, true)).getStatus().toString().toLowerCase();
+ public String update(String entity, File path) {
+ return doUpdate(entity, getValidPath(path, false, true))
+ .getStatus().toString().toLowerCase();
}
public String drop(String name, boolean cascade) {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensConnectionCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensConnectionCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensConnectionCommands.java
index 51c4baf..2795211 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensConnectionCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensConnectionCommands.java
@@ -40,6 +40,7 @@ import ch.qos.logback.core.*;
import com.google.common.base.Joiner;
+import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
@@ -99,7 +100,7 @@ public class LensConnectionCommands extends BaseLensCommand {
*/
@CliCommand(value = "add jar", help = "Adds jar resource to the session")
public String addJar(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-jar-on-server-side>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-jar-on-server-side>") @NonNull String path) {
APIResult result = getClient().addJarResource(path);
return result.getMessage();
}
@@ -112,7 +113,7 @@ public class LensConnectionCommands extends BaseLensCommand {
*/
@CliCommand(value = "remove jar", help = "Removes a jar resource from session")
public String removeJar(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-jar-on-server-side>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-jar-on-server-side>") @NonNull String path) {
APIResult result = getClient().removeJarResource(path);
return result.getMessage();
}
@@ -125,7 +126,7 @@ public class LensConnectionCommands extends BaseLensCommand {
*/
@CliCommand(value = "add file", help = "Adds a file resource to session")
public String addFile(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-file-on-server-side>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-file-on-server-side>") @NonNull String path) {
APIResult result = getClient().addFileResource(path);
return result.getMessage();
}
@@ -134,11 +135,11 @@ public class LensConnectionCommands extends BaseLensCommand {
* Removes the file.
*
* @param path the path
- * @return the string
+ * @return the stringadd
*/
@CliCommand(value = "remove file", help = "removes a file resource from session")
public String removeFile(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-file-on-server-side>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-file-on-server-side>") @NonNull String path) {
APIResult result = getClient().removeFileResource(path);
return result.getMessage();
}
@@ -181,8 +182,7 @@ public class LensConnectionCommands extends BaseLensCommand {
help = "prints all class level logs and verbose logs on cli for debugging purpose."
+ " 'debug false' to turn off all class level logging and verbose level logging ")
public void debug(@CliOption(key = {"", "enable"},
- mandatory = false, unspecifiedDefaultValue = "true",
- help = "To print all logs on cli for debugging purpose") boolean enable) {
+ mandatory = false, unspecifiedDefaultValue = "true") boolean enable) {
Logger logger = LoggerUtil.getRootLogger();
Logger cliLogger = LoggerUtil.getCliLogger();
if (enable) {
@@ -201,8 +201,7 @@ public class LensConnectionCommands extends BaseLensCommand {
@CliCommand(value = {"verbose"},
help = "Show cliLogger logs on cli. 'verbose false' turns off the cliLogger logs on console")
public void verbose(@CliOption(key = {"", "enable"},
- mandatory = false, unspecifiedDefaultValue = "true",
- help = "Print the clilogger logs on cli") boolean enable) {
+ mandatory = false, unspecifiedDefaultValue = "true") boolean enable) {
Logger cliLogger = LoggerUtil.getCliLogger();
if (enable) {
LoggerUtil.addConsoleAppenderIfNotPresent(cliLogger);
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCubeCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCubeCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCubeCommands.java
index 6ba702f..cfee32f 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCubeCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensCubeCommands.java
@@ -18,6 +18,7 @@
*/
package org.apache.lens.cli.commands;
+import java.io.File;
import java.util.Date;
import java.util.List;
@@ -29,6 +30,8 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
+import lombok.NonNull;
+
/**
* The Class LensCubeCommands.
*/
@@ -55,7 +58,7 @@ public class LensCubeCommands extends LogicalTableCrudCommand<XCube> {
*/
@CliCommand(value = "create cube", help = "Create a new Cube, taking spec from <path-to-cube-spec-file>")
public String createCube(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-cube-spec-file>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-cube-spec-file>") @NonNull final File path) {
return create(path, false);
}
@@ -80,7 +83,7 @@ public class LensCubeCommands extends LogicalTableCrudCommand<XCube> {
@CliCommand(value = "update cube", help = "update cube <cube_name> with spec from <path-to-cube-spec-file>")
public String updateCube(
@CliOption(key = {"", "name"}, mandatory = true, help = "<cube_name>") String name,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-cube-spec-file>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-cube-spec-file>") @NonNull final File path) {
return update(name, path);
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionCommands.java
index de022c1..1f70337 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionCommands.java
@@ -18,6 +18,7 @@
*/
package org.apache.lens.cli.commands;
+import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -29,6 +30,8 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
+import lombok.NonNull;
+
/**
* The Class LensDimensionCommands.
*/
@@ -56,7 +59,7 @@ public class LensDimensionCommands extends LogicalTableCrudCommand<XDimension> {
help = "Create a new Dimension, taking spec from <path-to-dimension-spec file>")
public String createDimension(
@CliOption(key = {"", "path"}, mandatory = true, help =
- "<path-to-dimension-spec file>") String path) {
+ "<path-to-dimension-spec file>") @NonNull final File path) {
return create(path, false);
}
@@ -87,7 +90,7 @@ public class LensDimensionCommands extends LogicalTableCrudCommand<XDimension> {
help = "update dimension <dimension_name>, taking spec from <path-to-dimension-spec file>")
public String updateDimension(
@CliOption(key = {"", "name"}, mandatory = true, help = "<dimension_name>") String name,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimension-spec-file>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimension-spec-file>") @NonNull final File path) {
return update(name, path);
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java
index 5fd80a1..1759d9c 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java
@@ -65,7 +65,7 @@ public class LensDimensionTableCommands extends PhysicalTableCrudCommand<XDimens
@CliCommand(value = "create dimtable",
help = "Create a new dimension table taking spec from <path-to-dimtable-spec-file>")
public String createDimensionTable(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimtable-spec-file>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimtable-spec-file>") @NonNull final File path) {
return create(path, false);
}
@@ -92,7 +92,7 @@ public class LensDimensionTableCommands extends PhysicalTableCrudCommand<XDimens
help = "update dimtable <dimtable_name> taking spec from <path-to-dimtable-spec>")
public String updateDimensionTable(
@CliOption(key = {"", "dimtable_name"}, mandatory = true, help = "<dimtable_name>") String name,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimtable-spec>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-dimtable-spec>") @NonNull final File path) {
return update(name, path);
}
@@ -138,7 +138,7 @@ public class LensDimensionTableCommands extends PhysicalTableCrudCommand<XDimens
help = "adds a new storage to dimtable <dimtable_name>, taking storage spec from <path-to-storage-spec>")
public String addNewDimStorage(
@CliOption(key = {"", "dimtable_name"}, mandatory = true, help = "<dimtable_name>") String tableName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") @NonNull final File path) {
return addStorage(tableName, path);
}
@@ -231,7 +231,7 @@ public class LensDimensionTableCommands extends PhysicalTableCrudCommand<XDimens
public String addPartitionToDimtable(
@CliOption(key = {"", "dimtable_name"}, mandatory = true, help = "<dimtable_name>") String tableName,
@CliOption(key = {"", "storage_name"}, mandatory = true, help = "<storage_name>") String storageName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-spec-path>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-spec-path>") @NonNull final File path) {
return addPartition(tableName, storageName, path);
}
@CliCommand(value = "dimtable update single-partition",
@@ -260,8 +260,8 @@ public class LensDimensionTableCommands extends PhysicalTableCrudCommand<XDimens
public String addPartitionsToDimtable(
@CliOption(key = {"", "dimtable_name"}, mandatory = true, help = "<dimtable_name>") String tableName,
@CliOption(key = {"", "storage_name"}, mandatory = true, help = "<storage_name>") String storageName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-list-spec-path>") String path) {
- return addPartitions(tableName, storageName, path);
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-list-spec-path>") @NonNull final File path) {
+ return addPartitions(tableName, storageName, path.getPath());
}
@CliCommand(value = "dimtable update partitions",
help = "update multiple partition to dimtable <dimtable_name>'s"
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
index 5493dba..e2f1c50 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
@@ -62,7 +62,7 @@ public class LensFactCommands extends PhysicalTableCrudCommand<XFactTable> {
*/
@CliCommand(value = "create fact", help = "create a fact table with spec from <path-to-fact-spec-file>")
public String createFact(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-fact-spec-file>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-fact-spec-file>") @NonNull final File path) {
return create(path, false);
}
@@ -88,7 +88,7 @@ public class LensFactCommands extends PhysicalTableCrudCommand<XFactTable> {
@CliCommand(value = "update fact", help = "update fact <fact_name> taking spec from <path-to-fact-spec>")
public String updateFactTable(
@CliOption(key = {"", "fact_name"}, mandatory = true, help = "<fact_name>") String name,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-fact-spec>") String specPath) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-fact-spec>") @NonNull final File specPath) {
return update(name, specPath);
}
@@ -133,7 +133,7 @@ public class LensFactCommands extends PhysicalTableCrudCommand<XFactTable> {
help = "adds a new storage to fact <fact_name>, taking storage spec from <path-to-storage-spec>")
public String addNewFactStorage(
@CliOption(key = {"", "fact_name"}, mandatory = true, help = "<fact_name>") String tableName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") @NonNull final File path) {
return addStorage(tableName, path);
}
@@ -226,7 +226,7 @@ public class LensFactCommands extends PhysicalTableCrudCommand<XFactTable> {
public String addPartitionToFact(
@CliOption(key = {"", "fact_name"}, mandatory = true, help = "<fact_name>") String tableName,
@CliOption(key = {"", "storage_name"}, mandatory = true, help = "<storage_name>") String storageName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-spec-path>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-spec-path>") @NonNull final File path) {
return addPartition(tableName, storageName, path);
}
/**
@@ -254,8 +254,8 @@ public class LensFactCommands extends PhysicalTableCrudCommand<XFactTable> {
public String addPartitionsToFact(
@CliOption(key = {"", "fact_name"}, mandatory = true, help = "<fact_name>") String tableName,
@CliOption(key = {"", "storage_name"}, mandatory = true, help = "<storage_name>") String storageName,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-list-spec-path>") String path) {
- return addPartitions(tableName, storageName, path);
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<partition-list-spec-path>") @NonNull final File path) {
+ return addPartitions(tableName, storageName, path.getPath());
}
@CliCommand(value = "fact update partitions",
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
index c48fabd..88facda 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
@@ -209,14 +209,14 @@ public class LensQueryCommands extends BaseLensCommand {
help = "Explain execution plan of query <query-string>. Can optionally save the plan"
+ " to a file by providing <save_location>")
public String explainQuery(@CliOption(key = {"", "query"}, mandatory = true, help = "<query-string>") String sql,
- @CliOption(key = {"save_location"}, mandatory = false, help = "<save_location>") String location)
+ @CliOption(key = {"save_location"}, mandatory = false, help = "<save_location>") final File path)
throws IOException {
QueryPlan plan = getClient().getQueryPlan(sql);
if (plan.isError()) {
return "Explain FAILED:" + plan.getErrorMsg();
}
- if (StringUtils.isNotBlank(location)) {
- String validPath = getValidPath(location, false, false);
+ if (path != null && StringUtils.isNotBlank(path.getPath())) {
+ String validPath = getValidPath(path, false, false);
try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(validPath), Charset.defaultCharset())) {
osw.write(plan.getPlanString());
}
@@ -284,20 +284,21 @@ public class LensQueryCommands extends BaseLensCommand {
+ "Can optionally save the results to a file by providing <save_location>.")
public String getQueryResults(
@CliOption(key = {"", "query_handle"}, mandatory = true, help = "<query_handle>") String qh,
- @CliOption(key = {"save_location"}, mandatory = false, help = "<save_location>") String location,
+ @CliOption(key = {"save_location"}, mandatory = false, help = "<save_location>") final File path,
@CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "true",
help = "<async>") boolean async) {
QueryHandle queryHandle = new QueryHandle(UUID.fromString(qh));
LensClient.LensClientResultSetWithStats results;
+ String location = path != null ? path.getPath() : null;
try {
String prefix = "";
if (StringUtils.isNotBlank(location)) {
- location = getValidPath(location, true, true);
+ location = getValidPath(path, true, true);
Response response = getClient().getHttpResults(queryHandle);
if (response.getStatus() == Response.Status.OK.getStatusCode()) {
String disposition = (String) response.getHeaders().get("content-disposition").get(0);
String fileName = disposition.split("=")[1].trim();
- location = getValidPath(location + File.separator + fileName, false, false);
+ location = getValidPath(new File(location + File.separator + fileName), false, false);
try (InputStream stream = response.readEntity(InputStream.class);
FileOutputStream outStream = new FileOutputStream(new File(location))) {
IOUtils.copy(stream, outStream);
@@ -312,7 +313,7 @@ public class LensQueryCommands extends BaseLensCommand {
if (results.getResultSet() == null) {
return "Resultset not yet available";
} else if (results.getResultSet().getResult() instanceof InMemoryQueryResult) {
- location = getValidPath(location + File.separator + qh + ".csv", false, false);
+ location = getValidPath(new File(location + File.separator + qh + ".csv"), false, false);
try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(location),
Charset.defaultCharset())) {
osw.write(formatResultSet(results));
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/LensStorageCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensStorageCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensStorageCommands.java
index 928120a..ca73af7 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensStorageCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensStorageCommands.java
@@ -18,6 +18,7 @@
*/
package org.apache.lens.cli.commands;
+import java.io.File;
import java.util.List;
import org.apache.lens.api.APIResult;
@@ -29,6 +30,8 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
+import lombok.NonNull;
+
/**
* The Class LensStorageCommands.
*/
@@ -49,7 +52,7 @@ public class LensStorageCommands extends LensCRUDCommand<XStorage> implements Co
*/
@CliCommand(value = "create storage", help = "Create a new Storage from file <path-to-storage-spec>")
public String createStorage(
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") @NonNull final File path) {
return create(path, false);
}
@@ -76,7 +79,7 @@ public class LensStorageCommands extends LensCRUDCommand<XStorage> implements Co
help = "update storage <storage-name> with storage spec from <path-to-storage-spec>")
public String updateStorage(
@CliOption(key = {"", "name"}, mandatory = true, help = "<storage-name>") String name,
- @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") String path) {
+ @CliOption(key = {"", "path"}, mandatory = true, help = "<path-to-storage-spec>") @NonNull final File path) {
return update(name, path);
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/main/java/org/apache/lens/cli/commands/PhysicalTableCrudCommand.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/PhysicalTableCrudCommand.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/PhysicalTableCrudCommand.java
index c505680..a1ccec6 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/PhysicalTableCrudCommand.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/PhysicalTableCrudCommand.java
@@ -53,7 +53,7 @@ public abstract class PhysicalTableCrudCommand<T> extends LensCRUDCommand<T> {
return ret.isEmpty() ? "No storage found for " + tableName : ret;
}
- public String addStorage(String tableName, String path) {
+ public String addStorage(String tableName, File path) {
return doAddStorage(tableName, getValidPath(path, false, true)).toString().toLowerCase();
}
@@ -81,22 +81,24 @@ public abstract class PhysicalTableCrudCommand<T> extends LensCRUDCommand<T> {
}
}
- public String addPartition(String tableName, String storageName, String path) {
- return doAddPartition(tableName, storageName, getValidPath(path, false, true)).toString().toLowerCase();
+ public String addPartition(String tableName, String storageName, File path) {
+ return doAddPartition(tableName, storageName,
+ getValidPath(path, false, true)).toString().toLowerCase();
}
public String updatePartition(String tableName, String storageName, File path) {
- // TODO: path.getPath() to be changed to path after LENS-634
- return doUpdatePartition(tableName, storageName, getValidPath(path.getPath(), false, true)).toString()
+ return doUpdatePartition(tableName, storageName, getValidPath(path, false, true)).toString()
.toLowerCase();
}
public String addPartitions(String tableName, String storageName, String path) {
- return doAddPartitions(tableName, storageName, getValidPath(path, false, true)).toString().toLowerCase();
+ return doAddPartitions(tableName, storageName,
+ getValidPath(new File(path), false, true)).toString().toLowerCase();
}
public String updatePartitions(String tableName, String storageName, String path) {
- return doUpdatePartitions(tableName, storageName, getValidPath(path, false, true)).toString().toLowerCase();
+ return doUpdatePartitions(tableName, storageName,
+ getValidPath(new File(path), false, true)).toString().toLowerCase();
}
public String dropPartitions(String tableName, String storageName, String filter) {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensCubeCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensCubeCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensCubeCommands.java
index 73661e1..9912eef 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensCubeCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensCubeCommands.java
@@ -56,7 +56,7 @@ public class TestLensCubeCommands extends LensCliApplicationTest {
URL cubeSpec = TestLensCubeCommands.class.getClassLoader().getResource("sample-cube.xml");
String cubeList = command.showCubes();
assertFalse(cubeList.contains("sample_cube"));
- command.createCube(new File(cubeSpec.toURI()).getAbsolutePath());
+ command.createCube(new File(cubeSpec.toURI()));
cubeList = command.showCubes();
assertEquals(command.getLatest("sample_cube", "dt"), "No Data Available");
assertTrue(cubeList.contains("sample_cube"));
@@ -127,7 +127,7 @@ public class TestLensCubeCommands extends LensCliApplicationTest {
assertTrue(desc.contains(propString));
- command.updateCube("sample_cube", "/tmp/sample_cube1.xml");
+ command.updateCube("sample_cube", new File("/tmp/sample_cube1.xml"));
desc = command.describeCube("sample_cube");
LOG.debug(desc);
assertTrue(desc.contains(propString));
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensDatabaseCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDatabaseCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDatabaseCommands.java
index b6f96e6..32ed7b0 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDatabaseCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDatabaseCommands.java
@@ -67,8 +67,7 @@ public class TestLensDatabaseCommands extends LensCliApplicationTest {
assertEquals(result, "Successfully switched to my_db");
if (cascade) {
String createOutput = cubeCommand.createCube(
- new File(TestLensDatabaseCommands.class.getClassLoader().getResource("sample-cube.xml").toURI())
- .getAbsolutePath());
+ new File(TestLensDatabaseCommands.class.getClassLoader().getResource("sample-cube.xml").toURI()));
assertEquals(createOutput, "succeeded");
assertTrue(cubeCommand.showCubes().contains("sample_cube"));
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
index a22862e..fa96fcc 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
@@ -63,7 +63,7 @@ public class TestLensDimensionCommands extends LensCliApplicationTest {
*/
public static void createDimension() throws URISyntaxException {
URL dimensionSpec = TestLensDimensionCommands.class.getClassLoader().getResource("test-dimension.xml");
- getCommand().createDimension(new File(dimensionSpec.toURI()).getAbsolutePath());
+ getCommand().createDimension(new File(dimensionSpec.toURI()));
}
/**
@@ -137,7 +137,7 @@ public class TestLensDimensionCommands extends LensCliApplicationTest {
String propString1 = "name : test_dim.prop1 value : test1";
Assert.assertTrue(desc.contains(propString));
- command.updateDimension("test_dim", "/tmp/test_dim1.xml");
+ command.updateDimension("test_dim", new File("/tmp/test_dim1.xml"));
desc = command.describeDimension("test_dim");
log.debug(desc);
Assert.assertTrue(desc.contains(propString));
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionTableCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionTableCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionTableCommands.java
index 56e962d..60849aa 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionTableCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionTableCommands.java
@@ -1,4 +1,4 @@
-/**
+ /**
* 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
@@ -89,7 +89,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
private void createDimension() throws URISyntaxException {
URL dimensionSpec = TestLensDimensionTableCommands.class.getClassLoader().getResource("test-dimension.xml");
- getDimensionCommand().createDimension(new File(dimensionSpec.toURI()).getAbsolutePath());
+ getDimensionCommand().createDimension(new File(dimensionSpec.toURI()));
}
@@ -113,7 +113,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
URL dimSpec = TestLensDimensionTableCommands.class.getClassLoader().getResource(specName);
try {
- command.createDimensionTable(new File(dimSpec.toURI()).getAbsolutePath());
+ command.createDimensionTable(new File(dimSpec.toURI()));
} catch (Exception e) {
log.error("Unable to create dimtable", e);
fail("Unable to create dimtable" + e.getMessage());
@@ -171,7 +171,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
String propString2 = "name : dim2.prop1 value : d2";
assertTrue(desc.contains(propString));
- command.updateDimensionTable("dim_table2", "/tmp/local-dim1.xml");
+ command.updateDimensionTable("dim_table2", new File("/tmp/local-dim1.xml"));
desc = command.describeDimensionTable("dim_table2");
log.debug(desc);
assertTrue(desc.contains(propString1));
@@ -212,7 +212,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
LensDimensionTableCommands command = getCommand();
String result;
URL resource = TestLensDimensionTableCommands.class.getClassLoader().getResource("dim-local-storage-element.xml");
- command.addNewDimStorage("dim_table2", new File(resource.toURI()).getAbsolutePath());
+ command.addNewDimStorage("dim_table2", new File(resource.toURI()));
result = command.getDimStorages("dim_table2");
assertEquals(DIM_LOCAL, result);
@@ -235,16 +235,17 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
assertTrue(command.getAllPartitionsOfDimtable("dim_table2", DIM_LOCAL, null).trim().isEmpty());
- assertEquals(command.addPartitionToDimtable("dim_table2", DIM_LOCAL, singlePartPath), SUCCESS_MESSAGE);
+ assertEquals(command.addPartitionToDimtable("dim_table2", DIM_LOCAL, new File(singlePartPath)), SUCCESS_MESSAGE);
assertEquals(command.updatePartitionOfDimtable("dim_table2", DIM_LOCAL, new File(singlePartPath)), SUCCESS_MESSAGE);
verifyAndDeletePartitions();
- assertEquals(command.addPartitionsToDimtable("dim_table2", DIM_LOCAL, multiplePartsPath), SUCCESS_MESSAGE);
+ assertEquals(
+ command.addPartitionsToDimtable("dim_table2", DIM_LOCAL, new File(multiplePartsPath)), SUCCESS_MESSAGE);
assertEquals(command.updatePartitionsOfDimtable("dim_table2", DIM_LOCAL, multiplePartsPath), SUCCESS_MESSAGE);
verifyAndDeletePartitions();
// Wrong files:
try {
- command.addPartitionToDimtable("dim_table2", DIM_LOCAL, multiplePartsPath);
+ command.addPartitionToDimtable("dim_table2", DIM_LOCAL, new File(multiplePartsPath));
fail("Should fail");
} catch (Throwable t) {
// pass
@@ -257,7 +258,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
}
try {
- command.addPartitionsToDimtable("dim_table2", DIM_LOCAL, singlePartPath);
+ command.addPartitionsToDimtable("dim_table2", DIM_LOCAL, new File(singlePartPath));
fail("Should fail");
} catch (Throwable t) {
// pass
@@ -291,7 +292,7 @@ public class TestLensDimensionTableCommands extends LensCliApplicationTest {
LensDimensionTableCommands command = getCommand();
URL resource = TestLensFactCommands.class.getClassLoader().getResource(localPartSpec);
try {
- command.addPartitionToDimtable(tableName, storageName, new File(resource.toURI()).getAbsolutePath());
+ command.addPartitionToDimtable(tableName, storageName, new File(resource.toURI()));
} catch (Throwable t) {
log.error("Unable to locate the storage part file for adding new storage to dim table dim_table2", t);
fail("Unable to locate the storage part file for adding new storage to dim table dim_table2");
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
index fa342c8..0cbf7db 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
@@ -68,7 +68,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
URL cubeSpec = TestLensCubeCommands.class.getClassLoader().getResource("sample-cube.xml");
String cubeList = getCubeCommand().showCubes();
assertFalse(cubeList.contains("sample_cube"), cubeList);
- getCubeCommand().createCube(new File(cubeSpec.toURI()).getAbsolutePath());
+ getCubeCommand().createCube(new File(cubeSpec.toURI()));
cubeList = getCubeCommand().showCubes();
assertTrue(cubeList.contains("sample_cube"), cubeList);
}
@@ -109,7 +109,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
TestLensStorageCommands.addLocalStorage(FACT_LOCAL);
URL factSpec = TestLensFactCommands.class.getClassLoader().getResource("fact1.xml");
try {
- command.createFact(new File(factSpec.toURI()).getAbsolutePath());
+ command.createFact(new File(factSpec.toURI()));
} catch (Exception e) {
fail("Unable to create fact table" + e.getMessage());
}
@@ -163,7 +163,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
assertTrue(desc.contains(propString));
- command.updateFactTable("fact1", "/tmp/local-fact1.xml");
+ command.updateFactTable("fact1", new File("/tmp/local-fact1.xml"));
desc = command.describeFactTable("fact1");
log.debug(desc);
assertTrue(desc.contains(propString), "The sample property value is not set");
@@ -205,7 +205,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
String result;
URL resource = TestLensFactCommands.class.getClassLoader().getResource("fact-local-storage-element.xml");
try {
- command.addNewFactStorage("fact1", new File(resource.toURI()).getAbsolutePath());
+ command.addNewFactStorage("fact1", new File(resource.toURI()));
} catch (Throwable t) {
log.error("Unable to locate the storage part file for adding new storage to fact table fact1", t);
fail("Unable to locate the storage part file for adding new storage to fact table fact1");
@@ -230,16 +230,16 @@ public class TestLensFactCommands extends LensCliApplicationTest {
TestLensFactCommands.class.getClassLoader().getResource("fact1-local-part.xml").toURI()).getAbsolutePath();
String multiplePartsPath = new File(
TestLensFactCommands.class.getClassLoader().getResource("fact1-local-parts.xml").toURI()).getAbsolutePath();
- assertEquals(command.addPartitionToFact("fact1", FACT_LOCAL, singlePartPath), SUCCESS_MESSAGE);
+ assertEquals(command.addPartitionToFact("fact1", FACT_LOCAL, new File(singlePartPath)), SUCCESS_MESSAGE);
assertEquals(command.updatePartitionOfFact("fact1", FACT_LOCAL, new File(singlePartPath)), SUCCESS_MESSAGE);
verifyAndDeletePartitions();
- assertEquals(command.addPartitionsToFact("fact1", FACT_LOCAL, multiplePartsPath), SUCCESS_MESSAGE);
+ assertEquals(command.addPartitionsToFact("fact1", FACT_LOCAL, new File(multiplePartsPath)), SUCCESS_MESSAGE);
assertEquals(command.updatePartitionsOfFact("fact1", FACT_LOCAL, multiplePartsPath), SUCCESS_MESSAGE);
verifyAndDeletePartitions();
// Wrong files:
try {
- command.addPartitionToFact("fact1", FACT_LOCAL, multiplePartsPath);
+ command.addPartitionToFact("fact1", FACT_LOCAL, new File(multiplePartsPath));
fail("Should fail");
} catch (Throwable t) {
// pass
@@ -252,7 +252,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
}
try {
- command.addPartitionsToFact("fact1", FACT_LOCAL, singlePartPath);
+ command.addPartitionsToFact("fact1", FACT_LOCAL, new File(singlePartPath));
fail("Should fail");
} catch (Throwable t) {
// pass
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommandsWithMissingWeight.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommandsWithMissingWeight.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommandsWithMissingWeight.java
index 73f3a78..6fe2f09 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommandsWithMissingWeight.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommandsWithMissingWeight.java
@@ -80,7 +80,7 @@ public class TestLensFactCommandsWithMissingWeight extends LensCliApplicationTes
URL cubeSpec = TestLensCubeCommands.class.getClassLoader().getResource(CUBE_XML_FILE);
String cubeList = getCubeCommand().showCubes();
Assert.assertFalse(cubeList.contains(CUBE_NAME));
- getCubeCommand().createCube(new File(cubeSpec.toURI()).getAbsolutePath());
+ getCubeCommand().createCube(new File(cubeSpec.toURI()));
cubeList = getCubeCommand().showCubes();
Assert.assertTrue(cubeList.contains(CUBE_NAME));
}
@@ -122,7 +122,7 @@ public class TestLensFactCommandsWithMissingWeight extends LensCliApplicationTes
TestLensStorageCommands.addLocalStorage(FACT_LOCAL);
URL factSpec = TestLensFactCommandsWithMissingWeight.class.getClassLoader().getResource(FACT_XML_FILE);
String response = null;
- response = command.createFact(new File(factSpec.toURI()).getAbsolutePath());
+ response = command.createFact(new File(factSpec.toURI()));
Assert.assertEquals(response, "failed", "Fact table creation should not be successful.");
Assert.assertEquals(command.showFacts(CUBE_NAME), "No fact found for " + CUBE_NAME,
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
index 319077a..7a437a1 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
@@ -192,7 +192,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest {
*/
private void testExplainQuery(LensQueryCommands qCom) throws Exception {
String sql = "cube select id, name from test_dim";
- String result = qCom.explainQuery(sql, "");
+ String result = qCom.explainQuery(sql, null);
log.debug(result);
assertTrue(result.contains(explainPlan));
@@ -206,7 +206,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest {
*/
private void testExplainFailQuery(LensQueryCommands qCom) throws Exception {
String sql = "cube select id2, name from test_dim";
- String result = qCom.explainQuery(sql, "");
+ String result = qCom.explainQuery(sql, null);
log.debug(result);
assertTrue(result.contains("Explain FAILED:"));
@@ -304,7 +304,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest {
}
private void downloadResult(LensQueryCommands qCom, String qh, String expected) throws IOException {
- assertTrue(qCom.getQueryResults(qh, resDir.getAbsolutePath(), true).contains("Saved"));
+ assertTrue(qCom.getQueryResults(qh, resDir, true).contains("Saved"));
assertEquals(readFile(resDir.getAbsolutePath() + File.separator + qh + ".csv").trim(), expected.trim());
}
@@ -324,7 +324,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest {
log.debug("Starting to test cube commands");
URL cubeSpec = TestLensQueryCommands.class.getClassLoader().getResource("sample-cube.xml");
- command.createCube(new File(cubeSpec.toURI()).getAbsolutePath());
+ command.createCube(new File(cubeSpec.toURI()));
TestLensDimensionCommands.createDimension();
TestLensDimensionTableCommands.addDim1Table("dim_table", "dim_table.xml", "local");
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-cli/src/test/java/org/apache/lens/cli/TestLensStorageCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensStorageCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensStorageCommands.java
index 3a04ec6..1284c99 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensStorageCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensStorageCommands.java
@@ -105,7 +105,7 @@ public class TestLensStorageCommands extends LensCliApplicationTest {
writer.close();
LOG.debug("Using Storage spec from file : " + newFile.getAbsolutePath());
String storageList = command.getStorages();
- command.createStorage(newFile.getAbsolutePath());
+ command.createStorage(newFile);
storageList = command.getStorages();
Assert.assertTrue(storageList.contains(storageName));
} finally {
@@ -152,7 +152,7 @@ public class TestLensStorageCommands extends LensCliApplicationTest {
String propString = "name : storage.url value : file:///";
Assert.assertTrue(desc.contains(propString));
- String updateResult = command.updateStorage(storageName, updateFilePath);
+ String updateResult = command.updateStorage(storageName, new File(updateFilePath));
Assert.assertTrue(updateResult.contains("succeeded"));
desc = command.describeStorage(storageName);
LOG.debug(desc);
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-client/src/main/java/org/apache/lens/client/LensClient.java
----------------------------------------------------------------------
diff --git a/lens-client/src/main/java/org/apache/lens/client/LensClient.java b/lens-client/src/main/java/org/apache/lens/client/LensClient.java
index 57c672c..cd34642 100644
--- a/lens-client/src/main/java/org/apache/lens/client/LensClient.java
+++ b/lens-client/src/main/java/org/apache/lens/client/LensClient.java
@@ -28,6 +28,7 @@ import org.apache.lens.api.APIResult;
import org.apache.lens.api.metastore.*;
import org.apache.lens.api.query.*;
import org.apache.lens.api.result.LensAPIResult;
+import org.apache.lens.api.util.PathValidator;
import org.apache.lens.client.exceptions.LensAPIException;
import org.apache.lens.client.exceptions.LensBriefErrorException;
import org.apache.lens.client.model.BriefError;
@@ -37,6 +38,7 @@ import org.apache.lens.client.model.IdBriefErrorTemplateKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import lombok.Getter;
@@ -57,6 +59,9 @@ public class LensClient {
Maps.newHashMap();
private final LensStatement statement;
+ @Getter
+ private PathValidator pathValidator;
+
public static Logger getCliLooger() {
return LoggerFactory.getLogger(CLILOGGER);
}
@@ -225,12 +230,13 @@ public class LensClient {
return new LensStatement(connection).getAllQueries(state, queryName, user, fromDate, toDate);
}
-
private void connectToLensServer() {
log.debug("Connecting to lens server {}", new LensConnectionParams(conf));
connection = new LensConnection(new LensConnectionParams(conf));
connection.open(password);
log.debug("Successfully connected to server {}", connection);
+ pathValidator = new PathValidator(connection.getLensConnectionParams().getSessionConf());
+ Preconditions.checkNotNull(pathValidator, "Error in initializing Path Validator.");
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java b/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java
index 1487c5a..0821fe7 100644
--- a/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java
+++ b/lens-server/src/main/java/org/apache/lens/server/BaseLensService.java
@@ -19,6 +19,7 @@
package org.apache.lens.server;
import java.io.Externalizable;
+import java.io.File;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -33,6 +34,7 @@ import javax.ws.rs.NotFoundException;
import org.apache.lens.api.LensConf;
import org.apache.lens.api.LensSessionHandle;
+import org.apache.lens.api.util.PathValidator;
import org.apache.lens.server.api.LensConfConstants;
import org.apache.lens.server.api.LensService;
import org.apache.lens.server.api.error.LensException;
@@ -73,6 +75,9 @@ public abstract class BaseLensService extends CompositeService implements Extern
/** The stopped. */
protected boolean stopped = false;
+ /** Utility to validate and get valid paths for input paths **/
+ private PathValidator pathValidator;
+
// Static session map which is used by query submission thread to get the
// lens session before submitting a query to hive server
/** The session map. */
@@ -430,4 +435,33 @@ public abstract class BaseLensService extends CompositeService implements Extern
*/
public abstract HealthStatus getHealthStatus();
+ /**
+ * Method that uses PathValidator to get appropriate path.
+ *
+ * @param path
+ * @param shouldBeDirectory
+ * @param shouldExist
+ * @return
+ */
+ public String getValidPath(File path, boolean shouldBeDirectory, boolean shouldExist) {
+ if (pathValidator == null) {
+ LensConf conf = new LensConf();
+ pathValidator = new PathValidator(conf);
+ }
+ return pathValidator.getValidPath(path, shouldBeDirectory, shouldExist);
+ }
+
+ /**
+ * Method to remove unrequired prefix from path.
+ *
+ * @param path
+ * @return
+ */
+ public String removePrefixBeforeURI(String path) {
+ if (pathValidator == null) {
+ LensConf conf = new LensConf();
+ pathValidator = new PathValidator(conf);
+ }
+ return pathValidator.removePrefixBeforeURI(path);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
index 49fab8a..2983db4 100644
--- a/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
+++ b/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
@@ -2739,9 +2739,8 @@ public class QueryExecutionServiceImpl extends BaseLensService implements QueryE
String uri = res.getLocation();
// Hive doesn't and URIs starting with file:/ correctly, so we have to change it to file:///
// See: org.apache.hadoop.hive.ql.exec.Utilities.addToClassPath
- if (uri.startsWith("file:") && !uri.startsWith("file://")) {
- uri = "file://" + uri.substring("file:".length());
- }
+ uri = removePrefixBeforeURI(uri);
+
String command = "add " + res.getType().toLowerCase() + " " + uri;
driver.execute(createResourceQuery(command, sessionHandle, driver));
log.info("Added resource to hive driver for session {} cmd: {}", sessionIdentifier, command);
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
index 4143525..50b3da8 100644
--- a/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
+++ b/lens-server/src/main/java/org/apache/lens/server/util/ScannedPaths.java
@@ -75,6 +75,7 @@ public class ScannedPaths implements Iterable<String> {
fs = FileSystem.get(new URI(path), new Configuration());
Path pt = new Path(new URI(path));
+
if (fs.exists(pt) && fs.isFile(pt)) {
/**
* CASE 1 : Direct FILE provided in path
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/e35b1065/src/site/apt/user/cli.apt
----------------------------------------------------------------------
diff --git a/src/site/apt/user/cli.apt b/src/site/apt/user/cli.apt
index 5dd0bfb..6273d89 100644
--- a/src/site/apt/user/cli.apt
+++ b/src/site/apt/user/cli.apt
@@ -92,7 +92,7 @@ User CLI Commands
*--+--+
|close/bye|Releases all resources of the server session and exits the shell|
*--+--+
-|debug [[--enable] To print all logs on cli for debugging purpose]|prints all class level logs and verbose logs on cli for debugging purpose. 'debug false' to turn off all class level logging and verbose level logging |
+|debug [[--enable] ]|prints all class level logs and verbose logs on cli for debugging purpose. 'debug false' to turn off all class level logging and verbose level logging |
*--+--+
|get [--key] \<key\>|Fetches and prints session parameter specified with name <<<key>>> from lens server|
*--+--+
@@ -108,7 +108,7 @@ User CLI Commands
*--+--+
|show params|Fetches and prints all session parameter from lens server|
*--+--+
-|verbose [[--enable] Print the clilogger logs on cli]|Show cliLogger logs on cli. 'verbose false' turns off the cliLogger logs on console|
+|verbose [[--enable] ]|Show cliLogger logs on cli. 'verbose false' turns off the cliLogger logs on console|
*--+--+
<<Lens Connection Commands>>