You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
More flexibility to parsing and passing JSON input/out in Java runtime #15
It would be great to have making OW Java Action use standard Java main method signature with just String[] args and we define custom Launcher that convert the args to JSON and delegate to OW Java Function Launcher, this way it will be easy for applications to be built and tested outside before testing in OW
@rabbah suggested the use of FDK (Function Developer Kit) to hide complexity to deal with a string from end users
On 3, did you consider an openwhisk java FDK which provides a standard wrapper instead for local development?
Also the current return type (com.google.gson.JsonObject) of a Java action signature prevents from returning a JSON array. I think it should be com.google.gson.JsonElement instead. Of course, this is irrelevant if the parsing method is changed completely.
@mkouba thanks for suggestion, we are working on to adhere to standard Java Signature like main(String args[]) and allow internal class like a Luncher to parse the args and give to Launcher to fire the function
I'd try to avoid main(String args[]) if possible. Instead, we could allow user to specify a java.util.function.Function implementation as a main class. And then when initializing action inspect the actual type arguments and make use of com.google.gson.Gson.fromJson(JsonElement, Type) and com.google.gson.Gson.toJsonTree(Object, Type) to perform the conversion automatically. So that a user can simply write something like:
The input to an action and the result of an action are a dictionary of key-value pairs,
where the key is a string and the value a valid JSON value.
We should perhaps make that more prominent. The function signature abstractly is dictionary -> dictionary where the implementation of dictionary is language specific, e.g., JSON object for Javascript.
I'd try to avoid main(String args[]) if possible. Instead, we could allow user to specify a java.util.function.Function implementation as a main class.
@mkouba +1, I assume you also mean there is a a serializer/deserializer from Foo to JSON object?
More generally a Function<T1, T2> where T1 and T2 could be first class types. This create serdes overhead but allows for better function abstractions.
I assume you also mean there is a a serializer/deserializer from Foo to JSON object?
This functionality is provided by Gson. So the only thing we need is to obtain input/output java.lang.reflect.Type through reflection and wrap the function call to convert the values.
@rabbah@mkouba all I was trying to avoid doing via main(String[] args) is to avoid any third party deps with simple functions, I tend see @mkouba style of using Function as entrypoint and use reflection then.. I am right now working with refactoring the javaAction to make it more simper and easier .. will share once its ready for you guys to comment and feedback
Activity
mkouba commentedon Mar 7, 2018
Also the current return type (
com.google.gson.JsonObject) of a Java action signature prevents from returning a JSON array. I think it should becom.google.gson.JsonElementinstead. Of course, this is irrelevant if the parsing method is changed completely.kameshsampath commentedon Mar 7, 2018
@mkouba thanks for suggestion, we are working on to adhere to standard Java Signature like main(String args[]) and allow internal class like a Luncher to parse the args and give to Launcher to fire the function
rabbah commentedon Mar 7, 2018
Note: Whisk actions must return json objects. If you change the signature you’ll need to box the return value into an object elsewhere.
mkouba commentedon Mar 7, 2018
I'd try to avoid
main(String args[])if possible. Instead, we could allow user to specify ajava.util.function.Functionimplementation as a main class. And then when initializing action inspect the actual type arguments and make use ofcom.google.gson.Gson.fromJson(JsonElement, Type)andcom.google.gson.Gson.toJsonTree(Object, Type)to perform the conversion automatically. So that a user can simply write something like:I can try to send a PR if you are interested ;-)
mkouba commentedon Mar 7, 2018
@rabbah Why is that? Is the contract for OW actions defined somewhere?
kameshsampath commentedon Mar 7, 2018
@mkouba - this is where it needs to be fixed further https://github.com/apache/incubator-openwhisk-runtime-java/blob/master/core/javaAction/proxy/src/main/java/openwhisk/java/action/Proxy.java
kameshsampath commentedon Mar 7, 2018
you are most welcome
mkouba commentedon Mar 7, 2018
@kameshsampath Yep, I've seen this code already. We can wrap the resulting array/primitive if necessary right there, e.g.
{result : [...]}rabbah commentedon Mar 7, 2018
@mkouba https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md#creating-and-invoking-openwhisk-actions
We should perhaps make that more prominent. The function signature abstractly is
dictionary -> dictionarywhere the implementation of dictionary is language specific, e.g., JSON object for Javascript.mkouba commentedon Mar 7, 2018
@rabbah Ok, thanks.
rabbah commentedon Mar 7, 2018
@mkouba +1, I assume you also mean there is a a serializer/deserializer from
Footo JSON object?More generally a
Function<T1, T2>whereT1andT2could be first class types. This create serdes overhead but allows for better function abstractions.mkouba commentedon Mar 7, 2018
This functionality is provided by Gson. So the only thing we need is to obtain input/output
java.lang.reflect.Typethrough reflection and wrap the function call to convert the values.csantanapr commentedon Mar 7, 2018
@rabbah this is similar in spirit what I’m doin in swift4 with Codable IN and Codable OUT?
kameshsampath commentedon Mar 7, 2018
@rabbah @mkouba all I was trying to avoid doing via
main(String[] args)is to avoid any third party deps with simple functions, I tend see @mkouba style of using Function as entrypoint and use reflection then.. I am right now working with refactoring the javaAction to make it more simper and easier .. will share once its ready for you guys to comment and feedback