You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by tz...@apache.org on 2022/08/04 03:47:01 UTC

[apisix-java-plugin-runner] branch main updated: feat: support release jar to apache nexus (#176)

This is an automated email from the ASF dual-hosted git repository.

tzssangglass pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/apisix-java-plugin-runner.git


The following commit(s) were added to refs/heads/main by this push:
     new 7b4fbb5  feat: support release jar to apache nexus (#176)
7b4fbb5 is described below

commit 7b4fbb50a4da0e3f6c940529651de3c3f38c73d6
Author: tzssangglass <tz...@gmail.com>
AuthorDate: Thu Aug 4 11:46:56 2022 +0800

    feat: support release jar to apache nexus (#176)
---
 .github/workflows/runner-e2e.yml                   |  7 +--
 MAINTAIN.md                                        | 56 ++++------------------
 Makefile                                           | 11 ++++-
 pom.xml                                            | 13 +----
 runner-core/pom.xml                                |  6 +--
 runner-dist/apisix-runner-bin-dist/pom.xml         |  2 +-
 runner-dist/apisix-runner-src-dist/pom.xml         |  4 +-
 runner-dist/pom.xml                                |  4 +-
 runner-plugin-sdk/pom.xml                          |  2 +-
 runner-plugin/pom.xml                              |  4 +-
 runner-starter/pom.xml                             |  9 +---
 .../apisix/plugin/runner/HotReloadProcess.java     | 53 ++++++++++++++++++--
 .../plugin/runner/PluginRunnerApplication.java     |  9 +++-
 runner-starter/src/main/resources/application.yaml |  1 +
 sample/pom.xml                                     |  4 +-
 15 files changed, 93 insertions(+), 92 deletions(-)

diff --git a/.github/workflows/runner-e2e.yml b/.github/workflows/runner-e2e.yml
index 4e46548..47bcfee 100644
--- a/.github/workflows/runner-e2e.yml
+++ b/.github/workflows/runner-e2e.yml
@@ -27,10 +27,6 @@ on:
     branches:
       - main
 
-env:
-  JAVA_RUNNER_VERSION: 0.2.0
-
-
 jobs:
   run-test:
     runs-on: ubuntu-latest
@@ -51,13 +47,14 @@ jobs:
 
     - name: build runner
       run: |
+        sed -i 's/apisix-runner-plugin-sdk/apisix-runner-plugin/' runner-core/pom.xml
         cp ./sample/src/main/java/org/apache/apisix/plugin/runner/filter/* ./runner-plugin/src/main/java/org/apache/apisix/plugin/runner/filter/
         ./mvnw clean install -Dgpg.skip=true
 
     - name: startup runner
       run: |
         cd dist
-        tar -zxvf apache-apisix-java-plugin-runner-$JAVA_RUNNER_VERSION-bin.tar.gz
+        tar -zxvf apache-apisix-java-plugin-runner-*bin.tar.gz
         java -jar -DAPISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock -DAPISIX_CONF_EXPIRE_TIME=3600 ./apisix-runner-bin/apisix-java-plugin-runner.jar &
 
     - name: startup apisix
diff --git a/MAINTAIN.md b/MAINTAIN.md
index 0f57bea..5cf7f66 100644
--- a/MAINTAIN.md
+++ b/MAINTAIN.md
@@ -20,55 +20,15 @@
 Project Maintenance
 =================
 
-Publishing to Maven Central Repository:
+## Release steps
 
-1. Create a Jira account by signing up at: https://issues.sonatype.org/secure/Signup!default.jspa
-2. Create a new project ticket at: https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134 (make sure the Issue Type is *New Project*)
-3. Generate a PGP Signature and distribute it to one or more public key servers. To generate a PGP Signature:
-   ```
-   $ gpg2 --gen-key
+### Publish Maven Artifacts
+Apache projects release all software packages through the ASF distribution system. 
 
-   $ gpg: key YOUR_KEY_ID marked as ultimately trusted
-   ```
-   To distribute:
-   ```
-   $ gpg2 --keyserver SERVER_NAME --send-keys YOUR_KEY_ID
-   ```
+1. Set up your development environment. For more details, see the [Publishing Maven Releases to Maven Central Repository](https://infra.apache.org/publishing-maven-artifacts.html).
 
-4. Find your ~.m2 folder (this folder is hidden on some systems)
-5. Update or create your settings.xml to contain your Jira and public key information:
-```xml
-<settings>
-  <servers>
-    <server>
-      <id>ossrh</id>
-      <username>jira_username</username>
-      <password>jira_password</password>
-    </server>
-  </servers>
-  <profiles>
-    <profile>
-      <id>ossrh</id>
-      <activation>
-        <activeByDefault>true</activeByDefault>
-      </activation>
-      <properties>
-        <gpg.executable>gpg2</gpg.executable>
-        <gpg.passphrase>your_key_passphrase</gpg.passphrase>
-      </properties>
-    </profile>
-  </profiles>
-</settings>
-```
-6. Run Maven from the project directory
-```
-$ mvn clean deploy
-```
-7. Login to nexus repository manager using your Jira account created in step 1 (https://s01.oss.sonatype.org/#welcome)
-8. Click on *Staging Repositories* on the left sidebar, your staging repository should be available
-9. Click on your staging repository and ensure it contains the correct contents, click *Close*, include a relevant description
-10. Wait a few seconds for Sonatype to buffer
-11. Click *Release*, include a relevant description
-12. Comment your Jira ticket to sync Maven Central with your Group ID
+2. Deploy the snapshot artifacts to Apache Nexus
 
-Congratulations! You have released to Maven Central Repository. The search query should sync within a few hours to a day.
\ No newline at end of file
+```shell
+make deploy
+```
diff --git a/Makefile b/Makefile
index d95db7a..6388a61 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@
 
 SHELL := /bin/bash -o pipefail
 
-VERSION ?= 0.2.0
+VERSION ?= 0.3.0-SNAPSHOT
 RELEASE_SRC = apisix-java-plugin-runner-${VERSION}-src
 
 .PHONY: release-src
@@ -34,3 +34,12 @@ release-src: compress-tar
 compress-tar:
 	./mvnw package
 
+.PHONY: dry-run
+dry-run:
+	./mvnw release:prepare -pl runner-starter -DdryRun=true -DautoVersionSubmodules=true
+	./mvnw release:prepare -pl runner-core -DdryRun=true -DautoVersionSubmodules=true
+	./mvnw release:prepare -pl runner-plugin-sdk -DdryRun=true -DautoVersionSubmodules=true
+
+.PHONY: deploy
+deploy:
+	./mvnw clean deploy -pl runner-starter,runner-core,runner-plugin-sdk -DskipTests=true
diff --git a/pom.xml b/pom.xml
index 346298d..50d97a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,18 +22,7 @@
 
     <groupId>org.apache.apisix</groupId>
     <artifactId>apisix-plugin-runner</artifactId>
-    <version>0.2.0</version>
-
-    <distributionManagement>
-        <snapshotRepository>
-            <id>ossrh</id>
-            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
-        </snapshotRepository>
-        <repository>
-            <id>ossrh</id>
-            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
-        </repository>
-    </distributionManagement>
+    <version>0.3.0-SNAPSHOT</version>
   
     <parent>
         <groupId>org.apache</groupId>
diff --git a/runner-core/pom.xml b/runner-core/pom.xml
index 6336a45..aaeaede 100644
--- a/runner-core/pom.xml
+++ b/runner-core/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-core</artifactId>
@@ -35,8 +35,8 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.apisix</groupId>
-            <artifactId>apisix-runner-plugin</artifactId>
-            <version>0.2.0</version>
+            <artifactId>apisix-runner-plugin-sdk</artifactId>
+            <version>0.3.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
diff --git a/runner-dist/apisix-runner-bin-dist/pom.xml b/runner-dist/apisix-runner-bin-dist/pom.xml
index 7f02304..48043e3 100644
--- a/runner-dist/apisix-runner-bin-dist/pom.xml
+++ b/runner-dist/apisix-runner-bin-dist/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-runner-dist</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-bin-dist</artifactId>
diff --git a/runner-dist/apisix-runner-src-dist/pom.xml b/runner-dist/apisix-runner-src-dist/pom.xml
index 91516a6..ab817be 100644
--- a/runner-dist/apisix-runner-src-dist/pom.xml
+++ b/runner-dist/apisix-runner-src-dist/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-runner-dist</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-src-dist</artifactId>
@@ -64,7 +64,7 @@
                         <configuration>
                             <target>
                                 <copy file="${project.build.directory}/apisix-java-plugin-runner.tgz"
-                                      tofile="${project.basedir}/../../apisix-java-plugin-runner-${project.version}-src.tgz"
+                                      tofile="${project.basedir}/../../dist/apisix-java-plugin-runner-${project.version}-src.tgz"
                                       overwrite="true" />
                             </target>
                         </configuration>
diff --git a/runner-dist/pom.xml b/runner-dist/pom.xml
index 4e8c6a4..f2e9bdf 100644
--- a/runner-dist/pom.xml
+++ b/runner-dist/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-dist</artifactId>
@@ -35,7 +35,7 @@
         <dependency>
             <groupId>org.apache.apisix</groupId>
             <artifactId>apisix-runner-starter</artifactId>
-            <version>0.2.0</version>
+            <version>0.3.0-SNAPSHOT</version>
         </dependency>
     </dependencies>
     <modules>
diff --git a/runner-plugin-sdk/pom.xml b/runner-plugin-sdk/pom.xml
index 55b8c8d..b52133f 100644
--- a/runner-plugin-sdk/pom.xml
+++ b/runner-plugin-sdk/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-plugin-sdk</artifactId>
diff --git a/runner-plugin/pom.xml b/runner-plugin/pom.xml
index 27554f4..9bffaf2 100644
--- a/runner-plugin/pom.xml
+++ b/runner-plugin/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-plugin</artifactId>
@@ -35,7 +35,7 @@
         <dependency>
             <groupId>org.apache.apisix</groupId>
             <artifactId>apisix-runner-plugin-sdk</artifactId>
-            <version>0.2.0</version>
+            <version>0.3.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
diff --git a/runner-starter/pom.xml b/runner-starter/pom.xml
index c1ba9b6..d9302eb 100644
--- a/runner-starter/pom.xml
+++ b/runner-starter/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-starter</artifactId>
@@ -35,12 +35,7 @@
         <dependency>
             <groupId>org.apache.apisix</groupId>
             <artifactId>apisix-runner-core</artifactId>
-            <version>0.2.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.apisix</groupId>
-            <artifactId>apisix-runner-plugin</artifactId>
-            <version>0.2.0</version>
+            <version>0.3.0-SNAPSHOT</version>
         </dependency>
 
         <dependency>
diff --git a/runner-starter/src/main/java/org/apache/apisix/plugin/runner/HotReloadProcess.java b/runner-starter/src/main/java/org/apache/apisix/plugin/runner/HotReloadProcess.java
index 0e60349..52ecaea 100644
--- a/runner-starter/src/main/java/org/apache/apisix/plugin/runner/HotReloadProcess.java
+++ b/runner-starter/src/main/java/org/apache/apisix/plugin/runner/HotReloadProcess.java
@@ -26,6 +26,10 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
+import org.springframework.scheduling.config.ScheduledTask;
+import org.springframework.scheduling.config.Task;
+import org.springframework.scheduling.support.ScheduledMethodRunnable;
 import org.springframework.stereotype.Component;
 
 import javax.tools.JavaCompiler;
@@ -33,11 +37,14 @@ import javax.tools.ToolProvider;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.FileSystems;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.WatchEvent;
 import java.nio.file.WatchKey;
 import java.nio.file.WatchService;
+import java.util.Objects;
+import java.util.Set;
 
 import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
 import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
@@ -48,6 +55,12 @@ public class HotReloadProcess implements ApplicationContextAware {
     private final Logger logger = LoggerFactory.getLogger(HotReloadProcess.class);
     private ApplicationContext ctx;
 
+    private final ScheduledAnnotationBeanPostProcessor postProcessor;
+
+    public HotReloadProcess(ScheduledAnnotationBeanPostProcessor postProcessor) {
+        this.postProcessor = postProcessor;
+    }
+
     @Override
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
         this.ctx = applicationContext;
@@ -59,6 +72,9 @@ public class HotReloadProcess implements ApplicationContextAware {
     @Value("${apisix.runner.dynamic-filter.package-name:org.apache.apisix.plugin.runner.filter}")
     private String packageName;
 
+    @Value("${apisix.runner.dynamic-filter.enable:false}")
+    private Boolean enableHotReload;
+
     private BeanDefinitionBuilder compile(String userDir, String filterName, String filePath) throws ClassNotFoundException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 
@@ -84,16 +100,33 @@ public class HotReloadProcess implements ApplicationContextAware {
     }
 
     @Scheduled(fixedRate = 1000, initialDelay = 1000)
-    private void watch() {
+    private void hotReloadFilter() {
+        if (!enableHotReload) {
+            cancelHotReload("hotReloadFilter");
+            return;
+        }
+
         final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory();
-        long now = System.currentTimeMillis() / 1000;
-        logger.warn("Fixed rate task with one second initial delay - {}", now);
         String userDir = System.getProperty("user.dir");
         String workDir = userDir + loadPath;
 
+        Path path = Paths.get(workDir);
+        boolean exists = Files.exists(path);
+        if (!exists) {
+            logger.warn("The filter workdir fot hot reload {} not exists", workDir);
+            cancelHotReload("hotReloadFilter");
+            return;
+        }
+
         try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
-            Path path = Paths.get(workDir);
             path.register(watchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE);
+            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+                try {
+                    watchService.close();
+                } catch (IOException e) {
+                    logger.error(e.getMessage());
+                }
+            }));
 
             while (true) {
                 final WatchKey key = watchService.take();
@@ -142,4 +175,16 @@ public class HotReloadProcess implements ApplicationContextAware {
             throw new RuntimeException(e);
         }
     }
+
+    public void cancelHotReload(String taskName) {
+        Set<ScheduledTask> tasks = postProcessor.getScheduledTasks();
+        tasks.forEach(task -> {
+            Task t = task.getTask();
+            ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) t.getRunnable();
+            if (Objects.equals(runnable.getMethod().getName(), taskName)) {
+                postProcessor.postProcessBeforeDestruction(runnable.getTarget(), taskName);
+                logger.warn("Cancel hot reload schedule task");
+            }
+        });
+    }
 }
diff --git a/runner-starter/src/main/java/org/apache/apisix/plugin/runner/PluginRunnerApplication.java b/runner-starter/src/main/java/org/apache/apisix/plugin/runner/PluginRunnerApplication.java
index 109f699..aa68755 100644
--- a/runner-starter/src/main/java/org/apache/apisix/plugin/runner/PluginRunnerApplication.java
+++ b/runner-starter/src/main/java/org/apache/apisix/plugin/runner/PluginRunnerApplication.java
@@ -20,14 +20,19 @@ package org.apache.apisix.plugin.runner;
 import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.context.annotation.Bean;
+import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
 
 @SpringBootApplication
-@EnableScheduling
 public class PluginRunnerApplication {
     private static ClassLoader PARENT_CLASS_LOADER;
     private static DynamicClassLoader CLASS_LOADER;
 
+    @Bean
+    public ScheduledAnnotationBeanPostProcessor processor() {
+        return new ScheduledAnnotationBeanPostProcessor();
+    }
+
     public static void main(String[] args) {
 
         //load specified classes using dynamic class loader
diff --git a/runner-starter/src/main/resources/application.yaml b/runner-starter/src/main/resources/application.yaml
index 17c64a4..3dad276 100644
--- a/runner-starter/src/main/resources/application.yaml
+++ b/runner-starter/src/main/resources/application.yaml
@@ -26,5 +26,6 @@ socket:
 #apisix:
 #  runner:
 #    dynamic-filter:
+#      enable: true
 #      load-path:
 #      package-name:
\ No newline at end of file
diff --git a/sample/pom.xml b/sample/pom.xml
index 9532445..a8875f1 100644
--- a/sample/pom.xml
+++ b/sample/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.apisix</groupId>
         <artifactId>apisix-plugin-runner</artifactId>
-        <version>0.2.0</version>
+        <version>0.3.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apisix-runner-sample</artifactId>
@@ -35,7 +35,7 @@
         <dependency>
             <groupId>org.apache.apisix</groupId>
             <artifactId>apisix-runner-plugin-sdk</artifactId>
-            <version>0.2.0</version>
+            <version>0.3.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>