Skip to content
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

Fix java8 template to support resources #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ivanayov
Copy link
Contributor

@ivanayov ivanayov commented Oct 2, 2018

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

  • 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

  • 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:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@spacedoudou
Copy link

it works for me, thanks !

@ivanayov
Copy link
Contributor Author

ivanayov commented Oct 2, 2018

Great :)

@alexellis
Copy link
Member

What is the impact on the build time before/after?

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 resources. Fixed
that by deleting this distribution and creating a controlled one
with `gradle distZip`

Signed-off-by: Ivana Yovcheva (VMware) <[email protected]>
@ivanayov
Copy link
Contributor Author

@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.

@burf2000
Copy link

@alexellis are you likely to merge this anytime soon?

@tessellator
Copy link
Contributor

@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.

@burf2000
Copy link

burf2000 commented Feb 22, 2019

@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

@tessellator
Copy link
Contributor

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.

@alexellis
Copy link
Member

@tessellator @burf2000 please could you both test and report back?

@alexellis
Copy link
Member

Hi @erlendv, please could you take a quick look at this?

Alex

@erlendv
Copy link

erlendv commented Jul 22, 2019

Im not able to reproduce this using the latest templates. Resources are included in the built jar-file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edit java template to allow resources
6 participants