diff --git a/.gitattributes b/.gitattributes index af19312d146..c2a655ad66c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -text=auto \ No newline at end of file +text=auto +*.sh text eol=lf diff --git a/scripts/helm/apollo-portal/Chart.yaml b/.github/FUNDING.yml similarity index 56% rename from scripts/helm/apollo-portal/Chart.yaml rename to .github/FUNDING.yml index e9fc01ff12a..39a0c9b4e22 100644 --- a/scripts/helm/apollo-portal/Chart.yaml +++ b/.github/FUNDING.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,15 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -apiVersion: v2 -name: apollo-portal -description: A Helm chart for Apollo Portal -type: application -version: 0.3.0 -appVersion: 1.9.0 -home: https://github.com/ctripcorp/apollo -icon: https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/logo-simple.png -maintainers: -- name: nobodyiam - email: nobodyiam@gmail.com - url: https://github.com/nobodyiam + +github: [apolloconfig] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +open_collective: apollo # Replace with a single Open Collective username diff --git a/.github/stale.yml b/.github/stale.yml index b5530ff060d..fe1582c9a20 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 515206e7951..12c52ca00c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - jdk: [7, 8, 11] + jdk: [8, 11, 17] steps: - uses: actions/checkout@v2 - name: Set up JDK @@ -42,15 +42,15 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - name: Build SDK with JDK 7 - if: matrix.jdk == '7' - run: mvn clean compile -pl apollo-client,apollo-mockserver,apollo-openapi -am -Dmaven.gitcommitid.skip=true - name: JDK 8 if: matrix.jdk == '8' run: mvn -B clean package -P travis jacoco:report -Dmaven.gitcommitid.skip=true - name: JDK 11 if: matrix.jdk == '11' - run: mvn clean compile -Dmaven.gitcommitid.skip=true + run: mvn -B clean compile -Dmaven.gitcommitid.skip=true + - name: JDK 17 + if: matrix.jdk == '17' + run: mvn -B clean compile -Dmaven.gitcommitid.skip=true - name: Upload coverage to Codecov if: matrix.jdk == '8' uses: codecov/codecov-action@v1 diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index a79e6970881..79092803691 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,10 +34,10 @@ jobs: PERSONAL_ACCESS_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN_FOR_CLA_ASSISTANT }} with: path-to-signatures: 'signatures/version1/cla.json' - path-to-document: 'https://github.com/ctripcorp/apollo-community/blob/master/CLA.md' # e.g. a CLA or a DCO document + path-to-document: 'https://github.com/apolloconfig/apollo-community/blob/master/CLA.md' # e.g. a CLA or a DCO document # branch should not be protected branch: 'master' - allowlist: dependabot,bot* + allowlist: dependabot,bot*,github-actions remote-repository-name: apollo-community #below are the optional inputs - If the optional inputs are not given, then default values will be taken @@ -49,4 +49,4 @@ jobs: #custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA' #custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.' #lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true) - #use-dco-flag: true - If you are using DCO instead of CLA \ No newline at end of file + #use-dco-flag: true - If you are using DCO instead of CLA diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml index 5daacbdad17..a23f86def14 100644 --- a/.github/workflows/license.yml +++ b/.github/workflows/license.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/.github/workflows/release-1.8.yml b/.github/workflows/release-1.8.yml deleted file mode 100644 index 6cd746a820a..00000000000 --- a/.github/workflows/release-1.8.yml +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright 2021 Apollo 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. -# -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: publish apollo-client-config-data - -on: - workflow_dispatch: - inputs: - repository: - description: 'Maven Repository(snapshots or releases)' - required: true - default: 'snapshots' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Maven Central Repository - uses: actions/setup-java@v1 - with: - java-version: 8 - server-id: ${{ github.event.inputs.repository }} - server-username: MAVEN_USERNAME - server-password: MAVEN_CENTRAL_TOKEN - gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} - gpg-passphrase: MAVEN_GPG_PASSPHRASE - - name: Publish to Apache Maven Central - run: mvn clean deploy -pl apollo-client-config-data -DskipTests=true "-Dreleases.repo=https://oss.sonatype.org/service/local/staging/deploy/maven2" "-Dsnapshots.repo=https://oss.sonatype.org/content/repositories/snapshots" - env: - MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} - MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cdcd6b95d56..d8f071e045b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,14 +34,14 @@ jobs: - name: Set up Maven Central Repository uses: actions/setup-java@v1 with: - java-version: 7 + java-version: 8 server-id: ${{ github.event.inputs.repository }} server-username: MAVEN_USERNAME server-password: MAVEN_CENTRAL_TOKEN gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} gpg-passphrase: MAVEN_GPG_PASSPHRASE - name: Publish to Apache Maven Central - run: mvn clean deploy -pl apollo-client,apollo-mockserver,apollo-openapi -am -DskipTests=true "-Dreleases.repo=https://oss.sonatype.org/service/local/staging/deploy/maven2" "-Dsnapshots.repo=https://oss.sonatype.org/content/repositories/snapshots" + run: mvn clean deploy -pl apollo-client,apollo-mockserver,apollo-openapi,apollo-client-config-data -am -DskipTests=true -Prelease "-Dreleases.repo=https://oss.sonatype.org/service/local/staging/deploy/maven2" "-Dsnapshots.repo=https://oss.sonatype.org/content/repositories/snapshots" env: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} diff --git a/.licenserc.yaml b/.licenserc.yaml index 7e1e7218a21..de3178ba7af 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/CHANGES.md b/CHANGES.md index 5b3c4c5971f..705767bc85f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,80 +2,55 @@ Changes by Version ================== Release Notes. -Apollo 1.9.0 +Apollo 2.0.0 ------------------ -* [extend DataChange_CreatedBy, DataChange_LastModifiedBy from 32 to 64.](https://github.com/ctripcorp/apollo/pull/3552) -* [add spring configuration metadata](https://github.com/ctripcorp/apollo/pull/3553) -* [fix #3551 and optimize ldap samples ](https://github.com/ctripcorp/apollo/pull/3561) -* [update wiki url and refine documentation](https://github.com/ctripcorp/apollo/pull/3563) -* [slim docker images](https://github.com/ctripcorp/apollo/pull/3572) -* [add network strategy guideline to docker quick start](https://github.com/ctripcorp/apollo/pull/3574) -* [Added support for consul service discovery](https://github.com/ctripcorp/apollo/pull/3575) -* [disable consul in apollo-assembly by default ](https://github.com/ctripcorp/apollo/pull/3585) -* [ServiceBootstrap unit test fix](https://github.com/ctripcorp/apollo/pull/3593) -* [replace http client implementation with interface ](https://github.com/ctripcorp/apollo/pull/3594) -* [Allow users to inject customized instance via ApolloInjectorCustomizer](https://github.com/ctripcorp/apollo/pull/3602) -* [Fixes #3606](https://github.com/ctripcorp/apollo/pull/3609) -* [Bump xstream from 1.4.15 to 1.4.16](https://github.com/ctripcorp/apollo/pull/3611) -* [docs: user practices. Alibaba Sentinel Dashboard Push Rules to apollo](https://github.com/ctripcorp/apollo/pull/3617) -* [update known users](https://github.com/ctripcorp/apollo/pull/3619) -* [add maven deploy action](https://github.com/ctripcorp/apollo/pull/3620) -* [fix the issue that access key doesn't work if appid passed is in different case](https://github.com/ctripcorp/apollo/pull/3627) -* [fix oidc logout](https://github.com/ctripcorp/apollo/pull/3628) -* [docs: third party sdk nodejs client](https://github.com/ctripcorp/apollo/pull/3632) -* [update known users](https://github.com/ctripcorp/apollo/pull/3633) -* [docs: use docsify pagination plugin](https://github.com/ctripcorp/apollo/pull/3634) -* [apollo client to support jdk16](https://github.com/ctripcorp/apollo/pull/3646) -* [add English version of readme](https://github.com/ctripcorp/apollo/pull/3656) -* [update known users](https://github.com/ctripcorp/apollo/pull/3657) -* [update apolloconfig.com domain](https://github.com/ctripcorp/apollo/pull/3658) -* [localize css to speed up the loading of google fonts](https://github.com/ctripcorp/apollo/pull/3660) -* [test(apollo-client): use assertEquals instead of assertThat](https://github.com/ctripcorp/apollo/pull/3667) -* [test(apollo-client): make timeout more longer when long poll](https://github.com/ctripcorp/apollo/pull/3668) -* [fix unit test](https://github.com/ctripcorp/apollo/pull/3669) -* [解决日志系统未初始化完成时,apollo 的加载日志没法输出问题](https://github.com/ctripcorp/apollo/pull/3677) -* [fix[apollo-configService]: Solve configService startup exception](https://github.com/ctripcorp/apollo/pull/3679) -* [Community Governance Proposal](https://github.com/ctripcorp/apollo/pull/3670) -* [增加阿波罗client的php库](https://github.com/ctripcorp/apollo/pull/3682) -* [Bump xstream from 1.4.16 to 1.4.17](https://github.com/ctripcorp/apollo/pull/3692) -* [Improve the nacos registry configuration document](https://github.com/ctripcorp/apollo/pull/3695) -* [Remove redundant invoke of trySyncFromUpstream](https://github.com/ctripcorp/apollo/pull/3699) -* [add apollo team introduction and community releated contents](https://github.com/ctripcorp/apollo/pull/3713) -* [fix oidc sql](https://github.com/ctripcorp/apollo/pull/3720) -* [feat(apollo-client): add method interestedChangedKeys to ConfigChangeEvent](https://github.com/ctripcorp/apollo/pull/3666) -* [add More... link for known users](https://github.com/ctripcorp/apollo/pull/3757) -* [update OIDC documentation](https://github.com/ctripcorp/apollo/pull/3766) -* [Improve the item-value length limit configuration document](https://github.com/ctripcorp/apollo/pull/3789) -* [Use queue#take instead of poll](https://github.com/ctripcorp/apollo/pull/3765) -* [feature: add Spring Boot 2.4 config data loader support](https://github.com/ctripcorp/apollo/pull/3754) -* [feat(open-api): get authorized apps](https://github.com/ctripcorp/apollo/pull/3647) -* [feature: shared session for multi apollo portal](https://github.com/ctripcorp/apollo/pull/3786) -* [feature: add email for select user on apollo portal](https://github.com/ctripcorp/apollo/pull/3797) -* [feature: modify item comment valid size](https://github.com/ctripcorp/apollo/pull/3803) -* [set default session store-type](https://github.com/ctripcorp/apollo/pull/3812) -* [speed up the stale issue mark and close phase](https://github.com/ctripcorp/apollo/pull/3808) -* [feature: add the delegating password encoder for apollo-portal simple auth](https://github.com/ctripcorp/apollo/pull/3804) -* [support release apollo-client-config-data](https://github.com/ctripcorp/apollo/pull/3822) -* [Fix possiable NPE](https://github.com/ctripcorp/apollo/pull/3832) -* [Reduce bootstrap time in the situation with large properties](https://github.com/ctripcorp/apollo/pull/3816) -* [docs: English catalog in sidebar](https://github.com/ctripcorp/apollo/pull/3831) -* [fix the issue that release messages might be missed in certain scenarios](https://github.com/ctripcorp/apollo/pull/3819) -* [use official docker images for manual kubernetes deployment](https://github.com/ctripcorp/apollo/pull/3840) -* [fix size of create project button](https://github.com/ctripcorp/apollo/pull/3849) -* [translation of "portal-how-to-enable-webhook-notification.md"](https://github.com/ctripcorp/apollo/pull/3847) -* [feature: add history detail for not key-value type of namespace](https://github.com/ctripcorp/apollo/pull/3856) -* [fix show-text-modal number display](https://github.com/ctripcorp/apollo/pull/3851) -* [Lazy load ConfigUtil](https://github.com/ctripcorp/apollo/pull/3864) -* [make jdbc session enable default](https://github.com/ctripcorp/apollo/pull/3869) -* [support json/yaml/xml format for public namespace](https://github.com/ctripcorp/apollo/pull/3836) -* [Translate application into 应用 not 项目](https://github.com/ctripcorp/apollo/pull/3877) -* [add spring configuration metadata for property names cache](https://github.com/ctripcorp/apollo/pull/3879) -* [Fix Multiple PropertySourcesPlaceholderConfigurer beans registered issue](https://github.com/ctripcorp/apollo/pull/3865) -* [use jdk 8 to publish apollo-client-config-data](https://github.com/ctripcorp/apollo/pull/3880) -* [fix apollo config data loader with profiles](https://github.com/ctripcorp/apollo/pull/3870) -* [polish log](https://github.com/ctripcorp/apollo/pull/3882) - +* [Fix issue that the $ symbol is not used when reading shell variables](https://github.com/ctripcorp/apollo/pull/3890) +* [Bump xstream from 1.4.17 to 1.4.18](https://github.com/apolloconfig/apollo/pull/3916) +* [switch apollo.config-service log from warning to info level](https://github.com/ctripcorp/apollo/pull/3884) +* [Make Access Key Timestamp check configurable](https://github.com/ctripcorp/apollo/pull/3908) +* [remove ctrip profile](https://github.com/ctripcorp/apollo/pull/3920) +* [Remove spring dependencies from internal code](https://github.com/apolloconfig/apollo/pull/3937) +* [Fix issue: ingress syntax](https://github.com/apolloconfig/apollo/pull/3933) +* [refactor: let open api more easier to use and development](https://github.com/apolloconfig/apollo/pull/3943) +* [feat(scripts): use bash to call openapi](https://github.com/apolloconfig/apollo/pull/3980) +* [Support search by item](https://github.com/apolloconfig/apollo/pull/3977) +* [Implement password policies to avoid weak passwords](https://github.com/apolloconfig/apollo/pull/4008) +* [Extend the gray release capability to support dimensions other than IP](https://github.com/apolloconfig/apollo/pull/4013) +* [public namespace basic function](https://github.com/apolloconfig/apollo/pull/3850) +* [Bump version to 2.0.0 and drop java 1.7 support](https://github.com/apolloconfig/apollo/pull/4015) +* [Optimize home page style](https://github.com/apolloconfig/apollo/pull/4052) +* [Support Java 17](https://github.com/apolloconfig/apollo/pull/4060) +* [Optimize top navbar style](https://github.com/apolloconfig/apollo/pull/4073) +* [Support export/import configs by apollo env](https://github.com/apolloconfig/apollo/pull/3947) +* [Catch LinkageError for ClassLoaderUtil.isClassPresent in case class is present but is failed to load](https://github.com/apolloconfig/apollo/pull/4097) +* [Split helm chart into another repo](https://github.com/apolloconfig/apollo/pull/4125) +* [fix gray publish refresh item status](https://github.com/apolloconfig/apollo/pull/4128) +* [Support only show difference keys when compare namespace](https://github.com/apolloconfig/apollo/pull/4165) +* [Fix the issue that property placeholder doesn't work for dubbo reference beans](https://github.com/apolloconfig/apollo/pull/4175) +* [Fix the NPE occurred when using EnableApolloConfig with Spring 3.1.1](https://github.com/apolloconfig/apollo/pull/4180) +* [Bump guava from 29.0 to 31.0.1](https://github.com/apolloconfig/apollo/pull/4182) +* [fix the json number display issue when it's longer than 16](https://github.com/apolloconfig/apollo/pull/4183) +* [Bump client springboot version](https://github.com/apolloconfig/apollo/pull/4189) +* [The release history of namespaces that are not properties will also show comments and release times](https://github.com/apolloconfig/apollo/pull/4198) +* [Add unit tests for Utils](https://github.com/apolloconfig/apollo/pull/4193) +* [Change Copy Right year to 2022](https://github.com/apolloconfig/apollo/pull/4202) +* [Optimize create namespace page](https://github.com/apolloconfig/apollo/pull/4213) +* [Allow disable apollo client cache](https://github.com/apolloconfig/apollo/pull/4199) +* [Make password check not hardcoded](https://github.com/apolloconfig/apollo/pull/4207) +* [Fix update user's password failure](https://github.com/apolloconfig/apollo/pull/4212) +* [Fix bug: associated namespace display incorrect in text view](https://github.com/apolloconfig/apollo/pull/4219) +* [Add Ordered interface to ProviderManager SPI](https://github.com/apolloconfig/apollo/pull/4218) +* [Using commons-lang3 to replace commons-lang](https://github.com/apolloconfig/apollo/pull/4225) +* [optimize import/export config](https://github.com/apolloconfig/apollo/pull/4231) +* [Configure publish and rollback modal boxes to add scrollbars](https://github.com/apolloconfig/apollo/pull/4251) +* [fix import config bug](https://github.com/apolloconfig/apollo/pull/4262) +* [Refactor the soft delete design](https://github.com/apolloconfig/apollo/pull/3866) +* [Fix the potential data inconsistency issue](https://github.com/apolloconfig/apollo/pull/4256) +* [Fix the deleted items display issue in text mode](https://github.com/apolloconfig/apollo/pull/4279) +* [Upgrade spring boot to 2.6.6 and spring cloud to 2021.0.1](https://github.com/apolloconfig/apollo/pull/4295) +* [Fix the apollo portal start failed issue](https://github.com/apolloconfig/apollo/pull/4298) +* [fix: javax.net.ssl.SSLHandshakeException: No appropriate protocol](https://github.com/apolloconfig/apollo/pull/4308) +* [Upgrade flyway to 8.0.5](https://github.com/apolloconfig/apollo/pull/4312) ------------------ -All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/6?closed=1) - +All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4dadc8243fe..5455a2531b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Contributing to apollo -Apollo is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below. +Apollo is released under the non-restrictive Apache 2.0 license, and follows a very standard GitHub development process, using GitHub tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below. ### Sign the Contributor License Agreement @@ -12,9 +12,7 @@ Our code style is in line with [Google Java Style Guide](https://google.github.i We provide template files [intellij-java-google-style.xml](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/intellij-java-google-style.xml) for IntelliJ IDEA and [eclipse-java-google-style.xml](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/eclipse-java-google-style.xml) for Eclipse. If you use other IDEs, then you may config manually by referencing the template files. -* Make sure all new .java files have a simple Javadoc class comment with at least an `@author` tag identifying you, and preferably at least a paragraph on what the class is for. - -* Add yourself as an @author to the .java files that you modify substantially (more than cosmetic changes). +* Make sure all new .java files have a simple Javadoc class comment on what the class is for. * Add some Javadocs and, if you change the namespace, some XSD doc elements. diff --git a/GOVERNANCE.md b/GOVERNANCE.md index 702b2f36429..bf7d46e352b 100644 --- a/GOVERNANCE.md +++ b/GOVERNANCE.md @@ -37,6 +37,23 @@ You are also encouraged to participate in the projects in the following ways: - Give representations of Apollo topic in conferences. - Take part in our discussions of features, enhancements, etc. +## Members + +Members are active contributors who have made multiple contributions to the project or community. They will be invited as a member of the [apollo organization](https://github.com/apolloconfig). + +### How to become a Member + +- Enabled [two-factor authentication](https://help.github.com/articles/about-two-factor-authentication) on their GitHub account +- Have made multiple contributions to the project or community, e.g. authoring or reviewing PRs, commenting on issues/discussions, etc +- [Submit a member request](https://github.com/apolloconfig/apollo-community/issues/new?template=membership-request.md&title=REQUEST%3A+New+membership+for+%3Cyour-github-username%3E) in the [apollo-community](https://github.com/apolloconfig/apollo-community) repo +- Sponsored by two PMC members, i.e. replying `+1` to confirm sponsorship in the member request + +### Privileges and responsibilities + +- Have the [Triage role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization#about-the-inherited-role) of the apollo community +- Responsive to issues and PRs assigned to them +- Active owner of code contributed by them, e.g. Addresses bugs or issues discovered after code is accepted + ## Committers Committers are contributors who have shown that they are committed to the continued development of the project through ongoing engagement with the community and recognized by PMCs for their outstanding contributions. @@ -53,6 +70,7 @@ A Committer must have accomplished one or more of the following items: ### Privileges and responsibilities +- Have the [Write role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization#about-the-inherited-role) of the apollo community - Control overall code quality of projects - Guide Contributors to contribute to the community continuously - Participate in design discussions @@ -91,4 +109,4 @@ Any change in this Governance document, or similar nature of changes to other go # Credits -The contents of this document are based on by Ross Gardler and Gabriel Hanganu, and [TiDB Governance](https://github.com/pingcap/community/blob/master/GOVERNANCE.md). +The contents of this document are based on [Meritocratic Governance Model](http://oss-watch.ac.uk/resources/meritocraticgovernancemodel), [TiDB Governance](https://github.com/pingcap/community/blob/master/GOVERNANCE.md) and [Dapr Community Membership](https://github.com/dapr/community/blob/master/community-membership.md). diff --git a/README.md b/README.md index fc558a01f11..ef2ca7adef2 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -apollo-logo +apollo-logo + +English | [中文](https://www.apolloconfig.com/#/zh/README) # Apollo - A reliable configuration management system -[![Build Status](https://github.com/ctripcorp/apollo/workflows/build/badge.svg)](https://github.com/ctripcorp/apollo/actions) -[![GitHub Release](https://img.shields.io/github/release/ctripcorp/apollo.svg)](https://github.com/ctripcorp/apollo/releases) +[![Build Status](https://github.com/apolloconfig/apollo/workflows/build/badge.svg)](https://github.com/apolloconfig/apollo/actions) +[![GitHub Release](https://img.shields.io/github/release/apolloconfig/apollo.svg)](https://github.com/apolloconfig/apollo/releases) [![Maven Central Repo](https://img.shields.io/maven-central/v/com.ctrip.framework.apollo/apollo.svg)](https://mvnrepository.com/artifact/com.ctrip.framework.apollo/apollo-client) -[![codecov.io](https://codecov.io/github/ctripcorp/apollo/coverage.svg?branch=master)](https://codecov.io/github/ctripcorp/apollo?branch=master) +[![codecov.io](https://codecov.io/github/apolloconfig/apollo/coverage.svg?branch=master)](https://codecov.io/github/apolloconfig/apollo?branch=master) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) Apollo is a reliable configuration management system. It can centrally manage the configurations of different applications and different clusters. It is suitable for microservice configuration management scenarios. @@ -25,7 +27,7 @@ Demo Environment: - User/Password: apollo/admin # Screenshots -![Screenshot](https://raw.githubusercontent.com/ctripcorp/apollo/master/docs/en/images/apollo-home-screenshot.jpg) +![Screenshot](https://cdn.jsdelivr.net/gh/apolloconfig/apollo@master/docs/en/images/apollo-home-screenshot.jpg) # Features * **Unified management of the configurations of different environments and different clusters** @@ -75,7 +77,7 @@ Demo Environment: 4. [Third Party SDK User Guide](https://www.apolloconfig.com/#/zh/usage/third-party-sdks-user-guide) 5. [Other Language Client User Guide](https://www.apolloconfig.com/#/zh/usage/other-language-client-user-guide) 6. [Apollo Open APIs](https://www.apolloconfig.com/#/zh/usage/apollo-open-api-platform) - 7. [Apollo Use Cases](https://github.com/ctripcorp/apollo-use-cases) + 7. [Apollo Use Cases](https://github.com/apolloconfig/apollo-use-cases) 8. [Apollo User Practices](https://www.apolloconfig.com/#/zh/usage/apollo-user-practices) 9. [Apollo Security Best Practices](https://www.apolloconfig.com/#/zh/usage/apollo-user-guide?id=_71-%e5%ae%89%e5%85%a8%e7%9b%b8%e5%85%b3) @@ -88,15 +90,15 @@ Demo Environment: # Development * [Apollo Development Guide](https://www.apolloconfig.com/#/zh/development/apollo-development-guide) * Code Styles - * [Eclipse Code Style](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/eclipse-java-google-style.xml) - * [Intellij Code Style](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/intellij-java-google-style.xml) + * [Eclipse Code Style](https://github.com/apolloconfig/apollo/blob/master/apollo-buildtools/style/eclipse-java-google-style.xml) + * [Intellij Code Style](https://github.com/apolloconfig/apollo/blob/master/apollo-buildtools/style/intellij-java-google-style.xml) # Deployment * [Quick Start](https://www.apolloconfig.com/#/zh/deployment/quick-start) * [Distributed Deployment Guide](https://www.apolloconfig.com/#/zh/deployment/distributed-deployment-guide) # Release Notes - * [Releases](https://github.com/ctripcorp/apollo/releases) + * [Releases](https://github.com/apolloconfig/apollo/releases) # FAQ * [FAQ](https://www.apolloconfig.com/#/zh/faq/faq) @@ -104,9 +106,9 @@ Demo Environment: # Presentation * [Design and Implementation Details of Apollo](http://www.itdks.com/dakalive/detail/3420) - * [Slides](https://myslide.cn/slides/10168) + * [Slides](https://github.com/apolloconfig/apollo-community/blob/master/slides/design-and-implementation-of-apollo.pdf) * [Configuration Center Makes Microservices Smart](https://2018.qconshanghai.com/presentation/799) - * [Slides](https://myslide.cn/slides/10035) + * [Slides](https://github.com/apolloconfig/apollo-community/blob/master/slides/configuration-center-makes-microservices-smart.pdf) # Publication * [Design and Implementation Details of Apollo](https://www.infoq.cn/article/open-source-configuration-center-apollo) @@ -114,429 +116,429 @@ Demo Environment: # Community * [Apollo Team](https://www.apolloconfig.com/#/en/community/team) - * [Community Governance](https://github.com/ctripcorp/apollo/blob/master/GOVERNANCE.md) - * [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) + * [Community Governance](https://github.com/apolloconfig/apollo/blob/master/GOVERNANCE.md) + * [Contributing Guide](https://github.com/apolloconfig/apollo/blob/master/CONTRIBUTING.md) # License -The project is licensed under the [Apache 2 license](https://github.com/ctripcorp/apollo/blob/master/LICENSE). +The project is licensed under the [Apache 2 license](https://github.com/apolloconfig/apollo/blob/master/LICENSE). # Known Users -> Sorted by registration order,users are welcome to register in [https://github.com/ctripcorp/apollo/issues/451](https://github.com/ctripcorp/apollo/issues/451) (reference purpose only for the community) +> Sorted by registration order,users are welcome to register in [https://github.com/apolloconfig/apollo/issues/451](https://github.com/apolloconfig/apollo/issues/451) (reference purpose only for the community) - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + +
携程青石证券沙绿航旅纵横58转转携程青石证券沙绿航旅纵横58转转
蜂助手海南航空CVTE明博教育麻袋理财蜂助手海南航空CVTE明博教育麻袋理财
美行科技首展科技易微行人才加凯京集团美行科技首展科技易微行人才加凯京集团
乐刻运动大疆快看漫画我来贷虚实软件乐刻运动大疆快看漫画我来贷虚实软件
网易严选视觉中国资产360亿咖通5173网易严选视觉中国资产360亿咖通5173
沪江网易云基础服务现金巴士锤子科技头等仓沪江网易云基础服务现金巴士锤子科技头等仓
吉祥航空263移动通信投投金融每天健康麦芽金服吉祥航空263移动通信投投金融每天健康麦芽金服
蜂向科技即科金融贝壳网有赞云集汇通蜂向科技即科金融贝壳网有赞云集汇通
犀牛瀚海科技农信互联蘑菇租房狐狸金服漫道集团犀牛瀚海科技农信互联蘑菇租房狐狸金服漫道集团
怪兽充电南瓜租房石投金融土巴兔平安银行怪兽充电南瓜租房石投金融土巴兔平安银行
新新贷中国华戎科技集团涂鸦智能立创商城乐赚金服新新贷中国华戎科技集团涂鸦智能立创商城乐赚金服
开心汽车乐赚金服普元信息医帮管家付啦信用卡管家开心汽车乐赚金服普元信息医帮管家付啦信用卡管家
悠哉网梧桐诚选拍拍贷信用飞丁香园悠哉网梧桐诚选拍拍贷信用飞丁香园
国槐科技亲宝宝华为视频直播微播易欧飞国槐科技亲宝宝华为视频直播微播易欧飞
迷说一下科技DaoCloud汽摩交易所好未来教育集团迷说一下科技DaoCloud汽摩交易所好未来教育集团
猎户星空卓健科技银江股份途虎养车河姆渡猎户星空卓健科技银江股份途虎养车河姆渡
新网银行中旅安信云贷美柚震坤行万谷盛世新网银行中旅安信云贷美柚震坤行万谷盛世
铂涛旅行乐心亿投传媒股先生财学堂铂涛旅行乐心亿投传媒股先生财学堂
4399汽车之家面包财经虎扑搜狐汽车4399汽车之家面包财经虎扑搜狐汽车
量富征信卖好车中移物联网易车网一药网量富征信卖好车中移物联网易车网一药网
小影彩贝壳YEELIGHT积目极致医疗小影彩贝壳YEELIGHT积目极致医疗
金汇金融久柏易游小麦铺搜款网米庄理财金汇金融久柏易游小麦铺搜款网米庄理财
贝吉塔网络科技微盟网易卡搭股书聚贸贝吉塔网络科技微盟网易卡搭股书聚贸
广联达bimface环球易购浙江执御二维火上品广联达bimface环球易购浙江执御二维火上品
浪潮集团纳里健康橙红科技龙腾出行荔枝浪潮集团纳里健康橙红科技龙腾出行荔枝
汇通达云融金科天生掌柜容联光辉云天励飞汇通达云融金科天生掌柜容联光辉云天励飞
嘉云数据中泰证券网络金融部网易易盾享物说申通嘉云数据中泰证券网络金融部网易易盾享物说申通
金和网络二三四五恒天财富沐雪微信温州医科大学附属眼视光医院金和网络二三四五恒天财富沐雪微信温州医科大学附属眼视光医院
联通支付杉数科技分利宝核桃编程小红书联通支付杉数科技分利宝核桃编程小红书
幸福西饼跨越速运OYO叮咚买菜智道网联幸福西饼跨越速运OYO叮咚买菜智道网联
雪球车通云哒哒英语小E微店达令家雪球车通云哒哒英语小E微店达令家
人力窝嘉美在线极易付智慧开源车仕库人力窝嘉美在线极易付智慧开源车仕库
太美医疗科技亿联百汇舟谱数据芙蓉兴盛野兽派太美医疗科技亿联百汇舟谱数据芙蓉兴盛野兽派
凯叔讲故事好大夫在线云幂信息技术兑吧九机网凯叔讲故事好大夫在线云幂信息技术兑吧九机网
随手科技万谷盛世云账房浙江远图互联青客公寓随手科技万谷盛世云账房浙江远图互联青客公寓
东方财富极客修美市科技中通快递易流科技东方财富极客修美市科技中通快递易流科技
实习僧达令家寺库连连支付众安保险实习僧达令家寺库连连支付众安保险
360金融中航服商旅贝壳Yeahmobi易点天下北京登云美业网络科技有限公司360金融中航服商旅贝壳Yeahmobi易点天下北京登云美业网络科技有限公司
金和网络中移(杭州)信息技术有限公司北森合肥维天运通北京蜜步科技有限公司金和网络中移(杭州)信息技术有限公司北森合肥维天运通北京蜜步科技有限公司
术康富力集团天府行八商山中原地产术康富力集团天府行八商山中原地产
智科云达中原730百果园波罗蜜Xignite智科云达中原730百果园波罗蜜Xignite
杭州有云科技有限公司成都书声科技有限公司斯维登集团广东快乐种子科技有限公司上海盈翼文化传播有限公司杭州有云科技有限公司成都书声科技有限公司斯维登集团广东快乐种子科技有限公司上海盈翼文化传播有限公司
上海尚诚消费金融股份有限公司自如网京东兔展智能竹贝上海尚诚消费金融股份有限公司自如网京东兔展智能竹贝
iMile(中东)哈罗出行智联招聘阿卡索妙知旅iMile(中东)哈罗出行智联招聘阿卡索妙知旅
程多多上汽通用五菱乐言科技樊登读书找一找教程网程多多上汽通用五菱乐言科技樊登读书找一找教程网
中油碧辟石油有限公司四川商旅无忧科技服务有限公司懿鸢网络科技(上海)有限公司稿定科技搵樓 - 利嘉閣中油碧辟石油有限公司四川商旅无忧科技服务有限公司懿鸢网络科技(上海)有限公司稿定科技搵樓 - 利嘉閣
南京领行科技股份有限公司北京希瑞亚斯科技有限公司印彩虹印刷公司Million Tech果果科技南京领行科技股份有限公司北京希瑞亚斯科技有限公司印彩虹印刷公司Million Tech果果科技
昆明航空我爱我家国金证券不亦乐乎惠农网昆明航空我爱我家国金证券不亦乐乎惠农网
成都道壳澳优乳业河南有态度信息科技有限公司智阳第一人力上海保险交易所成都道壳澳优乳业河南有态度信息科技有限公司智阳第一人力上海保险交易所
万顺叫车收钱吧宝尊电商喜百年供应链南京观为智慧软件科技有限公司万顺叫车收钱吧宝尊电商喜百年供应链南京观为智慧软件科技有限公司
在途商旅哗啦啦优信二手车每刻科技杭州蛮牛在途商旅哗啦啦优信二手车每刻科技杭州蛮牛
翼支付魔筷科技畅唐网络准时达早道网校翼支付魔筷科技畅唐网络准时达早道网校
万店掌推文科技Lemonbox保利票务芯翼科技万店掌推文科技Lemonbox保利票务芯翼科技
浙商银行易企银科技上海云盾苏州盖雅信息技术有限公司爱库存浙商银行易企银科技上海云盾苏州盖雅信息技术有限公司爱库存
极豆车联网伴鱼少儿英语锐达科技新东方在线金康高科极豆车联网伴鱼少儿英语锐达科技新东方在线金康高科
soul驿氪慧聪中塑在线甄云科技soul驿氪慧聪中塑在线甄云科技
追溯科技玩吧广州卡桑信息技术有限公司水滴酷我音乐追溯科技玩吧广州卡桑信息技术有限公司水滴酷我音乐
小米今典签宝科技广州趣米网络科技有限公司More...小米今典签宝科技广州趣米网络科技有限公司More...
# Awards -The most popular Chinese open source software in 2018 +The most popular Chinese open source software in 2018 # Stargazers over time -[![Stargazers over time](https://starcharts.herokuapp.com/ctripcorp/apollo.svg)](https://starcharts.herokuapp.com/ctripcorp/apollo) +[![Stargazers over time](https://starchart.cc/apolloconfig/apollo.svg)](https://starchart.cc/apolloconfig/apollo) diff --git a/apollo-adminservice/pom.xml b/apollo-adminservice/pom.xml index 22f2dd4a074..a4e2fd11329 100644 --- a/apollo-adminservice/pom.xml +++ b/apollo-adminservice/pom.xml @@ -1,6 +1,6 @@ + + org.springframework.cloud + spring-cloud-starter-zookeeper-discovery + com.h2database h2 diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizConfig.java index 61e627b90e1..e345f586c17 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/ApolloBizConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/auth/WebSecurityConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/auth/WebSecurityConfig.java index b4f6b287339..0cec692750b 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/auth/WebSecurityConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/auth/WebSecurityConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java index 06c17e07ce2..95913140abc 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,9 @@ public class BizConfig extends RefreshableConfig { private static final int DEFAULT_APPNAMESPACE_CACHE_REBUILD_INTERVAL = 60; //60s private static final int DEFAULT_GRAY_RELEASE_RULE_SCAN_INTERVAL = 60; //60s private static final int DEFAULT_APPNAMESPACE_CACHE_SCAN_INTERVAL = 1; //1s - private static final int DEFAULT_ACCESSKEY_CACHE_SCAN_INTERVAL = 1; //1s - private static final int DEFAULT_ACCESSKEY_CACHE_REBUILD_INTERVAL = 60; //60s + private static final int DEFAULT_ACCESS_KEY_CACHE_SCAN_INTERVAL = 1; //1s + private static final int DEFAULT_ACCESS_KEY_CACHE_REBUILD_INTERVAL = 60; //60s + private static final int DEFAULT_ACCESS_KEY_AUTH_TIME_DIFF_TOLERANCE = 60; //60s private static final int DEFAULT_RELEASE_MESSAGE_CACHE_SCAN_INTERVAL = 1; //1s private static final int DEFAULT_RELEASE_MESSAGE_SCAN_INTERVAL_IN_MS = 1000; //1000ms private static final int DEFAULT_RELEASE_MESSAGE_NOTIFICATION_BATCH = 100; @@ -138,8 +139,9 @@ public TimeUnit appNamespaceCacheRebuildIntervalTimeUnit() { } public int accessKeyCacheScanInterval() { - int interval = getIntProperty("apollo.access-key-cache-scan.interval", DEFAULT_ACCESSKEY_CACHE_SCAN_INTERVAL); - return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_ACCESSKEY_CACHE_SCAN_INTERVAL); + int interval = getIntProperty("apollo.access-key-cache-scan.interval", + DEFAULT_ACCESS_KEY_CACHE_SCAN_INTERVAL); + return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_ACCESS_KEY_CACHE_SCAN_INTERVAL); } public TimeUnit accessKeyCacheScanIntervalTimeUnit() { @@ -147,14 +149,22 @@ public TimeUnit accessKeyCacheScanIntervalTimeUnit() { } public int accessKeyCacheRebuildInterval() { - int interval = getIntProperty("apollo.access-key-cache-rebuild.interval", DEFAULT_ACCESSKEY_CACHE_REBUILD_INTERVAL); - return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_ACCESSKEY_CACHE_REBUILD_INTERVAL); + int interval = getIntProperty("apollo.access-key-cache-rebuild.interval", + DEFAULT_ACCESS_KEY_CACHE_REBUILD_INTERVAL); + return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_ACCESS_KEY_CACHE_REBUILD_INTERVAL); } public TimeUnit accessKeyCacheRebuildIntervalTimeUnit() { return TimeUnit.SECONDS; } + public int accessKeyAuthTimeDiffTolerance() { + int authTimeDiffTolerance = getIntProperty("apollo.access-key.auth-time-diff-tolerance", + DEFAULT_ACCESS_KEY_AUTH_TIME_DIFF_TOLERANCE); + return checkInt(authTimeDiffTolerance, 1, Integer.MAX_VALUE, + DEFAULT_ACCESS_KEY_AUTH_TIME_DIFF_TOLERANCE); + } + public int releaseMessageCacheScanInterval() { int interval = getIntProperty("apollo.release-message-cache-scan.interval", DEFAULT_RELEASE_MESSAGE_CACHE_SCAN_INTERVAL); return checkInt(interval, 1, Integer.MAX_VALUE, DEFAULT_RELEASE_MESSAGE_CACHE_SCAN_INTERVAL); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/BizLoggingCustomizer.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/BizLoggingCustomizer.java index c8ff3b9d2bf..608175f0ed9 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/BizLoggingCustomizer.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/BizLoggingCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/package-info.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/package-info.java index 43b37217d61..9b40e61a843 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/package-info.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/customize/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/AccessKey.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/AccessKey.java index 3719bfbec0c..260c91f071a 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/AccessKey.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/AccessKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ @Entity @Table(name = "AccessKey") -@SQLDelete(sql = "Update AccessKey set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update AccessKey set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class AccessKey extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java index 2dd6a280cdd..8bd08ff14b7 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ @Entity @Table(name = "Audit") -@SQLDelete(sql = "Update Audit set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Audit set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Audit extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java index 9f30d2df97d..8be52d30508 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ */ @Entity @Table(name = "Cluster") -@SQLDelete(sql = "Update Cluster set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Cluster set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Cluster extends BaseEntity implements Comparable { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java index 9f6edff4c12..0dd5e2cc0f9 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ @Entity @Table(name = "Commit") -@SQLDelete(sql = "Update Commit set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Commit set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Commit extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java index 394b9f0156a..4b8e10f7baf 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ @Entity @Table(name = "GrayReleaseRule") -@SQLDelete(sql = "Update GrayReleaseRule set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update GrayReleaseRule set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class GrayReleaseRule extends BaseEntity{ diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java index b5496661a7c..d394e6ff12d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java index f8bb7af9dee..5b0785d4227 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java index 6156b21d5bf..c30623908bd 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ @Entity @Table(name = "Item") -@SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Item set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Item extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java index 01206bf463f..869e582d104 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ @Entity @Table(name = "Namespace") -@SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Namespace set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Namespace extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java index 05f4c1a8663..83fa80582fa 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java index 28f9414294e..baa6f693ea3 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ @Entity @Table(name = "Privilege") -@SQLDelete(sql = "Update Privilege set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Privilege set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Privilege extends BaseEntity { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java index e2aab0827a9..d6099279c40 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ */ @Entity @Table(name = "Release") -@SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update Release set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class Release extends BaseEntity { @Column(name = "ReleaseKey", nullable = false) diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java index 2f697124460..e3a13f13de3 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ */ @Entity @Table(name = "ReleaseHistory") -@SQLDelete(sql = "Update ReleaseHistory set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update ReleaseHistory set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class ReleaseHistory extends BaseEntity { @Column(name = "AppId", nullable = false) diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java index 466ee9953c3..ff153b0d709 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java index 6631c1090b3..2b4a8cfd044 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ */ @Entity @Table(name = "ServerConfig") -@SQLDelete(sql = "Update ServerConfig set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update ServerConfig set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class ServerConfig extends BaseEntity { @Column(name = "Key", nullable = false) diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/eureka/ApolloEurekaClientConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/eureka/ApolloEurekaClientConfig.java index 41316dfdf48..278d3d9c70f 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/eureka/ApolloEurekaClientConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/eureka/ApolloEurekaClientConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java index 9a73440188c..a44f7f8944a 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,9 +75,9 @@ public String getNamespaceName() { return namespaceName; } - public boolean matches(String clientAppId, String clientIp) { + public boolean matches(String clientAppId, String clientIp, String clientLabel) { for (GrayReleaseRuleItemDTO ruleItem : ruleItems) { - if (ruleItem.matches(clientAppId, clientIp)) { + if (ruleItem.matches(clientAppId, clientIp, clientLabel)) { return true; } } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java index 4ef0e90cdd6..36777b70718 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,7 +134,7 @@ private void periodicScanRules() { } } - public Long findReleaseIdFromGrayReleaseRule(String clientAppId, String clientIp, String + public Long findReleaseIdFromGrayReleaseRule(String clientAppId, String clientIp, String clientLabel, String configAppId, String configCluster, String configNamespaceName) { String key = assembleGrayReleaseRuleKey(configAppId, configCluster, configNamespaceName); if (!grayReleaseRuleCache.containsKey(key)) { @@ -147,7 +147,7 @@ public Long findReleaseIdFromGrayReleaseRule(String clientAppId, String clientIp if (rule.getBranchStatus() != NamespaceBranchStatus.ACTIVE) { continue; } - if (rule.matches(clientAppId, clientIp)) { + if (rule.matches(clientAppId, clientIp, clientLabel)) { return rule.getReleaseId(); } } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSender.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSender.java index f00f6aea432..90aa8f7a9df 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSender.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/MessageSender.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/MessageSender.java index 37265c26309..eac554a507b 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/MessageSender.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/MessageSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageListener.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageListener.java index 81f65b0e5ca..7be5f910ebc 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageListener.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScanner.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScanner.java index ca8890c62c8..7ed80386ec9 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScanner.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/Topics.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/Topics.java index b1a0e6584a4..5c840ec62b2 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/Topics.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/message/Topics.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepository.java index e30bb019309..5b67de341da 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java index 84bdf4ce61f..46e783a6a9d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,10 +43,10 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository findFirst500ByIdGreaterThanOrderByIdAsc(long id); @Modifying - @Query("UPDATE AppNamespace SET IsDeleted=1,DataChange_LastModifiedBy = ?2 WHERE AppId=?1") + @Query("UPDATE AppNamespace SET IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?2 WHERE AppId=?1") int batchDeleteByAppId(String appId, String operator); @Modifying - @Query("UPDATE AppNamespace SET IsDeleted=1,DataChange_LastModifiedBy = ?3 WHERE AppId=?1 and Name = ?2") + @Query("UPDATE AppNamespace SET IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?3 WHERE AppId=?1 and Name = ?2") int delete(String appId, String namespaceName, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java index 2dace37d223..bc19b345e80 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java index 4e9aafa623f..004cdf50a1d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ClusterRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ClusterRepository.java index f9b23a1add3..bb6bfb9cf5e 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ClusterRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ClusterRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java index 0af8fa80c89..dab026c945d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,8 @@ List findByAppIdAndClusterNameAndNamespaceNameAndDataChangeLastModifiedT String appId, String clusterName, String namespaceName, Date dataChangeLastModifiedTime, Pageable pageable); @Modifying - @Query("update Commit set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("update Commit set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); + List findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(String appId, String clusterName, String namespaceName,String changeSets, Pageable page); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java index 5def9c0b5fa..fd0830e52cb 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/GrayReleaseRuleRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java index 8e73dbf90ad..7f6d376fdf9 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceRepository.java index efb74ed9409..5a7a7ce3ea5 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java index 572569e2e7c..d9d61769f4c 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import com.ctrip.framework.apollo.biz.entity.Item; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; @@ -35,10 +37,12 @@ public interface ItemRepository extends PagingAndSortingRepository { List findByNamespaceIdAndDataChangeLastModifiedTimeGreaterThan(Long namespaceId, Date date); + Page findByKey(String key, Pageable pageable); + Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId); @Modifying - @Query("update Item set isdeleted=1,DataChange_LastModifiedBy = ?2 where namespaceId = ?1") + @Query("update Item set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?2 where namespaceId = ?1") int deleteByNamespaceId(long namespaceId, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceLockRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceLockRepository.java index 89c428ecca1..58afbd42a2c 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceLockRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceLockRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java index 29755bb636d..6ca111c8a97 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.data.repository.PagingAndSortingRepository; import java.util.List; +import java.util.Set; public interface NamespaceRepository extends PagingAndSortingRepository { @@ -32,13 +33,15 @@ public interface NamespaceRepository extends PagingAndSortingRepository findByAppIdAndNamespaceNameOrderByIdAsc(String appId, String namespaceName); List findByNamespaceName(String namespaceName, Pageable page); + List findByIdIn(Set namespaceIds); + int countByNamespaceNameAndAppIdNot(String namespaceName, String appId); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java index e2759b5eed5..2bf17f4a04a 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java index f0c9ef896f8..1671fa194ef 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ Page findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(Stri Page findByReleaseIdAndOperationInOrderByIdDesc(long releaseId, Set operations, Pageable pageable); @Modifying - @Query("update ReleaseHistory set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("update ReleaseHistory set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java index eb02d5d3f02..a649858f40a 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java index e0e3314e1ea..ce0afe3ac7f 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ Release findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderBy List findByIdIn(Set releaseIds); @Modifying - @Query("update Release set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("update Release set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000), DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); // For release history conversion program, need to delete after conversion it done diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ServerConfigRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ServerConfigRepository.java index 0edc2e0bca5..464d379eddb 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ServerConfigRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ServerConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AccessKeyService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AccessKeyService.java index fefe0e686f1..aa342e0b05f 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AccessKeyService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AccessKeyService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java index 78bff67a511..49b006bce93 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AdminService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java index 27f416ac76e..8625de8645d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java index f3cbb092156..c257d34320b 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AuditService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AuditService.java index 169f8298295..a03e474c083 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AuditService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AuditService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java index 0a3cf8de429..68f76d65337 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java index e534b740fa2..d2adf09b4fe 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java index 5238bb23939..2c1a67bd8ab 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +51,11 @@ public List find(String appId, String clusterName, String namespaceName, appId, clusterName, namespaceName, lastModifiedTime, page); } + public List findByKey(String appId, String clusterName, String namespaceName, String key,Pageable page){ + String queryKey = "\"key\":\""+ key +"\""; + return commitRepository.findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(appId, clusterName, namespaceName, "%"+ queryKey + "%", page); + } + @Transactional public int batchDelete(String appId, String clusterName, String namespaceName, String operator){ return commitRepository.batchDelete(appId, clusterName, namespaceName, operator); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/InstanceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/InstanceService.java index ca2e720c476..7a4435215ec 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/InstanceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/InstanceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java index 127f14e0c4d..9dc7aff01b3 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,10 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.core.utils.StringUtils; + import org.springframework.context.annotation.Lazy; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -138,6 +141,10 @@ public List findItemsModifiedAfterDate(long namespaceId, Date date) { return itemRepository.findByNamespaceIdAndDataChangeLastModifiedTimeGreaterThan(namespaceId, date); } + public Page findItemsByKey(String key, Pageable pageable) { + return itemRepository.findByKey(key, pageable); + } + @Transactional public Item save(Item entity) { checkItemKeyLength(entity.getKey()); @@ -159,6 +166,26 @@ public Item save(Item entity) { return item; } + @Transactional + public Item saveComment(Item entity) { + entity.setKey(""); + entity.setValue(""); + entity.setId(0);//protection + + if (entity.getLineNum() == 0) { + Item lastItem = findLastOne(entity.getNamespaceId()); + int lineNum = lastItem == null ? 1 : lastItem.getLineNum() + 1; + entity.setLineNum(lineNum); + } + + Item item = itemRepository.save(entity); + + auditService.audit(Item.class.getSimpleName(), item.getId(), Audit.OP.INSERT, + item.getDataChangeCreatedBy()); + + return item; + } + @Transactional public Item update(Item item) { checkItemValueLength(item.getNamespaceId(), item.getValue()); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java index 84386e7460b..809aaed70fe 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder; import com.ctrip.framework.apollo.common.dto.ItemChangeSets; import com.ctrip.framework.apollo.common.dto.ItemDTO; +import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.utils.BeanUtils; import org.springframework.stereotype.Service; @@ -36,14 +37,17 @@ public class ItemSetService { private final AuditService auditService; private final CommitService commitService; private final ItemService itemService; + private final NamespaceService namespaceService; public ItemSetService( final AuditService auditService, final CommitService commitService, - final ItemService itemService) { + final ItemService itemService, + final NamespaceService namespaceService) { this.auditService = auditService; this.commitService = commitService; this.itemService = itemService; + this.namespaceService = namespaceService; } @Transactional @@ -54,11 +58,21 @@ public ItemChangeSets updateSet(Namespace namespace, ItemChangeSets changeSets){ @Transactional public ItemChangeSets updateSet(String appId, String clusterName, String namespaceName, ItemChangeSets changeSet) { + Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); + + if (namespace == null) { + throw new NotFoundException(String.format("Namespace %s not found", namespaceName)); + } + String operator = changeSet.getDataChangeLastModifiedBy(); ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder(); if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) { for (ItemDTO item : changeSet.getCreateItems()) { + if (item.getNamespaceId() != namespace.getId()) { + throw new BadRequestException("Invalid request, item and namespace do not match!"); + } + Item entity = BeanUtils.transform(Item.class, item); entity.setDataChangeCreatedBy(operator); entity.setDataChangeLastModifiedBy(operator); @@ -76,6 +90,9 @@ public ItemChangeSets updateSet(String appId, String clusterName, if (managedItem == null) { throw new NotFoundException(String.format("item not found.(key=%s)", entity.getKey())); } + if (managedItem.getNamespaceId() != namespace.getId()) { + throw new BadRequestException("Invalid request, item and namespace do not match!"); + } Item beforeUpdateItem = BeanUtils.transform(Item.class, managedItem); //protect. only value,comment,lastModifiedBy,lineNum can be modified @@ -94,6 +111,9 @@ public ItemChangeSets updateSet(String appId, String clusterName, if (!CollectionUtils.isEmpty(changeSet.getDeleteItems())) { for (ItemDTO item : changeSet.getDeleteItems()) { Item deletedItem = itemService.delete(item.getId(), operator); + if (deletedItem.getNamespaceId() != namespace.getId()) { + throw new BadRequestException("Invalid request, item and namespace do not match!"); + } configChangeContentBuilder.deleteItem(deletedItem); } auditService.audit("ItemSet", null, Audit.OP.DELETE, operator); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java index 6b3784b1a1f..fe574702108 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceLockService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceLockService.java index ff7c732d636..cafa7aaf108 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceLockService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceLockService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java index ba1f8e1f685..708151312ac 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,8 @@ import com.google.common.collect.Maps; import com.google.gson.Gson; import org.springframework.context.annotation.Lazy; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -104,6 +106,21 @@ public Namespace findOne(String appId, String clusterName, String namespaceName) namespaceName); } + /** + * the returned content's size is not fixed. so please carefully used. + */ + public Page findByItem(String itemKey, Pageable pageable) { + Page items = itemService.findItemsByKey(itemKey, pageable); + + if (!items.hasContent()) { + return Page.empty(); + } + + Set namespaceIds = BeanUtils.toPropertySet("namespaceId", items.getContent()); + + return new PageImpl<>(namespaceRepository.findByIdIn(namespaceIds)); + } + public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) { AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName); if (appNamespace == null) { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseHistoryService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseHistoryService.java index 6c74a0ebe0d..743bfa160b1 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseHistoryService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseHistoryService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseMessageService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseMessageService.java index a7aa2749eba..420ca6a8457 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseMessageService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseMessageService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java index 71a51f3662a..6e1e25d7040 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java index 05c807d91d7..5f622006346 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/EntityManagerUtil.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/EntityManagerUtil.java index 04b386f423e..e0de0c54666 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/EntityManagerUtil.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/EntityManagerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGenerator.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGenerator.java index ce0fbc29ed7..ebe2c591f26 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGenerator.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseMessageKeyGenerator.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseMessageKeyGenerator.java index e0f78a138b5..c9d699c545c 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseMessageKeyGenerator.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseMessageKeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractIntegrationTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractIntegrationTest.java index 2bfc807b53e..5dd265bcaeb 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractIntegrationTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractUnitTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractUnitTest.java index 608b1c5a6b5..d79c151b7ef 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractUnitTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AbstractUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/BizTestConfiguration.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/BizTestConfiguration.java index aa495a2d69b..0023055771d 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/BizTestConfiguration.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/BizTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java index 6a06a7c1979..a7cda3ab553 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/MockBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java index a42825c1f16..f13d0b176f6 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java index af94fcb3c24..77693973450 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,12 +84,14 @@ public void testScanGrayReleaseRules() throws Exception { String someClientAppId = "clientAppId1"; String someClientIp = "1.1.1.1"; + String someClientLabel = "myLabel"; String anotherClientAppId = "clientAppId2"; String anotherClientIp = "2.2.2.2"; + String anotherClientLabel = "testLabel"; GrayReleaseRule someRule = assembleGrayReleaseRule(someAppId, someClusterName, someNamespaceName, Lists.newArrayList(assembleRuleItem(someClientAppId, Sets.newHashSet - (someClientIp))), someReleaseId, activeBranchStatus); + (someClientIp), Sets.newHashSet(someClientLabel))), someReleaseId, activeBranchStatus); when(bizConfig.grayReleaseRuleScanInterval()).thenReturn(30); when(grayReleaseRuleRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0L)).thenReturn(Lists @@ -99,16 +101,18 @@ public void testScanGrayReleaseRules() throws Exception { grayReleaseRulesHolder.afterPropertiesSet(); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule - (someClientAppId, someClientIp, someAppId, someClusterName, someNamespaceName)); + (someClientAppId, someClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule - (someClientAppId.toUpperCase(), someClientIp, someAppId.toUpperCase(), someClusterName, someNamespaceName.toUpperCase())); + (someClientAppId, anotherClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (someClientAppId.toUpperCase(), someClientIp, someClientLabel, someAppId.toUpperCase(), someClusterName, someNamespaceName.toUpperCase())); assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(someClientAppId, - anotherClientIp, someAppId, someClusterName, someNamespaceName)); + anotherClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(anotherClientAppId, - someClientIp, someAppId, someClusterName, someNamespaceName)); + someClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(anotherClientAppId, - anotherClientIp, someAppId, someClusterName, someNamespaceName)); + anotherClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); assertTrue(grayReleaseRulesHolder.hasGrayReleaseRule(someClientAppId, someClientIp, someNamespaceName)); @@ -126,7 +130,7 @@ public void testScanGrayReleaseRules() throws Exception { GrayReleaseRule anotherRule = assembleGrayReleaseRule(someAppId, someClusterName, someNamespaceName, Lists.newArrayList(assembleRuleItem(anotherClientAppId, Sets.newHashSet - (anotherClientIp))), someReleaseId, activeBranchStatus); + (anotherClientIp),Sets.newHashSet(anotherClientLabel))), someReleaseId, activeBranchStatus); when(grayReleaseRuleRepository.findByAppIdAndClusterNameAndNamespaceName(someAppId, someClusterName, someNamespaceName)).thenReturn(Lists.newArrayList(anotherRule)); @@ -136,9 +140,14 @@ public void testScanGrayReleaseRules() throws Exception { someNamespaceName), Topics.APOLLO_RELEASE_TOPIC); assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule - (someClientAppId, someClientIp, someAppId, someClusterName, someNamespaceName)); + (someClientAppId, someClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (anotherClientAppId, anotherClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule - (anotherClientAppId, anotherClientIp, someAppId, someClusterName, someNamespaceName)); + (anotherClientAppId, someClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (anotherClientAppId, anotherClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); + assertFalse(grayReleaseRulesHolder.hasGrayReleaseRule(someClientAppId, someClientIp, someNamespaceName)); @@ -168,8 +177,8 @@ private GrayReleaseRule assembleGrayReleaseRule(String appId, String clusterName return rule; } - private GrayReleaseRuleItemDTO assembleRuleItem(String clientAppId, Set clientIpList) { - return new GrayReleaseRuleItemDTO(clientAppId, clientIpList); + private GrayReleaseRuleItemDTO assembleRuleItem(String clientAppId, Set clientIpList, Set clientLabelList) { + return new GrayReleaseRuleItemDTO(clientAppId, clientIpList, clientLabelList); } private ReleaseMessage assembleReleaseMessage(String appId, String clusterName, String diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSenderTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSenderTest.java index 523083e9c60..6af6c658878 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSenderTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/DatabaseMessageSenderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScannerTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScannerTest.java index 6c0585c05df..33aa4e8dd26 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScannerTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/message/ReleaseMessageScannerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepositoryTest.java index 664bab83c00..e455300f798 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AccessKeyRepositoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java index 017be8d269c..bfc804d0485 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppRepositoryTest.java index 29c5bee1e86..7e833a2d77a 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppRepositoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java index f648c957f0f..5b77df6eaba 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepositoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AccessKeyServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AccessKeyServiceTest.java index 9463f8180b1..2b3ab77780e 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AccessKeyServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AccessKeyServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java index 4fe30a3af7c..0c3b75cd595 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTransactionTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTransactionTest.java index cd772bda900..f9b5c728efc 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTransactionTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/AdminServiceTransactionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySourceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySourceTest.java index 7d6662d422b..bb139805796 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySourceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/BizDBPropertySourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ClusterServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ClusterServiceTest.java index 6eb0df61195..a9fdde425b1 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ClusterServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ClusterServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/InstanceServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/InstanceServiceTest.java index 8aa82a50b12..c4fd393a064 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/InstanceServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/InstanceServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchServiceTest.java index b59af90ae12..5b2124c2c27 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceBranchServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespacePublishInfoTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespacePublishInfoTest.java index 3991d249d25..865f76e2c18 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespacePublishInfoTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespacePublishInfoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceIntegrationTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceIntegrationTest.java index bfe71a82ff2..3853e467be7 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceIntegrationTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceTest.java index 364d015daca..2758bf6e4e4 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseCreationTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseCreationTest.java index 8815384160d..3f14db8731e 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseCreationTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseCreationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java index 23171ae544c..7d37cb2eef2 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java index 7ef8313ce4f..f62991b218c 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilderTest.java @@ -1,61 +1,79 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo 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 + * 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. + * 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.ctrip.framework.apollo.biz.utils; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import com.ctrip.framework.apollo.biz.MockBeanFactory; -import com.ctrip.framework.apollo.biz.entity.Item; import org.junit.Before; import org.junit.Test; +import com.ctrip.framework.apollo.biz.MockBeanFactory; +import com.ctrip.framework.apollo.biz.entity.Item; + /** * @author jian.tan */ public class ConfigChangeContentBuilderTest { - private final ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder(); + private ConfigChangeContentBuilder configChangeContentBuilder; private String configString; + private Item createdItem; + private Item updatedItem; + private Item updatedItemFalseCheck; + private Item createdItemFalseCheck; @Before public void initConfig() { - - Item createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); - Item updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1); - + configChangeContentBuilder = new ConfigChangeContentBuilder(); + createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); + updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1); + updatedItemFalseCheck = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); + createdItemFalseCheck = MockBeanFactory.mockItem(1, 1, "", "100", 1); configChangeContentBuilder.createItem(createdItem); + configChangeContentBuilder.createItem(createdItemFalseCheck); configChangeContentBuilder.updateItem(createdItem, updatedItem); + configChangeContentBuilder.updateItem(createdItem, updatedItemFalseCheck); configChangeContentBuilder.deleteItem(updatedItem); - + configChangeContentBuilder.deleteItem(createdItemFalseCheck); configString = configChangeContentBuilder.build(); } @Test public void testHasContent() { assertTrue(configChangeContentBuilder.hasContent()); + configChangeContentBuilder.getCreateItems().clear(); + assertTrue(configChangeContentBuilder.hasContent()); + configChangeContentBuilder.getUpdateItems().clear(); + assertTrue(configChangeContentBuilder.hasContent()); } @Test - public void testConvertJsonString() { - ConfigChangeContentBuilder contentBuilder = ConfigChangeContentBuilder - .convertJsonString(configString); + public void testHasContentFalseCheck() { + configChangeContentBuilder.getCreateItems().clear(); + configChangeContentBuilder.getUpdateItems().clear(); + configChangeContentBuilder.getDeleteItems().clear(); + assertFalse(configChangeContentBuilder.hasContent()); + } + @Test + public void testConvertJsonString() { + ConfigChangeContentBuilder contentBuilder = + ConfigChangeContentBuilder.convertJsonString(configString); assertNotNull(contentBuilder.getCreateItems()); assertNotNull(contentBuilder.getUpdateItems().get(0).oldItem); assertNotNull(contentBuilder.getUpdateItems().get(0).newItem); diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGeneratorTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGeneratorTest.java index d8f5e036b0f..a8498c5ac20 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGeneratorTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/resources/application.properties b/apollo-biz/src/test/resources/application.properties index abf1d215ca2..9b4c61093ad 100644 --- a/apollo-biz/src/test/resources/application.properties +++ b/apollo-biz/src/test/resources/application.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,9 @@ spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.properties.hibernate.show_sql=false +spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor spring.h2.console.enabled = true spring.h2.console.settings.web-allow-others=true -spring.cloud.consul.enabled=false \ No newline at end of file +spring.cloud.consul.enabled=false +spring.cloud.zookeeper.enabled=false +spring.jpa.defer-datasource-initialization=true \ No newline at end of file diff --git a/apollo-biz/src/test/resources/data.sql b/apollo-biz/src/test/resources/data.sql index 2309093ab07..37aad55eb7d 100644 --- a/apollo-biz/src/test/resources/data.sql +++ b/apollo-biz/src/test/resources/data.sql @@ -1,5 +1,5 @@ -- --- Copyright 2021 Apollo Authors +-- Copyright 2022 Apollo Authors -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. diff --git a/apollo-biz/src/test/resources/import.sql b/apollo-biz/src/test/resources/import.sql new file mode 100644 index 00000000000..afd2dd89066 --- /dev/null +++ b/apollo-biz/src/test/resources/import.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2022 Apollo 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. +-- +CREATE ALIAS IF NOT EXISTS UNIX_TIMESTAMP FOR "com.ctrip.framework.apollo.common.jpa.H2Function.unixTimestamp"; \ No newline at end of file diff --git a/apollo-biz/src/test/resources/logback-test.xml b/apollo-biz/src/test/resources/logback-test.xml index e7a409bb2f2..cc57b46b93f 100644 --- a/apollo-biz/src/test/resources/logback-test.xml +++ b/apollo-biz/src/test/resources/logback-test.xml @@ -1,6 +1,6 @@ - - - org.springframework.boot - spring-boot-dependencies - 1.5.16.RELEASE - pom - import - - - diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java index ef87f2dd5b2..26e507d6b2d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigChangeListener.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigChangeListener.java index a673c376cc3..c303af9c712 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigChangeListener.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFile.java index 14bfc7972c5..50b84a38d8e 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFileChangeListener.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFileChangeListener.java index 0a3d854e4a6..141386567e7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFileChangeListener.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFileChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java index 2108f0c2abe..184c5ee356d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/PropertiesCompatibleConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/PropertiesCompatibleConfigFile.java index b28a701fc63..7e428ef6d4c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/PropertiesCompatibleConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/PropertiesCompatibleConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java index 4c4652a06d9..2871cc96494 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/build/ApolloInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/ConfigSourceType.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/ConfigSourceType.java index 76515de32c7..b8249472fb8 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/ConfigSourceType.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/ConfigSourceType.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/PropertyChangeType.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/PropertyChangeType.java index d6a14573b29..ec72282e113 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/PropertyChangeType.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/enums/PropertyChangeType.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigException.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigException.java index 968eee0e6f2..3a7483cb0c9 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigException.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigStatusCodeException.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigStatusCodeException.java index 939f789ab72..ea2e0fe856e 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigStatusCodeException.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigStatusCodeException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java index e08c5e72934..2f4703bdc76 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java index 86c765dbfca..3a1c0df077c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java index 0c76738e56c..35ff55616c6 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigManager.java index 3c61a0269e8..0fedcbea8ce 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigRepository.java index b6f0b2138c6..faf4b6103ec 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java index ac165f1c0c5..e7cba404beb 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,7 +109,7 @@ private List getCustomizedConfigService() { return null; } - logger.warn("Located config services from apollo.config-service configuration: {}, will not refresh config services from remote meta service!", configServices); + logger.info("Located config services from apollo.config-service configuration: {}, will not refresh config services from remote meta service!", configServices); // mock service dto list String[] configServiceUrls = configServices.split(","); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java index 5ab8338ce9b..7b17d75f0b2 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,6 @@ import com.ctrip.framework.apollo.util.ExceptionUtil; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.RateLimiter; -import org.springframework.util.CollectionUtils; - /** * @author Jason Song(song_s@ctrip.com) @@ -186,10 +184,10 @@ public Set getPropertyNames() { // propertyNames include system property and system env might cause some compatibility issues, though that looks like the correct implementation. Set fromRepository = this.getPropertyNamesFromRepository(); Set fromAdditional = this.getPropertyNamesFromAdditional(); - if (CollectionUtils.isEmpty(fromRepository)) { + if (fromRepository == null || fromRepository.isEmpty()) { return fromAdditional; } - if (CollectionUtils.isEmpty(fromAdditional)) { + if (fromAdditional == null || fromAdditional.isEmpty()) { return fromRepository; } Set propertyNames = Sets diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java index 9f96eb335dc..f583a915ffa 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java index 6e26fc2336d..707ad6c519c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultMetaServerProvider.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultMetaServerProvider.java index e4aec00a7c6..1a00395976e 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultMetaServerProvider.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultMetaServerProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java index 8df7c977971..fab83b5fc9d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/Injector.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/InterestedConfigChangeEvent.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/InterestedConfigChangeEvent.java index 02b1afeb703..2d3365070f7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/InterestedConfigChangeEvent.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/InterestedConfigChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java index 79c14a0ef87..80befc927e8 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/JsonConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java index 60e3184e35c..f5e481161c4 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java index 770cd780dc1..f5f05d0ee19 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PlainTextConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesCompatibleFileConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesCompatibleFileConfigRepository.java index 181ec6b2e78..e505d18ac07 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesCompatibleFileConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesCompatibleFileConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesConfigFile.java index 485fbe570ae..205941a7e5e 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/PropertiesConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,28 @@ */ package com.ctrip.framework.apollo.internals; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; - +import com.ctrip.framework.apollo.PropertiesCompatibleConfigFile; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.utils.PropertiesUtil; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.util.ExceptionUtil; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicReference; /** + * Represents a config file that is of the file format `.properties` + * * @author Jason Song(song_s@ctrip.com) + * @author Diego Krupitza(info@diegokrupitza.com) */ -public class PropertiesConfigFile extends AbstractConfigFile { +public class PropertiesConfigFile extends AbstractConfigFile implements + PropertiesCompatibleConfigFile { + protected AtomicReference m_contentCache; public PropertiesConfigFile(String namespace, - ConfigRepository configRepository) { + ConfigRepository configRepository) { super(namespace, configRepository); m_contentCache = new AtomicReference<>(); } @@ -78,4 +83,8 @@ public ConfigFileFormat getConfigFileFormat() { return ConfigFileFormat.Properties; } + @Override + public Properties asProperties() { + return this.hasContent() ? m_configProperties.get() : propertiesFactory.getPropertiesInstance(); + } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java index 6e42a2718ac..12c25018829 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 53f75daa10a..6008f63e84f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -310,6 +310,11 @@ String assembleQueryConfigUrl(String uri, String appId, String cluster, String n queryParams.put("ip", queryParamEscaper.escape(localIp)); } + String label = m_configUtil.getApolloLabel(); + if (!Strings.isNullOrEmpty(label)) { + queryParams.put("label", queryParamEscaper.escape(label)); + } + if (remoteMessages != null) { queryParams.put("messages", queryParamEscaper.escape(GSON.toJson(remoteMessages))); } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RepositoryChangeListener.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RepositoryChangeListener.java index f9ddca3530f..77334d961cf 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RepositoryChangeListener.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RepositoryChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java index f9b29ccd095..c8897bbd918 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java index 6394abf0d10..dcffbcd6b5c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/TxtConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java index b19ec81a73e..8300a8360ce 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/XmlConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java index 2f01094004e..3443d582e08 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java index d03bc41eacc..5e922a53145 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YmlConfigFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChange.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChange.java index 304e05807c5..bcc6e4e66c5 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChange.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChange.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChangeEvent.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChangeEvent.java index a7676e63893..eddf003f71c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChangeEvent.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigFileChangeEvent.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigFileChangeEvent.java index 9ce0cb0c551..4c3569bf86d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigFileChangeEvent.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/model/ConfigFileChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ApolloInjectorCustomizer.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ApolloInjectorCustomizer.java index db2d482dc21..632ba40f13f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ApolloInjectorCustomizer.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ApolloInjectorCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactory.java index 6c78e51a1be..da4223f8195 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactoryManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactoryManager.java index 1b068f3117c..5d77a2bca9b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactoryManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigFactoryManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigRegistry.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigRegistry.java index a6a6f125191..8e34df6df36 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigRegistry.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/ConfigRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java index a74fdab60d9..36c300f47b6 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,32 +16,45 @@ */ package com.ctrip.framework.apollo.spi; -import com.ctrip.framework.apollo.ConfigService; -import com.ctrip.framework.apollo.PropertiesCompatibleConfigFile; -import com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository; -import com.ctrip.framework.apollo.internals.TxtConfigFile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigFile; +import com.ctrip.framework.apollo.ConfigService; +import com.ctrip.framework.apollo.PropertiesCompatibleConfigFile; import com.ctrip.framework.apollo.build.ApolloInjector; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.internals.ConfigRepository; import com.ctrip.framework.apollo.internals.DefaultConfig; import com.ctrip.framework.apollo.internals.JsonConfigFile; import com.ctrip.framework.apollo.internals.LocalFileConfigRepository; +import com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository; import com.ctrip.framework.apollo.internals.PropertiesConfigFile; import com.ctrip.framework.apollo.internals.RemoteConfigRepository; +import com.ctrip.framework.apollo.internals.TxtConfigFile; import com.ctrip.framework.apollo.internals.XmlConfigFile; import com.ctrip.framework.apollo.internals.YamlConfigFile; import com.ctrip.framework.apollo.internals.YmlConfigFile; import com.ctrip.framework.apollo.util.ConfigUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** + * The default implementation of {@link ConfigFactory}. + *

