You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2021/06/01 04:43:49 UTC

[GitHub] [openwhisk-runtime-java] mattwelke commented on pull request #82: Add OpenJDK 11 action loop runtime

mattwelke commented on pull request #82:
URL: https://github.com/apache/openwhisk-runtime-java/pull/82#issuecomment-851799588


   I agree that it's a bad idea to use flags like --add-opens and -illegal-access. I think the best solution would be to change the contract between the runtime and the user action code so that those hacks aren't needed.
   
   I think the "OpenWhisk variables" as I like to call them (the env vars that start with `__OW_`) just need to get to the user action code in any way, as long as it's secure. The OpenWhisk user (making an action) probably doesn't care how. I thought it would make sense for them to just be included in the parameters object the user action is already expected to have. To make things safer, in case users have code like "log all parameters" in their actions, it could be a second parameter. That way, the first parameter is the function's parameters (set at deploy time, with overrides per request) and the second parameter is these more internal OpenWhisk variables like API key.
   
   I made a Java 11 runtime to test this out: https://github.com/mattwelke/apache-openwhisk-runtime-java
   
   It works pretty well, as you can see from the screenshot in that repo's README:
   
   ![image](https://raw.githubusercontent.com/mattwelke/apache-openwhisk-runtime-java/main/img/java-11-test.png)
   
   Note that I'm also using a technique I mentioned in https://github.com/apache/openwhisk-runtime-dotnet/issues/51, where I suggest using the language's native map data stricture instead of JSON for the user action contract (as the Node.js and Go runtimes already do) so that the user doesn't have to link to a JSON library dependency to build their action code. In Java, that means `java.util.Map`.
   
   My custom runtime repo's example action shows it all put together, which is what's running in that IBM Cloud Function:
   
   ```java
   import java.util.HashMap;
   import java.util.Map;
   
   public class Function {
       public static Map<String, Object> main(Map<String, Object> params, Map<String, Object> owVars) {
   
           System.out.println("Runtime version: " + Runtime.version());
   
           printMap(params, "Params");
           printMap(owVars, "OpenWhisk variables");
   
           var output = new HashMap<String, Object>();
           output.put("hello", "world");
           output.put("answer", 42);
   
           return output;
       }
   
       private static void printMap(Map<String, Object> map, String mapName) {
           System.out.println(mapName + " entries:");
           for (var entry : map.entrySet()) {            
               System.out.println("Key: " + entry.getKey() + " | Value: " + entry.getValue());
           }
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org