[Swift-commit] r6673 - in trunk/src/org/griphyn/vdl: karajan/lib karajan/lib/swiftscript mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Sun Jul 28 23:35:49 CDT 2013
Author: hategan
Date: 2013-07-28 23:35:49 -0500 (Sun, 28 Jul 2013)
New Revision: 6673
Modified:
trunk/src/org/griphyn/vdl/karajan/lib/AppStageins.java
trunk/src/org/griphyn/vdl/karajan/lib/AppStageouts.java
trunk/src/org/griphyn/vdl/karajan/lib/FileCopier.java
trunk/src/org/griphyn/vdl/karajan/lib/InFileDirs.java
trunk/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java
trunk/src/org/griphyn/vdl/karajan/lib/PathUtils.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
trunk/src/org/griphyn/vdl/mapping/AbsFile.java
Log:
removed the use of java.net.(URI|URL) for parsing and use a custom based thing in cog since there are problems with URIs and spaces and URLs and path-only strings
Modified: trunk/src/org/griphyn/vdl/karajan/lib/AppStageins.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/AppStageins.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/AppStageins.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -79,8 +79,8 @@
if (protocol.equals("file")) {
protocol = stagingMethod;
}
- String path = file.getDir().equals("") ?
- file.getName() : file.getDir() + "/" + file.getName();
+ String path = file.getDirectory() == null ?
+ file.getName() : file.getDirectory() + "/" + file.getName();
String relpath = path.startsWith("/") ? path.substring(1) : path;
if (logger.isDebugEnabled()) {
logger.debug("will stage in: " + relpath + " via: " + protocol);
Modified: trunk/src/org/griphyn/vdl/karajan/lib/AppStageouts.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/AppStageouts.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/AppStageouts.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -73,7 +73,7 @@
if (protocol.equals("file")) {
protocol = stagingMethod;
}
- String path = file.getDir().equals("") ? file.getName() : file.getDir()
+ String path = file.getDirectory() == null ? file.getName() : file.getDirectory()
+ "/" + file.getName();
String relpath = path.startsWith("/") ? path.substring(1) : path;
cr_stageout.append(stack,
Modified: trunk/src/org/griphyn/vdl/karajan/lib/FileCopier.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/FileCopier.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/FileCopier.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -50,9 +50,9 @@
AbsFile fsrc = (AbsFile) src;
AbsFile fdst = (AbsFile) dst;
FileTransferSpecification fts = new FileTransferSpecificationImpl();
- fts.setDestinationDirectory(fdst.getDir());
+ fts.setDestinationDirectory(fdst.getDirectory());
fts.setDestinationFile(fdst.getName());
- fts.setSourceDirectory(fsrc.getDir());
+ fts.setSourceDirectory(fsrc.getDirectory());
fts.setSourceFile(fsrc.getName());
fts.setThirdPartyIfPossible(true);
task = new FileTransferTask();
Modified: trunk/src/org/griphyn/vdl/karajan/lib/InFileDirs.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/InFileDirs.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/InFileDirs.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -50,14 +50,16 @@
Channel<Object> ret = cr_vargs.get(stack);
for (String path : files) {
AbsFile af = new AbsFile(path);
- String dir = af.getDir();
- if ("file".equals(af.getProtocol())) {
- ret.add(PathUtils.remotePathName(dir));
+ String dir = af.getDirectory();
+ if (dir != null) {
+ if ("file".equals(af.getProtocol())) {
+ ret.add(PathUtils.remotePathName(dir));
+ }
+ else {
+ // also prepend host name to the path
+ ret.add(af.getHost() + "/" + PathUtils.remotePathName(dir));
+ }
}
- else {
- // also prepend host name to the path
- ret.add(af.getHost() + "/" + PathUtils.remotePathName(dir));
- }
}
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/OutFileDirs.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -22,6 +22,7 @@
import java.util.List;
+import k.rt.Channel;
import k.rt.ExecutionException;
import k.rt.Stack;
@@ -46,6 +47,7 @@
@Override
public Object function(Stack stack) {
List<List<Object>> files = stageouts.getValue(stack);
+ Channel<Object> ret = cr_vargs.get(stack);
try {
for (List<Object> pv : files) {
Path p = parsePath(pv.get(0));
@@ -53,18 +55,15 @@
DSHandle leaf = handle.getField(p);
String fname = SwiftFunction.filename(leaf)[0];
AbsFile af = new AbsFile(fname);
- if ("file".equals(af.getProtocol())) {
- String dir = af.getDir();
- if (dir.startsWith("/") && dir.length() != 1) {
- cr_vargs.append(stack, dir.substring(1));
+ String dir = af.getDirectory();
+ if (dir != null) {
+ if ("file".equals(af.getProtocol())) {
+ ret.add(PathUtils.remotePathName(dir));
}
- else if (dir.length() != 0) {
- cr_vargs.append(stack, dir);
+ else {
+ ret.add(af.getHost() + "/" + PathUtils.remotePathName(dir));
}
}
- else {
- cr_vargs.append(stack, af.getHost() + "/" + af.getDir());
- }
}
}
catch (Exception e) {
Modified: trunk/src/org/griphyn/vdl/karajan/lib/PathUtils.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/PathUtils.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/PathUtils.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -40,7 +40,7 @@
@Override
public Object function(Stack stack) {
- return new AbsFile(path.getValue(stack)).getDir();
+ return new AbsFile(path.getValue(stack)).getDirectory();
}
}
@@ -54,8 +54,13 @@
@Override
public Object function(Stack stack) {
- String dir = new AbsFile(path.getValue(stack)).getDir();
- return remotePathName(dir);
+ String dir = new AbsFile(path.getValue(stack)).getDirectory();
+ if (dir != null) {
+ return remotePathName(dir);
+ }
+ else {
+ return null;
+ }
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -584,8 +584,8 @@
AbstractDataNode dn = file.getValue(stack);
String name = SwiftFunction.filename(dn)[0];
- String result = new AbsFile(name).getDir();
- DSHandle handle = new RootDataNode(Types.BOOLEAN, result);
+ String result = new AbsFile(name).getDirectory();
+ DSHandle handle = new RootDataNode(Types.STRING, result);
if (PROVENANCE_ENABLED) {
int provid = SwiftFunction.nextProvenanceID();
Modified: trunk/src/org/griphyn/vdl/mapping/AbsFile.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbsFile.java 2013-07-27 18:18:11 UTC (rev 6672)
+++ trunk/src/org/griphyn/vdl/mapping/AbsFile.java 2013-07-29 04:35:49 UTC (rev 6673)
@@ -31,78 +31,43 @@
import org.globus.cog.abstraction.impl.file.FileResourceCache;
import org.globus.cog.abstraction.interfaces.FileResource;
import org.globus.cog.abstraction.interfaces.GridFile;
+import org.globus.cog.abstraction.interfaces.RemoteFile;
import org.globus.cog.abstraction.interfaces.Service;
-public class AbsFile implements GeneralizedFileFormat {
- private final String protocol;
- private final String host;
- private final String path;
- private String dir, name;
+public class AbsFile extends RemoteFile implements GeneralizedFileFormat {
public AbsFile(String url) {
- int pi = url.indexOf("://");
- if (pi == -1) {
- protocol = "file";
- host = "localhost";
- path = normalize(url);
- }
- else {
- protocol = url.substring(0, pi);
- if (protocol.equals("file")) {
- host = "localhost";
- String rp = url.substring(pi + 3);
- if (rp.startsWith("localhost/")) {
- rp = rp.substring("localhost/".length());
- }
- path = normalize(rp);
- }
- else {
- int si = url.indexOf('/', pi + 3);
- if (si == -1) {
- host = url.substring(pi + 3);
- path = "";
- }
- else {
- host = url.substring(pi + 3, si);
- path = normalize(url.substring(si + 1));
- }
- }
- }
- initDirAndName();
+ super(url);
}
- private String normalize(String path) {
- // there is a slight performance penalty here, but it makes things
- // cleaner
- return path.replace("/./", "/");
+ public AbsFile(String protocol, String host, String path) {
+ super(protocol, host, path);
+ }
+
+ public AbsFile(String protocol, String host, int port, String dir, String name) {
+ super(protocol, host, port, dir, name);
}
- private void initDirAndName() {
- int di = path.lastIndexOf('/');
- if (di == 0) {
- dir = "/";
+ public AbsFile(String protocol, String host, int port, String path) {
+ super(protocol, host, port, path);
+ }
+
+ @Override
+ protected void parse(String str) {
+ super.parse(str);
+ if (getProtocol() == null) {
+ setProtocol("file");
}
- else if (di > 0) {
- dir = path.substring(0, di);
+ if (getHost() == null) {
+ setHost("localhost");
}
- else {
- dir = "";
- }
- name = path.substring(di + 1);
}
- public AbsFile(String protocol, String host, String path) {
- this.protocol = protocol;
- this.host = host;
- this.path = path;
- initDirAndName();
- }
-
- protected FileResource getFileResource() throws IOException {
+ protected FileResource getFileResource() throws IOException {
Service s = new ServiceImpl();
- s.setProvider(protocol);
+ s.setProvider(getProtocol());
s.setType(Service.FILE_OPERATION);
- s.setServiceContact(new ServiceContactImpl(host));
+ s.setServiceContact(new ServiceContactImpl(getHost(), getPort()));
try {
return FileResourceCache.getDefault().getResource(s);
}
@@ -119,7 +84,7 @@
try {
FileResource fr = getFileResource();
try {
- return fr.exists(path);
+ return fr.exists(getPath());
}
finally {
releaseResource(fr);
@@ -137,10 +102,16 @@
try {
FileResource fr = getFileResource();
try {
+ String protocol = getProtocol();
+ String host = getHost();
+ int port = getPort();
+ String dir = getPath();
List<AbsFile> l = new ArrayList<AbsFile>();
- for (GridFile gf : fr.list(path)) {
- AbsFile f = new AbsFile(protocol, host, gf.getAbsolutePathName());
- if (gf.isDirectory() && (filter == null || filter.accept(new File(f.getDir()), f.getName()))) {
+ for (GridFile gf : fr.list(dir)) {
+ AbsFile f = new AbsFile(protocol, host, port, dir, gf.getName());
+ // f.getDirectory() cannot be null since dir cannot be null since getPath() returns
+ // a non-null string
+ if (gf.isDirectory() && (filter == null || filter.accept(new File(f.getDirectory()), f.getName()))) {
l.add(f);
}
}
@@ -160,10 +131,14 @@
try {
FileResource fr = getFileResource();
try {
+ String protocol = getProtocol();
+ String host = getHost();
+ int port = getPort();
+ String dir = getPath();
List<AbsFile> l = new ArrayList<AbsFile>();
- for (GridFile gf : fr.list(path)) {
- AbsFile f = new AbsFile(protocol, host, gf.getAbsolutePathName());
- if (filter == null || filter.accept(new File(f.getDir()), f.getName())) {
+ for (GridFile gf : fr.list(dir)) {
+ AbsFile f = new AbsFile(protocol, host, port, dir, gf.getName());
+ if (filter == null || filter.accept(new File(f.getDirectory()), f.getName())) {
l.add(f);
}
}
@@ -179,64 +154,16 @@
}
}
- public String getName() {
- return name;
- }
-
- public String getDir() {
- return dir;
- }
-
- public String getProtocol() {
- return protocol;
- }
-
- public String getHost() {
- return host;
- }
-
- public String getPath() {
- return path;
- }
-
- public boolean isAbsolute() {
- return !path.isEmpty() && path.startsWith("/");
- }
-
public String getType() {
return "file";
}
- public String getURIAsString() {
- return protocol + "://" + host + '/' + path;
- }
-
- public String toString() {
- return getURIAsString();
- }
-
public void clean() {
try {
- getFileResource().deleteFile(path);
+ getFileResource().deleteFile(getPath());
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof AbsFile) {
- AbsFile a = (AbsFile) obj;
- return protocol.equals(a.protocol) && host.equals(a.host) && path.equals(a.path);
- }
- else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- return protocol.hashCode() + host.hashCode() + path.hashCode();
- }
}
More information about the Swift-commit
mailing list