From 818372d295a43c303bb3f314b1284964c7ad2532 Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Thu, 11 Jan 2024 16:42:30 +0800 Subject: [PATCH] [ISSUE #15] Set up core module and ASF License (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set up CI * Add LICENSE * Add CheckStyle * Set up DB * Add druid StatFilter controller * sync CI change in https://github.com/apache/eventmesh/pull/4722 * fix(*)1. 完成项目设计 2. 完成项目与模块搭建 * Supplement module dependency relation and fix project info * Move original Admin into Core & rewrite dependencies --------- Co-authored-by: laohu <2732554140@qq.com> --- .asf.yaml | 47 --- .gitattributes | 20 + .github/workflows/build.yaml | 18 +- .github/workflows/ci.yml | 55 +++ .gitignore | 145 +++---- LICENSE | 201 ++++++++++ NOTICE | 5 + README.md | 37 +- docker/Dockerfile | 22 ++ eventmesh-dashboard-core/pom.xml | 165 +++++++- .../core/EventMeshDashboardApplication.java | 32 ++ .../core/config/AdminProperties.java | 83 ++++ .../dashboard/core/config/BeanTypeConfig.java | 83 ++++ .../dashboard/core/constant/ConfigConst.java | 40 ++ .../dashboard/core/constant/NacosConst.java | 43 ++ .../core/controller/ConnectionController.java | 51 +++ .../core/controller/MetricsController.java | 31 ++ .../controller/SubscriptionController.java | 72 ++++ .../core/controller/TopicController.java | 82 ++++ .../core/dto/CreateTopicRequest.java | 35 ++ .../core/dto/DeleteTopicRequest.java | 35 ++ .../eventmesh/dashboard/core/dto/Result.java | 144 +++++++ .../dashboard/core/enums/Status.java | 91 +++++ .../core/exception/BaseException.java | 54 +++ .../exception/EventMeshAdminException.java | 40 ++ .../core/exception/EventMeshException.java | 31 ++ .../exception/GlobalExceptionHandler.java | 62 +++ .../core/exception/MetaException.java | 44 +++ .../dashboard/core/model/ConnectionInfo.java | 22 ++ .../core/model/SubscriptionInfo.java | 35 ++ .../dashboard/core/model/TopicProperties.java | 40 ++ .../core/service/ConnectionService.java | 28 ++ .../dashboard/core/service/Main.java | 7 + .../core/service/SubscriptionService.java | 36 ++ .../dashboard/core/service/TopicService.java | 38 ++ .../service/meta/EtcdConnectionService.java | 30 ++ .../service/meta/EtcdSubscriptionService.java | 43 ++ .../service/meta/NacosConnectionService.java | 34 ++ .../meta/NacosSubscriptionService.java | 196 ++++++++++ .../service/store/RocketmqTopicService.java | 58 +++ .../dashboard/core/util/ExceptionUtil.java | 35 ++ .../src/main/resources/application-dev.yml | 75 ++++ .../src/main/resources/application.yml | 40 ++ .../src/main/resources/logback.xml | 50 +++ .../EventMeshDashboardApplicationTest.java | 13 + eventmesh-dashboard-view/.gitignore | 167 ++++++-- pom.xml | 25 +- style/checkStyle.xml | 370 ++++++++++++++++++ style/checkstyle-header1.txt | 17 + style/checkstyle-header2.txt | 16 + style/checkstyle-header3.txt | 18 + style/eventmesh-code-style.xml | 299 ++++++++++++++ 52 files changed, 3254 insertions(+), 206 deletions(-) delete mode 100644 .asf.yaml create mode 100644 .gitattributes create mode 100644 .github/workflows/ci.yml create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 docker/Dockerfile create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplication.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/AdminProperties.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/BeanTypeConfig.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/ConfigConst.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/NacosConst.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/ConnectionController.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/MetricsController.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/SubscriptionController.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/TopicController.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/CreateTopicRequest.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/DeleteTopicRequest.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/Result.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/enums/Status.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/BaseException.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshAdminException.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshException.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/GlobalExceptionHandler.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/MetaException.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/ConnectionInfo.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/SubscriptionInfo.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/TopicProperties.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/ConnectionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/Main.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/SubscriptionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/TopicService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdConnectionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdSubscriptionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosConnectionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosSubscriptionService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/store/RocketmqTopicService.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/util/ExceptionUtil.java create mode 100644 eventmesh-dashboard-core/src/main/resources/application-dev.yml create mode 100644 eventmesh-dashboard-core/src/main/resources/application.yml create mode 100644 eventmesh-dashboard-core/src/main/resources/logback.xml create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplicationTest.java create mode 100644 style/checkStyle.xml create mode 100644 style/checkstyle-header1.txt create mode 100644 style/checkstyle-header2.txt create mode 100644 style/checkstyle-header3.txt create mode 100644 style/eventmesh-code-style.xml diff --git a/.asf.yaml b/.asf.yaml deleted file mode 100644 index ec35b205..00000000 --- a/.asf.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# -# 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. -# - -github: - description: EventMesh dashboard - features: - # Enable issue management - issues: true - # Enable wiki - wiki: true - homepage: https://eventmesh.apache.org/ - labels: - - pubsub - enabled_merge_buttons: - squash: true - merge: true - rebase: false - protected_branches: - main: - required_status_checks: - strict: true - required_pull_request_reviews: - dismiss_stale_reviews: true - required_approving_review_count: 1 -notifications: - commits: commits@eventmesh.apache.org - # Send all issue emails (new, closed, comments) to issues@ - issues: issues@eventmesh.apache.org - # Send new/closed PR notifications to dev@ - pullrequests_status: dev@eventmesh.apache.org - # Send individual PR comments/reviews to issues@ - pullrequests_comment: issues@eventmesh.apache.org - jira_options: link label worklog diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..b27bb300 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,20 @@ +# +# 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. +# +*.sh text eol=lf +gradlew text eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index be2c833e..e8c512e9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -16,11 +16,11 @@ # specific language governing permissions and limitations # under the License. # -name: Build +name: Docker on: push: - branches: - - main + tags: + - 'v*' jobs: docker: @@ -31,12 +31,20 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + apache/eventmesh-dashboard + - name: Build and push uses: docker/build-push-action@v4 with: push: true - tags: apache/eventmesh-dashboard:latest + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} file: docker/Dockerfile context: . diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..dba06dcd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +# +# 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. +# + +name: "Continuous Integration" + +on: + push: + branches: [ '*' ] + pull_request: + branches: [ '*' ] + +jobs: + build: + name: Build + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + java: [ 8 ] + language: ['java'] + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: ${{ matrix.java }} + + - name: Build + run: ./gradlew clean build bootJar --parallel --daemon + env: + GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore index b1f31d2b..1098c796 100644 --- a/.gitignore +++ b/.gitignore @@ -1,50 +1,74 @@ -.settings/ -.project +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated .classpath -.target -./**/.settings/ -./**/.project ./**/.classpath -./**/target/ - - -#gitignore文件的内容 .factorypath -.DS_Store .project -*.prefs -.classpath -.setting/h -.settings/ -.idea/ +./**/.project +.settings +./**/.settings/ +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws *.iml *.ipr -*.iws -logs/ +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ -#忽略eclipse相关 +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache org.eclipse.core.resources.prefs org.eclipse.jdt.core.prefs org.eclipse.m2e.core.prefs org.eclipse.wst.common.component org.eclipse.wst.common.project.facet.core.xml +*.prefs -#忽略java相关的文件 +### Java ### *.class *.trc -# Mobile Tools for Java (J2ME) -.mtj.tmp/ -# Package Files # +### Package Files ### *.jar *.war *.ear -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -#忽略maven相关的文件 +### Maven ### +.target target/ +./**/target/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup @@ -54,69 +78,8 @@ dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties -# Built application files -*.apk -*.ap_ - - -#忽略andriod相关的文件 -# Files for the Dalvik VM -*.dex -# Generated files -bin/ -gen/ -# Gradle files -.gradle/ -build/ -*/build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ -# Log Files +### Log Files ### *.log -# Android Studio Navigation editor temp files -.navigation/ -# Android Studio captures folder -captures/ - -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file +logs/ +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/NOTICE b/NOTICE new file mode 100644 index 00000000..910ee067 --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +Apache EventMesh +Copyright 2021-2024 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/README.md b/README.md index 1d3574c3..5c7eac23 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,45 @@ - +# EventMesh Dashboard ## 介绍 - ## 业务架构 - ## 技术架构 - ### 模块依赖图 ### 模块介绍 -1. eventmesh-dashboard-console 业务模块的代码 +1. eventmesh-dashboard-console 业务模块的代码,调用service接口 2. eventmesh-dashboard-observe 监控模块的代码 -3. eventmesh-dashboard-core 对eventmesh以及相关组件的代码 -4. eventmesh-dashboard-service 公用接口 +3. eventmesh-dashboard-core 对eventmesh以及相关组件的代码,提供service实现 +4. eventmesh-dashboard-service 公用API接口,对core的抽象 5. eventmesh-dashboard-common 公共模块的代码 6. eventmesh-dashboard-view 前端代码 - ### eventmesh-dashboard-core 介绍 + +## Build + +### Build on source code + +``` +cd eventmesh-dashboard +./gradlew clean bootJar +``` + +``` +java -jar build/libs/eventmesh-dashboard-0.0.1-SNAPSHOT.jar +``` + +### Build and Run with Docker + +``` +cd eventmesh-dashboard +./gradlew clean bootJar +docker build -t yourname/eventmesh-dashboard -f docker/Dockerfile . +``` + +``` +docker run -d --name eventmesh-dashboard -p 8080:8080 yourname/eventmesh-dashboard +``` \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..326c8b19 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,22 @@ +# +# 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. +# + +FROM openjdk:8-jdk +VOLUME /tmp +COPY build/libs/eventmesh-dashboard-*.jar eventmesh-dashboard.jar +ENV JAVA_OPTS="" +ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /eventmesh-dashboard.jar"] diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 7192775b..1f23357b 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -1,4 +1,25 @@ + + @@ -8,14 +29,150 @@ eventmesh-dashboard 0.0.1 - org.apache.eventmesh.dashboard.core eventmesh-dashboard-core - + 0.0.1-SNAPSHOT + eventmesh-dashboard-core - 17 - 17 + 1.8 UTF-8 + UTF-8 + 2.7.6 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.apache.commons + commons-lang3 + 3.13.0 + + + com.alibaba.fastjson2 + fastjson2 + 2.0.40 + + + + + org.springdoc + springdoc-openapi-ui + 1.7.0 + + + org.springdoc + springdoc-openapi-javadoc + 1.7.0 + + + + + org.mockito + mockito-core + 5.5.0 + test + + + + + com.alibaba.nacos + nacos-client + 2.2.4 + + + + + org.apache.rocketmq + rocketmq-client + 4.9.7 + + + + + com.alibaba + druid-spring-boot-starter + 1.2.21 + + + com.baomidou + mybatis-plus-boot-starter + 3.5.5 + + + com.mysql + mysql-connector-j + runtime + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + org.apache.eventmesh.dashboard.core.EventMeshDashboardApplication + true + + + + repackage + + repackage + + + + + + \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplication.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplication.java new file mode 100644 index 00000000..7caeddb7 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplication.java @@ -0,0 +1,32 @@ +/* + * 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.eventmesh.dashboard.core; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; + +@ServletComponentScan // Druid Monitor +@SpringBootApplication +public class EventMeshDashboardApplication { + + public static void main(String[] args) { + SpringApplication.run(EventMeshDashboardApplication.class, args); + } + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/AdminProperties.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/AdminProperties.java new file mode 100644 index 00000000..efcb74cf --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/AdminProperties.java @@ -0,0 +1,83 @@ +/* + * 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.eventmesh.dashboard.config; + +import org.apache.eventmesh.dashboard.constant.ConfigConst; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import lombok.Data; + +@Data +@Component +@ConfigurationProperties(prefix = ConfigConst.ADMIN_PROPS_PREFIX) +public class AdminProperties { + + private MetaProperties meta = new MetaProperties(); + private StoreProperties store = new StoreProperties(); + + @Data + public static class MetaProperties { + + private String type = ConfigConst.META_TYPE_NACOS; + private NacosProperties nacos = new NacosProperties(); + private EtcdProperties etcd = new EtcdProperties(); + private int timeoutMs = 5000; + + @Data + public static class NacosProperties { + private String addr = "127.0.0.1:8848"; + private String namespace = ""; + private boolean authEnabled = false; + private String protocol = "http"; + private String username; + private String password; + private String accessKey; + private String secretKey; + } + + @Data + public static class EtcdProperties { + private String addr; + } + } + + @Data + public static class StoreProperties { + + private String type = ConfigConst.STORE_TYPE_ROCKETMQ; // TODO should be standalone + private RocketMQProperties rocketmq = new RocketMQProperties(); + private KafkaProperties kafka = new KafkaProperties(); + + @Data + public static class RocketMQProperties { + private String namesrvAddr; + private String clusterName = ""; + private String accessKey = ""; + private String secretKey = ""; + } + + @Data + public static class KafkaProperties { + private String namesrvAddr; + private int partitions = 1; + private int replicationFactors = 1; + } + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/BeanTypeConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/BeanTypeConfig.java new file mode 100644 index 00000000..3a169f7c --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/config/BeanTypeConfig.java @@ -0,0 +1,83 @@ +/* + * 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.eventmesh.dashboard.config; + +import org.apache.eventmesh.dashboard.constant.ConfigConst; +import org.apache.eventmesh.dashboard.service.ConnectionService; +import org.apache.eventmesh.dashboard.service.SubscriptionService; +import org.apache.eventmesh.dashboard.service.TopicService; +import org.apache.eventmesh.dashboard.service.meta.EtcdConnectionService; +import org.apache.eventmesh.dashboard.service.meta.EtcdSubscriptionService; +import org.apache.eventmesh.dashboard.service.meta.NacosConnectionService; +import org.apache.eventmesh.dashboard.service.meta.NacosSubscriptionService; +import org.apache.eventmesh.dashboard.service.store.RocketmqTopicService; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Use different registry SDK depending on the configured meta type; + * Use different storage SDK depending on the configured storage type. + */ +@Configuration +public class BeanTypeConfig { + + private final AdminProperties adminProperties; + + public BeanTypeConfig(AdminProperties adminProperties) { + this.adminProperties = adminProperties; + } + + @Bean + public ConnectionService connectionService() { + switch (adminProperties.getMeta().getType()) { + case ConfigConst.META_TYPE_NACOS: + return new NacosConnectionService(adminProperties); + case ConfigConst.META_TYPE_ETCD: + return new EtcdConnectionService(); + default: + throw new IllegalArgumentException("Unsupported EventMesh Meta type: " + adminProperties.getMeta().getType()); + } + } + + @Bean + public SubscriptionService subscriptionService() { + switch (adminProperties.getMeta().getType()) { + case ConfigConst.META_TYPE_NACOS: + return new NacosSubscriptionService(adminProperties); + case ConfigConst.META_TYPE_ETCD: + return new EtcdSubscriptionService(); + default: + throw new IllegalArgumentException("Unsupported EventMesh Meta type: " + adminProperties.getMeta().getType()); + } + } + + @Bean + public TopicService topicService() { + switch (adminProperties.getStore().getType()) { + case ConfigConst.STORE_TYPE_STANDALONE: + return null; // TODO StandaloneTopicService + case ConfigConst.STORE_TYPE_ROCKETMQ: + return new RocketmqTopicService(adminProperties); + case ConfigConst.STORE_TYPE_KAFKA: + return null; // TODO KafkaTopicService + default: + throw new IllegalArgumentException("Unsupported EventMesh Store type: " + adminProperties.getStore().getType()); + } + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/ConfigConst.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/ConfigConst.java new file mode 100644 index 00000000..4932adfd --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/ConfigConst.java @@ -0,0 +1,40 @@ +/* + * 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.eventmesh.dashboard.constant; + +public class ConfigConst { + + // yml config + public static final String ADMIN_PROPS_PREFIX = "eventmesh"; + public static final String META_TYPE_NACOS = "nacos"; + public static final String META_TYPE_ETCD = "etcd"; + public static final String STORE_TYPE_STANDALONE = "standalone"; + public static final String STORE_TYPE_ROCKETMQ = "rocketmq"; + public static final String STORE_TYPE_KAFKA = "kafka"; + + // Open-API + public static final String HTTP_PREFIX = "http://"; + public static final String HTTPS_PREFIX = "https://"; + + // common + /** + * colon with space + */ + public static final String COLON = ": "; + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/NacosConst.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/NacosConst.java new file mode 100644 index 00000000..d0b027e8 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/constant/NacosConst.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.eventmesh.dashboard.constant; + +public class NacosConst { + + public static final String LOGIN_API = "/nacos/v1/auth/login"; + + public static final String LOGIN_REQ_USERNAME = "username"; + public static final String LOGIN_REQ_PASSWORD = "password"; + + public static final String LOGIN_RESP_TOKEN = "accessToken"; + + public static final String CONFIGS_API = "/nacos/v1/cs/configs"; + + public static final String CONFIGS_REQ_PAGE = "pageNo"; + public static final String CONFIGS_REQ_PAGE_SIZE = "pageSize"; + public static final String CONFIGS_REQ_DATAID = "dataId"; + public static final String CONFIGS_REQ_GROUP = "group"; + public static final String CONFIGS_REQ_SEARCH = "search"; + public static final String CONFIGS_REQ_TOKEN = "accessToken"; + + public static final String CONFIGS_RESP_CONTENT_LIST = "pageItems"; // json page data list field + public static final String CONFIGS_RESP_CONTENT = "content"; // json page data field + public static final String CONFIGS_RESP_PAGES = "pagesAvailable"; // json total pages field + public static final String CONFIGS_RESP_DATAID = "dataId"; + public static final String CONFIGS_RESP_GROUP = "group"; +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/ConnectionController.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/ConnectionController.java new file mode 100644 index 00000000..b723e66b --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/ConnectionController.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.eventmesh.dashboard.controller; + +import org.apache.eventmesh.dashboard.service.ConnectionService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +public class ConnectionController { + + @Autowired + ConnectionService connectionService; + + /** + * Query Connection List + *

+ * The subscription information of SourceConnector and SinkConnector reported by EventMesh Runtime to the meta, + * containing the configuration of each connection. + * + * @param page the page number + * @param size the page size + * @return A paged list of connection configuration and total number of pages + */ + @GetMapping("/connection") + public String listConnections(@RequestParam("page") Integer page, @RequestParam("size") String size) { + return null; + } + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/MetricsController.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/MetricsController.java new file mode 100644 index 00000000..dfe3a463 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/MetricsController.java @@ -0,0 +1,31 @@ +/* + * 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.eventmesh.dashboard.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.alibaba.druid.stat.DruidStatManagerFacade; + +@RestController +public class MetricsController { + @GetMapping("/druid/stat") + public Object druidStat() { + return DruidStatManagerFacade.getInstance().getDataSourceStatDataList(); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/SubscriptionController.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/SubscriptionController.java new file mode 100644 index 00000000..0ae0091b --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/SubscriptionController.java @@ -0,0 +1,72 @@ +/* + * 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.eventmesh.dashboard.controller; + +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.model.SubscriptionInfo; +import org.apache.eventmesh.dashboard.service.SubscriptionService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1") +public class SubscriptionController { + + @Autowired + SubscriptionService subscriptionService; + + // the subscription dataId naming pattern of EventMesh clients: ip-protocol + private static final String CLIENT_DATA_ID_PATTERN = "*.*.*.*-*"; + + /** + * Retrieve the config content of a specified config. + * + * @param dataId nacos config data id (Exact Matching) + * @param group config group (Exact Matching) + * @return config content + */ + @GetMapping("/subscription") + public Result retrieveSubscription(@RequestParam("dataId") String dataId, @RequestParam("group") String group) { + return Result.success(subscriptionService.retrieveConfig(dataId, group)); + } + + /** + * Retrieve a list of configs. + * + * @param page page number + * @param size page size + * @param dataId nacos config data id (Fuzzy Matching) + * @param group config group (Fuzzy Matching) + * @return config properties and base64 encoded config content + */ + @GetMapping("/subscriptions") + public Result> listSubscriptions( + @RequestParam(name = "page", defaultValue = "1") Integer page, + @RequestParam(name = "size", defaultValue = "10") Integer size, + @RequestParam(name = "dataId", defaultValue = CLIENT_DATA_ID_PATTERN) String dataId, + @RequestParam(name = "group", defaultValue = "") String group) { + return Result.success(subscriptionService.retrieveConfigs(page, size, dataId, group)); + } + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/TopicController.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/TopicController.java new file mode 100644 index 00000000..09d848c2 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/controller/TopicController.java @@ -0,0 +1,82 @@ +/* + * 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.eventmesh.dashboard.controller; + +import org.apache.eventmesh.dashboard.dto.CreateTopicRequest; +import org.apache.eventmesh.dashboard.dto.DeleteTopicRequest; +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.model.TopicProperties; +import org.apache.eventmesh.dashboard.service.TopicService; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/topic") +public class TopicController { + + @Autowired + TopicService topicService; + + /** + * TODO Is OPTIONS method and @CrossOrigin necessary? + */ + @CrossOrigin + @RequestMapping(method = RequestMethod.OPTIONS) + public ResponseEntity preflight() { + return ResponseEntity.ok() + .header("Access-Control-Allow-Origin", "*") + .header("Access-Control-Allow-Methods", "*") + .header("Access-Control-Allow-Headers", "*") + .header("Access-Control-Max-Age", "86400") + .build(); + } + + @CrossOrigin + @GetMapping + public Result> getList() { + List topicList = topicService.getTopic(); + return Result.success(topicList); + } + + @CrossOrigin + @PostMapping + public Result create(@RequestBody CreateTopicRequest createTopicRequest) { + String topicName = createTopicRequest.getName(); + topicService.createTopic(topicName); + return Result.success(); + } + + @CrossOrigin + @DeleteMapping + public Result delete(@RequestBody DeleteTopicRequest deleteTopicRequest) { + String topicName = deleteTopicRequest.getName(); + topicService.deleteTopic(topicName); + return Result.success(); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/CreateTopicRequest.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/CreateTopicRequest.java new file mode 100644 index 00000000..2475a213 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/CreateTopicRequest.java @@ -0,0 +1,35 @@ +/* + * 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.eventmesh.dashboard.dto; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +public class CreateTopicRequest { + + private String name; + + @JsonCreator + public CreateTopicRequest(@JsonProperty("name") String name) { + super(); + this.name = name; + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/DeleteTopicRequest.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/DeleteTopicRequest.java new file mode 100644 index 00000000..094a0085 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/DeleteTopicRequest.java @@ -0,0 +1,35 @@ +/* + * 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.eventmesh.dashboard.dto; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; + +@Data +public class DeleteTopicRequest { + + private String name; + + @JsonCreator + public DeleteTopicRequest(@JsonProperty("name") String name) { + super(); + this.name = name; + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/Result.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/Result.java new file mode 100644 index 00000000..50b90c1b --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/dto/Result.java @@ -0,0 +1,144 @@ +/* + * 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.eventmesh.dashboard.dto; + +import static org.apache.eventmesh.dashboard.enums.Status.SUCCESS; + +import org.apache.eventmesh.dashboard.enums.Status; +import org.apache.eventmesh.dashboard.exception.BaseException; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * A RESTful response DTO. + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Result { + + private T data; + + private Integer pages; + + private StatusMessage message; + + public Result(StatusMessage statusMessage) { + this.message = statusMessage; + } + + public Result(T data, Integer pages) { + this.data = data; + this.pages = pages; + } + + /** + * The request is valid and the result is wrapped in {@link Result}. + */ + public static Result success() { + return new Result<>(new StatusMessage(SUCCESS)); + } + + public static Result success(Result result) { + result.setMessage(new StatusMessage(SUCCESS)); + return result; + } + + public static Result success(T data) { + return new Result<>(data, null, new StatusMessage(SUCCESS)); + } + + /** + * The request is valid and the result is returned in {@link ResponseEntity}. + * Logic issues should use 422 Unprocessable Entity instead of 200 OK. + */ + public static ResponseEntity> ok() { + return ResponseEntity.ok(new Result<>(new StatusMessage(SUCCESS))); + } + + public static ResponseEntity> ok(Result result) { + result.setMessage(new StatusMessage(SUCCESS)); + return ResponseEntity.ok(result); + } + + /** + * The request is invalid. + */ + public static ResponseEntity> badRequest(String message) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new Result<>(new StatusMessage(message))); + } + + /** + * The request is valid but cannot be processed due to business logic issues. + */ + public static ResponseEntity> unprocessable(String message) { + return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(new Result<>(new StatusMessage(message))); + } + + /** + * Uncaught exception happened in EventMeshAdmin application. + */ + public static ResponseEntity> internalError(String message) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Result<>(new StatusMessage(message))); + } + + /** + * Upstream service unavailable such as Meta. + */ + public static ResponseEntity> badGateway(String message) { + return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(new Result<>(new StatusMessage(message))); + } + + @Data + public static class StatusMessage { + + private String status; + + private String category; + + private String desc; + + public StatusMessage(BaseException e) { + this.status = e.getStatus().name(); + this.category = e.getStatus().getCategory().name(); + this.desc = e.getMessage(); + } + + /** + * Only recommended for returning successful results, + * the stack trace cannot be displayed when returning unsuccessful results. + */ + public StatusMessage(Status status) { + this.status = status.name(); + this.category = status.getCategory().name(); + this.desc = status.getDesc(); // no stack trace + } + + public StatusMessage(String desc) { + this.desc = desc; + } + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/enums/Status.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/enums/Status.java new file mode 100644 index 00000000..958b3bb7 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/enums/Status.java @@ -0,0 +1,91 @@ +/* + * 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.eventmesh.dashboard.enums; + +import static org.apache.eventmesh.dashboard.constant.ConfigConst.COLON; + +import org.springframework.http.HttpStatus; + +import lombok.Getter; + +/** + * An error enumeration class that conforms to the RESTful specifications and custom error reporting requirements. + *
    + *
  • The 'code' field is used to return the HTTP status code using {@link HttpStatus}.
  • + *
  • The 'category' field represents the major category of the error.
  • + *
  • the 'desc' field represents the detailed subcategory and information of the error.
  • + *
+ */ + +@Getter +public enum Status { + + SUCCESS(HttpStatus.OK, Category.SUCCESS, "Operation success."), + + NACOS_SDK_CONFIG_ERR(HttpStatus.INTERNAL_SERVER_ERROR, Category.SDK_CONFIG_ERR, + "Failed to create Nacos ConfigService. Please check EventMeshAdmin application configuration."), + + NACOS_GET_CONFIGS_ERR(HttpStatus.BAD_GATEWAY, Category.META_COM_ERR, "Failed to retrieve Nacos config(s)."), + + NACOS_EMPTY_RESP_ERR(HttpStatus.BAD_GATEWAY, Category.META_COM_ERR, "No result returned by Nacos. Please check Nacos."), + + NACOS_LOGIN_ERR(HttpStatus.UNAUTHORIZED, Category.META_COM_ERR, "Nacos login failed."), + + NACOS_LOGIN_EMPTY_RESP_ERR(HttpStatus.BAD_GATEWAY, Category.META_COM_ERR, "Nacos didn't return accessToken. Please check Nacos status."), + ; + + // error code + private final HttpStatus code; + + // error type + private final Category category; + + // error message + private final String desc; + + Status(HttpStatus code, Category category, String desc) { + this.code = code; + this.category = category; + this.desc = desc; + } + + @Override + public String toString() { + return name() + " of " + category + COLON + desc; + } + + @Getter + public enum Category { + + SUCCESS("Successfully received and processed"), + + SDK_CONFIG_ERR("The Meta SDK config in EventMeshAdmin application.yml error"), + + META_COM_ERR("Network communication to Meta error"), + ; + + /** + * Helpful for understanding and not used for now + */ + private final String desc; + + Category(String desc) { + this.desc = desc; + } + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/BaseException.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/BaseException.java new file mode 100644 index 00000000..872ac4c0 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/BaseException.java @@ -0,0 +1,54 @@ +/* + * 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.eventmesh.dashboard.exception; + +import static org.apache.eventmesh.dashboard.constant.ConfigConst.COLON; + +import org.apache.eventmesh.dashboard.enums.Status; +import org.apache.eventmesh.dashboard.util.ExceptionUtil; + +import lombok.Getter; + +/** + * Exceptions in EventMeshAdmin application + */ + +@Getter +public class BaseException extends RuntimeException { + + private static final long serialVersionUID = 3509261993355721168L; + + private Status status; + + public BaseException(String message) { + super(message); + } + + /** + * Customized error reporting using enums and exceptions + */ + public BaseException(Status status, Throwable cause) { + super(ExceptionUtil.trimDesc(status.getDesc()) + COLON + cause.getMessage(), cause); + this.status = status; + } + + public BaseException(Status status) { + super(status.getDesc()); + this.status = status; + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshAdminException.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshAdminException.java new file mode 100644 index 00000000..d298a7e5 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshAdminException.java @@ -0,0 +1,40 @@ +/* + * 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.eventmesh.dashboard.exception; + +import org.apache.eventmesh.dashboard.enums.Status; + +/** + * EventMeshAdmin Application side exception + */ + +public class EventMeshAdminException extends BaseException { + + private static final long serialVersionUID = 2002022502005456586L; + + public EventMeshAdminException(String message) { + super(message); + } + + /** + * Customized error reporting using enums and exceptions + */ + public EventMeshAdminException(Status status, Throwable cause) { + super(status, cause); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshException.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshException.java new file mode 100644 index 00000000..9a835cd1 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/EventMeshException.java @@ -0,0 +1,31 @@ +/* + * 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.eventmesh.dashboard.exception; + +/** + * EventMesh Runtime side exception + */ + +public class EventMeshException extends BaseException { + + private static final long serialVersionUID = 5648256502005456586L; + + public EventMeshException(String message) { + super(message); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/GlobalExceptionHandler.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..51a2deff --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/GlobalExceptionHandler.java @@ -0,0 +1,62 @@ +/* + * 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.eventmesh.dashboard.exception; + +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.dto.Result.StatusMessage; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import lombok.extern.slf4j.Slf4j; + +/** + * This class, in conjunction with {@linkplain org.apache.eventmesh.dashboard.enums.Status Status} and {@link BaseException}, + * collectively implements customized error reporting. + */ + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(BaseException.class) + public ResponseEntity> baseHandler(BaseException e, HttpServletRequest request) { + String uri = request.getRequestURI(); + log.error("RESTful API {} service error occurred, name: {}, category: {}", + uri, e.getStatus().name(), e.getStatus().getCategory().name(), e); + return ResponseEntity.status(e.getStatus().getCode()).body(new Result<>(new StatusMessage(e))); + } + + @ExceptionHandler(RuntimeException.class) + public ResponseEntity> runtimeHandler(RuntimeException e, HttpServletRequest request) { + String uri = request.getRequestURI(); + log.error("RESTful API {} runtime error occurred.", uri, e); + return Result.internalError(e.getMessage()); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> exceptionHandler(Exception e, HttpServletRequest request) { + String uri = request.getRequestURI(); + log.error("RESTful API {} unknown error occurred.", uri, e); + return Result.internalError(e.getMessage()); + } + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/MetaException.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/MetaException.java new file mode 100644 index 00000000..54db37d1 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/exception/MetaException.java @@ -0,0 +1,44 @@ +/* + * 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.eventmesh.dashboard.exception; + +import org.apache.eventmesh.dashboard.enums.Status; + +/** + * Meta side exception with EventMeshAdmin Application + */ + +public class MetaException extends BaseException { + + private static final long serialVersionUID = 6246145526338359773L; + + public MetaException(String message) { + super(message); + } + + /** + * Customized error reporting using enums and exceptions + */ + public MetaException(Status status, Throwable cause) { + super(status, cause); + } + + public MetaException(Status status) { + super(status); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/ConnectionInfo.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/ConnectionInfo.java new file mode 100644 index 00000000..8b3c61d5 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/ConnectionInfo.java @@ -0,0 +1,22 @@ +/* + * 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.eventmesh.dashboard.model; + +public class ConnectionInfo { + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/SubscriptionInfo.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/SubscriptionInfo.java new file mode 100644 index 00000000..a7fbfb78 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/SubscriptionInfo.java @@ -0,0 +1,35 @@ +/* + * 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.eventmesh.dashboard.model; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class SubscriptionInfo { + + // client name + private String clientName; + + // group name + private String group; + + // config content + private String subscription; +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/TopicProperties.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/TopicProperties.java new file mode 100644 index 00000000..c0018223 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/model/TopicProperties.java @@ -0,0 +1,40 @@ +/* + * 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.eventmesh.dashboard.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * One record displayed in 'Topic' page. + */ + +public class TopicProperties { + + public String name; + public long messageCount; + + @JsonCreator + public TopicProperties( + @JsonProperty("name") String name, + @JsonProperty("messageCount") long messageCount) { + super(); + this.name = name; + this.messageCount = messageCount; + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/ConnectionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/ConnectionService.java new file mode 100644 index 00000000..db004673 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/ConnectionService.java @@ -0,0 +1,28 @@ +/* + * 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.eventmesh.dashboard.service; + +/** + * "Connection" refers to the subscription relationship between connectors. + * It focuses on the configuration deployed on the source and sink connectors themselves, + * reported by the connector. + */ + +public interface ConnectionService { + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/Main.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/Main.java new file mode 100644 index 00000000..0927abf9 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/Main.java @@ -0,0 +1,7 @@ +package org.apache.eventmesh.dashboard.service; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/SubscriptionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/SubscriptionService.java new file mode 100644 index 00000000..01ba3dd9 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/SubscriptionService.java @@ -0,0 +1,36 @@ +/* + * 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.eventmesh.dashboard.service; + +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.model.SubscriptionInfo; + +import java.util.List; + +/** + * "Subscription" refers to the traditional MQ producer-consumer topic subscription relationship, + * emphasizing the subscription relationship between EventMesh clients (including SDK and connectors) and topics, + * reported by the EventMesh runtime. + */ + +public interface SubscriptionService { + + String retrieveConfig(String dataId, String group); + + Result> retrieveConfigs(Integer page, Integer size, String dataId, String group); +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/TopicService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/TopicService.java new file mode 100644 index 00000000..f617a777 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/TopicService.java @@ -0,0 +1,38 @@ +/* + * 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.eventmesh.dashboard.service; + +import org.apache.eventmesh.dashboard.model.TopicProperties; + +import java.util.List; + +/** + * Manage topics of eventmesh-storage-plugin (EventMesh Store). + */ + +public interface TopicService { + + /** + * TODO rename to getTopics after being implemented + */ + List getTopic(); + + void createTopic(String topicName); + + void deleteTopic(String topicName); +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdConnectionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdConnectionService.java new file mode 100644 index 00000000..f55ad705 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdConnectionService.java @@ -0,0 +1,30 @@ +/* + * 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.eventmesh.dashboard.service.meta; + +import org.apache.eventmesh.dashboard.service.ConnectionService; + +import org.springframework.stereotype.Service; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class EtcdConnectionService implements ConnectionService { + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdSubscriptionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdSubscriptionService.java new file mode 100644 index 00000000..d5c024f7 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/EtcdSubscriptionService.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.eventmesh.dashboard.service.meta; + +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.model.SubscriptionInfo; +import org.apache.eventmesh.dashboard.service.SubscriptionService; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class EtcdSubscriptionService implements SubscriptionService { + + @Override + public String retrieveConfig(String dataId, String group) { + return null; + } + + @Override + public Result> retrieveConfigs(Integer page, Integer size, String dataId, String group) { + return null; + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosConnectionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosConnectionService.java new file mode 100644 index 00000000..8e10082f --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosConnectionService.java @@ -0,0 +1,34 @@ +/* + * 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.eventmesh.dashboard.service.meta; + +import org.apache.eventmesh.dashboard.config.AdminProperties; +import org.apache.eventmesh.dashboard.service.ConnectionService; + +import org.springframework.stereotype.Service; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class NacosConnectionService implements ConnectionService { + + public NacosConnectionService(AdminProperties adminProperties) { + } + +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosSubscriptionService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosSubscriptionService.java new file mode 100644 index 00000000..09b675c6 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/meta/NacosSubscriptionService.java @@ -0,0 +1,196 @@ +/* + * 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.eventmesh.dashboard.service.meta; + +import static org.apache.eventmesh.dashboard.enums.Status.NACOS_EMPTY_RESP_ERR; +import static org.apache.eventmesh.dashboard.enums.Status.NACOS_GET_CONFIGS_ERR; +import static org.apache.eventmesh.dashboard.enums.Status.NACOS_LOGIN_EMPTY_RESP_ERR; +import static org.apache.eventmesh.dashboard.enums.Status.NACOS_LOGIN_ERR; +import static org.apache.eventmesh.dashboard.enums.Status.NACOS_SDK_CONFIG_ERR; + +import org.apache.eventmesh.dashboard.config.AdminProperties; +import org.apache.eventmesh.dashboard.constant.ConfigConst; +import org.apache.eventmesh.dashboard.constant.NacosConst; +import org.apache.eventmesh.dashboard.dto.Result; +import org.apache.eventmesh.dashboard.exception.EventMeshAdminException; +import org.apache.eventmesh.dashboard.exception.MetaException; +import org.apache.eventmesh.dashboard.model.SubscriptionInfo; +import org.apache.eventmesh.dashboard.service.SubscriptionService; + +import java.util.ArrayList; +import java.util.Base64; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class NacosSubscriptionService implements SubscriptionService { + + AdminProperties adminProperties; + + Properties nacosProps = new Properties(); + + RestTemplate restTemplate = new RestTemplate(); + + private static String HTTP_PREFIX = ConfigConst.HTTP_PREFIX; + + public NacosSubscriptionService(AdminProperties adminProperties) { + this.adminProperties = adminProperties; + + nacosProps.setProperty(PropertyKeyConst.SERVER_ADDR, adminProperties.getMeta().getNacos().getAddr()); + nacosProps.setProperty(PropertyKeyConst.NAMESPACE, adminProperties.getMeta().getNacos().getNamespace()); + if (adminProperties.getMeta().getNacos().isAuthEnabled()) { + if (!adminProperties.getMeta().getNacos().getUsername().isEmpty()) { + nacosProps.setProperty(PropertyKeyConst.USERNAME, adminProperties.getMeta().getNacos().getUsername()); + } + if (!adminProperties.getMeta().getNacos().getPassword().isEmpty()) { + nacosProps.setProperty(PropertyKeyConst.PASSWORD, adminProperties.getMeta().getNacos().getPassword()); + } + if (!adminProperties.getMeta().getNacos().getAccessKey().isEmpty()) { + nacosProps.setProperty(PropertyKeyConst.ACCESS_KEY, adminProperties.getMeta().getNacos().getAccessKey()); + } + if (!adminProperties.getMeta().getNacos().getSecretKey().isEmpty()) { + nacosProps.setProperty(PropertyKeyConst.SECRET_KEY, adminProperties.getMeta().getNacos().getSecretKey()); + } + } + if (adminProperties.getMeta().getNacos().getProtocol().equalsIgnoreCase("https")) { + HTTP_PREFIX = ConfigConst.HTTPS_PREFIX; + } + } + + /** + * Retrieve a specified config with Nacos SDK. + */ + @Override + public String retrieveConfig(String dataId, String group) { + ConfigService configService; + try { + configService = NacosFactory.createConfigService(nacosProps); + } catch (Exception e) { + log.error(NACOS_SDK_CONFIG_ERR.getDesc(), e); + throw new EventMeshAdminException(NACOS_SDK_CONFIG_ERR, e); + } + try { + return configService.getConfig(dataId, group, adminProperties.getMeta().getTimeoutMs()); + } catch (Exception e) { + log.error(NACOS_GET_CONFIGS_ERR.getDesc(), e); + throw new MetaException(NACOS_GET_CONFIGS_ERR, e); + } + } + + /** + * Retrieve a list of configs with Nacos OpenAPI, because Nacos SDK doesn't support listing and fuzzy matching. + * + * TODO Granularity should be based on subscriptions rather than Runtime; + * retrieve all subscriptions for each Runtime, rather than retrieving subscriptions for each individual Runtime. + */ + @Override + public Result> retrieveConfigs(Integer page, Integer size, String dataId, String group) { + UriComponentsBuilder urlBuilder = UriComponentsBuilder + .fromHttpUrl(HTTP_PREFIX + nacosProps.getProperty(PropertyKeyConst.SERVER_ADDR) + NacosConst.CONFIGS_API) + .queryParam(NacosConst.CONFIGS_REQ_PAGE, page) + .queryParam(NacosConst.CONFIGS_REQ_PAGE_SIZE, size) + .queryParam(NacosConst.CONFIGS_REQ_DATAID, dataId) + .queryParam(NacosConst.CONFIGS_REQ_GROUP, group) + .queryParam(NacosConst.CONFIGS_REQ_SEARCH, "blur"); + + if (adminProperties.getMeta().getNacos().isAuthEnabled()) { + urlBuilder.queryParam(NacosConst.CONFIGS_REQ_TOKEN, loginGetAccessToken()); + } + + ResponseEntity response; + try { + response = restTemplate.getForEntity(urlBuilder.toUriString(), String.class); + } catch (Exception e) { + log.error(NACOS_GET_CONFIGS_ERR.getDesc(), e); + throw new MetaException(NACOS_GET_CONFIGS_ERR, e); + } + if (response.getBody() == null || response.getBody().isEmpty()) { + log.error(NACOS_EMPTY_RESP_ERR.getDesc()); + throw new MetaException(NACOS_EMPTY_RESP_ERR); + } + + JSONObject obj = JSON.parseObject(response.getBody()); + return new Result<>(toSubscriptionInfos(obj), obj.getInteger(NacosConst.CONFIGS_RESP_PAGES)); + } + + private List toSubscriptionInfos(JSONObject obj) { + List subscriptionInfos = new ArrayList<>(); + for (Object pageItem : obj.getJSONArray(NacosConst.CONFIGS_RESP_CONTENT_LIST)) { + JSONObject pageItemObj = (JSONObject) pageItem; + subscriptionInfos.add(toSubscriptionInfo(pageItemObj)); + } + return subscriptionInfos; + } + + private SubscriptionInfo toSubscriptionInfo(JSONObject obj) { + String content = obj.getString(NacosConst.CONFIGS_RESP_CONTENT); + return SubscriptionInfo.builder() + .clientName(obj.getString(NacosConst.CONFIGS_RESP_DATAID)) + .group(obj.getString(NacosConst.CONFIGS_RESP_GROUP)) + // The subscription content of Nacos config should be base64 encoded to protect special characters. + .subscription(Base64.getEncoder().encodeToString(content.getBytes())) + .build(); + } + + /** + * Login if auth enabled and return accessToken. + */ + private String loginGetAccessToken() { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + MultiValueMap bodyParams = new LinkedMultiValueMap<>(); + bodyParams.put(NacosConst.LOGIN_REQ_USERNAME, Collections.singletonList(nacosProps.getProperty(PropertyKeyConst.USERNAME))); + bodyParams.put(NacosConst.LOGIN_REQ_PASSWORD, Collections.singletonList(nacosProps.getProperty(PropertyKeyConst.PASSWORD))); + + String loginUrl = HTTP_PREFIX + nacosProps.getProperty(PropertyKeyConst.SERVER_ADDR) + NacosConst.LOGIN_API; + HttpEntity> loginRequest = new HttpEntity<>(bodyParams, headers); + ResponseEntity loginResponse; + try { + loginResponse = restTemplate.postForEntity(loginUrl, loginRequest, String.class); + } catch (Exception e) { + log.error(NACOS_LOGIN_ERR.getDesc(), e); + throw new MetaException(NACOS_LOGIN_ERR, e); + } + if (loginResponse.getBody() == null || loginResponse.getBody().isEmpty()) { + log.error(NACOS_LOGIN_EMPTY_RESP_ERR + " Status code: {}", loginResponse.getStatusCode()); + throw new MetaException(NACOS_LOGIN_EMPTY_RESP_ERR + " Status code: " + loginResponse.getStatusCode()); + } + return JSON.parseObject(loginResponse.getBody()).getString(NacosConst.LOGIN_RESP_TOKEN); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/store/RocketmqTopicService.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/store/RocketmqTopicService.java new file mode 100644 index 00000000..ca8340c1 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/service/store/RocketmqTopicService.java @@ -0,0 +1,58 @@ +/* + * 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.eventmesh.dashboard.service.store; + +import org.apache.eventmesh.dashboard.config.AdminProperties; +import org.apache.eventmesh.dashboard.model.TopicProperties; +import org.apache.eventmesh.dashboard.service.TopicService; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import lombok.extern.slf4j.Slf4j; + +/** + * TODO implement methods from storage-plugin.admin + */ + +@Slf4j +@Service +public class RocketmqTopicService implements TopicService { + + AdminProperties adminProperties; + + public RocketmqTopicService(AdminProperties adminProperties) { + this.adminProperties = adminProperties; + } + + @Override + public List getTopic() { + return null; + } + + @Override + public void createTopic(String topicName) { + + } + + @Override + public void deleteTopic(String topicName) { + + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/util/ExceptionUtil.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/util/ExceptionUtil.java new file mode 100644 index 00000000..1da29567 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/util/ExceptionUtil.java @@ -0,0 +1,35 @@ +/* + * 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.eventmesh.dashboard.util; + +public class ExceptionUtil { + + /** + * Remove the last period of exception description. + */ + public static String trimDesc(String desc) { + if (desc == null) { + return ""; + } + if (desc.charAt(desc.length() - 1) == '.') { + return desc.substring(0, desc.length() - 1); + } + return desc; + } + +} diff --git a/eventmesh-dashboard-core/src/main/resources/application-dev.yml b/eventmesh-dashboard-core/src/main/resources/application-dev.yml new file mode 100644 index 00000000..91377864 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/resources/application-dev.yml @@ -0,0 +1,75 @@ +# +# 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. +# +spring: + datasource: + type: com.alibaba.druid.pool.DruidDataSource + druid: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/eventmesh-dashboard?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 + username: root + password: + + initial-size: 1 + max-active: 50 + min-idle: 5 + max-wait: 6000 + validation-query: select 'x' + validation-query-timeout: 15 + test-on-borrow: false + test-while-idle: true + min-evictable-idle-time-millis: 300000 + + stat-view-servlet: + enabled: true + url-pattern: /druid/* + filter: + wall: + config: + multi-statement-allow: true # corresponds to allowMultiQueries + +eventmesh: + meta: + # registry type: nacos, etcd + type: nacos + nacos: + addr: 127.0.0.1:8848 + namespace: # namespace id, empty by default + authEnabled: false + protocol: http # http or https + username: + password: + # Alibaba Cloud MSE Nacos auth, not nacos.token.secret.key + accessKey: + secretKey: + etcd: + addr: # TODO + # timeout for admin client + timeoutMs: 5000 + store: + # Event Store type, should be consistent with the EventMesh Runtime configuration. + type: rocketmq + standalone: + # TODO + rocketmq: + namesrvAddr: 127.0.0.1:9876;127.0.0.1:9876 + clusterName: DefaultCluster + accessKey: '********' + secretKey: '********' + kafka: + namesrvAddr: localhost:9092;localhost:9092 + partitions: 1 + replicationFactors: 1 \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/resources/application.yml b/eventmesh-dashboard-core/src/main/resources/application.yml new file mode 100644 index 00000000..434cf55a --- /dev/null +++ b/eventmesh-dashboard-core/src/main/resources/application.yml @@ -0,0 +1,40 @@ +# +# 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. +# +spring: + application: + name: eventmesh-dashboard + profiles: + active: dev + +server: + port: 8080 + servlet: + encoding: + charset: UTF-8 + enabled: true + force: true + +logging: + config: classpath:logback.xml + +mybatis-plus: + mapper-locations: classpath*:mappers/**/*.xml # Default value + typeAliasesPackage: org.apache.eventmesh.dashboard.entity + configuration: + call-setters-on-nulls: true # Display fields with null values in query results + map-underscore-to-camel-case: true # Convert database underscore naming convention to camel case (default is true) +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # Output SQL execution logs to console (for debugging) \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/resources/logback.xml b/eventmesh-dashboard-core/src/main/resources/logback.xml new file mode 100644 index 00000000..447ace7c --- /dev/null +++ b/eventmesh-dashboard-core/src/main/resources/logback.xml @@ -0,0 +1,50 @@ + + + + + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n + + + + + ${user.home}/logs/eventmesh-dashboard.log + true + + ${user.home}/logs/eventmesh-dashboard-%d{yyyy-MM-dd}.%i.log + + + 104857600 + + 10 + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n + UTF-8 + + + + + + + + + \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplicationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplicationTest.java new file mode 100644 index 00000000..cc049831 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/EventMeshDashboardApplicationTest.java @@ -0,0 +1,13 @@ +package org.apache.eventmesh.dashboard.core; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class EventMeshDashboardApplicationTest { + + @Test + void contextLoads() { + } + +} diff --git a/eventmesh-dashboard-view/.gitignore b/eventmesh-dashboard-view/.gitignore index 63d2f1a0..7415ebb1 100644 --- a/eventmesh-dashboard-view/.gitignore +++ b/eventmesh-dashboard-view/.gitignore @@ -1,36 +1,131 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ +# https://github.com/github/gitignore/blob/main/Node.gitignore +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0fae672e..f85cff67 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,6 @@ - 4.0.0 pom @@ -40,21 +39,19 @@ eventmesh-dashboard eventmesh-dashboard - https://github.com/apache/pulsar + https://github.com/apache/eventmesh-dashboard Apache Software Foundation - http://www.apache.org/ + https://www.apache.org/ - 2017 - + 2021 - Apache eventmesh developers - http://eventmesh.apache.org/ + Apache EventMesh developers + https://eventmesh.apache.org/ - Apache License, Version 2.0 @@ -62,7 +59,7 @@ repo - + https://github.com/apache/eventmesh-dashboard scm:git:https://github.com/apache/eventmesh-dashboard.git scm:git:ssh://git@github.com:apache/eventmesh-dashboard.git @@ -70,7 +67,7 @@ GitHub Actions - https://github.com/apache/puleventmesh-dashboardsar/actions + https://github.com/apache/eventmesh-dashboard/actions @@ -79,11 +76,11 @@ - 17 - 17 + 8 + 8 UTF-8 - + eventmesh-dashboard-console eventmesh-dashboard-observe @@ -91,6 +88,4 @@ eventmesh-dashboard-service eventmesh-dashboard-common - - \ No newline at end of file diff --git a/style/checkStyle.xml b/style/checkStyle.xml new file mode 100644 index 00000000..cfa19728 --- /dev/null +++ b/style/checkStyle.xml @@ -0,0 +1,370 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/style/checkstyle-header1.txt b/style/checkstyle-header1.txt new file mode 100644 index 00000000..6a9c0641 --- /dev/null +++ b/style/checkstyle-header1.txt @@ -0,0 +1,17 @@ +/* + * 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. + */ + diff --git a/style/checkstyle-header2.txt b/style/checkstyle-header2.txt new file mode 100644 index 00000000..b1312a09 --- /dev/null +++ b/style/checkstyle-header2.txt @@ -0,0 +1,16 @@ +# +# 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. +# diff --git a/style/checkstyle-header3.txt b/style/checkstyle-header3.txt new file mode 100644 index 00000000..446e3fb4 --- /dev/null +++ b/style/checkstyle-header3.txt @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Licensed to 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. Apache Software Foundation (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. diff --git a/style/eventmesh-code-style.xml b/style/eventmesh-code-style.xml new file mode 100644 index 00000000..c8bddd49 --- /dev/null +++ b/style/eventmesh-code-style.xml @@ -0,0 +1,299 @@ + + + + + + + +