-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,312 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,104 changes: 1,104 additions & 0 deletions
1,104
src/main/java/com/streever/hadoop/HadoopSession.java
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/main/java/com/streever/hadoop/hdfs/shell/command/ContextSide.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.streever.hadoop.hdfs.shell.command; | ||
|
||
public enum ContextSide { | ||
LEFT,RIGHT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/com/streever/hadoop/hdfs/shell/command/PathBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.streever.hadoop.hdfs.shell.command; | ||
|
||
import com.streever.tools.stemshell.Environment; | ||
import org.apache.hadoop.fs.FileSystem; | ||
|
||
public class PathBuilder { | ||
|
||
private Environment env; | ||
private PathDirectives directives; | ||
|
||
public PathBuilder(Environment env, PathDirectives directives) { | ||
this.env = env; | ||
this.directives = directives; | ||
} | ||
|
||
public String buildPath(Side side, String[] args) { | ||
String rtn = null; | ||
|
||
FileSystem localfs = (FileSystem)env.getValue(Constants.LOCAL_FS); | ||
FileSystem hdfs = (FileSystem) env.getValue(Constants.HDFS); | ||
|
||
String in = null; | ||
|
||
switch (side) { | ||
case LEFT: | ||
if (args.length > 0) | ||
if (directives.isBefore()) { | ||
in = args[directives.getDirectives()]; | ||
} else { | ||
if (directives.isOptional()) { | ||
if (args.length > directives.getDirectives()) { | ||
in = args[args.length-(directives.getDirectives()+1)]; | ||
} else { | ||
// in is null | ||
} | ||
} else { | ||
in = args[args.length-(directives.getDirectives()+1)]; | ||
} | ||
} | ||
switch (directives.getDirection()) { | ||
case REMOTE_LOCAL: | ||
case REMOTE_REMOTE: | ||
case NONE: | ||
rtn = resolveFullPath(hdfs.getWorkingDirectory().toString().substring(((String)env.getProperties().getProperty(Constants.HDFS_URL)).length()), in); | ||
break; | ||
case LOCAL_REMOTE: | ||
rtn = resolveFullPath(localfs.getWorkingDirectory().toString().substring(5), in); | ||
break; | ||
} | ||
break; | ||
case RIGHT: | ||
if (args.length > 1) | ||
if (directives.isBefore()) | ||
in = args[directives.getDirectives() + 1]; | ||
else | ||
in = args[args.length-(directives.getDirectives()+1)]; | ||
switch (directives.getDirection()) { | ||
case REMOTE_LOCAL: | ||
rtn = resolveFullPath(localfs.getWorkingDirectory().toString().substring(5), in); | ||
break; | ||
case LOCAL_REMOTE: | ||
case REMOTE_REMOTE: | ||
rtn = resolveFullPath(hdfs.getWorkingDirectory().toString().substring(((String)env.getProperties().getProperty(Constants.HDFS_URL)).length()), in); | ||
break; | ||
case NONE: | ||
break; | ||
} | ||
break; | ||
} | ||
// if (rtn != null && rtn.contains(" ")) { | ||
// rtn = "\"" + rtn + "\""; | ||
// } | ||
return rtn; | ||
} | ||
|
||
public static String resolveFullPath(String current, String input) { | ||
String adjusted = null; | ||
boolean enclose = false; | ||
if (input != null) { | ||
if (input.startsWith("\"") & input.endsWith("\"")) { | ||
adjusted = input.substring(1, input.length()-1); | ||
} else { | ||
adjusted = input; | ||
} | ||
if (!adjusted.startsWith("/")) | ||
adjusted = current + "/" + adjusted; | ||
} else { | ||
adjusted = current; | ||
// return current; | ||
} | ||
// if (adjusted.contains(" ")) { | ||
// adjusted = "\\\"" + adjusted + "\\\""; | ||
// } | ||
return adjusted; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/streever/hadoop/hdfs/shell/command/PathDirectives.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.streever.hadoop.hdfs.shell.command; | ||
|
||
public class PathDirectives { | ||
private Direction direction = null; | ||
|
||
private int directives = 0; //default | ||
private boolean before = true; //default | ||
private boolean optional = false; //default | ||
|
||
public Direction getDirection() { | ||
return direction; | ||
} | ||
|
||
public int getDirectives() { | ||
return directives; | ||
} | ||
|
||
public boolean isBefore() { | ||
return before; | ||
} | ||
|
||
public boolean isOptional() { | ||
return optional; | ||
} | ||
|
||
public PathDirectives(Direction direction, int directives, boolean before, boolean optional) { | ||
this.direction = direction; | ||
this.directives = directives; | ||
this.before = before; | ||
this.optional = optional; | ||
} | ||
|
||
public PathDirectives(Direction direction, int directives, boolean before) { | ||
this.direction = direction; | ||
this.directives = directives; | ||
this.before = before; | ||
} | ||
|
||
public PathDirectives(Direction direction, int directives) { | ||
this.direction = direction; | ||
this.directives = directives; | ||
} | ||
|
||
public PathDirectives(Direction direction) { | ||
this.direction = direction; | ||
} | ||
|
||
} |
Oops, something went wrong.