VirusTotalNet
VirusTotalNet copied to clipboard
Fix java8 template to support resources
With this change all resources within function's src/main/resources
will be added to function.jar.
Before that they used to be omited.
The distribution, created after gradle build
was modifying the jars, excluding all resoursed.
Fixed that by deleting this distribution and creating a controlled one with gradle distZip
Signed-off-by: Ivana Yovcheva (VMware) [email protected]
Motivation and Context
- [x] I have raised an issue to propose this change (required)
Which issue(s) this PR fixes
Fixes #72
How Has This Been Tested?
$ faas-cli build
$ docker run -ti hello-java sh
$ cd entry point-1.0/libs
$ jar xf function-1.0.jar
$ ls
META-INF function-1.0.jar com res_file.xml
Tested function from @spacedoudou with updated template: https://github.com/spacedoudou/openfaas1
Fixed code in Handler.java to prefix resource file with /
:
URL u = getClass().getResource("/res_file.xml");
$ echo "" | faas invoke hello-java
getResource = jar:file:/home/app/entrypoint-1.0/lib/function-1.0.jar!/res_file.xml
After modifying code to read contents:
$ curl -X GET http://127.0.0.1:8080/function/hello-java -d ""
getRessource = jar:file:/home/app/entrypoint-1.0/lib/function-1.0.jar!/res_file.xml
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>John</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Hi!</body>
</note>
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I've read the CONTRIBUTION guide
- [x] I have signed-off my commits with
git commit -s
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
it works for me, thanks !
Great :)
What is the impact on the build time before/after?
@alexellis
Build time before:
real 0m41.745s
user 0m0.126s
sys 0m0.197s
After:
real 0m48.179s
user 0m0.131s
sys 0m0.098s
I've updated the description with test for reading resource contents.
@alexellis are you likely to merge this anytime soon?
@ivanayov Is this still applicable? I am unable to duplicate the issue with the java8 template pulled as of this morning (21 Feb 2019). I followed your test procedure and was able to find the resource and load the content of the file without the changes suggested in this PR.
@tessellator When I run the current template, it does not find resources, I wrote functions to lists all files etc and it never found them
Hmm, that is really weird. Here are the changes I made to the sample function to list the file contents, and I get the following output:
➜ echo "" | faas invoke hello-java
getRessource = jar:file:/home/app/entrypoint-1.0/lib/function-1.0.jar!/res_file.xml
file content
end of file.%
Would you mind trying my version of the function and seeing what you get (repo link)? I just want to establish some common ground for debugging purposes.
@tessellator @burf2000 please could you both test and report back?
Hi @erlendv, please could you take a quick look at this?
Alex
Im not able to reproduce this using the latest templates. Resources are included in the built jar-file.