+ * Supports namespaces of format: + *

    + *
  • {@link ConfigFileFormat#Properties}
  • + *
  • {@link ConfigFileFormat#XML}
  • + *
  • {@link ConfigFileFormat#JSON}
  • + *
  • {@link ConfigFileFormat#YML}
  • + *
  • {@link ConfigFileFormat#YAML}
  • + *
  • {@link ConfigFileFormat#TXT}
  • + *
+ * * @author Jason Song(song_s@ctrip.com) + * @author Diego Krupitza(info@diegokrupitza.com) */ public class DefaultConfigFactory implements ConfigFactory { + private static final Logger logger = LoggerFactory.getLogger(DefaultConfigFactory.class); private final ConfigUtil m_configUtil; @@ -52,10 +65,24 @@ public DefaultConfigFactory() { @Override public Config create(String namespace) { ConfigFileFormat format = determineFileFormat(namespace); - if (ConfigFileFormat.isPropertiesCompatible(format)) { - return this.createRepositoryConfig(namespace, createPropertiesCompatibleFileConfigRepository(namespace, format)); + + ConfigRepository configRepository = null; + + // although ConfigFileFormat.Properties are compatible with themselves we + // should not create a PropertiesCompatibleFileConfigRepository for them + // calling the method `createLocalConfigRepository(...)` is more suitable + // for ConfigFileFormat.Properties + if (ConfigFileFormat.isPropertiesCompatible(format) && + format != ConfigFileFormat.Properties) { + configRepository = createPropertiesCompatibleFileConfigRepository(namespace, format); + } else { + configRepository = createConfigRepository(namespace); } - return this.createRepositoryConfig(namespace, createLocalConfigRepository(namespace)); + + logger.debug("Created a configuration repository of type [{}] for namespace [{}]", + configRepository.getClass().getName(), namespace); + + return this.createRepositoryConfig(namespace, configRepository); } protected Config createRepositoryConfig(String namespace, ConfigRepository configRepository) { @@ -64,7 +91,7 @@ protected Config createRepositoryConfig(String namespace, ConfigRepository confi @Override public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat) { - ConfigRepository configRepository = createLocalConfigRepository(namespace); + ConfigRepository configRepository = createConfigRepository(namespace); switch (configFileFormat) { case Properties: return new PropertiesConfigFile(namespace, configRepository); @@ -83,6 +110,19 @@ public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFile return null; } + ConfigRepository createConfigRepository(String namespace) { + if (m_configUtil.isPropertyFileCacheEnabled()) { + return createLocalConfigRepository(namespace); + } + return createRemoteConfigRepository(namespace); + } + + /** + * Creates a local repository for a given namespace + * + * @param namespace the namespace of the repository + * @return the newly created repository for the given namespace + */ LocalFileConfigRepository createLocalConfigRepository(String namespace) { if (m_configUtil.isInLocalMode()) { logger.warn( @@ -97,8 +137,8 @@ RemoteConfigRepository createRemoteConfigRepository(String namespace) { return new RemoteConfigRepository(namespace); } - PropertiesCompatibleFileConfigRepository createPropertiesCompatibleFileConfigRepository(String namespace, - ConfigFileFormat format) { + PropertiesCompatibleFileConfigRepository createPropertiesCompatibleFileConfigRepository( + String namespace, ConfigFileFormat format) { String actualNamespaceName = trimNamespaceFormat(namespace, format); PropertiesCompatibleConfigFile configFile = (PropertiesCompatibleConfigFile) ConfigService .getConfigFile(actualNamespaceName, format); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManager.java index 2a4867e73d6..b57a89b5dea 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactoryManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistry.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistry.java index 8e5cef2d187..02acc24cc51 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistry.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java index 556f19539df..3311daa8798 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfig.java index 6e361b73830..5b465ad1318 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigChangeListener.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigChangeListener.java index bf2b6656aff..85a2c4da800 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigChangeListener.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java index 52afd4e492c..3576026b17d 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloJsonValue.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloJsonValue.java index b8e804259d2..3e057f760ef 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloJsonValue.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloJsonValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloProcessor.java index d04e0284156..c745ffb5a80 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfig.java index 83e1f78e812..6b670945a5c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/EnableApolloConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/SpringValueProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/SpringValueProcessor.java index 8d4a0695710..860505423f3 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/SpringValueProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/SpringValueProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import com.google.common.collect.Multimap; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; +import java.lang.reflect.Member; import java.lang.reflect.Method; import java.util.Collection; import java.util.Set; @@ -46,7 +47,7 @@ /** * Spring value processor of field or method which has @Value and xml config placeholders. * - * @author github.com/zhegexiaohuozi seimimaster@gmail.com + * @author github.com/zhegexiaohuozi seimimaster@gmail.com mghio.dev@gmail.com * @since 2017/12/20. */ public class SpringValueProcessor extends ApolloProcessor implements BeanFactoryPostProcessor, BeanFactoryAware { @@ -94,17 +95,8 @@ protected void processField(Object bean, String beanName, Field field) { if (value == null) { return; } - Set keys = placeholderHelper.extractPlaceholderKeys(value.value()); - if (keys.isEmpty()) { - return; - } - - for (String key : keys) { - SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, field, false); - springValueRegistry.register(beanFactory, key, springValue); - logger.debug("Monitoring {}", springValue); - } + doRegister(bean, beanName, field, value); } @Override @@ -124,20 +116,33 @@ protected void processMethod(Object bean, String beanName, Method method) { return; } - Set keys = placeholderHelper.extractPlaceholderKeys(value.value()); + doRegister(bean, beanName, method, value); + } + private void doRegister(Object bean, String beanName, Member member, Value value) { + Set keys = placeholderHelper.extractPlaceholderKeys(value.value()); if (keys.isEmpty()) { return; } for (String key : keys) { - SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, method, false); + SpringValue springValue; + if (member instanceof Field) { + Field field = (Field) member; + springValue = new SpringValue(key, value.value(), bean, beanName, field, false); + } else if (member instanceof Method) { + Method method = (Method) member; + springValue = new SpringValue(key, value.value(), bean, beanName, method, false); + } else { + logger.error("Apollo @Value annotation currently only support to be used on methods and fields, " + + "but is used on {}", member.getClass()); + return; + } springValueRegistry.register(beanFactory, key, springValue); logger.info("Monitoring {}", springValue); } } - private void processBeanPropertyValues(Object bean, String beanName) { Collection propertySpringValues = beanName2SpringValueDefinitions .get(beanName); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java index 1726342ce82..a217d6762f8 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,6 +83,7 @@ public class ApolloApplicationContextInitializer implements private static final Splitter NAMESPACE_SPLITTER = Splitter.on(",").omitEmptyStrings() .trimResults(); public static final String[] APOLLO_SYSTEM_PROPERTIES = {ApolloClientSystemConsts.APP_ID, + ApolloClientSystemConsts.APOLLO_LABEL, ApolloClientSystemConsts.APOLLO_CLUSTER, ApolloClientSystemConsts.APOLLO_CACHE_DIR, ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET, diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloAutoConfiguration.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloAutoConfiguration.java index 7e05ca10c00..f0f5a0202a7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloAutoConfiguration.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/CachedCompositePropertySource.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/CachedCompositePropertySource.java index 022d94159f0..fc44459cb6b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/CachedCompositePropertySource.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/CachedCompositePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySource.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySource.java index e740e86b3e7..f2e913ae9d9 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySource.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourceFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourceFactory.java index 379c8519f07..2e13152f52f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourceFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java index 2c35202c09e..0ffce29b5c9 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/NamespaceHandler.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/NamespaceHandler.java index 9d2fb401c11..d82db9d913b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/NamespaceHandler.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/NamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesConstants.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesConstants.java index 4650ecb9eb6..05e0a11040b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesConstants.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesProcessor.java index 995cb33559c..c4eef96310b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/package-info.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/package-info.java index 87651b7854c..7eb42bb996c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/package-info.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/AutoUpdateConfigChangeListener.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/AutoUpdateConfigChangeListener.java index fc3da547ac0..ffeeefb3c36 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/AutoUpdateConfigChangeListener.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/AutoUpdateConfigChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/PlaceholderHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/PlaceholderHelper.java index 46db9965727..761e08a0030 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/PlaceholderHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/PlaceholderHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValue.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValue.java index 99628a49fb3..159d3b554b1 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValue.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinition.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinition.java index ad941ac8468..59a089b6a8b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinition.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java index ae5d4ffcbd3..df83a9c3552 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueDefinitionProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java index e5fdb1a4d19..f224c9fda66 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/property/SpringValueRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ApolloConfigRegistrarHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ApolloConfigRegistrarHelper.java index 918fdb896b5..826e73bcdab 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ApolloConfigRegistrarHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ApolloConfigRegistrarHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ConfigPropertySourcesProcessorHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ConfigPropertySourcesProcessorHelper.java index 8b21d1245ef..90d7075fb3a 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ConfigPropertySourcesProcessorHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/ConfigPropertySourcesProcessorHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java index 444c5aa4637..9214f444af7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultApolloConfigRegistrarHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ import com.google.common.collect.Lists; import java.util.HashMap; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.annotation.AnnotationAttributes; @@ -33,6 +35,8 @@ import org.springframework.core.type.AnnotationMetadata; public class DefaultApolloConfigRegistrarHelper implements ApolloConfigRegistrarHelper { + private static final Logger logger = LoggerFactory.getLogger( + DefaultApolloConfigRegistrarHelper.class); private Environment environment; @@ -62,6 +66,11 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B } private String[] resolveNamespaces(String[] namespaces) { + // no support for Spring version prior to 3.2.x, see https://github.com/apolloconfig/apollo/issues/4178 + if (this.environment == null) { + logNamespacePlaceholderNotSupportedMessage(namespaces); + return namespaces; + } String[] resolvedNamespaces = new String[namespaces.length]; for (int i = 0; i < namespaces.length; i++) { // throw IllegalArgumentException if given text is null or if any placeholders are unresolvable @@ -70,6 +79,17 @@ private String[] resolveNamespaces(String[] namespaces) { return resolvedNamespaces; } + private void logNamespacePlaceholderNotSupportedMessage(String[] namespaces) { + for (String namespace : namespaces) { + if (namespace.contains("${")) { + logger.warn("Namespace placeholder {} is not supported for Spring version prior to 3.2.x," + + " see https://github.com/apolloconfig/apollo/issues/4178 for more details.", + namespace); + break; + } + } + } + @Override public int getOrder() { return Ordered.LOWEST_PRECEDENCE; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java index befcf44d364..42e63e7c0f6 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/spi/DefaultConfigPropertySourcesProcessorHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java index 27b0cf5976d..079c366b63f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +18,27 @@ import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; -import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.type.MethodMetadata; /** * @author Jason Song(song_s@ctrip.com) */ public class BeanRegistrationUtil { + // reserved bean definitions, we should consider drop this if we will upgrade Spring version + private static final Map RESERVED_BEAN_DEFINITIONS = new ConcurrentHashMap<>(); + + static { + RESERVED_BEAN_DEFINITIONS.put( + "org.springframework.context.support.PropertySourcesPlaceholderConfigurer", + "org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer" + ); + } + public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName, Class beanClass) { return registerBeanDefinitionIfNotExists(registry, beanName, beanClass, null); @@ -41,17 +52,16 @@ public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry r String[] candidates = registry.getBeanDefinitionNames(); - if (registry instanceof BeanFactory) { - final BeanFactory beanFactory = (BeanFactory) registry; - for (String candidate : candidates) { - if (beanFactory.isTypeMatch(candidate, beanClass)) { - return false; - } + String reservedBeanDefinition = RESERVED_BEAN_DEFINITIONS.get(beanClass.getName()); + for (String candidate : candidates) { + BeanDefinition beanDefinition = registry.getBeanDefinition(candidate); + if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) { + return false; } - } else { - for (String candidate : candidates) { - BeanDefinition beanDefinition = registry.getBeanDefinition(candidate); - if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) { + + if (reservedBeanDefinition != null && beanDefinition.getSource() != null && beanDefinition.getSource() instanceof MethodMetadata) { + MethodMetadata metadata = (MethodMetadata) beanDefinition.getSource(); + if (Objects.equals(reservedBeanDefinition, String.format("%s#%s", metadata.getDeclaringClassName(), metadata.getMethodName()))) { return false; } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.java index 72adab00dff..098a01bd676 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java index d55bf334867..67e897c4c88 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,6 +57,7 @@ public class ConfigUtil { private final RateLimiter warnLogRateLimiter; private boolean propertiesOrdered = false; private boolean propertyNamesCacheEnabled = false; + private boolean propertyFileCacheEnabled = true; public ConfigUtil() { warnLogRateLimiter = RateLimiter.create(0.017); // 1 warning log output per minute @@ -70,6 +71,7 @@ public ConfigUtil() { initAutoUpdateInjectedSpringProperties(); initPropertiesOrdered(); initPropertyNamesCacheEnabled(); + initPropertyFileCacheEnabled(); } /** @@ -89,6 +91,15 @@ public String getAppId() { return appId; } + /** + * Get the apollo label for the current application. + * + * @return apollo Label + */ + public String getApolloLabel() { + return Foundation.app().getApolloLabel(); + } + /** * Get the access key secret for the current application. * @@ -401,23 +412,38 @@ public boolean isPropertyNamesCacheEnabled() { return propertyNamesCacheEnabled; } + public boolean isPropertyFileCacheEnabled() { + return propertyFileCacheEnabled; + } + private void initPropertyNamesCacheEnabled() { - String propertyName = ApolloClientSystemConsts.APOLLO_PROPERTY_NAMES_CACHE_ENABLE; - String propertyEnvName = ApolloClientSystemConsts.APOLLO_PROPERTY_NAMES_CACHE_ENABLE_ENVIRONMENT_VARIABLES; + propertyNamesCacheEnabled = getPropertyBoolean(ApolloClientSystemConsts.APOLLO_PROPERTY_NAMES_CACHE_ENABLE, + ApolloClientSystemConsts.APOLLO_PROPERTY_NAMES_CACHE_ENABLE_ENVIRONMENT_VARIABLES, + propertyNamesCacheEnabled); + } + + private void initPropertyFileCacheEnabled() { + propertyFileCacheEnabled = getPropertyBoolean(ApolloClientSystemConsts.APOLLO_CACHE_FILE_ENABLE, + ApolloClientSystemConsts.APOLLO_CACHE_FILE_ENABLE_ENVIRONMENT_VARIABLES, + propertyFileCacheEnabled); + } + + private boolean getPropertyBoolean(String propertyName, String envName, boolean defaultVal) { String enablePropertyNamesCache = System.getProperty(propertyName); if (Strings.isNullOrEmpty(enablePropertyNamesCache)) { - enablePropertyNamesCache = System.getenv(propertyEnvName); + enablePropertyNamesCache = System.getenv(envName); } if (Strings.isNullOrEmpty(enablePropertyNamesCache)) { - enablePropertyNamesCache = Foundation.app().getProperty(propertyName, "false"); + enablePropertyNamesCache = Foundation.app().getProperty(propertyName, null); } if (!Strings.isNullOrEmpty(enablePropertyNamesCache)) { try { - propertyNamesCacheEnabled = Boolean.parseBoolean(enablePropertyNamesCache); + return Boolean.parseBoolean(enablePropertyNamesCache); } catch (Throwable ex) { - logger.warn("Config for {} is invalid: {}, set default value: false", - propertyName, enablePropertyNamesCache); + logger.warn("Config for {} is invalid: {}, set default value: {}", + propertyName, enablePropertyNamesCache, defaultVal); } } + return defaultVal; } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java index 4d1e5616da5..0a179d977ec 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ExceptionUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/OrderedProperties.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/OrderedProperties.java index e4a534db89c..4fc0e0da4d7 100755 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/OrderedProperties.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/OrderedProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/DefaultPropertiesFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/DefaultPropertiesFactory.java index 7d44d51e2a9..a2c2e2b37da 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/DefaultPropertiesFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/DefaultPropertiesFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/PropertiesFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/PropertiesFactory.java index a74d58e5cf4..316b902c73f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/PropertiesFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/factory/PropertiesFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/function/Functions.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/function/Functions.java index 12b4c490c60..8f6d0c80bb1 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/function/Functions.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/function/Functions.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java index 4530e5388f7..5d5fb40ed0f 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/DefaultHttpClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpClient.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpClient.java index 205dc82f56c..852fcda489e 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpClient.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java index eb3d87f1fc8..aeac6326fab 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpResponse.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpResponse.java index 1650ed6194d..85374c4cfdc 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpResponse.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java index 7d69218a944..60ef11e3c59 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/http/HttpUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/ParserException.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/ParserException.java index 4eb5b10b676..cb49f73f911 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/ParserException.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/ParserException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/Parsers.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/Parsers.java index 1eaa43262e7..b6c1dae1184 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/Parsers.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/parser/Parsers.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java index 25eae814001..5b98233ff7b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/yaml/YamlParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,22 +18,23 @@ import com.ctrip.framework.apollo.build.ApolloInjector; import com.ctrip.framework.apollo.util.factory.PropertiesFactory; -import java.util.AbstractMap; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.parser.ParserException; import com.ctrip.framework.apollo.core.utils.StringUtils; +import org.yaml.snakeyaml.representer.Representer; /** * Transplanted from org.springframework.beans.factory.config.YamlProcessor since apollo can't depend on Spring directly @@ -64,7 +65,9 @@ public void process(Properties properties, Map map) { * Create the {@link Yaml} instance to use. */ private Yaml createYaml() { - return new Yaml(new StrictMapAppenderConstructor()); + LoaderOptions loadingConfig = new LoaderOptions(); + loadingConfig.setAllowDuplicateKeys(false); + return new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), loadingConfig); } private boolean process(MatchCallback callback, Yaml yaml, String content) { @@ -163,43 +166,4 @@ private interface MatchCallback { void process(Properties properties, Map map); } - /** - * A specialized {@link SafeConstructor} that checks for duplicate keys. - */ - private static class StrictMapAppenderConstructor extends SafeConstructor { - - // Declared as public for use in subclasses - StrictMapAppenderConstructor() { - super(); - } - - @Override - protected Map constructMapping(MappingNode node) { - try { - return super.constructMapping(node); - } catch (IllegalStateException ex) { - throw new ParserException("while parsing MappingNode", node.getStartMark(), ex.getMessage(), node.getEndMark()); - } - } - - @Override - protected Map createDefaultMap() { - final Map delegate = super.createDefaultMap(); - return new AbstractMap() { - @Override - public Object put(Object key, Object value) { - if (delegate.containsKey(key)) { - throw new IllegalStateException("Duplicate key: " + key); - } - return delegate.put(key, value); - } - - @Override - public Set> entrySet() { - return delegate.entrySet(); - } - }; - } - } - } diff --git a/apollo-client/src/main/resources/META-INF/apollo-1.0.0.xsd b/apollo-client/src/main/resources/META-INF/apollo-1.0.0.xsd index 7a6e3eaa681..f9fc6a1126e 100644 --- a/apollo-client/src/main/resources/META-INF/apollo-1.0.0.xsd +++ b/apollo-client/src/main/resources/META-INF/apollo-1.0.0.xsd @@ -1,6 +1,6 @@ diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java index ab86759ee5f..c3194c6cf74 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/ApolloCommonConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/aop/RepositoryAspect.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/aop/RepositoryAspect.java index 16469e703b7..d372bc54524 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/aop/RepositoryAspect.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/aop/RepositoryAspect.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnMissingProfile.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnMissingProfile.java index 3ab3d5f24b5..d9b3a6deb0d 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnMissingProfile.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnMissingProfile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnProfile.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnProfile.java index c2c41a9443c..d01d752fece 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnProfile.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/ConditionalOnProfile.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/OnProfileCondition.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/OnProfileCondition.java index ea61734f02e..63a09bdf7e4 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/OnProfileCondition.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/condition/OnProfileCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java index 73e1a81a7b3..3138a21e9e8 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshablePropertySource.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshablePropertySource.java index 01b790f2873..dd2daef732e 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshablePropertySource.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshablePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/GsonType.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/GsonType.java index 3bbbc3b0b08..c0e317c145f 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/GsonType.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/GsonType.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.google.gson.reflect.TypeToken; import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleItemDTO; +import com.ctrip.framework.apollo.common.dto.ItemDTO; import java.lang.reflect.Type; import java.util.List; @@ -30,4 +31,5 @@ public interface GsonType { Type RULE_ITEMS = new TypeToken>() {}.getType(); + Type ITEM_DTOS = new TypeToken>(){}.getType(); } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/NamespaceBranchStatus.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/NamespaceBranchStatus.java index 86283e0a038..2f29b205300 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/NamespaceBranchStatus.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/NamespaceBranchStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperation.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperation.java index c14474c699f..3487705d925 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperation.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperationContext.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperationContext.java index 6008192c5fd..42e352ee86a 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperationContext.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java index 75c79135f17..12eb95423b9 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/ApolloInfoController.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/CharacterEncodingFilterConfiguration.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/CharacterEncodingFilterConfiguration.java index b0588a3e079..6de7605c822 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/CharacterEncodingFilterConfiguration.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/CharacterEncodingFilterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java index 88541beef61..4ec03b69171 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/HttpMessageConverterConfiguration.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/HttpMessageConverterConfiguration.java index 2b0c290530c..16a468b7fd4 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/HttpMessageConverterConfiguration.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/HttpMessageConverterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/WebMvcConfig.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/WebMvcConfig.java index bdf8ded7a98..20c91f15a08 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/WebMvcConfig.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/WebMvcConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/LoggingCustomizer.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/LoggingCustomizer.java index 412f889681f..6e2143206ec 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/LoggingCustomizer.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/LoggingCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/package-info.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/package-info.java index 4b09d56afd3..b33a1c6c590 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/package-info.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/customize/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java index 7b6f8243e05..3480b400dcc 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java index 61129ed6cec..c98523c356d 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanEntityManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanSettings.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanSettings.java index 0a842c8b24d..2d349f6fe77 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanSettings.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/TitanSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/package-info.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/package-info.java index 142b4bd6249..9f82db27ed2 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/package-info.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AccessKeyDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AccessKeyDTO.java index 567230ea4dc..b75b45d79a6 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AccessKeyDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AccessKeyDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppDTO.java index 515b0a273e0..b603d82cdcc 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppNamespaceDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppNamespaceDTO.java index 83a5070bb0a..a59bd3acf08 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppNamespaceDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/AppNamespaceDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/BaseDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/BaseDTO.java index 6535f37b929..80bee1429d4 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/BaseDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/BaseDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ClusterDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ClusterDTO.java index 0bd77ab3e3a..58e5ca092be 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ClusterDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ClusterDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/CommitDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/CommitDTO.java index b2c780a363b..073ca0aadd2 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/CommitDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/CommitDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleDTO.java index b6a23f5a48f..d093d5f7d47 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java index c2d973d151d..ee419eae899 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,17 +27,20 @@ */ public class GrayReleaseRuleItemDTO { public static final String ALL_IP = "*"; + public static final String ALL_Label = "*"; private String clientAppId; private Set clientIpList; + private Set clientLabelList; public GrayReleaseRuleItemDTO(String clientAppId) { - this(clientAppId, Sets.newHashSet()); + this(clientAppId, Sets.newHashSet(), Sets.newHashSet()); } - public GrayReleaseRuleItemDTO(String clientAppId, Set clientIpList) { + public GrayReleaseRuleItemDTO(String clientAppId, Set clientIpList, Set clientLabelList) { this.clientAppId = clientAppId; this.clientIpList = clientIpList; + this.clientLabelList = clientLabelList; } public String getClientAppId() { @@ -48,8 +51,12 @@ public Set getClientIpList() { return clientIpList; } - public boolean matches(String clientAppId, String clientIp) { - return appIdMatches(clientAppId) && ipMatches(clientIp); + public Set getClientLabelList() { + return clientLabelList; + } + + public boolean matches(String clientAppId, String clientIp,String clientLabel) { + return (appIdMatches(clientAppId) && ipMatches(clientIp))||(appIdMatches(clientAppId) && labelMatches(clientLabel)); } private boolean appIdMatches(String clientAppId) { @@ -60,9 +67,14 @@ private boolean ipMatches(String clientIp) { return this.clientIpList.contains(ALL_IP) || clientIpList.contains(clientIp); } + private boolean labelMatches(String clientLabel) { + return this.clientLabelList.contains(ALL_Label) || clientLabelList.contains(clientLabel); + } + @Override public String toString() { return toStringHelper(this).add("clientAppId", clientAppId) - .add("clientIpList", clientIpList).toString(); + .add("clientIpList", clientIpList) + .add("clientLabelList", clientLabelList).toString(); } } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceConfigDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceConfigDTO.java index c6e84f132cc..04e0312701a 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceConfigDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceConfigDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceDTO.java index b41b36636c7..779dcd61593 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/InstanceDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemChangeSets.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemChangeSets.java index 76ff8628eec..3656a1886d3 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemChangeSets.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemChangeSets.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemDTO.java index 872f8ab4552..417ba29614f 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ItemDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceDTO.java index 8a894f334a0..ea4c91b9c64 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceLockDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceLockDTO.java index f8be3358fdf..7acffd38ce1 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceLockDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/NamespaceLockDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/PageDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/PageDTO.java index 2e1d2ead848..a679a7f6f28 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/PageDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/PageDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseDTO.java index 63d7c86454f..25f390afff7 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseHistoryDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseHistoryDTO.java index 9f121741de5..bc48b05a790 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseHistoryDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/ReleaseHistoryDTO.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java index f98c1f4eb00..57c45671964 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ @Entity @Table(name = "App") -@SQLDelete(sql = "Update App set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update App set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class App extends BaseEntity { diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java index 16804f433ae..085f2e544cf 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ @Entity @Table(name = "AppNamespace") -@SQLDelete(sql = "Update AppNamespace set isDeleted = 1 where id = ?") +@SQLDelete(sql = "Update AppNamespace set IsDeleted = 1, DeletedAt = ROUND(UNIX_TIMESTAMP(NOW(4))*1000) where Id = ?") @Where(clause = "isDeleted = 0") public class AppNamespace extends BaseEntity { diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java index 680114c5c60..aba375906c4 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; +import java.time.Instant; import java.util.Date; import javax.persistence.Column; @@ -44,6 +45,9 @@ public abstract class BaseEntity { @Column(name = "IsDeleted", columnDefinition = "Bit default '0'") protected boolean isDeleted = false; + @Column(name = "DeletedAt", columnDefinition = "Bigint default '0'") + protected long deletedAt; + @Column(name = "DataChange_CreatedBy", nullable = false) private String dataChangeCreatedBy; @@ -56,52 +60,62 @@ public abstract class BaseEntity { @Column(name = "DataChange_LastTime") private Date dataChangeLastModifiedTime; - public String getDataChangeCreatedBy() { - return dataChangeCreatedBy; + public long getId() { + return id; } - public Date getDataChangeCreatedTime() { - return dataChangeCreatedTime; + public void setId(long id) { + this.id = id; } - public String getDataChangeLastModifiedBy() { - return dataChangeLastModifiedBy; + public boolean isDeleted() { + return isDeleted; } - public Date getDataChangeLastModifiedTime() { - return dataChangeLastModifiedTime; + public void setDeleted(boolean deleted) { + isDeleted = deleted; + // also set deletedAt value as epoch millisecond + this.deletedAt = System.currentTimeMillis(); } - public long getId() { - return id; + public long getDeletedAt() { + return deletedAt; } - public boolean isDeleted() { - return isDeleted; + public void setDeletedAt(long deletedAt) { + this.deletedAt = deletedAt; + } + + public String getDataChangeCreatedBy() { + return dataChangeCreatedBy; } public void setDataChangeCreatedBy(String dataChangeCreatedBy) { this.dataChangeCreatedBy = dataChangeCreatedBy; } + public Date getDataChangeCreatedTime() { + return dataChangeCreatedTime; + } + public void setDataChangeCreatedTime(Date dataChangeCreatedTime) { this.dataChangeCreatedTime = dataChangeCreatedTime; } - public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) { - this.dataChangeLastModifiedBy = dataChangeLastModifiedBy; + public String getDataChangeLastModifiedBy() { + return dataChangeLastModifiedBy; } - public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) { - this.dataChangeLastModifiedTime = dataChangeLastModifiedTime; + public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) { + this.dataChangeLastModifiedBy = dataChangeLastModifiedBy; } - public void setDeleted(boolean deleted) { - isDeleted = deleted; + public Date getDataChangeLastModifiedTime() { + return dataChangeLastModifiedTime; } - public void setId(long id) { - this.id = id; + public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) { + this.dataChangeLastModifiedTime = dataChangeLastModifiedTime; } @PrePersist diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/EntityPair.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/EntityPair.java index 7027352f006..b66cff29e2e 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/EntityPair.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/EntityPair.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java index 147b16cd8a7..c91557ca0c2 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ */ package com.ctrip.framework.apollo.common.exception; +import com.google.common.base.Strings; import org.springframework.http.HttpStatus; public abstract class AbstractApolloHttpException extends RuntimeException{ @@ -24,8 +25,15 @@ public abstract class AbstractApolloHttpException extends RuntimeException{ protected HttpStatus httpStatus; - public AbstractApolloHttpException(String msg){ - super(msg); + /** + * When args not empty, use {@link com.google.common.base.Strings#lenientFormat(String, Object...)} + * to replace %s in msgtpl with args to set the error message. Otherwise, use msgtpl + * to set the error message. e.g.: + *
{@code new NotFoundException("... %s ... %s ... %s", "str", 0, 0.1)}
+ * If the number of '%s' in `msgtpl` does not match args length, the '%s' string will be printed. + */ + public AbstractApolloHttpException(String msgtpl, Object... args){ + super(args == null || args.length == 0 ? msgtpl : Strings.lenientFormat(msgtpl, args)); } public AbstractApolloHttpException(String msg, Exception e){ diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BadRequestException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BadRequestException.java index b9754e53d3c..07cb910b1b3 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BadRequestException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BadRequestException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,12 @@ public class BadRequestException extends AbstractApolloHttpException { - - public BadRequestException(String str) { - super(str); + /** + * @see AbstractApolloHttpException#AbstractApolloHttpException(String, Object...) + */ + public BadRequestException(String msgtpl, Object... args) { + super(msgtpl, args); setHttpStatus(HttpStatus.BAD_REQUEST); } + } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BeanUtilsException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BeanUtilsException.java index 15bbc08585b..0a877fa54de 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BeanUtilsException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/BeanUtilsException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java index 5a900514f28..c05288790fb 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,11 @@ public class NotFoundException extends AbstractApolloHttpException { - - public NotFoundException(String str) { - super(str); + /** + * @see AbstractApolloHttpException#AbstractApolloHttpException(String, Object...) + */ + public NotFoundException(String msgtpl, Object... args) { + super(msgtpl, args); setHttpStatus(HttpStatus.NOT_FOUND); } } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/ServiceException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/ServiceException.java index b35ccd0a3a6..ee49e6bc4c1 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/ServiceException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/ServiceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,11 @@ public class ServiceException extends AbstractApolloHttpException { - public ServiceException(String str) { - super(str); + /** + * @see AbstractApolloHttpException#AbstractApolloHttpException(String, Object...) + */ + public ServiceException(String msgtpl, Object... args) { + super(msgtpl, args); setHttpStatus(HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/MultiResponseEntity.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/MultiResponseEntity.java index ae864b86523..464f55ec758 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/MultiResponseEntity.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/MultiResponseEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/RichResponseEntity.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/RichResponseEntity.java index 770fcb9821c..a0b19dbe403 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/RichResponseEntity.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/http/RichResponseEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/H2Function.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/H2Function.java new file mode 100644 index 00000000000..2ca988a40b4 --- /dev/null +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/H2Function.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022 Apollo 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. + * + */ +package com.ctrip.framework.apollo.common.jpa; + +/** + * @author nisiyong + */ +public class H2Function { + + public static long unixTimestamp(java.sql.Timestamp timestamp) { + return timestamp.getTime() / 1000L; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripSsoHeartbeatHandler.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/SqlFunctionsMetadataBuilderContributor.java similarity index 50% rename from apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripSsoHeartbeatHandler.java rename to apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/SqlFunctionsMetadataBuilderContributor.java index c02dcb2e8fb..823faac65be 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripSsoHeartbeatHandler.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/SqlFunctionsMetadataBuilderContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,21 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.portal.spi.ctrip; +package com.ctrip.framework.apollo.common.jpa; -import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler; - -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import org.hibernate.boot.MetadataBuilder; +import org.hibernate.boot.spi.MetadataBuilderContributor; +import org.hibernate.dialect.function.StandardSQLFunction; +import org.hibernate.type.StandardBasicTypes; /** - * @author Jason Song(song_s@ctrip.com) + * @author nisiyong */ -public class CtripSsoHeartbeatHandler implements SsoHeartbeatHandler { +public class SqlFunctionsMetadataBuilderContributor implements MetadataBuilderContributor { @Override - public void doHeartbeat(HttpServletRequest request, HttpServletResponse response) { - try { - response.sendRedirect("ctrip_sso_heartbeat.html"); - } catch (IOException e) { - } + public void contribute(MetadataBuilder metadataBuilder) { + metadataBuilder.applySqlFunction("NOW", + new StandardSQLFunction("NOW", StandardBasicTypes.INTEGER)); } - } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java index b20fc613b16..65331c75459 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/ExceptionUtils.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/ExceptionUtils.java index 5fed1756ea3..19127d3ad3c 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/ExceptionUtils.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/ExceptionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/GrayReleaseRuleItemTransformer.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/GrayReleaseRuleItemTransformer.java index 95c9440a63f..28383df8130 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/GrayReleaseRuleItemTransformer.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/GrayReleaseRuleItemTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/InputValidator.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/InputValidator.java index 1992f1f2cbf..b5d2e72cbbf 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/InputValidator.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/InputValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/RequestPrecondition.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/RequestPrecondition.java index 155ca806608..5b98b76c5aa 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/RequestPrecondition.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/RequestPrecondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java index e78d21377c1..f914c7bb490 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/UniqueKeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,10 @@ */ package com.ctrip.framework.apollo.common.utils; -import com.google.common.base.Joiner; - import com.ctrip.framework.apollo.core.utils.ByteUtil; import com.ctrip.framework.apollo.core.utils.MachineUtil; - -import org.apache.commons.lang.time.FastDateFormat; +import com.google.common.base.Joiner; +import org.apache.commons.lang3.time.FastDateFormat; import java.security.SecureRandom; import java.util.Date; @@ -34,8 +32,6 @@ public class UniqueKeyGenerator { private static final AtomicInteger counter = new AtomicInteger(new SecureRandom().nextInt()); private static final Joiner KEY_JOINER = Joiner.on("-"); - - public static String generate(Object... args){ String hexIdString = ByteUtil.toHexString(toByteArray(Objects.hash(args), MachineUtil.getMachineIdentifier(), diff --git a/apollo-common/src/main/resources/application-ctrip.properties b/apollo-common/src/main/resources/application-ctrip.properties index 863b2c40925..bba2d70797f 100644 --- a/apollo-common/src/main/resources/application-ctrip.properties +++ b/apollo-common/src/main/resources/application-ctrip.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/resources/application-github.properties b/apollo-common/src/main/resources/application-github.properties index b354b40c406..40501fa989a 100644 --- a/apollo-common/src/main/resources/application-github.properties +++ b/apollo-common/src/main/resources/application-github.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/resources/application.properties b/apollo-common/src/main/resources/application.properties index 3ad3e837acc..5aa63e48675 100644 --- a/apollo-common/src/main/resources/application.properties +++ b/apollo-common/src/main/resources/application.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-common/src/main/resources/datasource.xml b/apollo-common/src/main/resources/datasource.xml index a2795765f41..82b9ca959e9 100644 --- a/apollo-common/src/main/resources/datasource.xml +++ b/apollo-common/src/main/resources/datasource.xml @@ -1,5 +1,5 @@ org.springframework.cloud spring-cloud-context - - org.apache.logging.log4j - log4j-core - - - org.apache.logging.log4j - log4j-api - - - org.apache.logging.log4j - log4j-slf4j-impl - org.slf4j diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/ApolloConfigDemo.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/ApolloConfigDemo.java index a6480db5432..6413fb0a52b 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/ApolloConfigDemo.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/ApolloConfigDemo.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/SimpleApolloConfigDemo.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/SimpleApolloConfigDemo.java index 2bd8c5ef96f..39415c910e5 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/SimpleApolloConfigDemo.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/SimpleApolloConfigDemo.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/AnnotatedBean.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/AnnotatedBean.java index 5fe6f21bd0b..c2ff015b34d 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/AnnotatedBean.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/AnnotatedBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AnotherAppConfig.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AnotherAppConfig.java index abeb9a2d869..785de5dd4b5 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AnotherAppConfig.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AnotherAppConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java index c0828f1f76e..659d1c4c551 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java index 60f4d504b89..0edf9d5e404 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/AnnotationApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java index 81a4f57fe1f..fabe7636b26 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java index 6b553537642..60857a18795 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java index 8e39f3cfeae..9b7c5cad0e2 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java index 333d1aa17ab..ca7dbdc3925 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/XmlApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/bean/XmlBean.java b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/bean/XmlBean.java index e987183d8e0..d29c50f0810 100644 --- a/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/bean/XmlBean.java +++ b/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/xmlConfigDemo/bean/XmlBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/resources/META-INF/app.properties b/apollo-demo/src/main/resources/META-INF/app.properties index aabe341d033..20f5e24af6f 100644 --- a/apollo-demo/src/main/resources/META-INF/app.properties +++ b/apollo-demo/src/main/resources/META-INF/app.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,3 +15,4 @@ # # test app.id=100004458 +apollo.label=myLabel \ No newline at end of file diff --git a/apollo-demo/src/main/resources/application.yml b/apollo-demo/src/main/resources/application.yml index bc72e6cde76..c5b4492806d 100644 --- a/apollo-demo/src/main/resources/application.yml +++ b/apollo-demo/src/main/resources/application.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-demo/src/main/resources/log4j2.xml b/apollo-demo/src/main/resources/log4j2.xml deleted file mode 100644 index 39c985375a7..00000000000 --- a/apollo-demo/src/main/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/apollo-demo/src/main/resources/logback.xml b/apollo-demo/src/main/resources/logback.xml new file mode 100644 index 00000000000..99476e81200 --- /dev/null +++ b/apollo-demo/src/main/resources/logback.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + diff --git a/apollo-demo/src/main/resources/spring.xml b/apollo-demo/src/main/resources/spring.xml index 8ac088a0ad3..bc0dab2019a 100644 --- a/apollo-demo/src/main/resources/spring.xml +++ b/apollo-demo/src/main/resources/spring.xml @@ -1,6 +1,6 @@ app.metadata + * -------------------------------------------> List * - * @param zipOutputStream zip file output stream - * @param configBO a namespace represent - * @return zip file output stream same as parameter zipOutputStream + * @param outputStream network file download stream to user */ - private static ZipOutputStream write2ZipOutputStream( - final ZipOutputStream zipOutputStream, final ConfigBO configBO) throws IOException { - final Env env = configBO.getEnv(); - final String ownerName = configBO.getOwnerName(); - final String appId = configBO.getAppId(); - final String clusterName = configBO.getClusterName(); - final String namespace = configBO.getNamespace(); - final String configFileContent = configBO.getConfigFileContent(); - final ConfigFileFormat configFileFormat = configBO.getFormat(); - final String configFilename = - ConfigFileUtils.toFilename(appId, clusterName, namespace, configFileFormat); - final String filePath = ConfigFileUtils.toFilePath(ownerName, appId, env, configFilename); - final ZipEntry zipEntry = new ZipEntry(filePath); - try { - zipOutputStream.putNextEntry(zipEntry); - zipOutputStream.write(configFileContent.getBytes()); - zipOutputStream.closeEntry(); - } catch (IOException e) { - logger.error("config export failed. {}", configBO); - throw new IOException("config export failed", e); + public void exportData(OutputStream outputStream, List exportEnvs) { + if (CollectionUtils.isEmpty(exportEnvs)) { + exportEnvs = portalSettings.getActiveEnvs(); } - return zipOutputStream; - } - /** @return the namespaces current user exists */ - private Stream makeStreamBy( - final Env env, final String ownerName, final String appId, final String clusterName) { - final List namespaceBOS = - namespaceService.findNamespaceBOs(appId, env, clusterName); - final Function function = - namespaceBO -> new ConfigBO(env, ownerName, appId, clusterName, namespaceBO); - return namespaceBOS.parallelStream().map(function); + exportApps(exportEnvs, outputStream); } - private Stream makeStreamBy(final Env env, final String ownerName, final String appId) { - final List clusterDTOS = clusterService.findClusters(env, appId); - final Function> function = - clusterDTO -> this.makeStreamBy(env, ownerName, appId, clusterDTO.getName()); - return clusterDTOS.parallelStream().flatMap(function); - } + private void exportApps(final Collection exportEnvs, OutputStream outputStream) { + List hasPermissionApps = findHasPermissionApps(); + + if (CollectionUtils.isEmpty(hasPermissionApps)) { + return; + } - private Stream makeStreamBy(final Env env, final List apps) { - final Function> function = - app -> this.makeStreamBy(env, app.getOwnerName(), app.getAppId()); + try (final ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) { + //write app info to zip + writeAppInfoToZip(hasPermissionApps, zipOutputStream); + + //export app namespace + exportAppNamespaces(zipOutputStream); - return apps.parallelStream().flatMap(function); + //export app's clusters + exportEnvs.parallelStream().forEach(env -> { + try { + this.exportClusters(env, hasPermissionApps, zipOutputStream); + } catch (Exception e) { + logger.error("export cluster error. env = {}", env, e); + } + }); + } catch (IOException e) { + logger.error("export config error", e); + throw new ServiceException("export config error", e); + } } - private Stream makeStreamBy(final Collection envs) { + private List findHasPermissionApps() { // get all apps final List apps = appService.findAll(); + if (CollectionUtils.isEmpty(apps)) { + return Collections.emptyList(); + } + // permission check final Predicate isAppAdmin = app -> { try { return permissionValidator.isAppAdmin(app.getAppId()); } catch (Exception e) { - logger.error("app = {}", app); - logger.error(app.getAppId()); + logger.error("permission check failed. app = {}", app); + return false; } - return false; }; // app admin permission filter - final List appsExistPermission = - apps.stream().filter(isAppAdmin).collect(Collectors.toList()); - return envs.parallelStream().flatMap(env -> this.makeStreamBy(env, appsExistPermission)); + return apps.stream().filter(isAppAdmin).collect(Collectors.toList()); } - /** - * Export all projects which current user own them. Permission check by {@link - * PermissionValidator#isAppAdmin(java.lang.String)} - * - * @param outputStream network file download stream to user - * @throws IOException if happen write problem - */ - public void exportAllTo(OutputStream outputStream) throws IOException { - final List activeEnvs = portalSettings.getActiveEnvs(); - final Stream configBOStream = this.makeStreamBy(activeEnvs); - writeAsZipOutputStream(configBOStream, outputStream); + private void writeAppInfoToZip(List apps, ZipOutputStream zipOutputStream) { + logger.info("to import app size = {}", apps.size()); + + final Consumer appConsumer = + app -> { + try { + synchronized (zipOutputStream) { + String fileName = ConfigFileUtils.genAppInfoPath(app); + String content = gson.toJson(app); + + writeToZip(fileName, content, zipOutputStream); + } + } catch (IOException e) { + logger.error("Write error. {}", app); + throw new ServiceException("Write app error. {}", e); + } + }; + + apps.forEach(appConsumer); } + + private void exportAppNamespaces(ZipOutputStream zipOutputStream) { + List appNamespaces = appNamespaceService.findAll(); + + logger.info("to import appnamespace size = " + appNamespaces.size()); + + Consumer appNamespaceConsumer = appNamespace -> { + try { + synchronized (zipOutputStream) { + String fileName = ConfigFileUtils.genAppNamespaceInfoPath(appNamespace); + String content = gson.toJson(appNamespace); + + writeToZip(fileName, content, zipOutputStream); + } + } catch (Exception e) { + logger.error("Write appnamespace error. {}", appNamespace); + throw new IllegalStateException(e); + } + }; + + appNamespaces.forEach(appNamespaceConsumer); + + } + + private void exportClusters(final Env env, final List exportApps, ZipOutputStream zipOutputStream) { + exportApps.parallelStream().forEach(exportApp -> { + try { + this.exportCluster(env, exportApp, zipOutputStream); + } catch (Exception e) { + logger.error("export cluster error. appId = {}", exportApp.getAppId(), e); + } + }); + } + + private void exportCluster(final Env env, final App exportApp, ZipOutputStream zipOutputStream) { + final List exportClusters = clusterService.findClusters(env, exportApp.getAppId()); + + if (CollectionUtils.isEmpty(exportClusters)) { + return; + } + + //write cluster info to zip + writeClusterInfoToZip(env, exportApp, exportClusters, zipOutputStream); + + //export namespaces + exportClusters.parallelStream().forEach(cluster -> { + try { + this.exportNamespaces(env, exportApp, cluster, zipOutputStream); + } catch (BadRequestException badRequestException) { + //ignore + } catch (Exception e) { + logger.error("export namespace error. appId = {}, cluster = {}", exportApp.getAppId(), cluster, e); + } + }); + } + + private void exportNamespaces(final Env env, final App exportApp, final ClusterDTO exportCluster, + ZipOutputStream zipOutputStream) { + String clusterName = exportCluster.getName(); + + List namespaceBOS = namespaceService.findNamespaceBOs(exportApp.getAppId(), env, clusterName); + + if (CollectionUtils.isEmpty(namespaceBOS)) { + return; + } + + Stream configBOStream = namespaceBOS.stream() + .map( + namespaceBO -> new ConfigBO(env, exportApp.getOwnerName(), exportApp.getAppId(), clusterName, namespaceBO)); + + writeNamespacesToZip(configBOStream, zipOutputStream); + } + + private void writeNamespacesToZip(Stream configBOStream, ZipOutputStream zipOutputStream) { + final Consumer configBOConsumer = + configBO -> { + try { + synchronized (zipOutputStream) { + String appId = configBO.getAppId(); + String clusterName = configBO.getClusterName(); + String namespace = configBO.getNamespace(); + String configFileContent = configBO.getConfigFileContent(); + ConfigFileFormat configFileFormat = configBO.getFormat(); + + String + configFileName = + ConfigFileUtils.toFilename(appId, clusterName, namespace, configFileFormat); + String filePath = + ConfigFileUtils.genNamespacePath(configBO.getOwnerName(), appId, configBO.getEnv(), configFileName); + + writeToZip(filePath, configFileContent, zipOutputStream); + } + } catch (IOException e) { + logger.error("Write error. {}", configBO); + throw new ServiceException("Write namespace error. {}", e); + } + }; + + configBOStream.forEach(configBOConsumer); + } + + private void writeClusterInfoToZip(Env env, App app, List exportClusters, + ZipOutputStream zipOutputStream) { + final Consumer clusterConsumer = + cluster -> { + try { + synchronized (zipOutputStream) { + String fileName = ConfigFileUtils.genClusterInfoPath(app, env, cluster); + String content = gson.toJson(cluster); + + writeToZip(fileName, content, zipOutputStream); + } + } catch (IOException e) { + logger.error("Write error. {}", cluster); + throw new ServiceException("Write error. {}", e); + } + }; + + exportClusters.forEach(clusterConsumer); + } + + private void writeToZip(String filePath, String content, ZipOutputStream zipOutputStream) + throws IOException { + final ZipEntry zipEntry = new ZipEntry(filePath); + try { + zipOutputStream.putNextEntry(zipEntry); + zipOutputStream.write(content.getBytes()); + zipOutputStream.closeEntry(); + } catch (IOException e) { + String errorMsg = "write content to zip error. file = " + filePath + ", content = " + content; + logger.error(errorMsg); + throw new IOException(errorMsg, e); + } + } + } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java index f5aa4b155ff..558e3c8ae79 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,43 @@ */ package com.ctrip.framework.apollo.portal.service; +import com.google.common.collect.Lists; +import com.google.gson.Gson; + +import com.ctrip.framework.apollo.common.constants.GsonType; +import com.ctrip.framework.apollo.common.dto.ClusterDTO; +import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.common.dto.NamespaceDTO; +import com.ctrip.framework.apollo.common.entity.App; +import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.exception.ServiceException; -import com.ctrip.framework.apollo.portal.component.PermissionValidator; -import com.ctrip.framework.apollo.portal.entity.model.NamespaceTextModel; +import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.portal.environment.Env; +import com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent; +import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.util.ConfigFileUtils; import com.ctrip.framework.apollo.portal.util.ConfigToFileUtils; -import java.io.IOException; -import java.io.InputStream; -import java.security.AccessControlException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Lazy; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpStatusCodeException; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.rmi.ServerException; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CountDownLatch; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; /** * @author wxq @@ -35,103 +60,463 @@ @Service public class ConfigsImportService { - private final ItemService itemService; + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigsImportService.class); - private final NamespaceService namespaceService; + private Gson gson = new Gson(); - private final PermissionValidator permissionValidator; + private final ItemService itemService; + private final AppService appService; + private final ClusterService clusterService; + private final NamespaceService namespaceService; + private final AppNamespaceService appNamespaceService; + private final ApplicationEventPublisher publisher; + private final UserInfoHolder userInfoHolder; + private final RoleInitializationService roleInitializationService; public ConfigsImportService( final ItemService itemService, + final AppService appService, + final ClusterService clusterService, final @Lazy NamespaceService namespaceService, - PermissionValidator permissionValidator) { + final AppNamespaceService appNamespaceService, + final ApplicationEventPublisher publisher, + final UserInfoHolder userInfoHolder, + final RoleInitializationService roleInitializationService) { this.itemService = itemService; + this.appService = appService; + this.clusterService = clusterService; this.namespaceService = namespaceService; - this.permissionValidator = permissionValidator; + this.appNamespaceService = appNamespaceService; + this.publisher = publisher; + this.userInfoHolder = userInfoHolder; + this.roleInitializationService = roleInitializationService; } /** - * move from {@link com.ctrip.framework.apollo.portal.controller.ConfigsImportController} + * force import, new items will overwrite existed items. */ - private void importConfig( - final String appId, - final String env, - final String clusterName, - final String namespaceName, - final long namespaceId, - final String format, - final String configText - ) { - final NamespaceTextModel model = new NamespaceTextModel(); - - model.setAppId(appId); - model.setEnv(env); - model.setClusterName(clusterName); - model.setNamespaceName(namespaceName); - model.setNamespaceId(namespaceId); - model.setFormat(format); - model.setConfigText(configText); - - itemService.updateConfigItemByText(model); + public void forceImportNamespaceFromFile(final Env env, final String standardFilename, + final InputStream zipInputStream) { + String configText; + try (InputStream in = zipInputStream) { + configText = ConfigToFileUtils.fileToString(in); + } catch (IOException e) { + throw new ServiceException("Read config file errors:{}", e); + } + + String operator = userInfoHolder.getUser().getUserId(); + + this.importNamespaceFromText(env, standardFilename, configText, false, operator); } /** - * import one config from file + * import all data include app、appnamespace、cluster、namespace、item */ - private void importOneConfigFromFile( - final String appId, - final String env, - final String clusterName, - final String namespaceName, - final String configText, - final String format - ) { - final NamespaceDTO namespaceDTO = namespaceService - .loadNamespaceBaseInfo(appId, Env.valueOf(env), clusterName, namespaceName); - this.importConfig(appId, env, clusterName, namespaceName, namespaceDTO.getId(), format, configText); + public void importDataFromZipFile(List importEnvs, ZipInputStream dataZip, boolean ignoreConflictNamespace) + throws IOException { + List toImportApps = Lists.newArrayList(); + List toImportAppNSs = Lists.newArrayList(); + List toImportClusters = Lists.newArrayList(); + List toImportNSs = Lists.newArrayList(); + + ZipEntry entry; + while ((entry = dataZip.getNextEntry()) != null) { + if (entry.isDirectory()) { + continue; + } + + String filePath = entry.getName(); + String content = readContent(dataZip); + + String[] info = filePath.split("/"); + + String fileName; + if (info.length == 1) { + //app namespace metadata file. path format : ${namespaceName}.appnamespace.metadata + fileName = info[0]; + if (fileName.endsWith(ConfigFileUtils.APP_NAMESPACE_METADATA_FILE_SUFFIX)) { + toImportAppNSs.add(content); + } + } else if (info.length == 3) { + fileName = info[2]; + if (fileName.equals(ConfigFileUtils.APP_METADATA_FILENAME)) { + //app metadata file. path format : apollo/${appId}/app.metadata + toImportApps.add(content); + } + } else { + String env = info[2]; + fileName = info[3]; + for (Env importEnv : importEnvs) { + if (Objects.equals(importEnv.getName(), env)) { + if (fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) { + //cluster metadata file. path format : apollo/${appId}/${env}/${clusterName}.cluster.metadata + toImportClusters.add(new ImportClusterData(Env.transformEnv(env), content)); + } else { + //namespace file.path format : apollo/${appId}/${env}/${appId}+${cluster}+${namespaceName} + toImportNSs.add(new ImportNamespaceData(Env.valueOf(env), fileName, content, ignoreConflictNamespace)); + } + } + } + } + } + + try { + LOGGER.info("Import data. app = {}, appns = {}, cluster = {}, namespace = {}", toImportApps.size(), + toImportAppNSs.size(), + toImportClusters.size(), toImportNSs.size()); + + doImport(importEnvs, toImportApps, toImportAppNSs, toImportClusters, toImportNSs); + + } catch (Exception e) { + LOGGER.error("import config error.", e); + throw new ServerException("import config error.", e); + } + } + + private void doImport(List importEnvs, List toImportApps, List toImportAppNSs, + List toImportClusters, List toImportNSs) + throws InterruptedException { + LOGGER.info("Start to import app. size = {}", toImportApps.size()); + + String operator = userInfoHolder.getUser().getUserId(); + + long startTime = System.currentTimeMillis(); + CountDownLatch appLatch = new CountDownLatch(toImportApps.size()); + toImportApps.parallelStream().forEach(app -> { + try { + importApp(app, importEnvs, operator); + } catch (Exception e) { + LOGGER.error("import app error. app = {}", app, e); + } finally { + appLatch.countDown(); + } + }); + appLatch.await(); + + LOGGER.info("Finish to import app. duration = {}", System.currentTimeMillis() - startTime); + LOGGER.info("Start to import appnamespace. size = {}", toImportAppNSs.size()); + + startTime = System.currentTimeMillis(); + CountDownLatch appNSLatch = new CountDownLatch(toImportAppNSs.size()); + toImportAppNSs.parallelStream().forEach(appNS -> { + try { + importAppNamespace(appNS, operator); + } catch (Exception e) { + LOGGER.error("import appnamespace error. appnamespace = {}", appNS, e); + } finally { + appNSLatch.countDown(); + } + }); + appNSLatch.await(); + + LOGGER.info("Finish to import appnamespace. duration = {}", System.currentTimeMillis() - startTime); + LOGGER.info("Start to import cluster. size = {}", toImportClusters.size()); + + startTime = System.currentTimeMillis(); + CountDownLatch clusterLatch = new CountDownLatch(toImportClusters.size()); + toImportClusters.parallelStream().forEach(cluster -> { + try { + importCluster(cluster, operator); + } catch (Exception e) { + LOGGER.error("import cluster error. cluster = {}", cluster, e); + } finally { + clusterLatch.countDown(); + } + }); + clusterLatch.await(); + + LOGGER.info("Finish to import cluster. duration = {}", System.currentTimeMillis() - startTime); + LOGGER.info("Start to import namespace. size = {}", toImportNSs.size()); + + startTime = System.currentTimeMillis(); + CountDownLatch nsLatch = new CountDownLatch(toImportNSs.size()); + toImportNSs.parallelStream().forEach(namespace -> { + try { + importNamespaceFromText(namespace.getEnv(), namespace.getFileName(), namespace.getContent(), + namespace.isIgnoreConflictNamespace(), operator); + } catch (Exception e) { + LOGGER.error("import namespace error. namespace = {}", namespace, e); + } finally { + nsLatch.countDown(); + } + }); + nsLatch.await(); + + LOGGER.info("Finish to import namespace. duration = {}", System.currentTimeMillis() - startTime); + } + + private void importApp(String appInfo, List importEnvs, String operator) { + App toImportApp = gson.fromJson(appInfo, App.class); + String appId = toImportApp.getAppId(); + + toImportApp.setDataChangeCreatedBy(operator); + toImportApp.setDataChangeLastModifiedBy(operator); + toImportApp.setDataChangeCreatedTime(new Date()); + toImportApp.setDataChangeLastModifiedTime(new Date()); + + App managedApp = appService.load(appId); + if (managedApp == null) { + appService.importAppInLocal(toImportApp); + } + + importEnvs.parallelStream().forEach(env -> { + try { + appService.load(env, appId); + } catch (Exception e) { + //not existed + appService.createAppInRemote(env, toImportApp); + } + }); + } + + private void importAppNamespace(String appNamespace, String operator) { + AppNamespace toImportPubAppNS = gson.fromJson(appNamespace, AppNamespace.class); + + String appId = toImportPubAppNS.getAppId(); + String namespaceName = toImportPubAppNS.getName(); + boolean isPublic = toImportPubAppNS.isPublic(); + + AppNamespace + managedAppNamespace = + isPublic ? appNamespaceService.findPublicAppNamespace(namespaceName) + : appNamespaceService.findByAppIdAndName(appId, namespaceName); + + if (managedAppNamespace == null) { + managedAppNamespace = new AppNamespace(); + managedAppNamespace.setAppId(toImportPubAppNS.getAppId()); + managedAppNamespace.setPublic(isPublic); + managedAppNamespace.setFormat(toImportPubAppNS.getFormat()); + managedAppNamespace.setComment(toImportPubAppNS.getComment()); + managedAppNamespace.setDataChangeCreatedBy(operator); + managedAppNamespace.setDataChangeLastModifiedBy(operator); + managedAppNamespace.setName(namespaceName); + + AppNamespace createdAppNamespace = appNamespaceService.importAppNamespaceInLocal(managedAppNamespace); + + //application namespace will be auto created when creating app + if (!ConfigConsts.NAMESPACE_APPLICATION.equals(namespaceName)) { + publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace)); + } + } + } + + private void importCluster(ImportClusterData importClusterData, String operator) { + Env env = importClusterData.getEnv(); + ClusterDTO toImportCluster = gson.fromJson(importClusterData.clusterInfo, ClusterDTO.class); + + toImportCluster.setDataChangeCreatedBy(operator); + toImportCluster.setDataChangeLastModifiedBy(operator); + toImportCluster.setDataChangeCreatedTime(new Date()); + toImportCluster.setDataChangeLastModifiedTime(new Date()); + + String appId = toImportCluster.getAppId(); + String clusterName = toImportCluster.getName(); + + try { + clusterService.loadCluster(appId, env, clusterName); + } catch (Exception e) { + //not existed + clusterService.createCluster(env, toImportCluster); + } } /** - * import a config file. - * the name of config file must be special like - * appId+cluster+namespace.format - * Example: + * import a config file. the name of config file must be special like appId+cluster+namespace.format Example: *
    *   123456+default+application.properties (appId is 123456, cluster is default, namespace is application, format is properties)
    *   654321+north+password.yml (appId is 654321, cluster is north, namespace is password, format is yml)
    * 
* so we can get the information of appId, cluster, namespace, format from the file name. - * @param env environment + * + * @param env environment * @param standardFilename appId+cluster+namespace.format - * @param configText config content + * @param configText config content */ - private void importOneConfigFromText( - final String env, - final String standardFilename, - final String configText - ) { + private void importNamespaceFromText(final Env env, final String standardFilename, final String configText, + boolean ignoreConflictNamespace, String operator) { final String appId = ConfigFileUtils.getAppId(standardFilename); final String clusterName = ConfigFileUtils.getClusterName(standardFilename); final String namespace = ConfigFileUtils.getNamespace(standardFilename); final String format = ConfigFileUtils.getFormat(standardFilename); - this.importOneConfigFromFile(appId, env, clusterName, namespace, configText, format); + + this.importNamespace(appId, env, clusterName, namespace, configText, format, ignoreConflictNamespace, operator); } - /** - * @see ConfigsImportService#importOneConfigFromText(java.lang.String, java.lang.String, java.lang.String) - * @throws AccessControlException if has no modify namespace permission - */ - public void importOneConfigFromFile( - final String env, - final String standardFilename, - final InputStream inputStream - ) { - final String configText; - try(InputStream in = inputStream) { - configText = ConfigToFileUtils.fileToString(in); + private void importNamespace(final String appId, final Env env, + final String clusterName, final String namespaceName, + final String configText, final String format, + boolean ignoreConflictNamespace, String operator) { + NamespaceDTO namespaceDTO; + try { + namespaceDTO = namespaceService.loadNamespaceBaseInfo(appId, env, clusterName, namespaceName); + } catch (Exception e) { + //not existed + namespaceDTO = null; + } + + if (namespaceDTO == null) { + namespaceDTO = new NamespaceDTO(); + namespaceDTO.setAppId(appId); + namespaceDTO.setClusterName(clusterName); + namespaceDTO.setNamespaceName(namespaceName); + namespaceDTO.setDataChangeCreatedBy(operator); + namespaceDTO.setDataChangeLastModifiedBy(operator); + namespaceDTO = namespaceService.createNamespace(env, namespaceDTO); + + roleInitializationService.initNamespaceRoles(appId, namespaceName, operator); + roleInitializationService.initNamespaceEnvRoles(appId, namespaceName, operator); + } + + List itemDTOS = itemService.findItems(appId, env, clusterName, namespaceName); + // skip import if target namespace has existed items + if (!CollectionUtils.isEmpty(itemDTOS) && ignoreConflictNamespace) { + return; + } + + importItems(appId, env, clusterName, namespaceName, configText, namespaceDTO, operator); + } + + private void importItems(String appId, Env env, String clusterName, String namespaceName, String configText, + NamespaceDTO namespaceDTO, String operator) { + List toImportItems = gson.fromJson(configText, GsonType.ITEM_DTOS); + + toImportItems.parallelStream().forEach(newItem -> { + String key = newItem.getKey(); + newItem.setNamespaceId(namespaceDTO.getId()); + newItem.setDataChangeCreatedBy(operator); + newItem.setDataChangeLastModifiedBy(operator); + newItem.setDataChangeCreatedTime(new Date()); + newItem.setDataChangeLastModifiedTime(new Date()); + + if (StringUtils.hasText(key)) { + //create or update normal item + try { + ItemDTO oldItem = itemService.loadItem(env, appId, clusterName, namespaceName, key); + newItem.setId(oldItem.getId()); + //existed + itemService.updateItem(appId, env, clusterName, namespaceName, newItem); + } catch (Exception e) { + if (e instanceof HttpStatusCodeException && ((HttpStatusCodeException) e).getStatusCode() + .equals(HttpStatus.NOT_FOUND)) { + //not existed + itemService.createItem(appId, env, clusterName, namespaceName, newItem); + } else { + LOGGER.error("Load or update item error. appId = {}, env = {}, cluster = {}, namespace = {}", appId, env, + clusterName, namespaceDTO, e); + } + } + } else if (StringUtils.hasText(newItem.getComment())){ + //create comment item + itemService.createCommentItem(appId, env, clusterName, namespaceName, newItem); + } + + }); + } + + + private String readContent(ZipInputStream zipInputStream) { + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + byte[] buffer = new byte[1024]; + int offset; + while ((offset = zipInputStream.read(buffer)) != -1) { + out.write(buffer, 0, offset); + } + return out.toString("UTF-8"); } catch (IOException e) { - throw new ServiceException("Read config file errors:{}", e); + LOGGER.error("Read file content from zip error.", e); + return null; + } + } + + static class ImportNamespaceData { + + private Env env; + private String fileName; + private String content; + private boolean ignoreConflictNamespace; + + public ImportNamespaceData(Env env, String fileName, String content, boolean ignoreConflictNamespace) { + this.env = env; + this.fileName = fileName; + this.content = content; + this.ignoreConflictNamespace = ignoreConflictNamespace; + } + + public Env getEnv() { + return env; + } + + public void setEnv(Env env) { + this.env = env; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public boolean isIgnoreConflictNamespace() { + return ignoreConflictNamespace; + } + + public void setIgnoreConflictNamespace(boolean ignoreConflictNamespace) { + this.ignoreConflictNamespace = ignoreConflictNamespace; + } + + @Override + public String toString() { + return "NamespaceImportData{" + + "env=" + env + + ", fileName='" + fileName + '\'' + + ", content='" + content + '\'' + + ", ignoreConflictNamespace=" + ignoreConflictNamespace + + '}'; + } + } + + static class ImportClusterData { + + private Env env; + private String clusterInfo; + + public ImportClusterData(Env env, String clusterInfo) { + this.env = env; + this.clusterInfo = clusterInfo; + } + + public Env getEnv() { + return env; + } + + public void setEnv(Env env) { + this.env = env; + } + + public String getClusterInfo() { + return clusterInfo; + } + + public void setClusterInfo(String clusterInfo) { + this.clusterInfo = clusterInfo; + } + + @Override + public String toString() { + return "ImportClusterData{" + + "env=" + env + + ", clusterName='" + clusterInfo + '\'' + + '}'; } - this.importOneConfigFromText(env, standardFilename, configText); } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java index 96841cb2581..3d51530d7fd 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/FavoriteService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,11 @@ import com.ctrip.framework.apollo.portal.repository.FavoriteRepository; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserService; -import java.util.Collections; +import com.google.common.base.Strings; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -77,8 +76,8 @@ public Favorite addFavorite(Favorite favorite) { public List search(String userId, String appId, Pageable page) { - boolean isUserIdEmpty = StringUtils.isEmpty(userId); - boolean isAppIdEmpty = StringUtils.isEmpty(appId); + boolean isUserIdEmpty = Strings.isNullOrEmpty(userId); + boolean isAppIdEmpty = Strings.isNullOrEmpty(appId); if (isAppIdEmpty && isUserIdEmpty) { throw new BadRequestException("user id and app id can't be empty at the same time"); @@ -106,7 +105,6 @@ public List search(String userId, String appId, Pageable page) { return Collections.singletonList(favoriteRepository.findByUserIdAndAppId(userId, appId)); } - public void deleteFavorite(long favoriteId) { Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/InstanceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/InstanceService.java index d13625b62d9..65343a90c1c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/InstanceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/InstanceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public PageDTO getByNamespace(Env env, String appId, String cluster return instanceAPI.getByNamespace(appId, env, clusterName, namespaceName, instanceAppId, page, size); } - public int getInstanceCountByNamepsace(String appId, Env env, String clusterName, String namespaceName){ + public int getInstanceCountByNamespace(String appId, Env env, String clusterName, String namespaceName){ return instanceAPI.getInstanceCountByNamespace(appId, env, clusterName, namespaceName); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java index 00c1f566635..36072039fb8 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,6 +96,11 @@ public void updateConfigItemByText(NamespaceTextModel model) { } long namespaceId = namespace.getId(); + // In case someone constructs an attack scenario + if (model.getNamespaceId() != namespaceId) { + throw new BadRequestException("Invalid request, item and namespace do not match!"); + } + String configText = model.getConfigText(); ConfigTextResolver resolver = @@ -107,7 +112,12 @@ public void updateConfigItemByText(NamespaceTextModel model) { return; } - changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); + String operator = model.getOperator(); + if (StringUtils.isBlank(operator)) { + operator = userInfoHolder.getUser().getUserId(); + } + changeSets.setDataChangeLastModifiedBy(operator); + updateItems(appId, env, clusterName, namespaceName, changeSets); Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE_BY_TEXT, @@ -133,6 +143,17 @@ public ItemDTO createItem(String appId, Env env, String clusterName, String name return itemDTO; } + public ItemDTO createCommentItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) { + NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); + if (namespace == null) { + throw new BadRequestException( + "namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName); + } + item.setNamespaceId(namespace.getId()); + + return itemAPI.createCommentItem(appId, env, clusterName, namespaceName, item); + } + public void updateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) { itemAPI.updateItem(appId, env, clusterName, namespaceName, item.getId(), item); } @@ -223,9 +244,9 @@ public void revokeItem(String appId, Env env, String clusterName, String namespa updateItems(appId, env, clusterName, namespaceName, changeSets); - Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE_BY_TEXT, - String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName)); - Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName)); + String formatStr = String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName); + Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE_BY_TEXT, formatStr); + Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE, formatStr); } public List compare(List comparedNamespaces, List sourceItems) { @@ -252,7 +273,7 @@ private long getNamespaceId(NamespaceIdentifier namespaceIdentifier) { String clusterName = namespaceIdentifier.getClusterName(); String namespaceName = namespaceIdentifier.getNamespaceName(); Env env = namespaceIdentifier.getEnv(); - NamespaceDTO namespaceDTO = null; + NamespaceDTO namespaceDTO; try { namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); } catch (HttpClientErrorException e) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java index c9c68707c5a..9abda67eab5 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceBranchService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java index 6b5106de16b..14192bebe0b 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java index ff37c3f08c8..55a91bd5680 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import com.ctrip.framework.apollo.common.constants.GsonType; import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.common.dto.NamespaceDTO; +import com.ctrip.framework.apollo.common.dto.PageDTO; import com.ctrip.framework.apollo.common.dto.ReleaseDTO; import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.exception.BadRequestException; @@ -48,13 +49,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service public class NamespaceService { - private Logger logger = LoggerFactory.getLogger(NamespaceService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceService.class); private static final Gson GSON = new Gson(); private final PortalConfig portalConfig; @@ -99,7 +101,10 @@ public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) { if (StringUtils.isEmpty(namespace.getDataChangeCreatedBy())) { namespace.setDataChangeCreatedBy(userInfoHolder.getUser().getUserId()); } - namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); + + if (StringUtils.isEmpty(namespace.getDataChangeLastModifiedBy())) { + namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); + } NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace); Tracer.logEvent(TracerEventType.CREATE_NAMESPACE, @@ -168,7 +173,7 @@ public List findNamespaceBOs(String appId, Env env, String clusterN namespaceBO = transformNamespace2BO(env, namespace); namespaceBOs.add(namespaceBO); } catch (Exception e) { - logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", + LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", appId, env, clusterName, namespace.getNamespaceName(), e); throw e; } @@ -181,6 +186,13 @@ public List findNamespaces(String appId, Env env, String clusterNa return namespaceAPI.findNamespaceByCluster(appId, env, clusterName); } + /** + * the returned content's size is not fixed. so please carefully used. + */ + public PageDTO findNamespacesByItem(Env env, String itemKey, Pageable pageable) { + return namespaceAPI.findByItem(env, itemKey, pageable.getPageNumber(), pageable.getPageSize()); + } + public List getPublicAppNamespaceAllNamespaces(Env env, String publicNamespaceName, int page, int size) { @@ -198,7 +210,7 @@ public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName, public boolean namespaceHasInstances(String appId, Env env, String clusterName, String namespaceName) { - return instanceService.getInstanceCountByNamepsace(appId, env, clusterName, namespaceName) > 0; + return instanceService.getInstanceCountByNamespace(appId, env, clusterName, namespaceName) > 0; } public boolean publicAppNamespaceHasAssociatedNamespace(String publicNamespaceName, Env env) { @@ -298,7 +310,7 @@ private void fillAppNamespaceProperties(NamespaceBO namespace) { final boolean isPublic; if (appNamespace == null) { //dirty data - logger.warn("Dirty data, cannot find appNamespace by namespaceName [{}], appId = {}, cluster = {}, set it format to {}, make public", namespaceName, appId, clusterName, ConfigFileFormat.Properties.getValue()); + LOGGER.warn("Dirty data, cannot find appNamespace by namespaceName [{}], appId = {}, cluster = {}, set it format to {}, make public", namespaceName, appId, clusterName, ConfigFileFormat.Properties.getValue()); format = ConfigFileFormat.Properties.getValue(); isPublic = true; // set to true, because public namespace allowed to delete by user } else { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java index 0a439ab49bd..26ddffb63dd 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/PortalDBPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseHistoryService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseHistoryService.java index 373e90ab658..742bc5014e5 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseHistoryService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseHistoryService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java index 94b226aada6..01897ddbc20 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java index 6d2a3c18b3f..876ca056b61 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java index dfe0ee5adaf..bfda36e5449 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RolePermissionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/SystemRoleManagerService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/SystemRoleManagerService.java index f0926f588f9..dde42c11e5f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/SystemRoleManagerService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/SystemRoleManagerService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/EmailService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/EmailService.java index 255ec65c550..2a0ec1ca564 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/EmailService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/EmailService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/LogoutHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/LogoutHandler.java index c08a1ab3858..14ed932e602 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/LogoutHandler.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/LogoutHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/MQService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/MQService.java index e3c4c7dc5f7..ab431a76ac6 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/MQService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/MQService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/SsoHeartbeatHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/SsoHeartbeatHandler.java index d188a30659b..5ffc1ab1f81 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/SsoHeartbeatHandler.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/SsoHeartbeatHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserInfoHolder.java index e878d93c4d5..63c0cff237c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserInfoHolder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserInfoHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java index d237bf6341c..3eefca17b8e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java index 27fcd9b8377..9948ecefaef 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. * */ + package com.ctrip.framework.apollo.portal.spi.configuration; import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile; import com.ctrip.framework.apollo.core.utils.StringUtils; -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; +import com.ctrip.framework.apollo.portal.repository.AuthorityRepository; import com.ctrip.framework.apollo.portal.repository.UserRepository; import com.ctrip.framework.apollo.portal.spi.LogoutHandler; import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserService; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripLogoutHandler; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripSsoHeartbeatHandler; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripUserInfoHolder; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripUserService; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultLogoutHandler; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultSsoHeartbeatHandler; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultUserInfoHolder; @@ -44,15 +41,15 @@ import com.ctrip.framework.apollo.portal.spi.springsecurity.ApolloPasswordEncoderFactory; import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserInfoHolder; import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService; -import com.google.common.collect.Maps; +import java.util.Collections; +import javax.sql.DataSource; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties; import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Profile; import org.springframework.core.annotation.Order; import org.springframework.core.env.Environment; @@ -75,12 +72,6 @@ import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; -import javax.servlet.Filter; -import javax.sql.DataSource; -import java.util.Collections; -import java.util.EventListener; -import java.util.Map; - @Configuration public class AuthConfiguration { @@ -88,147 +79,6 @@ public class AuthConfiguration { "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**", "/i18n/**", "/prefix-path", "/health"}; - /** - * spring.profiles.active = ctrip - */ - @Configuration - @Profile("ctrip") - static class CtripAuthAutoConfiguration { - - private final PortalConfig portalConfig; - - public CtripAuthAutoConfiguration(final PortalConfig portalConfig) { - this.portalConfig = portalConfig; - } - - @Bean - public ServletListenerRegistrationBean redisAppSettingListner() { - ServletListenerRegistrationBean redisAppSettingListener = new ServletListenerRegistrationBean(); - redisAppSettingListener - .setListener(listener("org.jasig.cas.client.credis.CRedisAppSettingListner")); - return redisAppSettingListener; - } - - @Bean - public ServletListenerRegistrationBean singleSignOutHttpSessionListener() { - ServletListenerRegistrationBean singleSignOutHttpSessionListener = new ServletListenerRegistrationBean(); - singleSignOutHttpSessionListener - .setListener(listener("org.jasig.cas.client.session.SingleSignOutHttpSessionListener")); - return singleSignOutHttpSessionListener; - } - - @Bean - public FilterRegistrationBean casFilter() { - FilterRegistrationBean singleSignOutFilter = new FilterRegistrationBean(); - singleSignOutFilter.setFilter(filter("org.jasig.cas.client.session.SingleSignOutFilter")); - singleSignOutFilter.addUrlPatterns("/*"); - singleSignOutFilter.setOrder(1); - return singleSignOutFilter; - } - - @Bean - public FilterRegistrationBean authenticationFilter() { - FilterRegistrationBean casFilter = new FilterRegistrationBean(); - - Map filterInitParam = Maps.newHashMap(); - filterInitParam.put("redisClusterName", "casClientPrincipal"); - filterInitParam.put("serverName", portalConfig.portalServerName()); - filterInitParam.put("casServerLoginUrl", portalConfig.casServerLoginUrl()); - //we don't want to use session to store login information, since we will be deployed to a cluster, not a single instance - filterInitParam.put("useSession", "false"); - filterInitParam.put("/openapi.*", "exclude"); - - casFilter.setInitParameters(filterInitParam); - casFilter - .setFilter(filter("com.ctrip.framework.apollo.sso.filter.ApolloAuthenticationFilter")); - casFilter.addUrlPatterns("/*"); - casFilter.setOrder(2); - - return casFilter; - } - - @Bean - public FilterRegistrationBean casValidationFilter() { - FilterRegistrationBean casValidationFilter = new FilterRegistrationBean(); - Map filterInitParam = Maps.newHashMap(); - filterInitParam.put("casServerUrlPrefix", portalConfig.casServerUrlPrefix()); - filterInitParam.put("serverName", portalConfig.portalServerName()); - filterInitParam.put("encoding", "UTF-8"); - //we don't want to use session to store login information, since we will be deployed to a cluster, not a single instance - filterInitParam.put("useSession", "false"); - filterInitParam.put("useRedis", "true"); - filterInitParam.put("redisClusterName", "casClientPrincipal"); - - casValidationFilter - .setFilter( - filter("org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter")); - casValidationFilter.setInitParameters(filterInitParam); - casValidationFilter.addUrlPatterns("/*"); - casValidationFilter.setOrder(3); - - return casValidationFilter; - } - - @Bean - public FilterRegistrationBean assertionHolder() { - FilterRegistrationBean assertionHolderFilter = new FilterRegistrationBean(); - - Map filterInitParam = Maps.newHashMap(); - filterInitParam.put("/openapi.*", "exclude"); - - assertionHolderFilter.setInitParameters(filterInitParam); - - assertionHolderFilter.setFilter( - filter("com.ctrip.framework.apollo.sso.filter.ApolloAssertionThreadLocalFilter")); - assertionHolderFilter.addUrlPatterns("/*"); - assertionHolderFilter.setOrder(4); - - return assertionHolderFilter; - } - - @Bean - public CtripUserInfoHolder ctripUserInfoHolder() { - return new CtripUserInfoHolder(); - } - - @Bean - public CtripLogoutHandler logoutHandler() { - return new CtripLogoutHandler(); - } - - private Filter filter(String className) { - Class clazz = null; - try { - clazz = Class.forName(className); - Object obj = clazz.newInstance(); - return (Filter) obj; - } catch (Exception e) { - throw new RuntimeException("instance filter fail", e); - } - } - - private EventListener listener(String className) { - Class clazz = null; - try { - clazz = Class.forName(className); - Object obj = clazz.newInstance(); - return (EventListener) obj; - } catch (Exception e) { - throw new RuntimeException("instance listener fail", e); - } - } - - @Bean - public UserService ctripUserService(PortalConfig portalConfig) { - return new CtripUserService(portalConfig); - } - - @Bean - public SsoHeartbeatHandler ctripSsoHeartbeatHandler() { - return new CtripSsoHeartbeatHandler(); - } - } - /** * spring.profiles.active = auth */ @@ -287,11 +137,11 @@ public static JdbcUserDetailsManager jdbcUserDetailsManager(PasswordEncoder pass } @Bean + @DependsOn("jdbcUserDetailsManager") @ConditionalOnMissingBean(UserService.class) public UserService springSecurityUserService(PasswordEncoder passwordEncoder, - JdbcUserDetailsManager userDetailsManager, - UserRepository userRepository) { - return new SpringSecurityUserService(passwordEncoder, userDetailsManager, userRepository); + UserRepository userRepository, AuthorityRepository authorityRepository) { + return new SpringSecurityUserService(passwordEncoder, userRepository, authorityRepository); } } @@ -398,7 +248,7 @@ static class SpringSecurityLDAPConfigurer extends WebSecurityConfigurerAdapter { public SpringSecurityLDAPConfigurer(final LdapProperties ldapProperties, final LdapContextSource ldapContextSource, - final LdapExtendProperties ldapExtendProperties) { + final LdapExtendProperties ldapExtendProperties) { this.ldapProperties = ldapProperties; this.ldapContextSource = ldapContextSource; this.ldapExtendProperties = ldapExtendProperties; @@ -409,7 +259,8 @@ public FilterBasedLdapUserSearch userSearch() { if (ldapExtendProperties.getGroup() == null || StringUtils .isBlank(ldapExtendProperties.getGroup().getGroupSearch())) { FilterBasedLdapUserSearch filterBasedLdapUserSearch = new FilterBasedLdapUserSearch("", - ldapProperties.getSearchFilter(), ldapContextSource); + ldapProperties.getSearchFilter(), ldapContextSource + ); filterBasedLdapUserSearch.setSearchSubtree(true); return filterBasedLdapUserSearch; } @@ -418,7 +269,8 @@ public FilterBasedLdapUserSearch userSearch() { ldapProperties.getBase(), ldapProperties.getSearchFilter(), ldapExtendProperties.getGroup().getGroupBase(), ldapContextSource, ldapExtendProperties.getGroup().getGroupSearch(), ldapExtendProperties.getMapping().getRdnKey(), - ldapExtendProperties.getGroup().getGroupMembership(),ldapExtendProperties.getMapping().getLoginId()); + ldapExtendProperties.getGroup().getGroupMembership(), ldapExtendProperties.getMapping().getLoginId() + ); filterLdapByGroupUserSearch.setSearchSubtree(true); return filterLdapByGroupUserSearch; } @@ -445,9 +297,9 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers(BY_PASS_URLS).permitAll() .antMatchers("/**").authenticated(); http.formLogin().loginPage("/signin").defaultSuccessUrl("/", true).permitAll().failureUrl("/signin?#/error").and() - .httpBasic(); + .httpBasic(); http.logout().logoutUrl("/user/logout").invalidateHttpSession(true).clearAuthentication(true) - .logoutSuccessUrl("/signin?#/logout"); + .logoutSuccessUrl("/signin?#/logout"); http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/signin")); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthFilterConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthFilterConfiguration.java index 5b7fc6053c0..6c747f4d9e2 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthFilterConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthFilterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter; import com.ctrip.framework.apollo.openapi.util.ConsumerAuditUtil; import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil; - import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,9 +27,11 @@ public class AuthFilterConfiguration { @Bean - public FilterRegistrationBean openApiAuthenticationFilter(ConsumerAuthUtil consumerAuthUtil, - ConsumerAuditUtil consumerAuditUtil) { - FilterRegistrationBean openApiFilter = new FilterRegistrationBean(); + public FilterRegistrationBean openApiAuthenticationFilter( + ConsumerAuthUtil consumerAuthUtil, + ConsumerAuditUtil consumerAuditUtil) { + + FilterRegistrationBean openApiFilter = new FilterRegistrationBean<>(); openApiFilter.setFilter(new ConsumerAuthenticationFilter(consumerAuthUtil, consumerAuditUtil)); openApiFilter.addUrlPatterns("/openapi/*"); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/EmailConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/EmailConfiguration.java index 6d44ba6bda2..b6499346023 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/EmailConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/EmailConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,47 +14,21 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.portal.spi.configuration; +package com.ctrip.framework.apollo.portal.spi.configuration; -import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile; import com.ctrip.framework.apollo.portal.spi.EmailService; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailService; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailRequestBuilder; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultEmailService; - import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; @Configuration public class EmailConfiguration { - /** - * spring.profiles.active = ctrip - */ @Configuration - @Profile("ctrip") - public static class CtripEmailConfiguration { - - @Bean - public EmailService ctripEmailService() { - return new CtripEmailService(); - } - - @Bean - public CtripEmailRequestBuilder emailRequestBuilder() { - return new CtripEmailRequestBuilder(); - } - } - - /** - * spring.profiles.active != ctrip - */ - @Configuration - @ConditionalOnMissingProfile({"ctrip"}) public static class DefaultEmailConfiguration { + @Bean @ConditionalOnMissingBean(EmailService.class) public EmailService defaultEmailService() { @@ -62,7 +36,5 @@ public EmailService defaultEmailService() { } } - - } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java index c757a97df7e..01ef0d76281 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapExtendProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java index 0c585f7972e..d81362004df 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapGroupProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java index dbe7266972d..d18a497a5d7 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapMappingProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java index 4168e9519df..aee86762bda 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/LdapProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/MQConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/MQConfiguration.java index 8a8cc813d05..c34e07452d5 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/MQConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/MQConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,34 +14,17 @@ * limitations under the License. * */ + package com.ctrip.framework.apollo.portal.spi.configuration; -import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile; -import com.ctrip.framework.apollo.portal.spi.ctrip.CtripMQService; import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultMQService; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; @Configuration public class MQConfiguration { @Configuration - @Profile("ctrip") - public static class CtripMQConfiguration { - - @Bean - public CtripMQService mqService() { - return new CtripMQService(); - } - } - - /** - * spring.profiles.active != ctrip - */ - @Configuration - @ConditionalOnMissingProfile({"ctrip"}) public static class DefaultMQConfiguration { @Bean diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/RoleConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/RoleConfiguration.java index e5cdab43c9e..c5fa40ecddf 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/RoleConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/RoleConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/BizLoggingCustomizer.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/BizLoggingCustomizer.java deleted file mode 100644 index 3e442fff0b8..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/BizLoggingCustomizer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.common.customize.LoggingCustomizer; -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("ctrip") -public class BizLoggingCustomizer extends LoggingCustomizer { - - private final PortalConfig portalConfig; - - public BizLoggingCustomizer(final PortalConfig portalConfig) { - this.portalConfig = portalConfig; - } - - @Override - protected String cloggingUrl() { - return portalConfig.cloggingUrl(); - } - - @Override - protected String cloggingPort() { - return portalConfig.cloggingPort(); - } -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailRequestBuilder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailRequestBuilder.java deleted file mode 100644 index 968f1d60767..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailRequestBuilder.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.entity.bo.Email; -import com.ctrip.framework.apollo.tracer.Tracer; - -import org.apache.commons.lang.time.DateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -import java.lang.reflect.Method; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import javax.annotation.PostConstruct; - -public class CtripEmailRequestBuilder { - - private static final Logger logger = LoggerFactory.getLogger(CtripEmailRequestBuilder.class); - - private static Class sendEmailRequestClazz; - private static Method setBodyContent; - private static Method setRecipient; - private static Method setSendCode; - private static Method setBodyTemplateID; - private static Method setSender; - private static Method setSubject; - private static Method setIsBodyHtml; - private static Method setCharset; - private static Method setExpiredTime; - private static Method setAppID; - - @Autowired - private PortalConfig portalConfig; - - - @PostConstruct - public void init() { - try { - sendEmailRequestClazz = Class.forName("com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest"); - - setSendCode = sendEmailRequestClazz.getMethod("setSendCode", String.class); - setBodyTemplateID = sendEmailRequestClazz.getMethod("setBodyTemplateID", Integer.class); - setSender = sendEmailRequestClazz.getMethod("setSender", String.class); - setBodyContent = sendEmailRequestClazz.getMethod("setBodyContent", String.class); - setRecipient = sendEmailRequestClazz.getMethod("setRecipient", List.class); - setSubject = sendEmailRequestClazz.getMethod("setSubject", String.class); - setIsBodyHtml = sendEmailRequestClazz.getMethod("setIsBodyHtml", Boolean.class); - setCharset = sendEmailRequestClazz.getMethod("setCharset", String.class); - setExpiredTime = sendEmailRequestClazz.getMethod("setExpiredTime", Calendar.class); - setAppID = sendEmailRequestClazz.getMethod("setAppID", Integer.class); - - } catch (Throwable e) { - logger.error("init email request build failed", e); - Tracer.logError("init email request build failed", e); - } - } - - - public Object buildEmailRequest(Email email) throws Exception { - - Object emailRequest = createBasicEmailRequest(); - - setSender.invoke(emailRequest, email.getSenderEmailAddress()); - setSubject.invoke(emailRequest, email.getSubject()); - String emailBodyBuilder = "" + - email.getBody() + - "]]>"; - setBodyContent.invoke(emailRequest, emailBodyBuilder); - setRecipient.invoke(emailRequest, email.getRecipients()); - - return emailRequest; - } - - private Object createBasicEmailRequest() throws Exception { - Object request = sendEmailRequestClazz.newInstance(); - - setSendCode.invoke(request, portalConfig.sendCode()); - setBodyTemplateID.invoke(request, portalConfig.templateId()); - setIsBodyHtml.invoke(request, true); - setCharset.invoke(request, "UTF-8"); - setExpiredTime.invoke(request, calExpiredTime()); - setAppID.invoke(request, portalConfig.appId()); - - return request; - } - - - private Calendar calExpiredTime() { - - Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtils.addHours(new Date(), portalConfig.survivalDuration())); - - return calendar; - } - - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailService.java deleted file mode 100644 index 217073b696f..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailService.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.entity.bo.Email; -import com.ctrip.framework.apollo.portal.spi.EmailService; -import com.ctrip.framework.apollo.tracer.Tracer; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -import java.lang.reflect.Method; - -import javax.annotation.PostConstruct; - - -public class CtripEmailService implements EmailService { - - private static final Logger logger = LoggerFactory.getLogger(CtripEmailService.class); - - private Object emailServiceClient; - private Method sendEmailAsync; - private Method sendEmail; - - @Autowired - private CtripEmailRequestBuilder emailRequestBuilder; - @Autowired - private PortalConfig portalConfig; - - @PostConstruct - public void init() { - try { - initServiceClientConfig(); - - Class emailServiceClientClazz = - Class.forName("com.ctrip.framework.apolloctripservice.emailservice.EmailServiceClient"); - - Method getInstanceMethod = emailServiceClientClazz.getMethod("getInstance"); - emailServiceClient = getInstanceMethod.invoke(null); - - Class sendEmailRequestClazz = - Class.forName("com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest"); - sendEmailAsync = emailServiceClientClazz.getMethod("sendEmailAsync", sendEmailRequestClazz); - sendEmail = emailServiceClientClazz.getMethod("sendEmail", sendEmailRequestClazz); - } catch (Throwable e) { - logger.error("init ctrip email service failed", e); - Tracer.logError("init ctrip email service failed", e); - } - } - - private void initServiceClientConfig() throws Exception { - - Class serviceClientConfigClazz = Class.forName("com.ctriposs.baiji.rpc.client.ServiceClientConfig"); - Object serviceClientConfig = serviceClientConfigClazz.newInstance(); - Method setFxConfigServiceUrlMethod = serviceClientConfigClazz.getMethod("setFxConfigServiceUrl", String.class); - - setFxConfigServiceUrlMethod.invoke(serviceClientConfig, portalConfig.soaServerAddress()); - - Class serviceClientBaseClazz = Class.forName("com.ctriposs.baiji.rpc.client.ServiceClientBase"); - Method initializeMethod = serviceClientBaseClazz.getMethod("initialize", serviceClientConfigClazz); - initializeMethod.invoke(null, serviceClientConfig); - } - - @Override - public void send(Email email) { - - try { - Object emailRequest = emailRequestBuilder.buildEmailRequest(email); - - Object sendResponse = portalConfig.isSendEmailAsync() ? - sendEmailAsync.invoke(emailServiceClient, emailRequest) : - sendEmail.invoke(emailServiceClient, emailRequest); - - logger.info("Email server response: " + sendResponse); - - } catch (Throwable e) { - logger.error("send email failed", e); - Tracer.logError("send email failed", e); - } - - - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripLogoutHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripLogoutHandler.java deleted file mode 100644 index 2e34ed0a907..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripLogoutHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.spi.LogoutHandler; - -import org.springframework.beans.factory.annotation.Autowired; - -import java.io.IOException; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -public class CtripLogoutHandler implements LogoutHandler { - - @Autowired - private PortalConfig portalConfig; - - @Override - public void logout(HttpServletRequest request, HttpServletResponse response) { - //将session销毁 - HttpSession session = request.getSession(false); - if (session != null) { - session.invalidate(); - } - - Cookie cookie = new Cookie("memCacheAssertionID", null); - //将cookie的有效期设置为0,命令浏览器删除该cookie - cookie.setMaxAge(0); - cookie.setPath(request.getContextPath() + "/"); - response.addCookie(cookie); - - //重定向到SSO的logout地址 - String casServerUrl = portalConfig.casServerUrlPrefix(); - String serverName = portalConfig.portalServerName(); - - try { - response.sendRedirect(casServerUrl + "/logout?service=" + serverName); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripMQService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripMQService.java deleted file mode 100644 index aecb43620d9..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripMQService.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.google.gson.Gson; - -import com.ctrip.framework.apollo.common.entity.App; -import com.ctrip.framework.apollo.portal.environment.Env; -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.entity.bo.ReleaseHistoryBO; -import com.ctrip.framework.apollo.portal.service.AppService; -import com.ctrip.framework.apollo.portal.service.ReleaseService; -import com.ctrip.framework.apollo.portal.spi.MQService; -import com.ctrip.framework.apollo.tracer.Tracer; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.http.converter.FormHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.client.RestTemplate; - -import java.util.Arrays; - -import javax.annotation.PostConstruct; - - -public class CtripMQService implements MQService { - - private static final org.apache.commons.lang.time.FastDateFormat - TIMESTAMP_FORMAT = org.apache.commons.lang.time.FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss"); - private static final String CONFIG_PUBLISH_NOTIFY_TO_NOC_TOPIC = "ops.noc.record.created"; - - private static final Gson GSON = new Gson(); - - @Autowired - private AppService appService; - @Autowired - private ReleaseService releaseService; - @Autowired - private PortalConfig portalConfig; - - private RestTemplate restTemplate; - - @PostConstruct - public void init() { - restTemplate = new RestTemplate(); - - SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory(); - rf.setReadTimeout(portalConfig.readTimeout()); - rf.setConnectTimeout(portalConfig.connectTimeout()); - - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - converter.setSupportedMediaTypes( - Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.APPLICATION_OCTET_STREAM)); - - restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter())); - - } - - @Override - public void sendPublishMsg(Env env, ReleaseHistoryBO releaseHistory) { - if (releaseHistory == null) { - return; - } - - PublishMsg msg = buildPublishMsg(env, releaseHistory); - - sendMsg(portalConfig.hermesServerAddress(), CONFIG_PUBLISH_NOTIFY_TO_NOC_TOPIC, msg); - } - - private PublishMsg buildPublishMsg(Env env, ReleaseHistoryBO releaseHistory) { - - PublishMsg msg = new PublishMsg(); - - msg.setPriority("中"); - msg.setTool_origin("Apollo"); - - String appId = releaseHistory.getAppId(); - App app = appService.load(appId); - msg.setInfluence_bu(app.getOrgName()); - msg.setAppid(appId); - msg.setAssginee(releaseHistory.getOperator()); - msg.setOperation_time(TIMESTAMP_FORMAT.format(releaseHistory.getReleaseTime())); - msg.setDesc(GSON.toJson(releaseService.compare(env, releaseHistory.getPreviousReleaseId(), - releaseHistory.getReleaseId()))); - - return msg; - } - - private void sendMsg(String serverAddress, String topic, Object msg) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.parseMediaType(MediaType.APPLICATION_OCTET_STREAM + ";charset=UTF-8")); - HttpEntity request = new HttpEntity<>(msg, headers); - - try { - //send msg by hermes RestAPI - restTemplate.postForObject(serverAddress + "/topics/" + topic, request, Object.class); - - } catch (Exception e) { - Tracer.logError("Send publish msg to hermes failed", e); - } - - } - - private static class PublishMsg { - - private String assginee; - private String desc; - private String operation_time; - private String tool_origin; - private String priority; - private String influence_bu; - private String appid; - - - public String getAssginee() { - return assginee; - } - - public void setAssginee(String assginee) { - this.assginee = assginee; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getOperation_time() { - return operation_time; - } - - public void setOperation_time(String operation_time) { - this.operation_time = operation_time; - } - - public String getTool_origin() { - return tool_origin; - } - - public void setTool_origin(String tool_origin) { - this.tool_origin = tool_origin; - } - - public String getPriority() { - return priority; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public String getInfluence_bu() { - return influence_bu; - } - - public void setInfluence_bu(String influence_bu) { - this.influence_bu = influence_bu; - } - - public String getAppid() { - return appid; - } - - public void setAppid(String appid) { - this.appid = appid; - } - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserInfoHolder.java deleted file mode 100644 index afd3db9334c..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserInfoHolder.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; -import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; - -import java.lang.reflect.Method; - -/** - * ctrip内部实现的获取用户信息 - */ -public class CtripUserInfoHolder implements UserInfoHolder { - - private Object assertionHolder; - - private Method getAssertion; - - - public CtripUserInfoHolder() { - Class clazz = null; - try { - clazz = Class.forName("org.jasig.cas.client.util.AssertionHolder"); - assertionHolder = clazz.newInstance(); - getAssertion = assertionHolder.getClass().getMethod("getAssertion"); - } catch (Exception e) { - throw new RuntimeException("init AssertionHolder fail", e); - } - } - - @Override - public UserInfo getUser() { - try { - - Object assertion = getAssertion.invoke(assertionHolder); - Method getPrincipal = assertion.getClass().getMethod("getPrincipal"); - Object principal = getPrincipal.invoke(assertion); - Method getName = principal.getClass().getMethod("getName"); - String name = (String) getName.invoke(principal); - - UserInfo userInfo = new UserInfo(); - userInfo.setUserId(name); - - return userInfo; - } catch (Exception e) { - throw new RuntimeException("get user info from assertion holder error", e); - } - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserService.java deleted file mode 100644 index f9eb8dfe5fb..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserService.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; -import com.ctrip.framework.apollo.portal.spi.UserService; - -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.util.CollectionUtils; -import org.springframework.web.client.RestTemplate; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * @author Jason Song(song_s@ctrip.com) - */ -public class CtripUserService implements UserService { - private RestTemplate restTemplate; - private List searchUserMatchFields; - private ParameterizedTypeReference>> responseType; - private PortalConfig portalConfig; - - public CtripUserService(PortalConfig portalConfig) { - this.portalConfig = portalConfig; - this.restTemplate = new RestTemplate(clientHttpRequestFactory()); - this.searchUserMatchFields = - Lists.newArrayList("empcode", "empaccount", "displayname", "c_name", "pinyin"); - this.responseType = new ParameterizedTypeReference>>() { - }; - } - - private ClientHttpRequestFactory clientHttpRequestFactory() { - SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); - factory.setConnectTimeout(portalConfig.connectTimeout()); - factory.setReadTimeout(portalConfig.readTimeout()); - - return factory; - } - - @Override - public List searchUsers(String keyword, int offset, int limit) { - UserServiceRequest request = assembleSearchUserRequest(keyword, offset, limit); - - HttpEntity entity = new HttpEntity<>(request); - ResponseEntity>> response = - restTemplate.exchange(portalConfig.userServiceUrl(), HttpMethod.POST, entity, responseType); - - if (!response.getBody().containsKey("result")) { - return Collections.emptyList(); - } - - List result = Lists.newArrayList(); - result.addAll( - response.getBody().get("result").stream().map(this::transformUserServiceResponseToUserInfo) - .collect(Collectors.toList())); - - return result; - } - - @Override - public UserInfo findByUserId(String userId) { - List userInfoList = this.findByUserIds(Lists.newArrayList(userId)); - if (CollectionUtils.isEmpty(userInfoList)) { - return null; - } - return userInfoList.get(0); - } - - @Override - public List findByUserIds(List userIds) { - UserServiceRequest request = assembleFindUserRequest(Lists.newArrayList(userIds)); - - HttpEntity entity = new HttpEntity<>(request); - ResponseEntity>> response = - restTemplate.exchange(portalConfig.userServiceUrl(), HttpMethod.POST, entity, responseType); - - if (!response.getBody().containsKey("result")) { - return Collections.emptyList(); - } - - List result = Lists.newArrayList(); - result.addAll( - response.getBody().get("result").stream().map(this::transformUserServiceResponseToUserInfo) - .collect(Collectors.toList())); - - return result; - } - - private UserInfo transformUserServiceResponseToUserInfo(UserServiceResponse userServiceResponse) { - UserInfo userInfo = new UserInfo(); - userInfo.setUserId(userServiceResponse.getEmpaccount()); - userInfo.setName(userServiceResponse.getDisplayname()); - userInfo.setEmail(userServiceResponse.getEmail()); - return userInfo; - } - - UserServiceRequest assembleSearchUserRequest(String keyword, int offset, int limit) { - Map query = Maps.newHashMap(); - Map multiMatchMap = Maps.newHashMap(); - multiMatchMap.put("fields", searchUserMatchFields); - multiMatchMap.put("operator", "and"); - multiMatchMap.put("query", keyword); - multiMatchMap.put("type", "best_fields"); - query.put("multi_match", multiMatchMap); - - return assembleUserServiceRequest(query, offset, limit); - } - - UserServiceRequest assembleFindUserRequest(List userIds) { - Map - query = - ImmutableMap.of("filtered", ImmutableMap - .of("filter", ImmutableMap.of("terms", ImmutableMap.of("empaccount", userIds)))); - - return assembleUserServiceRequest(query, 0, userIds.size()); - } - - private UserServiceRequest assembleUserServiceRequest(Map query, int offset, - int limit) { - UserServiceRequest request = new UserServiceRequest(); - request.setAccess_token(portalConfig.userServiceAccessToken()); - - UserServiceRequestBody requestBody = new UserServiceRequestBody(); - requestBody.setIndexAlias("itdb_emloyee"); - requestBody.setType("emloyee"); - request.setRequest_body(requestBody); - - Map queryJson = Maps.newHashMap(); - requestBody.setQueryJson(queryJson); - - queryJson.put("query", query); - - queryJson.put("from", offset); - queryJson.put("size", limit); - - return request; - } - - - static class UserServiceRequest { - private String access_token; - private UserServiceRequestBody request_body; - - public String getAccess_token() { - return access_token; - } - - public void setAccess_token(String access_token) { - this.access_token = access_token; - } - - public UserServiceRequestBody getRequest_body() { - return request_body; - } - - public void setRequest_body( - UserServiceRequestBody request_body) { - this.request_body = request_body; - } - } - - static class UserServiceRequestBody { - private String indexAlias; - private String type; - private Map queryJson; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getIndexAlias() { - return indexAlias; - } - - public void setIndexAlias(String indexAlias) { - this.indexAlias = indexAlias; - } - - public Map getQueryJson() { - return queryJson; - } - - public void setQueryJson(Map queryJson) { - this.queryJson = queryJson; - } - } - - static class UserServiceResponse { - private String empaccount; - private String displayname; - private String email; - - public String getEmpaccount() { - return empaccount; - } - - public void setEmpaccount(String empaccount) { - this.empaccount = empaccount; - } - - public String getDisplayname() { - return displayname; - } - - public void setDisplayname(String displayname) { - this.displayname = displayname; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java deleted file mode 100644 index 2c960179791..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip; - -import com.ctrip.framework.apollo.portal.component.config.PortalConfig; -import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; -import com.ctrip.framework.apollo.portal.spi.ctrip.filters.UserAccessFilter; -import com.google.common.base.Strings; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.boot.web.servlet.ServletContextInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; - -@Configuration -@Profile("ctrip") -public class WebContextConfiguration { - - private final PortalConfig portalConfig; - private final UserInfoHolder userInfoHolder; - - public WebContextConfiguration(final PortalConfig portalConfig, final UserInfoHolder userInfoHolder) { - this.portalConfig = portalConfig; - this.userInfoHolder = userInfoHolder; - } - - @Bean - public ServletContextInitializer servletContextInitializer() { - return servletContext -> { - String loggingServerIP = portalConfig.cloggingUrl(); - String loggingServerPort = portalConfig.cloggingPort(); - String credisServiceUrl = portalConfig.credisServiceUrl(); - - servletContext.setInitParameter("loggingServerIP", - Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP); - servletContext.setInitParameter("loggingServerPort", - Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort); - servletContext.setInitParameter("credisServiceUrl", - Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl); - }; - } - - @Bean - public FilterRegistrationBean userAccessFilter() { - FilterRegistrationBean filter = new FilterRegistrationBean(); - filter.setFilter(new UserAccessFilter(userInfoHolder)); - filter.addUrlPatterns("/*"); - return filter; - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/filters/UserAccessFilter.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/filters/UserAccessFilter.java deleted file mode 100644 index 96968461258..00000000000 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/filters/UserAccessFilter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2021 Apollo 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. - * - */ -package com.ctrip.framework.apollo.portal.spi.ctrip.filters; - -import com.ctrip.framework.apollo.portal.constant.TracerEventType; -import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; -import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; -import com.ctrip.framework.apollo.tracer.Tracer; - -import com.google.common.base.Strings; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; - -import java.io.IOException; - -public class UserAccessFilter implements Filter { - - private static final String STATIC_RESOURCE_REGEX = ".*\\.(js|html|htm|png|css|woff2)$"; - - private UserInfoHolder userInfoHolder; - - public UserAccessFilter(UserInfoHolder userInfoHolder) { - this.userInfoHolder = userInfoHolder; - } - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - - String requestUri = ((HttpServletRequest) request).getRequestURI(); - - try { - if (!isOpenAPIRequest(requestUri) && !isStaticResource(requestUri)) { - UserInfo userInfo = userInfoHolder.getUser(); - if (userInfo != null) { - Tracer.logEvent(TracerEventType.USER_ACCESS, userInfo.getUserId()); - } - } - } catch (Throwable e) { - Tracer.logError("Record user access info error.", e); - } - - chain.doFilter(request, response); - } - - @Override - public void destroy() { - - } - - private boolean isOpenAPIRequest(String uri) { - return !Strings.isNullOrEmpty(uri) && uri.startsWith("/openapi"); - } - - private boolean isStaticResource(String uri) { - return !Strings.isNullOrEmpty(uri) && uri.matches(STATIC_RESOURCE_REGEX); - } - -} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java index ea45b6d1b4c..7a29dfc96a0 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ public void send(Email email) { static class HTMLDataSource implements DataSource { - private String html; + private final String html; HTMLDataSource(String htmlString) { html = htmlString; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultLogoutHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultLogoutHandler.java index 85120350adf..699625d8d02 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultLogoutHandler.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultLogoutHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultMQService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultMQService.java index 980865a15dd..a02240a0a00 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultMQService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultMQService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java index f20789ab383..4543c3e071a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java index 787dd714e3d..22505679fbf 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,13 +150,11 @@ public Set queryUsersWithRole(String roleName) { List userRoles = userRoleRepository.findByRoleId(role.getId()); - Set users = userRoles.stream().map(userRole -> { + return userRoles.stream().map(userRole -> { UserInfo userInfo = new UserInfo(); userInfo.setUserId(userRole.getUserId()); return userInfo; }).collect(Collectors.toSet()); - - return users; } /** diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultSsoHeartbeatHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultSsoHeartbeatHandler.java index e3f162d7a44..18ec729f8df 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultSsoHeartbeatHandler.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultSsoHeartbeatHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ public class DefaultSsoHeartbeatHandler implements SsoHeartbeatHandler { public void doHeartbeat(HttpServletRequest request, HttpServletResponse response) { try { response.sendRedirect("default_sso_heartbeat.html"); - } catch (IOException e) { + } catch (IOException ignore) { } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserInfoHolder.java index abe181447b5..15d7dbcb914 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserInfoHolder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserInfoHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java index a0d5cd2b64f..19f8f5b219e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java index b71cf9226f6..c753c31b88b 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/ApolloLdapAuthenticationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/FilterLdapByGroupUserSearch.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/FilterLdapByGroupUserSearch.java index 58301bc96fa..7f073014b2e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/FilterLdapByGroupUserSearch.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/FilterLdapByGroupUserSearch.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,17 +42,16 @@ public class FilterLdapByGroupUserSearch extends FilterBasedLdapUserSearch { private static final Logger logger = LoggerFactory.getLogger(FilterLdapByGroupUserSearch.class); private static final String MEMBER_UID_ATTR_NAME = "memberUid"; - private String searchBase; - private String groupBase; - private String groupSearch; - private String rdnKey; - private String groupMembershipAttrName; - private String loginIdAttrName; + private final String searchBase; + private final String groupBase; + private final String groupSearch; + private final String rdnKey; + private final String groupMembershipAttrName; + private final String loginIdAttrName; private final SearchControls searchControls = new SearchControls(); - private BaseLdapPathContextSource contextSource; - + private final BaseLdapPathContextSource contextSource; public FilterLdapByGroupUserSearch(String searchBase, String searchFilter, String groupBase, BaseLdapPathContextSource contextSource, String groupSearch, diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java index 1ea00fd1177..578bc705c9c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ldap/LdapUserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import java.util.TreeSet; import javax.naming.directory.Attribute; import javax.naming.ldap.LdapName; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.EmptyResultDataAccessException; @@ -135,7 +135,7 @@ public class LdapUserService implements UserService { /** * 用户信息Mapper */ - private ContextMapper ldapUserInfoMapper = (ctx) -> { + private final ContextMapper ldapUserInfoMapper = (ctx) -> { DirContextAdapter contextAdapter = (DirContextAdapter) ctx; UserInfo userInfo = new UserInfo(); userInfo.setUserId(contextAdapter.getStringAttribute(loginIdAttrName)); @@ -317,9 +317,7 @@ public List findByUserIds(List userIds) { return Collections.emptyList(); } if (StringUtils.isNotBlank(groupSearch)) { - List userListByGroup = searchUserInfoByGroup(groupBase, groupSearch, null, - userIds); - return userListByGroup; + return searchUserInfoByGroup(groupBase, groupSearch, null, userIds); } ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0)); userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId)); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/ExcludeClientCredentialsClientRegistrationRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/ExcludeClientCredentialsClientRegistrationRepository.java index 35d3ee4a232..1627709eb4f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/ExcludeClientCredentialsClientRegistrationRepository.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/ExcludeClientCredentialsClientRegistrationRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcAuthenticationSuccessEventListener.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcAuthenticationSuccessEventListener.java index 35f1784b67a..2d2f73f4a26 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcAuthenticationSuccessEventListener.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcAuthenticationSuccessEventListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserService.java index e782d8b1081..65512f42977 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java index 396deae4c95..0d31d4cd3eb 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLocalUserServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,9 @@ import com.ctrip.framework.apollo.portal.entity.po.UserPO; import com.ctrip.framework.apollo.portal.repository.UserRepository; import java.util.ArrayList; -import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLogoutHandler.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLogoutHandler.java index 68192b3965d..652a0182e1b 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLogoutHandler.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcLogoutHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcUserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcUserInfoHolder.java index c32304f1079..7ee19836ed7 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcUserInfoHolder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/OidcUserInfoHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/PlaceholderPasswordEncoder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/PlaceholderPasswordEncoder.java index 191bf047337..d7b32c01109 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/PlaceholderPasswordEncoder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/oidc/PlaceholderPasswordEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/package-info.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/package-info.java index bb13aa6a259..dc6bc01f6d3 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/package-info.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,7 @@ */ /** * This package defines common interfaces so that each company could provide their own implementations.
- * Currently we provide 2 implementations: Ctrip and Default.
- * Ctrip implementation will be activated only when spring.profiles.active = ctrip. - * So if spring.profiles.active is not ctrip, the default implementation will be activated. + * Currently we provide Default implementations: Default.
* You may refer com.ctrip.framework.apollo.portal.spi.configuration.AuthConfiguration when providing your own implementation. * * @see com.ctrip.framework.apollo.portal.spi.configuration.AuthConfiguration diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/ApolloPasswordEncoderFactory.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/ApolloPasswordEncoderFactory.java index 2ddff6b40c7..e4948bfe475 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/ApolloPasswordEncoderFactory.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/ApolloPasswordEncoderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/PasswordEncoderAdapter.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/PasswordEncoderAdapter.java index 6984fe953d9..6f22065aed5 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/PasswordEncoderAdapter.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/PasswordEncoderAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java index cf5635f012c..4290623a784 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java index 8f54680f8fd..55ebd651a2f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,20 +18,17 @@ import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; +import com.ctrip.framework.apollo.portal.entity.po.Authority; import com.ctrip.framework.apollo.portal.entity.po.UserPO; +import com.ctrip.framework.apollo.portal.repository.AuthorityRepository; import com.ctrip.framework.apollo.portal.repository.UserRepository; import com.ctrip.framework.apollo.portal.spi.UserService; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -41,41 +38,43 @@ */ public class SpringSecurityUserService implements UserService { - private final List authorities = Collections - .unmodifiableList(Arrays.asList(new SimpleGrantedAuthority("ROLE_user"))); - private final PasswordEncoder passwordEncoder; - private final JdbcUserDetailsManager userDetailsManager; - private final UserRepository userRepository; + private final AuthorityRepository authorityRepository; + public SpringSecurityUserService( PasswordEncoder passwordEncoder, - JdbcUserDetailsManager userDetailsManager, - UserRepository userRepository) { + UserRepository userRepository, + AuthorityRepository authorityRepository) { this.passwordEncoder = passwordEncoder; - this.userDetailsManager = userDetailsManager; this.userRepository = userRepository; + this.authorityRepository = authorityRepository; } @Transactional public void createOrUpdate(UserPO user) { String username = user.getUsername(); + String newPassword = passwordEncoder.encode(user.getPassword()); - User userDetails = new User(username, passwordEncoder.encode(user.getPassword()), authorities); - - if (userDetailsManager.userExists(username)) { - userDetailsManager.updateUser(userDetails); + UserPO managedUser = userRepository.findByUsername(username); + if (managedUser == null) { + user.setPassword(newPassword); + user.setEnabled(1); + userRepository.save(user); + + //save authorities + Authority authority = new Authority(); + authority.setUsername(username); + authority.setAuthority("ROLE_user"); + authorityRepository.save(authority); } else { - userDetailsManager.createUser(userDetails); + managedUser.setPassword(newPassword); + managedUser.setEmail(user.getEmail()); + managedUser.setUserDisplayName(user.getUserDisplayName()); + userRepository.save(managedUser); } - - UserPO managedUser = userRepository.findByUsername(username); - managedUser.setEmail(user.getEmail()); - managedUser.setUserDisplayName(user.getUserDisplayName()); - - userRepository.save(managedUser); } @Override diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java index 73ba87bee82..eed28b69f5d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigFileUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,20 @@ */ package com.ctrip.framework.apollo.portal.util; +import com.ctrip.framework.apollo.common.dto.ClusterDTO; +import com.ctrip.framework.apollo.common.entity.App; +import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.portal.controller.ConfigsImportController; import com.ctrip.framework.apollo.portal.environment.Env; + import com.google.common.base.Splitter; + import java.io.File; import java.util.List; + import org.springframework.web.multipart.MultipartFile; /** @@ -32,6 +38,10 @@ */ public class ConfigFileUtils { + public static final String APP_METADATA_FILENAME = "app.metadata"; + public static final String CLUSTER_METADATA_FILE_SUFFIX = ".cluster.metadata"; + public static final String APP_NAMESPACE_METADATA_FILE_SUFFIX = ".appnamespace.metadata"; + public static void check(MultipartFile file) { checkEmpty(file); final String originalFilename = file.getOriginalFilename(); @@ -168,7 +178,7 @@ public static String toFilename( * file path = ownerName/appId/env/configFilename * @return file path in compressed file */ - public static String toFilePath( + public static String genNamespacePath( final String ownerName, final String appId, final Env env, @@ -176,4 +186,27 @@ public static String toFilePath( ) { return String.join(File.separator, ownerName, appId, env.getName(), configFilename); } + + /** + * path = ownerName/appId/app.metadata + */ + public static String genAppInfoPath(App app) { + return String.join(File.separator, app.getOwnerName(), app.getAppId(), APP_METADATA_FILENAME); + } + + /** + * path = {appNamespace}.appnamespace.metadata + */ + public static String genAppNamespaceInfoPath(AppNamespace appNamespace) { + return String.join(File.separator, + appNamespace.getAppId() + "+" + appNamespace.getName() + APP_NAMESPACE_METADATA_FILE_SUFFIX); + } + + /** + * path = ownerName/appId/env/${clusterName}.metadata + */ + public static String genClusterInfoPath(App app, Env env, ClusterDTO cluster) { + return String.join(File.separator, app.getOwnerName(), app.getAppId(), env.getName(), + cluster.getName() + CLUSTER_METADATA_FILE_SUFFIX); + } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java index c5df7f53fb9..725fa00fb96 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/KeyValueUtils.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/KeyValueUtils.java index dd416a5cef9..48f86265627 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/KeyValueUtils.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/KeyValueUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/NamespaceBOUtils.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/NamespaceBOUtils.java index bbb9dad8a19..f5e322aab4e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/NamespaceBOUtils.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/NamespaceBOUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,24 +16,36 @@ */ package com.ctrip.framework.apollo.portal.util; +import com.google.common.collect.Lists; +import com.google.gson.Gson; + +import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.utils.PropertiesUtil; import com.ctrip.framework.apollo.portal.controller.ConfigsExportController; import com.ctrip.framework.apollo.portal.entity.bo.ItemBO; import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO; + +import org.springframework.util.CollectionUtils; + import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; /** * @author wxq */ public class NamespaceBOUtils { + private static final Gson GSON = new Gson(); + /** - * namespace must not be {@link ConfigFileFormat#Properties}. - * the content of namespace in item's value which item's key is {@link ConfigConsts#CONFIG_FILE_CONTENT_KEY}. + * namespace must not be {@link ConfigFileFormat#Properties}. the content of namespace in item's value which item's + * key is {@link ConfigConsts#CONFIG_FILE_CONTENT_KEY}. + * * @param namespaceBO namespace * @return content of non-properties's namespace */ @@ -43,17 +55,18 @@ static String convertNonProperties2configFileContent(NamespaceBO namespaceBO) { String key = itemBO.getItem().getKey(); // special namespace format(not properties) if (ConfigConsts.CONFIG_FILE_CONTENT_KEY.equals(key)) { - return itemBO.getItem().getValue(); + ItemDTO dto = itemBO.getItem(); + dto.setId(0); + dto.setNamespaceId(0); + return GSON.toJson(Lists.newArrayList(dto)); } } - // If there is no items? - // return empty string "" return ""; } /** - * copy from old {@link ConfigsExportController}. - * convert {@link NamespaceBO} to a file content. + * copy from old {@link ConfigsExportController}. convert {@link NamespaceBO} to a file content. + * * @return content of config file * @throws IllegalStateException if convert properties to string fail */ @@ -66,23 +79,18 @@ public static String convert2configFileContent(NamespaceBO namespaceBO) { // it must be a properties format namespace List itemBOS = namespaceBO.getItems(); - // save the kev value pair - Properties properties = new Properties(); - for (ItemBO itemBO : itemBOS) { - String key = itemBO.getItem().getKey(); - String value = itemBO.getItem().getValue(); - // ignore comment, so the comment will lack - properties.put(key, value); + if (CollectionUtils.isEmpty(itemBOS)) { + return GSON.toJson(Collections.emptyList()); } - // use a special method convert properties to string - final String configFileContent; - try { - configFileContent = PropertiesUtil.toString(properties); - } catch (IOException e) { - throw new IllegalStateException("convert properties to string fail.", e); - } - return configFileContent; + List itemDTOS = itemBOS.stream().map(itemBO -> { + ItemDTO dto = itemBO.getItem(); + dto.setId(0); + dto.setNamespaceId(0); + return dto; + }).collect(Collectors.toList()); + + return GSON.toJson(itemDTOS); } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java index 7e5e7e97057..072915f969e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RelativeDateFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,16 @@ */ package com.ctrip.framework.apollo.portal.util; -import org.apache.commons.lang.time.FastDateFormat; +import org.apache.commons.lang3.time.FastDateFormat; -import java.util.Calendar; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Date; - public class RelativeDateFormat { private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd"); - private static final long ONE_MINUTE = 60000L; - private static final long ONE_HOUR = 3600000L; - private static final long ONE_DAY = 86400000L; private static final String ONE_SECOND_AGO = " seconds ago"; private static final String ONE_MINUTE_AGO = " minutes ago"; @@ -35,80 +34,34 @@ public class RelativeDateFormat { private static final String ONE_MONTH_AGO = " months ago"; public static String format(Date date) { - if (date.after(new Date())) { - return "now"; - } - - long delta = new Date().getTime() - date.getTime(); - if (delta < ONE_MINUTE) { - long seconds = toSeconds(delta); - return (seconds <= 0 ? 1 : seconds) + ONE_SECOND_AGO; - } - if (delta < 45L * ONE_MINUTE) { - long minutes = toMinutes(delta); - return (minutes <= 0 ? 1 : minutes) + ONE_MINUTE_AGO; - } - if (delta < 24L * ONE_HOUR) { - long hours = toHours(delta); - return (hours <= 0 ? 1 : hours) + ONE_HOUR_AGO; - } - - Date lastDayBeginTime = getDateOffset(-1); - if (date.after(lastDayBeginTime)) { - return "yesterday"; - } - Date lastTwoDaysBeginTime = getDateOffset(-2); - if (date.after(lastTwoDaysBeginTime)) { - return "the day before yesterday"; - } - if (delta < 30L * ONE_DAY) { - long days = toDays(delta); - return (days <= 0 ? 1 : days) + ONE_DAY_AGO; - } - - long months = toMonths(delta); - if (months <= 3) { - return (months <= 0 ? 1 : months) + ONE_MONTH_AGO; + Instant instant = date.toInstant(); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); + Duration duration = Duration.between(localDateTime, LocalDateTime.now()); + if (duration.toMillis() <= 0L) { + return "now"; + } + if (duration.getSeconds() <= 60L) { + return (duration.getSeconds() <= 0 ? 1 : duration.getSeconds()) + ONE_SECOND_AGO; + } + if (duration.toMinutes() < 45L) { + return (duration.toMinutes() <= 0 ? 1 : duration.toMinutes()) + ONE_MINUTE_AGO; + } + if (duration.toHours() < 24L) { + return (duration.toHours() <= 0 ? 1 : duration.toHours()) + ONE_HOUR_AGO; + } + if (localDateTime.isAfter(LocalDateTime.now().minusDays(1))) { + return "yesterday"; + } + if (localDateTime.isAfter(LocalDateTime.now().minusDays(2))) { + return "the day before yesterday"; + } + if (duration.toDays() < 30L) { + return (duration.toDays() <= 0 ? 1 : duration.toDays()) + ONE_DAY_AGO; + } + if (duration.toDays() / 30 <= 3L) { + return duration.toDays() / 30 + ONE_MONTH_AGO; + } + return TIMESTAMP_FORMAT.format(date); } - return TIMESTAMP_FORMAT.format(date); - } - - private static long toSeconds(long date) { - return date / 1000L; - } - - private static long toMinutes(long date) { - return toSeconds(date) / 60L; - } - - private static long toHours(long date) { - return toMinutes(date) / 60L; - } - - private static long toDays(long date) { - return toHours(date) / 24L; - } - - private static long toMonths(long date) { - return toDays(date) / 30L; - } - - public static Date getDateOffset(int offset) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.DATE, offset); - - return getDayBeginTime(calendar.getTime()); - } - - private static Date getDayBeginTime(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.set(Calendar.HOUR, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - return new Date(calendar.getTime().getTime()); - } - } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java index 9bd7ab7d22d..03d2a2136e6 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 Apollo Authors + * Copyright 2022 Apollo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/AuthUserPasswordChecker.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/AuthUserPasswordChecker.java new file mode 100644 index 00000000000..0a0b7849221 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/AuthUserPasswordChecker.java @@ -0,0 +1,66 @@ +/* + * Copyright 2022 Apollo 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. + * + */ +package com.ctrip.framework.apollo.portal.util.checker; + +import com.ctrip.framework.apollo.portal.component.config.PortalConfig; +import com.google.common.base.Strings; +import java.util.List; +import java.util.regex.Pattern; +import org.springframework.stereotype.Component; + +@Component +public class AuthUserPasswordChecker implements UserPasswordChecker { + + private static final Pattern PWD_PATTERN = Pattern + .compile("^(?=.*[0-9].*)(?=.*[a-zA-Z].*).{8,20}$"); + + private final PortalConfig portalConfig; + + public AuthUserPasswordChecker(final PortalConfig portalConfig) { + this.portalConfig = portalConfig; + } + + @Override + public CheckResult checkWeakPassword(String password) { + if (Strings.isNullOrEmpty(password) || !PWD_PATTERN.matcher(password).matches()) { + return new CheckResult(Boolean.FALSE, + "Password needs a number and letter and between 8~20 characters"); + } + if (isCommonlyUsed(password)) { + return new CheckResult(Boolean.FALSE, + "Passwords cannot be consecutive, regular letters or numbers. And cannot be commonly used. " + + "e.g: abcd1234, 1234qwer, 1q2w3e4r, 1234asdfghjk, ..."); + } + return new CheckResult(Boolean.TRUE, null); + } + + /** + * @return The password contains code fragment. + */ + private boolean isCommonlyUsed(String password) { + List list = portalConfig.getUserPasswordNotAllowList(); + if (list == null || list.isEmpty()) { + return false; + } + for (String s : list) { + if (password.toLowerCase().contains(s)) { + return true; + } + } + return false; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/CheckResult.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/CheckResult.java new file mode 100644 index 00000000000..6c745bc77ac --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/CheckResult.java @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Apollo 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. + * + */ +package com.ctrip.framework.apollo.portal.util.checker; + +public class CheckResult { + + private final boolean success; + private final String message; + + public CheckResult(boolean success, String message) { + this.success = success; + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public String getMessage() { + return message; + } +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/UserPasswordChecker.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/UserPasswordChecker.java new file mode 100644 index 00000000000..52c6862e860 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/checker/UserPasswordChecker.java @@ -0,0 +1,22 @@ +/* + * Copyright 2022 Apollo 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. + * + */ +package com.ctrip.framework.apollo.portal.util.checker; + +public interface UserPasswordChecker { + + CheckResult checkWeakPassword(String password); +} diff --git a/apollo-portal/src/main/resources/META-INF/app.properties b/apollo-portal/src/main/resources/META-INF/app.properties index 2d8973969e0..a7379b3bf68 100644 --- a/apollo-portal/src/main/resources/META-INF/app.properties +++ b/apollo-portal/src/main/resources/META-INF/app.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/resources/apollo-env.properties b/apollo-portal/src/main/resources/apollo-env.properties index d3375faa58b..617c8e64232 100644 --- a/apollo-portal/src/main/resources/apollo-env.properties +++ b/apollo-portal/src/main/resources/apollo-env.properties @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/resources/application-ctrip.yml b/apollo-portal/src/main/resources/application-ctrip.yml index d60e4935651..b90363195f8 100644 --- a/apollo-portal/src/main/resources/application-ctrip.yml +++ b/apollo-portal/src/main/resources/application-ctrip.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/apollo-portal/src/main/resources/application.yml b/apollo-portal/src/main/resources/application.yml index 34b3fffedda..d8c88cd9828 100644 --- a/apollo-portal/src/main/resources/application.yml +++ b/apollo-portal/src/main/resources/application.yml @@ -1,5 +1,5 @@ # -# Copyright 2021 Apollo Authors +# Copyright 2022 Apollo Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,17 @@ spring: jpa: properties: hibernate: + metadata_builder_contributor: com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor query: plan_cache_max_size: 192 # limit query plan cache max size session: store-type: jdbc jdbc: initialize-schema: never + servlet: + multipart: + max-file-size: 200MB # import data configs + max-request-size: 200MB server: port: 8070 compression: diff --git a/apollo-portal/src/main/resources/logback.xml b/apollo-portal/src/main/resources/logback.xml index 2904cfdd65a..ea375200221 100644 --- a/apollo-portal/src/main/resources/logback.xml +++ b/apollo-portal/src/main/resources/logback.xml @@ -1,6 +1,6 @@ +
@@ -446,10 +450,12 @@