From 1d0a82137ea8a367af0a35a6e460be5ae7b019fa Mon Sep 17 00:00:00 2001 From: "youji.zzl" Date: Mon, 25 Sep 2023 17:07:08 +0800 Subject: [PATCH] modify github workflow arklet path --- .github/workflows/arklet_release.yml | 6 +- .github/workflows/arklet_unit_test.yml | 12 +- .github/workflows/base_runtime_release.yml | 33 -- sofa-serverless-runtime/README.md | 427 +++++++++++++++++++++ sofa-serverless-runtime/check_format.sh | 13 + 5 files changed, 449 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/base_runtime_release.yml create mode 100644 sofa-serverless-runtime/README.md create mode 100644 sofa-serverless-runtime/check_format.sh diff --git a/.github/workflows/arklet_release.yml b/.github/workflows/arklet_release.yml index d63c244fe..3bce83201 100644 --- a/.github/workflows/arklet_release.yml +++ b/.github/workflows/arklet_release.yml @@ -1,7 +1,7 @@ # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Arklet Release +name: SOFA Serverless Runtime Release ## https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release ## trigger manually @@ -21,7 +21,7 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - working-directory: arklet + working-directory: sofa-serverless-runtime run: mvn clean install -DskipTests -B -U -e && sh ./check_format.sh release: needs: build @@ -41,7 +41,7 @@ jobs: gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase - name: Build with Maven run: mvn --batch-mode deploy -DskipTests -Prelease - working-directory: arklet + working-directory: sofa-serverless-runtime env: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} diff --git a/.github/workflows/arklet_unit_test.yml b/.github/workflows/arklet_unit_test.yml index f212424e1..dc55233fa 100644 --- a/.github/workflows/arklet_unit_test.yml +++ b/.github/workflows/arklet_unit_test.yml @@ -1,28 +1,28 @@ -name: Arklet Unit Test -run-name: ${{ github.actor }} pushed arklet code +name: SOFAServerless Runtime Unit Test +run-name: ${{ github.actor }} pushed code on: push: branches: - master paths: - - 'arklet/**' + - 'sofa-serverless-runtime/**' pull_request: branches: - master paths: - - 'arklet/**' + - 'sofa-serverless-runtime/**' # enable manually running the workflow workflow_dispatch: env: - WORK_DIR: arklet + WORK_DIR: sofa-serverless-runtime defaults: run: - working-directory: arklet + working-directory: sofa-serverless-runtime jobs: unit-test: diff --git a/.github/workflows/base_runtime_release.yml b/.github/workflows/base_runtime_release.yml deleted file mode 100644 index e1278d8cc..000000000 --- a/.github/workflows/base_runtime_release.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Base Runtime Release - -## https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release -## trigger manually -on: - workflow_dispatch: - -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import - gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase - - name: Build with Maven - run: mvn --batch-mode deploy -DskipTests -Prelease - working-directory: sofa-serverless-runtime-starter - env: - MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} diff --git a/sofa-serverless-runtime/README.md b/sofa-serverless-runtime/README.md new file mode 100644 index 000000000..03a0ab662 --- /dev/null +++ b/sofa-serverless-runtime/README.md @@ -0,0 +1,427 @@ +# Overview + +Arklet provides an operational interface for delivery of SofaArk bases and modules. With Arklet, the release and operation of Ark Biz can be easily and flexibly operated. + +Arklet is internally constructed by **ArkletComponent** + +![image](https://github.com/sofastack/sofa-serverless/assets/11410549/a2740422-569e-4dd3-9c9a-1503996bd2f1) +- ApiClient: The core components responsible for interacting with the outside world +- CommandService: Arklet exposes capability instruction definition and extension +- OperationService: Ark Biz interacts with SofaArk to add, delete, modify, and encapsulate basic capabilities +- HealthService: Based on health and stability, base, Biz, system and other indicators are calculated + +The collaboration between them is shown in the figure +![overview](https://user-images.githubusercontent.com/11410549/266193839-7865e417-6909-4e89-bd48-c926162eaf83.jpg) + + +Of course, you can also extend Arklet's component capabilities by implementing the **ArkletComponent** interface + +# Command Extension +The Arklet exposes the instruction API externally and handles the instruction internally through a CommandHandler mapped from each API. +> CommandHandler related extensions belong to the unified management of the CommandService component + +You can customize extension commands by inheriting **AbstractCommandHandler** + +## Build-in Command API + +All of the following instruction apis access the arklet using the POST(application/json) request format + +The http protocol is enabled and the default port is 1238 +> You can set `sofa.serverless.arklet.http.port` JVM startup parameters override the default port + + +## Query the supported commands +- URL: 127.0.0.1:1238/help +- input sample: +```json +{} +``` +- output sample: +```json +{ + "code":"SUCCESS", + "data":[ + { + "desc":"query all ark biz(including master biz)", + "id":"queryAllBiz" + }, + { + "desc":"list all supported commands", + "id":"help" + }, + { + "desc":"uninstall one ark biz", + "id":"uninstallBiz" + }, + { + "desc":"switch one ark biz", + "id":"switchBiz" + }, + { + "desc":"install one ark biz", + "id":"installBiz" + } + ] +} +``` + +## Install a biz +- URL: 127.0.0.1:1238/installBiz +- input sample: +```json +{ + "bizName": "test", + "bizVersion": "1.0.0", + // local path should start with file://, alse support remote url which can be downloaded + "bizUrl": "file:///Users/jaimezhang/workspace/github/sofa-ark-dynamic-guides/dynamic-provider/target/dynamic-provider-1.0.0-ark-biz.jar" +} +``` + +- output sample(success): +```json +{ + "code":"SUCCESS", + "data":{ + "bizInfos":[ + { + "bizName":"dynamic-provider", + "bizState":"ACTIVATED", + "bizVersion":"1.0.0", + "declaredMode":true, + "identity":"dynamic-provider:1.0.0", + "mainClass":"io.sofastack.dynamic.provider.ProviderApplication", + "priority":100, + "webContextPath":"provider" + } + ], + "code":"SUCCESS", + "message":"Install Biz: dynamic-provider:1.0.0 success, cost: 1092 ms, started at: 16:07:47,769" + } +} +``` + +- output sample(failed): +```json +{ + "code":"FAILED", + "data":{ + "code":"REPEAT_BIZ", + "message":"Biz: dynamic-provider:1.0.0 has been installed or registered." + } +} +``` + + +## Uninstall a biz +- URL: 127.0.0.1:1238/uninstallBiz +- input sample: +```json +{ + "bizName":"dynamic-provider", + "bizVersion":"1.0.0" +} +``` +- output sample(success): +```json +{ + "code":"SUCCESS" +} +``` + +- output sample(failed): +```json +{ + "code":"FAILED", + "data":{ + "code":"NOT_FOUND_BIZ", + "message":"Uninstall biz: test:1.0.0 not found." + } +} +``` + +## Switch a biz +- URL: 127.0.0.1:1238/switchBiz +- input sample: +```json +{ + "bizName":"dynamic-provider", + "bizVersion":"1.0.0" +} +``` +- output sample: +```json +{ + "code":"SUCCESS" +} +``` + +## Query all Biz +- URL: 127.0.0.1:1238/queryAllBiz +- input sample: +```json +{} +``` +- output sample: +```json +{ + "code":"SUCCESS", + "data":[ + { + "bizName":"dynamic-provider", + "bizState":"ACTIVATED", + "bizVersion":"1.0.0", + "mainClass":"io.sofastack.dynamic.provider.ProviderApplication", + "webContextPath":"provider" + }, + { + "bizName":"stock-mng", + "bizState":"ACTIVATED", + "bizVersion":"1.0.0", + "mainClass":"embed main", + "webContextPath":"/" + } + ] +} +``` + +## Query Health +- URL: 127.0.0.1:1238/health + +### Query All Health Info +- input sample: +```json +{} +``` +- output sample: +```json +{ + "code": "SUCCESS", + "data": { + "healthData": { + "jvm": { + "max non heap memory(M)": -9.5367431640625E-7, + "java version": "1.8.0_331", + "max memory(M)": 885.5, + "max heap memory(M)": 885.5, + "used heap memory(M)": 137.14127349853516, + "used non heap memory(M)": 62.54662322998047, + "loaded class count": 10063, + "init non heap memory(M)": 2.4375, + "total memory(M)": 174.5, + "free memory(M)": 37.358726501464844, + "unload class count": 0, + "total class count": 10063, + "committed heap memory(M)": 174.5, + "java home": "****\\jre", + "init heap memory(M)": 64.0, + "committed non heap memory(M)": 66.203125, + "run time(s)": 34.432 + }, + "cpu": { + "count": 4, + "total used (%)": 131749.0, + "type": "****", + "user used (%)": 9.926451054656962, + "free (%)": 81.46475495070172, + "system used (%)": 6.249762806548817 + }, + "masterBizInfo": { + "webContextPath": "/", + "bizName": "bookstore-manager", + "bizState": "ACTIVATED", + "bizVersion": "1.0.0" + }, + "pluginListInfo": [ + { + "artifactId": "web-ark-plugin", + "groupId": "com.alipay.sofa", + "pluginActivator": "com.alipay.sofa.ark.web.embed.WebPluginActivator", + "pluginName": "web-ark-plugin", + "pluginUrl": "file:/****/2.2.3-SNAPSHOT/web-ark-plugin-2.2.3-20230901.090402-2.jar!/", + "pluginVersion": "2.2.3-SNAPSHOT" + }, + { + "artifactId": "runtime-sofa-boot-plugin", + "groupId": "com.alipay.sofa", + "pluginActivator": "com.alipay.sofa.runtime.ark.plugin.SofaRuntimeActivator", + "pluginName": "runtime-sofa-boot-plugin", + "pluginUrl": "file:/****/runtime-sofa-boot-plugin-3.11.0.jar!/", + "pluginVersion": "3.11.0" + } + ], + "masterBizHealth": { + "readinessState": "ACCEPTING_TRAFFIC" + }, + "bizListInfo": [ + { + "bizName": "bookstore-manager", + "bizState": "ACTIVATED", + "bizVersion": "1.0.0", + "webContextPath": "/" + } + ] + } + } +} +``` + +### Query System Health Info +- input sample: + +```json +{ + "type": "system", + // [OPTIONAL] if metrics is null -> query all system health info + "metrics": ["cpu", "jvm"] +} +``` +- output sample: +```json +{ + "code": "SUCCESS", + "data": { + "healthData": { + "jvm": {...}, + "cpu": {...}, +// "masterBizHealth": {...} + } + } +} +``` + +### Query Biz Health Info +- input sample: + +```json +{ + "type": "biz", + // [OPTIONAL] if moduleName is null and moduleVersion is null -> query all biz + "moduleName": "bookstore-manager", + // [OPTIONAL] if moduleVersion is null -> query all biz named moduleName + "moduleVersion": "1.0.0" +} +``` +- output sample: +```json +{ + "code": "SUCCESS", + "data": { + "healthData": { + "bizInfo": { + "bizName": "bookstore-manager", + "bizState": "ACTIVATED", + "bizVersion": "1.0.0", + "webContextPath": "/" + } +// "bizListInfo": [ +// { +// "bizName": "bookstore-manager", +// "bizState": "ACTIVATED", +// "bizVersion": "1.0.0", +// "webContextPath": "/" +// } +// ] + } + } +} +``` + +### Query Plugin Health Info +- input sample: + +```json +{ + "type": "plugin", + // [OPTIONAL] if moduleName is null -> query all biz + "moduleName": "web-ark-plugin" +} +``` +- output sample: +```json +{ + "code": "SUCCESS", + "data": { + "healthData": { + "pluginListInfo": [ + { + "artifactId": "web-ark-plugin", + "groupId": "com.alipay.sofa", + "pluginActivator": "com.alipay.sofa.ark.web.embed.WebPluginActivator", + "pluginName": "web-ark-plugin", + "pluginUrl": "file:/****/web-ark-plugin-2.2.3-20230901.090402-2.jar!/", + "pluginVersion": "2.2.3-SNAPSHOT" + } + ] + } + } +} +``` + +### Query Health Using Endpoint + +use endpoint for k8s module to get helath info + +**default config** +* endpoints exposure include: `*` +* endpoints base path: `/` +* endpoints sever port: `8080` + +**http code result** +* `HEALTHY(200)`: get health if all health indicator is healthy +* `UNHEALTHY(400)`: get health once a health indicator is unhealthy +* `ENDPOINT_NOT_FOUND(404)`: endpoint path or params not found +* `ENDPOINT_PROCESS_INTERNAL_ERROR(500)`: get health process throw an error + +### query all health info +- url: 127.0.0.1:8080/arkletHealth +- method: GET +- output sample + +```json +{ + "healthy": true, + "code": 200, + "codeType": "HEALTHY", + "data": { + "jvm": {...}, + "masterBizHealth": {...}, + "cpu": {...}, + "masterBizInfo": {...}, + "bizListInfo": [...], + "pluginListInfo": [...] + } +} +``` +### query all biz/plugin health info +- url: 127.0.0.1:8080/arkletHealth/{moduleType} (moduleType must in ['biz', 'plugin']) +- method: GET +- output sample + ```json +{ + "healthy": true, + "code": 200, + "codeType": "HEALTHY", + "data": { + "bizListInfo": [...], + // "pluginListInfo": [...] + } +} +``` +### query single biz/plugin health info +- url: 127.0.0.1:8080/arkletHealth/{moduleType}/moduleName/moduleVersion (moduleType must in ['biz', 'plugin']) +- method: GET +- output sample + + ```json +{ + "healthy": true, + "code": 200, + "codeType": "HEALTHY", + "data": { + "bizInfo": {...}, + // "pluginInfo": {...} + } +} +``` + + diff --git a/sofa-serverless-runtime/check_format.sh b/sofa-serverless-runtime/check_format.sh new file mode 100644 index 000000000..061d8e8f0 --- /dev/null +++ b/sofa-serverless-runtime/check_format.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +BASEDIR=$(dirname $0) + +cd ${BASEDIR} + +# make sure git has no un commit files +if [ -n "$(git status --untracked-files=no --porcelain)" ]; then + echo "Please commit your change before run this shell, un commit files:" + git status --untracked-files=no --porcelain + echo "Please run ## mvn clean install -DskipTests -Dmaven.javadoc.skip=true -B -U && sh ./check_format.sh ## locally, then push it." + exit -1 +fi \ No newline at end of file