-
Notifications
You must be signed in to change notification settings - Fork 16
Irsa 729 add ws commands #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,8 +179,14 @@ public class ServerParams { | |
public static final String LOGOUT = "CmdLogout"; | ||
|
||
//Workspaces | ||
public static final String WS_LIST = "wsList"; | ||
public static final String WS_GET_FILE = "wsGet"; | ||
public static final String WS_PUT_FILE = "wsPut"; | ||
public static final String WS_LIST = "wsList"; // Gets the list of content/files | ||
public static final String WS_GET_FILE = "wsGet"; // TODO | ||
public static final String WS_UPLOAD_FILE = "wsUpload";// to get the path of the file uploaded into firefly server from WS | ||
public static final String WS_PUT_IMAGE_FILE = "wsPut"; //FITS, PNG, comes from edu.caltech.ipac.firefly.server.servlets.AnyFileDownload | ||
public static final String WS_PUT_TABLE_FILE = "wsPutTable"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need to distinguish image from table? Why not have WS_PUT_FILE and allow for additional params. I am sure there are other types beside image and table. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, a file should be a file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i feel that will be in the context where we use the WS manager that piece can be moved later to the right place, keeping it like this for now. |
||
public static final String WS_DELETE_FILE = "wsDel"; | ||
public static final String WS_MOVE_FILE = "wsMove"; | ||
public static final String WS_GET_METADATA = "wsGetMeta"; | ||
public static final String WS_CREATE_FOLDER = "wsParent"; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,7 +269,7 @@ public WsResponse davGet(File outfile, String fromPath) throws IOException { | |
try { | ||
if (!executeMethod(get, false)) { | ||
// handle error | ||
LOG.error("Unable to download file:" + fromPath + " -- " + get.getStatusText()); | ||
LOG.error("Unable to download file:" + fromPath + " , url " +url+" -- "+ get.getStatusText()); | ||
return WsUtil.error(get.getStatusCode(), get.getStatusText()); | ||
} | ||
if (get.getResponseContentLength() > 0) { | ||
|
@@ -374,7 +374,7 @@ public WsResponse delete(String uri) throws WsException { | |
try { | ||
if (!executeMethod(rm, true)) { | ||
// handle error | ||
LOG.error("Unable to delete file:" + uri + " -- " + rm.getStatusText()); | ||
LOG.error("Unable to delete file uri:" + uri + " -- " + rm.getStatusText()); | ||
return WsUtil.error(rm); | ||
} | ||
} catch (Exception e) { | ||
|
@@ -407,6 +407,25 @@ public WsResponse createParent(String newRelPath) throws WsException { | |
return WsUtil.success(200, "Created", getResourceUrl(newRelPath)); | ||
} | ||
|
||
public WsResponse moveFile(String originalFileRelPath, String newPath, boolean overwrite) throws WsException { | ||
WspaceMeta meta = new WspaceMeta(newPath); | ||
String parent = meta.getParentPath(); | ||
|
||
//WARNING: WEBDAv forces me to create new parent first! UGLY! | ||
createParent(parent); | ||
|
||
String newUrl = getResourceUrl(newPath); | ||
|
||
// This doesn't create parent , you must create the parent folder in order to move it | ||
MoveMethod move = new MoveMethod(getResourceUrl(originalFileRelPath), newUrl, overwrite); | ||
if (!executeMethod(move)) { | ||
// handle error | ||
LOG.error("Unable to move:" + originalFileRelPath + " based on url -- " +newUrl+" -- "+ move.getStatusText()); | ||
return WsUtil.error(move.getStatusCode(), move.getStatusLine().getReasonPhrase()); | ||
} | ||
return WsUtil.success(move.getStatusCode(), move.getStatusText(), newUrl); | ||
} | ||
|
||
@Override | ||
public WsResponse renameFile(String originalFileRelPath, String newfileName, boolean overwrite) throws WsException { | ||
WspaceMeta meta = new WspaceMeta(originalFileRelPath); | ||
|
@@ -417,7 +436,7 @@ public WsResponse renameFile(String originalFileRelPath, String newfileName, boo | |
MoveMethod move = new MoveMethod(getResourceUrl(originalFileRelPath), newUrl, overwrite); | ||
if (!executeMethod(move)) { | ||
// handle error | ||
LOG.error("Unable to move:" + originalFileRelPath + " -- " + move.getStatusText()); | ||
LOG.error("Unable to move:" + originalFileRelPath + " based on url -- " +newUrl+" -- "+ move.getStatusText()); | ||
return WsUtil.error(move.getStatusCode(), move.getStatusLine().getReasonPhrase()); | ||
} | ||
return WsUtil.success(move.getStatusCode(), move.getStatusText(), newUrl); | ||
|
@@ -427,34 +446,6 @@ public WspaceMeta getMeta(String relPath) { | |
return getMeta(relPath, WspaceMeta.Includes.ALL); | ||
} | ||
|
||
public WsResponse search(String relPath) throws IOException { | ||
String query = "" + | ||
" " + | ||
" SELECT *" + | ||
" " + | ||
""; | ||
query = "//element(*,rep:root)"; | ||
|
||
OptionsMethod options = new OptionsMethod(getResourceUrl(relPath)); | ||
executeMethod(options); | ||
String okMethod = "SEARCH"; | ||
if (!options.isAllowed(okMethod)) { | ||
String s = ""; | ||
String[] allowedMethods = options.getAllowedMethods(); | ||
for (String method : allowedMethods) { | ||
s += method + "\n"; | ||
} | ||
return WsUtil.error(options.getStatusCode(), options.getStatusText(), okMethod + " is not allowed - only:\n" + s); | ||
} | ||
SearchMethod m = new SearchMethod(getResourceUrl(relPath), query, "xpath"); | ||
if (!executeMethod(m)) { | ||
// handle error | ||
LOG.error("Unable to move:" + relPath + " -- " + m.getStatusText()); | ||
return WsUtil.error(m.getStatusCode(), m.getStatusLine().getReasonPhrase()); | ||
} | ||
return WsUtil.success(m.getStatusCode(), m.getStatusText(), relPath); | ||
} | ||
|
||
public WspaceMeta getMeta(String relPath, WspaceMeta.Includes includes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to get a set of props for all the files. i.e. owner? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, getMeta("/", ALL). See unit test or I can explain later when we meet again. |
||
|
||
// this can be optimized by retrieving only the props we care for. | ||
|
@@ -594,7 +585,9 @@ private WspaceMeta convertToWspaceMeta(WspaceMeta meta, MultiStatusResponse res) | |
if (name.equals(DavConstants.PROPERTY_GETLASTMODIFIED)) { | ||
meta.setLastModified(v); | ||
} else if (name.equals(DavConstants.PROPERTY_GETCONTENTLENGTH)) { | ||
meta.setSize(Long.parseLong(v)); | ||
long size = Long.parseLong(v); | ||
meta.setSize(size); | ||
meta.setIsFile(true); // WEBDAV/IRSA only set cvontent length for files. (?)TODO: is it WEBDav general behaviour? | ||
} else if (name.equals(DavConstants.PROPERTY_GETCONTENTTYPE)) { | ||
meta.setContentType(v); | ||
} else if (p.getName().getNamespace().equals(IRSA_NS)) { | ||
|
@@ -635,45 +628,45 @@ private boolean executeMethod(DavMethod method, boolean releaseConnection) { | |
|
||
} | ||
|
||
// public static void main(String[] args) { | ||
// WebDAVWorkspaceManager man = null; | ||
//// man = (WebDAVWorkspaceManager) ServerContext.getRequestOwner().getWsManager(); | ||
// | ||
// man = new WebDAVWorkspaceManager("ejoliet-tmp2"); | ||
// | ||
public static void main(String[] args) { | ||
WebDAVWorkspaceManager man = null; | ||
// man = (WebDAVWorkspaceManager) ServerContext.getRequestOwner().getWsManager(); | ||
|
||
man = new WebDAVWorkspaceManager("ejoliet-tmp2"); | ||
|
||
simpleTest(man); | ||
|
||
// AppProperties.setProperty("sso.server.url", "http://irsa.ipac.caltech.edu/account/"); | ||
// String session = JOSSOAdapter.createSession("", ""); | ||
// Map<String, String> cookies = new HashMap<String, String>(); | ||
// cookies.put(WebAuthModule.AUTH_KEY, session); | ||
// WorkspaceManager man = new WorkspaceManager("<someuser>@ipac.caltech.edu", cookies); | ||
// simpleTest(man); | ||
// | ||
//// AppProperties.setProperty("sso.server.url", "http://irsa.ipac.caltech.edu/account/"); | ||
//// String session = JOSSOAdapter.createSession("", ""); | ||
//// Map<String, String> cookies = new HashMap<String, String>(); | ||
//// cookies.put(WebAuthModule.AUTH_KEY, session); | ||
//// WorkspaceManager man = new WorkspaceManager("<someuser>@ipac.caltech.edu", cookies); | ||
//// simpleTest(man); | ||
// } | ||
// | ||
// private static void simpleTest(WebDAVWorkspaceManager man) { | ||
// String relPath = "124/"; | ||
// File f = man.davMakeDir(relPath); | ||
// System.out.println("new directory: " + String.valueOf(f)); | ||
// | ||
// WspaceMeta m = new WspaceMeta(null, relPath); | ||
// m.setProperty("test1", "an awesome idea"); | ||
// m.setProperty("test", null); | ||
// man.setMeta(m); | ||
// | ||
// String ufilePath = relPath + "gaia-binary.vot"; | ||
// WsResponse wsResponse = man.davPut(new File("/Users/ejoliet/devspace/branch/dev/firefly_test_data/edu/caltech/ipac/firefly/ws/gaia-binary.vot"), ufilePath, null); | ||
// | ||
// System.out.println(wsResponse); | ||
// | ||
// WspaceMeta meta = new WspaceMeta(null, ufilePath); | ||
// meta.setProperty("added_by", man.userHome); | ||
// man.setMeta(meta); | ||
// man.setMeta(ufilePath, "added_by", man.userHome); | ||
// | ||
// WspaceMeta meta2 = man.getMeta("/", WspaceMeta.Includes.ALL_PROPS); | ||
// System.out.println(meta2.getNodesAsString()); | ||
// } | ||
} | ||
|
||
private static void simpleTest(WebDAVWorkspaceManager man) { | ||
String relPath = "124/"; | ||
File f = man.davMakeDir(relPath); | ||
System.out.println("new directory: " + String.valueOf(f)); | ||
|
||
WspaceMeta m = new WspaceMeta(null, relPath); | ||
m.setProperty("test1", "an awesome idea"); | ||
m.setProperty("test", null); | ||
man.setMeta(m); | ||
|
||
String ufilePath = relPath + "gaia-binary.vot"; | ||
WsResponse wsResponse = man.davPut(new File("/Users/ejoliet/devspace/branch/dev/firefly_test_data/edu/caltech/ipac/firefly/ws/gaia-binary.vot"), ufilePath, null); | ||
|
||
System.out.println(wsResponse); | ||
|
||
WspaceMeta meta = new WspaceMeta(null, ufilePath); | ||
meta.setProperty("added_by", man.userHome); | ||
man.setMeta(meta); | ||
man.setMeta(ufilePath, "added_by", man.userHome); | ||
|
||
WspaceMeta meta2 = man.getMeta("/", WspaceMeta.Includes.ALL_PROPS); | ||
System.out.println(meta2.getNodesAsString()); | ||
} | ||
|
||
|
||
class WebDAVGetMethod extends DavMethodBase { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
*/ | ||
public class WebDAVWorkspaceHandler implements WorkspaceHandler { | ||
|
||
String managerClass = AppProperties.getProperty("workspace.protocol.irsa.webdav", "edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager"); | ||
|
||
|
||
/** | ||
* map userKey and ws, | ||
|
@@ -31,10 +31,13 @@ public WorkspaceManager withCredentials(WsCredentials cred) { | |
|
||
synchronized (cred) { | ||
String id = cred.getWsId(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cred did not override equals. I doubt if this synchronized does anything. Plus, I don't think a wsPool is necessary. The manager is meant as a way to encapsulate logic. It's should be fine for single use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it will work as expected either. However, I would like to know what you are trying to accomplish. What will happen it is is not synchronized? If it is necessary there might be another way to do it. |
||
String protocol = AppProperties.getProperty("workspace.protocol", "webdav"); | ||
String managerClass = AppProperties.getProperty("workspace.protocol."+protocol.toLowerCase(), "edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager"); | ||
|
||
if (wsPool.containsKey(id)) { | ||
//TODO The problem is how do i know that the cookkie/session is authtenticated at this point? | ||
/*if (wsPool.containsKey(id)) { | ||
return wsPool.get(id); | ||
} | ||
}*/ | ||
WorkspaceManager ws = null;//new WebDAVWorkspaceManager(cred.getWsId(), cred.getCookies()); | ||
try { | ||
Class clazz = Class.forName(managerClass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like using reflection here. This should be very flexible. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed. We already have an 'upload' command that will handle url and multipart. We can add from workspace in there as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to decide what what workspace upload even means. I would prefer for out stuff treat workspace file the same way we treat URLs. Not so much with URLDownload but as a file that is retrieved when it is used instread requiring the user to wait while a file is transferred from one server to another. it could come in as
workspace://a/b/c.tbl
then we have the workspace layer know how to deal with that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the request is sent to CmdSrv by using command ServerParams.UPLOAD, current request parameter has either file: or URL: , we may add workspace: for workspace upload.