----初始化项目
This commit is contained in:
106
.gitignore
vendored
106
.gitignore
vendored
@ -1,88 +1,20 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# ---> Eclipse
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
# Java annotation processor (APT)
|
||||
# Except this file !.gitignore
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
target
|
||||
.idea
|
||||
.vscode
|
||||
.DS_Store
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated/
|
||||
.apt_generated_test/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
# Uncomment this line if you wish to ignore the project description file.
|
||||
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||
#.project
|
||||
|
||||
/logs
|
||||
*.iml
|
||||
*.log
|
||||
node_modules
|
||||
test/derby.log
|
||||
derby.log
|
||||
work
|
||||
test/logs
|
||||
derby.log
|
||||
yarn.lock
|
||||
.flattened-pom.xml
|
||||
|
||||
46
.travis.yml
Normal file
46
.travis.yml
Normal file
@ -0,0 +1,46 @@
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- dev-nacos@googlegroups.com
|
||||
- mw_configcenter@list.alibaba-inc.com
|
||||
on_success: change
|
||||
on_failure: always
|
||||
|
||||
language: java
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# On OSX, run with default JDK only.
|
||||
# - os: osx
|
||||
# On Linux, run with specific JDKs only.
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="oraclejdk8"
|
||||
- name: Linux aarch64
|
||||
dist: focal
|
||||
arch: arm64-graviton2
|
||||
group: edge
|
||||
virt: vm
|
||||
|
||||
|
||||
jdk:
|
||||
- openjdk11
|
||||
- openjdk8
|
||||
|
||||
before_install:
|
||||
- echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc
|
||||
- cat ~/.mavenrc
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export JAVA_HOME=$(/usr/libexec/java_home); fi
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
||||
|
||||
script:
|
||||
- mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
|
||||
- mvn clean -Premove-test-data
|
||||
- mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
|
||||
- mvn clean -Premove-test-data
|
||||
- mvn clean package -Pcit-test
|
||||
- mvn clean -Premove-test-data
|
||||
- mvn clean package -Pnit-test
|
||||
- mvn clean -Premove-test-data
|
||||
after_success:
|
||||
- mvn clean package -Pit-test
|
||||
- mvn sonar:sonar -Psonar-apache
|
||||
38
BUILDING
Normal file
38
BUILDING
Normal file
@ -0,0 +1,38 @@
|
||||
Build Instructions for NACOS
|
||||
|
||||
====================================================
|
||||
|
||||
(1) Prerequisites
|
||||
|
||||
JDK 1.8+ is required in order to compile and run Nacos.
|
||||
|
||||
nacos utilizes Maven as a distribution management and packaging tool. Version 3.0.3 or later is required.
|
||||
Maven installation and configuration instructions can be found here:
|
||||
|
||||
http://maven.apache.org/run-maven/index.html
|
||||
|
||||
|
||||
(2) Run test cases
|
||||
|
||||
Execute the following command in order to compile and run test cases of each components:
|
||||
|
||||
$ mvn test
|
||||
|
||||
|
||||
(3) Import projects to Eclipse IDE
|
||||
|
||||
First, generate eclipse project files:
|
||||
|
||||
$ mvn -U eclipse:eclipse
|
||||
|
||||
Then, import to eclipse by specifying the root directory of the project via:
|
||||
|
||||
[File] > [Import] > [Existing Projects into Workspace].
|
||||
|
||||
|
||||
(4) Build distribution packages
|
||||
|
||||
Execute the following command in order to build the tar.gz packages and install JAR into local repository:
|
||||
|
||||
#build nacos
|
||||
$ mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
|
||||
229
CHANGELOG.md
Normal file
229
CHANGELOG.md
Normal file
@ -0,0 +1,229 @@
|
||||
## 1.0.0-RC4(Mar 22, 2019)
|
||||
* [#923] Nacos 1.0.0 compatible with nacos-client 0.6.2
|
||||
* [#938] Client beat processor task lost
|
||||
* [#946] Change default server mode to AP
|
||||
|
||||
|
||||
|
||||
## 1.0.0-RC1(Mar 15, 2019)
|
||||
|
||||
* [#870] About Nacos's namespace and tenant design
|
||||
* [#869] Client exception message is confusing
|
||||
* [#866] BeatInfo scheduled property may have the memory visibility issue
|
||||
* [#865] checksum value is not correct
|
||||
* [#839] Refactor API URLs
|
||||
* [#811] ApiCommands.updateIpPublish countDownLatch timeout issue
|
||||
* [#809] Instance field 'valid' should be deprecated and replaced by 'healthy'
|
||||
* [#803] Nacos front-end function regression plan and landing
|
||||
* [#801] Nacos uses nignx as a best practice article for current limiting.
|
||||
* [#757] The word 'domain' should be replaced by 'service'
|
||||
* [#745] Support server running mode in CP, AP or mixed
|
||||
* [#744] The exact status of server should be stored and controlled
|
||||
* [#725] Will the nacos registry be how to do multi-environment deployment?
|
||||
* [#677] Support ephemeral instances and persistent instances
|
||||
* [#651] Remove old API entry 'APICommands'
|
||||
* [#650] Refactor server list management to make it irrelevant to consistency protocol
|
||||
* [#634] Add global push enable switch and data query enable switch
|
||||
* [#629] Server data needs warm up before open traffic
|
||||
* [#502] Registering ephemeral instance as well as persistent instances
|
||||
* [#501] Health check mode confict when building muilt clusters whit nacos sync + nacos
|
||||
* [#479] Metadata should be displayed and edited using standard property syntax
|
||||
* [#327] Inform the ACM SDK of the RAM role name and access the configuration ? ?
|
||||
* [#269] need to support service group in naming module
|
||||
|
||||
## 0.9.0(Feb 28, 2019)
|
||||
|
||||
* [#840] Nacos server adds startup mode to distinguish between config and naming.
|
||||
* [#762] Register instance returns failed when the health check mode is 'server' in standalone mode.
|
||||
* [#473] Nacos Cluster Mode kubernate Startup nacos.log error Log.
|
||||
* [#240] Log strong dependence problem.
|
||||
* [#824] getServicesOfServer throws exception if service list is empty.
|
||||
* [#802] Nacos server multi-boot mode support.
|
||||
* [#800] Nacos's client-to-server addressing mode document introduction.
|
||||
* [#768] The interval at which the heartbeat is sent in BeatReactor is not controlled by the server return value.
|
||||
* [#759] why instance can't auto-delete.
|
||||
* [#756] Format of instance and service should be validated.
|
||||
* [#720] Memory leak in PushService.
|
||||
* [#653] IoUtils under nacos-common-0.2.1-RC1.jar lacks "" judgment on encoding.
|
||||
* [#588] Client compatible to jdk1.6.
|
||||
|
||||
## 0.8.0(Jan 22, 2019) PRE-GA
|
||||
|
||||
* [#162] Support open metrics and prometheus
|
||||
* [#268] Health check is performed in the Nacos startup script
|
||||
* [#320] Nacos supports multiple configuration files, configuration template abstraction and inheritance
|
||||
* [#333] Use nacos in k8s to get hostname exception
|
||||
* [#335] update nacos.io docker img priority/low
|
||||
* [#339] Project language problem identified in github
|
||||
* [#381] Discuss:How to support Login
|
||||
* [#397] Some questions for Nacos
|
||||
* [#402] When the configuration is added or edited, the edit box will not come out
|
||||
* [#462] Nacos monitor discuss (0.8 version)
|
||||
* [#496] Warning log printing when quering a nonexistent service
|
||||
* [#497] Make subscription of service triggered by getInstance method optional
|
||||
* [#498] Support namespace for service discovery
|
||||
* [#499] When the configuration is newly created (if data-id and group already exist), the original configuration will be overwritten
|
||||
* [#512] nacos-logs start.out always print 8848 (but port can be changed)
|
||||
* [#514] Nacos 0.7 not support namespace
|
||||
* [#523] Add a switch to control server detection and client reporting heartbeat switching
|
||||
* [#526] Possible data loss in server side health check mode
|
||||
* [#527] Many repeat client beat tasks can be generated
|
||||
* [#558] Enable access log recording by default
|
||||
* [#560] Nacos server startup issues
|
||||
* [#579] New API support - “update health in none health check mode through api”
|
||||
* [#587] Client sends request concurrently
|
||||
* [#592] Service restful interface put/post is reversed
|
||||
* [#599] getSubscribeServices method gets services that were deregistered
|
||||
* [#603] Format log of naming module
|
||||
* [#609] Always print a NPE log at start
|
||||
* [#663] Nacos update instance info NPE
|
||||
* [#668] 0.8.0-SNAPSHOT naming heartbeat not compatible with lower version client
|
||||
* [#672] Startup.cmd bug
|
||||
|
||||
## 0.7.0(Dec, 2018)
|
||||
|
||||
* [ #461 ] Registration failed when instance port is set to 0
|
||||
* [ #455 ] The console can't change the change code
|
||||
* [ #447 ] 集群模式server挂掉一台后,提供方注册失败
|
||||
* [ #445 ] 0.6.1控制台创建配置发布提交时,提示信息有问题
|
||||
* [ #442 ] Typos in class names and variables.
|
||||
* [ #413 ] The console has some uncaught exceptions
|
||||
* [ #395 ] nacos surport mysql in the case of stand-alone mode
|
||||
* [ #393 ] Support operation of selector on console
|
||||
* [ #365 ] NodeJs SDK support
|
||||
* [ #362 ] The metadata will lost when online or offline instance through web ui
|
||||
* [ #187 ] Provide Label ability for Naming Service into NACOS for complex multi-DC scenario.
|
||||
|
||||
## 0.6.1(Dec, 2018)
|
||||
|
||||
* [#421] NamingService's serivce name can't use colon(:) in Windows
|
||||
* [#432] When packing nacos-core, ${user.home} is replaced in the logback configuration file (nacos.xml)
|
||||
|
||||
## 0.6.0(Dec, 2018)
|
||||
|
||||
* [#388] Cluster name should be provided in the Instance
|
||||
* [#377] Clean up messy code in Naming module
|
||||
* [#369] Support instance list persisted on disk
|
||||
* [#366] findbugs-maven-plugin version
|
||||
* [#362] The metadata will lost when online or offline instance through web ui
|
||||
* [#352] Refactoring internationalization Nacos console
|
||||
* [#278] Nacos docker img
|
||||
* [#243] optimize the efficiency of integration testing, it’s taking too long now
|
||||
|
||||
## 0.5.0(Nov, 2018)
|
||||
|
||||
* [#148] Naming write performace.
|
||||
* [#175] Support deregistering instance automatically.
|
||||
* [#176] Naming client query instance method should bypass local cache at client start.
|
||||
* [#177] Console supports registering new empty service and delete empty service.
|
||||
* [#181] NPE when adding an instance if no leader in the raft cluster.
|
||||
* [#193] Configure host domain name cause nacos server cluster is unavailable.
|
||||
* [#209] Disable service and cluster level customization in client registerInstance method.
|
||||
* [#214] Please support Java 11.
|
||||
* [#222] print more nacos server start status info in start.log.
|
||||
* [#231] Refactoring: Parsing the Nacos home directory and the cluster.conf file.
|
||||
* [#246] "mvn -B clean apache-rat:check findbugs:findbugs" did not work as expected.
|
||||
* [#251] Console Editor Optimization.
|
||||
* [#254] DataId and group are required in historical version and listener query.
|
||||
* [#256] Whether the service discovery data needs to add a newline link symbol.
|
||||
* [#257] Listening query switching query dimension data is not refreshed.
|
||||
* [#258] Remove the Balloon of DataId/Group.
|
||||
* [#259] Listening query paging size problem.
|
||||
* [#272] "#it is ip" is also parsed into an instance IP.
|
||||
* [#275] nacos coredns plugin to support DNS.
|
||||
* [#281] We should lint the console code.
|
||||
* [#302] Maven build project supports java 11.
|
||||
* [#316] In stand alone mode, Nacos still checks the cluster.conf.
|
||||
|
||||
## 0.4.0(Nov 7, 2018)
|
||||
|
||||
* [#216] Fix tenant dir problem
|
||||
* [#197] Service update ignored some properties
|
||||
* [#190] Client beat lose weight info and metadata info
|
||||
* [#188] Console delete data cannot be updated in time
|
||||
* [#179] Listening query fail when namespace is not blank
|
||||
* [#157] Lack information in readme.md to describe the related project repositories for Nacos echosystem
|
||||
* [#144] There have a error and something are not clear
|
||||
* [#106] Snapshot file create error
|
||||
* [#92] Eliminate warnings, refactor code, show start.log detail
|
||||
|
||||
|
||||
## 0.3.0(Oct 26, 2018)
|
||||
|
||||
* [#171] UI debug errors
|
||||
* [#156] Web UI 404 problem
|
||||
* [#155] use local resource
|
||||
* [#145] nacos-example not found :org.apache.logging.log4j.core.Logger
|
||||
* [#142] UI console show Group
|
||||
* [#149] Fix naming client beat process failed bug.
|
||||
* [#150] Fix naming service registration hangs bug.
|
||||
|
||||
## 0.3.0-RC1(Oct 19, 2018)
|
||||
|
||||
* [#33] Support console for config management.
|
||||
* [#51] Support console for naming service.
|
||||
* [#121] Fix get instance method hanging bug.
|
||||
* [#138] Add a flag to indicate if instance is offline.
|
||||
* [#130] Fix health check disabled if machine has one CPU core bug.
|
||||
* [#139] Fix still get instance with zero weight bug.
|
||||
* [#128] Fix console layout bug.
|
||||
|
||||
|
||||
|
||||
## 0.2.1-release(Sept 28, 2018)
|
||||
|
||||
* Fix deregister last instance failed error.
|
||||
* Fix url pattern error.
|
||||
* Fully integrate with and seamlessly support Spring framework, Spring Boot and Spring Cloud
|
||||
* Separate nacos-api from nacos client implementation
|
||||
* Support high available cluster mode
|
||||
* Fix cluster node health check abnormality
|
||||
* Fix stand-alone mode gets the change history list exception
|
||||
* Fix Pulling does not exist configuration print io exception
|
||||
* Optimized log framework
|
||||
* Service Discovery: Client support getting server status.
|
||||
* Service Discovery: Client support get all service names of server.
|
||||
* Service Discovery: Client support get all subscribed services.
|
||||
|
||||
## 0.2.0 (Sept 17, 2018)
|
||||
|
||||
#### FEATURES:
|
||||
|
||||
* separate nacos-api from nacos client implementation
|
||||
* Cluster node health check abnormality
|
||||
* Stand-alone mode gets the change history list exception
|
||||
* Pulling does not exist configuration print io exception
|
||||
* Optimized log framework
|
||||
* Service Discovery: Client support getting server status.
|
||||
* Service Discovery: Client support get all service names of server.
|
||||
* Service Discovery: Client support get all subscribed services.
|
||||
|
||||
|
||||
#### IMPROVEMENTS:
|
||||
|
||||
#### BUG FIXES:
|
||||
|
||||
#### BREAKING CHANGES:
|
||||
|
||||
|
||||
|
||||
## 0.1.0 (July 18, 2018)
|
||||
|
||||
#### FEATURES:
|
||||
|
||||
* Creating, deleting, modifying, and querying configurations: the core functionalities.
|
||||
* Multiple languages support: supports Java/Shell/HTTP OpenAPI.
|
||||
* Service Discovery: Basic service registry and discovery.
|
||||
* Service Discovery: Service load balancing using instance weights, protect threshold and instance health statuses.
|
||||
* Service Discovery: Supports four ways for health check: http, tcp, mysql and client heartbeat.
|
||||
* Service Discovery: CRUD operations on service instances through Java client and open API.
|
||||
* Service Discovery: Service subscribtion and push through Java client.
|
||||
* Nacos official website is coming. https://nacos.io/
|
||||
|
||||
|
||||
|
||||
#### IMPROVEMENTS:
|
||||
|
||||
#### BUG FIXES:
|
||||
|
||||
#### BREAKING CHANGES:
|
||||
73
CODE_OF_CONDUCT.md
Normal file
73
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,73 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
education, socio-economic status, nationality, personal appearance, race,
|
||||
religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at users-nacos@googlegroups.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
124
CONTRIBUTING.md
Normal file
124
CONTRIBUTING.md
Normal file
@ -0,0 +1,124 @@
|
||||
# Contributing to Nacos
|
||||
|
||||
Welcome to Nacos! This document is a guideline about how to contribute to Nacos.
|
||||
|
||||
If you find something incorrect or missing, please leave comments / suggestions.
|
||||
|
||||
## Before you get started
|
||||
|
||||
### Code of Conduct
|
||||
|
||||
Please make sure to read and observe our [Code of Conduct](./CODE_OF_CONDUCT.md).
|
||||
|
||||
## Contributing
|
||||
|
||||
Nacos welcome new participants of any role, including user, contributor, committer and PMC.
|
||||
|
||||

|
||||
|
||||
|
||||
We encourage newcomers actively joining in Nacos projects and involving from user roles to committer roles, and even PMC roles. In order to accomplish this, new comers needs to actively contribute in Nacos project. The following paragraph introduce how to contribute in Nacos way.
|
||||
|
||||
#### Open / pickup an issue for preparation
|
||||
|
||||
If you find a typo in a document, find a bug in code or want new features, or want to give suggestions, you can [open an issue on GitHub](https://github.com/alibaba/Nacos/issues/new) to report it.
|
||||
|
||||
If you just want to contribute directly you can choose the issue below.
|
||||
|
||||
- [Contribution Welcome](https://github.com/alibaba/nacos/labels/contribution%20welcome): Heavily needed issue, but currently short of hand.
|
||||
|
||||
- [good first issue](https://github.com/alibaba/nacos/labels/good%20first%20issue): Good for newcomers, newcomers can pick up one for warm-up.
|
||||
|
||||
|
||||
We strongly value documentation and integration with other projects such as Spring Cloud, Kubernetes, Dubbo, etc. We are very glad to work on any issue for these aspects.
|
||||
|
||||
Please note that any PR must be associated with a valid issue. Otherwise, the PR will be rejected.
|
||||
|
||||
#### Begin your contribution
|
||||
|
||||
Now if you want to contribute, please create a new pull request.
|
||||
|
||||
We use the `develop` branch as the development branch, which indicates that this is an unstable branch.
|
||||
|
||||
Furthermore, our branching model complies with [https://nvie.com/posts/a-successful-git-branching-model/](https://nvie.com/posts/a-successful-git-branching-model/). We strongly suggest new comers walk through the above article before creating PR.
|
||||
|
||||
Now, if you are ready to create PR, here is the workflow for contributors:
|
||||
|
||||
1. Fork to your own
|
||||
|
||||
2. Clone fork to a local repository
|
||||
|
||||
3. Create a new branch and work on it
|
||||
|
||||
4. Keep your branch in sync
|
||||
|
||||
5. Commit your changes (make sure your commit message is concise)
|
||||
|
||||
6. Push your commits to your forked repository
|
||||
|
||||
7. Create a pull request to **develop** branch.
|
||||
|
||||
|
||||
When creating pull request:
|
||||
|
||||
1. Please follow [the pull request template](./.github/PULL_REQUEST_TEMPLATE.md).
|
||||
|
||||
2. Please create the request to **develop** branch.
|
||||
|
||||
3. Please make sure the PR has a corresponding issue.
|
||||
|
||||
4. If your PR contains large changes, e.g. component refactor or new components, please write detailed documents about its design and usage.
|
||||
|
||||
5. Note that a single PR should not be too large. If heavy changes are required, it's better to separate the changes to a few individual PRs.
|
||||
|
||||
6. After creating a PR, one or more reviewers will be assigned to the pull request.
|
||||
|
||||
7. Before merging a PR, squash any fix review feedback, typo, merged and rebased sorts of commits. The final commit message should be clear and concise.
|
||||
|
||||
|
||||
If your PR contains large changes, e.g. component refactor or new components, please write detailed documents about its design and usage.
|
||||
|
||||
### Code review guidance
|
||||
|
||||
Committers will rotate reviewing the code to make sure all the PR will be reviewed timely and by at least one committer before merge. If we aren't doing our job (sometimes we drop things). And as always, we welcome volunteers for code review.
|
||||
|
||||
Some principles:
|
||||
|
||||
- Readability - Important code should be well-documented. API should have Javadoc. Code style should be complied with the existing one.
|
||||
|
||||
- Elegance: New functions, classes or components should be well-designed.
|
||||
|
||||
- Testability - 80% of the new code should be covered by unit test cases.
|
||||
|
||||
- Maintainability - Comply with our [PMD spec](style/codeStyle.md), and 3-month-frequency update should be maintained at least.
|
||||
|
||||
|
||||
### Now how about try become a committer?
|
||||
|
||||
Generally speaking, contribute 8 non-trivial patches and get at least three different people to review them (you'll need three people to support you). Then ask someone to nominate you. You're demonstrating your:
|
||||
|
||||
- at least 8 PR and the associated issues to the project,
|
||||
|
||||
- ability to collaborate with the team,
|
||||
|
||||
- understanding of the projects' code base and coding style, and
|
||||
|
||||
- ability to write good code (last but certainly not least)
|
||||
|
||||
|
||||
A current committer nominates you by slacking the team on the Nacos issue with the label "nomination"
|
||||
|
||||
- your first and last name
|
||||
|
||||
- a link to your Git profile
|
||||
|
||||
- an explanation of why you should be a committer,
|
||||
|
||||
- Elaborate on the top 3 PR and the associated issues the nominator has worked with you that can demonstrate your ability.
|
||||
|
||||
|
||||
Two other committers need to second your nomination. If no one objects in 5 working days (China), you're a committer. If anyone objects or wants more information, the committers discuss and usually come to a consensus (within the 5 working days). If issues cannot be resolved, there's a vote among current committers.
|
||||
|
||||

|
||||
|
||||
In the worst case, this can drag out for two weeks. Keep contributing! Even in the rare cases where a nomination fails, the objection is usually something easy to address like "more patches" or "not enough people are familiar with this person's work."
|
||||
44
Dockerfile
Normal file
44
Dockerfile
Normal file
@ -0,0 +1,44 @@
|
||||
FROM jdk8u112:v1
|
||||
MAINTAINER zhangfucai
|
||||
|
||||
ENV TZ "Asia/Shanghai"
|
||||
RUN echo "set fileencodings=utf-8,gbk,gb2312,gb18030,cp936,latin1 \n set fenc=utf-8 \n set tenc=utf-8 \n set enc=utf-8 \n" |tee ~/.vimrc
|
||||
|
||||
# 定义Nacos版本(可根据需要修改)
|
||||
ENV NACOS_VERSION=2.3.2
|
||||
ENV MODE=standalone
|
||||
ENV BASE_DIR=/home/nacos
|
||||
ENV PREFER_HOST_MODE=hostname
|
||||
|
||||
COPY ./distribution/target/nacos-server-${NACOS_VERSION}.tar.gz /home/
|
||||
|
||||
|
||||
|
||||
# 创建目录并复制本地编译的Nacos包
|
||||
RUN cd /home && \
|
||||
tar -zxvf nacos-server-${NACOS_VERSION}.tar.gz && \
|
||||
rm -rf /home/nacos-server-${NACOS_VERSION}.tar.gz && \
|
||||
rm -rf /home/nacos/bin/*
|
||||
|
||||
WORKDIR ${BASE_DIR}
|
||||
|
||||
# 添加启动脚本
|
||||
ADD ./distribution/bin/docker-startup.sh ${BASE_DIR}/bin/
|
||||
RUN chmod +x ${BASE_DIR}/bin/docker-startup.sh
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8848 9848 9849
|
||||
|
||||
# 设置数据和日志目录为挂载点
|
||||
VOLUME ["${BASE_DIR}/conf/application.properties","${BASE_DIR}/logs", "${BASE_DIR}/data"]
|
||||
|
||||
# 启动命令(支持动态参数)
|
||||
ENTRYPOINT ["sh", "-c", "${BASE_DIR}/bin/docker-startup.sh"]
|
||||
|
||||
# docker build -t nacos-server-kingbase:2.3.0 .
|
||||
# 启动命令
|
||||
# docker run -d --restart always --name nacos-server \
|
||||
# -p 8848:8848 -p 9848:9848 -p 9849:9849 \
|
||||
# -e MODE=standalone \
|
||||
# -v /docker-data/nacos/conf/application.properties:/home/nacos/conf/application.properties \
|
||||
# nacos-server-kingbase:2.3.0
|
||||
44
Dockerfile-arm64
Normal file
44
Dockerfile-arm64
Normal file
@ -0,0 +1,44 @@
|
||||
FROM --platform=linux/arm64 openjdk-arm64:8-jre
|
||||
MAINTAINER zhangfucai
|
||||
|
||||
ENV TZ "Asia/Shanghai"
|
||||
RUN echo "set fileencodings=utf-8,gbk,gb2312,gb18030,cp936,latin1 \n set fenc=utf-8 \n set tenc=utf-8 \n set enc=utf-8 \n" |tee ~/.vimrc
|
||||
|
||||
# 定义Nacos版本(可根据需要修改)
|
||||
ENV NACOS_VERSION=2.3.2
|
||||
ENV MODE=standalone
|
||||
ENV BASE_DIR=/home/nacos
|
||||
ENV PREFER_HOST_MODE=hostname
|
||||
|
||||
COPY ./distribution/target/nacos-server-${NACOS_VERSION}.tar.gz /home/
|
||||
|
||||
|
||||
|
||||
# 创建目录并复制本地编译的Nacos包
|
||||
RUN cd /home && \
|
||||
tar -zxvf nacos-server-${NACOS_VERSION}.tar.gz && \
|
||||
rm -rf /home/nacos-server-${NACOS_VERSION}.tar.gz && \
|
||||
rm -rf /home/nacos/bin/*
|
||||
|
||||
WORKDIR ${BASE_DIR}
|
||||
|
||||
# 添加启动脚本
|
||||
ADD ./distribution/bin/docker-startup.sh ${BASE_DIR}/bin/
|
||||
RUN chmod +x ${BASE_DIR}/bin/docker-startup.sh
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8848 9848 9849
|
||||
|
||||
# 设置数据和日志目录为挂载点
|
||||
VOLUME ["${BASE_DIR}/conf/application.properties","${BASE_DIR}/logs", "${BASE_DIR}/data"]
|
||||
|
||||
# 启动命令(支持动态参数)
|
||||
ENTRYPOINT ["sh", "-c", "${BASE_DIR}/bin/docker-startup.sh"]
|
||||
|
||||
# docker build -f Dockerfile-arm64 -t nacos-server-kingbase-arm64:2.3.0 .
|
||||
# 启动命令
|
||||
# docker run -d --restart always --name nacos-server \
|
||||
# -p 8848:8848 -p 9848:9848 -p 9849:9849 \
|
||||
# -e MODE=standalone \
|
||||
# -v /docker-data/nacos/conf/application.properties:/home/nacos/conf/application.properties \
|
||||
# nacos-server-kingbase:2.3.0
|
||||
108
NOTICE
Normal file
108
NOTICE
Normal file
@ -0,0 +1,108 @@
|
||||
Nacos
|
||||
Copyright 2018-2020
|
||||
|
||||
This product includes software developed at
|
||||
The Alibaba MiddleWare Group.
|
||||
|
||||
------
|
||||
This product has a bundle Spring Boot:
|
||||
The Spring Boot Project
|
||||
=================
|
||||
|
||||
Please visit the Spring Boot web site for more information:
|
||||
|
||||
* https://spring.io/projects/spring-boot
|
||||
|
||||
Copyright 2014 The Spring Boot Project
|
||||
|
||||
The Spring Boot Project 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.
|
||||
|
||||
Also, please refer to each LICENSE.<component>.txt file, which is located in
|
||||
the 'license' directory of the distribution file, for the license terms of the
|
||||
components that this product depends on.
|
||||
|
||||
------
|
||||
This product has a bundle Spring Framework:
|
||||
Spring Framework
|
||||
=================
|
||||
|
||||
Please visit the git for more information:
|
||||
|
||||
* https://github.com/spring-projects/spring-framework.git
|
||||
|
||||
Copyright 2002-2020 the original author or authors.
|
||||
|
||||
The Spring Framework 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.
|
||||
|
||||
Also, please refer to each LICENSE.<component>.txt file, which is located in
|
||||
the 'license' directory of the distribution file, for the license terms of the
|
||||
components that this product depends on.
|
||||
|
||||
------
|
||||
com.alibaba.nacos.common.utils.InetAddressValidator.java in this product is
|
||||
copied from com.dynatrace.openkit.core.util.InetAddressValidator.java of openkit-java project.
|
||||
https://github.com/Dynatrace/openkit-java
|
||||
openkit-java
|
||||
======================
|
||||
|
||||
Copyright 2018-2021 Dynatrace LLC
|
||||
|
||||
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.
|
||||
|
||||
------
|
||||
This product has a bundle Protocol Buffers<72><73>
|
||||
Protocol Buffers
|
||||
=======================
|
||||
Protocol Buffers for Go with Gadgets
|
||||
|
||||
Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
http://github.com/gogo/protobuf
|
||||
|
||||
------
|
||||
This product has a bundle Istio<69><6F>
|
||||
Istio
|
||||
=======================
|
||||
|
||||
Copyright 2018 Istio Authors
|
||||
|
||||
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.
|
||||
17
README.md
17
README.md
@ -1,3 +1,16 @@
|
||||
# nacos-server-kingbase
|
||||
# 项目编译命令:
|
||||
mvn -Prelease-nacos -Dmaven.test.skip=true -Drat.skip=true -Dpmd.skip=true clean install -U
|
||||
* 编译成功标志
|
||||
* 当控制台输出 BUILD SUCCESS 时,说明编译完成。
|
||||
## 生成的可执行文件位于:
|
||||
* distribution/target/nacos-server-${version}.tar.gz # Linux 版本
|
||||
* distribution/target/nacos-server-${version}.zip # Windows 版本
|
||||
|
||||
# 编译docker
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
扩展nacos-kingbase支持
|
||||
39
REPORTING-BUGS.md
Normal file
39
REPORTING-BUGS.md
Normal file
@ -0,0 +1,39 @@
|
||||
# How to report bugs
|
||||
|
||||
If any part of the Nacos project has bugs or documentation mistakes, please let us know by [opening an issue][Nacos-issue]. We treat bugs and mistakes very seriously and believe no issue is too small, anyone is implement. Before creating a bug report, please check that an issue reporting the same problem does not already exist.
|
||||
|
||||
To make the bug report accurate and easy to understand, please try to create bug reports that are:
|
||||
|
||||
- Specific. Include as many details as possible: which version, what environment, what configuration, etc. If the bug is related to running the Nacos server, please attach the Nacos log (the starting log with Nacos configuration is especially important).
|
||||
|
||||
- Reproducible. Include the steps to reproduce the problem. We understand some issues might be hard to reproduce, please includes the steps that might lead to the problem. If possible, please attach the affected Nacos data dir and stack strace to the bug report.
|
||||
|
||||
- Unique. Do not duplicate the existing bug report.
|
||||
|
||||
|
||||
It may be worthwhile to read [Elika Etemad’s article on filing good bug reports][filing-good-bugs] before creating a bug report.
|
||||
|
||||
We might ask for further information to locate a bug. A duplicated bug report will be closed.
|
||||
|
||||
[etcd-issue]: https://github.com/etcd-io/etcd/issues/new
|
||||
[filing-good-bugs]: http://fantasai.inkedblade.net/style/talks/filing-good-bugs/
|
||||
|
||||
|
||||
# 如何提交错误报告
|
||||
|
||||
如果Nacos项目的任何部分存在问题或文档问题,请通过[opening an issue][Nacos-issue]告诉我们。我们非常认真地对待错误和缺陷,在产品面前没有不重要的问题。不过在创建错误报告之前,请检查是否存在报告相同问题的issues。
|
||||
|
||||
为了使错误报告准确且易于理解,请尝试创建以下错误报告:
|
||||
|
||||
- 具体到细节。包括尽可能多的细节:哪个版本,什么环境,什么配置等。如果错误与运行Nacos服务器有关,请附加Nacos日志(具有Nacos配置的起始日志尤为重要)。
|
||||
|
||||
- 可复现。包括重现问题的步骤。我们理解某些问题可能难以重现,请包括可能导致问题的步骤。如果可能,请将受影响的Nacos数据目录和堆栈strace附加到错误报告中。
|
||||
|
||||
- 不重复。不要复制现有的错误报告。
|
||||
|
||||
在创建错误报告之前,最好阅读下[Elika Etemad关于提交好错误报告的文章] [归档好错误],相信 会给你启发。
|
||||
|
||||
我们可能会要求您提供更多信息以查找错误。将关闭重复的错误报告。
|
||||
|
||||
[etcd-issue]:https://github.com/etcd-io/etcd/issues/new
|
||||
[filing-good-bugs]:http://fantasai.inkedblade.net/style/talks/filing-good-bugs/
|
||||
102
address/pom.xml
Normal file
102
address/pom.xml
Normal file
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nacos-address</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>nacos-address ${project.version}</name>
|
||||
<url>https://nacos.io</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-naming</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-cmdb</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release-address</id>
|
||||
<build>
|
||||
<finalName>nacos-address</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.alibaba.nacos.address.AddressServer</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* support address server.
|
||||
*
|
||||
* @author nacos
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos")
|
||||
public class AddressServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(AddressServer.class, args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.common.utils.InternetAddressUtil;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* will generator some result by the input parameter.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-07-01 8:53 PM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class AddressServerGeneratorManager {
|
||||
|
||||
/**
|
||||
* Generate product name.
|
||||
*
|
||||
* @param name name
|
||||
* @return product
|
||||
*/
|
||||
public String generateProductName(String name) {
|
||||
|
||||
if (StringUtils.isBlank(name) || AddressServerConstants.DEFAULT_PRODUCT.equals(name)) {
|
||||
|
||||
return AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME;
|
||||
}
|
||||
|
||||
return String.format(AddressServerConstants.ALIWARE_NACOS_PRODUCT_DOM_TEMPLATE, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: if the parameter inputted is empty then will return the empty list.
|
||||
*
|
||||
* @param serviceName service name
|
||||
* @param clusterName cluster name
|
||||
* @param ipArray array of ips
|
||||
* @return instance list
|
||||
*/
|
||||
public List<Instance> generateInstancesByIps(String serviceName, String rawProductName, String clusterName,
|
||||
String[] ipArray) {
|
||||
if (StringUtils.isEmpty(serviceName) || StringUtils.isEmpty(clusterName) || ipArray == null
|
||||
|| ipArray.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Instance> instanceList = new ArrayList<>(ipArray.length);
|
||||
for (String ip : ipArray) {
|
||||
String[] ipAndPort = generateIpAndPort(ip);
|
||||
Instance instance = new Instance();
|
||||
instance.setIp(ipAndPort[0]);
|
||||
instance.setPort(Integer.parseInt(ipAndPort[1]));
|
||||
instance.setClusterName(clusterName);
|
||||
instance.setServiceName(serviceName);
|
||||
instance.setEphemeral(false);
|
||||
instance.getMetadata().put("app", rawProductName);
|
||||
instance.getMetadata().put("tenant", Constants.DEFAULT_NAMESPACE_ID);
|
||||
instanceList.add(instance);
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
private String[] generateIpAndPort(String ip) {
|
||||
String[] result = InternetAddressUtil.splitIPPortStr(ip);
|
||||
if (result.length != InternetAddressUtil.SPLIT_IP_PORT_RESULT_LENGTH) {
|
||||
return new String[] {result[0], String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate response ips.
|
||||
*
|
||||
* @param instanceList an instance set will generate string response to client.
|
||||
* @return the result of response to client
|
||||
*/
|
||||
public String generateResponseIps(List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList) {
|
||||
|
||||
StringBuilder ips = new StringBuilder();
|
||||
instanceList.forEach(instance -> {
|
||||
ips.append(instance.getIp()).append(':').append(instance.getPort());
|
||||
ips.append('\n');
|
||||
});
|
||||
|
||||
return ips.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate nacos service name.
|
||||
*
|
||||
* @param rawServiceName the raw service name will not contain the {@link Constants#DEFAULT_GROUP}.
|
||||
* @return the nacos service name
|
||||
*/
|
||||
public String generateNacosServiceName(String rawServiceName) {
|
||||
|
||||
if (rawServiceName.contains(Constants.DEFAULT_GROUP)) {
|
||||
return rawServiceName;
|
||||
}
|
||||
|
||||
return Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + rawServiceName;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This class holds the IP list of the CAI's address service.
|
||||
*
|
||||
* @author deshao
|
||||
* @date 2016/4/28 20:58
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class AddressServerManager {
|
||||
|
||||
public String getRawProductName(String name) {
|
||||
|
||||
if (StringUtils.isBlank(name)) {
|
||||
|
||||
return AddressServerConstants.DEFAULT_PRODUCT;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the name is empty then return the default {@link UtilsAndCommons#DEFAULT_CLUSTER_NAME}, or return the source
|
||||
* name by input.
|
||||
*
|
||||
* @param name name
|
||||
* @return default cluster name
|
||||
*/
|
||||
public String getDefaultClusterNameIfEmpty(String name) {
|
||||
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return AddressServerConstants.DEFAULT_GET_CLUSTER;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRawClusterName(String name) {
|
||||
|
||||
return getDefaultClusterNameIfEmpty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split ips.
|
||||
*
|
||||
* @param ips multi ip will separator by the ','
|
||||
* @return array of ip
|
||||
*/
|
||||
public String[] splitIps(String ips) {
|
||||
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
return ips.split(AddressServerConstants.MULTI_IPS_SEPARATOR);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
/**
|
||||
* nacos web security configuration.
|
||||
*
|
||||
* @author onewe
|
||||
*/
|
||||
@Configuration
|
||||
public class AddressServerSecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(99)
|
||||
public SecurityFilterChain addressServerSecurityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests(
|
||||
requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated()).csrf()
|
||||
.disable().httpBasic();
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.constant;
|
||||
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
||||
/**
|
||||
* Uniform constant parameter naming for address servers and default values for related parameters.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-06-17 7:23 PM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public interface AddressServerConstants {
|
||||
|
||||
|
||||
/**
|
||||
* the default server port when create the Instance object.
|
||||
*/
|
||||
int DEFAULT_SERVER_PORT = 8848;
|
||||
|
||||
/**
|
||||
* when post ips is not given the product,then use the default.
|
||||
*/
|
||||
String DEFAULT_PRODUCT = "nacos";
|
||||
|
||||
/**
|
||||
* the separator for service name between raw service name and group.
|
||||
*/
|
||||
String GROUP_SERVICE_NAME_SEP = "@@";
|
||||
|
||||
/**
|
||||
* when post ips is not given the cluster,then use the default.
|
||||
*/
|
||||
String DEFAULT_GET_CLUSTER = "serverlist";
|
||||
|
||||
/**
|
||||
* post multi ip will use the "," to separator.
|
||||
*/
|
||||
String MULTI_IPS_SEPARATOR = ",";
|
||||
|
||||
/**
|
||||
* the default product name when deploy nacos with naming and config.
|
||||
*/
|
||||
String ALIWARE_NACOS_DEFAULT_PRODUCT_NAME = "nacos.as.default";
|
||||
|
||||
/**
|
||||
* when the config and naming will separate deploy,then must specify product name by the client.
|
||||
*/
|
||||
String ALIWARE_NACOS_PRODUCT_DOM_TEMPLATE = "nacos.as.%s";
|
||||
|
||||
/**
|
||||
* the url for address server prefix.
|
||||
*/
|
||||
String ADDRESS_SERVER_REQUEST_URL =
|
||||
UtilsAndCommons.NACOS_SERVER_CONTEXT + UtilsAndCommons.NACOS_SERVER_VERSION + "/as";
|
||||
|
||||
}
|
||||
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
import com.alibaba.nacos.address.component.AddressServerManager;
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.address.misc.Loggers;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.api.naming.utils.NamingUtils;
|
||||
import com.alibaba.nacos.common.utils.InternetAddressUtil;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.naming.core.ClusterOperator;
|
||||
import com.alibaba.nacos.naming.core.InstanceOperator;
|
||||
import com.alibaba.nacos.naming.core.v2.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Address server cluster controller.
|
||||
*
|
||||
* @author pbting
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping({AddressServerConstants.ADDRESS_SERVER_REQUEST_URL + "/nodes"})
|
||||
public class AddressServerClusterController {
|
||||
|
||||
private final InstanceOperator instanceOperator;
|
||||
|
||||
private final NamingMetadataManager metadataManager;
|
||||
|
||||
private final ClusterOperator clusterOperator;
|
||||
|
||||
private final AddressServerManager addressServerManager;
|
||||
|
||||
private final AddressServerGeneratorManager addressServerGeneratorManager;
|
||||
|
||||
public AddressServerClusterController(InstanceOperator instanceOperator, NamingMetadataManager metadataManager,
|
||||
ClusterOperator clusterOperator, AddressServerManager addressServerManager,
|
||||
AddressServerGeneratorManager addressServerGeneratorManager) {
|
||||
this.instanceOperator = instanceOperator;
|
||||
this.metadataManager = metadataManager;
|
||||
this.clusterOperator = clusterOperator;
|
||||
this.addressServerManager = addressServerManager;
|
||||
this.addressServerGeneratorManager = addressServerGeneratorManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new cluster.
|
||||
*
|
||||
* @param product Ip list of products to be associated
|
||||
* @param cluster Ip list of product cluster to be associated
|
||||
* @param ips will post ip list.
|
||||
* @return result of create new cluster
|
||||
*/
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public ResponseEntity<String> postCluster(@RequestParam(required = false) String product,
|
||||
@RequestParam(required = false) String cluster, @RequestParam(name = "ips") String ips) {
|
||||
|
||||
//1. prepare the storage name for product and cluster
|
||||
String productName = addressServerGeneratorManager.generateProductName(product);
|
||||
String clusterName = addressServerManager.getDefaultClusterNameIfEmpty(cluster);
|
||||
|
||||
//2. prepare the response name for product and cluster to client
|
||||
String rawProductName = addressServerManager.getRawProductName(product);
|
||||
String rawClusterName = addressServerManager.getRawClusterName(cluster);
|
||||
Loggers.ADDRESS_LOGGER.info("put cluster node,the cluster name is " + cluster + "; the product name=" + product
|
||||
+ "; the ip list=" + ips);
|
||||
ResponseEntity<String> responseEntity;
|
||||
try {
|
||||
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
|
||||
|
||||
Result result = registerCluster(serviceName, rawProductName, clusterName, ips);
|
||||
if (InternetAddressUtil.checkOK(result.getCheckResult())) {
|
||||
responseEntity = ResponseEntity
|
||||
.ok("product=" + rawProductName + ",cluster=" + rawClusterName + "; put success with size="
|
||||
+ result.getSize());
|
||||
} else {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result.getCheckResult());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
|
||||
}
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
private Result registerCluster(String serviceName, String productName, String clusterName, String ips)
|
||||
throws NacosException {
|
||||
String serviceWithoutGroup = NamingUtils.getServiceName(serviceName);
|
||||
String groupName = NamingUtils.getGroupName(serviceName);
|
||||
Service service = Service.newService(Constants.DEFAULT_NAMESPACE_ID, groupName, serviceWithoutGroup, false);
|
||||
service = ServiceManager.getInstance().getSingleton(service);
|
||||
if (service.isEphemeral()) {
|
||||
return new Result(
|
||||
String.format("Service %s is ephemeral service, can't use as address server", serviceName), 0);
|
||||
}
|
||||
ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(service).orElse(new ServiceMetadata());
|
||||
if (!serviceMetadata.getClusters().containsKey(clusterName)) {
|
||||
ClusterMetadata metadata = new ClusterMetadata();
|
||||
metadata.setHealthyCheckType(AbstractHealthChecker.None.TYPE);
|
||||
metadata.setHealthChecker(new AbstractHealthChecker.None());
|
||||
clusterOperator.updateClusterMetadata(Constants.DEFAULT_NAMESPACE_ID, serviceName, clusterName, metadata);
|
||||
}
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = InternetAddressUtil.checkIPs(ipArray);
|
||||
if (InternetAddressUtil.checkOK(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, productName, clusterName, ipArray);
|
||||
for (Instance instance : instanceList) {
|
||||
instanceOperator.registerInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, instance);
|
||||
}
|
||||
}
|
||||
return new Result(checkResult, ipArray.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete cluster.
|
||||
*
|
||||
* @param product Ip list of products to be associated
|
||||
* @param cluster Ip list of product cluster to be associated
|
||||
* @param ips will delete ips.
|
||||
* @return delete result (the cluster information is return if success, exception information is return if fail)
|
||||
*/
|
||||
@RequestMapping(value = "", method = RequestMethod.DELETE)
|
||||
public ResponseEntity<String> deleteCluster(@RequestParam(required = false) String product,
|
||||
@RequestParam(required = false) String cluster, @RequestParam String ips) {
|
||||
//1. prepare the storage name for product and cluster
|
||||
String productName = addressServerGeneratorManager.generateProductName(product);
|
||||
String clusterName = addressServerManager.getDefaultClusterNameIfEmpty(cluster);
|
||||
|
||||
//2. prepare the response name for product and cluster to client
|
||||
String rawProductName = addressServerManager.getRawProductName(product);
|
||||
String rawClusterName = addressServerManager.getRawClusterName(cluster);
|
||||
ResponseEntity responseEntity = ResponseEntity.status(HttpStatus.OK)
|
||||
.body("product=" + rawProductName + ", cluster=" + rawClusterName + " delete success.");
|
||||
try {
|
||||
|
||||
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
|
||||
String serviceWithoutGroup = NamingUtils.getServiceName(serviceName);
|
||||
String groupName = NamingUtils.getGroupName(serviceName);
|
||||
Optional<com.alibaba.nacos.naming.core.v2.pojo.Service> service = com.alibaba.nacos.naming.core.v2.ServiceManager
|
||||
.getInstance().getSingletonIfExist(Constants.DEFAULT_NAMESPACE_ID, groupName, serviceWithoutGroup);
|
||||
|
||||
if (!service.isPresent()) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + rawProductName + " not found.");
|
||||
}
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
// delete all ips from the cluster
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("ips must not be empty.");
|
||||
}
|
||||
// delete specified ip list
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = InternetAddressUtil.checkIPs(ipArray);
|
||||
if (InternetAddressUtil.checkOK(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
for (Instance each : instanceList) {
|
||||
instanceOperator.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, each);
|
||||
}
|
||||
} else {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getCause());
|
||||
}
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
private class Result {
|
||||
|
||||
private final String checkResult;
|
||||
|
||||
private final int size;
|
||||
|
||||
public Result(String checkResult, int size) {
|
||||
this.checkResult = checkResult;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getCheckResult() {
|
||||
return checkResult;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||
import com.alibaba.nacos.api.naming.utils.NamingUtils;
|
||||
import com.alibaba.nacos.naming.core.v2.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.v2.index.ServiceStorage;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import com.alibaba.nacos.naming.utils.ServiceUtil;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Server list controller.
|
||||
*
|
||||
* @author pbting
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@RestController
|
||||
public class ServerListController {
|
||||
|
||||
private final AddressServerGeneratorManager addressServerBuilderManager;
|
||||
|
||||
private final NamingMetadataManager metadataManager;
|
||||
|
||||
private final ServiceStorage serviceStorage;
|
||||
|
||||
public ServerListController(AddressServerGeneratorManager addressServerBuilderManager,
|
||||
NamingMetadataManager metadataManager, ServiceStorage serviceStorage) {
|
||||
this.addressServerBuilderManager = addressServerBuilderManager;
|
||||
this.metadataManager = metadataManager;
|
||||
this.serviceStorage = serviceStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cluster.
|
||||
*
|
||||
* @param product will get Ip list of that products to be associated
|
||||
* @param cluster will get Ip list of that product cluster to be associated
|
||||
* @return result of get
|
||||
*/
|
||||
@RequestMapping(value = "/{product}/{cluster}", method = RequestMethod.GET)
|
||||
public ResponseEntity<String> getCluster(@PathVariable String product, @PathVariable String cluster) {
|
||||
|
||||
String productName = addressServerBuilderManager.generateProductName(product);
|
||||
String serviceName = addressServerBuilderManager.generateNacosServiceName(productName);
|
||||
String serviceWithoutGroup = NamingUtils.getServiceName(serviceName);
|
||||
String groupName = NamingUtils.getGroupName(serviceName);
|
||||
Optional<Service> service = ServiceManager.getInstance()
|
||||
.getSingletonIfExist(Constants.DEFAULT_NAMESPACE_ID, groupName, serviceWithoutGroup);
|
||||
if (!service.isPresent()) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + product + " not found.");
|
||||
}
|
||||
ClusterMetadata metadata = metadataManager.getServiceMetadata(service.get()).orElse(new ServiceMetadata())
|
||||
.getClusters().get(cluster);
|
||||
if (null == metadata) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body("product=" + product + ",cluster=" + cluster + " not found.");
|
||||
}
|
||||
ServiceInfo serviceInfo = serviceStorage.getData(service.get());
|
||||
serviceInfo = ServiceUtil.selectInstances(serviceInfo, cluster, false);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(addressServerBuilderManager.generateResponseIps(serviceInfo.getHosts()));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.misc;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Loggers holder.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-07-04 4:34 PM
|
||||
*/
|
||||
public class Loggers {
|
||||
|
||||
public static final Logger ADDRESS_LOGGER = LoggerFactory.getLogger("com.alibaba.nacos.address.main");
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<included>
|
||||
|
||||
<springProperty scope="context" name="logPath" source="nacos.logs.path" defaultValue="${user.home}/nacos/logs"/>
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
|
||||
<appender name="nacos-address"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_HOME}/nacos-address.log</file>
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_HOME}/nacos-address.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>2GB</maxFileSize>
|
||||
<maxHistory>15</maxHistory>
|
||||
<totalSizeCap>7GB</totalSizeCap>
|
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<Pattern>%date %level %msg%n%n</Pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="com.alibaba.nacos.address.main" additivity="false">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="nacos-address"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
16
address/src/main/resources/META-INF/nacos-default.properties
Normal file
16
address/src/main/resources/META-INF/nacos-default.properties
Normal file
@ -0,0 +1,16 @@
|
||||
#
|
||||
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
17
address/src/main/resources/application.properties
Normal file
17
address/src/main/resources/application.properties
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
server.port=8080
|
||||
server.servlet.context-path=/
|
||||
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddressServerGeneratorManagerTest {
|
||||
|
||||
@Test
|
||||
public void testGenerateProductName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final String blankName = manager.generateProductName("");
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||
|
||||
final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||
|
||||
final String testName = manager.generateProductName("test");
|
||||
Assert.assertEquals("nacos.as.test", testName);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateInstancesByIps() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
|
||||
Assert.assertNotNull(empty);
|
||||
Assert.assertTrue(empty.isEmpty());
|
||||
|
||||
String[] ipArray = new String[]{"192.168.3.1:8848", "192.168.3.2:8848", "192.168.3.3:8848"};
|
||||
final List<Instance> instanceList = manager.generateInstancesByIps("DEFAULT_GROUP@@nacos.as.test", "test", "test",
|
||||
ipArray);
|
||||
Assert.assertNotNull(instanceList);
|
||||
Assert.assertFalse(instanceList.isEmpty());
|
||||
Assert.assertEquals(3, instanceList.size());
|
||||
|
||||
final Instance instance1 = instanceList.get(0);
|
||||
Assert.assertEquals("192.168.3.1", instance1.getIp());
|
||||
|
||||
final Instance instance2 = instanceList.get(1);
|
||||
Assert.assertEquals("192.168.3.2", instance2.getIp());
|
||||
|
||||
final Instance instance3 = instanceList.get(2);
|
||||
Assert.assertEquals("192.168.3.3", instance3.getIp());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateResponseIps() {
|
||||
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
|
||||
Instance instance1 = new Instance();
|
||||
instance1.setIp("192.168.3.1");
|
||||
instance1.setPort(8848);
|
||||
|
||||
Instance instance2 = new Instance();
|
||||
instance2.setIp("192.168.3.2");
|
||||
instance2.setPort(8848);
|
||||
|
||||
Instance instance3 = new Instance();
|
||||
instance3.setIp("192.168.3.3");
|
||||
instance3.setPort(8848);
|
||||
|
||||
instanceList.add(instance1);
|
||||
instanceList.add(instance2);
|
||||
instanceList.add(instance3);
|
||||
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final String ipListStr = manager.generateResponseIps(instanceList);
|
||||
|
||||
StringBuilder expectStr = new StringBuilder();
|
||||
final StringBuilder ret = expectStr
|
||||
.append("192.168.3.1:8848").append('\n')
|
||||
.append("192.168.3.2:8848").append('\n')
|
||||
.append("192.168.3.3:8848").append('\n');
|
||||
Assert.assertEquals(ret.toString(), ipListStr);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateNacosServiceName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
|
||||
final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
|
||||
Assert.assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||
|
||||
final String product = manager.generateNacosServiceName("product");
|
||||
Assert.assertEquals("DEFAULT_GROUP@@product", product);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AddressServerManagerTests {
|
||||
|
||||
private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();
|
||||
|
||||
@Test
|
||||
public void getRawProductName() {
|
||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT, ADDRESS_SERVER_MANAGER.getRawProductName(""));
|
||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT,
|
||||
ADDRESS_SERVER_MANAGER.getRawProductName(AddressServerConstants.DEFAULT_PRODUCT));
|
||||
assertEquals("otherProduct", ADDRESS_SERVER_MANAGER.getRawProductName("otherProduct"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultClusterNameIfEmpty() {
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(""));
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER,
|
||||
ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(AddressServerConstants.DEFAULT_GET_CLUSTER));
|
||||
assertEquals("otherServerList", ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty("otherServerList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRawClusterName() {
|
||||
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitIps() {
|
||||
final String[] emptyArr = ADDRESS_SERVER_MANAGER.splitIps("");
|
||||
assertEquals(0, emptyArr.length);
|
||||
final String[] one = ADDRESS_SERVER_MANAGER.splitIps("192.168.1.12:8848");
|
||||
assertEquals(1, one.length);
|
||||
assertEquals("192.168.1.12:8848", one[0]);
|
||||
final String[] two = ADDRESS_SERVER_MANAGER.splitIps("192.168.1.12:8848,192.268.3.33:8848");
|
||||
assertEquals(2, two.length);
|
||||
assertEquals("192.168.1.12:8848", two[0]);
|
||||
assertEquals("192.268.3.33:8848", two[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
import com.alibaba.nacos.address.component.AddressServerManager;
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.core.ClusterOperator;
|
||||
import com.alibaba.nacos.naming.core.InstanceOperator;
|
||||
import com.alibaba.nacos.naming.core.v2.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AddressServerClusterControllerTest {
|
||||
|
||||
@Mock
|
||||
private InstanceOperator instanceOperator;
|
||||
|
||||
@Mock
|
||||
private NamingMetadataManager metadataManager;
|
||||
|
||||
@Mock
|
||||
private ClusterOperator clusterOperator;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(
|
||||
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
|
||||
new AddressServerManager(), new AddressServerGeneratorManager())).build();
|
||||
Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().getSingleton(service);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostCluster() throws Exception {
|
||||
|
||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostClusterWithErrorIps() throws Exception {
|
||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostClusterThrowException() throws Exception {
|
||||
|
||||
Mockito.doThrow(new NacosException(500, "create service error")).when(clusterOperator)
|
||||
.updateClusterMetadata(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||
Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + "nacos.as.default"),
|
||||
Mockito.eq("serverList"), Mockito.any());
|
||||
|
||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCluster() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterCannotFindService() throws Exception {
|
||||
tearDown();
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterEmptyIps() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterErrorIps() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterThrowException() throws Exception {
|
||||
Mockito.doThrow(new NacosException(500, "remove service error")).when(instanceOperator)
|
||||
.removeInstance(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||
Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + "nacos.as.default"),
|
||||
Mockito.any());
|
||||
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isInternalServerError());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||
import com.alibaba.nacos.naming.core.v2.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.v2.index.ServiceStorage;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServerListControllerTest {
|
||||
|
||||
@Mock
|
||||
private NamingMetadataManager metadataManager;
|
||||
|
||||
@Mock
|
||||
private ServiceStorage serviceStorage;
|
||||
|
||||
private Service service;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(
|
||||
new ServerListController(new AddressServerGeneratorManager(), metadataManager, serviceStorage)).build();
|
||||
service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().getSingleton(service);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCluster() throws Exception {
|
||||
|
||||
final Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceMetadata serviceMetadata = new ServiceMetadata();
|
||||
serviceMetadata.getClusters().put("serverList", new ClusterMetadata());
|
||||
when(metadataManager.getServiceMetadata(service)).thenReturn(Optional.of(serviceMetadata));
|
||||
List<Instance> list = new ArrayList<>(2);
|
||||
list.add(new Instance());
|
||||
list.add(new Instance());
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.setHosts(list);
|
||||
when(serviceStorage.getData(service)).thenReturn(serviceInfo);
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClusterCannotFindService() throws Exception {
|
||||
tearDown();
|
||||
mockMvc.perform(get("/default/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClusterCannotFindCluster() throws Exception {
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
}
|
||||
118
api/pom.xml
Normal file
118
api/pom.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nacos-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>nacos-api ${project.version}</name>
|
||||
<url>https://nacos.io</url>
|
||||
<description>Nacos api pom.xml file</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- reuse when you need to update grpc model -->
|
||||
<!-- <plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>0.5.0</version>
|
||||
<version>0.6.1</version>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-java.version}:exe:${os.detected.classifier}</pluginArtifact>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo.maven.apache.org/maven2</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-protobuf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api.grpc</groupId>
|
||||
<artifactId>proto-google-common-protos</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 其他依赖 -->
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
<!-- <scope>compile</scope> -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
101
api/src/main/java/com/alibaba/nacos/api/NacosFactory.java
Normal file
101
api/src/main/java/com/alibaba/nacos/api/NacosFactory.java
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Nacos Factory.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class NacosFactory {
|
||||
|
||||
/**
|
||||
* Create config service.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return config
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static ConfigService createConfigService(Properties properties) throws NacosException {
|
||||
return ConfigFactory.createConfigService(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create config service.
|
||||
*
|
||||
* @param serverAddr server list
|
||||
* @return config
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static ConfigService createConfigService(String serverAddr) throws NacosException {
|
||||
return ConfigFactory.createConfigService(serverAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create naming service.
|
||||
*
|
||||
* @param serverAddr server list
|
||||
* @return Naming
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static NamingService createNamingService(String serverAddr) throws NacosException {
|
||||
return NamingFactory.createNamingService(serverAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create naming service.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return Naming
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static NamingService createNamingService(Properties properties) throws NacosException {
|
||||
return NamingFactory.createNamingService(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create maintain service.
|
||||
*
|
||||
* @param serverAddr server address
|
||||
* @return NamingMaintainService
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException {
|
||||
return NamingMaintainFactory.createMaintainService(serverAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create maintain service.
|
||||
*
|
||||
* @param properties server address
|
||||
* @return NamingMaintainService
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
|
||||
return NamingMaintainFactory.createMaintainService(properties);
|
||||
}
|
||||
}
|
||||
106
api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Normal file
106
api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
/**
|
||||
* Property Key Const.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class PropertyKeyConst {
|
||||
|
||||
public static final String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing";
|
||||
|
||||
public static final String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
||||
|
||||
public static final String ENDPOINT = "endpoint";
|
||||
|
||||
public static final String ENDPOINT_QUERY_PARAMS = "endpointQueryParams";
|
||||
|
||||
public static final String ENDPOINT_PORT = "endpointPort";
|
||||
|
||||
public static final String ENDPOINT_CONTEXT_PATH = "endpointContextPath";
|
||||
|
||||
public static final String SERVER_NAME = "serverName";
|
||||
|
||||
public static final String NAMESPACE = "namespace";
|
||||
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
public static final String PASSWORD = "password";
|
||||
|
||||
public static final String ACCESS_KEY = "accessKey";
|
||||
|
||||
public static final String SECRET_KEY = "secretKey";
|
||||
|
||||
public static final String RAM_ROLE_NAME = "ramRoleName";
|
||||
|
||||
public static final String SERVER_ADDR = "serverAddr";
|
||||
|
||||
public static final String CONTEXT_PATH = "contextPath";
|
||||
|
||||
public static final String CLUSTER_NAME = "clusterName";
|
||||
|
||||
public static final String ENCODE = "encode";
|
||||
|
||||
public static final String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
public static final String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
public static final String CLIENT_WORKER_MAX_THREAD_COUNT = "clientWorkerMaxThreadCount";
|
||||
|
||||
public static final String CLIENT_WORKER_THREAD_COUNT = "clientWorkerThreadCount";
|
||||
|
||||
public static final String MAX_RETRY = "maxRetry";
|
||||
|
||||
public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
public static final String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
|
||||
|
||||
public static final String NAMING_CACHE_REGISTRY_DIR = "namingCacheRegistryDir";
|
||||
|
||||
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_MAX_THREAD_COUNT = "namingPollingMaxThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";
|
||||
|
||||
public static final String NAMING_PUSH_EMPTY_PROTECTION = "namingPushEmptyProtection";
|
||||
|
||||
public static final String NAMING_ASYNC_QUERY_SUBSCRIBE_SERVICE = "namingAsyncQuerySubscribeService";
|
||||
|
||||
public static final String REDO_DELAY_TIME = "redoDelayTime";
|
||||
|
||||
public static final String REDO_DELAY_THREAD_COUNT = "redoDelayThreadCount";
|
||||
|
||||
/**
|
||||
* Get the key value of some variable value from the system property.
|
||||
*/
|
||||
public static class SystemEnv {
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_CONTEXT_PATH = "ALIBABA_ALIWARE_ENDPOINT_CONTEXT_PATH";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_NAMESPACE = "ALIBABA_ALIWARE_NAMESPACE";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
/**
|
||||
* Support for reading the value of the specified variable from the -D parameter.
|
||||
*
|
||||
* <p>Properties that are preferred to which in {@link PropertyKeyConst}
|
||||
*
|
||||
* @author pbting
|
||||
*/
|
||||
public interface SystemPropertyKeyConst {
|
||||
|
||||
String NAMING_SERVER_PORT = "nacos.naming.exposed.port";
|
||||
|
||||
/**
|
||||
* In the cloud (Alibaba Cloud or other cloud vendors) environment, whether to enable namespace resolution in the
|
||||
* cloud environment.
|
||||
* <p>
|
||||
* The default is on.
|
||||
* </p>
|
||||
*/
|
||||
String IS_USE_CLOUD_NAMESPACE_PARSING = "nacos.use.cloud.namespace.parsing";
|
||||
|
||||
/**
|
||||
* In the cloud environment, if the process level requires a globally uniform namespace, it can be specified with
|
||||
* the -D parameter.
|
||||
*/
|
||||
String ANS_NAMESPACE = "ans.namespace";
|
||||
|
||||
/**
|
||||
* It is also supported by the -D parameter.
|
||||
*/
|
||||
String IS_USE_ENDPOINT_PARSING_RULE = "nacos.use.endpoint.parsing.rule";
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability;
|
||||
|
||||
import com.alibaba.nacos.api.config.ability.ClientConfigAbility;
|
||||
import com.alibaba.nacos.api.naming.ability.ClientNamingAbility;
|
||||
import com.alibaba.nacos.api.remote.ability.ClientRemoteAbility;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* abilities of nacos client.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
@Deprecated
|
||||
public class ClientAbilities implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3590789441404549261L;
|
||||
|
||||
private ClientRemoteAbility remoteAbility = new ClientRemoteAbility();
|
||||
|
||||
private ClientConfigAbility configAbility = new ClientConfigAbility();
|
||||
|
||||
private ClientNamingAbility namingAbility = new ClientNamingAbility();
|
||||
|
||||
public ClientRemoteAbility getRemoteAbility() {
|
||||
return remoteAbility;
|
||||
}
|
||||
|
||||
public void setRemoteAbility(ClientRemoteAbility remoteAbility) {
|
||||
this.remoteAbility = remoteAbility;
|
||||
}
|
||||
|
||||
public ClientConfigAbility getConfigAbility() {
|
||||
return configAbility;
|
||||
}
|
||||
|
||||
public void setConfigAbility(ClientConfigAbility configAbility) {
|
||||
this.configAbility = configAbility;
|
||||
}
|
||||
|
||||
public ClientNamingAbility getNamingAbility() {
|
||||
return namingAbility;
|
||||
}
|
||||
|
||||
public void setNamingAbility(ClientNamingAbility namingAbility) {
|
||||
this.namingAbility = namingAbility;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability;
|
||||
|
||||
import com.alibaba.nacos.api.config.ability.ServerConfigAbility;
|
||||
import com.alibaba.nacos.api.naming.ability.ServerNamingAbility;
|
||||
import com.alibaba.nacos.api.remote.ability.ServerRemoteAbility;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* abilities of nacos server.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ServerAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
@Deprecated
|
||||
public class ServerAbilities implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2120543002911304171L;
|
||||
|
||||
private ServerRemoteAbility remoteAbility = new ServerRemoteAbility();
|
||||
|
||||
private ServerConfigAbility configAbility = new ServerConfigAbility();
|
||||
|
||||
private ServerNamingAbility namingAbility = new ServerNamingAbility();
|
||||
|
||||
public ServerRemoteAbility getRemoteAbility() {
|
||||
return remoteAbility;
|
||||
}
|
||||
|
||||
public void setRemoteAbility(ServerRemoteAbility remoteAbility) {
|
||||
this.remoteAbility = remoteAbility;
|
||||
}
|
||||
|
||||
public ServerConfigAbility getConfigAbility() {
|
||||
return configAbility;
|
||||
}
|
||||
|
||||
public void setConfigAbility(ServerConfigAbility configAbility) {
|
||||
this.configAbility = configAbility;
|
||||
}
|
||||
|
||||
public ServerNamingAbility getNamingAbility() {
|
||||
return namingAbility;
|
||||
}
|
||||
|
||||
public void setNamingAbility(ServerNamingAbility namingAbility) {
|
||||
this.namingAbility = namingAbility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ServerAbilities that = (ServerAbilities) o;
|
||||
return Objects.equals(remoteAbility, that.remoteAbility) && Objects.equals(configAbility, that.configAbility)
|
||||
&& Objects.equals(namingAbility, that.namingAbility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(remoteAbility, configAbility, namingAbility);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.constant;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Ability key constant. It is used to constrain the ability key.<br/>
|
||||
* <strong>Ensure that return value of {@link AbilityKey#getName()} is unique under one specify {@link AbilityMode}</strong>.
|
||||
*
|
||||
* @author Daydreamer
|
||||
* @date 2022/8/31 12:27
|
||||
**/
|
||||
public enum AbilityKey {
|
||||
|
||||
/**
|
||||
* Server support register or deregister persistent instance by grpc.
|
||||
*/
|
||||
SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC("supportPersistentInstanceByGrpc",
|
||||
"support persistent instance by grpc", AbilityMode.SERVER),
|
||||
|
||||
/**
|
||||
* For Test temporarily.
|
||||
*/
|
||||
SERVER_TEST_1("test_1", "just for junit test", AbilityMode.SERVER),
|
||||
|
||||
/**
|
||||
* For Test temporarily.
|
||||
*/
|
||||
SERVER_TEST_2("test_2", "just for junit test", AbilityMode.SERVER),
|
||||
|
||||
/**
|
||||
* For Test temporarily.
|
||||
*/
|
||||
SDK_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.SDK_CLIENT),
|
||||
|
||||
/**
|
||||
* For Test temporarily.
|
||||
*/
|
||||
CLUSTER_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.CLUSTER_CLIENT);
|
||||
|
||||
/**
|
||||
* the name of a certain ability.
|
||||
*/
|
||||
private final String keyName;
|
||||
|
||||
/**
|
||||
* description or comment about this ability.
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* ability mode, which endpoint hold this ability.
|
||||
*/
|
||||
private final AbilityMode mode;
|
||||
|
||||
AbilityKey(String keyName, String description, AbilityMode mode) {
|
||||
this.keyName = keyName;
|
||||
this.description = description;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return keyName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public AbilityMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* All key set.
|
||||
*/
|
||||
private static final Map<AbilityMode, Map<String, AbilityKey>> ALL_ABILITIES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Get all keys.
|
||||
*
|
||||
* @return all keys
|
||||
*/
|
||||
public static Collection<AbilityKey> getAllValues(AbilityMode mode) {
|
||||
return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all names.
|
||||
*
|
||||
* @return all names
|
||||
*/
|
||||
public static Collection<String> getAllNames(AbilityMode mode) {
|
||||
return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether contains this name.
|
||||
*
|
||||
* @param name key name
|
||||
* @return whether contains
|
||||
*/
|
||||
public static boolean isLegalKey(AbilityMode mode, String name) {
|
||||
return ALL_ABILITIES.get(mode).containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the string key to enum.
|
||||
*
|
||||
* @param abilities map
|
||||
* @return enum map
|
||||
*/
|
||||
public static Map<AbilityKey, Boolean> mapEnum(AbilityMode mode, Map<String, Boolean> abilities) {
|
||||
if (abilities == null || abilities.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return abilities.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> isLegalKey(mode, entry.getKey()))
|
||||
.collect(Collectors.toMap((entry) -> getEnum(mode, entry.getKey()), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
/**.
|
||||
* Map the string key to enum
|
||||
*
|
||||
* @param abilities map
|
||||
* @return enum map
|
||||
*/
|
||||
public static Map<String, Boolean> mapStr(Map<AbilityKey, Boolean> abilities) {
|
||||
if (abilities == null || abilities.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return abilities.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap((entry) -> entry.getKey().getName(), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
/**.
|
||||
* getter to obtain enum
|
||||
*
|
||||
* @param key string key
|
||||
* @return enum
|
||||
*/
|
||||
public static AbilityKey getEnum(AbilityMode mode, String key) {
|
||||
return ALL_ABILITIES.get(mode).get(key);
|
||||
}
|
||||
|
||||
static {
|
||||
// check for developer
|
||||
// ensure that name filed is unique under a AbilityMode
|
||||
try {
|
||||
for (AbilityKey value : AbilityKey.values()) {
|
||||
AbilityMode mode = value.getMode();
|
||||
Map<String, AbilityKey> map = ALL_ABILITIES.getOrDefault(mode, new HashMap<>());
|
||||
AbilityKey previous = map.putIfAbsent(value.getName(), value);
|
||||
if (previous != null) {
|
||||
throw new IllegalStateException("Duplicate key name field " + value + " and " + previous + " under mode: " + mode);
|
||||
}
|
||||
ALL_ABILITIES.put(mode, map);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// for developer checking
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.constant;
|
||||
|
||||
/**
|
||||
* Ability mode.
|
||||
*
|
||||
* @author Daydreamer
|
||||
* @date 2023/9/25 12:32
|
||||
**/
|
||||
public enum AbilityMode {
|
||||
|
||||
/**
|
||||
* for server ability.
|
||||
*/
|
||||
SERVER,
|
||||
|
||||
/**
|
||||
* for sdk client.
|
||||
*/
|
||||
SDK_CLIENT,
|
||||
|
||||
/**
|
||||
* for cluster client.
|
||||
*/
|
||||
CLUSTER_CLIENT;
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.constant;
|
||||
|
||||
/**.
|
||||
* @author Daydreamer
|
||||
* @description It is used to know a certain ability whether supporting.
|
||||
* @date 2022/8/31 12:27
|
||||
**/
|
||||
public enum AbilityStatus {
|
||||
|
||||
/**.
|
||||
* Support a certain ability
|
||||
*/
|
||||
SUPPORTED,
|
||||
|
||||
/**.
|
||||
* Not support a certain ability
|
||||
*/
|
||||
NOT_SUPPORTED,
|
||||
|
||||
/**.
|
||||
* Cannot find ability table, unknown
|
||||
*/
|
||||
UNKNOWN
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 1999-2021 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.initializer;
|
||||
|
||||
/**
|
||||
* Nacos ability initializer.
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
@Deprecated
|
||||
public interface AbilityInitializer<A> {
|
||||
|
||||
/**
|
||||
* Initialize target type abilities content.
|
||||
*
|
||||
* @param abilities abilities
|
||||
*/
|
||||
void initialize(A abilities);
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.initializer;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityMode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Nacos ability post processor, load by spi.
|
||||
*
|
||||
* @author Daydreamer-ia
|
||||
*/
|
||||
public interface AbilityPostProcessor {
|
||||
|
||||
|
||||
/**
|
||||
* process before loading by <code>Ability Controller </code>.
|
||||
*
|
||||
* @param mode mode: sdk client, server or cluster client
|
||||
* @param abilities abilities
|
||||
*/
|
||||
void process(AbilityMode mode, Map<AbilityKey, Boolean> abilities);
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.register;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**.
|
||||
* @author Daydreamer
|
||||
* @description Operation for bit table.
|
||||
* @date 2022/7/12 19:23
|
||||
**/
|
||||
public abstract class AbstractAbilityRegistry {
|
||||
|
||||
protected final Map<AbilityKey, Boolean> supportedAbilities = new HashMap<>();
|
||||
|
||||
/**.
|
||||
* get static ability current server supports
|
||||
*
|
||||
* @return static ability
|
||||
*/
|
||||
public Map<AbilityKey, Boolean> getSupportedAbilities() {
|
||||
return Collections.unmodifiableMap(supportedAbilities);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* It is used to register cluster client abilities.
|
||||
*
|
||||
* @author Daydreamer
|
||||
**/
|
||||
public class ClusterClientAbilities extends AbstractAbilityRegistry {
|
||||
|
||||
private static final ClusterClientAbilities INSTANCE = new ClusterClientAbilities();
|
||||
|
||||
{
|
||||
/*
|
||||
* example:
|
||||
* There is a function named "compression".
|
||||
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||
*
|
||||
* You can add a new public field in <p>AbilityKey</p> like:
|
||||
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||
*
|
||||
* And then you need to declare whether turn on in the ability table, you can:
|
||||
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||
*
|
||||
*/
|
||||
// put ability here, which you want current client supports
|
||||
}
|
||||
|
||||
/**
|
||||
* get static ability current cluster client supports.
|
||||
*
|
||||
* @return static ability
|
||||
*/
|
||||
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||
return INSTANCE.getSupportedAbilities();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* It is used to register client abilities.
|
||||
*
|
||||
* @author Daydreamer
|
||||
* @date 2022/8/31 12:32
|
||||
**/
|
||||
public class SdkClientAbilities extends AbstractAbilityRegistry {
|
||||
|
||||
private static final SdkClientAbilities INSTANCE = new SdkClientAbilities();
|
||||
|
||||
{
|
||||
/*
|
||||
* example:
|
||||
* There is a function named "compression".
|
||||
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||
*
|
||||
* You can add a new public field in <p>AbilityKey</p> like:
|
||||
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||
*
|
||||
* And then you need to declare whether turn on in the ability table, you can:
|
||||
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||
*
|
||||
*/
|
||||
// put ability here, which you want current client supports
|
||||
}
|
||||
|
||||
/**.
|
||||
* get static ability current server supports
|
||||
*
|
||||
* @return static ability
|
||||
*/
|
||||
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||
return INSTANCE.getSupportedAbilities();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* It is used to register server abilities.
|
||||
*
|
||||
* @author Daydreamer
|
||||
* @date 2022/8/31 12:32
|
||||
**/
|
||||
public class ServerAbilities extends AbstractAbilityRegistry {
|
||||
|
||||
private static final ServerAbilities INSTANCE = new ServerAbilities();
|
||||
|
||||
{
|
||||
/*
|
||||
* example:
|
||||
* There is a function named "compression".
|
||||
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||
*
|
||||
* You can add a new public field in <p>AbilityKey</p> like:
|
||||
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||
*
|
||||
* And then you need to declare whether turn on in the ability table, you can:
|
||||
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||
*
|
||||
*/
|
||||
// put ability here, which you want current server supports
|
||||
supportedAbilities.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true);
|
||||
}
|
||||
|
||||
/**.
|
||||
* get static ability current server supports
|
||||
*
|
||||
* @return static ability
|
||||
*/
|
||||
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||
return INSTANCE.getSupportedAbilities();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos API v2 Controller.
|
||||
* @author dongyafei
|
||||
* @date 2022/7/22
|
||||
*/
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosApi {
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation to inject {@link ConfigService} or {@link NamingService} instance into the target Bean.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see ConfigService
|
||||
* @see NamingService
|
||||
* @see NacosProperties
|
||||
* @since 0.2.1
|
||||
*/
|
||||
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosInjected {
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
}
|
||||
@ -0,0 +1,300 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos Properties.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see PropertyKeyConst
|
||||
* @since 0.2.1
|
||||
*/
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosProperties {
|
||||
|
||||
/**
|
||||
* The prefix of property name of Nacos.
|
||||
*/
|
||||
String PREFIX = "nacos.";
|
||||
|
||||
/**
|
||||
* The property name of "endpoint".
|
||||
*/
|
||||
String ENDPOINT = "endpoint";
|
||||
|
||||
/**
|
||||
* The property name of "namespace".
|
||||
*/
|
||||
String NAMESPACE = "namespace";
|
||||
|
||||
/**
|
||||
* The property name of "access-key".
|
||||
*/
|
||||
String ACCESS_KEY = "access-key";
|
||||
|
||||
/**
|
||||
* The property name of "secret-key".
|
||||
*/
|
||||
String SECRET_KEY = "secret-key";
|
||||
|
||||
/**
|
||||
* The property name of "server-addr".
|
||||
*/
|
||||
String SERVER_ADDR = "server-addr";
|
||||
|
||||
/**
|
||||
* The property name of "context-path".
|
||||
*/
|
||||
String CONTEXT_PATH = "context-path";
|
||||
|
||||
/**
|
||||
* The property name of "cluster-name".
|
||||
*/
|
||||
String CLUSTER_NAME = "cluster-name";
|
||||
|
||||
/**
|
||||
* The property name of "encode".
|
||||
*/
|
||||
String ENCODE = "encode";
|
||||
|
||||
/**
|
||||
* The property name of "long-poll.timeout".
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
/**
|
||||
* The property name of "config.retry.time".
|
||||
*/
|
||||
String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
/**
|
||||
* The property name of "maxRetry".
|
||||
*/
|
||||
String MAX_RETRY = "maxRetry";
|
||||
|
||||
/**
|
||||
* The property name of "enableRemoteSyncConfig".
|
||||
*/
|
||||
String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
/**
|
||||
* The property name of "username".
|
||||
*/
|
||||
String USERNAME = "username";
|
||||
|
||||
/**
|
||||
* The property name of "password".
|
||||
*/
|
||||
String PASSWORD = "password";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>.
|
||||
*/
|
||||
String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code>.
|
||||
*/
|
||||
String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code>.
|
||||
*/
|
||||
String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code>.
|
||||
*/
|
||||
String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code>.
|
||||
*/
|
||||
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is ${nacos.context-path:}.
|
||||
*/
|
||||
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code>.
|
||||
*/
|
||||
String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code>.
|
||||
*/
|
||||
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is
|
||||
* <code>"${nacos.configLongPollTimeout:}"</code>.
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER = "${" + PREFIX + CONFIG_LONG_POLL_TIMEOUT + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is
|
||||
* <code>"${nacos.configRetryTime:}"</code>.
|
||||
*/
|
||||
String CONFIG_RETRY_TIME_PLACEHOLDER = "${" + PREFIX + CONFIG_RETRY_TIME + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code>.
|
||||
*/
|
||||
String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is
|
||||
* <code>"${nacos.enableRemoteSyncConfig:}"</code>.
|
||||
*/
|
||||
String ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER = "${" + PREFIX + ENABLE_REMOTE_SYNC_CONFIG + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.username:}"</code>.
|
||||
*/
|
||||
String USERNAME_PLACEHOLDER = "${" + PREFIX + USERNAME + ":}";
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.password:}"</code>.
|
||||
*/
|
||||
String PASSWORD_PLACEHOLDER = "${" + PREFIX + PASSWORD + ":}";
|
||||
|
||||
/**
|
||||
* The property of "endpoint".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ENDPOINT_PLACEHOLDER
|
||||
*/
|
||||
String endpoint() default ENDPOINT_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "namespace".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #NAMESPACE_PLACEHOLDER
|
||||
*/
|
||||
String namespace() default NAMESPACE_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "access-key".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ACCESS_KEY_PLACEHOLDER
|
||||
*/
|
||||
String accessKey() default ACCESS_KEY_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "secret-key".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #SECRET_KEY_PLACEHOLDER
|
||||
*/
|
||||
String secretKey() default SECRET_KEY_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "server-addr".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #SERVER_ADDR_PLACEHOLDER
|
||||
*/
|
||||
String serverAddr() default SERVER_ADDR_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "context-path".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONTEXT_PATH_PLACEHOLDER
|
||||
*/
|
||||
String contextPath() default CONTEXT_PATH_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "cluster-name".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CLUSTER_NAME_PLACEHOLDER
|
||||
*/
|
||||
String clusterName() default CLUSTER_NAME_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "encode".
|
||||
*
|
||||
* @return "UTF-8" as default value
|
||||
* @see #ENCODE_PLACEHOLDER
|
||||
*/
|
||||
String encode() default ENCODE_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "configLongPollTimeout".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER
|
||||
*/
|
||||
String configLongPollTimeout() default CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "configRetryTime".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_RETRY_TIME_PLACEHOLDER
|
||||
*/
|
||||
String configRetryTime() default CONFIG_RETRY_TIME_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "maxRetry".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #MAX_RETRY
|
||||
*/
|
||||
String maxRetry() default MAX_RETRY_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "enableRemoteSyncConfig".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ENABLE_REMOTE_SYNC_CONFIG
|
||||
*/
|
||||
String enableRemoteSyncConfig() default ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "username".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #USERNAME_PLACEHOLDER
|
||||
*/
|
||||
String username() default USERNAME_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* The property of "password".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #PASSWORD_PLACEHOLDER
|
||||
*/
|
||||
String password() default PASSWORD_PLACEHOLDER;
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* CMDB entity.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class Entity {
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
|
||||
private Map<String, String> labels;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB entity event.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class EntityEvent {
|
||||
|
||||
private EntityEventType type;
|
||||
|
||||
private String entityName;
|
||||
|
||||
private String entityType;
|
||||
|
||||
public EntityEventType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(EntityEventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
public void setEntityName(String entityName) {
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public String getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public void setEntityType(String entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB entity event type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public enum EntityEventType {
|
||||
|
||||
/**
|
||||
* Add or update entity.
|
||||
*/
|
||||
ENTITY_ADD_OR_UPDATE,
|
||||
/**
|
||||
* Remove entity.
|
||||
*/
|
||||
ENTITY_REMOVE
|
||||
}
|
||||
58
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Label.java
Normal file
58
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Label.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* CMDB label.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class Label {
|
||||
|
||||
private String name;
|
||||
|
||||
private Set<String> values;
|
||||
|
||||
private String description;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(Set<String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB preserved entity type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public enum PreservedEntityTypes {
|
||||
/**
|
||||
* Ip.
|
||||
*/
|
||||
ip,
|
||||
/**
|
||||
* Service.
|
||||
*/
|
||||
service
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.spi;
|
||||
|
||||
import com.alibaba.nacos.api.cmdb.pojo.Entity;
|
||||
import com.alibaba.nacos.api.cmdb.pojo.EntityEvent;
|
||||
import com.alibaba.nacos.api.cmdb.pojo.Label;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service to visit CMDB store.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public interface CmdbService {
|
||||
|
||||
/**
|
||||
* Get all label names stored in CMDB.
|
||||
*
|
||||
* @return label name set
|
||||
*/
|
||||
Set<String> getLabelNames();
|
||||
|
||||
/**
|
||||
* Get all possible entity types in CMDB.
|
||||
*
|
||||
* @return all entity types
|
||||
*/
|
||||
Set<String> getEntityTypes();
|
||||
|
||||
/**
|
||||
* Get label info.
|
||||
*
|
||||
* @param labelName label name
|
||||
* @return label info
|
||||
*/
|
||||
Label getLabel(String labelName);
|
||||
|
||||
/**
|
||||
* Get label value of label name of ip.
|
||||
*
|
||||
* @param entityName entity name
|
||||
* @param entityType entity type
|
||||
* @param labelName target label name
|
||||
* @return label value
|
||||
*/
|
||||
String getLabelValue(String entityName, String entityType, String labelName);
|
||||
|
||||
/**
|
||||
* Get all label value of ip.
|
||||
*
|
||||
* @param entityName entity name
|
||||
* @param entityType entity type
|
||||
* @return all label values
|
||||
*/
|
||||
Map<String, String> getLabelValues(String entityName, String entityType);
|
||||
|
||||
/**
|
||||
* Dump all entities in CMDB.
|
||||
*
|
||||
* @return all entities
|
||||
*/
|
||||
Map<String, Map<String, Entity>> getAllEntities();
|
||||
|
||||
/**
|
||||
* get label change events.
|
||||
*
|
||||
* @param timestamp start time of generated events
|
||||
* @return label events
|
||||
*/
|
||||
List<EntityEvent> getEntityEvents(long timestamp);
|
||||
|
||||
/**
|
||||
* Get single entity.
|
||||
*
|
||||
* @param entityName name of entity
|
||||
* @param entityType type of entity
|
||||
* @return entity.
|
||||
*/
|
||||
Entity getEntity(String entityName, String entityType);
|
||||
}
|
||||
287
api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Normal file
287
api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.common;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Constants.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
public static final String CLIENT_VERSION = "3.0.0";
|
||||
|
||||
public static final int DATA_IN_BODY_VERSION = 204;
|
||||
|
||||
public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
|
||||
|
||||
public static final String APPNAME = "AppName";
|
||||
|
||||
public static final String CLIENT_VERSION_KEY = "ClientVersion";
|
||||
|
||||
public static final String UNKNOWN_APP = "UnknownApp";
|
||||
|
||||
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
|
||||
|
||||
public static final String DAILY_DOMAINNAME = "commonconfig.taobao.net";
|
||||
|
||||
public static final String NULL = "";
|
||||
|
||||
public static final String DATAID = "dataId";
|
||||
|
||||
public static final String GROUP = "group";
|
||||
|
||||
public static final String LAST_MODIFIED = "Last-Modified";
|
||||
|
||||
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
||||
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
|
||||
public static final String PROBE_MODIFY_REQUEST = "Listening-Configs";
|
||||
|
||||
public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
|
||||
|
||||
public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
|
||||
|
||||
public static final String USE_ZIP = "true";
|
||||
|
||||
public static final String CONTENT_MD5 = "Content-MD5";
|
||||
|
||||
public static final String CONFIG_VERSION = "Config-Version";
|
||||
|
||||
public static final String CONFIG_TYPE = "Config-Type";
|
||||
|
||||
public static final String ENCRYPTED_DATA_KEY = "Encrypted-Data-Key";
|
||||
|
||||
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||
|
||||
public static final String SPACING_INTERVAL = "client-spacing-interval";
|
||||
|
||||
public static final String BASE_PATH = "/v1/cs";
|
||||
|
||||
public static final String CONFIG_CONTROLLER_PATH = BASE_PATH + "/configs";
|
||||
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
public static final String ACCESS_TOKEN = "accessToken";
|
||||
|
||||
public static final String TOKEN_TTL = "tokenTtl";
|
||||
|
||||
public static final String GLOBAL_ADMIN = "globalAdmin";
|
||||
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
|
||||
|
||||
public static final Integer SDK_GRPC_PORT_DEFAULT_OFFSET = 1000;
|
||||
|
||||
public static final Integer CLUSTER_GRPC_PORT_DEFAULT_OFFSET = 1001;
|
||||
|
||||
/**
|
||||
* second.
|
||||
*/
|
||||
public static final int ASYNC_UPDATE_ADDRESS_INTERVAL = 300;
|
||||
|
||||
/**
|
||||
* second.
|
||||
*/
|
||||
public static final int POLLING_INTERVAL_TIME = 15;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int ONCE_TIMEOUT = 2000;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int SO_TIMEOUT = 60000;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int CONFIG_LONG_POLL_TIMEOUT = 30000;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int MIN_CONFIG_LONG_POLL_TIMEOUT = 10000;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int CONFIG_RETRY_TIME = 2000;
|
||||
|
||||
/**
|
||||
* Maximum number of retries.
|
||||
*/
|
||||
public static final int MAX_RETRY = 3;
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;
|
||||
|
||||
public static final String ENCODE = "UTF-8";
|
||||
|
||||
public static final String MAP_FILE = "map-file.js";
|
||||
|
||||
public static final int FLOW_CONTROL_THRESHOLD = 20;
|
||||
|
||||
public static final int FLOW_CONTROL_SLOT = 10;
|
||||
|
||||
public static final int FLOW_CONTROL_INTERVAL = 1000;
|
||||
|
||||
public static final float DEFAULT_PROTECT_THRESHOLD = 0.0F;
|
||||
|
||||
public static final String LINE_SEPARATOR = Character.toString((char) 1);
|
||||
|
||||
public static final String WORD_SEPARATOR = Character.toString((char) 2);
|
||||
|
||||
public static final String LONGPOLLING_LINE_SEPARATOR = "\r\n";
|
||||
|
||||
public static final String CLIENT_APPNAME_HEADER = "Client-AppName";
|
||||
|
||||
public static final String CLIENT_REQUEST_TS_HEADER = "Client-RequestTS";
|
||||
|
||||
public static final String CLIENT_REQUEST_TOKEN_HEADER = "Client-RequestToken";
|
||||
|
||||
public static final int ATOMIC_MAX_SIZE = 1000;
|
||||
|
||||
public static final String NAMING_INSTANCE_ID_SPLITTER = "#";
|
||||
|
||||
public static final int NAMING_INSTANCE_ID_SEG_COUNT = 4;
|
||||
|
||||
public static final String NAMING_HTTP_HEADER_SPLITTER = "\\|";
|
||||
|
||||
public static final String DEFAULT_CLUSTER_NAME = "DEFAULT";
|
||||
|
||||
public static final long DEFAULT_HEART_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);
|
||||
|
||||
public static final long DEFAULT_IP_DELETE_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
public static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
public static final String DEFAULT_NAMESPACE_ID = "public";
|
||||
|
||||
public static final boolean DEFAULT_USE_CLOUD_NAMESPACE_PARSING = true;
|
||||
|
||||
public static final int WRITE_REDIRECT_CODE = 307;
|
||||
|
||||
public static final String SERVICE_INFO_SPLITER = "@@";
|
||||
|
||||
public static final int SERVICE_INFO_SPLIT_COUNT = 2;
|
||||
|
||||
public static final String NULL_STRING = "null";
|
||||
|
||||
public static final String NUMBER_PATTERN_STRING = "^\\d+$";
|
||||
|
||||
public static final String ANY_PATTERN = ".*";
|
||||
|
||||
public static final String DEFAULT_INSTANCE_ID_GENERATOR = "simple";
|
||||
|
||||
public static final String SNOWFLAKE_INSTANCE_ID_GENERATOR = "snowflake";
|
||||
|
||||
public static final String HTTP_PREFIX = "http";
|
||||
|
||||
public static final String ALL_PATTERN = "*";
|
||||
|
||||
public static final String COLON = ":";
|
||||
|
||||
public static final String LINE_BREAK = "\n";
|
||||
|
||||
public static final String POUND = "#";
|
||||
|
||||
public static final String VIPSERVER_TAG = "Vipserver-Tag";
|
||||
|
||||
public static final String AMORY_TAG = "Amory-Tag";
|
||||
|
||||
public static final String LOCATION_TAG = "Location-Tag";
|
||||
|
||||
public static final String CHARSET_KEY = "charset";
|
||||
|
||||
public static final String CLUSTER_NAME_PATTERN_STRING = "^[0-9a-zA-Z-]+$";
|
||||
|
||||
/**
|
||||
* millisecond.
|
||||
*/
|
||||
public static final long DEFAULT_REDO_DELAY_TIME = 3000L;
|
||||
|
||||
public static final int DEFAULT_REDO_THREAD_COUNT = 1;
|
||||
|
||||
public static final String APP_CONN_LABELS_KEY = "nacos.app.conn.labels";
|
||||
|
||||
public static final String DOT = ".";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
|
||||
public static final String PROPERTIES_KEY = "properties";
|
||||
|
||||
public static final String JVM_KEY = "jvm";
|
||||
|
||||
public static final String ENV_KEY = "env";
|
||||
|
||||
public static final String APP_CONN_LABELS_PREFERRED = "nacos_app_conn_labels_preferred";
|
||||
|
||||
public static final String APP_CONN_PREFIX = "app_";
|
||||
|
||||
public static final String CONFIG_GRAY_LABEL = "nacos.config.gray.label";
|
||||
|
||||
/**
|
||||
* The constants in config directory.
|
||||
*/
|
||||
public static class Config {
|
||||
|
||||
public static final String CONFIG_MODULE = "config";
|
||||
|
||||
public static final String NOTIFY_HEADER = "notify";
|
||||
}
|
||||
|
||||
/**
|
||||
* The constants in naming directory.
|
||||
*/
|
||||
public static class Naming {
|
||||
|
||||
public static final String NAMING_MODULE = "naming";
|
||||
|
||||
public static final String CMDB_CONTEXT_TYPE = "CMDB";
|
||||
}
|
||||
|
||||
/**
|
||||
* The constants in remote directory.
|
||||
*/
|
||||
public static class Remote {
|
||||
|
||||
public static final String INTERNAL_MODULE = "internal";
|
||||
}
|
||||
|
||||
/**
|
||||
* The constants in exception directory.
|
||||
*/
|
||||
public static class Exception {
|
||||
|
||||
public static final int SERIALIZE_ERROR_CODE = 100;
|
||||
|
||||
public static final int DESERIALIZE_ERROR_CODE = 101;
|
||||
|
||||
public static final int FIND_DATASOURCE_ERROR_CODE = 102;
|
||||
|
||||
public static final int FIND_TABLE_ERROR_CODE = 103;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.common;
|
||||
|
||||
/**
|
||||
* Response code definitions.
|
||||
*
|
||||
* <p>This class and inherited classes define codes separated from HTTP code to provide richer and preciser information of
|
||||
* the API results. A recommended rule for defining response code is:
|
||||
* <li> Global and common code starts with 10001.
|
||||
* <li> Naming module code starts with 20001.
|
||||
* <li> Config module code starts with 30001.
|
||||
* <li> Core module code starts with 40001.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class ResponseCode {
|
||||
|
||||
/**
|
||||
* Everything normal.
|
||||
*/
|
||||
public static final int OK = 10200;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ConfigChangeEvent.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public class ConfigChangeEvent {
|
||||
|
||||
private final Map<String, ConfigChangeItem> data;
|
||||
|
||||
public ConfigChangeEvent(Map<String, ConfigChangeItem> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ConfigChangeItem getChangeItem(String key) {
|
||||
return data.get(key);
|
||||
}
|
||||
|
||||
public Collection<ConfigChangeItem> getChangeItems() {
|
||||
return data.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* ConfigChangeItem.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public class ConfigChangeItem {
|
||||
|
||||
private String key;
|
||||
|
||||
private String oldValue;
|
||||
|
||||
private String newValue;
|
||||
|
||||
private PropertyChangeType type;
|
||||
|
||||
public ConfigChangeItem(String key, String oldValue, String newValue) {
|
||||
this.key = key;
|
||||
this.oldValue = oldValue;
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getOldValue() {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public void setOldValue(String oldValue) {
|
||||
this.oldValue = oldValue;
|
||||
}
|
||||
|
||||
public String getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public void setNewValue(String newValue) {
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
public PropertyChangeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(PropertyChangeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigChangeItem{" + "key='" + key + '\'' + ", oldValue='" + oldValue + '\'' + ", newValue='" + newValue
|
||||
+ '\'' + ", type=" + type + '}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Config Factory.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class ConfigFactory {
|
||||
|
||||
/**
|
||||
* Create Config.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return ConfigService
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static ConfigService createConfigService(Properties properties) throws NacosException {
|
||||
try {
|
||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.config.NacosConfigService");
|
||||
Constructor constructor = driverImplClass.getConstructor(Properties.class);
|
||||
ConfigService vendorImpl = (ConfigService) constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Config.
|
||||
*
|
||||
* @param serverAddr serverList
|
||||
* @return Config
|
||||
* @throws NacosException create configService failed Exception
|
||||
*/
|
||||
public static ConfigService createConfigService(String serverAddr) throws NacosException {
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
|
||||
return createConfigService(properties);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Config Service Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
/**
|
||||
* Get config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param timeoutMs read timeout
|
||||
* @return config value
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
String getConfig(String dataId, String group, long timeoutMs) throws NacosException;
|
||||
|
||||
/**
|
||||
* Get config and register Listener.
|
||||
*
|
||||
* <p>If you want to pull it yourself when the program starts to get the configuration for the first time, and the
|
||||
* registered Listener is used for future configuration updates, you can keep the original code unchanged, just add
|
||||
* the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead); therefore we recommend
|
||||
* that you use this interface directly
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param timeoutMs read timeout
|
||||
* @param listener {@link Listener}
|
||||
* @return config value
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Add a listener to the configuration, after the server modified the configuration, the client will use the
|
||||
* incoming listener callback. Recommended asynchronous processing, the application can implement the getExecutor
|
||||
* method in the ManagerListener, provide a thread pool of execution. If not provided, use the main thread callback, May
|
||||
* block other configurations or be blocked by other configurations.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param listener listener
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
void addListener(String dataId, String group, Listener listener) throws NacosException;
|
||||
|
||||
/**
|
||||
* Publish config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param content content
|
||||
* @return Whether publish
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean publishConfig(String dataId, String group, String content) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Publish config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param content content
|
||||
* @param type config type {@link ConfigType}
|
||||
* @return Whether publish
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean publishConfig(String dataId, String group, String content, String type) throws NacosException;
|
||||
|
||||
/**
|
||||
* Cas Publish config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param content content
|
||||
* @param casMd5 casMd5 prev content's md5 to cas.
|
||||
* @return Whether publish
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean publishConfigCas(String dataId, String group, String content, String casMd5) throws NacosException;
|
||||
|
||||
/**
|
||||
* Cas Publish config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param content content
|
||||
* @param casMd5 casMd5 prev content's md5 to cas.
|
||||
* @param type config type {@link ConfigType}
|
||||
* @return Whether publish
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean publishConfigCas(String dataId, String group, String content, String casMd5, String type)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Remove config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @return whether remove
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean removeConfig(String dataId, String group) throws NacosException;
|
||||
|
||||
/**
|
||||
* Remove listener.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param listener listener
|
||||
*/
|
||||
void removeListener(String dataId, String group, Listener listener);
|
||||
|
||||
/**
|
||||
* Get server status.
|
||||
*
|
||||
* @return whether health
|
||||
*/
|
||||
String getServerStatus();
|
||||
|
||||
/**
|
||||
* add config filter.
|
||||
* It is recommended to use {@link com.alibaba.nacos.api.config.filter.AbstractConfigFilter} to expand the filter.
|
||||
*
|
||||
* @param configFilter filter
|
||||
* @since 2.3.0
|
||||
*/
|
||||
void addConfigFilter(IConfigFilter configFilter);
|
||||
|
||||
/**
|
||||
* Shutdown the resource service.
|
||||
*
|
||||
* @throws NacosException exception.
|
||||
*/
|
||||
void shutDown() throws NacosException;
|
||||
}
|
||||
105
api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java
Normal file
105
api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Config data type.
|
||||
*
|
||||
* @author liaochuntao
|
||||
**/
|
||||
public enum ConfigType {
|
||||
|
||||
/**
|
||||
* config type is "properties".
|
||||
*/
|
||||
PROPERTIES("properties"),
|
||||
|
||||
/**
|
||||
* config type is "xml".
|
||||
*/
|
||||
XML("xml"),
|
||||
|
||||
/**
|
||||
* config type is "json".
|
||||
*/
|
||||
JSON("json"),
|
||||
|
||||
/**
|
||||
* config type is "text".
|
||||
*/
|
||||
TEXT("text"),
|
||||
|
||||
/**
|
||||
* config type is "html".
|
||||
*/
|
||||
HTML("html"),
|
||||
|
||||
/**
|
||||
* config type is "yaml".
|
||||
*/
|
||||
YAML("yaml"),
|
||||
|
||||
/**
|
||||
* config type is "toml".
|
||||
*/
|
||||
TOML("toml"),
|
||||
|
||||
/**
|
||||
* not a real type.
|
||||
*/
|
||||
UNSET("unset");
|
||||
|
||||
private final String type;
|
||||
|
||||
private static final Map<String, ConfigType> LOCAL_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (ConfigType configType : values()) {
|
||||
LOCAL_MAP.put(configType.getType(), configType);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static ConfigType getDefaultType() {
|
||||
return TEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* check input type is valid.
|
||||
*
|
||||
* @param type config type
|
||||
* @return it the type valid
|
||||
*/
|
||||
public static Boolean isValidType(String type) {
|
||||
if (StringUtils.isBlank(type)) {
|
||||
return false;
|
||||
}
|
||||
return null != LOCAL_MAP.get(type);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* Property Change Type.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public enum PropertyChangeType {
|
||||
/**
|
||||
* add.
|
||||
*/
|
||||
ADDED,
|
||||
/**
|
||||
* modified.
|
||||
*/
|
||||
MODIFIED,
|
||||
/**
|
||||
* deleted.
|
||||
*/
|
||||
DELETED
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 1999-2021 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.ability;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* config abilities of nacos client.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ClientConfigAbility.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
public class ClientConfigAbility implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2442741206510725737L;
|
||||
|
||||
/**
|
||||
* support remote metrics get.
|
||||
*/
|
||||
private boolean supportRemoteMetrics;
|
||||
|
||||
public boolean isSupportRemoteMetrics() {
|
||||
return supportRemoteMetrics;
|
||||
}
|
||||
|
||||
public void setSupportRemoteMetrics(boolean supportRemoteMetrics) {
|
||||
this.supportRemoteMetrics = supportRemoteMetrics;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2021 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.ability;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* config abilities of nacos server.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ServerConfigAbility.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
public class ServerConfigAbility implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4976152499731684230L;
|
||||
|
||||
/**
|
||||
* support remote metrics get.
|
||||
*/
|
||||
private boolean supportRemoteMetrics;
|
||||
|
||||
public boolean isSupportRemoteMetrics() {
|
||||
return supportRemoteMetrics;
|
||||
}
|
||||
|
||||
public void setSupportRemoteMetrics(boolean supportRemoteMetrics) {
|
||||
this.supportRemoteMetrics = supportRemoteMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ServerConfigAbility that = (ServerConfigAbility) o;
|
||||
return supportRemoteMetrics == that.supportRemoteMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(supportRemoteMetrics);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
import com.alibaba.nacos.api.config.convert.NacosConfigConverter;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
|
||||
/**
|
||||
* Annotation that marks a method as a listener for Nacos Config change.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@Documented
|
||||
public @interface NacosConfigListener {
|
||||
|
||||
/**
|
||||
* Nacos Group ID.
|
||||
*
|
||||
* @return default value {@link Constants#DEFAULT_GROUP};
|
||||
*/
|
||||
String groupId() default DEFAULT_GROUP;
|
||||
|
||||
/**
|
||||
* Nacos Data ID.
|
||||
*
|
||||
* @return required value.
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
/**
|
||||
* Nacos Config type.
|
||||
*
|
||||
* @return default value is {@link ConfigType#UNSET}
|
||||
*/
|
||||
ConfigType type() default ConfigType.UNSET;
|
||||
|
||||
/**
|
||||
* Specify {@link NacosConfigConverter Nacos configuraion convertor} class to convert target type instance.
|
||||
*
|
||||
* @return The implementation class of {@link NacosConfigConverter}
|
||||
*/
|
||||
Class<? extends NacosConfigConverter> converter() default NacosConfigConverter.class;
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
/**
|
||||
* Maximum timeout value of execution in milliseconds, which is used to prevent long-time blocking execution
|
||||
* impacting others.
|
||||
*
|
||||
* @return default value is 1000
|
||||
*/
|
||||
long timeout() default 1000L;
|
||||
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos configuration Properties for binding POJO as Properties Object.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see PropertyKeyConst
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosConfigurationProperties {
|
||||
|
||||
/**
|
||||
* config prefix name.
|
||||
*
|
||||
* @return default value is <code>""</code>
|
||||
*/
|
||||
String prefix() default "";
|
||||
|
||||
/**
|
||||
* Nacos Group ID.
|
||||
*
|
||||
* @return default value {@link Constants#DEFAULT_GROUP};
|
||||
*/
|
||||
String groupId() default DEFAULT_GROUP;
|
||||
|
||||
/**
|
||||
* Nacos Data ID.
|
||||
*
|
||||
* @return required value.
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
/**
|
||||
* config style.
|
||||
*
|
||||
* @return default value is {@link ConfigType#UNSET}
|
||||
*/
|
||||
ConfigType type() default ConfigType.UNSET;
|
||||
|
||||
/**
|
||||
* It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.
|
||||
*
|
||||
* @return default value is <code>false</code>
|
||||
*/
|
||||
boolean autoRefreshed() default false;
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object invalid fields should be ignored. Invalid means invalid
|
||||
* according to the binder that is used, and usually this means fields of the wrong type (or that cannot be coerced
|
||||
* into the correct type).
|
||||
*
|
||||
* @return the flag value (default false)
|
||||
*/
|
||||
boolean ignoreInvalidFields() default false;
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object fields with periods in their names should be ignored.
|
||||
*
|
||||
* @return the flag value (default false)
|
||||
*/
|
||||
boolean ignoreNestedProperties() default false;
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object unknown fields should be ignored. An unknown field could be a
|
||||
* sign of a mistake in the Properties.
|
||||
*
|
||||
* @return the flag value (default true)
|
||||
*/
|
||||
boolean ignoreUnknownFields() default true;
|
||||
|
||||
/**
|
||||
* Flag to indicate that an exception should be raised if a Validator is available and validation fails. If it is
|
||||
* set to false, validation errors will be swallowed. They will be logged, but not propagated to the caller.
|
||||
*
|
||||
* @return the flag value (default true)
|
||||
*/
|
||||
boolean exceptionIfInvalid() default true;
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for ignore field from annotated {@link NacosConfigurationProperties} Properties Object.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see NacosConfigurationProperties
|
||||
* @see NacosProperty
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosIgnore {
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos Property name of Nacos Configuration to bind a field from annotated {@link
|
||||
* NacosConfigurationProperties} Properties Object.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see NacosConfigurationProperties
|
||||
* @see NacosIgnore
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosProperty {
|
||||
|
||||
/**
|
||||
* The property name of Nacos Configuration to bind a field.
|
||||
*
|
||||
* @return property name
|
||||
*/
|
||||
String value();
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation which extends value to support auto-refresh.
|
||||
*
|
||||
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a>
|
||||
* @since 0.2.0
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosValue {
|
||||
|
||||
/**
|
||||
* The actual value expression: e.g. "#{systemProperties.myProp}".
|
||||
*
|
||||
* @return value expression
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* It indicates that the currently bound property is auto-refreshed when Nacos configuration is changed.
|
||||
*
|
||||
* @return default value is <code>false</code>
|
||||
*/
|
||||
boolean autoRefreshed() default false;
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.convert;
|
||||
|
||||
/**
|
||||
* Nacos Config Converter.
|
||||
*
|
||||
* @param <T> the target type that wanted
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public interface NacosConfigConverter<T> {
|
||||
|
||||
/**
|
||||
* can convert to be target type or not.
|
||||
*
|
||||
* @param targetType the type of target
|
||||
* @return If can , return <code>true</code>, or <code>false</code>
|
||||
*/
|
||||
boolean canConvert(Class<T> targetType);
|
||||
|
||||
/**
|
||||
* Convert the Nacos' config of type S to target type T.
|
||||
*
|
||||
* @param config the Nacos's config to convert, which must be an instance of S (never {@code null})
|
||||
* @return the converted object, which must be an instance of T (potentially {@code null})
|
||||
*/
|
||||
T convert(String config);
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Filter Interface default implementation.
|
||||
*
|
||||
* @author luyanbo(RobberPhex)
|
||||
*/
|
||||
public abstract class AbstractConfigFilter implements IConfigFilter {
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Context Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigContext {
|
||||
|
||||
/**
|
||||
* Get context param by key.
|
||||
*
|
||||
* @param key parameter key
|
||||
* @return context
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
/**
|
||||
* Set context param.
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
void setParameter(String key, Object value);
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Config Filter Interface.
|
||||
*
|
||||
* <p>DO NOT implement this interface directly, you should extend <code>AbstractConfigFilter</code>.
|
||||
*
|
||||
* @author Nacos
|
||||
* @see AbstractConfigFilter
|
||||
*/
|
||||
public interface IConfigFilter {
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*
|
||||
* @param properties Filter Config
|
||||
*/
|
||||
void init(Properties properties);
|
||||
|
||||
/**
|
||||
* do filter.
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @param filterChain filter Chain
|
||||
* @throws NacosException exception
|
||||
*/
|
||||
void doFilter(IConfigRequest request, IConfigResponse response, IConfigFilterChain filterChain)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get order.
|
||||
*
|
||||
* @return order number
|
||||
*/
|
||||
int getOrder();
|
||||
|
||||
/**
|
||||
* Get filterName.
|
||||
*
|
||||
* @return filter name
|
||||
*/
|
||||
String getFilterName();
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Config Filter Chain Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigFilterChain {
|
||||
|
||||
/**
|
||||
* Filter action.
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
void doFilter(IConfigRequest request, IConfigResponse response) throws NacosException;
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Request Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigRequest {
|
||||
|
||||
/**
|
||||
* put param.
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
void putParameter(String key, Object value);
|
||||
|
||||
/**
|
||||
* get param.
|
||||
*
|
||||
* @param key key
|
||||
* @return value
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
/**
|
||||
* get config context.
|
||||
*
|
||||
* @return {@link IConfigContext}
|
||||
*/
|
||||
IConfigContext getConfigContext();
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Response Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigResponse {
|
||||
|
||||
/**
|
||||
* get param.
|
||||
*
|
||||
* @param key key
|
||||
* @return value
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
/**
|
||||
* put param.
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
void putParameter(String key, Object value);
|
||||
|
||||
/**
|
||||
* Get config context.
|
||||
*
|
||||
* @return configContext
|
||||
*/
|
||||
IConfigContext getConfigContext();
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Listener Adapter,use default notify thread.
|
||||
*
|
||||
* @author water.lyl
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public abstract class AbstractListener implements Listener {
|
||||
|
||||
/**
|
||||
* Use default executor.
|
||||
*/
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Shared Listener.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public abstract class AbstractSharedListener implements Listener {
|
||||
|
||||
private volatile String dataId;
|
||||
|
||||
private volatile String group;
|
||||
|
||||
public final void fillContext(String dataId, String group) {
|
||||
this.dataId = dataId;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void receiveConfigInfo(String configInfo) {
|
||||
innerReceive(dataId, group, configInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* receive.
|
||||
*
|
||||
* @param dataId data ID
|
||||
* @param group group
|
||||
* @param configInfo content
|
||||
*/
|
||||
public abstract void innerReceive(String dataId, String group, String configInfo);
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigChangeItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ConfigChangeParser.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public interface ConfigChangeParser {
|
||||
|
||||
/**
|
||||
* Judge type.
|
||||
*
|
||||
* @param type data type
|
||||
* @return true if is responsible type, otherwise false
|
||||
*/
|
||||
boolean isResponsibleFor(String type);
|
||||
|
||||
/**
|
||||
* Compare old and new data.
|
||||
*
|
||||
* @param oldContent old content
|
||||
* @param newContent new content
|
||||
* @param type data type
|
||||
* @return key and change item map
|
||||
* @throws IOException io exception
|
||||
*/
|
||||
Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException;
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Listener for watch config.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface Listener {
|
||||
|
||||
/**
|
||||
* Get executor for execute this receive.
|
||||
*
|
||||
* @return Executor
|
||||
*/
|
||||
Executor getExecutor();
|
||||
|
||||
/**
|
||||
* Receive config info.
|
||||
*
|
||||
* @param configInfo config info
|
||||
*/
|
||||
void receiveConfigInfo(final String configInfo);
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
|
||||
/**
|
||||
* abstract request of config module request,all config module request should extends this class.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigCommonRequest.java, v 0.1 2020年07月13日 9:05 PM liuzunfei Exp $
|
||||
*/
|
||||
public abstract class AbstractConfigRequest extends Request {
|
||||
|
||||
private String dataId;
|
||||
|
||||
private String group;
|
||||
|
||||
private String tenant;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return Constants.Config.CONFIG_MODULE;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.remote.request.ServerRequest;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* request of config module metrics.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ClientConfigMetricRequest.java, v 0.1 2020年12月30日 9:05 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ClientConfigMetricRequest extends ServerRequest {
|
||||
|
||||
private List<MetricsKey> metricsKeys = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return Constants.Config.CONFIG_MODULE;
|
||||
}
|
||||
|
||||
public List<MetricsKey> getMetricsKeys() {
|
||||
return metricsKeys;
|
||||
}
|
||||
|
||||
public void setMetricsKeys(List<MetricsKey> metricsKeys) {
|
||||
this.metricsKeys = metricsKeys;
|
||||
}
|
||||
|
||||
public static class MetricsKey implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2731160029960311757L;
|
||||
|
||||
String type;
|
||||
|
||||
String key;
|
||||
|
||||
public static final String CACHE_DATA = "cacheData";
|
||||
|
||||
public static final String SNAPSHOT_DATA = "snapshotData";
|
||||
|
||||
/**
|
||||
* build metrics key.
|
||||
*
|
||||
* @param type type.
|
||||
* @param key key.
|
||||
* @return metric key.
|
||||
*/
|
||||
public static MetricsKey build(String type, String key) {
|
||||
MetricsKey metricsKey = new MetricsKey();
|
||||
metricsKey.type = type;
|
||||
metricsKey.key = key;
|
||||
return metricsKey;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MetricsKey{" + "type='" + type + '\'' + ", key='" + key + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
MetricsKey that = (MetricsKey) o;
|
||||
return Objects.equals(type, that.type) && Objects.equals(key, that.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* request of listening a batch of configs.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigBatchListenRequest.java, v 0.1 2020年07月27日 7:46 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigBatchListenRequest extends AbstractConfigRequest {
|
||||
|
||||
/**
|
||||
* listen or remove listen.
|
||||
*/
|
||||
private boolean listen = true;
|
||||
|
||||
private List<ConfigListenContext> configListenContexts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* add listen config.
|
||||
*
|
||||
* @param group group.
|
||||
* @param dataId dataId.
|
||||
* @param tenant tenant.
|
||||
* @param md5 md5.
|
||||
*/
|
||||
public void addConfigListenContext(String group, String dataId, String tenant, String md5) {
|
||||
ConfigListenContext configListenContext = new ConfigListenContext();
|
||||
configListenContext.dataId = dataId;
|
||||
configListenContext.group = group;
|
||||
configListenContext.md5 = md5;
|
||||
configListenContext.tenant = tenant;
|
||||
configListenContexts.add(configListenContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>configListenContexts</tt>.
|
||||
*
|
||||
* @return property value of configListenContexts
|
||||
*/
|
||||
public List<ConfigListenContext> getConfigListenContexts() {
|
||||
return configListenContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>configListenContexts</tt>.
|
||||
*
|
||||
* @param configListenContexts value to be assigned to property configListenContexts
|
||||
*/
|
||||
public void setConfigListenContexts(List<ConfigListenContext> configListenContexts) {
|
||||
this.configListenContexts = configListenContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>listen</tt>.
|
||||
*
|
||||
* @return property value of listen
|
||||
*/
|
||||
public boolean isListen() {
|
||||
return listen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>listen</tt>.
|
||||
*
|
||||
* @param listen value to be assigned to property listen
|
||||
*/
|
||||
public void setListen(boolean listen) {
|
||||
this.listen = listen;
|
||||
}
|
||||
|
||||
public static class ConfigListenContext {
|
||||
|
||||
String group;
|
||||
|
||||
String md5;
|
||||
|
||||
String dataId;
|
||||
|
||||
String tenant;
|
||||
|
||||
public ConfigListenContext() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigListenContext{" + "group='" + group + '\'' + ", md5='" + md5 + '\'' + ", dataId='" + dataId
|
||||
+ '\'' + ", tenant='" + tenant + '\'' + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>group</tt>.
|
||||
*
|
||||
* @return property value of group
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>groupId</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property groupId
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>md5</tt>.
|
||||
*
|
||||
* @return property value of md5
|
||||
*/
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>md5</tt>.
|
||||
*
|
||||
* @param md5 value to be assigned to property md5
|
||||
*/
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.remote.request.ServerRequest;
|
||||
|
||||
/**
|
||||
* ConfigChangeNotifyRequest.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigChangeNotifyRequest.java, v 0.1 2020年07月14日 3:20 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigChangeNotifyRequest extends ServerRequest {
|
||||
|
||||
String dataId;
|
||||
|
||||
String group;
|
||||
|
||||
String tenant;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* build success response.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param tenant tenant
|
||||
* @return ConfigChangeNotifyResponse
|
||||
*/
|
||||
public static ConfigChangeNotifyRequest build(String dataId, String group, String tenant) {
|
||||
ConfigChangeNotifyRequest request = new ConfigChangeNotifyRequest();
|
||||
request.setDataId(dataId);
|
||||
request.setGroup(group);
|
||||
request.setTenant(tenant);
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return Constants.Config.CONFIG_MODULE;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* request to publish a config.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigPublishRequest.java, v 0.1 2020年07月16日 4:30 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigPublishRequest extends AbstractConfigRequest {
|
||||
|
||||
String content;
|
||||
|
||||
String casMd5;
|
||||
|
||||
private Map<String, String> additionMap;
|
||||
|
||||
public ConfigPublishRequest() {
|
||||
|
||||
}
|
||||
|
||||
public ConfigPublishRequest(String dataId, String group, String tenant, String content) {
|
||||
this.content = content;
|
||||
super.setGroup(group);
|
||||
super.setTenant(tenant);
|
||||
super.setDataId(dataId);
|
||||
}
|
||||
|
||||
/**
|
||||
* get additional param.
|
||||
*
|
||||
* @param key key of param.
|
||||
* @return value of param ,return null if not exist.
|
||||
*/
|
||||
public String getAdditionParam(String key) {
|
||||
return additionMap == null ? null : additionMap.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* put additional param value. will override if exist.
|
||||
*
|
||||
* @param key key of param.
|
||||
* @param value value of param.
|
||||
*/
|
||||
public void putAdditionalParam(String key, String value) {
|
||||
if (additionMap == null) {
|
||||
additionMap = new HashMap<>(2);
|
||||
}
|
||||
additionMap.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>content</tt>.
|
||||
*
|
||||
* @return property value of content
|
||||
*/
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>content</tt>.
|
||||
*
|
||||
* @param content value to be assigned to property content
|
||||
*/
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>casMd5</tt>.
|
||||
*
|
||||
* @return property value of casMd5
|
||||
*/
|
||||
public String getCasMd5() {
|
||||
return casMd5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>casMd5</tt>.
|
||||
*
|
||||
* @param casMd5 value to be assigned to property content
|
||||
*/
|
||||
public void setCasMd5(String casMd5) {
|
||||
this.casMd5 = casMd5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>casMd5</tt>.
|
||||
*
|
||||
* @return property value of casMd5
|
||||
*/
|
||||
public Map<String, String> getAdditionMap() {
|
||||
return additionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>additionMap</tt>.
|
||||
*
|
||||
* @param additionMap value to be assigned to property additionMap
|
||||
*/
|
||||
public void setAdditionMap(Map<String, String> additionMap) {
|
||||
this.additionMap = additionMap;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
|
||||
/**
|
||||
* request to query config content.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigQueryRequest.java, v 0.1 2020年07月13日 9:06 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigQueryRequest extends AbstractConfigRequest {
|
||||
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* request builder.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param tenant tenant
|
||||
* @return ConfigQueryRequest instance.
|
||||
*/
|
||||
public static ConfigQueryRequest build(String dataId, String group, String tenant) {
|
||||
ConfigQueryRequest request = new ConfigQueryRequest();
|
||||
request.setDataId(dataId);
|
||||
request.setGroup(group);
|
||||
request.setTenant(tenant);
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @return property value of tag
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @param tag value to be assigned to property tag
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public boolean isNotify() {
|
||||
String notify = getHeader(Constants.Config.NOTIFY_HEADER, Boolean.FALSE.toString());
|
||||
return Boolean.parseBoolean(notify);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
/**
|
||||
* request to remove a config .
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigRemoveRequest.java, v 0.1 2020年07月16日 4:31 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigRemoveRequest extends AbstractConfigRequest {
|
||||
|
||||
String tag;
|
||||
|
||||
public ConfigRemoveRequest() {
|
||||
|
||||
}
|
||||
|
||||
public ConfigRemoveRequest(String dataId, String group, String tenant, String tag) {
|
||||
super.setDataId(dataId);
|
||||
super.setGroup(group);
|
||||
super.setTenant(tenant);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @return property value of tag
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @param tag value to be assigned to property tag
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.request.cluster;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.AbstractConfigRequest;
|
||||
|
||||
/**
|
||||
* config change sync request on clusters.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigChangeClusterSyncRequest.java, v 0.1 2020年08月11日 4:30 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigChangeClusterSyncRequest extends AbstractConfigRequest {
|
||||
|
||||
String tag;
|
||||
|
||||
long lastModified;
|
||||
|
||||
boolean isBeta;
|
||||
|
||||
boolean isBatch;
|
||||
|
||||
public boolean isBeta() {
|
||||
return isBeta;
|
||||
}
|
||||
|
||||
public void setBeta(boolean beta) {
|
||||
isBeta = beta;
|
||||
}
|
||||
|
||||
public boolean isBatch() {
|
||||
return isBatch;
|
||||
}
|
||||
|
||||
public void setBatch(boolean batch) {
|
||||
isBatch = batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @return property value of tag
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tag</tt>.
|
||||
*
|
||||
* @param tag value to be assigned to property tag
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>lastModified</tt>.
|
||||
*
|
||||
* @return property value of lastModified
|
||||
*/
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>lastModified</tt>.
|
||||
*
|
||||
* @param lastModified value to be assigned to property lastModified
|
||||
*/
|
||||
public void setLastModified(long lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* client config metrics response.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ClientConfigMetricResponse.java, v 0.1 2020年12月30日 2:59 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ClientConfigMetricResponse extends Response {
|
||||
|
||||
private Map<String, Object> metrics = new HashMap<>();
|
||||
|
||||
public Map<String, Object> getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
public void setMetrics(Map<String, Object> metrics) {
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
public void putMetric(String key, Object value) {
|
||||
metrics.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ConfigChangeBatchListenResponse.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigChangeBatchListenResponse.java, v 0.1 2020年07月14日 3:07 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigChangeBatchListenResponse extends Response {
|
||||
|
||||
List<ConfigContext> changedConfigs = new ArrayList<>();
|
||||
|
||||
public ConfigChangeBatchListenResponse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* add changed config.
|
||||
*
|
||||
* @param dataId dataId.
|
||||
* @param group group.
|
||||
* @param tenant tenant.
|
||||
*/
|
||||
public void addChangeConfig(String dataId, String group, String tenant) {
|
||||
ConfigContext configContext = new ConfigContext();
|
||||
configContext.dataId = dataId;
|
||||
configContext.group = group;
|
||||
configContext.tenant = tenant;
|
||||
changedConfigs.add(configContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>changedConfigs</tt>.
|
||||
*
|
||||
* @return property value of changedConfigs
|
||||
*/
|
||||
public List<ConfigContext> getChangedConfigs() {
|
||||
return changedConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>changedConfigs</tt>.
|
||||
*
|
||||
* @param changedConfigs value to be assigned to property changedConfigs
|
||||
*/
|
||||
public void setChangedConfigs(List<ConfigContext> changedConfigs) {
|
||||
this.changedConfigs = changedConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* build fail response.
|
||||
*
|
||||
* @param errorMessage errorMessage.
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigChangeBatchListenResponse buildFailResponse(String errorMessage) {
|
||||
ConfigChangeBatchListenResponse response = new ConfigChangeBatchListenResponse();
|
||||
response.setResultCode(ResponseCode.FAIL.getCode());
|
||||
response.setMessage(errorMessage);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static class ConfigContext {
|
||||
|
||||
String group;
|
||||
|
||||
String dataId;
|
||||
|
||||
String tenant;
|
||||
|
||||
public ConfigContext() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>groupId</tt>.
|
||||
*
|
||||
* @return property value of groupId
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>groupId</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property groupId
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigContext{" + "group='" + group + '\'' + ", dataId='" + dataId + '\'' + ", tenant='" + tenant
|
||||
+ '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
|
||||
/**
|
||||
* config change notify response from client.
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigChangeNotifyResponse.java, v 0.1 2020年09月01日 2:59 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigChangeNotifyResponse extends Response {
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* ConfigPublishResponse.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigPublishResponse.java, v 0.1 2020年07月16日 4:59 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigPublishResponse extends Response {
|
||||
|
||||
public ConfigPublishResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build success response.
|
||||
*
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigPublishResponse buildSuccessResponse() {
|
||||
return new ConfigPublishResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build fail response.
|
||||
*
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigPublishResponse buildFailResponse(int errorCode, String errorMsg) {
|
||||
ConfigPublishResponse configPublishResponse = new ConfigPublishResponse();
|
||||
configPublishResponse.setResultCode(ResponseCode.FAIL.getCode());
|
||||
configPublishResponse.setMessage(errorMsg);
|
||||
configPublishResponse.setErrorCode(errorCode);
|
||||
return configPublishResponse;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
|
||||
/**
|
||||
* ConfigQueryResponse.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigQueryResponse.java, v 0.1 2020年07月14日 2:47 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigQueryResponse extends Response {
|
||||
|
||||
public static final int CONFIG_NOT_FOUND = 300;
|
||||
|
||||
public static final int CONFIG_QUERY_CONFLICT = 400;
|
||||
|
||||
String content;
|
||||
|
||||
String encryptedDataKey;
|
||||
|
||||
String contentType;
|
||||
|
||||
String md5;
|
||||
|
||||
long lastModified;
|
||||
|
||||
boolean isBeta;
|
||||
|
||||
String tag;
|
||||
|
||||
public ConfigQueryResponse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build fail response.
|
||||
*
|
||||
* @param errorCode errorCode.
|
||||
* @param message message.
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigQueryResponse buildFailResponse(int errorCode, String message) {
|
||||
ConfigQueryResponse response = new ConfigQueryResponse();
|
||||
response.setErrorInfo(errorCode, message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build success response.
|
||||
*
|
||||
* @param content content.
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigQueryResponse buildSuccessResponse(String content) {
|
||||
ConfigQueryResponse response = new ConfigQueryResponse();
|
||||
response.setContent(content);
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void setLastModified(long lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public boolean isBeta() {
|
||||
return isBeta;
|
||||
}
|
||||
|
||||
public void setBeta(boolean beta) {
|
||||
isBeta = beta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>content</tt>.
|
||||
*
|
||||
* @return property value of content
|
||||
*/
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>content</tt>.
|
||||
*
|
||||
* @param content value to be assigned to property content
|
||||
*/
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setEncryptedDataKey(String encryptedDataKey) {
|
||||
this.encryptedDataKey = encryptedDataKey;
|
||||
}
|
||||
|
||||
public String getEncryptedDataKey() {
|
||||
return encryptedDataKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>contentType</tt>.
|
||||
*
|
||||
* @return property value of contentType
|
||||
*/
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>contentType</tt>.
|
||||
*
|
||||
* @param contentType value to be assigned to property contentType
|
||||
*/
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* ConfigRemoveResponse.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigRemoveResponse.java, v 0.1 2020年07月16日 4:59 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigRemoveResponse extends Response {
|
||||
|
||||
public ConfigRemoveResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build success response.
|
||||
*
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigRemoveResponse buildSuccessResponse() {
|
||||
return new ConfigRemoveResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build fail response.
|
||||
*
|
||||
* @return response.
|
||||
*/
|
||||
public static ConfigRemoveResponse buildFailResponse(String errorMsg) {
|
||||
ConfigRemoveResponse removeResponse = new ConfigRemoveResponse();
|
||||
removeResponse.setResultCode(ResponseCode.FAIL.getCode());
|
||||
removeResponse.setMessage(errorMsg);
|
||||
return removeResponse;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.remote.response.cluster;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
|
||||
/**
|
||||
* config change sync response on clusters.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigChangeClusterSyncResponse.java, v 0.1 2020年08月11日 4:32 PM liuzunfei Exp $
|
||||
*/
|
||||
public class ConfigChangeClusterSyncResponse extends Response {
|
||||
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Nacos Exception.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class NacosException extends Exception {
|
||||
|
||||
/**
|
||||
* serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -3913902031489277776L;
|
||||
|
||||
private int errCode;
|
||||
|
||||
private String errMsg;
|
||||
|
||||
private Throwable causeThrowable;
|
||||
|
||||
public NacosException() {
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final String errMsg) {
|
||||
super(errMsg);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
this.setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final String errMsg, final Throwable throwable) {
|
||||
super(errMsg, throwable);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
this.setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return this.errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
if (!StringUtils.isBlank(this.errMsg)) {
|
||||
return this.errMsg;
|
||||
}
|
||||
if (this.causeThrowable != null) {
|
||||
return this.causeThrowable.getMessage();
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
|
||||
public void setErrCode(final int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public void setErrMsg(final String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public void setCauseThrowable(final Throwable throwable) {
|
||||
this.causeThrowable = this.getCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
private Throwable getCauseThrowable(final Throwable t) {
|
||||
if (t.getCause() == null) {
|
||||
return t;
|
||||
}
|
||||
return this.getCauseThrowable(t.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
|
||||
}
|
||||
|
||||
/*
|
||||
* client error code.
|
||||
* -400 -503 throw exception to user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* invalid param(参数错误).
|
||||
*/
|
||||
public static final int CLIENT_INVALID_PARAM = -400;
|
||||
|
||||
/**
|
||||
* client disconnect.
|
||||
*/
|
||||
public static final int CLIENT_DISCONNECT = -401;
|
||||
|
||||
/**
|
||||
* over client threshold(超过client端的限流阈值).
|
||||
*/
|
||||
public static final int CLIENT_OVER_THRESHOLD = -503;
|
||||
|
||||
/*
|
||||
* server error code.
|
||||
* 400 403 throw exception to user
|
||||
* 500 502 503 change ip and retry
|
||||
*/
|
||||
|
||||
/**
|
||||
* invalid param(参数错误).
|
||||
*/
|
||||
public static final int INVALID_PARAM = 400;
|
||||
|
||||
/**
|
||||
* no right(鉴权失败).
|
||||
*/
|
||||
public static final int NO_RIGHT = 403;
|
||||
|
||||
/**
|
||||
* not found.
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* conflict(写并发冲突).
|
||||
*/
|
||||
public static final int CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* server error(server异常,如超时).
|
||||
*/
|
||||
public static final int SERVER_ERROR = 500;
|
||||
|
||||
/**
|
||||
* client error(client异常,返回给服务端).
|
||||
*/
|
||||
public static final int CLIENT_ERROR = -500;
|
||||
|
||||
/**
|
||||
* bad gateway(路由异常,如nginx后面的Server挂掉).
|
||||
*/
|
||||
public static final int BAD_GATEWAY = 502;
|
||||
|
||||
/**
|
||||
* over threshold(超过server端的限流阈值).
|
||||
*/
|
||||
public static final int OVER_THRESHOLD = 503;
|
||||
|
||||
/**
|
||||
* Server is not started.
|
||||
*/
|
||||
public static final int INVALID_SERVER_STATUS = 300;
|
||||
|
||||
/**
|
||||
* Connection is not registered.
|
||||
*/
|
||||
public static final int UN_REGISTER = 301;
|
||||
|
||||
/**
|
||||
* No Handler Found.
|
||||
*/
|
||||
public static final int NO_HANDLER = 302;
|
||||
|
||||
public static final int RESOURCE_NOT_FOUND = -404;
|
||||
|
||||
/**
|
||||
* http client error code, ome exceptions that occurred when there use the Nacos RestTemplate and Nacos
|
||||
* AsyncRestTemplate.
|
||||
*/
|
||||
public static final int HTTP_CLIENT_ERROR_CODE = -500;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception.api;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
|
||||
/** Exception for open API. <BR/>
|
||||
* errCode -> HTTP status code inherited from {@link NacosException} <BR/>
|
||||
* errMsg -> detail error message inherited from {@link NacosException} <BR/>
|
||||
* detailErrCode -> error code for api v2.0 <BR/>
|
||||
* errAbstract -> abstract error message for api v2.0
|
||||
* @author dongyafei
|
||||
* @date 2022/7/22
|
||||
*/
|
||||
public class NacosApiException extends NacosException {
|
||||
|
||||
/**
|
||||
* serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 2245627968556056573L;
|
||||
|
||||
/**
|
||||
* error code for api v2.0.
|
||||
*/
|
||||
private int detailErrCode;
|
||||
|
||||
/**
|
||||
* abstract error description for api v2.0.
|
||||
*/
|
||||
private String errAbstract;
|
||||
|
||||
public NacosApiException() {
|
||||
}
|
||||
|
||||
public NacosApiException(int statusCode, ErrorCode errorCode, Throwable throwable, String message) {
|
||||
super(statusCode, message, throwable);
|
||||
this.detailErrCode = errorCode.getCode();
|
||||
this.errAbstract = errorCode.getMsg();
|
||||
}
|
||||
|
||||
public NacosApiException(int statusCode, ErrorCode errorCode, String message) {
|
||||
super(statusCode, message);
|
||||
this.detailErrCode = errorCode.getCode();
|
||||
this.errAbstract = errorCode.getMsg();
|
||||
}
|
||||
|
||||
public int getDetailErrCode() {
|
||||
return detailErrCode;
|
||||
}
|
||||
|
||||
public String getErrAbstract() {
|
||||
if (!StringUtils.isBlank(this.errAbstract)) {
|
||||
return this.errAbstract;
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Exception.DESERIALIZE_ERROR_CODE;
|
||||
|
||||
/**
|
||||
* Nacos deserialization exception.
|
||||
*
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosDeserializationException extends NacosRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -2742350751684273728L;
|
||||
|
||||
private static final String DEFAULT_MSG = "Nacos deserialize failed. ";
|
||||
|
||||
private static final String MSG_FOR_SPECIFIED_CLASS = "Nacos deserialize for class [%s] failed. ";
|
||||
|
||||
private static final String ERROR_MSG_FOR_SPECIFIED_CLASS = "Nacos deserialize for class [%s] failed, cause error[%s]. ";
|
||||
|
||||
private Class<?> targetClass;
|
||||
|
||||
public NacosDeserializationException() {
|
||||
super(DESERIALIZE_ERROR_CODE);
|
||||
}
|
||||
|
||||
public NacosDeserializationException(Class<?> targetClass) {
|
||||
super(DESERIALIZE_ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetClass.getName()));
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
public NacosDeserializationException(Type targetType) {
|
||||
super(DESERIALIZE_ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetType.toString()));
|
||||
}
|
||||
|
||||
public NacosDeserializationException(Throwable throwable) {
|
||||
super(DESERIALIZE_ERROR_CODE, DEFAULT_MSG, throwable);
|
||||
}
|
||||
|
||||
public NacosDeserializationException(Class<?> targetClass, Throwable throwable) {
|
||||
super(DESERIALIZE_ERROR_CODE, String.format(ERROR_MSG_FOR_SPECIFIED_CLASS, targetClass.getName(), throwable.getMessage()), throwable);
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
public NacosDeserializationException(Type targetType, Throwable throwable) {
|
||||
super(DESERIALIZE_ERROR_CODE, String.format(ERROR_MSG_FOR_SPECIFIED_CLASS, targetType.toString(), throwable.getMessage()), throwable);
|
||||
}
|
||||
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
/**
|
||||
* Nacos load exception.
|
||||
*
|
||||
* @author hujun
|
||||
*/
|
||||
public class NacosLoadException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 3513491993982295562L;
|
||||
|
||||
public NacosLoadException(String errMsg) {
|
||||
super(errMsg);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
/**
|
||||
* Nacos runtime exception.
|
||||
*
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosRuntimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 3513491993982293262L;
|
||||
|
||||
public static final String ERROR_MESSAGE_FORMAT = "errCode: %d, errMsg: %s ";
|
||||
|
||||
private final int errCode;
|
||||
|
||||
public NacosRuntimeException(int errCode) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public NacosRuntimeException(int errCode, String errMsg) {
|
||||
super(String.format(ERROR_MESSAGE_FORMAT, errCode, errMsg));
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public NacosRuntimeException(int errCode, Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public NacosRuntimeException(int errCode, String errMsg, Throwable throwable) {
|
||||
super(String.format(ERROR_MESSAGE_FORMAT, errCode, errMsg), throwable);
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Exception.SERIALIZE_ERROR_CODE;
|
||||
|
||||
/**
|
||||
* Nacos serialization exception.
|
||||
*
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosSerializationException extends NacosRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -4308536346316915612L;
|
||||
|
||||
private static final String DEFAULT_MSG = "Nacos serialize failed. ";
|
||||
|
||||
private static final String MSG_FOR_SPECIFIED_CLASS = "Nacos serialize for class [%s] failed. ";
|
||||
|
||||
private Class<?> serializedClass;
|
||||
|
||||
public NacosSerializationException() {
|
||||
super(SERIALIZE_ERROR_CODE);
|
||||
}
|
||||
|
||||
public NacosSerializationException(Class<?> serializedClass) {
|
||||
super(SERIALIZE_ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, serializedClass.getName()));
|
||||
this.serializedClass = serializedClass;
|
||||
}
|
||||
|
||||
public NacosSerializationException(Throwable throwable) {
|
||||
super(SERIALIZE_ERROR_CODE, DEFAULT_MSG, throwable);
|
||||
}
|
||||
|
||||
public NacosSerializationException(Class<?> serializedClass, Throwable throwable) {
|
||||
super(SERIALIZE_ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, serializedClass.getName()), throwable);
|
||||
this.serializedClass = serializedClass;
|
||||
}
|
||||
|
||||
public Class<?> getSerializedClass() {
|
||||
return serializedClass;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.grpc.auto;
|
||||
|
||||
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
||||
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
|
||||
|
||||
/**
|
||||
*/
|
||||
@javax.annotation.Generated(
|
||||
value = "by gRPC proto compiler (version 1.14.0)",
|
||||
comments = "Source: nacos_grpc_service.proto")
|
||||
public final class BiRequestStreamGrpc {
|
||||
|
||||
private BiRequestStreamGrpc() {}
|
||||
|
||||
public static final String SERVICE_NAME = "BiRequestStream";
|
||||
|
||||
// Static method descriptors that strictly reflect the proto.
|
||||
private static volatile io.grpc.MethodDescriptor<com.alibaba.nacos.api.grpc.auto.Payload,
|
||||
com.alibaba.nacos.api.grpc.auto.Payload> getRequestBiStreamMethod;
|
||||
|
||||
@io.grpc.stub.annotations.RpcMethod(
|
||||
fullMethodName = SERVICE_NAME + '/' + "requestBiStream",
|
||||
requestType = com.alibaba.nacos.api.grpc.auto.Payload.class,
|
||||
responseType = com.alibaba.nacos.api.grpc.auto.Payload.class,
|
||||
methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
|
||||
public static io.grpc.MethodDescriptor<com.alibaba.nacos.api.grpc.auto.Payload,
|
||||
com.alibaba.nacos.api.grpc.auto.Payload> getRequestBiStreamMethod() {
|
||||
io.grpc.MethodDescriptor<com.alibaba.nacos.api.grpc.auto.Payload, com.alibaba.nacos.api.grpc.auto.Payload> getRequestBiStreamMethod;
|
||||
if ((getRequestBiStreamMethod = BiRequestStreamGrpc.getRequestBiStreamMethod) == null) {
|
||||
synchronized (BiRequestStreamGrpc.class) {
|
||||
if ((getRequestBiStreamMethod = BiRequestStreamGrpc.getRequestBiStreamMethod) == null) {
|
||||
BiRequestStreamGrpc.getRequestBiStreamMethod = getRequestBiStreamMethod =
|
||||
io.grpc.MethodDescriptor.<com.alibaba.nacos.api.grpc.auto.Payload, com.alibaba.nacos.api.grpc.auto.Payload>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"BiRequestStream", "requestBiStream"))
|
||||
.setSampledToLocalTracing(true)
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.alibaba.nacos.api.grpc.auto.Payload.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.alibaba.nacos.api.grpc.auto.Payload.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new BiRequestStreamMethodDescriptorSupplier("requestBiStream"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return getRequestBiStreamMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new async stub that supports all call types for the service
|
||||
*/
|
||||
public static BiRequestStreamStub newStub(io.grpc.Channel channel) {
|
||||
return new BiRequestStreamStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
|
||||
*/
|
||||
public static BiRequestStreamBlockingStub newBlockingStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new BiRequestStreamBlockingStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ListenableFuture-style stub that supports unary calls on the service
|
||||
*/
|
||||
public static BiRequestStreamFutureStub newFutureStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new BiRequestStreamFutureStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static abstract class BiRequestStreamImplBase implements io.grpc.BindableService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Sends a commonRequest
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<com.alibaba.nacos.api.grpc.auto.Payload> requestBiStream(
|
||||
io.grpc.stub.StreamObserver<com.alibaba.nacos.api.grpc.auto.Payload> responseObserver) {
|
||||
return asyncUnimplementedStreamingCall(getRequestBiStreamMethod(), responseObserver);
|
||||
}
|
||||
|
||||
@Override public final io.grpc.ServerServiceDefinition bindService() {
|
||||
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
|
||||
.addMethod(
|
||||
getRequestBiStreamMethod(),
|
||||
asyncBidiStreamingCall(
|
||||
new MethodHandlers<
|
||||
com.alibaba.nacos.api.grpc.auto.Payload,
|
||||
com.alibaba.nacos.api.grpc.auto.Payload>(
|
||||
this, METHODID_REQUEST_BI_STREAM)))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class BiRequestStreamStub extends io.grpc.stub.AbstractStub<BiRequestStreamStub> {
|
||||
private BiRequestStreamStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private BiRequestStreamStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BiRequestStreamStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new BiRequestStreamStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Sends a commonRequest
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<com.alibaba.nacos.api.grpc.auto.Payload> requestBiStream(
|
||||
io.grpc.stub.StreamObserver<com.alibaba.nacos.api.grpc.auto.Payload> responseObserver) {
|
||||
return asyncBidiStreamingCall(
|
||||
getChannel().newCall(getRequestBiStreamMethod(), getCallOptions()), responseObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class BiRequestStreamBlockingStub extends io.grpc.stub.AbstractStub<BiRequestStreamBlockingStub> {
|
||||
private BiRequestStreamBlockingStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private BiRequestStreamBlockingStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BiRequestStreamBlockingStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new BiRequestStreamBlockingStub(channel, callOptions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class BiRequestStreamFutureStub extends io.grpc.stub.AbstractStub<BiRequestStreamFutureStub> {
|
||||
private BiRequestStreamFutureStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private BiRequestStreamFutureStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BiRequestStreamFutureStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new BiRequestStreamFutureStub(channel, callOptions);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int METHODID_REQUEST_BI_STREAM = 0;
|
||||
|
||||
private static final class MethodHandlers<Req, Resp> implements
|
||||
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
|
||||
private final BiRequestStreamImplBase serviceImpl;
|
||||
private final int methodId;
|
||||
|
||||
MethodHandlers(BiRequestStreamImplBase serviceImpl, int methodId) {
|
||||
this.serviceImpl = serviceImpl;
|
||||
this.methodId = methodId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public io.grpc.stub.StreamObserver<Req> invoke(
|
||||
io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
case METHODID_REQUEST_BI_STREAM:
|
||||
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.requestBiStream(
|
||||
(io.grpc.stub.StreamObserver<com.alibaba.nacos.api.grpc.auto.Payload>) responseObserver);
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class BiRequestStreamBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
|
||||
BiRequestStreamBaseDescriptorSupplier() {}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
|
||||
return com.alibaba.nacos.api.grpc.auto.NacosGrpcService.getDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
|
||||
return getFileDescriptor().findServiceByName("BiRequestStream");
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BiRequestStreamFileDescriptorSupplier
|
||||
extends BiRequestStreamBaseDescriptorSupplier {
|
||||
BiRequestStreamFileDescriptorSupplier() {}
|
||||
}
|
||||
|
||||
private static final class BiRequestStreamMethodDescriptorSupplier
|
||||
extends BiRequestStreamBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
|
||||
private final String methodName;
|
||||
|
||||
BiRequestStreamMethodDescriptorSupplier(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
|
||||
return getServiceDescriptor().findMethodByName(methodName);
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
|
||||
|
||||
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
|
||||
io.grpc.ServiceDescriptor result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
synchronized (BiRequestStreamGrpc.class) {
|
||||
result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
|
||||
.setSchemaDescriptor(new BiRequestStreamFileDescriptorSupplier())
|
||||
.addMethod(getRequestBiStreamMethod())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
962
api/src/main/java/com/alibaba/nacos/api/grpc/auto/Metadata.java
Normal file
962
api/src/main/java/com/alibaba/nacos/api/grpc/auto/Metadata.java
Normal file
@ -0,0 +1,962 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.grpc.auto;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code Metadata}
|
||||
*/
|
||||
public final class Metadata extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:Metadata)
|
||||
MetadataOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use Metadata.newBuilder() to construct.
|
||||
private Metadata(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private Metadata() {
|
||||
type_ = "";
|
||||
clientIp_ = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new Metadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private Metadata(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
this();
|
||||
if (extensionRegistry == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 26: {
|
||||
String s = input.readStringRequireUtf8();
|
||||
|
||||
type_ = s;
|
||||
break;
|
||||
}
|
||||
case 58: {
|
||||
if (!((mutable_bitField0_ & 0x00000001) != 0)) {
|
||||
headers_ = com.google.protobuf.MapField.newMapField(
|
||||
HeadersDefaultEntryHolder.defaultEntry);
|
||||
mutable_bitField0_ |= 0x00000001;
|
||||
}
|
||||
com.google.protobuf.MapEntry<String, String>
|
||||
headers__ = input.readMessage(
|
||||
HeadersDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
|
||||
headers_.getMutableMap().put(
|
||||
headers__.getKey(), headers__.getValue());
|
||||
break;
|
||||
}
|
||||
case 66: {
|
||||
String s = input.readStringRequireUtf8();
|
||||
|
||||
clientIp_ = s;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (!parseUnknownField(
|
||||
input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return NacosGrpcService.internal_static_Metadata_descriptor;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
@Override
|
||||
protected com.google.protobuf.MapField internalGetMapField(
|
||||
int number) {
|
||||
switch (number) {
|
||||
case 7:
|
||||
return internalGetHeaders();
|
||||
default:
|
||||
throw new RuntimeException(
|
||||
"Invalid map field number: " + number);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return NacosGrpcService.internal_static_Metadata_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
Metadata.class, Builder.class);
|
||||
}
|
||||
|
||||
public static final int TYPE_FIELD_NUMBER = 3;
|
||||
private volatile Object type_;
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public String getType() {
|
||||
Object ref = type_;
|
||||
if (ref instanceof String) {
|
||||
return (String) ref;
|
||||
} else {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
String s = bs.toStringUtf8();
|
||||
type_ = s;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getTypeBytes() {
|
||||
Object ref = type_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(String) ref);
|
||||
type_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int CLIENTIP_FIELD_NUMBER = 8;
|
||||
private volatile Object clientIp_;
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public String getClientIp() {
|
||||
Object ref = clientIp_;
|
||||
if (ref instanceof String) {
|
||||
return (String) ref;
|
||||
} else {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
String s = bs.toStringUtf8();
|
||||
clientIp_ = s;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getClientIpBytes() {
|
||||
Object ref = clientIp_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(String) ref);
|
||||
clientIp_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int HEADERS_FIELD_NUMBER = 7;
|
||||
private static final class HeadersDefaultEntryHolder {
|
||||
static final com.google.protobuf.MapEntry<
|
||||
String, String> defaultEntry =
|
||||
com.google.protobuf.MapEntry
|
||||
.<String, String>newDefaultInstance(
|
||||
NacosGrpcService.internal_static_Metadata_HeadersEntry_descriptor,
|
||||
com.google.protobuf.WireFormat.FieldType.STRING,
|
||||
"",
|
||||
com.google.protobuf.WireFormat.FieldType.STRING,
|
||||
"");
|
||||
}
|
||||
private com.google.protobuf.MapField<
|
||||
String, String> headers_;
|
||||
private com.google.protobuf.MapField<String, String>
|
||||
internalGetHeaders() {
|
||||
if (headers_ == null) {
|
||||
return com.google.protobuf.MapField.emptyMapField(
|
||||
HeadersDefaultEntryHolder.defaultEntry);
|
||||
}
|
||||
return headers_;
|
||||
}
|
||||
|
||||
public int getHeadersCount() {
|
||||
return internalGetHeaders().getMap().size();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public boolean containsHeaders(
|
||||
String key) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
return internalGetHeaders().getMap().containsKey(key);
|
||||
}
|
||||
/**
|
||||
* Use {@link #getHeadersMap()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public java.util.Map<String, String> getHeaders() {
|
||||
return getHeadersMap();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public java.util.Map<String, String> getHeadersMap() {
|
||||
return internalGetHeaders().getMap();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public String getHeadersOrDefault(
|
||||
String key,
|
||||
String defaultValue) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
java.util.Map<String, String> map =
|
||||
internalGetHeaders().getMap();
|
||||
return map.getOrDefault(key, defaultValue);
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public String getHeadersOrThrow(
|
||||
String key) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
java.util.Map<String, String> map =
|
||||
internalGetHeaders().getMap();
|
||||
if (!map.containsKey(key)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
private byte memoizedIsInitialized = -1;
|
||||
@Override
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
if (!getTypeBytes().isEmpty()) {
|
||||
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, type_);
|
||||
}
|
||||
com.google.protobuf.GeneratedMessageV3
|
||||
.serializeStringMapTo(
|
||||
output,
|
||||
internalGetHeaders(),
|
||||
HeadersDefaultEntryHolder.defaultEntry,
|
||||
7);
|
||||
if (!getClientIpBytes().isEmpty()) {
|
||||
com.google.protobuf.GeneratedMessageV3.writeString(output, 8, clientIp_);
|
||||
}
|
||||
unknownFields.writeTo(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (!getTypeBytes().isEmpty()) {
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, type_);
|
||||
}
|
||||
for (java.util.Map.Entry<String, String> entry
|
||||
: internalGetHeaders().getMap().entrySet()) {
|
||||
com.google.protobuf.MapEntry<String, String>
|
||||
headers__ = HeadersDefaultEntryHolder.defaultEntry.newBuilderForType()
|
||||
.setKey(entry.getKey())
|
||||
.setValue(entry.getValue())
|
||||
.build();
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(7, headers__);
|
||||
}
|
||||
if (!getClientIpBytes().isEmpty()) {
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, clientIp_);
|
||||
}
|
||||
size += unknownFields.getSerializedSize();
|
||||
memoizedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Metadata)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
Metadata other = (Metadata) obj;
|
||||
|
||||
if (!getType()
|
||||
.equals(other.getType())) return false;
|
||||
if (!getClientIp()
|
||||
.equals(other.getClientIp())) return false;
|
||||
if (!internalGetHeaders().equals(
|
||||
other.internalGetHeaders())) return false;
|
||||
if (!unknownFields.equals(other.unknownFields)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
hash = (37 * hash) + TYPE_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getType().hashCode();
|
||||
hash = (37 * hash) + CLIENTIP_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getClientIp().hashCode();
|
||||
if (!internalGetHeaders().getMap().isEmpty()) {
|
||||
hash = (37 * hash) + HEADERS_FIELD_NUMBER;
|
||||
hash = (53 * hash) + internalGetHeaders().hashCode();
|
||||
}
|
||||
hash = (29 * hash) + unknownFields.hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static Metadata parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static Metadata parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static Metadata parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static Metadata parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
public static Metadata parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static Metadata parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder() {
|
||||
return DEFAULT_INSTANCE.toBuilder();
|
||||
}
|
||||
public static Builder newBuilder(Metadata prototype) {
|
||||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
}
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return this == DEFAULT_INSTANCE
|
||||
? new Builder() : new Builder().mergeFrom(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder newBuilderForType(
|
||||
BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code Metadata}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:Metadata)
|
||||
MetadataOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return NacosGrpcService.internal_static_Metadata_descriptor;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
protected com.google.protobuf.MapField internalGetMapField(
|
||||
int number) {
|
||||
switch (number) {
|
||||
case 7:
|
||||
return internalGetHeaders();
|
||||
default:
|
||||
throw new RuntimeException(
|
||||
"Invalid map field number: " + number);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
protected com.google.protobuf.MapField internalGetMutableMapField(
|
||||
int number) {
|
||||
switch (number) {
|
||||
case 7:
|
||||
return internalGetMutableHeaders();
|
||||
default:
|
||||
throw new RuntimeException(
|
||||
"Invalid map field number: " + number);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return NacosGrpcService.internal_static_Metadata_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
Metadata.class, Builder.class);
|
||||
}
|
||||
|
||||
// Construct using com.alibaba.nacos.api.grpc.auto.Metadata.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
type_ = "";
|
||||
|
||||
clientIp_ = "";
|
||||
|
||||
internalGetMutableHeaders().clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return NacosGrpcService.internal_static_Metadata_descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getDefaultInstanceForType() {
|
||||
return Metadata.getDefaultInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata build() {
|
||||
Metadata result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata buildPartial() {
|
||||
Metadata result = new Metadata(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
result.type_ = type_;
|
||||
result.clientIp_ = clientIp_;
|
||||
result.headers_ = internalGetHeaders();
|
||||
result.headers_.makeImmutable();
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder clone() {
|
||||
return super.clone();
|
||||
}
|
||||
@Override
|
||||
public Builder setField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
Object value) {
|
||||
return super.setField(field, value);
|
||||
}
|
||||
@Override
|
||||
public Builder clearField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field) {
|
||||
return super.clearField(field);
|
||||
}
|
||||
@Override
|
||||
public Builder clearOneof(
|
||||
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
|
||||
return super.clearOneof(oneof);
|
||||
}
|
||||
@Override
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
int index, Object value) {
|
||||
return super.setRepeatedField(field, index, value);
|
||||
}
|
||||
@Override
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
Object value) {
|
||||
return super.addRepeatedField(field, value);
|
||||
}
|
||||
@Override
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof Metadata) {
|
||||
return mergeFrom((Metadata)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(Metadata other) {
|
||||
if (other == Metadata.getDefaultInstance()) return this;
|
||||
if (!other.getType().isEmpty()) {
|
||||
type_ = other.type_;
|
||||
onChanged();
|
||||
}
|
||||
if (!other.getClientIp().isEmpty()) {
|
||||
clientIp_ = other.clientIp_;
|
||||
onChanged();
|
||||
}
|
||||
internalGetMutableHeaders().mergeFrom(
|
||||
other.internalGetHeaders());
|
||||
this.mergeUnknownFields(other.unknownFields);
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
Metadata parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (Metadata) e.getUnfinishedMessage();
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
private Object type_ = "";
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public String getType() {
|
||||
Object ref = type_;
|
||||
if (!(ref instanceof String)) {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
String s = bs.toStringUtf8();
|
||||
type_ = s;
|
||||
return s;
|
||||
} else {
|
||||
return (String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getTypeBytes() {
|
||||
Object ref = type_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(String) ref);
|
||||
type_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public Builder setType(
|
||||
String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
type_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public Builder clearType() {
|
||||
|
||||
type_ = getDefaultInstance().getType();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
*/
|
||||
public Builder setTypeBytes(
|
||||
com.google.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
checkByteStringIsUtf8(value);
|
||||
|
||||
type_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
private Object clientIp_ = "";
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public String getClientIp() {
|
||||
Object ref = clientIp_;
|
||||
if (!(ref instanceof String)) {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
String s = bs.toStringUtf8();
|
||||
clientIp_ = s;
|
||||
return s;
|
||||
} else {
|
||||
return (String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getClientIpBytes() {
|
||||
Object ref = clientIp_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(String) ref);
|
||||
clientIp_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public Builder setClientIp(
|
||||
String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
clientIp_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public Builder clearClientIp() {
|
||||
|
||||
clientIp_ = getDefaultInstance().getClientIp();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
*/
|
||||
public Builder setClientIpBytes(
|
||||
com.google.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
checkByteStringIsUtf8(value);
|
||||
|
||||
clientIp_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
private com.google.protobuf.MapField<
|
||||
String, String> headers_;
|
||||
private com.google.protobuf.MapField<String, String>
|
||||
internalGetHeaders() {
|
||||
if (headers_ == null) {
|
||||
return com.google.protobuf.MapField.emptyMapField(
|
||||
HeadersDefaultEntryHolder.defaultEntry);
|
||||
}
|
||||
return headers_;
|
||||
}
|
||||
private com.google.protobuf.MapField<String, String>
|
||||
internalGetMutableHeaders() {
|
||||
onChanged();
|
||||
if (headers_ == null) {
|
||||
headers_ = com.google.protobuf.MapField.newMapField(
|
||||
HeadersDefaultEntryHolder.defaultEntry);
|
||||
}
|
||||
if (!headers_.isMutable()) {
|
||||
headers_ = headers_.copy();
|
||||
}
|
||||
return headers_;
|
||||
}
|
||||
|
||||
public int getHeadersCount() {
|
||||
return internalGetHeaders().getMap().size();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public boolean containsHeaders(
|
||||
String key) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
return internalGetHeaders().getMap().containsKey(key);
|
||||
}
|
||||
/**
|
||||
* Use {@link #getHeadersMap()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public java.util.Map<String, String> getHeaders() {
|
||||
return getHeadersMap();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public java.util.Map<String, String> getHeadersMap() {
|
||||
return internalGetHeaders().getMap();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public String getHeadersOrDefault(
|
||||
String key,
|
||||
String defaultValue) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
java.util.Map<String, String> map =
|
||||
internalGetHeaders().getMap();
|
||||
return map.containsKey(key) ? map.get(key) : defaultValue;
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public String getHeadersOrThrow(
|
||||
String key) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
java.util.Map<String, String> map =
|
||||
internalGetHeaders().getMap();
|
||||
if (!map.containsKey(key)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public Builder clearHeaders() {
|
||||
internalGetMutableHeaders().getMutableMap()
|
||||
.clear();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public Builder removeHeaders(
|
||||
String key) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
internalGetMutableHeaders().getMutableMap()
|
||||
.remove(key);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Use alternate mutation accessors instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public java.util.Map<String, String>
|
||||
getMutableHeaders() {
|
||||
return internalGetMutableHeaders().getMutableMap();
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
public Builder putHeaders(
|
||||
String key,
|
||||
String value) {
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
if (value == null) { throw new NullPointerException(); }
|
||||
internalGetMutableHeaders().getMutableMap()
|
||||
.put(key, value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
|
||||
public Builder putAllHeaders(
|
||||
java.util.Map<String, String> values) {
|
||||
internalGetMutableHeaders().getMutableMap()
|
||||
.putAll(values);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:Metadata)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:Metadata)
|
||||
private static final Metadata DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new Metadata();
|
||||
}
|
||||
|
||||
public static Metadata getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<Metadata>
|
||||
PARSER = new com.google.protobuf.AbstractParser<Metadata>() {
|
||||
@Override
|
||||
public Metadata parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new Metadata(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<Metadata> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Parser<Metadata> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user