From 86ebde17597ba78c03dc25cc72a37c19c75a47ea Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Wed, 11 Apr 2018 21:11:52 -0400 Subject: [PATCH 01/18] Adding initial code for the maven plugin and annotations --- .gitignore | 5 + openwhisk-annotations/pom.xml | 23 ++ .../apache/openwhisk/annotations/Action.java | 90 +++++++ .../openwhisk/annotations/Annotation.java | 36 +++ .../apache/openwhisk/annotations/Package.java | 56 +++++ .../openwhisk/annotations/Parameter.java | 35 +++ .../apache/openwhisk/annotations/Rule.java | 53 ++++ .../apache/openwhisk/annotations/Trigger.java | 58 +++++ openwhisk-install-maven-plugin/pom.xml | 124 ++++++++++ .../src/it/settings.xml | 55 +++++ .../src/it/simple-it/pom.xml | 34 +++ .../src/it/simple-it/verify.groovy | 3 + .../java/org/apache/openwhisk/maven/TYPE.java | 43 ++++ .../openwhisk/maven/UpdateWhiskMojo.java | 231 ++++++++++++++++++ .../maven/commands/ActionCommand.java | 80 ++++++ .../openwhisk/maven/commands/Command.java | 127 ++++++++++ .../maven/commands/PackageCommand.java | 51 ++++ .../openwhisk/maven/commands/RuleCommand.java | 47 ++++ .../maven/commands/TriggerCommand.java | 50 ++++ 19 files changed, 1201 insertions(+) create mode 100644 openwhisk-annotations/pom.xml create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java create mode 100644 openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java create mode 100644 openwhisk-install-maven-plugin/pom.xml create mode 100644 openwhisk-install-maven-plugin/src/it/settings.xml create mode 100644 openwhisk-install-maven-plugin/src/it/simple-it/pom.xml create mode 100644 openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java create mode 100644 openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java diff --git a/.gitignore b/.gitignore index 24ad037b..81e044a2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ openwhisk-master* .idea .vscode **/.sts4-cache +target/ +.project +.settings/ +bin/ +.classpath \ No newline at end of file diff --git a/openwhisk-annotations/pom.xml b/openwhisk-annotations/pom.xml new file mode 100644 index 00000000..d54af145 --- /dev/null +++ b/openwhisk-annotations/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + + org.apache + apache + 19 + + + + org.apache.openwhisk + openwhisk-annotations + 0.0.1-SNAPSHOT + Apache OpenWhisk Annotations + + + UTF-8 + 1.8 + 1.8 + + \ No newline at end of file diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java new file mode 100644 index 00000000..9912c0bd --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java @@ -0,0 +1,90 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * An annotation to indicate that the specified class should register an OpenWhisk action. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md + */ +@Retention(RUNTIME) +@Target(TYPE) +public @interface Action { + + /** + * The annotation values for the action + */ + Annotation[] annotations() default {}; + + /** + * Use provided docker image (a path on DockerHub) to run the action + */ + String docker() default ""; + + /** + * The maximum log size LIMIT in MB for the action (default 10) + */ + int logsize() default -1; + + /** + * the maximum memory LIMIT in MB for the action (default 256) + */ + int memory() default -1; + + /** + * The name of the action + */ + String name(); + + /** + * The name of the package for this action + */ + String packageName() default ""; + + /** + * The parameter values for the action + */ + Parameter[] parameters() default {}; + + /** + * Treat ACTION as comma separated sequence of actions to invoke + */ + boolean sequence() default false; + + /** + * The timeout LIMIT in milliseconds after which the action is terminated + * (default 60000) + */ + int timeout() default -1; + + /** + * Treat ACTION as a web action, a raw HTTP web action, or as a standard action; + * yes | true = web action, raw = raw HTTP web action, no | false = standard + * action + */ + String web() default ""; + + /** + * Secure the web action. where SECRET is true, false, or any string. Only valid + * when the ACTION is a web action + */ + String websecure() default ""; +} diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java new file mode 100644 index 00000000..c8e86805 --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java @@ -0,0 +1,36 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Adds an annotation with a key and value to an OpenWhisk function. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/annotations.md + */ +@Retention(RUNTIME) +@Target(ANNOTATION_TYPE) +public @interface Annotation { + + String key(); + + String value(); + +} diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java new file mode 100644 index 00000000..f01e0617 --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java @@ -0,0 +1,56 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * An annotation to indicate that the specified class should register an + * OpenWhisk package. + * + * By convention, this will usually be registered on a package_info class in the + * package containing the actions, feeds and triggers for a particular package. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/packages.md + */ +@Retention(RUNTIME) +@Target(TYPE) +public @interface Package { + + /** + * The annotation values for the trigger + */ + Annotation[] annotations() default {}; + + /** + * The name of the trigger + */ + String name(); + + /** + * The parameter values for the trigger + */ + Parameter[] parameters() default {}; + + /** + * The scope for this package, should be one of "yes" or "no" + */ + String shared() default ""; + +} diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java new file mode 100644 index 00000000..70484914 --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java @@ -0,0 +1,35 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Adds an parameter with a key and value to an OpenWhisk function. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/parameters.md + */ +@Retention(RUNTIME) +@Target(ANNOTATION_TYPE) +public @interface Parameter { + + String key(); + + String value(); +} diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java new file mode 100644 index 00000000..142e7a70 --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java @@ -0,0 +1,53 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * An annotation to indicate that the specified class should register an + * OpenWhisk rule. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md + */ +@Retention(RUNTIME) +@Target(TYPE) +public @interface Rule { + + /** + * The name of the action to execute for this trigger + */ + String actionName(); + + /** + * The name of the trigger + */ + String name(); + + /** + * The name of the package for this rule + */ + String packageName(); + + /** + * The name of the trigger to execute this rule + */ + String triggerName(); + +} diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java new file mode 100644 index 00000000..fe217daf --- /dev/null +++ b/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java @@ -0,0 +1,58 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * An annotation to indicate that the specified class should register an + * OpenWhisk trigger. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md + */ +@Retention(RUNTIME) +@Target(TYPE) +public @interface Trigger { + + /** + * The annotation values for the trigger + */ + Annotation[] annotations() default {}; + + /** + * The name of the action to feed this trigger + */ + String feed(); + + /** + * The name of the trigger + */ + String name(); + + /** + * The name of the package for this trigger + */ + String packageName(); + + /** + * The parameter values for the trigger + */ + Parameter[] parameters() default {}; + +} diff --git a/openwhisk-install-maven-plugin/pom.xml b/openwhisk-install-maven-plugin/pom.xml new file mode 100644 index 00000000..77a6f62d --- /dev/null +++ b/openwhisk-install-maven-plugin/pom.xml @@ -0,0 +1,124 @@ + + 4.0.0 + + org.apache.openwhisk + openwhisk-update-maven-plugin + 0.0.1-SNAPSHOT + maven-plugin + + OpenWhisk Update Function Maven Plugin + + https://openwhisk.apache.org/ + + + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + provided + + + org.codehaus.plexus + plexus-utils + 3.0.8 + + + org.slf4j + slf4j-api + 1.7.4 + + + org.apache.openwhisk + openwhisk-annotations + 0.0.1-SNAPSHOT + + + junit + junit + 4.8.2 + test + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + openwhisk-update + true + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + + + + run-its + + + + + org.apache.maven.plugins + maven-invoker-plugin + 1.7 + + true + ${project.build.directory}/it + + */pom.xml + + verify + ${project.build.directory}/local-repo + src/it/settings.xml + + clean + test-compile + + + + + integration-test + + install + integration-test + verify + + + + + + + + + + diff --git a/openwhisk-install-maven-plugin/src/it/settings.xml b/openwhisk-install-maven-plugin/src/it/settings.xml new file mode 100644 index 00000000..c8f77f0b --- /dev/null +++ b/openwhisk-install-maven-plugin/src/it/settings.xml @@ -0,0 +1,55 @@ + + + + + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + diff --git a/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml b/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml new file mode 100644 index 00000000..5d0d77d8 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + org.apache.openwhisk.it + simple-it + 1.0-SNAPSHOT + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + touch + validate + + touch + + + + + + + diff --git a/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy b/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy new file mode 100644 index 00000000..7b307c78 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy @@ -0,0 +1,3 @@ +File touchFile = new File( basedir, "target/touch.txt" ); + +assert touchFile.isFile() diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java new file mode 100644 index 00000000..2186ca5e --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven; + +/** + * An enum of the different types supported by OpenWhisk + */ +public enum TYPE { + + /** + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md + */ + ACTION, + + /** + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/packages.md + */ + PACKAGE, + + /** + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md#associating-triggers-and-actions-by-using-rules + */ + RULE, + + /** + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md + */ + TRIGGER +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java new file mode 100644 index 00000000..44be34e0 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.openwhisk.annotations.Action; +import org.apache.openwhisk.annotations.Package; +import org.apache.openwhisk.annotations.Trigger; +import org.apache.openwhisk.maven.commands.ActionCommand; +import org.apache.openwhisk.maven.commands.PackageCommand; +import org.apache.openwhisk.maven.commands.TriggerCommand; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A goal which installs a Java Action into an OpenWhisk instance + */ +@Mojo(name = "update", defaultPhase = LifecyclePhase.INSTALL) +public class UpdateWhiskMojo extends AbstractMojo { + + /** + * Specify the whisk API HOST for connecting to OpenWhisk + */ + @Parameter(property = "openwhisk.apihost", required = false) + private String apihost; + + /** + * Specify the whisk API VERSION for connecting to OpenWhisk + */ + @Parameter(property = "openwhisk.apiversion", required = false) + private String apiversion; + + /** + * Specify the authorization KEY for connecting to OpenWhisk + */ + @Parameter(property = "openwhisk.auth", required = false) + private String auth; + + /** + * Specify the client cert for connecting to OpenWhisk + */ + @Parameter(property = "openwhisk.cert", required = false) + private String cert; + + /** + * The class directory for finding the main class + */ + @Parameter(defaultValue = "${project.build.directory}/classes", required = true, readonly = true) + private String classesDirectory; + + /** + * The executable for OpenWhisk CLI + */ + @Parameter(defaultValue = "wsk", property = "openwhisk.cli", required = true) + private String cli; + + /** + * Whether to debug the connection with OpenWhisk + */ + @Parameter(defaultValue = "false", property = "openwhisk.debug", required = false) + private Boolean debug; + + /** + * Whether to bypass signature checking for the connection with OpenWhisk + */ + @Parameter(defaultValue = "false", property = "openwhisk.insecure", required = false) + private Boolean insecure; + + /** + * The jar file for OpenWhisk to use for creating the functions + */ + @Parameter(defaultValue = "target/${project.build.finalName}.jar", property = "openwhisk.jar", required = true) + private String jar; + + /** + * Specify the client key for connecting to OpenWhisk + */ + @Parameter(property = "openwhisk.key", required = false) + private String key; + + /** + * Define the logger as a member for easy access + */ + private Logger log = LoggerFactory.getLogger(getClass()); + + /** + * A comma separated list of main classes to load into OpenWhisk + */ + @Parameter(defaultValue = "false", required = true) + private String main; + + public void execute() throws MojoExecutionException { + + final List globalFlags = calculateGlobalFlags(); + + List init = new ArrayList(); + + if (cli.contains(" ")) { + for (String c : cli.split(" ")) { + init.add(c); + } + } else { + init.add(cli); + } + + for (String mainClass : this.main.split("\\,")) { + mainClass = mainClass.trim(); + try { + processAnnotations(mainClass, init, globalFlags); + } catch (IOException e) { + throw new MojoExecutionException("IOException occured executing OpenWhisk update", e); + } + } + + } + + private List calculateGlobalFlags() { + List cmd = new ArrayList(); + if (debug) { + log.debug("Adding debugging flags"); + cmd.add("-v"); + cmd.add("-d"); + } + if (insecure) { + log.debug("Adding insecure flags"); + cmd.add("-i"); + } + if (StringUtils.isNotBlank(apihost)) { + log.debug("Setting API Host to " + apihost); + cmd.add("--apihost"); + cmd.add(apihost); + } + if (StringUtils.isNotBlank(apiversion)) { + log.debug("Setting API Version to " + apiversion); + cmd.add("--apiversion"); + cmd.add(apiversion); + } + if (StringUtils.isNotBlank(auth)) { + log.debug("Setting auth to " + auth); + cmd.add("--auth"); + cmd.add(auth); + } + if (StringUtils.isNotBlank(cert)) { + log.debug("Setting client cert to " + cert); + cmd.add("--cert"); + cmd.add(cert); + } + if (StringUtils.isNotBlank(key)) { + log.debug("Setting client key to " + key); + cmd.add("--key"); + cmd.add(key); + } + return cmd; + } + + private void processAnnotations(String mc, List cmd, List globalFlags) + throws MojoExecutionException, IOException { + URLClassLoader cl = null; + try { + cl = new URLClassLoader(new URL[] { new File(this.classesDirectory).toURI().toURL() }, + Thread.currentThread().getContextClassLoader()); + Class mainClass = cl.loadClass(mc); + log.debug("Loaded main class " + mainClass.getCanonicalName()); + + Package[] packages = mainClass.getDeclaredAnnotationsByType(Package.class); + if (packages != null) { + for (Package pkg : packages) { + PackageCommand pc = new PackageCommand(pkg, cmd, globalFlags); + pc.execute(); + } + } + + Action[] actions = mainClass.getDeclaredAnnotationsByType(Action.class); + if (actions != null) { + for (Action action : actions) { + ActionCommand ac = new ActionCommand(action, cmd, globalFlags, jar, main); + ac.execute(); + } + } + + Trigger[] triggers = mainClass.getDeclaredAnnotationsByType(Trigger.class); + if (triggers != null) { + for (Trigger trigger : triggers) { + TriggerCommand tc = new TriggerCommand(trigger, cmd, globalFlags); + tc.execute(); + } + } + + } catch (ClassNotFoundException e) { + log.error("Unable to find main class: " + main, e); + } catch (MalformedURLException e) { + log.error("Malformed URL for class directory: " + classesDirectory, e); + } finally { + if (cl != null) { + try { + cl.close(); + } catch (IOException e) { + // Swallow the exception + } + } + } + } + +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java new file mode 100644 index 00000000..5b792dc2 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.util.List; + +import org.apache.openwhisk.annotations.Action; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command for creating an action in OpenWhisk + */ +public class ActionCommand extends Command { + + private final Logger log = LoggerFactory.getLogger(ActionCommand.class); + + public ActionCommand(Action action, List init, List globalFlags, String jar, String main) { + super(init, action.packageName(), action.name(), globalFlags); + + cmd.add(jar); + cmd.add("--main"); + cmd.add(main); + + this.addAnnotations(action.annotations()); + this.addParameters(action.parameters()); + + if (StringUtils.isNotBlank(action.docker())) { + log.debug("Setting docker to " + action.docker()); + cmd.add("--docker"); + cmd.add(action.docker()); + } + if (action.logsize() != -1) { + log.debug("Setting logsize to " + action.logsize()); + cmd.add("--logsize"); + cmd.add(String.valueOf(action.logsize())); + } + if (action.memory() != -1) { + log.debug("Setting memory to " + action.memory()); + cmd.add("--memory"); + cmd.add(String.valueOf(action.memory())); + } + if (action.timeout() != -1) { + log.debug("Setting timeout to " + action.timeout()); + cmd.add("--timeout"); + cmd.add(String.valueOf(action.timeout())); + } + if (StringUtils.isNotBlank(action.web())) { + log.debug("Setting web to " + action.web()); + cmd.add("--web"); + cmd.add(action.web()); + } + if (StringUtils.isNotBlank(action.websecure())) { + log.debug("Setting web-secure to " + action.websecure()); + cmd.add("--web-secure"); + cmd.add(action.websecure()); + } + } + + @Override + public String getType() { + return "action"; + } + +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java new file mode 100644 index 00000000..853ac99f --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.openwhisk.annotations.Annotation; +import org.apache.openwhisk.annotations.Parameter; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * An abstract OpenWhisk command, base class for the specific types to extend. + */ +public abstract class Command { + + private static final Logger log = LoggerFactory.getLogger(Command.class); + + protected final List cmd = new ArrayList(); + + private List globalFlags = null; + + private String name; + + public Command(List init, String pkg, String name, List globalFlags) { + log.debug("Creating command for {}/{}", pkg, name); + this.cmd.addAll(init); + this.cmd.add(getType()); + this.cmd.add("update"); + if (StringUtils.isNotBlank(pkg)) { + this.cmd.add(pkg + "/" + name); + } else { + this.cmd.add(name); + } + this.globalFlags = globalFlags; + } + + protected void addAnnotations(Annotation[] annotations) { + if (annotations != null) { + for (Annotation a : annotations) { + cmd.add("-a"); + cmd.add(a.key()); + cmd.add(a.value()); + } + } + } + + protected void addParameters(Parameter[] parameters) { + if (parameters != null) { + for (Parameter p : parameters) { + cmd.add("-p"); + cmd.add(p.key()); + cmd.add(p.value()); + } + } + } + + public void execute() throws IOException, MojoExecutionException { + + log.info("Updating OpenWhisk {} {}", getType(), getName()); + + cmd.addAll(globalFlags); + + log.debug("Executing OpenWhisk CLI Command with command: {}", cmd); + ProcessBuilder builder = new ProcessBuilder(); + builder.command(cmd); + Process pr = builder.start(); + + readInput(pr.getInputStream(), false); + if (readInput(pr.getErrorStream(), true)) { + throw new MojoExecutionException("Call to OpenWhisk failed!"); + } else { + log.info("OpenWhisk Function Updated!"); + } + + } + + public String getName() { + return name; + } + + public abstract String getType(); + + private boolean readInput(InputStream is, boolean err) { + boolean read = false; + BufferedReader input = new BufferedReader(new InputStreamReader(is)); + String line = null; + try { + while ((line = input.readLine()) != null) { + if (err) { + log.error(line); + } else { + log.info(line); + } + read = true; + } + } catch (IOException e) { + log.error("Exception reading response from OpenWhisk CLI Command", e); + } + return read; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java new file mode 100644 index 00000000..8a482ce9 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.util.List; + +import org.apache.openwhisk.annotations.Package; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command for creating a package in OpenWhisk + */ +public class PackageCommand extends Command { + + private final Logger log = LoggerFactory.getLogger(PackageCommand.class); + + public PackageCommand(Package pkg, List init, List globalFlags) { + super(init, "", pkg.name(), globalFlags); + + this.addAnnotations(pkg.annotations()); + this.addParameters(pkg.parameters()); + + if (!StringUtils.isBlank(pkg.shared())) { + log.debug("Setting shared to {}", pkg.shared()); + cmd.add("--shared"); + cmd.add(pkg.shared()); + } + } + + @Override + public String getType() { + return "package"; + } + +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java new file mode 100644 index 00000000..f4d72501 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.util.List; + +import org.apache.openwhisk.annotations.Rule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command for creating a rule in OpenWhisk + */ +public class RuleCommand extends Command { + + private final Logger log = LoggerFactory.getLogger(RuleCommand.class); + + public RuleCommand(Rule rule, List init, List globalFlags) { + super(init, rule.packageName(), rule.name(), globalFlags); + + log.debug("Setting trigger name to {}", rule.triggerName()); + cmd.add(rule.triggerName()); + + log.debug("Setting trigger name to {}", rule.actionName()); + cmd.add(rule.actionName()); + } + + @Override + public String getType() { + return "rule"; + } + +} diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java new file mode 100644 index 00000000..46daef92 --- /dev/null +++ b/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.util.List; + +import org.apache.openwhisk.annotations.Trigger; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command for creating a trigger in OpenWhisk + */ +public class TriggerCommand extends Command { + + private final Logger log = LoggerFactory.getLogger(RuleCommand.class); + + public TriggerCommand(Trigger trigger, List init, List globalFlags) { + super(init, trigger.packageName(), trigger.name(), globalFlags); + + this.addAnnotations(trigger.annotations()); + this.addParameters(trigger.parameters()); + if (StringUtils.isBlank(trigger.feed())) { + log.debug("Setting feed to {}", trigger.feed()); + cmd.add("--feed"); + cmd.add(trigger.feed()); + } + } + + @Override + public String getType() { + return "trigger"; + } + +} From da1e66a87fd42a5393154c5467d917a559fffec1 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:25:26 -0400 Subject: [PATCH 02/18] Reorganizing the maven code, adding a parent project and adding readmes --- README.md | 8 +- .../action-archetype}/.editorconfig | 0 .../action-archetype}/.gitignore | 0 .../action-archetype}/.travis/build.sh | 0 .../action-archetype}/.travis/setup.sh | 0 .../action-archetype}/README.md | 1 - .../action-archetype}/pom.xml | 18 +- .../resources/META-INF/maven/archetype.xml | 0 .../resources/archetype-resources/pom.xml | 20 ++ .../src/main/java/FunctionApp.java | 2 + .../src/test/java/FunctionAppTest.java | 0 .../projects/basic/archetype.properties | 0 .../test/resources/projects/basic/goal.txt | 0 java-maven/annotations/README.md | 55 ++++ java-maven/annotations/pom.xml | 40 +++ .../apache/openwhisk/annotations/Action.java | 0 .../openwhisk/annotations/Annotation.java | 0 .../apache/openwhisk/annotations/Package.java | 0 .../openwhisk/annotations/Parameter.java | 0 .../apache/openwhisk/annotations/Rule.java | 2 +- .../apache/openwhisk/annotations/Trigger.java | 4 +- java-maven/parent/README.md | 5 + java-maven/parent/pom.xml | 241 ++++++++++++++++++ java-maven/update-maven-plugin/README.md | 72 ++++++ .../update-maven-plugin}/pom.xml | 24 ++ .../java/org/apache/openwhisk/maven/TYPE.java | 0 .../openwhisk/maven/UpdateWhiskMojo.java | 1 + .../maven/commands/ActionCommand.java | 0 .../openwhisk/maven/commands/Command.java | 5 +- .../maven/commands/PackageCommand.java | 0 .../openwhisk/maven/commands/RuleCommand.java | 0 .../maven/commands/TriggerCommand.java | 0 .../.editorconfig | 0 {maven-java => maven-java-example}/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.jar | Bin .../.mvn/wrapper/maven-wrapper.properties | 0 {maven-java => maven-java-example}/README.md | 0 .../dependency-reduced-pom.xml | 0 {maven-java => maven-java-example}/mvnw | 0 {maven-java => maven-java-example}/mvnw.cmd | 0 {maven-java => maven-java-example}/pom.xml | 2 +- .../apache/openwhisk/example/maven/App.java | 0 openwhisk-annotations/pom.xml | 23 -- .../src/it/settings.xml | 55 ---- .../src/it/simple-it/pom.xml | 34 --- .../src/it/simple-it/verify.groovy | 3 - 46 files changed, 486 insertions(+), 129 deletions(-) rename {java-action-archetype => java-maven/action-archetype}/.editorconfig (100%) rename {java-action-archetype => java-maven/action-archetype}/.gitignore (100%) rename {java-action-archetype => java-maven/action-archetype}/.travis/build.sh (100%) rename {java-action-archetype => java-maven/action-archetype}/.travis/setup.sh (100%) rename {java-action-archetype => java-maven/action-archetype}/README.md (92%) rename {java-action-archetype => java-maven/action-archetype}/pom.xml (66%) rename {java-action-archetype => java-maven/action-archetype}/src/main/resources/META-INF/maven/archetype.xml (100%) rename {java-action-archetype => java-maven/action-archetype}/src/main/resources/archetype-resources/pom.xml (71%) rename {java-action-archetype => java-maven/action-archetype}/src/main/resources/archetype-resources/src/main/java/FunctionApp.java (94%) rename {java-action-archetype => java-maven/action-archetype}/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java (100%) rename {java-action-archetype => java-maven/action-archetype}/src/test/resources/projects/basic/archetype.properties (100%) rename {java-action-archetype => java-maven/action-archetype}/src/test/resources/projects/basic/goal.txt (100%) create mode 100644 java-maven/annotations/README.md create mode 100644 java-maven/annotations/pom.xml rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Action.java (100%) rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Annotation.java (100%) rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Package.java (100%) rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Parameter.java (100%) rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Rule.java (97%) rename {openwhisk-annotations => java-maven/annotations}/src/main/java/org/apache/openwhisk/annotations/Trigger.java (95%) create mode 100644 java-maven/parent/README.md create mode 100644 java-maven/parent/pom.xml create mode 100644 java-maven/update-maven-plugin/README.md rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/pom.xml (76%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/TYPE.java (100%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java (99%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java (100%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/commands/Command.java (96%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java (100%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java (100%) rename {openwhisk-install-maven-plugin => java-maven/update-maven-plugin}/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java (100%) rename {maven-java => maven-java-example}/.editorconfig (100%) rename {maven-java => maven-java-example}/.gitignore (100%) rename {maven-java => maven-java-example}/.mvn/wrapper/maven-wrapper.jar (100%) rename {maven-java => maven-java-example}/.mvn/wrapper/maven-wrapper.properties (100%) rename {maven-java => maven-java-example}/README.md (100%) rename {maven-java => maven-java-example}/dependency-reduced-pom.xml (100%) rename {maven-java => maven-java-example}/mvnw (100%) rename {maven-java => maven-java-example}/mvnw.cmd (100%) rename {maven-java => maven-java-example}/pom.xml (96%) rename {maven-java => maven-java-example}/src/main/java/org/apache/openwhisk/example/maven/App.java (100%) delete mode 100644 openwhisk-annotations/pom.xml delete mode 100644 openwhisk-install-maven-plugin/src/it/settings.xml delete mode 100644 openwhisk-install-maven-plugin/src/it/simple-it/pom.xml delete mode 100644 openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy diff --git a/README.md b/README.md index eee3b31d..c7000b16 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,13 @@ This repository is part of [Apache OpenWhisk](http://openwhisk.incubator.apache. * [docker-compose](docker-compose/README.md) allows testing OpenWhisk locally, using Docker Compose. This is ideal if you are contributing to core development * [node-local](node-local/README.md) allows testing individual OpenWhisk functions locally, using only node.js. This is ideal if you are writing node.js functions to run in OpenWhisk, but need to emulate some of OpenWhisk's behavior in creating `params` and expecting promises. -* [maven-java](maven-java/README.md) allows testing OpenWhisk Java Actions. This shows how to package the function dependencies e.g. external jar. +* *java-maven* tooling to support building / deploying Java actions in OpenWhisk + * [action-archetype](java-maven/action-archetype) Archetype for creating a Java Action project using Apache Maven + * [annotations](java-maven/annotations) Java annotations to indicate OpenWhisk Actions, Packages, Rules and Triggers + * [parent](java-maven/parent) provides a baseline Maven configuration for Maven-based OpenWhisk sub-projects + * [update-maven-plugin](java-maven/update-maven-plugin) Apache Maven plugin to read the [annotations](java-maven/annotations) and automatically deploying the Actions, Packages, Rules and Trigger to OpenWhisk +* [maven-java-examplea](maven-java-example/README.md) shows how to package the function dependencies e.g. external jar. +* [java-local](java-local) allows testing OpenWhisk Java Actions ## Travis builds diff --git a/java-action-archetype/.editorconfig b/java-maven/action-archetype/.editorconfig similarity index 100% rename from java-action-archetype/.editorconfig rename to java-maven/action-archetype/.editorconfig diff --git a/java-action-archetype/.gitignore b/java-maven/action-archetype/.gitignore similarity index 100% rename from java-action-archetype/.gitignore rename to java-maven/action-archetype/.gitignore diff --git a/java-action-archetype/.travis/build.sh b/java-maven/action-archetype/.travis/build.sh similarity index 100% rename from java-action-archetype/.travis/build.sh rename to java-maven/action-archetype/.travis/build.sh diff --git a/java-action-archetype/.travis/setup.sh b/java-maven/action-archetype/.travis/setup.sh similarity index 100% rename from java-action-archetype/.travis/setup.sh rename to java-maven/action-archetype/.travis/setup.sh diff --git a/java-action-archetype/README.md b/java-maven/action-archetype/README.md similarity index 92% rename from java-action-archetype/README.md rename to java-maven/action-archetype/README.md index 67bf3daf..d85408c4 100644 --- a/java-action-archetype/README.md +++ b/java-maven/action-archetype/README.md @@ -29,7 +29,6 @@ The following step shows how to deploy the function to OpenWhisk ```sh cd demo-function mvn clean install -wsk action create demo target/demo-function.jar --main com.example.FunctionApp ``` After successful deployment of the function, we can invoke the same via `wsk action invoke demo --result` to see the response as: diff --git a/java-action-archetype/pom.xml b/java-maven/action-archetype/pom.xml similarity index 66% rename from java-action-archetype/pom.xml rename to java-maven/action-archetype/pom.xml index badbf920..51bc9db8 100644 --- a/java-action-archetype/pom.xml +++ b/java-maven/action-archetype/pom.xml @@ -2,12 +2,20 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - org.apache.openwhisk.java - java-action-archetype - 1.0-SNAPSHOT + + + org.apache.openwhisk + openwhisk + pom + 1-SNAPSHOT + + + org.apache.openwhisk + openwhisk-action-archetype + 1.0.0-SNAPSHOT maven-archetype - OpenWhisk:: Maven Archetype - Java Action - http://openwhisk.apache.org + Apache OpenWhisk - Java Action Maven Archetype + diff --git a/java-action-archetype/src/main/resources/META-INF/maven/archetype.xml b/java-maven/action-archetype/src/main/resources/META-INF/maven/archetype.xml similarity index 100% rename from java-action-archetype/src/main/resources/META-INF/maven/archetype.xml rename to java-maven/action-archetype/src/main/resources/META-INF/maven/archetype.xml diff --git a/java-action-archetype/src/main/resources/archetype-resources/pom.xml b/java-maven/action-archetype/src/main/resources/archetype-resources/pom.xml similarity index 71% rename from java-action-archetype/src/main/resources/archetype-resources/pom.xml rename to java-maven/action-archetype/src/main/resources/archetype-resources/pom.xml index c17dbd3f..cd7c55c1 100644 --- a/java-action-archetype/src/main/resources/archetype-resources/pom.xml +++ b/java-maven/action-archetype/src/main/resources/archetype-resources/pom.xml @@ -18,6 +18,11 @@ gson ${gson.version} + + org.apache.openwhisk + openwhisk-annotations + 0.0.1-SNAPSHOT + junit junit @@ -42,6 +47,21 @@ + + org.apache.openwhisk + openwhisk-update-maven-plugin + 0.0.1-SNAPSHOT + + + + update + + + + +
$groupId.FunctionApp
+
+
\ No newline at end of file diff --git a/java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java b/java-maven/action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java similarity index 94% rename from java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java rename to java-maven/action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java index 4b88ea0b..9d4727d8 100644 --- a/java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java +++ b/java-maven/action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java @@ -18,10 +18,12 @@ */ import com.google.gson.JsonObject; +import org.apache.openwhisk.annotations.Action; /** * Hello FunctionApp */ +@Action(name="demo") public class FunctionApp { public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); diff --git a/java-action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java b/java-maven/action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java similarity index 100% rename from java-action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java rename to java-maven/action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java diff --git a/java-action-archetype/src/test/resources/projects/basic/archetype.properties b/java-maven/action-archetype/src/test/resources/projects/basic/archetype.properties similarity index 100% rename from java-action-archetype/src/test/resources/projects/basic/archetype.properties rename to java-maven/action-archetype/src/test/resources/projects/basic/archetype.properties diff --git a/java-action-archetype/src/test/resources/projects/basic/goal.txt b/java-maven/action-archetype/src/test/resources/projects/basic/goal.txt similarity index 100% rename from java-action-archetype/src/test/resources/projects/basic/goal.txt rename to java-maven/action-archetype/src/test/resources/projects/basic/goal.txt diff --git a/java-maven/annotations/README.md b/java-maven/annotations/README.md new file mode 100644 index 00000000..06cb6fdd --- /dev/null +++ b/java-maven/annotations/README.md @@ -0,0 +1,55 @@ +# OpenWhisk Annotations for Java + +This project allows developers to define actions, packages, rules and triggers from annotations on java classes. + +## Pre-requisite + +The following softwares are required to use this project: + +* (Maven v3.3.x)[https://maven.apache.org] or above +* Java 8 or above +* OpenWhisk CLI +* [openwhisk-update-maven-plugin](../update-maven-plugin/) + +## Adding the Annotations + +All of the annotations are added at the class level. You can define more than one annotation per class. + +### Action Annotation + +The `@Action` annotation defines an OpenWhisk [action](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md): + +``` +@Action(name = "simple-function", packageName = "test", parameters = { @Parameter(key = "Name", value = "Bob") }) +public class FunctionApp { +``` + +### Package Annotation + +The `@Package` annotation defines an OpenWhisk [package](https://github.com/apache/incubator-openwhisk/blob/master/docs/packages.md): + +``` +@Package(name = "test") +public class FunctionApp { +``` + +Our recommendation would be to add this to a package-info.java class for the package containing the actions / code for a particular package. + +### Rule Annotation + +The `@Rule` annotation defines an OpenWhisk [rule](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md): + +``` +@Rule(actionName="test/simple-function", name = "dostuffrule", packageName = "test", triggerName="test/dostuff") +public class FunctionApp { +``` + + +### Trigger Annotation + +The `@Trigger` annotation defines an OpenWhisk [trigger](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md): + +``` +@Trigger(feed = "/whisk.system/alarms/alarm", name = "dostuff", packageName = "test", parameters = { @Parameter(key = "cron", value = "5 * * * *")}) +public class FunctionApp { +``` \ No newline at end of file diff --git a/java-maven/annotations/pom.xml b/java-maven/annotations/pom.xml new file mode 100644 index 00000000..727f2888 --- /dev/null +++ b/java-maven/annotations/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + + org.apache.openwhisk + openwhisk + 1-SNAPSHOT + + + + org.apache.openwhisk + openwhisk-annotations + 0.0.1-SNAPSHOT + Apache OpenWhisk Annotations + + + UTF-8 + 1.8 + 1.8 + + \ No newline at end of file diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java similarity index 100% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Action.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java similarity index 100% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Annotation.java diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Package.java similarity index 100% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Package.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Package.java diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java similarity index 100% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Parameter.java diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java similarity index 97% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java index 142e7a70..701e6491 100644 --- a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java @@ -43,7 +43,7 @@ /** * The name of the package for this rule */ - String packageName(); + String packageName() default ""; /** * The name of the trigger to execute this rule diff --git a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java similarity index 95% rename from openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java rename to java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java index fe217daf..211a907a 100644 --- a/openwhisk-annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java @@ -38,7 +38,7 @@ /** * The name of the action to feed this trigger */ - String feed(); + String feed() default ""; /** * The name of the trigger @@ -48,7 +48,7 @@ /** * The name of the package for this trigger */ - String packageName(); + String packageName() default ""; /** * The parameter values for the trigger diff --git a/java-maven/parent/README.md b/java-maven/parent/README.md new file mode 100644 index 00000000..1be35806 --- /dev/null +++ b/java-maven/parent/README.md @@ -0,0 +1,5 @@ +# Apache OpenWhisk Parent + +This module is part of the [Apache OpenWhisk](https://openwhisk.incubator.apache.org) project. + +This is the parent project for Apache OpenWhisk. diff --git a/java-maven/parent/pom.xml b/java-maven/parent/pom.xml new file mode 100644 index 00000000..76d6f43e --- /dev/null +++ b/java-maven/parent/pom.xml @@ -0,0 +1,241 @@ + + + + 4.0.0 + + + org.apache + apache + 19 + + + + org.apache.openwhisk + openwhisk + pom + 1-SNAPSHOT + + Apache OpenWhisk - Parent + The parent project for Apache OpenWhisk + 2016 + + http://openwhisk.incubator.apache.org/ + + + GitHub + https://github.com/apache/incubator-openwhisk/issues + + + + + UTF-8 + UTF-8 + + + + scm:git:https://gitbox.apache.org/repos/asf?p=incubator-openwhisk-devtools.git + scm:git:https://gitbox.apache.org/repos/asf?p=incubator-openwhisk-devtools.git + https://gitbox.apache.org/repos/asf?p=incubator-openwhisk-devtools.git + HEAD + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + javadoc + + + + + maven + *.impl:*.internal:${site.javadoc.exclude} + + + + org.apache.maven.plugins + maven-surefire-report-plugin + + + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + true + + + attach-sources + + jar + + + + + + + org.codehaus.mojo + ianal-maven-plugin + + + + verify-legal-files + + + + true + + + + + + + org.apache.maven.plugins + maven-release-plugin + + + org.apache.maven.release + maven-release-oddeven-policy + 2.5.3 + + + + OddEvenVersionPolicy + + + + org.apache.rat + apache-rat-plugin + + + + src/main/appended-resources/META-INF/* + + velocity.log + + target/* + + README.md + + maven-eclipse.xml + .* + .*/** + + **/*.json + + DEPENDENCIES + + **/*.rej + + hs_err_*.log + + + + + verify + + check + + + + + + + + + + org.codehaus.mojo + ianal-maven-plugin + 1.0-alpha-1 + + + + + + + + Apache OpenWhisk Development List + + dev-subscribe@openwhisk.incubator.apache.org + + + dev-unsubscribe@openwhisk.incubator.apache.org + + dev at sling.apache.org + + http://mail-archives.apache.org/mod_mbox/openwhisk-dev/ + + + + http://openwhisk-dev.markmail.org/ + + + http://www.mail-archive.com/dev@openwhisk.incubator.apache.org/ + + + + + + + + + Apache OpenWhisk Project + OpenWhisk + http://openwhisk.incubator.apache.org/contributors + + + + + + + + + + junit + junit + 4.12 + test + + + + + + + + apache.snapshots + Apache Snapshot Repository + http://repository.apache.org/snapshots + + false + + + + + \ No newline at end of file diff --git a/java-maven/update-maven-plugin/README.md b/java-maven/update-maven-plugin/README.md new file mode 100644 index 00000000..0ce77af5 --- /dev/null +++ b/java-maven/update-maven-plugin/README.md @@ -0,0 +1,72 @@ +# OpenWhisk Update Maven Plugin for Java + +This project automatically installs OpenWhisk actions, packages, rules and triggers based on Annotations added to Java classes. + +## Pre-requisite + +The following softwares are required to use this project: + +* (Maven v3.3.x)[https://maven.apache.org] or above +* Java 8 or above +* OpenWhisk CLI +* [openwhisk-annotations](../annotations/) + +## Adding the Plugin + +To enable the plugin in your Maven project, add the following into the build > plugins element within your pom.xml + +``` + + org.apache.openwhisk + openwhisk-update-maven-plugin + [VERSION] + + + + update + + + + +
com.test.FunctionApp
+
+
+``` + +## Deploying to OpenWhisk + +When you build your code with `mvn clean install`, you should see log messages similar to the following: + +``` +[INFO] --- openwhisk-update-maven-plugin:0.0.1-SNAPSHOT:update (default) @ simple-email-function --- +[INFO] Updating OpenWhisk package test +[INFO] ok: updated package test +[INFO] Updating OpenWhisk action simple-function +[INFO] ok: updated action test/simple-function +[INFO] OpenWhisk Updates Successful! +``` + +This will indicate the status of the deployment to OpenWhisk. If the deployment fails, it will provide a log message with details on how to resolve. You can add the `-X` parameter to enable debug level logging in the plugin. + +## FAQ + +**How do I change the Whisk CLI Path?** + +Add a parameter cli into the configuration element of the plugin with the path to the Whisk CLI for your environment, for example to support using BlueMix Functions: + +``` + + bx wsk +
[...]
+
+``` + +**How do I update more than one class in my project in OpenWhisk?** + +The main element is a comma-separated list of classes, the plugin will evaluate each class in the list and install anything defined in annotations. For example: + +``` + +
com.test.FunctionApp,com.test.FunctionApp2
+
+``` \ No newline at end of file diff --git a/openwhisk-install-maven-plugin/pom.xml b/java-maven/update-maven-plugin/pom.xml similarity index 76% rename from openwhisk-install-maven-plugin/pom.xml rename to java-maven/update-maven-plugin/pom.xml index 77a6f62d..bcb6834e 100644 --- a/openwhisk-install-maven-plugin/pom.xml +++ b/java-maven/update-maven-plugin/pom.xml @@ -1,7 +1,31 @@ + + 4.0.0 + + + org.apache.openwhisk + openwhisk + 1-SNAPSHOT + + org.apache.openwhisk openwhisk-update-maven-plugin diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java similarity index 100% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/TYPE.java diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java similarity index 99% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java index 44be34e0..4993dbc7 100644 --- a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java @@ -138,6 +138,7 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("IOException occured executing OpenWhisk update", e); } } + log.info("OpenWhisk Updates Successful!"); } diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java similarity index 100% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java similarity index 96% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java index 853ac99f..288dfef2 100644 --- a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java @@ -45,6 +45,7 @@ public abstract class Command { public Command(List init, String pkg, String name, List globalFlags) { log.debug("Creating command for {}/{}", pkg, name); + this.setName(name); this.cmd.addAll(init); this.cmd.add(getType()); this.cmd.add("update"); @@ -78,7 +79,7 @@ protected void addParameters(Parameter[] parameters) { public void execute() throws IOException, MojoExecutionException { - log.info("Updating OpenWhisk {} {}", getType(), getName()); + log.info("Updating OpenWhisk {} {}", getType(), name); cmd.addAll(globalFlags); @@ -90,8 +91,6 @@ public void execute() throws IOException, MojoExecutionException { readInput(pr.getInputStream(), false); if (readInput(pr.getErrorStream(), true)) { throw new MojoExecutionException("Call to OpenWhisk failed!"); - } else { - log.info("OpenWhisk Function Updated!"); } } diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java similarity index 100% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java similarity index 100% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java diff --git a/openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java similarity index 100% rename from openwhisk-install-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java rename to java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java diff --git a/maven-java/.editorconfig b/maven-java-example/.editorconfig similarity index 100% rename from maven-java/.editorconfig rename to maven-java-example/.editorconfig diff --git a/maven-java/.gitignore b/maven-java-example/.gitignore similarity index 100% rename from maven-java/.gitignore rename to maven-java-example/.gitignore diff --git a/maven-java/.mvn/wrapper/maven-wrapper.jar b/maven-java-example/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from maven-java/.mvn/wrapper/maven-wrapper.jar rename to maven-java-example/.mvn/wrapper/maven-wrapper.jar diff --git a/maven-java/.mvn/wrapper/maven-wrapper.properties b/maven-java-example/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from maven-java/.mvn/wrapper/maven-wrapper.properties rename to maven-java-example/.mvn/wrapper/maven-wrapper.properties diff --git a/maven-java/README.md b/maven-java-example/README.md similarity index 100% rename from maven-java/README.md rename to maven-java-example/README.md diff --git a/maven-java/dependency-reduced-pom.xml b/maven-java-example/dependency-reduced-pom.xml similarity index 100% rename from maven-java/dependency-reduced-pom.xml rename to maven-java-example/dependency-reduced-pom.xml diff --git a/maven-java/mvnw b/maven-java-example/mvnw similarity index 100% rename from maven-java/mvnw rename to maven-java-example/mvnw diff --git a/maven-java/mvnw.cmd b/maven-java-example/mvnw.cmd similarity index 100% rename from maven-java/mvnw.cmd rename to maven-java-example/mvnw.cmd diff --git a/maven-java/pom.xml b/maven-java-example/pom.xml similarity index 96% rename from maven-java/pom.xml rename to maven-java-example/pom.xml index 0db049e5..aad81135 100644 --- a/maven-java/pom.xml +++ b/maven-java-example/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 openwhisk.example.maven - maven-java + maven-java-example 1.0-SNAPSHOT jar OpenWhisk::Examples::Maven with External Deps diff --git a/maven-java/src/main/java/org/apache/openwhisk/example/maven/App.java b/maven-java-example/src/main/java/org/apache/openwhisk/example/maven/App.java similarity index 100% rename from maven-java/src/main/java/org/apache/openwhisk/example/maven/App.java rename to maven-java-example/src/main/java/org/apache/openwhisk/example/maven/App.java diff --git a/openwhisk-annotations/pom.xml b/openwhisk-annotations/pom.xml deleted file mode 100644 index d54af145..00000000 --- a/openwhisk-annotations/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - 4.0.0 - - - org.apache - apache - 19 - - - - org.apache.openwhisk - openwhisk-annotations - 0.0.1-SNAPSHOT - Apache OpenWhisk Annotations - - - UTF-8 - 1.8 - 1.8 - - \ No newline at end of file diff --git a/openwhisk-install-maven-plugin/src/it/settings.xml b/openwhisk-install-maven-plugin/src/it/settings.xml deleted file mode 100644 index c8f77f0b..00000000 --- a/openwhisk-install-maven-plugin/src/it/settings.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - it-repo - - true - - - - local.central - @localRepositoryUrl@ - - true - - - true - - - - - - local.central - @localRepositoryUrl@ - - true - - - true - - - - - - diff --git a/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml b/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml deleted file mode 100644 index 5d0d77d8..00000000 --- a/openwhisk-install-maven-plugin/src/it/simple-it/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - 4.0.0 - - org.apache.openwhisk.it - simple-it - 1.0-SNAPSHOT - - A simple IT verifying the basic use case. - - - UTF-8 - - - - - - @project.groupId@ - @project.artifactId@ - @project.version@ - - - touch - validate - - touch - - - - - - - diff --git a/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy b/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy deleted file mode 100644 index 7b307c78..00000000 --- a/openwhisk-install-maven-plugin/src/it/simple-it/verify.groovy +++ /dev/null @@ -1,3 +0,0 @@ -File touchFile = new File( basedir, "target/touch.txt" ); - -assert touchFile.isFile() From 24b14ab4296b12258857405821473c4d84785675 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:26:53 -0400 Subject: [PATCH 03/18] Update README.md --- java-maven/annotations/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java-maven/annotations/README.md b/java-maven/annotations/README.md index 06cb6fdd..ebc76f86 100644 --- a/java-maven/annotations/README.md +++ b/java-maven/annotations/README.md @@ -6,7 +6,7 @@ This project allows developers to define actions, packages, rules and triggers f The following softwares are required to use this project: -* (Maven v3.3.x)[https://maven.apache.org] or above +* [Maven v3.3.x](https://maven.apache.org) or above * Java 8 or above * OpenWhisk CLI * [openwhisk-update-maven-plugin](../update-maven-plugin/) @@ -52,4 +52,4 @@ The `@Trigger` annotation defines an OpenWhisk [trigger](https://github.com/apac ``` @Trigger(feed = "/whisk.system/alarms/alarm", name = "dostuff", packageName = "test", parameters = { @Parameter(key = "cron", value = "5 * * * *")}) public class FunctionApp { -``` \ No newline at end of file +``` From 23e5ffe669876792b1e64ae14ff5e1af7020a18c Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:27:14 -0400 Subject: [PATCH 04/18] Update README.md --- java-maven/update-maven-plugin/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java-maven/update-maven-plugin/README.md b/java-maven/update-maven-plugin/README.md index 0ce77af5..18387009 100644 --- a/java-maven/update-maven-plugin/README.md +++ b/java-maven/update-maven-plugin/README.md @@ -6,7 +6,7 @@ This project automatically installs OpenWhisk actions, packages, rules and trigg The following softwares are required to use this project: -* (Maven v3.3.x)[https://maven.apache.org] or above +* [Maven v3.3.x](https://maven.apache.org) or above * Java 8 or above * OpenWhisk CLI * [openwhisk-annotations](../annotations/) @@ -69,4 +69,4 @@ The main element is a comma-separated list of classes, the plugin will evaluate
com.test.FunctionApp,com.test.FunctionApp2
-``` \ No newline at end of file +``` From 5480db47e55f47f32d866c4085da72c0738b6414 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:42:12 -0400 Subject: [PATCH 05/18] Update README.md --- java-maven/action-archetype/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java-maven/action-archetype/README.md b/java-maven/action-archetype/README.md index d85408c4..144389e8 100644 --- a/java-maven/action-archetype/README.md +++ b/java-maven/action-archetype/README.md @@ -1,12 +1,14 @@ # Maven Archetype for Java Action +This module is part of the Apache OpenWhisk project. + This archetype helps to generate the Java Action template project. ## Pre-requisite The following softwares are required to build and deploy a Java Action to OpenWhisk: -* (Maven v3.3.x)[https://maven.apache.org] or above +* [Maven v3.3.x]https://maven.apache.org) or above * Java 8 or above [WSK CLI](https://github.com/apache/incubator-openwhisk/blob/master/docs/cli.md) is configured @@ -35,4 +37,4 @@ After successful deployment of the function, we can invoke the same via `wsk act ```json {"greetings": "Hello! Welcome to OpenWhisk" } -``` \ No newline at end of file +``` From a891205b0ec817d7d47749aa2a639792a3ad5016 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:42:22 -0400 Subject: [PATCH 06/18] Update README.md --- java-maven/action-archetype/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-maven/action-archetype/README.md b/java-maven/action-archetype/README.md index 144389e8..1e3f3f7f 100644 --- a/java-maven/action-archetype/README.md +++ b/java-maven/action-archetype/README.md @@ -8,7 +8,7 @@ This archetype helps to generate the Java Action template project. The following softwares are required to build and deploy a Java Action to OpenWhisk: -* [Maven v3.3.x]https://maven.apache.org) or above +* [Maven v3.3.x](https://maven.apache.org) or above * Java 8 or above [WSK CLI](https://github.com/apache/incubator-openwhisk/blob/master/docs/cli.md) is configured From bc8addda42f897c29ad9bebce061cf90152f2936 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:42:56 -0400 Subject: [PATCH 07/18] Update README.md --- java-maven/action-archetype/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-maven/action-archetype/README.md b/java-maven/action-archetype/README.md index 1e3f3f7f..8de1b90c 100644 --- a/java-maven/action-archetype/README.md +++ b/java-maven/action-archetype/README.md @@ -1,6 +1,6 @@ # Maven Archetype for Java Action -This module is part of the Apache OpenWhisk project. +This module is part of the [Apache OpenWhisk](http://openwhisk.incubator.apache.org/) project. This archetype helps to generate the Java Action template project. From 529399142937e24dfd7286a17c964db19b6ddec5 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:43:33 -0400 Subject: [PATCH 08/18] Update README.md --- java-maven/annotations/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java-maven/annotations/README.md b/java-maven/annotations/README.md index ebc76f86..a3308dd7 100644 --- a/java-maven/annotations/README.md +++ b/java-maven/annotations/README.md @@ -1,5 +1,7 @@ # OpenWhisk Annotations for Java +This module is part of the [Apache OpenWhisk](http://openwhisk.incubator.apache.org/) project. + This project allows developers to define actions, packages, rules and triggers from annotations on java classes. ## Pre-requisite From a4c92d4c4534d71899ed36fdd605f23eabf39161 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 09:43:53 -0400 Subject: [PATCH 09/18] Update README.md --- java-maven/update-maven-plugin/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java-maven/update-maven-plugin/README.md b/java-maven/update-maven-plugin/README.md index 18387009..0919fe6a 100644 --- a/java-maven/update-maven-plugin/README.md +++ b/java-maven/update-maven-plugin/README.md @@ -1,5 +1,7 @@ # OpenWhisk Update Maven Plugin for Java +This module is part of the [Apache OpenWhisk](http://openwhisk.incubator.apache.org/) project. + This project automatically installs OpenWhisk actions, packages, rules and triggers based on Annotations added to Java classes. ## Pre-requisite From dc032075a1483ac3e9918e031c0f47b8cfafa648 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 10:21:00 -0400 Subject: [PATCH 10/18] Adding Travis configuration --- .gitignore | 3 ++- .travis.yml | 5 ++++- java-maven/annotations/.travis/build.sh | 10 ++++++++++ java-maven/annotations/.travis/setup.sh | 10 ++++++++++ java-maven/parent/.travis/build.sh | 10 ++++++++++ java-maven/parent/.travis/setup.sh | 10 ++++++++++ java-maven/update-maven-plugin/.travis/build.sh | 10 ++++++++++ java-maven/update-maven-plugin/.travis/setup.sh | 10 ++++++++++ 8 files changed, 66 insertions(+), 2 deletions(-) create mode 100755 java-maven/annotations/.travis/build.sh create mode 100755 java-maven/annotations/.travis/setup.sh create mode 100755 java-maven/parent/.travis/build.sh create mode 100755 java-maven/parent/.travis/setup.sh create mode 100755 java-maven/update-maven-plugin/.travis/build.sh create mode 100755 java-maven/update-maven-plugin/.travis/setup.sh diff --git a/.gitignore b/.gitignore index 81e044a2..6c652001 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ target/ .project .settings/ bin/ -.classpath \ No newline at end of file +.classpath +.DS_Store \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8748b274..763e792f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,10 @@ env: - DOCKER_COMPOSE_VERSION: 1.13.0 matrix: - TOOL: docker-compose - - TOOL: java-action-archetype + - TOOL: java-maven/parent + - TOOL: java-maven/annotations + - TOOL: java-maven/update-maven-plugin + - TOOL: java-maven/action-archetype services: - docker diff --git a/java-maven/annotations/.travis/build.sh b/java-maven/annotations/.travis/build.sh new file mode 100755 index 00000000..d29d3fc5 --- /dev/null +++ b/java-maven/annotations/.travis/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -V test + +#TODO steps that can push this artifact to nexus diff --git a/java-maven/annotations/.travis/setup.sh b/java-maven/annotations/.travis/setup.sh new file mode 100755 index 00000000..f2c79519 --- /dev/null +++ b/java-maven/annotations/.travis/setup.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -x -e +uname -sm + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install diff --git a/java-maven/parent/.travis/build.sh b/java-maven/parent/.travis/build.sh new file mode 100755 index 00000000..d29d3fc5 --- /dev/null +++ b/java-maven/parent/.travis/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -V test + +#TODO steps that can push this artifact to nexus diff --git a/java-maven/parent/.travis/setup.sh b/java-maven/parent/.travis/setup.sh new file mode 100755 index 00000000..f2c79519 --- /dev/null +++ b/java-maven/parent/.travis/setup.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -x -e +uname -sm + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install diff --git a/java-maven/update-maven-plugin/.travis/build.sh b/java-maven/update-maven-plugin/.travis/build.sh new file mode 100755 index 00000000..d29d3fc5 --- /dev/null +++ b/java-maven/update-maven-plugin/.travis/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -V test + +#TODO steps that can push this artifact to nexus diff --git a/java-maven/update-maven-plugin/.travis/setup.sh b/java-maven/update-maven-plugin/.travis/setup.sh new file mode 100755 index 00000000..f2c79519 --- /dev/null +++ b/java-maven/update-maven-plugin/.travis/setup.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -x -e +uname -sm + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +TOOLDIR="$SCRIPTDIR/../" + +cd $TOOLDIR + +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install From 9dc985a7a4572957e0db85fb16da5ee16f77fea4 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 11:20:35 -0400 Subject: [PATCH 11/18] Removing some of the child projects out of the travis build until the parent is released --- .travis.yml | 4 ++-- java-maven/action-archetype/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 763e792f..9e479768 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ env: matrix: - TOOL: docker-compose - TOOL: java-maven/parent - - TOOL: java-maven/annotations - - TOOL: java-maven/update-maven-plugin +# - TOOL: java-maven/annotations +# - TOOL: java-maven/update-maven-plugin - TOOL: java-maven/action-archetype services: diff --git a/java-maven/action-archetype/pom.xml b/java-maven/action-archetype/pom.xml index 51bc9db8..3022a2d1 100644 --- a/java-maven/action-archetype/pom.xml +++ b/java-maven/action-archetype/pom.xml @@ -3,12 +3,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - + org.apache.openwhisk openwhisk-action-archetype From 42e0513fcf08bd2012ba62a64bc5f1a4c5fd5261 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 11:56:43 -0400 Subject: [PATCH 12/18] Updating the travis builds to trigger the required parent build --- .travis.yml | 4 ++-- java-maven/action-archetype/.travis/setup.sh | 11 +++++++++++ java-maven/annotations/.travis/setup.sh | 7 +++++++ java-maven/update-maven-plugin/.travis/setup.sh | 9 +++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e479768..763e792f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ env: matrix: - TOOL: docker-compose - TOOL: java-maven/parent -# - TOOL: java-maven/annotations -# - TOOL: java-maven/update-maven-plugin + - TOOL: java-maven/annotations + - TOOL: java-maven/update-maven-plugin - TOOL: java-maven/action-archetype services: diff --git a/java-maven/action-archetype/.travis/setup.sh b/java-maven/action-archetype/.travis/setup.sh index f2c79519..5a5330fb 100755 --- a/java-maven/action-archetype/.travis/setup.sh +++ b/java-maven/action-archetype/.travis/setup.sh @@ -5,6 +5,17 @@ uname -sm SCRIPTDIR=$(cd $(dirname "$0") && pwd) TOOLDIR="$SCRIPTDIR/../" +# Build the parent so this compiles +mkdir -p $TOOLDIR/target +cd $TOOLDIR/target +git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/annotations +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/update-maven-plugin +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install + cd $TOOLDIR mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install diff --git a/java-maven/annotations/.travis/setup.sh b/java-maven/annotations/.travis/setup.sh index f2c79519..6aa87cff 100755 --- a/java-maven/annotations/.travis/setup.sh +++ b/java-maven/annotations/.travis/setup.sh @@ -5,6 +5,13 @@ uname -sm SCRIPTDIR=$(cd $(dirname "$0") && pwd) TOOLDIR="$SCRIPTDIR/../" +# Build the parent so this compiles +mkdir -p $TOOLDIR/target +cd $TOOLDIR/target +git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install + cd $TOOLDIR mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install diff --git a/java-maven/update-maven-plugin/.travis/setup.sh b/java-maven/update-maven-plugin/.travis/setup.sh index f2c79519..5e043c3b 100755 --- a/java-maven/update-maven-plugin/.travis/setup.sh +++ b/java-maven/update-maven-plugin/.travis/setup.sh @@ -5,6 +5,15 @@ uname -sm SCRIPTDIR=$(cd $(dirname "$0") && pwd) TOOLDIR="$SCRIPTDIR/../" +# Build the parent so this compiles +mkdir -p $TOOLDIR/target +cd $TOOLDIR/target +git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install +cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/annotations +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install + cd $TOOLDIR mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install From cb1f735093520bcc43bfeecd5cee9e9443e28a0d Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 14:10:57 -0400 Subject: [PATCH 13/18] Fixing to check if an item exists before updating as it seems like triggers don't support updates if not existing and removed the package option from triggers and rules --- .../apache/openwhisk/annotations/Rule.java | 5 -- .../apache/openwhisk/annotations/Trigger.java | 5 -- .../openwhisk/maven/UpdateWhiskMojo.java | 10 ++++ .../openwhisk/maven/commands/Command.java | 48 ++++++++++++++++++- .../maven/commands/PackageCommand.java | 2 +- .../openwhisk/maven/commands/RuleCommand.java | 2 +- .../maven/commands/TriggerCommand.java | 2 +- 7 files changed, 60 insertions(+), 14 deletions(-) diff --git a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java index 701e6491..7f45cfc8 100644 --- a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Rule.java @@ -39,11 +39,6 @@ * The name of the trigger */ String name(); - - /** - * The name of the package for this rule - */ - String packageName() default ""; /** * The name of the trigger to execute this rule diff --git a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java index 211a907a..c784b225 100644 --- a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Trigger.java @@ -44,11 +44,6 @@ * The name of the trigger */ String name(); - - /** - * The name of the package for this trigger - */ - String packageName() default ""; /** * The parameter values for the trigger diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java index 4993dbc7..a2aaf3ee 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java @@ -31,9 +31,11 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.openwhisk.annotations.Action; import org.apache.openwhisk.annotations.Package; +import org.apache.openwhisk.annotations.Rule; import org.apache.openwhisk.annotations.Trigger; import org.apache.openwhisk.maven.commands.ActionCommand; import org.apache.openwhisk.maven.commands.PackageCommand; +import org.apache.openwhisk.maven.commands.RuleCommand; import org.apache.openwhisk.maven.commands.TriggerCommand; import org.codehaus.plexus.util.StringUtils; import org.slf4j.Logger; @@ -214,6 +216,14 @@ private void processAnnotations(String mc, List cmd, List global } } + Rule[] rules = mainClass.getDeclaredAnnotationsByType(Rule.class); + if (rules != null) { + for (Rule rule : rules) { + RuleCommand rc = new RuleCommand(rule, cmd, globalFlags); + rc.execute(); + } + } + } catch (ClassNotFoundException e) { log.error("Unable to find main class: " + main, e); } catch (MalformedURLException e) { diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java index 288dfef2..59ce8ffc 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java @@ -39,16 +39,41 @@ public abstract class Command { protected final List cmd = new ArrayList(); + private final List getCmd = new ArrayList(); + private List globalFlags = null; private String name; + + + public Command(List init, String name, List globalFlags) { + this(init, "", name, globalFlags); + } public Command(List init, String pkg, String name, List globalFlags) { log.debug("Creating command for {}/{}", pkg, name); this.setName(name); this.cmd.addAll(init); this.cmd.add(getType()); - this.cmd.add("update"); + + // construct the get command + + getCmd.addAll(init); + getCmd.add(getType()); + getCmd.add("get"); + if (StringUtils.isNotBlank(pkg)) { + getCmd.add(pkg + "/" + name); + } else { + getCmd.add(name); + } + getCmd.addAll(globalFlags); + + if (itemExists()) { + this.cmd.add("update"); + } else { + + this.cmd.add("create"); + } if (StringUtils.isNotBlank(pkg)) { this.cmd.add(pkg + "/" + name); } else { @@ -57,6 +82,27 @@ public Command(List init, String pkg, String name, List globalFl this.globalFlags = globalFlags; } + private boolean itemExists() { + boolean exists = true; + try { + log.debug("Checking to see if {} {} exists", getType(), name); + + log.debug("Executing OpenWhisk CLI Command with command: {}", getCmd); + ProcessBuilder builder = new ProcessBuilder(); + builder.command(getCmd); + Process pr = builder.start(); + + readInput(pr.getInputStream(), false); + if (readInput(pr.getErrorStream(), false)) { + exists = false; + } + } catch (Exception e) { + log.warn("Exception checking to see if entity exists, ", e); + exists = false; + } + return exists; + } + protected void addAnnotations(Annotation[] annotations) { if (annotations != null) { for (Annotation a : annotations) { diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java index 8a482ce9..ef5c8fc6 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java @@ -31,7 +31,7 @@ public class PackageCommand extends Command { private final Logger log = LoggerFactory.getLogger(PackageCommand.class); public PackageCommand(Package pkg, List init, List globalFlags) { - super(init, "", pkg.name(), globalFlags); + super(init, pkg.name(), globalFlags); this.addAnnotations(pkg.annotations()); this.addParameters(pkg.parameters()); diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java index f4d72501..79a8d888 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java @@ -30,7 +30,7 @@ public class RuleCommand extends Command { private final Logger log = LoggerFactory.getLogger(RuleCommand.class); public RuleCommand(Rule rule, List init, List globalFlags) { - super(init, rule.packageName(), rule.name(), globalFlags); + super(init, rule.name(), globalFlags); log.debug("Setting trigger name to {}", rule.triggerName()); cmd.add(rule.triggerName()); diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java index 46daef92..99358513 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java @@ -31,7 +31,7 @@ public class TriggerCommand extends Command { private final Logger log = LoggerFactory.getLogger(RuleCommand.class); public TriggerCommand(Trigger trigger, List init, List globalFlags) { - super(init, trigger.packageName(), trigger.name(), globalFlags); + super(init, trigger.name(), globalFlags); this.addAnnotations(trigger.annotations()); this.addParameters(trigger.parameters()); From 47afa9177307a6633135c15b1007a0dc35c6a7ef Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 14:15:38 -0400 Subject: [PATCH 14/18] Updating documentation to match the latest changes --- java-maven/annotations/README.md | 4 +- java-maven/update-maven-plugin/README.md | 78 +++++++++++++++++++++++- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/java-maven/annotations/README.md b/java-maven/annotations/README.md index a3308dd7..d42dc0c5 100644 --- a/java-maven/annotations/README.md +++ b/java-maven/annotations/README.md @@ -42,7 +42,7 @@ Our recommendation would be to add this to a package-info.java class for the pac The `@Rule` annotation defines an OpenWhisk [rule](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md): ``` -@Rule(actionName="test/simple-function", name = "dostuffrule", packageName = "test", triggerName="test/dostuff") +@Rule(actionName="test/simple-function", name = "dostuffrule", triggerName="dostuff") public class FunctionApp { ``` @@ -52,6 +52,6 @@ public class FunctionApp { The `@Trigger` annotation defines an OpenWhisk [trigger](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md): ``` -@Trigger(feed = "/whisk.system/alarms/alarm", name = "dostuff", packageName = "test", parameters = { @Parameter(key = "cron", value = "5 * * * *")}) +@Trigger(feed = "/whisk.system/alarms/alarm", name = "dostuff", parameters = { @Parameter(key = "cron", value = "5 * * * *")}) public class FunctionApp { ``` diff --git a/java-maven/update-maven-plugin/README.md b/java-maven/update-maven-plugin/README.md index 0919fe6a..6a8f44ce 100644 --- a/java-maven/update-maven-plugin/README.md +++ b/java-maven/update-maven-plugin/README.md @@ -40,11 +40,83 @@ To enable the plugin in your Maven project, add the following into the build > p When you build your code with `mvn clean install`, you should see log messages similar to the following: ``` -[INFO] --- openwhisk-update-maven-plugin:0.0.1-SNAPSHOT:update (default) @ simple-email-function --- +[INFO] ok: got package test +[INFO] { +[INFO] "namespace": "user@email_dev", +[INFO] "name": "test", +[INFO] "version": "0.0.13", +[INFO] "publish": false, +[INFO] "binding": {}, +[INFO] "actions": [ +[INFO] { +[INFO] "name": "simple-email", +[INFO] "version": "0.0.11", +[INFO] "annotations": [ +[INFO] { +[INFO] "key": "exec", +[INFO] "value": "java" +[INFO] }, +[INFO] { +[INFO] "key": "web-export", +[INFO] "value": true +[INFO] }, +[INFO] { +[INFO] "key": "raw-http", +[INFO] "value": false +[INFO] }, +[INFO] { +[INFO] "key": "final", +[INFO] "value": true +[INFO] } +[INFO] ] +[INFO] } +[INFO] ] +[INFO] } [INFO] Updating OpenWhisk package test [INFO] ok: updated package test -[INFO] Updating OpenWhisk action simple-function -[INFO] ok: updated action test/simple-function +[INFO] ok: got action test/simple-action +[INFO] { +[INFO] "namespace": "user@email/test", +[INFO] "name": "simple-action", +[INFO] "version": "0.0.11", +[INFO] "exec": { +[INFO] "kind": "java", +[INFO] "main": "com.test.FunctionApp", +[INFO] "binary": true +[INFO] }, +[INFO] "annotations": [ +[INFO] { +[INFO] "key": "exec", +[INFO] "value": "java" +[INFO] }, +[INFO] { +[INFO] "key": "web-export", +[INFO] "value": true +[INFO] }, +[INFO] { +[INFO] "key": "raw-http", +[INFO] "value": false +[INFO] }, +[INFO] { +[INFO] "key": "final", +[INFO] "value": true +[INFO] } +[INFO] ], +[INFO] "parameters": [ +[INFO] { +[INFO] "key": "Name", +[INFO] "value": "Bob" +[INFO] } +[INFO] ], +[INFO] "limits": { +[INFO] "timeout": 60000, +[INFO] "memory": 256, +[INFO] "logs": 10 +[INFO] }, +[INFO] "publish": false +[INFO] } +[INFO] Updating OpenWhisk action simple-action +[INFO] ok: updated action test/simple-action [INFO] OpenWhisk Updates Successful! ``` From 7c87be57cc37364c1bf8a66217dd351dfa5a9044 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 14:58:33 -0400 Subject: [PATCH 15/18] Adding support for Action Sequences --- java-maven/annotations/README.md | 11 +++++++++++ .../java/org/apache/openwhisk/annotations/Action.java | 10 ---------- .../org/apache/openwhisk/maven/UpdateWhiskMojo.java | 10 ++++++++++ .../openwhisk/maven/commands/ActionCommand.java | 5 ----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/java-maven/annotations/README.md b/java-maven/annotations/README.md index d42dc0c5..1ed56c4a 100644 --- a/java-maven/annotations/README.md +++ b/java-maven/annotations/README.md @@ -26,6 +26,17 @@ The `@Action` annotation defines an OpenWhisk [action](https://github.com/apache public class FunctionApp { ``` + + +### ActionSequence Annotation + +The `@ActionSequence` annotation defines an OpenWhisk [action](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md) sequence: + +``` +@Action(name = "simple-function", packageName = "test", parameters = { @Parameter(key = "Name", value = "Bob") }) +public class FunctionApp { +``` + ### Package Annotation The `@Package` annotation defines an OpenWhisk [package](https://github.com/apache/incubator-openwhisk/blob/master/docs/packages.md): diff --git a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java index 9912c0bd..42ce33bc 100644 --- a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/Action.java @@ -34,11 +34,6 @@ */ Annotation[] annotations() default {}; - /** - * Use provided docker image (a path on DockerHub) to run the action - */ - String docker() default ""; - /** * The maximum log size LIMIT in MB for the action (default 10) */ @@ -64,11 +59,6 @@ */ Parameter[] parameters() default {}; - /** - * Treat ACTION as comma separated sequence of actions to invoke - */ - boolean sequence() default false; - /** * The timeout LIMIT in milliseconds after which the action is terminated * (default 60000) diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java index a2aaf3ee..c5f781a8 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java @@ -30,10 +30,12 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.openwhisk.annotations.Action; +import org.apache.openwhisk.annotations.ActionSequence; import org.apache.openwhisk.annotations.Package; import org.apache.openwhisk.annotations.Rule; import org.apache.openwhisk.annotations.Trigger; import org.apache.openwhisk.maven.commands.ActionCommand; +import org.apache.openwhisk.maven.commands.ActionSequenceCommand; import org.apache.openwhisk.maven.commands.PackageCommand; import org.apache.openwhisk.maven.commands.RuleCommand; import org.apache.openwhisk.maven.commands.TriggerCommand; @@ -208,6 +210,14 @@ private void processAnnotations(String mc, List cmd, List global } } + ActionSequence[] actionSequences = mainClass.getDeclaredAnnotationsByType(ActionSequence.class); + if (actionSequences != null) { + for (ActionSequence actionSequence : actionSequences) { + ActionSequenceCommand asc = new ActionSequenceCommand(actionSequence, cmd, globalFlags); + asc.execute(); + } + } + Trigger[] triggers = mainClass.getDeclaredAnnotationsByType(Trigger.class); if (triggers != null) { for (Trigger trigger : triggers) { diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java index 5b792dc2..52d29740 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java @@ -40,11 +40,6 @@ public ActionCommand(Action action, List init, List globalFlags, this.addAnnotations(action.annotations()); this.addParameters(action.parameters()); - if (StringUtils.isNotBlank(action.docker())) { - log.debug("Setting docker to " + action.docker()); - cmd.add("--docker"); - cmd.add(action.docker()); - } if (action.logsize() != -1) { log.debug("Setting logsize to " + action.logsize()); cmd.add("--logsize"); From c11c4b5a5daa62e2e6f2a8b84f19b76d2e9d50c6 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 12 Apr 2018 15:47:26 -0400 Subject: [PATCH 16/18] Adding missing classes --- java-maven/annotations/pom.xml | 1 - .../openwhisk/annotations/ActionSequence.java | 87 +++++++++++++++++++ .../update-maven-plugin/.travis/setup.sh | 6 +- java-maven/update-maven-plugin/pom.xml | 3 - .../maven/commands/ActionSequenceCommand.java | 76 ++++++++++++++++ 5 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/ActionSequence.java create mode 100644 java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java diff --git a/java-maven/annotations/pom.xml b/java-maven/annotations/pom.xml index 727f2888..bfd80d58 100644 --- a/java-maven/annotations/pom.xml +++ b/java-maven/annotations/pom.xml @@ -27,7 +27,6 @@ - org.apache.openwhisk openwhisk-annotations 0.0.1-SNAPSHOT Apache OpenWhisk Annotations diff --git a/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/ActionSequence.java b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/ActionSequence.java new file mode 100644 index 00000000..3f850a4b --- /dev/null +++ b/java-maven/annotations/src/main/java/org/apache/openwhisk/annotations/ActionSequence.java @@ -0,0 +1,87 @@ +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.annotations; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * An annotation to indicate that the specified class should register an + * OpenWhisk action sequence. Action sequences will not attempt to upload the + * class code, but will instead be created as a sequence of other actions. + * + * @see https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md + */ +@Retention(RUNTIME) +@Target(TYPE) +public @interface ActionSequence { + + /** + * The annotation values for the action + */ + Annotation[] annotations() default {}; + + /** + * The maximum log size LIMIT in MB for the action (default 10) + */ + int logsize() default -1; + + /** + * the maximum memory LIMIT in MB for the action (default 256) + */ + int memory() default -1; + + /** + * The name of the action + */ + String name(); + + /** + * The name of the package for this action + */ + String packageName() default ""; + + /** + * The parameter values for the action + */ + Parameter[] parameters() default {}; + + /** + * The comma separated sequence of actions to invoke + */ + String sequence(); + + /** + * The timeout LIMIT in milliseconds after which the action is terminated + * (default 60000) + */ + int timeout() default -1; + + /** + * Treat ACTION as a web action, a raw HTTP web action, or as a standard action; + * yes | true = web action, raw = raw HTTP web action, no | false = standard + * action + */ + String web() default ""; + + /** + * Secure the web action. where SECRET is true, false, or any string. Only valid + * when the ACTION is a web action + */ + String websecure() default ""; +} diff --git a/java-maven/update-maven-plugin/.travis/setup.sh b/java-maven/update-maven-plugin/.travis/setup.sh index 5e043c3b..ece1e793 100755 --- a/java-maven/update-maven-plugin/.travis/setup.sh +++ b/java-maven/update-maven-plugin/.travis/setup.sh @@ -9,10 +9,8 @@ TOOLDIR="$SCRIPTDIR/../" mkdir -p $TOOLDIR/target cd $TOOLDIR/target git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git -cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent -mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install -cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/annotations -mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -q clean install -f $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent/pom.xml +mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -q clean install -f $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/annotations/pom.xml cd $TOOLDIR diff --git a/java-maven/update-maven-plugin/pom.xml b/java-maven/update-maven-plugin/pom.xml index bcb6834e..3550f10a 100644 --- a/java-maven/update-maven-plugin/pom.xml +++ b/java-maven/update-maven-plugin/pom.xml @@ -27,7 +27,6 @@ - org.apache.openwhisk openwhisk-update-maven-plugin 0.0.1-SNAPSHOT maven-plugin @@ -73,7 +72,6 @@ junit junit - 4.8.2 test @@ -83,7 +81,6 @@ org.apache.maven.plugins maven-plugin-plugin - 3.2 openwhisk-update true diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java new file mode 100644 index 00000000..128c36dd --- /dev/null +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openwhisk.maven.commands; + +import java.util.List; + +import org.apache.openwhisk.annotations.ActionSequence; +import org.codehaus.plexus.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A command for creating an action sequence in OpenWhisk + */ +public class ActionSequenceCommand extends Command { + + private final Logger log = LoggerFactory.getLogger(ActionSequenceCommand.class); + + public ActionSequenceCommand(ActionSequence actionSequence, List init, List globalFlags) { + super(init, actionSequence.packageName(), actionSequence.name(), globalFlags); + + this.addAnnotations(actionSequence.annotations()); + this.addParameters(actionSequence.parameters()); + + if (actionSequence.logsize() != -1) { + log.debug("Setting logsize to " + actionSequence.logsize()); + cmd.add("--logsize"); + cmd.add(String.valueOf(actionSequence.logsize())); + } + if (actionSequence.memory() != -1) { + log.debug("Setting memory to " + actionSequence.memory()); + cmd.add("--memory"); + cmd.add(String.valueOf(actionSequence.memory())); + } + if (StringUtils.isNotBlank(actionSequence.sequence())) { + log.debug("Setting sequence to " + actionSequence.sequence()); + cmd.add("--sequence"); + cmd.add(actionSequence.sequence()); + } + if (actionSequence.timeout() != -1) { + log.debug("Setting timeout to " + actionSequence.timeout()); + cmd.add("--timeout"); + cmd.add(String.valueOf(actionSequence.timeout())); + } + if (StringUtils.isNotBlank(actionSequence.web())) { + log.debug("Setting web to " + actionSequence.web()); + cmd.add("--web"); + cmd.add(actionSequence.web()); + } + if (StringUtils.isNotBlank(actionSequence.websecure())) { + log.debug("Setting web-secure to " + actionSequence.websecure()); + cmd.add("--web-secure"); + cmd.add(actionSequence.websecure()); + } + } + + @Override + public String getType() { + return "action"; + } + +} From 6016e141f2ff2ae2933b29572ecca6e70735072a Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 19 Apr 2018 17:13:06 -0400 Subject: [PATCH 17/18] Fixing an issue when using in maven multi-module projects --- .../openwhisk/maven/UpdateWhiskMojo.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java index c5f781a8..583ed84f 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/UpdateWhiskMojo.java @@ -100,7 +100,7 @@ public class UpdateWhiskMojo extends AbstractMojo { /** * The jar file for OpenWhisk to use for creating the functions */ - @Parameter(defaultValue = "target/${project.build.finalName}.jar", property = "openwhisk.jar", required = true) + @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.jar", property = "openwhisk.jar", required = true) private String jar; /** @@ -120,6 +120,12 @@ public class UpdateWhiskMojo extends AbstractMojo { @Parameter(defaultValue = "false", required = true) private String main; + /** + * The namespace to use to deploy to OpenWhisk + */ + @Parameter(property = "openwhisk.namespace", required = false) + private String namespace; + public void execute() throws MojoExecutionException { final List globalFlags = calculateGlobalFlags(); @@ -197,7 +203,7 @@ private void processAnnotations(String mc, List cmd, List global Package[] packages = mainClass.getDeclaredAnnotationsByType(Package.class); if (packages != null) { for (Package pkg : packages) { - PackageCommand pc = new PackageCommand(pkg, cmd, globalFlags); + PackageCommand pc = new PackageCommand(namespace, pkg, cmd, globalFlags); pc.execute(); } } @@ -205,7 +211,7 @@ private void processAnnotations(String mc, List cmd, List global Action[] actions = mainClass.getDeclaredAnnotationsByType(Action.class); if (actions != null) { for (Action action : actions) { - ActionCommand ac = new ActionCommand(action, cmd, globalFlags, jar, main); + ActionCommand ac = new ActionCommand(namespace, action, cmd, globalFlags, jar, mc); ac.execute(); } } @@ -213,7 +219,7 @@ private void processAnnotations(String mc, List cmd, List global ActionSequence[] actionSequences = mainClass.getDeclaredAnnotationsByType(ActionSequence.class); if (actionSequences != null) { for (ActionSequence actionSequence : actionSequences) { - ActionSequenceCommand asc = new ActionSequenceCommand(actionSequence, cmd, globalFlags); + ActionSequenceCommand asc = new ActionSequenceCommand(namespace, actionSequence, cmd, globalFlags); asc.execute(); } } @@ -221,7 +227,7 @@ private void processAnnotations(String mc, List cmd, List global Trigger[] triggers = mainClass.getDeclaredAnnotationsByType(Trigger.class); if (triggers != null) { for (Trigger trigger : triggers) { - TriggerCommand tc = new TriggerCommand(trigger, cmd, globalFlags); + TriggerCommand tc = new TriggerCommand(namespace, trigger, cmd, globalFlags); tc.execute(); } } @@ -229,15 +235,17 @@ private void processAnnotations(String mc, List cmd, List global Rule[] rules = mainClass.getDeclaredAnnotationsByType(Rule.class); if (rules != null) { for (Rule rule : rules) { - RuleCommand rc = new RuleCommand(rule, cmd, globalFlags); + RuleCommand rc = new RuleCommand(namespace, rule, cmd, globalFlags); rc.execute(); } } } catch (ClassNotFoundException e) { log.error("Unable to find main class: " + main, e); + throw new MojoExecutionException("Unable to find main class: " + main, e); } catch (MalformedURLException e) { log.error("Malformed URL for class directory: " + classesDirectory, e); + throw new MojoExecutionException("Malformed URL for class directory: " + classesDirectory, e); } finally { if (cl != null) { try { From cb802c882626b4d725cf95524d4032cf5c0c7529 Mon Sep 17 00:00:00 2001 From: Dan Klco Date: Thu, 19 Apr 2018 17:13:26 -0400 Subject: [PATCH 18/18] Adding support for namespaces --- .../maven/commands/ActionCommand.java | 4 +- .../maven/commands/ActionSequenceCommand.java | 5 +- .../openwhisk/maven/commands/Command.java | 84 +++++++++++-------- .../maven/commands/PackageCommand.java | 5 +- .../openwhisk/maven/commands/RuleCommand.java | 4 +- .../maven/commands/TriggerCommand.java | 4 +- 6 files changed, 59 insertions(+), 47 deletions(-) diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java index 52d29740..3ee50ac9 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionCommand.java @@ -30,8 +30,8 @@ public class ActionCommand extends Command { private final Logger log = LoggerFactory.getLogger(ActionCommand.class); - public ActionCommand(Action action, List init, List globalFlags, String jar, String main) { - super(init, action.packageName(), action.name(), globalFlags); + public ActionCommand(String namespace, Action action, List init, List globalFlags, String jar, String main) { + super(init, namespace, action.packageName(), action.name(), globalFlags); cmd.add(jar); cmd.add("--main"); diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java index 128c36dd..6960ff22 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/ActionSequenceCommand.java @@ -30,8 +30,9 @@ public class ActionSequenceCommand extends Command { private final Logger log = LoggerFactory.getLogger(ActionSequenceCommand.class); - public ActionSequenceCommand(ActionSequence actionSequence, List init, List globalFlags) { - super(init, actionSequence.packageName(), actionSequence.name(), globalFlags); + public ActionSequenceCommand(String namespace, ActionSequence actionSequence, List init, + List globalFlags) { + super(init, namespace, actionSequence.packageName(), actionSequence.name(), globalFlags); this.addAnnotations(actionSequence.annotations()); this.addParameters(actionSequence.parameters()); diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java index 59ce8ffc..2f516494 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/Command.java @@ -44,65 +44,46 @@ public abstract class Command { private List globalFlags = null; private String name; - - public Command(List init, String name, List globalFlags) { - this(init, "", name, globalFlags); + private String namespace; + + public Command(List init, String namespace, String name, List globalFlags) { + this(init, namespace, "", name, globalFlags); } - public Command(List init, String pkg, String name, List globalFlags) { + public Command(List init, String namespace, String pkg, String name, List globalFlags) { log.debug("Creating command for {}/{}", pkg, name); + this.setNamespace(namespace); this.setName(name); this.cmd.addAll(init); this.cmd.add(getType()); + + // figure out the name + String fqn = ""; + if(StringUtils.isNotEmpty(namespace)) { + fqn = "/"+namespace; + } + if (StringUtils.isNotBlank(pkg)) { + fqn+=pkg + "/" ; + } + fqn+=name; // construct the get command - getCmd.addAll(init); getCmd.add(getType()); getCmd.add("get"); - if (StringUtils.isNotBlank(pkg)) { - getCmd.add(pkg + "/" + name); - } else { - getCmd.add(name); - } + getCmd.add(fqn); getCmd.addAll(globalFlags); if (itemExists()) { this.cmd.add("update"); } else { - this.cmd.add("create"); } - if (StringUtils.isNotBlank(pkg)) { - this.cmd.add(pkg + "/" + name); - } else { - this.cmd.add(name); - } + this.cmd.add(fqn); this.globalFlags = globalFlags; } - private boolean itemExists() { - boolean exists = true; - try { - log.debug("Checking to see if {} {} exists", getType(), name); - - log.debug("Executing OpenWhisk CLI Command with command: {}", getCmd); - ProcessBuilder builder = new ProcessBuilder(); - builder.command(getCmd); - Process pr = builder.start(); - - readInput(pr.getInputStream(), false); - if (readInput(pr.getErrorStream(), false)) { - exists = false; - } - } catch (Exception e) { - log.warn("Exception checking to see if entity exists, ", e); - exists = false; - } - return exists; - } - protected void addAnnotations(Annotation[] annotations) { if (annotations != null) { for (Annotation a : annotations) { @@ -145,8 +126,33 @@ public String getName() { return name; } + public String getNamespace() { + return namespace; + } + public abstract String getType(); + private boolean itemExists() { + boolean exists = true; + try { + log.debug("Checking to see if {} {} exists", getType(), name); + + log.debug("Executing OpenWhisk CLI Command with command: {}", getCmd); + ProcessBuilder builder = new ProcessBuilder(); + builder.command(getCmd); + Process pr = builder.start(); + + readInput(pr.getInputStream(), false); + if (readInput(pr.getErrorStream(), false)) { + exists = false; + } + } catch (Exception e) { + log.warn("Exception checking to see if entity exists, ", e); + exists = false; + } + return exists; + } + private boolean readInput(InputStream is, boolean err) { boolean read = false; BufferedReader input = new BufferedReader(new InputStreamReader(is)); @@ -169,4 +175,8 @@ private boolean readInput(InputStream is, boolean err) { public void setName(String name) { this.name = name; } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } } diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java index ef5c8fc6..2c0c8e66 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/PackageCommand.java @@ -30,8 +30,8 @@ public class PackageCommand extends Command { private final Logger log = LoggerFactory.getLogger(PackageCommand.class); - public PackageCommand(Package pkg, List init, List globalFlags) { - super(init, pkg.name(), globalFlags); + public PackageCommand(String namespace, Package pkg, List init, List globalFlags) { + super(init, namespace, pkg.name(), globalFlags); this.addAnnotations(pkg.annotations()); this.addParameters(pkg.parameters()); @@ -43,6 +43,7 @@ public PackageCommand(Package pkg, List init, List globalFlags) } } + @Override public String getType() { return "package"; diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java index 79a8d888..4ee092ba 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/RuleCommand.java @@ -29,8 +29,8 @@ public class RuleCommand extends Command { private final Logger log = LoggerFactory.getLogger(RuleCommand.class); - public RuleCommand(Rule rule, List init, List globalFlags) { - super(init, rule.name(), globalFlags); + public RuleCommand(String namespace, Rule rule, List init, List globalFlags) { + super(init, namespace, rule.name(), globalFlags); log.debug("Setting trigger name to {}", rule.triggerName()); cmd.add(rule.triggerName()); diff --git a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java index 99358513..72f19535 100644 --- a/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java +++ b/java-maven/update-maven-plugin/src/main/java/org/apache/openwhisk/maven/commands/TriggerCommand.java @@ -30,8 +30,8 @@ public class TriggerCommand extends Command { private final Logger log = LoggerFactory.getLogger(RuleCommand.class); - public TriggerCommand(Trigger trigger, List init, List globalFlags) { - super(init, trigger.name(), globalFlags); + public TriggerCommand(String namespace, Trigger trigger, List init, List globalFlags) { + super(init, namespace, trigger.name(), globalFlags); this.addAnnotations(trigger.annotations()); this.addParameters(trigger.parameters());