-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: createFile handler * fix: Use byte primitive * chore: Remove RMI demo from App.java * chore: apply clang-format * feat: Abstract rmi connection * chore: Update rmi lib * chore: Utils package * feat: Auth abstraction * feat: Authenticate jwt on upload file * feat: Get user's UUID * feat: Get file mimetype from bytes * fix: Make metadata & auth services use a single postgres instance * feat: Pre declare userUUID * fix: Get userUUID from token * docs: Update env vars default values * feat(upload-file): save metadata * fix: ManagerRMI interface import * chore: Remove debug msgs * refactor: Switch SOAP data types sufix to prefix * chore: Remove debug msgs * chore: Update RMI submodule * refactor: Redesign request / response types * fix: Adapt current service implementation with new interface design * docs: Add open api specification * docs: Add API definition to README.md * docs: Improve CLI.md examples * refactor: Redesign request / response types * chore: Update python sample client * chore: Update submodule * chore: update submodule * fix: Typo in request type * feat(upload-file): Add file size limits * chore: Use error instead of success * fix: Simplify http requests * refactor: External services: Managers to Services * refactor: Separate SOAP request handlers as controllers * chore: Add http codes to auth method * feat: Add http codes to Metadata save file * feat: Better http code handling * feat: Add ResStatus generic downcast support * feat: Validate field types * feat: Adapt getUserUUID method to a ResStatus response * test: Test util to tweak configurations * fix: controller exit codes * test: Authorization service abstraction * test: FileIO upload-file * docs: Update README & API spec * test: show realtime std, err on tests execution * feat: update python client demo * chore: Update docker compose with worker service & adminer * docs: Update default MetadataURI env var * chore: Use worker release image * ci: Fix workflows: testing, coverage * fix: Do not assume api sufix * fix: Exclude tests on Dockerfile build * chore: Update RMI types to use UUID * feat(ServiceMetadata): canRead wrapper added * feat(ServiceMetadata): getFileMetadata wrapper added * chore: update fileDownload res/req types * feat: fileDownload service implementation * chore: Add RMI Streaming library * feat(fileDownload): Add 404 code case * fix: Login return code * test: Add new ASCII generator * test: Update uploadFile test to save relevant data for other tests * test: Add fileDownload tests * chore: Remove debug messages & unclutter test output * fix: Add workaround issue Metadata#74 * chore: increase buffer size for data streaming * chore: update submodule * feat: Update demo python SOAP client * fix: Nullable extension result * fix: Give time for file to finish uploading before next test * ci: run test workflows on PRs against main * chore: Improve cli client (#55) * refactor: Make cli client reusable --------- Co-authored-by: woynert <[email protected]> --------- Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>
- Loading branch information
1 parent
a14b096
commit 0d2eaa1
Showing
23 changed files
with
497 additions
and
75 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
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
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 |
---|---|---|
|
@@ -16,6 +16,10 @@ node_modules | |
|
||
# python envs | ||
pyenv | ||
venv | ||
|
||
# python cache | ||
**/__pycache__ | ||
|
||
# JDTLS | ||
bin | ||
|
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
80 changes: 80 additions & 0 deletions
80
app/src/main/java/gateway/controller/CtrlFileDownload.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,80 @@ | ||
package gateway.controller; | ||
|
||
import capyfile.rmi.IWorkerService; | ||
import gateway.services.ServiceAuth; | ||
import gateway.services.ServiceMetadata; | ||
import gateway.services.ServiceWorker; | ||
import gateway.services.UtilValidator; | ||
import gateway.soap.request.ReqFile; | ||
import gateway.soap.response.ResFileDownload; | ||
import gateway.soap.response.ResStatus; | ||
import java.io.FileNotFoundException; | ||
import java.util.UUID; | ||
|
||
public class CtrlFileDownload | ||
{ | ||
public static ResFileDownload file_download (ReqFile args) | ||
{ | ||
ResFileDownload s = new ResFileDownload (); | ||
UUID userUUID; | ||
|
||
ResStatus resValidate = UtilValidator.validate (args); | ||
if (resValidate.error) { | ||
return ResStatus.downCast (ResFileDownload.class, resValidate); | ||
} | ||
|
||
// auth | ||
|
||
ResStatus resAuth = ServiceAuth.authenticate (args.token); | ||
if (resAuth.error) { | ||
return ResStatus.downCast (ResFileDownload.class, resAuth); | ||
} | ||
userUUID = UUID.fromString (ServiceAuth.tokenGetClaim (args.token, "uuid")); | ||
|
||
// file exists & user has access | ||
|
||
ResStatus resRead = ServiceMetadata.canRead (userUUID, args.fileUUID); | ||
if (resRead.error) { | ||
return ResStatus.downCast (ResFileDownload.class, resRead); | ||
} | ||
|
||
// which volume | ||
|
||
ServiceMetadata.ResFileMetadata resMeta = ServiceMetadata.getFileMetadata (args.fileUUID); | ||
if (resMeta.error) { | ||
return ResStatus.downCast (ResFileDownload.class, resMeta); | ||
} | ||
|
||
// try download it from worker | ||
|
||
try { | ||
IWorkerService server = ServiceWorker.getServer (); | ||
s.fileContent = ServiceWorker.downloadFile (server, args.fileUUID, resMeta.volume); | ||
s.fileName = resMeta.name; | ||
s.fileUUID = args.fileUUID; | ||
|
||
s.code = 200; | ||
s.error = false; | ||
s.msg = ""; | ||
} catch (Exception e) { | ||
|
||
System.err.println (e); | ||
if (e instanceof FileNotFoundException) { | ||
System.err.println ("File not found"); | ||
s.code = 404; | ||
s.msg = "File not found"; | ||
|
||
// NOTE: At this point the metadata service claims a file | ||
// exists in this volume. But it wasn't found. | ||
} else { | ||
System.err.println ("Can't connect to RMI"); | ||
s.code = 500; | ||
s.msg = "Internal error, try again later"; | ||
} | ||
|
||
s.error = true; | ||
} | ||
|
||
return s; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,23 +1,55 @@ | ||
package gateway.services; | ||
|
||
import capyfile.rmi.DownloadFileArgs; | ||
import capyfile.rmi.DownloadFileRes; | ||
import capyfile.rmi.IWorkerService; | ||
import com.healthmarketscience.rmiio.RemoteInputStreamClient; | ||
import gateway.config.Config; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.rmi.registry.LocateRegistry; | ||
import java.rmi.registry.Registry; | ||
import java.util.UUID; | ||
|
||
public class ServiceWorker | ||
{ | ||
// TODO: Use worker pool | ||
public static IWorkerService getServer () throws Exception | ||
{ | ||
Registry registry = | ||
LocateRegistry.getRegistry (Config.getWorkerHost (), Config.getWorkerPort ()); | ||
IWorkerService server = (IWorkerService)registry.lookup ("WorkerService"); | ||
|
||
return server; | ||
} | ||
|
||
public static byte[] downloadFile (IWorkerService worker, UUID fileUUID, int volume) | ||
throws Exception | ||
{ | ||
InputStream istream = null; | ||
|
||
try { | ||
Registry registry = | ||
LocateRegistry.getRegistry (Config.getWorkerHost (), Config.getWorkerPort ()); | ||
IWorkerService server = (IWorkerService)registry.lookup ("WorkerService"); | ||
// get data stream | ||
|
||
DownloadFileRes res = worker.downloadFile (new DownloadFileArgs (fileUUID, volume)); | ||
istream = RemoteInputStreamClient.wrap (res.stream); | ||
byte[] bytes = new byte[(int)res.size]; | ||
|
||
// copy data from stream by chunks | ||
|
||
byte[] buf = new byte[102400]; // 100KB | ||
int bytesPos = 0; | ||
int bytesRead = 0; | ||
|
||
while ((bytesRead = istream.read (buf)) >= 0) { | ||
System.arraycopy (buf, 0, bytes, bytesPos, bytesRead); | ||
bytesPos += bytesRead; | ||
} | ||
|
||
return server; | ||
} catch (Exception e) { | ||
throw e; | ||
return bytes; | ||
} finally { | ||
if (istream != null) { | ||
istream.close (); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.