You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2023/10/10 01:47:25 UTC
[servicecomb-java-chassis] branch master updated (eec5b5cb8 -> a72776737)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
from eec5b5cb8 [SCB-2811] support global route rule for gray (#3948)
new 7395e9221 [SCB-2008]change DynamicPropertyFactory to Environment: in huawei cloud
new 5f660e28c [SCB-2008]change DynamicPropertyFactory to Environment: in common rest
new 97c4c7a99 [SCB-2008]change DynamicPropertyFactory to Environment: in edge
new f2c562ddf [SCB-2008]allows not injectable property in model
new afddef347 [SCB-2008]change DynamicPropertyFactory to Environment: in public key
new d27969a56 [SCB-2008]change DynamicPropertyFactory to Environment: in edge core
new 55f827169 [SCB-2008]remove archaius dependency: apollo adapter
new c8c647922 [SCB-2008]remove archaius dependency: apollo adapter
new 42d07fd84 [SCB-2008]remove archaius dependency: cc adapter
new 8d2d91a1f [SCB-2008]remove archaius dependency: kie adapter
new 3e24ad182 [SCB-2008]remove archaius dependency: nacos adapter
new 58c036983 [SCB-2008]remove archaius dependency: fix tests
new c2437e376 [SCB-2008]remove archaius dependency: remove ArchaiusUtils usage
new 4120fa790 [SCB-2008]remove archaius dependency: remove ArchaiusUtils usage and DynamicProperty
new ccd96f164 [SCB-2008]remove archaius dependency: remove Archaius dependency
new 133732780 [SCB-2008]remove inspector module
new a1cc01d06 [SCB-2008]adapt DynamicProperties
new ef42dbac0 [SCB-2008]remove deployment module
new d9a431d08 [SCB-2008]remove ConfigUtil methods
new f4ac0ec8b [SCB-2008]remove archaius adapters
new bf0b2fc1d [SCB-2008]priority property adapter
new 1a9b3ffd7 [SCB-2008]remove un-maintained jsr305 usages
new 4b6272350 [SCB-2008]remove commons-configuration usage
new cb657eb66 [SCB-2008]fix test case error
new a72776737 [SCB-2008]fix rebase code error
The 25 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../common/rest/RestProducerInvocationCreator.java | 15 +-
.../rest/RestVertxProducerInvocationCreator.java | 6 +-
.../rest/codec/param/BodyProcessorCreator.java | 6 +-
.../rest/codec/param/HeaderProcessorCreator.java | 6 +-
.../rest/codec/param/QueryProcessorCreator.java | 14 +-
.../rest/codec/query/AbstractQueryCodec.java | 7 +-
.../common/rest/codec/query/QueryCodec.java | 12 +-
.../common/rest/codec/query/QueryCodecMulti.java | 4 +-
.../rest/codec/query/QueryCodecWithDelimiter.java | 7 +-
.../common/rest/codec/query/QueryCodecs.java | 8 +-
.../common/rest/codec/query/QueryCodecsUtils.java | 3 -
.../rest/definition/path/URLPathBuilder.java | 4 +-
.../rest/filter/inner/RestServerCodecFilter.java | 3 -
.../rest/RestProducerInvocationCreatorTest.java | 14 +-
.../common/rest/TestRestEngineSchemaListener.java | 12 +-
.../common/rest/codec/TestRestCodec.java | 16 +
.../common/rest/codec/param/TestBodyProcessor.java | 6 +
.../rest/codec/param/TestBodyProcessorCreator.java | 13 +
.../rest/codec/param/TestHeaderProcessor.java | 15 +-
.../codec/param/TestHeaderProcessorCreator.java | 13 +
.../rest/codec/param/TestQueryProcessor.java | 16 +
.../codec/param/TestQueryProcessorCreator.java | 21 +-
.../common/rest/codec/query/QueryCodecCsvTest.java | 17 ++
.../rest/codec/query/QueryCodecMultiTest.java | 14 +
.../rest/codec/query/QueryCodecPipesTest.java | 17 ++
.../common/rest/codec/query/QueryCodecSsvTest.java | 19 +-
.../common/rest/definition/TestPath.java | 15 +
.../rest/definition/TestRestOperationMeta.java | 8 +-
.../definition/path/QueryVarParamWriterTest.java | 13 +
.../rest/definition/path/URLPathBuilderTest.java | 17 ++
.../filter/inner/RestServerCodecFilterTest.java | 8 +-
.../common/rest/locator/TestMicroservicePaths.java | 10 +-
.../rest/locator/TestServicePathManager.java | 20 +-
core/pom.xml | 4 -
.../core/ConfigurationSpringInitializer.java | 194 +-----------
.../org/apache/servicecomb/core/SCBEngine.java | 4 +-
.../core/ServiceCombCoreConfiguration.java | 8 +-
.../servicecomb/core/bootstrap/SCBBootstrap.java | 5 +-
.../core/bootstrap/SCBEngineForTest.java | 6 +-
.../core/exception/DefaultExceptionProcessor.java | 15 +-
.../core/exception/ExceptionConverter.java | 7 +-
.../core/exception/ExceptionProcessor.java | 18 +-
.../servicecomb/core/exception/Exceptions.java | 14 +-
.../ConnectTimeoutExceptionConverter.java | 6 +-
.../converter/DefaultExceptionConverter.java | 8 +-
.../IllegalArgumentExceptionConverter.java | 7 +-
.../converter/InvocationExceptionConverter.java | 7 +-
.../converter/ServiceCombExceptionConverter.java | 9 +-
.../converter/TimeoutExceptionConverter.java | 7 +-
.../servicecomb/core/executor/ExecutorManager.java | 12 +-
.../servicecomb/core/filter/ConsumerFilter.java | 3 -
.../org/apache/servicecomb/core/filter/Filter.java | 3 -
.../servicecomb/core/filter/ProviderFilter.java | 3 -
.../servicecomb/core/filter/impl/EmptyFilter.java | 3 -
.../core/filter/impl/ParameterValidatorFilter.java | 3 -
.../core/filter/impl/ProviderOperationFilter.java | 3 -
.../core/filter/impl/ScheduleFilter.java | 3 -
.../ServiceCombConfigurationEventAdapter.java | 21 +-
.../core/provider/consumer/InvokerUtils.java | 6 +-
.../core/TestConfigurationSpringInitializer.java | 98 +-----
.../core/TestSCBApplicationListener.java | 6 +-
.../servicecomb/core/exception/ExceptionsTest.java | 6 +-
.../core/executor/TestExecutorManager.java | 14 +-
.../core/executor/TestGroupExecutor.java | 2 -
.../servicecomb/core/filter/SimpleRetryFilter.java | 3 -
.../filter/impl/ParameterValidatorFilterTest.java | 3 +-
.../producer/TestProducerBootListener.java | 68 +----
.../producer/TestProducerProviderManager.java | 2 +-
.../discovery/TestEndpointDiscoveryFilter.java | 6 +-
.../core/tracing/BraveTraceIdGeneratorTest.java | 2 +-
coverage-reports/pom.xml | 12 -
...CustomExceptionToProducerResponseConverter.java | 9 +-
.../service/encrypt/filter/DecodeBodyFilter.java | 3 -
.../encrypt/filter/EdgeSignatureRequestFilter.java | 3 -
.../filter/EdgeSignatureResponseFilter.java | 3 -
.../edge/service/encrypt/filter/UserIdFilter.java | 3 -
.../demo/edge/service/handler/AuthHandler.java | 3 -
.../apache/servicecomb/demo/jaxrs/JaxrsClient.java | 10 +-
.../pojoDefault/DefaultModelServiceClient.java | 4 +-
.../client/validation/ValidationServiceClient.java | 8 +-
.../servicecomb/demo/pojo/client/PojoClient.java | 8 +-
.../demo/CategorizedTestCaseRunner.java | 4 +-
.../servicecomb/demo/CodeFirstRestTemplate.java | 4 +-
.../springboot/pojo/client/PojoClientTest.java | 4 +-
.../springboot/pojo/server/handler/MyHandler.java | 3 -
.../springmvc/server/SpringmvcServer.java | 11 +-
.../demo/springmvc/SpringmvcClient.java | 4 +-
.../demo/springmvc/filter/ProviderTestFilter.java | 3 -
dependencies/bom/pom.xml | 15 +-
dependencies/default/pom.xml | 26 --
deployment/README.md | 13 -
deployment/pom.xml | 71 -----
.../apache/servicecomb/deployment/Deployment.java | 35 ---
.../servicecomb/deployment/DeploymentProvider.java | 27 --
.../deployment/SystemBootstrapInfo.java | 47 ---
.../deployment/CustomDeploymentProvider.java | 48 ---
.../servicecomb/deployment/TestDeployment.java | 39 ---
...pache.servicecomb.deployment.DeploymentProvider | 18 --
distribution/pom.xml | 12 -
.../config/{client => apollo}/ApolloClient.java | 48 ++-
.../config/{client => apollo}/ApolloConfig.java | 35 +--
.../config/apollo/ApolloConfiguration.java | 13 +-
.../apollo/ApolloDynamicPropertiesSource.java | 87 ++++++
.../{client => apollo}/ConfigurationAction.java | 2 +-
.../sources/ApolloConfigurationSourceImpl.java | 147 ---------
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +-
.../{client => apollo}/ApolloClientTest.java | 28 +-
.../sources/ApolloConfigurationSourceImplTest.java | 78 -----
.../config/client/ApolloConfigTest.java | 43 ---
dynamic-config/config-cc/pom.xml | 4 -
.../servicecomb/config/ConfigCenterConfig.java | 138 ---------
.../servicecomb/config/cc/ConfigCenterConfig.java | 89 ++++++
.../config/{ => cc}/ConfigCenterConfiguration.java | 14 +-
.../ConfigCenterDynamicPropertiesSource.java} | 145 ++++-----
.../ConfigCenterInformationCollector.java | 20 +-
.../config/{ => cc}/TransportUtils.java | 54 ++--
.../ConfigCenterDefaultDeploymentProvider.java | 53 ----
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
...vicecomb.core.bootup.BootUpInformationCollector | 2 +-
...pache.servicecomb.deployment.DeploymentProvider | 17 --
...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +-
.../ConfigCenterAddressManagerTest.java | 3 +-
.../ConfigCenterConfigurationSourceImplTest.java | 2 +-
.../TestConfigCenterDefaultDeploymentProvider.java | 67 -----
dynamic-config/config-kie/pom.xml | 4 -
.../apache/servicecomb/config/kie/KieConfig.java | 83 ++---
.../config/kie/KieConfigConfiguration.java | 11 +
...ceImpl.java => KieDynamicPropertiesSource.java} | 155 ++++------
.../servicecomb/config/kie/TransportUtils.java | 52 ++--
.../KieCenterDefaultDeploymentProvider.java | 53 ----
.../kie/collect/KieClientInformationCollector.java | 19 +-
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
...pache.servicecomb.deployment.DeploymentProvider | 17 --
.../TestKieCenterDefaultDeploymentProvider.java | 69 -----
.../nacos/{client => }/ConfigurationAction.java | 2 +-
.../config/nacos/{client => }/NacosClient.java | 38 ++-
.../config/nacos/{client => }/NacosConfig.java | 27 +-
.../config/nacos/NacosConfigConfiguration.java | 15 +-
.../config/nacos/NacosDynamicPropertiesSource.java | 89 ++++++
.../sources/NacosConfigurationSourceImpl.java | 145 ---------
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +-
.../config/nacos/{client => }/NacosClientTest.java | 17 +-
.../sources/NacosConfigurationSourceImplTest.java | 74 -----
.../config/nacos/client/NacosConfigTest.java | 38 ---
.../edge/core/CommonHttpEdgeDispatcher.java | 40 ++-
.../edge/core/DefaultEdgeDispatcher.java | 21 +-
.../servicecomb/edge/core/EdgeAddHeaderFilter.java | 36 ++-
.../servicecomb/edge/core/EdgeBootListener.java | 26 +-
.../edge/core/EdgeCoreConfiguration.java | 5 +-
.../edge/core/EdgeServerCodecFilter.java | 4 -
.../edge/core/URLMappedConfigurationLoader.java | 30 +-
.../edge/core/URLMappedEdgeDispatcher.java | 39 ++-
.../edge/core/TestEdgeBootListener.java | 77 -----
.../edge/core/TestURLMappedEdgeDispatcher.java | 63 +++-
foundations/foundation-common/pom.xml | 4 -
.../foundation/common/LegacyPropertyFactory.java | 5 +-
.../foundation/common/utils/KeyPairUtils.java | 15 +-
.../foundation/common/utils/TestRSAUtil.java | 21 +-
foundations/foundation-config/pom.xml | 9 +-
.../servicecomb/config/BootStrapProperties.java | 166 +++-------
.../config/ConcurrentMapConfigurationExt.java | 53 ----
.../apache/servicecomb/config/ConfigMapping.java | 12 +-
.../org/apache/servicecomb/config/ConfigUtil.java | 287 +++---------------
.../config}/ConfigurationChangedEvent.java | 38 ++-
.../config/DynamicConfigurationExt.java | 34 ---
.../servicecomb/config/DynamicProperties.java | 4 -
.../servicecomb/config/DynamicPropertiesImpl.java | 165 +++++++---
.../config/DynamicPropertiesSource.java} | 8 +-
.../config/DynamicWatchedConfigurationExt.java | 75 -----
.../config/FoundationConfigConfiguration.java | 13 +-
.../config/InMemoryDynamicPropertiesSource.java | 56 ++++
.../scheduler/NeverStartPollingScheduler.java | 35 ---
.../config/archaius/sources/ConfigSourceMaker.java | 28 --
.../sources/MicroserviceConfigurationSource.java | 49 ---
.../event/DynamicConfigurationChangedEvent.java | 32 --
.../event/RefreshGovernanceConfigurationEvent.java | 32 --
.../sources => file}/AbstractConfigLoader.java | 2 +-
.../{archaius/sources => file}/ConfigModel.java | 2 +-
.../sources => file}/MicroserviceConfigLoader.java | 2 +-
.../sources => file}/YAMLConfigLoader.java | 2 +-
.../config/inject/PlaceholderResolver.java | 4 +-
.../config/priority/ConfigObjectFactory.java | 15 +-
.../config/priority/ConfigObjectProperty.java | 5 +-
.../config/priority/DynamicProperty.java | 47 ++-
.../config/priority/PriorityProperty.java | 11 +-
.../config/priority/PriorityPropertyFactory.java | 38 +--
.../config/priority/PriorityPropertyManager.java | 35 +--
.../spi/ConfigCenterConfigurationSource.java | 35 ---
.../spi/ConfigCenterConfigurationSourceLoader.java | 42 ---
.../config/BootStrapPropertiesTest.java | 76 ++---
.../servicecomb/config/DynamicPropertiesTest.java | 70 +++--
.../config/MapBasedConfigurationSource.java | 103 -------
.../apache/servicecomb/config/TestConfigUtil.java | 335 ---------------------
.../sources/TestYAMLConfigurationSource.java | 98 ------
.../TestMicroserviceConfigLoader.java | 2 +-
.../config/inject/TestConfigObjectFactory.java | 242 ++++++++++-----
.../config/priority/TestPriorityProperty.java | 147 ++++-----
.../config/priority/TestPriorityPropertyBase.java | 24 +-
.../priority/TestPriorityPropertyManager.java | 16 +-
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
.../src/test/resources/microservice.yaml | 6 -
foundations/foundation-metrics/pom.xml | 4 -
.../internal/parser/ContentFileReader.java | 4 +-
.../registry/config/ConfigurePropertyUtils.java | 55 ----
.../registry/discovery/TestDiscoveryTree.java | 5 +-
foundations/foundation-test-scaffolding/pom.xml | 9 -
.../test/scaffolding/config/ArchaiusUtils.java | 83 -----
.../foundation/vertx/TestVertxUtils.java | 3 -
.../http/TestStandardHttpServletResponseEx.java | 2 +-
.../foundation/vertx/stream/TestPumpFromPart.java | 7 +-
.../faultinjection/ConsumerAbortFaultFilter.java | 3 -
.../faultinjection/ConsumerDelayFaultFilter.java | 3 -
.../TestConsumerAbortFaultFilter.java | 28 --
.../java/org/apache/servicecomb/qps/Config.java | 2 +
.../servicecomb/qps/ConsumerFlowControlFilter.java | 10 +-
.../qps/FlowControlQpsConfiguration.java | 9 +-
.../servicecomb/qps/ProviderFlowControlFilter.java | 10 +-
.../servicecomb/qps/QpsControllerManager.java | 96 ++----
.../servicecomb/qps/QpsControllerManagerTest.java | 63 ++--
.../governance/ConsumerInstanceBulkheadFilter.java | 5 +-
.../ConsumerInstanceIsolationFilter.java | 3 -
.../handler/governance/ProviderBulkheadFilter.java | 3 -
.../governance/ProviderCircuitBreakerFilter.java | 3 -
.../governance/ProviderRateLimitingFilter.java | 3 -
handlers/handler-loadbalance/pom.xml | 4 -
.../servicecomb/loadbalance/Configuration.java | 4 +-
.../servicecomb/loadbalance/LoadBalanceFilter.java | 3 -
.../servicecomb/loadbalance/TestConfiguration.java | 23 --
.../loadbalance/TestLoadBalanceCreator.java | 3 -
.../loadbalance/TestLoadBalanceFilter.java | 6 +-
.../loadbalance/TestLoadBalanceFilter2.java | 6 -
.../TestInstancePropertyDiscoveryFilter.java | 62 ++--
.../AuthenticationConfiguration.java | 7 +
.../consumer/ConsumerAuthFilter.java | 3 -
.../authentication/provider/AccessController.java | 54 ++--
.../provider/ProviderAuthFilter.java | 3 -
.../provider/ProviderTokenManager.java | 7 +-
.../authentication/TestAccessController.java | 186 +++++++++---
.../TestAuthenticationBootListener.java | 27 +-
.../authentication/TestRSAAuthenticationToken.java | 20 ++
.../provider/TestProviderTokenManager.java | 34 ++-
.../router/custom/RouterAddHeaderFilter.java | 3 -
.../tracing/zipkin/TracingConfiguration.java | 5 +-
.../tracing/zipkin/ZipkinTracingFilter.java | 3 -
.../darklaunch/DarklaunchServerListFilter.java | 10 +-
huawei-cloud/dashboard/pom.xml | 4 -
.../dashboard/monitor/DashboardConfiguration.java | 7 +
.../huaweicloud/dashboard/monitor/DataFactory.java | 12 +-
.../monitor/DefaultMonitorDataPublisher.java | 47 +--
.../monitor/MetricsMonitorDataProvider.java | 22 +-
.../dashboard/monitor/MonitorBootListener.java | 10 +-
.../monitor/MonitorDefaultDeploymentProvider.java | 56 ----
.../monitor/MonitorInformationCollector.java | 22 +-
.../dashboard/monitor/TransportUtils.java | 52 ++--
.../dashboard/monitor/data/MonitorConstant.java | 109 +++----
...pache.servicecomb.deployment.DeploymentProvider | 17 --
.../huaweicloud/servicestage/CasEnvConfig.java | 39 ++-
.../huaweicloud/servicestage/TestCasEnvConfig.java | 55 ----
inspector/pom.xml | 72 -----
.../inspector/internal/InspectorBootListener.java | 67 -----
.../inspector/internal/InspectorConfig.java | 35 ---
.../inspector/internal/InspectorConfiguration.java | 35 ---
.../inspector/internal/InspectorImpl.java | 262 ----------------
.../internal/model/DynamicPropertyView.java | 59 ----
.../internal/model/PriorityPropertyView.java | 52 ----
.../inspector/internal/swagger/SchemaFormat.java | 32 --
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 --
inspector/src/main/resources/webroot/index.html | 84 ------
.../src/main/resources/webroot/static/css/main.css | 93 ------
.../webroot/static/dynamicProperties.html | 66 ----
.../webroot/static/images/ServiceComb-logo-3.jpg | Bin 80000 -> 0 bytes
.../webroot/static/images/download-all.png | Bin 208 -> 0 bytes
.../resources/webroot/static/images/download.png | Bin 178 -> 0 bytes
.../src/main/resources/webroot/static/js/main.js | 38 ---
.../webroot/static/priorityProperties.html | 89 ------
.../resources/webroot/static/schemas/schemas.css | 37 ---
.../resources/webroot/static/schemas/schemas.js | 111 -------
.../main/resources/webroot/static/tree/tree.css | 117 -------
.../src/main/resources/webroot/static/tree/tree.js | 110 -------
.../src/main/resources/webroot/static/welcome.html | 22 --
.../internal/TestInspectorBootListener.java | 81 -----
.../inspector/internal/TestInspectorImpl.java | 313 -------------------
inspector/src/test/resources/microservice.yaml | 23 --
inspector/src/test/resources/schema1.yaml | 61 ----
inspector/src/test/resources/schema2.yaml | 61 ----
.../metrics/core/TestHealthBootListener.java | 3 -
.../core/publish/TestDefaultLogPublisher.java | 6 -
.../core/publish/TestSlowInvocationLogger.java | 5 +-
.../prometheus/TestPrometheusPublisher.java | 8 +-
pom.xml | 2 -
.../provider/pojo/FilterInvocationCaller.java | 4 +-
.../provider/pojo/definition/PojoConsumerMeta.java | 3 -
.../pojo/reference/PojoReferenceMetaTest.java | 10 +-
.../pojo/reference/TestRpcReferenceProcessor.java | 10 +-
.../provider/rest/common/RestProducers.java | 20 +-
.../provider/rest/common/TestRestProducers.java | 14 +
.../servicecomb/registry/lightweight/Self.java | 17 +-
.../model/AbstractPropertiesLoader.java | 20 +-
.../model/InstancePropertiesLoader.java | 10 +-
.../lightweight/model/MicroserviceFactory.java | 44 ++-
.../lightweight/model/MicroserviceInstance.java | 23 +-
.../model/MicroservicePropertiesLoader.java | 10 +-
.../config/TestAbstractPropertiesLoader.java | 20 +-
.../registry/lightweight/StoreServiceTest.java | 39 ++-
.../servicecomb/registry/lightweight/TestBase.java | 59 ----
service-registry/registry-local/pom.xml | 4 -
.../servicecomb/localregistry/RegistryBean.java | 2 +-
.../registry/nacos/NacosMicroserviceHandler.java | 37 ++-
service-registry/registry-service-center/pom.xml | 4 -
.../registry/sc/MicroserviceHandler.java | 68 +++--
.../servicecomb/registry/sc/SCRegistration.java | 15 +-
.../ConfigurationSpringBootInitializer.java | 2 +-
.../generator/core/TestSwaggerGenerator.java | 20 +-
.../transport/highway/HighwayClientFilter.java | 3 -
.../highway/HighwayServerCodecFilter.java | 3 -
.../highway/HighwayServerCodecFilterTest.java | 3 +-
.../rest/client/RestClientCodecFilter.java | 3 -
.../transport/rest/client/RestClientEncoder.java | 15 +-
.../client/RestClientRequestParametersImpl.java | 6 +-
.../rest/client/RestClientSenderFilter.java | 3 -
.../RestServletProducerInvocationCreator.java | 6 +-
.../transport/rest/servlet/TestRestServlet.java | 2 +-
.../transport/rest/vertx/VertxHttpDispatcher.java | 1 +
.../rest/vertx/TestRestServerVerticle.java | 8 +-
.../rest/vertx/TestVertxRestDispatcher.java | 6 +-
327 files changed, 2743 insertions(+), 7423 deletions(-)
delete mode 100644 deployment/README.md
delete mode 100644 deployment/pom.xml
delete mode 100644 deployment/src/main/java/org/apache/servicecomb/deployment/Deployment.java
delete mode 100644 deployment/src/main/java/org/apache/servicecomb/deployment/DeploymentProvider.java
delete mode 100644 deployment/src/main/java/org/apache/servicecomb/deployment/SystemBootstrapInfo.java
delete mode 100644 deployment/src/test/java/org/apache/servicecomb/deployment/CustomDeploymentProvider.java
delete mode 100644 deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
delete mode 100644 deployment/src/test/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
rename dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/{client => apollo}/ApolloClient.java (78%)
rename dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/{client => apollo}/ApolloConfig.java (67%)
copy huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/ServiceStageConfiguration.java => dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java (75%)
create mode 100644 dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
rename dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/{client => apollo}/ConfigurationAction.java (94%)
delete mode 100644 dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
delete mode 100644 dynamic-config/config-apollo/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
copy dynamic-config/{config-kie => config-apollo}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (94%)
rename dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/{client => apollo}/ApolloClientTest.java (74%)
delete mode 100644 dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImplTest.java
delete mode 100644 dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloConfigTest.java
delete mode 100644 dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
create mode 100644 dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
rename dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/{ => cc}/ConfigCenterConfiguration.java (73%)
rename dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/{ConfigCenterConfigurationSourceImpl.java => cc/ConfigCenterDynamicPropertiesSource.java} (58%)
rename dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/{collect => cc}/ConfigCenterInformationCollector.java (69%)
rename dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/{ => cc}/TransportUtils.java (66%)
delete mode 100644 dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java
delete mode 100644 dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
delete mode 100644 dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
rename dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/{center/client => cc}/ConfigCenterAddressManagerTest.java (96%)
rename dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/{ => cc}/ConfigCenterConfigurationSourceImplTest.java (98%)
delete mode 100644 dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
rename dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/{KieConfigurationSourceImpl.java => KieDynamicPropertiesSource.java} (50%)
delete mode 100644 dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieCenterDefaultDeploymentProvider.java
delete mode 100644 dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
delete mode 100644 dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
delete mode 100644 dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
rename dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/{client => }/ConfigurationAction.java (94%)
rename dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/{client => }/NacosClient.java (77%)
rename dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/{client => }/NacosConfig.java (69%)
copy huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/ServiceStageConfiguration.java => dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfigConfiguration.java (74%)
create mode 100644 dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
delete mode 100644 dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImpl.java
delete mode 100644 dynamic-config/config-nacos/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
copy dynamic-config/{config-kie => config-nacos}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (93%)
rename dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/{client => }/NacosClientTest.java (78%)
delete mode 100644 dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImplTest.java
delete mode 100644 dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosConfigTest.java
delete mode 100644 edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeBootListener.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConcurrentMapConfigurationExt.java
copy {clients/config-common/src/main/java/org/apache/servicecomb/config/common => foundations/foundation-config/src/main/java/org/apache/servicecomb/config}/ConfigurationChangedEvent.java (77%)
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicConfigurationExt.java
copy foundations/{foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/InstancePing.java => foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesSource.java} (75%)
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicWatchedConfigurationExt.java
create mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/scheduler/NeverStartPollingScheduler.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigSourceMaker.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigurationSource.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/DynamicConfigurationChangedEvent.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/RefreshGovernanceConfigurationEvent.java
rename foundations/foundation-config/src/main/java/org/apache/servicecomb/config/{archaius/sources => file}/AbstractConfigLoader.java (98%)
rename foundations/foundation-config/src/main/java/org/apache/servicecomb/config/{archaius/sources => file}/ConfigModel.java (96%)
rename foundations/foundation-config/src/main/java/org/apache/servicecomb/config/{archaius/sources => file}/MicroserviceConfigLoader.java (98%)
rename foundations/foundation-config/src/main/java/org/apache/servicecomb/config/{archaius/sources => file}/YAMLConfigLoader.java (95%)
copy metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/HealthBootListener.java => foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/DynamicProperty.java (51%)
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
delete mode 100644 foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSourceLoader.java
delete mode 100644 foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
delete mode 100644 foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
delete mode 100644 foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
rename foundations/foundation-config/src/test/java/org/apache/servicecomb/config/{archaius/sources => file}/TestMicroserviceConfigLoader.java (98%)
delete mode 100644 foundations/foundation-config/src/test/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
delete mode 100644 foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
delete mode 100644 foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/config/ArchaiusUtils.java
delete mode 100644 huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorDefaultDeploymentProvider.java
delete mode 100644 huawei-cloud/dashboard/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
delete mode 100644 huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
delete mode 100644 inspector/pom.xml
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfig.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/DynamicPropertyView.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/PriorityPropertyView.java
delete mode 100644 inspector/src/main/java/org/apache/servicecomb/inspector/internal/swagger/SchemaFormat.java
delete mode 100644 inspector/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
delete mode 100644 inspector/src/main/resources/webroot/index.html
delete mode 100644 inspector/src/main/resources/webroot/static/css/main.css
delete mode 100644 inspector/src/main/resources/webroot/static/dynamicProperties.html
delete mode 100644 inspector/src/main/resources/webroot/static/images/ServiceComb-logo-3.jpg
delete mode 100644 inspector/src/main/resources/webroot/static/images/download-all.png
delete mode 100644 inspector/src/main/resources/webroot/static/images/download.png
delete mode 100644 inspector/src/main/resources/webroot/static/js/main.js
delete mode 100644 inspector/src/main/resources/webroot/static/priorityProperties.html
delete mode 100644 inspector/src/main/resources/webroot/static/schemas/schemas.css
delete mode 100644 inspector/src/main/resources/webroot/static/schemas/schemas.js
delete mode 100644 inspector/src/main/resources/webroot/static/tree/tree.css
delete mode 100644 inspector/src/main/resources/webroot/static/tree/tree.js
delete mode 100644 inspector/src/main/resources/webroot/static/welcome.html
delete mode 100644 inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
delete mode 100644 inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
delete mode 100644 inspector/src/test/resources/microservice.yaml
delete mode 100644 inspector/src/test/resources/schema1.yaml
delete mode 100644 inspector/src/test/resources/schema2.yaml
delete mode 100644 service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/TestBase.java
[servicecomb-java-chassis] 13/25: [SCB-2008]remove archaius dependency: remove ArchaiusUtils usage
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit c2437e376a2350643391f8e63b9c281e11ad3b4e
Author: liubao <bi...@qq.com>
AuthorDate: Sat Oct 7 18:02:53 2023 +0800
[SCB-2008]remove archaius dependency: remove ArchaiusUtils usage
---
.../rest/RestProducerInvocationCreatorTest.java | 2 -
.../common/rest/TestRestEngineSchemaListener.java | 2 -
.../codec/param/TestQueryProcessorCreator.java | 2 -
.../rest/definition/TestRestOperationMeta.java | 2 -
.../filter/inner/RestServerCodecFilterTest.java | 3 -
.../common/rest/locator/TestMicroservicePaths.java | 2 -
.../rest/locator/TestServicePathManager.java | 2 -
.../core/TestConfigurationSpringInitializer.java | 3 -
.../core/TestSCBApplicationListener.java | 2 -
.../core/executor/TestGroupExecutor.java | 2 -
.../discovery/TestEndpointDiscoveryFilter.java | 6 +-
.../apache/servicecomb/demo/jaxrs/JaxrsClient.java | 10 +--
.../pojoDefault/DefaultModelServiceClient.java | 4 +-
.../client/validation/ValidationServiceClient.java | 8 +--
.../servicecomb/demo/pojo/client/PojoClient.java | 8 +--
.../demo/CategorizedTestCaseRunner.java | 4 +-
.../servicecomb/demo/CodeFirstRestTemplate.java | 2 +-
.../springboot/pojo/client/PojoClientTest.java | 4 +-
.../demo/springmvc/SpringmvcClient.java | 4 +-
.../servicecomb/deployment/TestDeployment.java | 2 -
.../TestConfigCenterDefaultDeploymentProvider.java | 13 ++--
.../TestKieCenterDefaultDeploymentProvider.java | 12 ++--
.../config/ConfigurationChangedEvent.java | 6 +-
.../config/InMemoryDynamicPropertiesSource.java | 18 +++++-
.../registry/discovery/TestDiscoveryTree.java | 2 -
.../foundation/vertx/TestVertxUtils.java | 3 -
.../TestConsumerAbortFaultFilter.java | 28 --------
.../servicecomb/qps/QpsControllerManagerTest.java | 1 +
.../loadbalance/TestLoadBalanceCreator.java | 3 -
.../loadbalance/TestLoadBalanceFilter.java | 2 -
.../loadbalance/TestLoadBalanceFilter2.java | 6 --
.../authentication/TestAccessController.java | 2 -
.../TestAuthenticationBootListener.java | 2 -
.../provider/TestProviderTokenManager.java | 4 --
.../inspector/internal/InspectorBootListener.java | 11 +---
.../inspector/internal/InspectorConfiguration.java | 6 +-
.../inspector/internal/InspectorImpl.java | 75 ----------------------
.../internal/TestInspectorBootListener.java | 6 +-
.../inspector/internal/TestInspectorImpl.java | 44 -------------
.../metrics/core/TestHealthBootListener.java | 3 -
.../core/publish/TestDefaultLogPublisher.java | 6 --
.../core/publish/TestSlowInvocationLogger.java | 5 +-
.../prometheus/TestPrometheusPublisher.java | 8 +--
.../pojo/reference/PojoReferenceMetaTest.java | 4 --
.../pojo/reference/TestRpcReferenceProcessor.java | 4 --
.../generator/core/TestSwaggerGenerator.java | 1 +
.../rest/vertx/TestRestServerVerticle.java | 2 -
.../rest/vertx/TestVertxRestDispatcher.java | 4 +-
48 files changed, 73 insertions(+), 282 deletions(-)
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
index 88f340566..ea326b912 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
@@ -37,7 +37,6 @@ import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
@@ -97,7 +96,6 @@ public class RestProducerInvocationCreatorTest {
@AfterAll
public static void afterClass() {
engine.destroy();
- ArchaiusUtils.resetConfig();
}
@BeforeEach
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
index 7efbbeee8..4f782eeb9 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
@@ -32,7 +32,6 @@ import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -71,7 +70,6 @@ public class TestRestEngineSchemaListener {
@AfterAll
public static void teardown() {
scbEngine.destroy();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
index d1f98da4e..a75e1df2b 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.common.rest.codec.param;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -96,6 +95,5 @@ public class TestQueryProcessorCreator {
result = (String) processor.convertValue(null, TypeFactory.defaultInstance().constructType(String.class));
result = (String) processor.getValue(request);
Assertions.assertNull(result);
- ArchaiusUtils.resetConfig();
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
index f5e5a88a9..86662b3a2 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
@@ -35,7 +35,6 @@ import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -191,7 +190,6 @@ public class TestRestOperationMeta {
@AfterAll
public static void classTeardown() {
scbEngine.destroy();
- ArchaiusUtils.resetConfig();
}
private void findOperation(String operationId) {
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
index 2b48ce520..8ac941cd8 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
@@ -41,7 +41,6 @@ import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.core.filter.FilterNode;
import org.apache.servicecomb.core.invocation.InvocationFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -99,7 +98,6 @@ public class RestServerCodecFilterTest {
@BeforeAll
public static void beforeClass() {
- ArchaiusUtils.resetConfig();
ConfigUtil.installDynamicConfig();
engine = SCBBootstrap.createSCBEngineForTest();
@@ -113,7 +111,6 @@ public class RestServerCodecFilterTest {
@AfterAll
public static void afterClass() {
engine.destroy();
- ArchaiusUtils.resetConfig();
}
@BeforeEach
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
index 442368b0a..e1d53e7f5 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
@@ -32,7 +32,6 @@ import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -72,7 +71,6 @@ public class TestMicroservicePaths {
@AfterAll
public static void teardown() {
scbEngine.destroy();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
index 85476f627..f7843353e 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
@@ -32,7 +32,6 @@ import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
@@ -62,7 +61,6 @@ public class TestServicePathManager {
@AfterEach
public void tearDown() {
scbEngine.destroy();
- ArchaiusUtils.resetConfig();
ClassLoaderScopeContext.clearClassLoaderScopeProperty();
}
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
index e6c448657..a5fbd6f2c 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
@@ -22,7 +22,6 @@ import java.util.Map;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -42,7 +41,6 @@ public class TestConfigurationSpringInitializer {
Configurator.setRootLevel(Level.OFF);
ConfigUtil.clearExtraConfig();
- ArchaiusUtils.resetConfig();
Configurator.setRootLevel(Level.INFO);
}
@@ -50,7 +48,6 @@ public class TestConfigurationSpringInitializer {
@AfterEach
public void afterTest() {
ConfigUtil.clearExtraConfig();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
index ec4045741..37eebd201 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
@@ -21,7 +21,6 @@ import static org.apache.servicecomb.core.SCBEngine.DEFAULT_TURN_DOWN_STATUS_WAI
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -38,7 +37,6 @@ public class TestSCBApplicationListener {
@AfterAll
public static void classTeardown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/core/src/test/java/org/apache/servicecomb/core/executor/TestGroupExecutor.java b/core/src/test/java/org/apache/servicecomb/core/executor/TestGroupExecutor.java
index f44496d8a..d92ca3bb2 100644
--- a/core/src/test/java/org/apache/servicecomb/core/executor/TestGroupExecutor.java
+++ b/core/src/test/java/org/apache/servicecomb/core/executor/TestGroupExecutor.java
@@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -55,7 +54,6 @@ public class TestGroupExecutor {
@AfterAll
public static void teardown() {
- ArchaiusUtils.resetConfig();
}
Environment environment = Mockito.mock(Environment.class);
diff --git a/core/src/test/java/org/apache/servicecomb/core/registry/discovery/TestEndpointDiscoveryFilter.java b/core/src/test/java/org/apache/servicecomb/core/registry/discovery/TestEndpointDiscoveryFilter.java
index a445b5967..cc79ba2f6 100644
--- a/core/src/test/java/org/apache/servicecomb/core/registry/discovery/TestEndpointDiscoveryFilter.java
+++ b/core/src/test/java/org/apache/servicecomb/core/registry/discovery/TestEndpointDiscoveryFilter.java
@@ -17,14 +17,12 @@
package org.apache.servicecomb.core.registry.discovery;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.discovery.DiscoveryContext;
import org.apache.servicecomb.registry.discovery.StatefulDiscoveryInstance;
import org.junit.jupiter.api.AfterEach;
@@ -42,13 +40,11 @@ public class TestEndpointDiscoveryFilter {
@BeforeEach
public void setup() {
- ArchaiusUtils.resetConfig();
- ConfigUtil.installDynamicConfig();
+
}
@AfterEach
public void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/JaxrsClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/JaxrsClient.java
index e54a8f000..133760548 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/JaxrsClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/JaxrsClient.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.http.HttpStatus;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.demo.CategorizedTestCaseRunner;
import org.apache.servicecomb.demo.CodeFirstRestTemplate;
import org.apache.servicecomb.demo.DemoConst;
@@ -35,7 +36,6 @@ import org.apache.servicecomb.demo.jaxrs.client.pojoDefault.DefaultModelServiceC
import org.apache.servicecomb.demo.jaxrs.client.validation.ValidationServiceClient;
import org.apache.servicecomb.demo.validator.Student;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.springboot.starter.EnableServiceComb;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
@@ -105,7 +105,7 @@ public class JaxrsClient {
private static void testOnlyRest(RestTemplate template) {
String microserviceName = "jaxrs";
String cseUrlPrefix = "cse://" + microserviceName;
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, "rest");
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, "rest");
testGetRest(template, cseUrlPrefix);
testSpringMvcDefaultValuesJavaPrimitiveRest(templateNew);
@@ -114,7 +114,7 @@ public class JaxrsClient {
private static void testCompute(RestTemplate template) throws Exception {
String microserviceName = "jaxrs";
for (String transport : DemoConst.transports) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
String cseUrlPrefix = "cse://" + microserviceName;
@@ -131,7 +131,7 @@ public class JaxrsClient {
private static void testValidator(RestTemplate template) {
String microserviceName = "jaxrs";
for (String transport : DemoConst.transports) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
String cseUrlPrefix = "cse://" + microserviceName + "/validator/";
@@ -198,7 +198,7 @@ public class JaxrsClient {
private static void testJaxRSDefaultValuesAllTransport(RestTemplate template) {
String microserviceName = "jaxrs";
for (String transport : DemoConst.transports) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
String cseUrlPrefix = "cse://" + microserviceName + "/JaxRSDefaultValues/";
diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/pojoDefault/DefaultModelServiceClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/pojoDefault/DefaultModelServiceClient.java
index 99744957e..d5ef35517 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/pojoDefault/DefaultModelServiceClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/pojoDefault/DefaultModelServiceClient.java
@@ -17,9 +17,9 @@
package org.apache.servicecomb.demo.jaxrs.client.pojoDefault;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.jaxrs.server.pojoDefault.DefaultResponseModel;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;
@@ -30,7 +30,7 @@ public class DefaultModelServiceClient {
public static void run() {
// highway do not support this feature
- ArchaiusUtils.setProperty("servicecomb.references.transport.jaxrs", "rest");
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport.jaxrs", "rest");
testDefaultModelService();
}
diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/validation/ValidationServiceClient.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/validation/ValidationServiceClient.java
index d36bc0cfa..6ca9d5b7d 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/validation/ValidationServiceClient.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/validation/ValidationServiceClient.java
@@ -19,17 +19,17 @@ package org.apache.servicecomb.demo.jaxrs.client.validation;
import java.util.ArrayList;
-import jakarta.ws.rs.core.Response.Status;
-
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.jaxrs.server.validation.ValidationModel;
import org.apache.servicecomb.demo.validator.Teacher;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.web.client.RestTemplate;
+import jakarta.ws.rs.core.Response.Status;
+
public class ValidationServiceClient {
private static RestTemplate template = RestTemplateBuilder.create();
@@ -37,7 +37,7 @@ public class ValidationServiceClient {
public static void run() {
// highway do not support this feature
- ArchaiusUtils.setProperty("servicecomb.references.transport.jaxrs", "rest");
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport.jaxrs", "rest");
testValidation();
}
diff --git a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
index ad70588cf..7fc990aac 100644
--- a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
+++ b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
@@ -26,6 +26,7 @@ import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.IntStream;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
import org.apache.servicecomb.demo.CategorizedTestCaseRunner;
@@ -38,7 +39,6 @@ import org.apache.servicecomb.demo.smartcare.Application;
import org.apache.servicecomb.demo.smartcare.Group;
import org.apache.servicecomb.demo.smartcare.SmartCare;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.client.http.HttpClients;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.springboot.starter.EnableServiceComb;
@@ -115,7 +115,7 @@ public class PojoClient {
String microserviceName = "pojo";
for (String transport : DemoConst.transports) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
LOGGER.info("test {}, transport {}", microserviceName, transport);
@@ -125,9 +125,9 @@ public class PojoClient {
// This test case shows destroy of WeightedResponseTimeRule timer task. after test finished will not print:
// "Weight adjusting job started" and thread "NFLoadBalancer-serverWeightTimer-unknown" destroyed.
- ArchaiusUtils.setProperty("servicecomb.loadbalance.strategy.name", "WeightedResponse");
+ InMemoryDynamicPropertiesSource.update("servicecomb.loadbalance.strategy.name", "WeightedResponse");
testStringArray(test);
- ArchaiusUtils.setProperty("servicecomb.loadbalance.strategy.name", "RoundRobin");
+ InMemoryDynamicPropertiesSource.update("servicecomb.loadbalance.strategy.name", "RoundRobin");
testStringArray(test);
boolean checkerDestroyed = true;
diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
index 531be9280..acb821903 100644
--- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
+++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
@@ -19,8 +19,8 @@ package org.apache.servicecomb.demo;
import java.util.Map;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +56,7 @@ public class CategorizedTestCaseRunner {
}
public static void changeTransport(String microserviceName, String transport) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
}
}
diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
index dfdafb0d8..681b5c0a0 100644
--- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
+++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
@@ -50,7 +50,7 @@ public class CodeFirstRestTemplate {
}
protected void changeTransport(String microserviceName, String transport) {
- InMemoryDynamicPropertiesSource.DYNAMIC.put("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
}
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/springboot/pojo/client/PojoClientTest.java b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/springboot/pojo/client/PojoClientTest.java
index 05fdfd776..e087b0b62 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/springboot/pojo/client/PojoClientTest.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/springboot/pojo/client/PojoClientTest.java
@@ -21,11 +21,11 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
import org.apache.servicecomb.demo.springboot.pojo.server.schema.server.Test;
import org.apache.servicecomb.demo.springboot.pojo.server.schema.server.TestRequest;
import org.apache.servicecomb.demo.springboot.pojo.server.schema.server.User;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +56,7 @@ public class PojoClientTest {
String microserviceName = "spring-boot-pojo-server";
for (String transport : DemoConst.transports) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
LOGGER.info("test {}, transport {}", microserviceName, transport);
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
index 3b10de632..a9902b524 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpStatus;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.demo.CategorizedTestCaseRunner;
import org.apache.servicecomb.demo.DemoConst;
import org.apache.servicecomb.demo.TestMgr;
@@ -31,7 +32,6 @@ import org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringm
import org.apache.servicecomb.demo.springmvc.client.ThirdSvc.ThirdSvcClient;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.client.http.HttpClients;
import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
@@ -83,7 +83,7 @@ public class SpringmvcClient {
}
private static void changeTransport(String microserviceName, String transport) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.update("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
}
diff --git a/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java b/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
index 41d6476bd..99637c4eb 100644
--- a/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
+++ b/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
@@ -18,7 +18,6 @@
package org.apache.servicecomb.deployment;
import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -26,7 +25,6 @@ import org.junit.jupiter.api.Test;
public class TestDeployment {
@AfterEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
index be3c4b207..51af1da3f 100644
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
+++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
@@ -18,10 +18,8 @@
package org.apache.servicecomb.config.cc;
import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider;
import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -30,18 +28,17 @@ import org.junit.jupiter.api.Test;
public class TestConfigCenterDefaultDeploymentProvider {
@BeforeEach
public void start() {
- ArchaiusUtils.resetConfig();
}
@AfterEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
public void testConfiguration() {
ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
Assertions.assertEquals("https://172.16.8.7:30103", info.getAccessURL().get(0));
Assertions.assertNull(Deployment.getSystemBootStrapInfo("wrong"));
}
@@ -50,7 +47,8 @@ public class TestConfigCenterDefaultDeploymentProvider {
public void testConfigurationEnv() {
System.setProperty("servicecomb.config.client.serverUri", "https://localhost:9988");
ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
Assertions.assertEquals("https://localhost:9988", info.getAccessURL().get(0));
System.getProperties().remove("servicecomb.config.client.serverUri");
}
@@ -59,7 +57,8 @@ public class TestConfigCenterDefaultDeploymentProvider {
public void testConfigurationEnvTwo() {
System.setProperty("servicecomb.config.client.serverUri", "https://localhost:9988,https://localhost:9987");
ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
Assertions.assertEquals(2, info.getAccessURL().size());
Assertions.assertEquals("https://localhost:9988", info.getAccessURL().get(0));
Assertions.assertEquals("https://localhost:9987", info.getAccessURL().get(1));
diff --git a/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java b/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
index 805336c23..fa659843d 100644
--- a/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
+++ b/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
@@ -20,7 +20,6 @@ package org.apache.servicecomb.config.kie.collect;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -29,18 +28,17 @@ import org.junit.jupiter.api.Test;
public class TestKieCenterDefaultDeploymentProvider {
@BeforeEach
public void start() {
- ArchaiusUtils.resetConfig();
}
@AfterEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
public void testConfiguration() {
KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
Assertions.assertEquals("https://172.16.8.7:30110", info.getAccessURL().get(0));
Assertions.assertNull(Deployment.getSystemBootStrapInfo("wrong"));
}
@@ -49,7 +47,8 @@ public class TestKieCenterDefaultDeploymentProvider {
public void testConfigurationEnv() {
System.setProperty("servicecomb.kie.serverUri", "https://localhost:30110");
KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
Assertions.assertEquals("https://localhost:30110", info.getAccessURL().get(0));
System.getProperties().remove("servicecomb.kie.serverUri");
}
@@ -59,7 +58,8 @@ public class TestKieCenterDefaultDeploymentProvider {
System.setProperty("servicecomb.kie.serverUri", "http://127.0.0.1:30110,http://127.0.0.2:30110");
KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
+ SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
+ KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
Assertions.assertEquals(2, info.getAccessURL().size());
Assertions.assertEquals("http://127.0.0.1:30110", info.getAccessURL().get(0));
Assertions.assertEquals("http://127.0.0.2:30110", info.getAccessURL().get(1));
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
index ff56ae202..ba2590c17 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
@@ -68,11 +68,15 @@ public class ConfigurationChangedEvent {
return event;
}
- private static ConfigurationChangedEvent createIncremental(Map<String, Object> added, Map<String, Object> updated,
+ public static ConfigurationChangedEvent createIncremental(Map<String, Object> added, Map<String, Object> updated,
Map<String, Object> deleted, boolean changed) {
return new ConfigurationChangedEvent(added, updated, deleted, changed);
}
+ public static ConfigurationChangedEvent createIncremental(Map<String, Object> updated) {
+ return new ConfigurationChangedEvent(new HashMap<>(), updated, new HashMap<>(), true);
+ }
+
public final Map<String, Object> getAdded() {
return added;
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
index 515d5ae82..e9a450f92 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
@@ -19,14 +19,18 @@ package org.apache.servicecomb.config;
import java.util.HashMap;
import java.util.Map;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
+/**
+ * This DynamicPropertiesSource is created for easier system tests.
+ */
public class InMemoryDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
public static final String SOURCE_NAME = "in-memory";
- public static final Map<String, Object> DYNAMIC = new HashMap<>();
+ private static final Map<String, Object> DYNAMIC = new HashMap<>();
@Override
public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
@@ -37,4 +41,16 @@ public class InMemoryDynamicPropertiesSource implements DynamicPropertiesSource<
public int getOrder() {
return -100;
}
+
+ public static void update(String key, Object value) {
+ DYNAMIC.put(key, value);
+
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(key, value);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+ }
+
+ public static void reset() {
+ DYNAMIC.clear();
+ }
}
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
index c68592fbd..1d161792c 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
@@ -27,7 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
@@ -50,7 +49,6 @@ public class TestDiscoveryTree {
@AfterEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
index e675efa7c..399d0b1f6 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
@@ -26,7 +26,6 @@ import java.util.concurrent.CountDownLatch;
import org.apache.commons.io.FileUtils;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -86,8 +85,6 @@ public class TestVertxUtils {
VertxUtils.getOrCreateVertxByName("testCreateVertxWithFileCPResolvingTrue", null);
Assertions.assertFalse(isCacheFileExists());
VertxUtils.blockCloseVertxByName("testCreateVertxWithFileCPResolvingTrue");
-
- ArchaiusUtils.resetConfig();
}
private void deleteCacheFile() {
diff --git a/handlers/handler-fault-injection/src/test/java/org/apache/servicecomb/faultinjection/TestConsumerAbortFaultFilter.java b/handlers/handler-fault-injection/src/test/java/org/apache/servicecomb/faultinjection/TestConsumerAbortFaultFilter.java
index fbc0409ee..d44fd849b 100644
--- a/handlers/handler-fault-injection/src/test/java/org/apache/servicecomb/faultinjection/TestConsumerAbortFaultFilter.java
+++ b/handlers/handler-fault-injection/src/test/java/org/apache/servicecomb/faultinjection/TestConsumerAbortFaultFilter.java
@@ -25,7 +25,6 @@ import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.core.filter.FilterNode;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
@@ -37,8 +36,6 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
-import com.netflix.config.DynamicProperty;
-
public class TestConsumerAbortFaultFilter {
private Invocation invocation;
@@ -140,17 +137,6 @@ public class TestConsumerAbortFaultFilter {
@Test
public void injectFaultNoError() throws Exception {
- ArchaiusUtils
- .setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.httpStatus", "421");
- ArchaiusUtils.setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent", "0");
-
- Assertions.assertEquals("421", DynamicProperty
- .getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.httpStatus")
- .getString());
- Assertions.assertEquals("0", DynamicProperty
- .getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent")
- .getString());
-
ConsumerAbortFaultFilter abortFault = new ConsumerAbortFaultFilter();
FilterNode filterNode = Mockito.mock(FilterNode.class);
Mockito.when(filterNode.onFilter(invocation))
@@ -161,13 +147,6 @@ public class TestConsumerAbortFaultFilter {
@Test
public void injectFaultNoPercentageConfig() throws Exception {
- ArchaiusUtils
- .setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent", null);
-
- Assertions.assertNull(DynamicProperty
- .getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent")
- .getString());
-
ConsumerAbortFaultFilter abortFault = new ConsumerAbortFaultFilter();
FilterNode filterNode = Mockito.mock(FilterNode.class);
Mockito.when(filterNode.onFilter(invocation))
@@ -178,13 +157,6 @@ public class TestConsumerAbortFaultFilter {
@Test
public void injectFaultNoErrorCodeConfig() throws Exception {
- ArchaiusUtils
- .setProperty("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent", "10");
-
- Assertions.assertEquals("10", DynamicProperty
- .getInstance("servicecomb.governance.Consumer._global.policy.fault.protocols.rest.abort.percent")
- .getString());
-
ConsumerAbortFaultFilter abortFault = new ConsumerAbortFaultFilter();
FilterNode filterNode = Mockito.mock(FilterNode.class);
Mockito.when(filterNode.onFilter(invocation))
diff --git a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
index 8554968aa..8f4aaf135 100644
--- a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
+++ b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
@@ -32,6 +32,7 @@ public class QpsControllerManagerTest {
@BeforeEach
public void beforeTest() {
+ // TODO: fix DynamicProperty
ArchaiusUtils.resetConfig();
}
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
index 3d329333c..71e74d76c 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceCreator.java
@@ -23,7 +23,6 @@ import java.util.List;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.apache.servicecomb.registry.discovery.StatefulDiscoveryInstance;
import org.junit.Test;
@@ -237,11 +236,9 @@ public class TestLoadBalanceCreator {
long time = Deencapsulation.getField(rule, "lastAccessedTime");
Deencapsulation.setField(rule, "lastAccessedTime", time - 1000 * 300);
- ArchaiusUtils.setProperty("cse.loadbalance.service.SessionStickinessRule.sessionTimeoutInSeconds", 9);
s = lb.chooseServer(invocation);
Assertions.assertEquals(server2, s);
- ArchaiusUtils.setProperty("cse.loadbalance.service.SessionStickinessRule.successiveFailedTimes", 5);
lb.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(s);
lb.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(s);
lb.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(s);
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
index 512240542..bdc657b81 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
@@ -31,7 +31,6 @@ import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
import org.apache.servicecomb.registry.discovery.DiscoveryTree;
import org.apache.servicecomb.registry.discovery.TelnetInstancePing;
@@ -124,7 +123,6 @@ public class TestLoadBalanceFilter {
@After
public void teardown() {
scbEngine.destroy();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter2.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter2.java
index 954c6b4bb..5e4c47e9c 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter2.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter2.java
@@ -35,7 +35,6 @@ import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.loadbalance.filter.ServerDiscoveryFilter;
import org.apache.servicecomb.loadbalance.filter.ZoneAwareDiscoveryFilter;
import org.apache.servicecomb.registry.DiscoveryManager;
@@ -244,7 +243,6 @@ public class TestLoadBalanceFilter2 {
@Test
public void testZoneAwareFilterWorksEmptyInstanceProtectionEnabled() {
- ArchaiusUtils.setProperty("servicecomb.loadbalance.filter.isolation.emptyInstanceProtectionEnabled", "true");
ReferenceConfig referenceConfig = Mockito.mock(ReferenceConfig.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
InvocationRuntimeType invocationRuntimeType = Mockito.mock(InvocationRuntimeType.class);
@@ -261,7 +259,6 @@ public class TestLoadBalanceFilter2 {
SCBEngine scbEngine = Mockito.mock(SCBEngine.class);
Mockito.when(scbEngine.getTransportManager()).thenReturn(transportManager);
Mockito.when(scbEngine.getEnvironment()).thenReturn(environment);
- ArchaiusUtils.setProperty("servicecomb.loadbalance.filter.operation.enabled", "false");
// set up data
DataCenterProperties myself = new DataCenterProperties();
@@ -455,12 +452,9 @@ public class TestLoadBalanceFilter2 {
@Test
public void testStatusFilterUsingMockedInvocationWorks() {
- ArchaiusUtils.setProperty("servicecomb.loadbalance.filter.status.enabled", "false");
-
Invocation invocation = new NonSwaggerInvocation("testApp", "testMicroserviceName");
TransportManager transportManager = Mockito.mock(TransportManager.class);
Transport transport = Mockito.mock(Transport.class);
- ArchaiusUtils.setProperty("servicecomb.loadbalance.filter.operation.enabled", "false");
SCBEngine scbEngine = Mockito.mock(SCBEngine.class);
Mockito.when(scbEngine.getTransportManager()).thenReturn(transportManager);
Mockito.when(scbEngine.getEnvironment()).thenReturn(environment);
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
index ad4b47326..0c6c6afd3 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
@@ -21,7 +21,6 @@ import java.util.Map;
import org.apache.servicecomb.authentication.provider.AccessController;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -135,7 +134,6 @@ public class TestAccessController {
Mockito.when(service.getServiceName()).thenReturn("Customer_trust_not");
Assertions.assertTrue(controller.isAllowed(service));
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust");
Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
.thenReturn("trust");
latest = new HashMap<>();
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
index fa0469cdf..99f6877f5 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
@@ -27,7 +27,6 @@ import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.BootListener.BootEvent;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.token.Keypair4Auth;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.registry.definition.DefinitionConst;
@@ -55,7 +54,6 @@ public class TestAuthenticationBootListener {
@AfterEach
public void teardown() {
engine.destroy();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
index 4e584c7ca..f058ef6bc 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.authentication.provider;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.endsWith;
import java.util.HashMap;
import java.util.Map;
@@ -28,7 +27,6 @@ import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.foundation.common.utils.KeyPairEntry;
import org.apache.servicecomb.foundation.common.utils.KeyPairUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.token.Keypair4Auth;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.apache.servicecomb.registry.definition.DefinitionConst;
@@ -40,7 +38,6 @@ import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import com.google.common.cache.Cache;
@@ -55,7 +52,6 @@ public class TestProviderTokenManager {
@AfterEach
public void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
index 076364a7e..c694817f1 100644
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
+++ b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
@@ -16,9 +16,8 @@
*/
package org.apache.servicecomb.inspector.internal;
-import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
-import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.config.MicroserviceProperties;
+import org.apache.servicecomb.core.BootListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,13 +27,10 @@ public class InspectorBootListener implements BootListener {
private final InspectorConfig inspectorConfig;
- private final PriorityPropertyFactory propertyFactory;
-
private MicroserviceProperties microserviceProperties;
- public InspectorBootListener(InspectorConfig inspectorConfig, PriorityPropertyFactory propertyFactory) {
+ public InspectorBootListener(InspectorConfig inspectorConfig) {
this.inspectorConfig = inspectorConfig;
- this.propertyFactory = propertyFactory;
}
@Autowired
@@ -57,9 +53,8 @@ public class InspectorBootListener implements BootListener {
// will not register this schemas to service registry
InspectorImpl inspector = new InspectorImpl()
- .setPropertyFactory(propertyFactory)
.setServiceName(microserviceProperties.getName());
- // TODO: inspector get schemas
+ // TODO: inspector get schemas
// .setSchemas(RegistrationManager.INSTANCE.getMicroservice().getSchemaMap())
// .correctBasePathForOnlineTest(event.getScbEngine());
event.getScbEngine().getProducerProviderManager().registerSchema("inspector", inspector);
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
index afdfb3943..47ac953dc 100644
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
+++ b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
@@ -16,16 +16,14 @@
*/
package org.apache.servicecomb.inspector.internal;
-import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class InspectorConfiguration {
@Bean
- public InspectorBootListener inspectorBootListener(InspectorConfig inspectorConfig,
- PriorityPropertyFactory propertyFactory) {
- return new InspectorBootListener(inspectorConfig, propertyFactory);
+ public InspectorBootListener inspectorBootListener(InspectorConfig inspectorConfig) {
+ return new InspectorBootListener(inspectorConfig);
}
@Bean
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
index 8045bb77b..cfe7de0a5 100644
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
+++ b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
@@ -19,14 +19,7 @@ package org.apache.servicecomb.inspector.internal;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
@@ -35,16 +28,11 @@ import java.util.zip.ZipOutputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.common.rest.resource.ClassPathStaticResourceHandler;
import org.apache.servicecomb.common.rest.resource.StaticResourceHandler;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.priority.PriorityProperty;
-import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.foundation.common.part.InputStreamPart;
import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
-import org.apache.servicecomb.inspector.internal.model.DynamicPropertyView;
-import org.apache.servicecomb.inspector.internal.model.PriorityPropertyView;
import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.SwaggerUtils;
@@ -54,7 +42,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.DynamicProperty;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -73,21 +60,12 @@ import jakarta.ws.rs.core.Response.Status;
public class InspectorImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(InspectorImpl.class);
- private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
private final StaticResourceHandler resourceHandler = new ClassPathStaticResourceHandler();
private Map<String, String> schemas;
- private PriorityPropertyFactory propertyFactory;
-
private String serviceName;
- public InspectorImpl setPropertyFactory(PriorityPropertyFactory propertyFactory) {
- this.propertyFactory = propertyFactory;
- return this;
- }
-
@VisibleForTesting
public Map<String, String> getSchemas() {
return schemas;
@@ -206,57 +184,4 @@ public class InspectorImpl {
public Response getStaticResource(@PathParam("path") String path) {
return resourceHandler.handle(path);
}
-
- @Path("/dynamicProperties")
- @GET
- public List<DynamicPropertyView> dynamicProperties() {
- List<DynamicPropertyView> views = new ArrayList<>();
- for (DynamicProperty property : ConfigUtil.getAllDynamicProperties().values()) {
- views.add(createDynamicPropertyView(property));
- }
-
- // show more callback first, because maybe there is memory leak problem
- // show recently changed second
- // and sort by key
- views.sort(Comparator
- .comparing(DynamicPropertyView::getCallbackCount)
- .thenComparing(DynamicPropertyView::getChangedTime).reversed()
- .thenComparing(DynamicPropertyView::getKey));
- return views;
- }
-
- private DynamicPropertyView createDynamicPropertyView(DynamicProperty property) {
- DynamicPropertyView view = new DynamicPropertyView();
- view.setKey(property.getName());
- view.setValue(property.getString());
-
- if (property.getChangedTimestamp() != 0) {
- LocalDateTime localDatetime = LocalDateTime
- .ofInstant(Instant.ofEpochMilli(property.getChangedTimestamp()), ZoneId.systemDefault());
- view.setChangedTime(localDatetime.format(FORMATTER));
- }
-
- view.setCallbackCount(ConfigUtil.getCallbacks(property).size());
- return view;
- }
-
- @Path("/priorityProperties")
- @GET
- public List<PriorityPropertyView> priorityProperties() {
- List<PriorityPropertyView> views = new ArrayList<>();
- propertyFactory.getProperties()
- .forEach(p -> views.add(createPriorityPropertyView(p)));
- return views;
- }
-
- private PriorityPropertyView createPriorityPropertyView(PriorityProperty<?> priorityProperty) {
- PriorityPropertyView view = new PriorityPropertyView();
- view.setDynamicProperties(new ArrayList<>());
- for (DynamicProperty property : priorityProperty.getProperties()) {
- view.getDynamicProperties().add(createDynamicPropertyView(property));
- }
- view.setDefaultValue(String.valueOf(priorityProperty.getDefaultValue()));
- view.setValue(String.valueOf(priorityProperty.getValue()));
- return view;
- }
}
diff --git a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
index e6ce70c36..9203082dd 100644
--- a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
+++ b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
@@ -45,13 +45,13 @@ public class TestInspectorBootListener {
@Test
public void getOrder() {
- Assertions.assertEquals(Short.MAX_VALUE, new InspectorBootListener(null, null).getOrder());
+ Assertions.assertEquals(Short.MAX_VALUE, new InspectorBootListener(null).getOrder());
}
@Test
public void filterEvent() {
BootEvent event = new BootEvent();
- InspectorBootListener listener = new InspectorBootListener(new InspectorConfig(), null);
+ InspectorBootListener listener = new InspectorBootListener(new InspectorConfig());
try (LogCollector logCollector = new LogCollector()) {
for (EventType eventType : EventType.values()) {
@@ -73,7 +73,7 @@ public class TestInspectorBootListener {
InspectorConfig inspectorConfig = new InspectorConfig()
.setEnabled(false);
- new InspectorBootListener(inspectorConfig, null)
+ new InspectorBootListener(inspectorConfig)
.onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
Assertions.assertNull(scbEngine.getProducerMicroserviceMeta().findSchemaMeta("inspector"));
diff --git a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
index 8febcb69b..b99d6a58d 100644
--- a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
+++ b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
@@ -24,27 +24,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
-import org.apache.servicecomb.inspector.internal.model.DynamicPropertyView;
-import org.apache.servicecomb.inspector.internal.model.PriorityPropertyView;
import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.invocation.Response;
@@ -63,8 +55,6 @@ import org.junit.jupiter.api.condition.JRE;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
-import com.netflix.config.DynamicProperty;
-
import io.vertx.core.file.impl.FileResolverImpl;
import jakarta.servlet.http.Part;
import jakarta.ws.rs.core.HttpHeaders;
@@ -116,7 +106,6 @@ public class TestInspectorImpl {
@AfterAll
public static void teardown() {
- ArchaiusUtils.resetConfig();
SCBEngine.getInstance().destroy();
ClassLoaderScopeContext.clearClassLoaderScopeProperty();
}
@@ -266,39 +255,6 @@ public class TestInspectorImpl {
}
}
- @Test
- public void dynamicProperties() {
- DynamicProperty.getInstance("zzz");
- ArchaiusUtils.setProperty("zzz", "abc");
- DynamicProperty.getInstance("yyy").addCallback(() -> {
- });
-
- List<DynamicPropertyView> views = inspector.dynamicProperties();
- Map<String, DynamicPropertyView> viewMap = views.stream()
- .collect(Collectors.toMap(DynamicPropertyView::getKey, Function.identity()));
- Assertions.assertEquals(1, viewMap.get("yyy").getCallbackCount());
- Assertions.assertEquals(0, viewMap.get("zzz").getCallbackCount());
-
- int count = ConfigUtil.getAllDynamicProperties().size();
- ConfigUtil.getAllDynamicProperties().remove("yyy");
- ConfigUtil.getAllDynamicProperties().remove("zzz");
- Assertions.assertEquals(count - 2, ConfigUtil.getAllDynamicProperties().size());
- }
-
- @Test
- public void priorityProperties() {
- PriorityPropertyFactory propertyFactory = new PriorityPropertyFactory();
- inspector.setPropertyFactory(propertyFactory);
-
- propertyFactory.getOrCreate(int.class, 0, 0, "high", "low");
-
- List<PriorityPropertyView> views = inspector.priorityProperties();
- Assertions.assertEquals(1, views.size());
- MatcherAssert.assertThat(
- views.get(0).getDynamicProperties().stream().map(DynamicPropertyView::getKey).collect(Collectors.toList()),
- Matchers.contains("high", "low"));
- }
-
@Test
public void urlPrefix() {
Mockito.when(environment.getProperty("servicecomb.transport.eventloop.size", int.class, -1))
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
index ed87a5809..c99141cf3 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
@@ -24,7 +24,6 @@ import org.apache.servicecomb.core.BootListener.BootEvent;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.provider.producer.ProducerMeta;
import org.apache.servicecomb.core.provider.producer.ProducerProviderManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -38,12 +37,10 @@ public class TestHealthBootListener {
@Before
public void setUp() {
- ArchaiusUtils.resetConfig();
}
@After
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
index 0c36b84fa..2b136e7b5 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestDefaultLogPublisher.java
@@ -32,7 +32,6 @@ import org.apache.servicecomb.foundation.metrics.PolledEvent;
import org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementNode;
import org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementTree;
import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
import org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
@@ -87,7 +86,6 @@ public class TestDefaultLogPublisher {
@After
public void teardown() {
collector.teardown();
- ArchaiusUtils.resetConfig();
}
@Test
@@ -116,8 +114,6 @@ public class TestDefaultLogPublisher {
}
};
- ArchaiusUtils.setProperty(DefaultLogPublisher.ENABLED, true);
-
publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig(environment));
Assertions.assertTrue(registered.value);
}
@@ -133,8 +129,6 @@ public class TestDefaultLogPublisher {
}
};
- ArchaiusUtils.setProperty(DefaultLogPublisher.ENABLED, false);
-
publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig(environment));
Assertions.assertNull(registered.value);
}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestSlowInvocationLogger.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestSlowInvocationLogger.java
index 6a2b883bd..dad92b737 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestSlowInvocationLogger.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/TestSlowInvocationLogger.java
@@ -26,17 +26,16 @@ import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.invocation.InvocationStageTrace;
import org.apache.servicecomb.core.tracing.TraceIdLogger;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.swagger.invocation.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
import mockit.Expectations;
import mockit.Mocked;
-import org.junit.jupiter.api.Assertions;
public class TestSlowInvocationLogger {
@Mocked
@@ -70,14 +69,12 @@ public class TestSlowInvocationLogger {
public void setup() {
logger = new SlowInvocationLogger(scbEngine);
event = new InvocationFinishEvent(invocation, response);
- ArchaiusUtils.resetConfig();
logCollector = new LogCollector();
}
@After
public void teardown() {
logCollector.teardown();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java b/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
index c9b0d605f..a8549059f 100644
--- a/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
+++ b/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
@@ -34,7 +34,6 @@ import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig;
import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -69,21 +68,22 @@ public class TestPrometheusPublisher {
@AfterAll
public static void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
public void testBadPublishAddress() {
+ Mockito.when(environment.getProperty(METRICS_PROMETHEUS_ADDRESS, String.class, "0.0.0.0:9696"))
+ .thenReturn("a:b:c");
Assertions.assertThrows(ServiceCombException.class, () -> {
- ArchaiusUtils.setProperty(METRICS_PROMETHEUS_ADDRESS, "a:b:c");
publisher.init(globalRegistry, null, null);
});
}
@Test
public void testBadPublishAddress_BadPort() {
+ Mockito.when(environment.getProperty(METRICS_PROMETHEUS_ADDRESS, String.class, "0.0.0.0:9696"))
+ .thenReturn("localhost:xxxx");
Assertions.assertThrows(ServiceCombException.class, () -> {
- ArchaiusUtils.setProperty(METRICS_PROMETHEUS_ADDRESS, "localhost:xxxx");
publisher.init(globalRegistry, null, null);
});
}
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
index 5e529f40c..98ba2de92 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
@@ -19,11 +19,9 @@ package org.apache.servicecomb.provider.pojo.reference;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.pojo.IPerson;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterEach;
@@ -34,12 +32,10 @@ import org.junit.jupiter.api.Test;
public class PojoReferenceMetaTest {
@BeforeEach
public void setUp() {
- ConfigUtil.installDynamicConfig();
}
@AfterEach
public void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
index d32a9b9c5..b20c3785b 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
@@ -17,10 +17,8 @@
package org.apache.servicecomb.provider.pojo.reference;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.test.scaffolding.spring.SpringUtils;
import org.apache.servicecomb.provider.pojo.Person;
import org.apache.servicecomb.provider.pojo.PersonReference;
@@ -34,12 +32,10 @@ public class TestRpcReferenceProcessor {
@BeforeEach
public void setUp() {
- ConfigUtil.installDynamicConfig();
}
@AfterEach
public void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
index 2bae07fe8..79c7890f7 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
@@ -38,6 +38,7 @@ public class TestSwaggerGenerator {
@Test
public void testBasePathPlaceHolder() {
+ // TODO: fix PlaceholderResolver
ArchaiusUtils.setProperty("var", "varValue");
PojoSwaggerGenerator swaggerGenerator = new PojoSwaggerGenerator(null);
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
index d4d73d759..ed2247da3 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
@@ -49,7 +49,6 @@ import org.apache.servicecomb.core.transport.AbstractTransport;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.client.tcp.TcpClientConfig;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -180,7 +179,6 @@ public class TestRestServerVerticle {
instance = null;
startPromise = null;
SCBEngine.getInstance().destroy();
- ArchaiusUtils.resetConfig();
}
@Test
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
index a0758445f..aeab3878b 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
@@ -19,11 +19,10 @@ package org.apache.servicecomb.transport.rest.vertx;
import org.apache.http.HttpHeaders;
import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -75,7 +74,6 @@ public class TestVertxRestDispatcher {
@After
public void teardown() {
SCBEngine.getInstance().destroy();
- ArchaiusUtils.resetConfig();
}
@Test
[servicecomb-java-chassis] 25/25: [SCB-2008]fix rebase code error
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit a72776737e794d8e0c76b2a62647197b0d7952e3
Author: liubao <bi...@qq.com>
AuthorDate: Tue Oct 10 09:01:14 2023 +0800
[SCB-2008]fix rebase code error
---
.../registry/nacos/NacosMicroserviceHandler.java | 37 +++++++++++-----------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosMicroserviceHandler.java b/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosMicroserviceHandler.java
index 704a68039..cada738df 100644
--- a/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosMicroserviceHandler.java
+++ b/service-registry/registry-nacos/src/main/java/org/apache/servicecomb/registry/nacos/NacosMicroserviceHandler.java
@@ -23,8 +23,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.foundation.common.net.NetUtils;
import org.springframework.core.env.Environment;
@@ -59,12 +59,11 @@ public class NacosMicroserviceHandler {
metadata.put("alias", microserviceProperties.getAlias());
metadata.put("description", microserviceProperties.getDescription());
metadata.put("secure", String.valueOf(properties.isSecure()));
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
- metadata.put("version", envConfig.getString(VERSION_MAPPING));
+ if (!StringUtils.isEmpty(environment.getProperty(VERSION_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(VERSION_MAPPING)))) {
+ metadata.put("version", environment.getProperty(environment.getProperty(VERSION_MAPPING)));
}
- metadata.putAll(genCasProperties());
+ metadata.putAll(genCasProperties(environment));
instance.setMetadata(metadata);
instance.setClusterName(properties.getClusterName());
instance.setEphemeral(properties.isEphemeral());
@@ -80,26 +79,26 @@ public class NacosMicroserviceHandler {
return Integer.parseInt(environment.getProperty("server.port"));
}
- private static Map<String, String> genCasProperties() {
+ private static Map<String, String> genCasProperties(Environment environment) {
Map<String, String> properties = new HashMap<>();
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(CAS_APPLICATION_ID))) {
- properties.put(CAS_APPLICATION_ID, envConfig.getString(CAS_APPLICATION_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_APPLICATION_ID))) {
+ properties.put(CAS_APPLICATION_ID, environment.getProperty(CAS_APPLICATION_ID));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_COMPONENT_NAME))) {
- properties.put(CAS_COMPONENT_NAME, envConfig.getString(CAS_COMPONENT_NAME));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_COMPONENT_NAME))) {
+ properties.put(CAS_COMPONENT_NAME, environment.getProperty(CAS_COMPONENT_NAME));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_INSTANCE_VERSION))) {
- properties.put(CAS_INSTANCE_VERSION, envConfig.getString(CAS_INSTANCE_VERSION));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_INSTANCE_VERSION))) {
+ properties.put(CAS_INSTANCE_VERSION, environment.getProperty(CAS_INSTANCE_VERSION));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_INSTANCE_ID))) {
- properties.put(CAS_INSTANCE_ID, envConfig.getString(CAS_INSTANCE_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_INSTANCE_ID))) {
+ properties.put(CAS_INSTANCE_ID, environment.getProperty(CAS_INSTANCE_ID));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_ENVIRONMENT_ID))) {
- properties.put(CAS_ENVIRONMENT_ID, envConfig.getString(CAS_ENVIRONMENT_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_ENVIRONMENT_ID))) {
+ properties.put(CAS_ENVIRONMENT_ID, environment.getProperty(CAS_ENVIRONMENT_ID));
}
- String[] instancePropArray = envConfig.getStringArray(INSTANCE_PROPS);
+ String[] instancePropArray = ConfigUtil.parseArrayValue(environment.getProperty(INSTANCE_PROPS))
+ .toArray(new String[0]);
if (instancePropArray.length != 0) {
properties.putAll(parseProps(instancePropArray));
}
[servicecomb-java-chassis] 14/25: [SCB-2008]remove archaius dependency: remove ArchaiusUtils usage and DynamicProperty
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 4120fa790ccc3956b3bf6aa242f4993c009a439d
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 11:11:56 2023 +0800
[SCB-2008]remove archaius dependency: remove ArchaiusUtils usage and DynamicProperty
---
.../config/inject/PlaceholderResolver.java | 4 +-
.../config/priority/TestPriorityPropertyBase.java | 11 ++-
.../java/org/apache/servicecomb/qps/Config.java | 2 +
.../servicecomb/qps/ConsumerFlowControlFilter.java | 7 +-
.../qps/FlowControlQpsConfiguration.java | 9 +-
.../servicecomb/qps/ProviderFlowControlFilter.java | 7 +-
.../servicecomb/qps/QpsControllerManager.java | 101 +++++++--------------
.../servicecomb/qps/QpsControllerManagerTest.java | 64 +++++++++----
.../generator/core/TestSwaggerGenerator.java | 21 ++---
9 files changed, 120 insertions(+), 106 deletions(-)
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/PlaceholderResolver.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/PlaceholderResolver.java
index 050bcf50e..b05ab11a7 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/PlaceholderResolver.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/PlaceholderResolver.java
@@ -25,7 +25,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
/**
* <pre>
@@ -203,7 +203,7 @@ public class PlaceholderResolver {
private Object findValue(Map<String, Object> parameters, String key) {
Object value = parameters.get(key);
if (value == null) {
- value = ConfigUtil.getProperty(key);
+ value = LegacyPropertyFactory.getStringProperty(key);
}
return value;
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
index 4f76abbae..1b2d5f450 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
@@ -16,24 +16,31 @@
*/
package org.apache.servicecomb.config.priority;
-import com.netflix.config.DynamicPropertyFactory;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
+
+import com.netflix.config.DynamicPropertyFactory;
public class TestPriorityPropertyBase {
protected PriorityPropertyManager priorityPropertyManager;
protected PriorityPropertyFactory propertyFactory;
+ protected Environment environment;
+
@BeforeEach
public void setup() {
// avoid write too many logs
Configurator.setRootLevel(Level.OFF);
- ArchaiusUtils.resetConfig();
+ environment = Mockito.mock(Environment.class);
+ LegacyPropertyFactory.setEnvironment(environment);
// make sure create a DynamicPropertyFactory instance
// otherwise will cause wrong order of configurationListeners
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/Config.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/Config.java
index c7f286c2d..8325352d7 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/Config.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/Config.java
@@ -20,6 +20,8 @@ package org.apache.servicecomb.qps;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
public final class Config {
+ public static final String CONFIG_PREFIX = "servicecomb.flowcontrol.";
+
public static final String STRATEGY_KEY = "servicecomb.flowcontrol.strategy";
public static final String ANY_SERVICE = "ANY";
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
index ac848c56a..749514aae 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
@@ -29,11 +29,16 @@ import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
public class ConsumerFlowControlFilter implements ConsumerFilter {
- private final QpsControllerManager qpsControllerMgr = new QpsControllerManager(false);
+ private final QpsControllerManager qpsControllerMgr;
+
+ public ConsumerFlowControlFilter(Environment environment) {
+ qpsControllerMgr = new QpsControllerManager(false, environment);
+ }
@VisibleForTesting
public QpsControllerManager getQpsControllerMgr() {
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/FlowControlQpsConfiguration.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/FlowControlQpsConfiguration.java
index de13eae57..27bef6dcb 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/FlowControlQpsConfiguration.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/FlowControlQpsConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.qps;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
@Configuration
@ConditionalOnProperty(value = FlowControlQpsConfiguration.FLOW_CONTROL_ENABLED,
@@ -29,12 +30,12 @@ public class FlowControlQpsConfiguration {
public static final String FLOW_CONTROL_ENABLED = FLOW_CONTROL_PREFIX + ".enabled";
@Bean
- public ProviderFlowControlFilter providerFlowControlFilter() {
- return new ProviderFlowControlFilter();
+ public ProviderFlowControlFilter providerFlowControlFilter(Environment environment) {
+ return new ProviderFlowControlFilter(environment);
}
@Bean
- public ConsumerFlowControlFilter consumerFlowControlFilter() {
- return new ConsumerFlowControlFilter();
+ public ConsumerFlowControlFilter consumerFlowControlFilter(Environment environment) {
+ return new ConsumerFlowControlFilter(environment);
}
}
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
index 9f5dcbbc3..c941f2900 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
@@ -30,11 +30,16 @@ import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
public class ProviderFlowControlFilter implements ProviderFilter {
- private final QpsControllerManager qpsControllerMgr = new QpsControllerManager(true);
+ private final QpsControllerManager qpsControllerMgr;
+
+ public ProviderFlowControlFilter(Environment environment) {
+ qpsControllerMgr = new QpsControllerManager(true, environment);
+ }
@Override
public int getOrder(InvocationType invocationType, String application, String serviceName) {
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
index 436d6db13..8e33088e3 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
@@ -17,23 +17,26 @@
package org.apache.servicecomb.qps;
-import java.util.Iterator;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.qps.strategy.AbstractQpsStrategy;
import org.apache.servicecomb.qps.strategy.IStrategyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.DynamicProperty;
+import com.google.common.eventbus.Subscribe;
public class QpsControllerManager {
private static final Logger LOGGER = LoggerFactory.getLogger(QpsControllerManager.class);
@@ -60,7 +63,10 @@ public class QpsControllerManager {
private final String globalBucketKey;
- public QpsControllerManager(boolean isProvider) {
+ private final Environment environment;
+
+ public QpsControllerManager(boolean isProvider, Environment environment) {
+ this.environment = environment;
if (isProvider) {
limitKeyPrefix = Config.PROVIDER_LIMIT_KEY_PREFIX;
bucketKeyPrefix = Config.PROVIDER_BUCKET_KEY_PREFIX;
@@ -74,6 +80,24 @@ public class QpsControllerManager {
}
initGlobalQpsController();
+ EventManager.register(this);
+ }
+
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ Map<String, Object> changed = new HashMap<>();
+ changed.putAll(event.getDeleted());
+ changed.putAll(event.getAdded());
+ changed.putAll(event.getUpdated());
+
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(Config.CONFIG_PREFIX)) {
+ configQpsControllerMap.clear();
+ qualifiedNameControllerMap.clear();
+ initGlobalQpsController();
+ break;
+ }
+ }
}
@VisibleForTesting
@@ -172,74 +196,19 @@ public class QpsControllerManager {
}
LOGGER.info("Create qpsController, configKey = [{}]", configKey);
- DynamicProperty limitProperty = DynamicProperty.getInstance(limitKeyPrefix + configKey);
- DynamicProperty bucketProperty = DynamicProperty.getInstance(bucketKeyPrefix + configKey);
- DynamicProperty strategyProperty = DynamicProperty.getInstance(Config.STRATEGY_KEY);
- AbstractQpsStrategy qpsStrategy = chooseStrategy(configKey, limitProperty.getLong(),
- bucketProperty.getLong(), strategyProperty.getString());
-
- strategyProperty.addCallback(() -> {
- AbstractQpsStrategy innerQpsStrategy = chooseStrategy(configKey, limitProperty.getLong(),
- bucketProperty.getLong(), strategyProperty.getString());
- configQpsControllerMap.put(configKey, innerQpsStrategy);
- LOGGER.info("Global flow control strategy update, value = [{}]",
- strategyProperty.getString());
- updateObjMap();
- });
- limitProperty.addCallback(() -> {
- qpsStrategy.setQpsLimit(limitProperty.getLong());
- LOGGER.info("Qps limit updated, configKey = [{}], value = [{}]", configKey,
- limitProperty.getString());
- updateObjMap();
- });
- bucketProperty.addCallback(() -> {
- qpsStrategy.setBucketLimit(bucketProperty.getLong());
- LOGGER.info("bucket limit updated, configKey = [{}], value = [{}]", configKey,
- bucketProperty.getString());
- updateObjMap();
- });
+ AbstractQpsStrategy qpsStrategy = chooseStrategy(configKey,
+ environment.getProperty(limitKeyPrefix + configKey, Long.class),
+ environment.getProperty(bucketKeyPrefix + configKey, Long.class),
+ environment.getProperty(Config.STRATEGY_KEY));
configQpsControllerMap.put(configKey, qpsStrategy);
}
- protected void updateObjMap() {
- Iterator<Entry<String, AbstractQpsStrategy>> it = qualifiedNameControllerMap.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<String, AbstractQpsStrategy> entry = it.next();
- AbstractQpsStrategy qpsStrategy = searchQpsController(entry.getKey());
- if (qpsStrategy == null) {
- it.remove();
- continue;
- }
- if (qpsStrategy != entry.getValue()) {
- entry.setValue(qpsStrategy);
- LOGGER.info("QpsController updated, operationId = [{}], configKey = [{}], qpsLimit = [{}]",
- entry.getKey(), qpsStrategy.getKey(), qpsStrategy.getQpsLimit());
- }
- }
- }
-
private void initGlobalQpsController() {
- DynamicProperty globalLimitProperty = DynamicProperty.getInstance(globalLimitKey);
- DynamicProperty globalBucketProperty = DynamicProperty.getInstance(globalBucketKey);
- DynamicProperty globalStrategyProperty = DynamicProperty
- .getInstance(Config.STRATEGY_KEY);
- globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE),
- globalBucketProperty.getLong(), globalStrategyProperty.getString());
- globalStrategyProperty.addCallback(() -> {
- globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE),
- globalBucketProperty.getLong(), globalStrategyProperty.getString());
- LOGGER.info("Global flow control strategy update, value = [{}]",
- globalStrategyProperty.getString());
- });
- globalLimitProperty.addCallback(() -> {
- globalQpsStrategy.setQpsLimit(globalLimitProperty.getLong((long) Integer.MAX_VALUE));
- LOGGER.info("Global qps limit update, value = [{}]", globalLimitProperty.getLong());
- });
- globalBucketProperty.addCallback(() -> {
- globalQpsStrategy.setBucketLimit(globalBucketProperty.getLong());
- LOGGER.info("Global bucket limit update, value = [{}]", globalBucketProperty.getLong());
- });
+ globalQpsStrategy = chooseStrategy(globalLimitKey,
+ environment.getProperty(globalLimitKey, Long.class, (long) Integer.MAX_VALUE),
+ environment.getProperty(globalBucketKey, Long.class),
+ environment.getProperty(Config.STRATEGY_KEY));
}
private AbstractQpsStrategy chooseStrategy(String configKey, Long limit, Long bucket,
diff --git a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
index 8f4aaf135..e2b5f79fa 100644
--- a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
+++ b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/QpsControllerManagerTest.java
@@ -17,28 +17,36 @@
package org.apache.servicecomb.qps;
+import java.util.HashMap;
+
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.qps.strategy.AbstractQpsStrategy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class QpsControllerManagerTest {
+ static Environment environment = Mockito.mock(Environment.class);
@BeforeEach
public void beforeTest() {
- // TODO: fix DynamicProperty
- ArchaiusUtils.resetConfig();
+ Mockito.when(environment.getProperty(Config.PROVIDER_LIMIT_KEY_GLOBAL, Long.class, (long) Integer.MAX_VALUE))
+ .thenReturn((long) Integer.MAX_VALUE);
+ Mockito.when(environment.getProperty(Config.CONSUMER_LIMIT_KEY_GLOBAL, Long.class, (long) Integer.MAX_VALUE))
+ .thenReturn((long) Integer.MAX_VALUE);
}
@AfterEach
public void afterTest() {
- ArchaiusUtils.resetConfig();
+
}
@Test
@@ -49,7 +57,7 @@ public class QpsControllerManagerTest {
Mockito.when(invocation.getSchemaId()).thenReturn("server");
Mockito.when(operationMeta.getSchemaQualifiedName()).thenReturn("server.test");
- QpsControllerManager testQpsControllerManager = new QpsControllerManager(false);
+ QpsControllerManager testQpsControllerManager = new QpsControllerManager(false, environment);
initTestQpsControllerManager(false, testQpsControllerManager, invocation, operationMeta);
// pojo
@@ -65,12 +73,23 @@ public class QpsControllerManagerTest {
Assertions.assertEquals(Config.CONSUMER_LIMIT_KEY_GLOBAL, ((AbstractQpsStrategy) qpsStrategy).getKey());
Assertions.assertEquals(Integer.MAX_VALUE, ((AbstractQpsStrategy) qpsStrategy).getQpsLimit().intValue());
- ArchaiusUtils.setProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server", 10000);
+ Mockito.when(environment.getProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server",
+ Long.class)).thenReturn(Long.valueOf(10000));
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put("servicecomb.flowcontrol.Consumer.qps.limit.poj.server", Long.valueOf(10000));
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
qpsStrategy = testQpsControllerManager.getOrCreate("poj", invocation);
Assertions.assertEquals("poj.server", ((AbstractQpsStrategy) qpsStrategy).getKey());
Assertions.assertEquals(((AbstractQpsStrategy) qpsStrategy).getQpsLimit(), (Long) 10000L);
- ArchaiusUtils.setProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server.test", 20000);
+ InMemoryDynamicPropertiesSource.update("servicecomb.flowcontrol.Consumer.qps.limit.poj.server.test", 20000);
+ Mockito.when(environment.getProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server.test",
+ Long.class)).thenReturn(Long.valueOf(20000));
+ updated = new HashMap<>();
+ updated.put("servicecomb.flowcontrol.Consumer.qps.limit.poj.server.test", Long.valueOf(20000));
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
qpsStrategy = testQpsControllerManager.getOrCreate("poj", invocation);
Assertions.assertEquals("poj.server.test", ((AbstractQpsStrategy) qpsStrategy).getKey());
Assertions.assertEquals(((AbstractQpsStrategy) qpsStrategy).getQpsLimit(), (Long) 20000L);
@@ -86,10 +105,15 @@ public class QpsControllerManagerTest {
Mockito.when(invocation.getSchemaId()).thenReturn("server");
Mockito.when(operationMeta.getSchemaQualifiedName()).thenReturn("server.test");
- QpsControllerManager testQpsControllerManager = new QpsControllerManager(true);
+ QpsControllerManager testQpsControllerManager = new QpsControllerManager(true, environment);
// global
- setConfig(Config.PROVIDER_LIMIT_KEY_GLOBAL, 50);
+ Mockito.when(environment.getProperty(Config.PROVIDER_LIMIT_KEY_GLOBAL, Long.class,
+ (long) Integer.MAX_VALUE)).thenReturn(50L);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(Config.PROVIDER_LIMIT_KEY_GLOBAL, 50L);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
QpsStrategy qpsStrategy = testQpsControllerManager.getOrCreate("pojo", invocation);
Assertions.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, ((AbstractQpsStrategy) qpsStrategy).getKey());
Assertions.assertEquals(50, (long) ((AbstractQpsStrategy) qpsStrategy).getQpsLimit());
@@ -122,7 +146,7 @@ public class QpsControllerManagerTest {
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(invocation.getSchemaId()).thenReturn("schema");
Mockito.when(operationMeta.getSchemaQualifiedName()).thenReturn("schema.opr");
- QpsControllerManager qpsControllerManager = new QpsControllerManager(true);
+ QpsControllerManager qpsControllerManager = new QpsControllerManager(true, environment);
QpsStrategy qpsStrategy = qpsControllerManager.getOrCreate("service", invocation);
Assertions.assertEquals("servicecomb.flowcontrol.Provider.qps.global.limit",
((AbstractQpsStrategy) qpsStrategy).getKey());
@@ -316,17 +340,16 @@ public class QpsControllerManagerTest {
return operationMeta;
}
- public static void setConfig(String key, int value) {
- ArchaiusUtils.setProperty(key, value);
- }
-
private static void setConfigWithDefaultPrefix(boolean isProvider, String key, int value) {
String configKey = Config.CONSUMER_LIMIT_KEY_PREFIX + key;
if (isProvider) {
configKey = Config.PROVIDER_LIMIT_KEY_PREFIX + key;
}
- ArchaiusUtils.setProperty(configKey, value);
+ Mockito.when(environment.getProperty(configKey, Long.class)).thenReturn(Long.valueOf(value));
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(configKey, value);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
}
private static void deleteConfigWithDefaultPrefix(boolean isProvider, String key) {
@@ -335,7 +358,10 @@ public class QpsControllerManagerTest {
configKey = Config.PROVIDER_LIMIT_KEY_PREFIX + key;
}
- ArchaiusUtils.setProperty(configKey, null);
+ Mockito.when(environment.getProperty(configKey, Long.class)).thenReturn(null);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(configKey, null);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
}
@Test
@@ -346,7 +372,7 @@ public class QpsControllerManagerTest {
final String operationId = "add";
final String configKey = "springmvcClient.controller.add";
- QpsControllerManager testManager = new QpsControllerManager(true);
+ QpsControllerManager testManager = new QpsControllerManager(true, environment);
Invocation testInvocation = getMockInvocation(microserviceName, schemaId, operationId);
Mockito.when(testInvocation.getSchemaId()).thenReturn(schemaId);
@@ -358,6 +384,8 @@ public class QpsControllerManagerTest {
QpsStrategy strategy2 = testManager.getOrCreate(microserviceName, testInvocation);
- Assertions.assertEquals(strategy1, strategy2);
+ Assertions.assertEquals(((AbstractQpsStrategy) strategy1).getQpsLimit(),
+ ((AbstractQpsStrategy) strategy2).getQpsLimit());
+ Assertions.assertEquals(((AbstractQpsStrategy) strategy1).getQpsLimit(), Long.valueOf(Integer.MAX_VALUE));
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
index 79c7890f7..a05bbce20 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
@@ -17,29 +17,26 @@
package org.apache.servicecomb.swagger.generator.core;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.SwaggerUtils;
import org.apache.servicecomb.swagger.generator.pojo.PojoSwaggerGenerator;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class TestSwaggerGenerator {
- @BeforeClass
- public static void setup() {
- ArchaiusUtils.resetConfig();
- }
+ Environment environment = Mockito.mock(Environment.class);
- @AfterClass
- public static void teardown() {
- ArchaiusUtils.resetConfig();
+ @BeforeEach
+ public void setUp() {
+ LegacyPropertyFactory.setEnvironment(environment);
}
@Test
public void testBasePathPlaceHolder() {
- // TODO: fix PlaceholderResolver
- ArchaiusUtils.setProperty("var", "varValue");
+ Mockito.when(environment.getProperty("var")).thenReturn("varValue");
PojoSwaggerGenerator swaggerGenerator = new PojoSwaggerGenerator(null);
swaggerGenerator.setBasePath("/a/${var}/b");
[servicecomb-java-chassis] 06/25: [SCB-2008]change DynamicPropertyFactory to Environment: in edge core
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit d27969a56155104270a572084d898a7ea6131fbf
Author: liubao <bi...@qq.com>
AuthorDate: Sun Sep 24 18:00:48 2023 +0800
[SCB-2008]change DynamicPropertyFactory to Environment: in edge core
---
.../edge/core/CommonHttpEdgeDispatcher.java | 28 ++++++----
.../servicecomb/edge/core/EdgeAddHeaderFilter.java | 41 +++++++++-----
.../edge/core/EdgeCoreConfiguration.java | 5 +-
.../edge/core/URLMappedConfigurationLoader.java | 30 +++++------
.../edge/core/URLMappedEdgeDispatcher.java | 28 ++++++----
.../edge/core/TestURLMappedEdgeDispatcher.java | 62 +++++++++++++++++-----
6 files changed, 131 insertions(+), 63 deletions(-)
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
index f131caf28..fbeb0585d 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
@@ -19,7 +19,9 @@ package org.apache.servicecomb.edge.core;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
@@ -41,8 +43,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
+import com.google.common.eventbus.Subscribe;
import io.vertx.core.Future;
import io.vertx.core.Handler;
@@ -122,15 +123,22 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
}
private void loadConfigurations() {
- ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
- .getBackingConfigurationSource();
- configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
- config.addConfigurationListener(event -> {
- if (event.getPropertyName().startsWith(KEY_MAPPING_PREFIX)) {
- LOG.info("Map rule have been changed. Reload configurations. Event=" + event.getType());
- configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
+ configurations = URLMappedConfigurationLoader.loadConfigurations(environment, KEY_MAPPING_PREFIX);
+ }
+
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ Map<String, Object> changed = new HashMap<>();
+ changed.putAll(event.getDeleted());
+ changed.putAll(event.getAdded());
+ changed.putAll(event.getUpdated());
+
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(KEY_MAPPING_PREFIX)) {
+ loadConfigurations();
+ break;
}
- });
+ }
}
protected void onRequest(RoutingContext context) {
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
index 0a55d51dd..65a20bc7e 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
@@ -18,26 +18,31 @@ package org.apache.servicecomb.edge.core;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.transport.rest.client.RestClientTransportContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicPropertyFactory;
+import com.google.common.eventbus.Subscribe;
public class EdgeAddHeaderFilter implements ConsumerFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(EdgeAddHeaderFilter.class);
@@ -50,24 +55,36 @@ public class EdgeAddHeaderFilter implements ConsumerFilter {
private static final String KEY_HEADERS = PREFIX + ".allowedHeaders";
+ private final Environment environment;
+
private List<String> publicHeaders = new ArrayList<>();
private boolean enabled = false;
- public EdgeAddHeaderFilter() {
+ public EdgeAddHeaderFilter(Environment environment) {
+ this.environment = environment;
init();
- ConfigurationManager.getConfigInstance()
- .addConfigurationListener(event -> {
- if (StringUtils.startsWith(event.getPropertyName(), PREFIX)) {
- LOGGER.info("Public headers config have been changed. Event=" + event.getType());
- init();
- }
- });
+ EventManager.register(this);
+ }
+
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ Map<String, Object> changed = new HashMap<>();
+ changed.putAll(event.getDeleted());
+ changed.putAll(event.getAdded());
+ changed.putAll(event.getUpdated());
+
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(PREFIX)) {
+ init();
+ break;
+ }
+ }
}
private void init() {
- enabled = DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
- String publicHeaderStr = DynamicPropertyFactory.getInstance().getStringProperty(KEY_HEADERS, "").get();
+ enabled = environment.getProperty(KEY_ENABLED, boolean.class, false);
+ String publicHeaderStr = environment.getProperty(KEY_HEADERS, "");
String[] split = publicHeaderStr.split(",");
if (split.length > 0) {
publicHeaders = Arrays.asList(split);
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeCoreConfiguration.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeCoreConfiguration.java
index e6cb427ee..45333b7d0 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeCoreConfiguration.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeCoreConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.servicecomb.edge.core;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
@Configuration
public class EdgeCoreConfiguration {
@@ -32,7 +33,7 @@ public class EdgeCoreConfiguration {
}
@Bean
- public EdgeAddHeaderFilter edgeAddHeaderFilter() {
- return new EdgeAddHeaderFilter();
+ public EdgeAddHeaderFilter edgeAddHeaderFilter(Environment environment) {
+ return new EdgeAddHeaderFilter(environment);
}
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedConfigurationLoader.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedConfigurationLoader.java
index b7fd78f16..ae93c1349 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedConfigurationLoader.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedConfigurationLoader.java
@@ -18,16 +18,16 @@
package org.apache.servicecomb.edge.core;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.Environment;
public class URLMappedConfigurationLoader {
private static final Logger LOG = LoggerFactory.getLogger(URLMappedConfigurationLoader.class);
@@ -41,15 +41,13 @@ public class URLMappedConfigurationLoader {
private static final String KEY_MAPPING_PREFIX_SEGMENT_COUNT = "%s.%s.prefixSegmentCount";
public static Map<String, URLMappedConfigurationItem> loadConfigurations(
- ConcurrentCompositeConfiguration config, String configPrefix) {
+ Environment environment, String configPrefix) {
Map<String, URLMappedConfigurationItem> configurations = new HashMap<>();
- Iterator<String> configsItems = config.getKeys(configPrefix);
- while (configsItems.hasNext()) {
- String pathKey = configsItems.next();
+ Set<String> configsItems = ConfigUtil.propertiesWithPrefix((ConfigurableEnvironment) environment, configPrefix);
+ for (String pathKey : configsItems) {
if (pathKey.endsWith(KEY_MAPPING_PATH)) {
URLMappedConfigurationItem configurationItem = new URLMappedConfigurationItem();
- String pattern = DynamicPropertyFactory.getInstance()
- .getStringProperty(pathKey, null).get();
+ String pattern = environment.getProperty(pathKey);
if (StringUtils.isEmpty(pattern)) {
continue;
}
@@ -57,15 +55,15 @@ public class URLMappedConfigurationLoader {
configurationItem.setStringPattern(pattern);
String pathKeyItem = pathKey
.substring(configPrefix.length() + 1, pathKey.length() - KEY_MAPPING_PATH.length());
- configurationItem.setMicroserviceName(DynamicPropertyFactory.getInstance()
- .getStringProperty(String.format(KEY_MAPPING_SERVICE_NAME, configPrefix, pathKeyItem), null).get());
+ configurationItem.setMicroserviceName(environment.getProperty(
+ String.format(KEY_MAPPING_SERVICE_NAME, configPrefix, pathKeyItem)));
if (StringUtils.isEmpty(configurationItem.getMicroserviceName())) {
continue;
}
- configurationItem.setPrefixSegmentCount(DynamicPropertyFactory.getInstance()
- .getIntProperty(String.format(KEY_MAPPING_PREFIX_SEGMENT_COUNT, configPrefix, pathKeyItem), 0).get());
- configurationItem.setVersionRule(DynamicPropertyFactory.getInstance()
- .getStringProperty(String.format(KEY_MAPPING_VERSION_RULE, configPrefix, pathKeyItem), "0.0.0+").get());
+ configurationItem.setPrefixSegmentCount(environment.getProperty(
+ String.format(KEY_MAPPING_PREFIX_SEGMENT_COUNT, configPrefix, pathKeyItem), int.class, 0));
+ configurationItem.setVersionRule(environment.getProperty(
+ String.format(KEY_MAPPING_VERSION_RULE, configPrefix, pathKeyItem), "0.0.0+"));
configurations.put(pathKeyItem, configurationItem);
}
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
index 868e12e09..310381e8a 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -19,8 +19,10 @@ package org.apache.servicecomb.edge.core;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.core.invocation.InvocationCreator;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -33,8 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
+import com.google.common.eventbus.Subscribe;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
@@ -100,15 +101,22 @@ public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
}
private void loadConfigurations() {
- ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
- .getBackingConfigurationSource();
- configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
- config.addConfigurationListener(event -> {
- if (event.getPropertyName().startsWith(KEY_MAPPING_PREFIX)) {
- LOG.info("Map rule have been changed. Reload configurations. Event=" + event.getType());
- configurations = URLMappedConfigurationLoader.loadConfigurations(config, KEY_MAPPING_PREFIX);
+ configurations = URLMappedConfigurationLoader.loadConfigurations(environment, KEY_MAPPING_PREFIX);
+ }
+
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ Map<String, Object> changed = new HashMap<>();
+ changed.putAll(event.getDeleted());
+ changed.putAll(event.getAdded());
+ changed.putAll(event.getUpdated());
+
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(KEY_MAPPING_PREFIX)) {
+ loadConfigurations();
+ break;
}
- });
+ }
}
protected void preCheck(RoutingContext context) {
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
index 805374bd9..2e23ab673 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
@@ -17,36 +17,41 @@
package org.apache.servicecomb.edge.core;
+import java.util.HashMap;
import java.util.Map;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.transport.rest.vertx.RestBodyHandler;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.springframework.core.env.Environment;
-
-import com.netflix.config.DynamicPropertyFactory;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MutablePropertySources;
import io.vertx.ext.web.RoutingContext;
public class TestURLMappedEdgeDispatcher {
- Environment environment = Mockito.mock(Environment.class);
+ ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
@BeforeEach
public void setUp() throws Exception {
- DynamicPropertyFactory.getInstance();
}
@AfterEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
}
@Test
public void testConfigurations() {
+ EnumerablePropertySource<?> propertySource = Mockito.mock(EnumerablePropertySource.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ });
Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.enabled", boolean.class, false))
.thenReturn(true);
URLMappedEdgeDispatcher dispatcher = new URLMappedEdgeDispatcher();
@@ -58,10 +63,26 @@ public class TestURLMappedEdgeDispatcher {
Mockito.when(context.get(RestBodyHandler.BYPASS_BODY_HANDLER)).thenReturn(Boolean.TRUE);
dispatcher.onRequest(context);
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.path", "/a/b/c/.*");
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount", 2);
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule", "2.0.0+");
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.path",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule"
+ });
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.path"))
+ .thenReturn("/a/b/c/.*");
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount",
+ int.class, 0))
+ .thenReturn(2);
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule",
+ "0.0.0+"))
+ .thenReturn("2.0.0+");
+ Map<String, Object> latest = new HashMap<>();
+ latest.put("servicecomb.http.dispatcher.edge.url.mappings.service1.path", "/a/b/c/.*");
+ dispatcher.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
+
items = dispatcher.getConfigurations();
Assertions.assertEquals(items.size(), 1);
URLMappedConfigurationItem item = items.get("service1");
@@ -70,8 +91,23 @@ public class TestURLMappedEdgeDispatcher {
Assertions.assertEquals(item.getStringPattern(), "/a/b/c/.*");
Assertions.assertEquals(item.getVersionRule(), "2.0.0+");
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service2.versionRule", "2.0.0+");
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service3.path", "/b/c/d/.*");
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.path",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount",
+ "servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule",
+ "servicecomb.http.dispatcher.edge.url.mappings.service2.versionRule",
+ "servicecomb.http.dispatcher.edge.url.mappings.service3.path"
+ });
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service2.versionRule"))
+ .thenReturn("2.0.0+");
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.mappings.service3.path"))
+ .thenReturn("/b/c/d/.*");
+
+ latest = new HashMap<>();
+ latest.put("servicecomb.http.dispatcher.edge.url.mappings.service3.path", "/a/b/c/.*");
+ dispatcher.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
+
items = dispatcher.getConfigurations();
Assertions.assertEquals(items.size(), 1);
item = items.get("service1");
[servicecomb-java-chassis] 18/25: [SCB-2008]remove deployment module
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit ef42dbac08477ee36cdf484159584935daf455d1
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 16:32:19 2023 +0800
[SCB-2008]remove deployment module
---
core/pom.xml | 4 -
coverage-reports/pom.xml | 6 -
dependencies/bom/pom.xml | 7 -
deployment/README.md | 13 -
deployment/pom.xml | 71 -----
.../apache/servicecomb/deployment/Deployment.java | 35 ---
.../servicecomb/deployment/DeploymentProvider.java | 27 --
.../deployment/SystemBootstrapInfo.java | 47 ---
.../deployment/CustomDeploymentProvider.java | 48 ---
.../servicecomb/deployment/TestDeployment.java | 37 ---
...pache.servicecomb.deployment.DeploymentProvider | 18 --
distribution/pom.xml | 6 -
dynamic-config/config-cc/pom.xml | 4 -
.../servicecomb/config/cc/ConfigCenterConfig.java | 11 +-
.../cc/ConfigCenterDefaultDeploymentProvider.java | 53 ----
.../cc/ConfigCenterDynamicPropertiesSource.java | 4 +-
.../cc/ConfigCenterInformationCollector.java | 18 +-
...pache.servicecomb.deployment.DeploymentProvider | 17 --
.../TestConfigCenterDefaultDeploymentProvider.java | 67 -----
dynamic-config/config-kie/pom.xml | 4 -
.../KieCenterDefaultDeploymentProvider.java | 53 ----
.../kie/collect/KieClientInformationCollector.java | 19 +-
...pache.servicecomb.deployment.DeploymentProvider | 17 --
.../TestKieCenterDefaultDeploymentProvider.java | 69 -----
.../servicecomb/config/DynamicProperties.java | 4 -
.../apache/servicecomb/config/TestConfigUtil.java | 335 ---------------------
.../sources/TestYAMLConfigurationSource.java | 4 +-
.../src/test/resources/microservice.yaml | 6 -
huawei-cloud/dashboard/pom.xml | 4 -
.../monitor/DefaultMonitorDataPublisher.java | 20 +-
.../monitor/MonitorDefaultDeploymentProvider.java | 56 ----
.../monitor/MonitorInformationCollector.java | 22 +-
...pache.servicecomb.deployment.DeploymentProvider | 17 --
pom.xml | 1 -
service-registry/registry-local/pom.xml | 4 -
service-registry/registry-service-center/pom.xml | 4 -
36 files changed, 50 insertions(+), 1082 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index d0c3933a7..0b40ab80e 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -28,10 +28,6 @@
<name>Java Chassis::Core</name>
<dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-vertx</artifactId>
diff --git a/coverage-reports/pom.xml b/coverage-reports/pom.xml
index 8e672de7e..6fea27342 100644
--- a/coverage-reports/pom.xml
+++ b/coverage-reports/pom.xml
@@ -77,12 +77,6 @@
<artifactId>java-chassis-core</artifactId>
</dependency>
- <!-- deployment -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
-
<!-- dynamic-config -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index 4268ac285..f6febb1fa 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -90,13 +90,6 @@
<version>${project.version}</version>
</dependency>
- <!-- ServiceComb: deployment -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<!-- ServiceComb: dynamic-config -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/deployment/README.md b/deployment/README.md
deleted file mode 100644
index b2764cc0a..000000000
--- a/deployment/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# About Deployment Module
-
-Deployment is a mechanism to manage how microservics interact with external services. When running a microservice in a Cloud Native environment, it will interact with many external services, like service center, config center, an APM service to report tracing data, a dashboard service to report health data, etc. Deployment Service manages the meta data of these services. Deployment queries the addresses , the parameters, the authentication information of these services and so on.
-
-Deployment Service is some kind of service like service center, they are differ from two aspects:
-1. All microservics will report their information to service center. But Deployment Service acts as a management system and knows the meta information in deploy time.
-2. Service center provide some other functions like instance management and heartbeat, while Deployment Service only provides metadata query services and it is simple.
-
-This module does not provide a Deployment Service, it provides the interface to interacts with Deployment Service. Service providers can implement the interface.
-
-They are some design constraints need to be considered when implement Deployment interface:
-1. Deployment can only read configurations of environment, microservics.yaml. It can not read dynamic configurations.
-2. Deployment is initialized before bean initialization.
diff --git a/deployment/pom.xml b/deployment/pom.xml
deleted file mode 100644
index eb09e8728..000000000
--- a/deployment/pom.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>java-chassis-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <relativePath>../parents/default</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>deployment</artifactId>
- <name>Java Chassis::Deployment</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-config</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-vertx</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-common</artifactId>
- </dependency>
-
- <dependency>
- <groupId>io.vertx</groupId>
- <artifactId>vertx-codegen</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-test-scaffolding</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/deployment/src/main/java/org/apache/servicecomb/deployment/Deployment.java b/deployment/src/main/java/org/apache/servicecomb/deployment/Deployment.java
deleted file mode 100644
index 2a35110d9..000000000
--- a/deployment/src/main/java/org/apache/servicecomb/deployment/Deployment.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.deployment;
-
-import java.util.List;
-
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-
-public class Deployment {
- private static final List<DeploymentProvider> providerList = SPIServiceUtils.getSortedService(DeploymentProvider.class);
-
- public static SystemBootstrapInfo getSystemBootStrapInfo(String systemKey) {
- for (DeploymentProvider provider : providerList) {
- if (provider.getSystemBootStrapInfo(systemKey) != null) {
- return provider.getSystemBootStrapInfo(systemKey);
- }
- }
- return null;
- }
-}
diff --git a/deployment/src/main/java/org/apache/servicecomb/deployment/DeploymentProvider.java b/deployment/src/main/java/org/apache/servicecomb/deployment/DeploymentProvider.java
deleted file mode 100644
index e2e5396e5..000000000
--- a/deployment/src/main/java/org/apache/servicecomb/deployment/DeploymentProvider.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.deployment;
-
-public interface DeploymentProvider {
-
- default int getOrder() {
- return 100;
- }
-
- SystemBootstrapInfo getSystemBootStrapInfo(String systemKey);
-}
diff --git a/deployment/src/main/java/org/apache/servicecomb/deployment/SystemBootstrapInfo.java b/deployment/src/main/java/org/apache/servicecomb/deployment/SystemBootstrapInfo.java
deleted file mode 100644
index c98f93e6a..000000000
--- a/deployment/src/main/java/org/apache/servicecomb/deployment/SystemBootstrapInfo.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.deployment;
-
-import java.util.List;
-import java.util.Map;
-
-public class SystemBootstrapInfo {
- private List<String> accessURL;
-
- private Map<String, Object> properties;
-
- public List<String> getAccessURL() {
- return accessURL;
- }
-
- public void setAccessURL(List<String> accessURL) {
- this.accessURL = accessURL;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
-
- public Object getProperty(String key) {
- return properties.get(key);
- }
-}
diff --git a/deployment/src/test/java/org/apache/servicecomb/deployment/CustomDeploymentProvider.java b/deployment/src/test/java/org/apache/servicecomb/deployment/CustomDeploymentProvider.java
deleted file mode 100644
index 43c0a7177..000000000
--- a/deployment/src/test/java/org/apache/servicecomb/deployment/CustomDeploymentProvider.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.deployment;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.servicecomb.config.ConfigUtil;
-
-import java.util.Arrays;
-
-public class CustomDeploymentProvider implements DeploymentProvider {
- private static AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
-
- @Override
- public int getOrder() {
- return 0;
- }
-
- @Override
- public SystemBootstrapInfo getSystemBootStrapInfo(String systemKey) {
- if (!systemKey.equals("TestCenter")) {
- return null;
- }
- SystemBootstrapInfo cc = new SystemBootstrapInfo();
- cc.setAccessURL(Arrays.asList("http://localhost/custom"));
- return cc;
- }
-
- @VisibleForTesting
- public static void setConfiguration(AbstractConfiguration configuration) {
- CustomDeploymentProvider.configuration = configuration;
- }
-}
diff --git a/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java b/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
deleted file mode 100644
index 99637c4eb..000000000
--- a/deployment/src/test/java/org/apache/servicecomb/deployment/TestDeployment.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.deployment;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestDeployment {
- @AfterEach
- public void tearDown() {
- }
-
- @Test
- public void testConfiguration() {
- CustomDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo("TestCenter");
- Assertions.assertEquals("http://localhost/custom", info.getAccessURL().get(0));
- Assertions.assertNull(Deployment.getSystemBootStrapInfo("wrong"));
- }
-}
diff --git a/deployment/src/test/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/deployment/src/test/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
deleted file mode 100644
index d07cc1e76..000000000
--- a/deployment/src/test/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.deployment.CustomDeploymentProvider
diff --git a/distribution/pom.xml b/distribution/pom.xml
index 947433068..df56de4a5 100644
--- a/distribution/pom.xml
+++ b/distribution/pom.xml
@@ -79,12 +79,6 @@
<artifactId>java-chassis-core</artifactId>
</dependency>
- <!-- deployment -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
-
<!-- dynamic-config -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/dynamic-config/config-cc/pom.xml b/dynamic-config/config-cc/pom.xml
index a841532d7..42786bce1 100644
--- a/dynamic-config/config-cc/pom.xml
+++ b/dynamic-config/config-cc/pom.xml
@@ -33,10 +33,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-config</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-ssl</artifactId>
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
index 0522f5b43..3476bb2e6 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
@@ -20,7 +20,7 @@ package org.apache.servicecomb.config.cc;
import java.util.Collections;
import java.util.List;
-import org.apache.servicecomb.deployment.Deployment;
+import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.vertx.VertxConst;
import org.springframework.core.env.Environment;
@@ -33,6 +33,8 @@ public final class ConfigCenterConfig {
private static final String AUTO_DISCOVERY_ENABLED = "servicecomb.service.registry.autodiscovery";
+ private static final String ADDRESS = "servicecomb.config.client.serverUri";
+
private static final String DOMAIN_NAME = "servicecomb.config.client.domainName";
private static final String REFRESH_INTERVAL = "servicecomb.config.client.refresh_interval";
@@ -96,11 +98,6 @@ public final class ConfigCenterConfig {
}
public List<String> getServerUri() {
- return Deployment.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER)
- .getAccessURL();
- }
-
- public boolean getAutoDiscoveryEnabled() {
- return environment.getProperty(AUTO_DISCOVERY_ENABLED, boolean.class, false);
+ return ConfigUtil.parseArrayValue(environment.getProperty(ADDRESS, ""));
}
}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java
deleted file mode 100644
index e6e836c47..000000000
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.cc;
-
-import java.util.List;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.deployment.DeploymentProvider;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class ConfigCenterDefaultDeploymentProvider implements DeploymentProvider {
- public static final String SYSTEM_KEY_CONFIG_CENTER = "ConfigCenter";
-
- private static AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
-
- @Override
- public SystemBootstrapInfo getSystemBootStrapInfo(String systemKey) {
- if (!systemKey.equals(SYSTEM_KEY_CONFIG_CENTER)) {
- return null;
- }
- List<String> ccAddresses = ConfigUtil
- .parseArrayValue(configuration.getString("servicecomb.config.client.serverUri"));
- if (ccAddresses.isEmpty()) {
- return null;
- }
- SystemBootstrapInfo cc = new SystemBootstrapInfo();
- cc.setAccessURL(ccAddresses);
- return cc;
- }
-
- @VisibleForTesting
- public static void setConfiguration(AbstractConfiguration configuration) {
- ConfigCenterDefaultDeploymentProvider.configuration = configuration;
- }
-}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
index 089741159..22de503db 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
@@ -37,7 +37,6 @@ import org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequ
import org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse;
import org.apache.servicecomb.config.common.ConfigConverter;
import org.apache.servicecomb.config.common.ConfigurationChangedEvent;
-import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.event.EventManager;
@@ -182,8 +181,7 @@ public class ConfigCenterDynamicPropertiesSource implements DynamicPropertiesSou
private ConfigCenterAddressManager configKieAddressManager() {
return new ConfigCenterAddressManager(configCenterConfig.getDomainName(),
- Deployment
- .getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER).getAccessURL(),
+ configCenterConfig.getServerUri(),
EventManager.getEventBus());
}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
index 76cc6fa19..e5b774129 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
@@ -18,24 +18,24 @@
package org.apache.servicecomb.config.cc;
import org.apache.servicecomb.core.bootup.BootUpInformationCollector;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-
-import java.util.Objects;
+import org.springframework.beans.factory.annotation.Autowired;
public class ConfigCenterInformationCollector implements BootUpInformationCollector {
+ private ConfigCenterConfig configCenterConfig;
+
+ @Autowired
+ public void setConfigCenterConfig(ConfigCenterConfig configCenterConfig) {
+ this.configCenterConfig = configCenterConfig;
+ }
+
@Override
public String collect() {
- return "Config Center: " + getCenterInfo(Deployment.getSystemBootStrapInfo("ConfigCenter"));
+ return "Config Center: " + configCenterConfig.getServerUri();
}
@Override
public int getOrder() {
return 1;
}
-
- private String getCenterInfo(SystemBootstrapInfo systemBootstrapInfo) {
- return Objects.isNull(systemBootstrapInfo) ? "not exist" : systemBootstrapInfo.getAccessURL().toString();
- }
}
diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
deleted file mode 100644
index bd9118aff..000000000
--- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
deleted file mode 100644
index 51af1da3f..000000000
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.cc;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-public class TestConfigCenterDefaultDeploymentProvider {
- @BeforeEach
- public void start() {
- }
-
- @AfterEach
- public void tearDown() {
- }
-
- @Test
- public void testConfiguration() {
- ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
- Assertions.assertEquals("https://172.16.8.7:30103", info.getAccessURL().get(0));
- Assertions.assertNull(Deployment.getSystemBootStrapInfo("wrong"));
- }
-
- @Test
- public void testConfigurationEnv() {
- System.setProperty("servicecomb.config.client.serverUri", "https://localhost:9988");
- ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
- Assertions.assertEquals("https://localhost:9988", info.getAccessURL().get(0));
- System.getProperties().remove("servicecomb.config.client.serverUri");
- }
-
- @Test
- public void testConfigurationEnvTwo() {
- System.setProperty("servicecomb.config.client.serverUri", "https://localhost:9988,https://localhost:9987");
- ConfigCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
- Assertions.assertEquals(2, info.getAccessURL().size());
- Assertions.assertEquals("https://localhost:9988", info.getAccessURL().get(0));
- Assertions.assertEquals("https://localhost:9987", info.getAccessURL().get(1));
- System.getProperties().remove("servicecomb.config.client.serverUri");
- }
-}
diff --git a/dynamic-config/config-kie/pom.xml b/dynamic-config/config-kie/pom.xml
index 513c0641f..4a3a7f2cd 100644
--- a/dynamic-config/config-kie/pom.xml
+++ b/dynamic-config/config-kie/pom.xml
@@ -35,10 +35,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-config</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-ssl</artifactId>
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieCenterDefaultDeploymentProvider.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieCenterDefaultDeploymentProvider.java
deleted file mode 100644
index 9412314d4..000000000
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieCenterDefaultDeploymentProvider.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.kie.collect;
-
-import java.util.List;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.deployment.DeploymentProvider;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class KieCenterDefaultDeploymentProvider implements DeploymentProvider {
- public static final String SYSTEM_KEY_KIE_CENTER = "KieCenter";
-
- private static AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
-
- @Override
- public SystemBootstrapInfo getSystemBootStrapInfo(String systemKey) {
- if (!systemKey.equals(SYSTEM_KEY_KIE_CENTER)) {
- return null;
- }
- List<String> kieAddresses = ConfigUtil
- .parseArrayValue(configuration.getString("servicecomb.kie.serverUri"));
- if (kieAddresses.isEmpty()) {
- return null;
- }
- SystemBootstrapInfo kie = new SystemBootstrapInfo();
- kie.setAccessURL(kieAddresses);
- return kie;
- }
-
- @VisibleForTesting
- public static void setConfiguration(AbstractConfiguration configuration) {
- KieCenterDefaultDeploymentProvider.configuration = configuration;
- }
-}
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieClientInformationCollector.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieClientInformationCollector.java
index eed0c9d4c..135f0319a 100644
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieClientInformationCollector.java
+++ b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/collect/KieClientInformationCollector.java
@@ -17,25 +17,26 @@
package org.apache.servicecomb.config.kie.collect;
+import org.apache.servicecomb.config.kie.KieConfig;
import org.apache.servicecomb.core.bootup.BootUpInformationCollector;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-
-import java.util.Objects;
+import org.springframework.beans.factory.annotation.Autowired;
public class KieClientInformationCollector implements BootUpInformationCollector {
+ private KieConfig kieConfig;
+
+ @Autowired
+ public void setKieConfig(KieConfig kieConfig) {
+ this.kieConfig = kieConfig;
+ }
+
@Override
public String collect() {
- return "Kie Center: " + getCenterInfo(Deployment.getSystemBootStrapInfo("KieCenter"));
+ return "Kie Center: " + kieConfig.getServerUri();
}
@Override
public int getOrder() {
return 2;
}
-
- private String getCenterInfo(SystemBootstrapInfo systemBootstrapInfo) {
- return Objects.isNull(systemBootstrapInfo) ? "not exist" : systemBootstrapInfo.getAccessURL().toString();
- }
}
diff --git a/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
deleted file mode 100644
index c712d01e3..000000000
--- a/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-org.apache.servicecomb.config.kie.collect.KieCenterDefaultDeploymentProvider
\ No newline at end of file
diff --git a/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java b/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
deleted file mode 100644
index fa659843d..000000000
--- a/dynamic-config/config-kie/src/test/java/org/apache/servicecomb/config/kie/collect/TestKieCenterDefaultDeploymentProvider.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.kie.collect;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-public class TestKieCenterDefaultDeploymentProvider {
- @BeforeEach
- public void start() {
- }
-
- @AfterEach
- public void tearDown() {
- }
-
- @Test
- public void testConfiguration() {
- KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
- Assertions.assertEquals("https://172.16.8.7:30110", info.getAccessURL().get(0));
- Assertions.assertNull(Deployment.getSystemBootStrapInfo("wrong"));
- }
-
- @Test
- public void testConfigurationEnv() {
- System.setProperty("servicecomb.kie.serverUri", "https://localhost:30110");
- KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
- Assertions.assertEquals("https://localhost:30110", info.getAccessURL().get(0));
- System.getProperties().remove("servicecomb.kie.serverUri");
- }
-
- @Test
- public void testConfigurationEnvTwo() {
- System.setProperty("servicecomb.kie.serverUri", "http://127.0.0.1:30110,http://127.0.0.2:30110");
- KieCenterDefaultDeploymentProvider.setConfiguration(ConfigUtil.createLocalConfig());
-
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- KieCenterDefaultDeploymentProvider.SYSTEM_KEY_KIE_CENTER);
- Assertions.assertEquals(2, info.getAccessURL().size());
- Assertions.assertEquals("http://127.0.0.1:30110", info.getAccessURL().get(0));
- Assertions.assertEquals("http://127.0.0.2:30110", info.getAccessURL().get(1));
-
- System.getProperties().remove("servicecomb.kie.serverUri");
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicProperties.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicProperties.java
index 47e060af7..58f84dd97 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicProperties.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicProperties.java
@@ -23,10 +23,6 @@ import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
public interface DynamicProperties {
-
- DynamicProperties DEFAULT_PROPERTY_OBSERVATION = new DynamicProperties() {
- };
-
default String getStringProperty(String propertyName, Consumer<String> consumer, String defaultValue) {
return defaultValue;
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
deleted file mode 100644
index 08c409f3e..000000000
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config;
-
-import static com.seanyinx.github.unit.scaffolding.Randomness.uniquify;
-import static org.hamcrest.CoreMatchers.equalTo;
-
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
-import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
-import org.hamcrest.MatcherAssert;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicWatchedConfiguration;
-
-import mockit.Expectations;
-import mockit.Mock;
-import mockit.MockUp;
-
-import org.junit.jupiter.api.Assertions;
-
-public class TestConfigUtil {
- private static final String systemPropertyName = "servicecomb.cse.servicecomb.system.setting";
-
- private static final String systemExpected = uniquify("ran");
-
- private static final String environmentPropertyName = "servicecomb.cse.servicecomb.environment.setting";
-
- private static final String environmentExpected = uniquify("ran");
-
- private final MapBasedConfigurationSource configurationSource = new MapBasedConfigurationSource();
-
- @BeforeClass
- public static void beforeTest() {
- Configurator.setRootLevel(Level.OFF);
-
- ArchaiusUtils.resetConfig();
-
- System.setProperty(systemPropertyName, systemExpected);
- try {
- setEnv(environmentPropertyName, environmentExpected);
- setEnv("MY_SERVICES_ENDPOINT", "https://myhost:8888");
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
-
- ConfigUtil.installDynamicConfig();
-
- Configurator.setRootLevel(Level.INFO);
- }
-
- @AfterClass
- public static void tearDown() {
- ArchaiusUtils.resetConfig();
- }
-
- @Test
- public void testArrayData() {
- Configuration configuration = ConfigUtil.createLocalConfig();
- Assertions.assertEquals("a,b,c", configuration.getString("test.commonSeparatedString"));
- Assertions.assertEquals(1, configuration.getStringArray("test.commonSeparatedString").length);
- Assertions.assertEquals("a,b,c", configuration.getStringArray("test.commonSeparatedString")[0]);
-
- Assertions.assertEquals("b,c,d", configuration.getString("test.commonSeparatedStringHolder"));
- Assertions.assertEquals(1, configuration.getStringArray("test.commonSeparatedStringHolder").length);
- Assertions.assertEquals("b,c,d", configuration.getStringArray("test.commonSeparatedStringHolder")[0]);
-
- Assertions.assertEquals("m", configuration.getString("test.stringArray")); // first element
- Assertions.assertEquals(2, configuration.getStringArray("test.stringArray").length);
- Assertions.assertEquals("m", configuration.getStringArray("test.stringArray")[0]);
- Assertions.assertEquals("n", configuration.getStringArray("test.stringArray")[1]);
- }
-
- @Test
- public void testAddConfig() {
- Map<String, Object> config = new HashMap<>();
- config.put("service_description.name", "service_name_test");
- ConfigUtil.setConfigs(config);
- ConfigUtil.addConfig("service_description.version", "1.0.2");
- ConfigUtil.addConfig("cse.test.enabled", true);
- ConfigUtil.addConfig("cse.test.num", 10);
- AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
- Assertions.assertEquals(configuration.getString("service_description.name"), "service_name_test");
- Assertions.assertTrue(configuration.getBoolean("cse.test.enabled"));
- Assertions.assertEquals(configuration.getInt("cse.test.num"), 10);
- }
-
- @Test
- public void testCreateDynamicConfigNoConfigCenterSPI() {
- AbstractConfiguration dynamicConfig = ConfigUtil.createLocalConfig();
- Assertions.assertNotEquals(DynamicWatchedConfiguration.class,
- ((ConcurrentCompositeConfiguration) dynamicConfig).getConfiguration(0).getClass());
- }
-
- @Test
- public void testGetPropertyInvalidConfig() {
- Assertions.assertNull(ConfigUtil.getProperty(null, "any"));
- Assertions.assertNull(ConfigUtil.getProperty(new Object(), "any"));
- }
-
- @Test
- public void propertiesFromFileIsDuplicatedToCse() {
- String expected = "value";
-
- Assertions.assertNull(DynamicPropertyFactory
- .getInstance()
- .getStringProperty("cse.cse.servicecomb.file", null)
- .get());
-
- Assertions.assertEquals(expected, DynamicPropertyFactory
- .getInstance()
- .getStringProperty("servicecomb.cse.servicecomb.file", null)
- .get());
- }
-
- @Test
- public void propertiesFromSystemIsDuplicatedToCse() {
- MatcherAssert.assertThat(DynamicPropertyFactory
- .getInstance()
- .getStringProperty(systemPropertyName, null)
- .get(),
- equalTo(systemExpected));
-
- MatcherAssert.assertThat(DynamicPropertyFactory
- .getInstance()
- .getStringProperty("servicecomb.cse.servicecomb.system.setting", null)
- .get(),
- equalTo(systemExpected));
- }
-
- @Test
- public void propertiesFromEnvironmentIsDuplicatedToCse() {
- MatcherAssert.assertThat(DynamicPropertyFactory
- .getInstance()
- .getStringProperty(environmentPropertyName, null)
- .get(),
- equalTo(environmentExpected));
-
- MatcherAssert.assertThat(DynamicPropertyFactory
- .getInstance()
- .getStringProperty("servicecomb.cse.servicecomb.environment.setting", null)
- .get(),
- equalTo(environmentExpected));
- }
-
- @Test
- public void propertiesAddFromDynamicConfigSourceIsDuplicated() {
- String expected = uniquify("ran");
- String someProperty = "cse.cse.servicecomb.add";
-
- configurationSource.addProperty(someProperty, expected);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- String changed = uniquify("changed");
- configurationSource.addProperty(someProperty, changed);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(changed));
-
- expected = uniquify("ran");
- someProperty = "cse.servicecomb.cse.add";
-
- configurationSource.addProperty(someProperty, expected);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- changed = uniquify("changed");
- configurationSource.addProperty(someProperty, changed);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(changed));
- }
-
- @Test
- public void propertiesChangeFromDynamicConfigSourceIsDuplicated() {
- String expected = uniquify("ran");
- String someProperty = "cse.cse.servicecomb.change";
- configurationSource.addProperty(someProperty, expected);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- String changed = uniquify("changed");
- configurationSource.setProperty(someProperty, changed);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(changed));
-
- expected = uniquify("ran");
- someProperty = "cse.servicecomb.cse.change";
-
- configurationSource.addProperty(someProperty, expected);
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- changed = uniquify("changed");
- configurationSource.setProperty(someProperty, changed);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(changed));
- }
-
- @Test
- public void propertiesDeleteFromDynamicConfigSourceIsDuplicated() {
- String expected = uniquify("ran");
- String someProperty = "cse.cse.servicecomb.delete";
-
- configurationSource.addProperty(someProperty, expected);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- configurationSource.deleteProperty(someProperty);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(null));
-
- expected = uniquify("ran");
- someProperty = "cse.servicecomb.cse.delete";
-
- configurationSource.addProperty(someProperty, expected);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(expected));
-
- configurationSource.deleteProperty(someProperty);
-
- MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
- equalTo(null));
- }
-
- @Test
- public void testConvertEnvVariable() {
- String someProperty = "cse_service_registry_address";
- AbstractConfiguration config = new DynamicConfiguration();
- config.addProperty(someProperty, "testing");
- AbstractConfiguration result = ConfigUtil.convertEnvVariable(config);
- Assertions.assertEquals("testing", result.getString("cse.service.registry.address"));
- }
-
- @Test
- public void testCreateLocalConfigWithExtraConfig() {
- Map<String, Object> extraConfig = new ConcurrentHashMapEx<>(1);
- String extraConfigKey = "extraConfigKey";
- String extraConfigValue = "value";
- String overriddenConfigKey = "servicecomb.cse.servicecomb.file";
- extraConfig.put(extraConfigKey, extraConfigValue);
- final String propertyHigherPriority = "higher_priority";
- String mapedKey1 = "servicecomb.service.mapping.address";
- String mapedKey2 = "servicecomb.service1.mapping.address";
- extraConfig.put(overriddenConfigKey, propertyHigherPriority);
-
- ConfigUtil.addExtraConfig("testExtraConfig", extraConfig);
-
- ConcurrentCompositeConfiguration localConfiguration = ConfigUtil.createLocalConfig();
-
- Assertions.assertEquals(extraConfigValue, localConfiguration.getProperty(extraConfigKey));
- Assertions.assertEquals(propertyHigherPriority, localConfiguration.getString(overriddenConfigKey));
- // Test mapping key/value from self mappfing.xml
- Assertions.assertEquals("https://myhost:8888", localConfiguration.getString(mapedKey1));
- Assertions.assertEquals("https://myhost:8888", localConfiguration.getString(mapedKey2));
- }
-
- @SuppressWarnings("unchecked")
- private static void setEnv(String key, String value) throws IllegalAccessException, NoSuchFieldException {
- Class<?>[] classes = Collections.class.getDeclaredClasses();
- Map<String, String> env = System.getenv();
- for (Class<?> cl : classes) {
- if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Object obj = field.get(env);
- Map<String, String> map = (Map<String, String>) obj;
- map.put(key, value);
- }
- }
- }
-
- @Test
- public void destroyConfigCenterConfigurationSource() {
- AtomicInteger count = new AtomicInteger();
- ConfigCenterConfigurationSource source = new MockUp<ConfigCenterConfigurationSource>() {
- @Mock
- void destroy() {
- count.incrementAndGet();
- }
- }.getMockInstance();
-
- new Expectations(SPIServiceUtils.class) {
- {
- SPIServiceUtils.getAllService(ConfigCenterConfigurationSource.class);
- result = Arrays.asList(source, source);
- }
- };
-
- ConfigUtil.destroyConfigCenterConfigurationSource();
-
- Assertions.assertEquals(2, count.get());
- }
-}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
index 533c7e79b..34fbea2cd 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
@@ -45,7 +45,7 @@ public class TestYAMLConfigurationSource {
PollResult result = configSource.poll(true, null);
Map<String, Object> configMap = result.getComplete();
Assertions.assertNotNull(configMap);
- Assertions.assertEquals(24, configMap.size());
+ Assertions.assertEquals(23, configMap.size());
Assertions.assertNotNull(configMap.get("trace.handler.sampler.percent"));
Assertions.assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));
}
@@ -65,7 +65,7 @@ public class TestYAMLConfigurationSource {
Assertions.assertEquals(3, configSource.getConfigModels().size());
Assertions.assertNotNull(configMap);
- Assertions.assertEquals(35, configMap.size());
+ Assertions.assertEquals(34, configMap.size());
Assertions.assertNotNull(configMap.get("trace.handler.sampler.percent"));
Assertions.assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));
diff --git a/foundations/foundation-config/src/test/resources/microservice.yaml b/foundations/foundation-config/src/test/resources/microservice.yaml
index d820050cf..f8f6825d8 100644
--- a/foundations/foundation-config/src/test/resources/microservice.yaml
+++ b/foundations/foundation-config/src/test/resources/microservice.yaml
@@ -60,12 +60,6 @@ cse:
service_description:
name: testDemo
-
-servicecomb:
- cse:
- servicecomb:
- file: value # this is a config for TestConfigUtil.testCreateLocalConfigWithExtraConfig()
-
holder: b,c,d
test:
commonSeparatedString: a,b,c
diff --git a/huawei-cloud/dashboard/pom.xml b/huawei-cloud/dashboard/pom.xml
index 165ce0042..5d9f67982 100644
--- a/huawei-cloud/dashboard/pom.xml
+++ b/huawei-cloud/dashboard/pom.xml
@@ -31,10 +31,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-common</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-core</artifactId>
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
index 8846a760e..330bd0d09 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.huaweicloud.dashboard.monitor;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,8 +32,6 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.dashboard.client.DashboardAddressManager;
import org.apache.servicecomb.dashboard.client.DashboardClient;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
@@ -45,6 +42,7 @@ import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataProvider;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataPublisher;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
private static final String SSL_KEY = "mc.consumer";
@@ -53,11 +51,18 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
private MonitorConstant monitorConstant;
+ private Environment environment;
+
@Autowired
public void setMonitorConstant(MonitorConstant monitorConstant) {
this.monitorConstant = monitorConstant;
}
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public void init() {
DashboardAddressManager addressManager = createDashboardAddressManager();
@@ -72,13 +77,10 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
dashboardClient = new DashboardClient(addressManager, httpTransport);
}
+ @SuppressWarnings("unchecked")
private DashboardAddressManager createDashboardAddressManager() {
- List<String> addresses = new ArrayList<>();
- SystemBootstrapInfo info = Deployment.getSystemBootStrapInfo(
- MonitorConstant.SYSTEM_KEY_DASHBOARD_SERVICE);
- if (info != null && info.getAccessURL() != null) {
- addresses.addAll(info.getAccessURL());
- }
+ List<String> addresses = ConfigUtil.parseArrayValue(
+ environment.getProperty(MonitorConstant.SYSTEM_KEY_DASHBOARD_SERVICE, ""));
if (addresses.isEmpty()) {
throw new IllegalStateException("dashboard address is not configured.");
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorDefaultDeploymentProvider.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorDefaultDeploymentProvider.java
deleted file mode 100644
index 35a5ff232..000000000
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorDefaultDeploymentProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.huaweicloud.dashboard.monitor;
-
-import java.util.List;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.deployment.DeploymentProvider;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
-import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class MonitorDefaultDeploymentProvider implements DeploymentProvider {
- private static AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
-
- @Override
- public int getOrder() {
- return 3;
- }
-
- @Override
- public SystemBootstrapInfo getSystemBootStrapInfo(String systemKey) {
- if (!systemKey.equals(MonitorConstant.SYSTEM_KEY_DASHBOARD_SERVICE)) {
- return null;
- }
- List<String> msAddresses = ConfigUtil.parseArrayValue(configuration.getString(MonitorConstant.MONITOR_URI));
- if (msAddresses.isEmpty()) {
- return null;
- }
- SystemBootstrapInfo ms = new SystemBootstrapInfo();
- ms.setAccessURL(msAddresses);
- return ms;
- }
-
- @VisibleForTesting
- public static void setConfiguration(AbstractConfiguration configuration) {
- MonitorDefaultDeploymentProvider.configuration = configuration;
- }
-}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorInformationCollector.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorInformationCollector.java
index 30f765d30..ef8b03a13 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorInformationCollector.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorInformationCollector.java
@@ -17,25 +17,29 @@
package org.apache.servicecomb.huaweicloud.dashboard.monitor;
+import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.bootup.BootUpInformationCollector;
-import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
-
-import java.util.Objects;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
public class MonitorInformationCollector implements BootUpInformationCollector {
+ private Environment environment;
+
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public String collect() {
- return "monitor center: " + getCenterInfo(Deployment.getSystemBootStrapInfo(MonitorConstant.SYSTEM_KEY_DASHBOARD_SERVICE));
+ return "monitor center: " +
+ ConfigUtil.parseArrayValue(
+ environment.getProperty(MonitorConstant.SYSTEM_KEY_DASHBOARD_SERVICE, ""));
}
@Override
public int getOrder() {
return 100;
}
-
- private String getCenterInfo(SystemBootstrapInfo systemBootstrapInfo) {
- return Objects.isNull(systemBootstrapInfo) ? "not exist" : systemBootstrapInfo.getAccessURL().toString();
- }
}
diff --git a/huawei-cloud/dashboard/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/huawei-cloud/dashboard/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
deleted file mode 100644
index 38547076b..000000000
--- a/huawei-cloud/dashboard/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-org.apache.servicecomb.huaweicloud.dashboard.monitor.MonitorDefaultDeploymentProvider
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index b5c2f97fb..b9f6d13d1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -139,7 +139,6 @@
<module>parents</module>
<module>common</module>
<module>foundations</module>
- <module>deployment</module>
<module>handlers</module>
<module>providers</module>
<module>transports</module>
diff --git a/service-registry/registry-local/pom.xml b/service-registry/registry-local/pom.xml
index 30b78653b..9118bde3f 100644
--- a/service-registry/registry-local/pom.xml
+++ b/service-registry/registry-local/pom.xml
@@ -29,10 +29,6 @@
<name>Java Chassis::Java Chassis::Service Registry::Local</name>
<dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-vertx</artifactId>
diff --git a/service-registry/registry-service-center/pom.xml b/service-registry/registry-service-center/pom.xml
index 20e38d555..a68676302 100644
--- a/service-registry/registry-service-center/pom.xml
+++ b/service-registry/registry-service-center/pom.xml
@@ -29,10 +29,6 @@
<name>Java Chassis::Service Registry::Service Center</name>
<dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>deployment</artifactId>
- </dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-vertx</artifactId>
[servicecomb-java-chassis] 23/25: [SCB-2008]remove commons-configuration usage
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 4b62723505abc7bf8c738a6f94bd0319a8a8a6c6
Author: liubao <bi...@qq.com>
AuthorDate: Mon Oct 9 15:24:59 2023 +0800
[SCB-2008]remove commons-configuration usage
---
dependencies/default/pom.xml | 8 ---
foundations/foundation-config/pom.xml | 5 +-
.../servicecomb/config/BootStrapProperties.java | 22 --------
.../org/apache/servicecomb/config/ConfigUtil.java | 12 +++-
foundations/foundation-test-scaffolding/pom.xml | 5 --
.../http/TestStandardHttpServletResponseEx.java | 2 +-
.../foundation/vertx/stream/TestPumpFromPart.java | 7 +--
.../dashboard/monitor/TransportUtils.java | 1 -
.../model/InstancePropertiesLoader.java | 1 -
.../lightweight/model/MicroserviceFactory.java | 21 +++----
.../registry/sc/MicroserviceHandler.java | 65 +++++++++++-----------
.../servicecomb/registry/sc/SCRegistration.java | 15 ++++-
12 files changed, 71 insertions(+), 93 deletions(-)
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index a4881cacf..a7b93a5ff 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -32,14 +32,12 @@
<properties>
<!-- Dependency versions: sort by alphabetic order -->
<activation.version>1.2.2</activation.version>
- <archaius.version>0.7.7</archaius.version>
<asciidoctorj.version>2.5.3</asciidoctorj.version>
<aspectj.version>1.9.19</aspectj.version>
<assertj.version>3.24.2</assertj.version>
<awaitility.version>4.2.0</awaitility.version>
<brave.version>5.16.0</brave.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
- <commons-configuration.version>1.10</commons-configuration.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-lang.version>2.6</commons-lang.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
@@ -298,12 +296,6 @@
<version>${commons-beanutils.version}</version>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- <version>${commons-configuration.version}</version>
- </dependency>
-
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git a/foundations/foundation-config/pom.xml b/foundations/foundation-config/pom.xml
index f79b84d72..465bda360 100644
--- a/foundations/foundation-config/pom.xml
+++ b/foundations/foundation-config/pom.xml
@@ -43,10 +43,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- </dependency>
+
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
index 6e9d9abcd..1023bdb38 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
@@ -18,11 +18,9 @@
package org.apache.servicecomb.config;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
@@ -50,15 +48,11 @@ public class BootStrapProperties {
public static final String OLD_CONFIG_SERVICE_PROPERTIES = "service_description.properties";
- public static final String OLD_CONFIG_SERVICE_PATHS = "service_description.paths";
-
// service instance definition keys of old version
public static final String OLD_CONFIG_SERVICE_INSTANCE_PROPERTIES = "instance_description.properties";
public static final String OLD_CONFIG_SERVICE_INSTANCE_EXTENDED_CLASS = "instance_description.propertyExtendedClass";
- public static final String OLD_CONFIG_SERVICE_INSTANCE_ENVIRONMENT = "instance_description.environment";
-
public static final String OLD_CONFIG_SERVICE_INSTANCE_INITIAL_STATUS = "instance_description.initialStatus";
// service definition keys of new version
@@ -78,17 +72,11 @@ public class BootStrapProperties {
public static final String CONFIG_SERVICE_PROPERTIES = "servicecomb.service.properties";
- public static final String CONFIG_SERVICE_PATHS = "servicecomb.service.paths";
-
- public static final String CONFIG_SERVICE_ALIAS = "servicecomb.service.alias";
-
// service instance definition keys of new version
public static final String CONFIG_SERVICE_INSTANCE_PROPERTIES = "servicecomb.instance.properties";
public static final String CONFIG_SERVICE_INSTANCE_EXTENDED_CLASS = "servicecomb.instance.propertyExtendedClass";
- public static final String CONFIG_SERVICE_INSTANCE_ENVIRONMENT = "servicecomb.instance.environment";
-
public static final String CONFIG_SERVICE_INSTANCE_INITIAL_STATUS = "servicecomb.instance.initialStatus";
// configuration default values
@@ -102,8 +90,6 @@ public class BootStrapProperties {
public static final String DEFAULT_MICROSERVICE_ENVIRONMENT = "";
- public static final String DEFAULT_MICROSERVICE_INSTANCE_ENVIRONMENT = "production";
-
public static final String DEFAULT_MICROSERVICE_INSTANCE_INITIAL_STATUS = "UP";
public static String readApplication(Environment environment) {
@@ -159,14 +145,6 @@ public class BootStrapProperties {
return readProperties(environment, CONFIG_SERVICE_PROPERTIES, OLD_CONFIG_SERVICE_PROPERTIES);
}
- public static List<Object> readServicePaths(Configuration configuration) {
- List<Object> result = configuration.getList(CONFIG_SERVICE_PATHS);
- if (result == null || result.isEmpty()) {
- result = configuration.getList(OLD_CONFIG_SERVICE_PATHS);
- }
- return result;
- }
-
public static Map<String, String> readServiceInstanceProperties(Environment environment) {
return readProperties(environment, CONFIG_SERVICE_INSTANCE_PROPERTIES, OLD_CONFIG_SERVICE_INSTANCE_PROPERTIES);
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index 73dc2348a..a09b2eaac 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -17,13 +17,13 @@
package org.apache.servicecomb.config;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.configuration.PropertyConverter;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
@@ -34,7 +34,15 @@ public final class ConfigUtil {
}
public static List<String> parseArrayValue(String value) {
- return PropertyConverter.split(value, ',', true);
+ if (value == null) {
+ return new ArrayList<>(0);
+ }
+ String[] tokens = value.split(",");
+ List<String> result = new ArrayList<>(tokens.length);
+ for (String t : tokens) {
+ result.add(t.trim());
+ }
+ return result;
}
public static Set<String> propertiesWithPrefix(Environment environment, String prefix) {
diff --git a/foundations/foundation-test-scaffolding/pom.xml b/foundations/foundation-test-scaffolding/pom.xml
index 201d814b0..a149ef9de 100644
--- a/foundations/foundation-test-scaffolding/pom.xml
+++ b/foundations/foundation-test-scaffolding/pom.xml
@@ -31,11 +31,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- <scope>compile</scope>
- </dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
index dbfd816a2..c672fb288 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
@@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
import org.apache.servicecomb.foundation.common.part.InputStreamPart;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.junit.Before;
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
index 67415e00d..dafa8e7f0 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
@@ -22,23 +22,22 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.ExecutionException;
-import jakarta.servlet.http.Part;
-
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
import org.apache.servicecomb.foundation.common.part.InputStreamPart;
import org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream.ReadResult;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
import io.vertx.core.Context;
import io.vertx.core.Promise;
import io.vertx.core.impl.SyncContext;
+import jakarta.servlet.http.Part;
import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
-import org.junit.jupiter.api.Assertions;
public class TestPumpFromPart {
String src = RandomStringUtils.random(100, true, true);
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
index ed2aaec26..f508038f9 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.huaweicloud.dashboard.monitor;
import static org.apache.servicecomb.foundation.ssl.SSLOption.DEFAULT_OPTION;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.foundation.ssl.SSLCustom;
import org.apache.servicecomb.foundation.ssl.SSLOption;
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
index 33bfff41c..a4dd1d30d 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.registry.lightweight.model;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.BootStrapProperties;
import org.springframework.core.env.Environment;
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
index b4612b2ac..fed3b9a28 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
@@ -23,8 +23,6 @@ import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.foundation.common.Version;
@@ -40,23 +38,22 @@ public class MicroserviceFactory {
private Microservice createMicroserviceFromConfiguration(Environment environment) {
Microservice microservice = new Microservice();
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
- microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
+ if (!StringUtils.isEmpty(environment.getProperty(APP_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(APP_MAPPING)))) {
+ microservice.setAppId(environment.getProperty(environment.getProperty(APP_MAPPING)));
} else {
microservice.setAppId(BootStrapProperties.readApplication(environment));
}
- if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
- microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
+ if (!StringUtils.isEmpty(environment.getProperty(SERVICE_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(SERVICE_MAPPING)))) {
+ microservice.setServiceName(environment.getProperty(environment.getProperty(SERVICE_MAPPING)));
} else {
microservice.setServiceName(BootStrapProperties.readServiceName(environment));
}
String version;
- if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
- version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
+ if (!StringUtils.isEmpty(environment.getProperty(VERSION_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(VERSION_MAPPING)))) {
+ version = environment.getProperty(environment.getProperty(VERSION_MAPPING));
} else {
version = BootStrapProperties.readServiceVersion(environment);
}
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
index ec495c710..92abac9c9 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
@@ -22,8 +22,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.DataCenterProperties;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.foundation.common.net.NetUtils;
@@ -35,6 +35,7 @@ import org.apache.servicecomb.service.center.client.model.Microservice;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstance;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstanceStatus;
import org.apache.servicecomb.service.center.client.model.MicroserviceStatus;
+import org.springframework.core.env.Environment;
public class MicroserviceHandler {
private static final String SERVICE_MAPPING = "SERVICE_MAPPING";
@@ -57,26 +58,27 @@ public class MicroserviceHandler {
private static final String INSTANCE_PROPS = "SERVICECOMB_INSTANCE_PROPS";
- public static Microservice createMicroservice(SCConfigurationProperties bootstrapProperties,
+ public static Microservice createMicroservice(
+ Environment environment,
+ SCConfigurationProperties bootstrapProperties,
MicroserviceProperties microserviceProperties) {
Microservice microservice = new Microservice();
microservice.setProperties(microserviceProperties.getProperties());
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
- microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
+ if (!StringUtils.isEmpty(environment.getProperty(APP_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(APP_MAPPING)))) {
+ microservice.setAppId(environment.getProperty(environment.getProperty(APP_MAPPING)));
} else {
microservice.setAppId(microserviceProperties.getApplication());
}
- if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
- microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
+ if (!StringUtils.isEmpty(environment.getProperty(SERVICE_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(SERVICE_MAPPING)))) {
+ microservice.setServiceName(environment.getProperty(environment.getProperty(SERVICE_MAPPING)));
} else {
microservice.setServiceName(microserviceProperties.getName());
}
- if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
- microservice.setVersion(envConfig.getString(envConfig.getString(VERSION_MAPPING)));
+ if (!StringUtils.isEmpty(environment.getProperty(VERSION_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(VERSION_MAPPING)))) {
+ microservice.setVersion(environment.getProperty(environment.getProperty(VERSION_MAPPING)));
} else {
microservice.setVersion(microserviceProperties.getVersion());
}
@@ -84,7 +86,8 @@ public class MicroserviceHandler {
Framework framework = createFramework();
microservice.setFramework(framework);
- String[] servicePropArray = envConfig.getStringArray(SERVICE_PROPS);
+ String[] servicePropArray = ConfigUtil.parseArrayValue(environment.getProperty(SERVICE_PROPS))
+ .toArray(new String[0]);
if (servicePropArray.length != 0) {
microservice.getProperties().putAll(parseProps(servicePropArray));
}
@@ -101,6 +104,7 @@ public class MicroserviceHandler {
}
public static MicroserviceInstance createMicroserviceInstance(
+ Environment environment,
SCConfigurationProperties scConfigurationProperties,
MicroserviceProperties microserviceProperties,
DataCenterProperties dataCenterProperties) {
@@ -130,42 +134,41 @@ public class MicroserviceHandler {
microserviceInstance.setModTimestamp(currTime);
// what's MicroserviceInstance doing? same sa Microservice?
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
- !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
- microserviceInstance.setVersion(envConfig.getString(VERSION_MAPPING));
+ if (!StringUtils.isEmpty(environment.getProperty(VERSION_MAPPING)) &&
+ !StringUtils.isEmpty(environment.getProperty(environment.getProperty(VERSION_MAPPING)))) {
+ microserviceInstance.setVersion(environment.getProperty(environment.getProperty(VERSION_MAPPING)));
} else {
microserviceInstance.setVersion(microserviceProperties.getVersion());
}
Map<String, String> properties = new HashMap<>();
properties.putAll(microserviceProperties.getProperties());
- properties.putAll(genCasProperties());
+ properties.putAll(genCasProperties(environment));
microserviceInstance.setProperties(properties);
microserviceInstance.setStatus(MicroserviceInstanceStatus.valueOf(scConfigurationProperties.getInitialStatus()));
return microserviceInstance;
}
- private static Map<String, String> genCasProperties() {
+ private static Map<String, String> genCasProperties(Environment environment) {
Map<String, String> properties = new HashMap<>();
- EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
- if (!StringUtils.isEmpty(envConfig.getString(CAS_APPLICATION_ID))) {
- properties.put(CAS_APPLICATION_ID, envConfig.getString(CAS_APPLICATION_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_APPLICATION_ID))) {
+ properties.put(CAS_APPLICATION_ID, environment.getProperty(CAS_APPLICATION_ID));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_COMPONENT_NAME))) {
- properties.put(CAS_COMPONENT_NAME, envConfig.getString(CAS_COMPONENT_NAME));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_COMPONENT_NAME))) {
+ properties.put(CAS_COMPONENT_NAME, environment.getProperty(CAS_COMPONENT_NAME));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_INSTANCE_VERSION))) {
- properties.put(CAS_INSTANCE_VERSION, envConfig.getString(CAS_INSTANCE_VERSION));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_INSTANCE_VERSION))) {
+ properties.put(CAS_INSTANCE_VERSION, environment.getProperty(CAS_INSTANCE_VERSION));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_INSTANCE_ID))) {
- properties.put(CAS_INSTANCE_ID, envConfig.getString(CAS_INSTANCE_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_INSTANCE_ID))) {
+ properties.put(CAS_INSTANCE_ID, environment.getProperty(CAS_INSTANCE_ID));
}
- if (!StringUtils.isEmpty(envConfig.getString(CAS_ENVIRONMENT_ID))) {
- properties.put(CAS_ENVIRONMENT_ID, envConfig.getString(CAS_ENVIRONMENT_ID));
+ if (!StringUtils.isEmpty(environment.getProperty(CAS_ENVIRONMENT_ID))) {
+ properties.put(CAS_ENVIRONMENT_ID, environment.getProperty(CAS_ENVIRONMENT_ID));
}
- String[] instancePropArray = envConfig.getStringArray(INSTANCE_PROPS);
+ String[] instancePropArray = ConfigUtil.parseArrayValue(environment.getProperty(INSTANCE_PROPS))
+ .toArray(new String[0]);
if (instancePropArray.length != 0) {
properties.putAll(parseProps(instancePropArray));
}
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/SCRegistration.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/SCRegistration.java
index b21400a84..fda0273ca 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/SCRegistration.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/SCRegistration.java
@@ -33,6 +33,7 @@ import org.apache.servicecomb.service.center.client.model.MicroserviceInstance;
import org.apache.servicecomb.service.center.client.model.SchemaInfo;
import org.apache.servicecomb.service.center.client.model.ServiceCenterConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.google.common.base.Charsets;
import com.google.common.eventbus.EventBus;
@@ -60,6 +61,8 @@ public class SCRegistration implements Registration<SCRegistrationInstance> {
private DataCenterProperties dataCenterProperties;
+ private Environment environment;
+
private CountDownLatch readyWaiter = new CountDownLatch(1);
@Autowired
@@ -80,11 +83,19 @@ public class SCRegistration implements Registration<SCRegistrationInstance> {
this.dataCenterProperties = dataCenterProperties;
}
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public void init() {
- microservice = MicroserviceHandler.createMicroservice(configurationProperties, microserviceProperties);
- microserviceInstance = MicroserviceHandler.createMicroserviceInstance(configurationProperties,
+ microservice = MicroserviceHandler.createMicroservice(
+ environment, configurationProperties, microserviceProperties);
+ microserviceInstance = MicroserviceHandler.createMicroserviceInstance(
+ environment,
+ configurationProperties,
microserviceProperties,
dataCenterProperties);
serviceCenterRegistration = new ServiceCenterRegistration(serviceCenterClient,
[servicecomb-java-chassis] 02/25: [SCB-2008]change DynamicPropertyFactory to Environment: in common rest
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 5f660e28c3ebee1d183624211b43093c8bfe92ae
Author: liubao <bi...@qq.com>
AuthorDate: Thu Sep 21 15:07:51 2023 +0800
[SCB-2008]change DynamicPropertyFactory to Environment: in common rest
---
.../common/rest/RestProducerInvocationCreator.java | 11 +++++------
.../common/rest/codec/param/BodyProcessorCreator.java | 6 +++---
.../rest/codec/param/HeaderProcessorCreator.java | 6 +++---
.../rest/codec/param/QueryProcessorCreator.java | 14 +++++++-------
.../servicecomb/common/rest/codec/TestRestCodec.java | 14 ++++++++++++++
.../rest/codec/param/TestHeaderProcessorCreator.java | 13 +++++++++++++
.../common/rest/codec/param/TestQueryProcessor.java | 16 ++++++++++++++++
.../rest/codec/param/TestQueryProcessorCreator.java | 19 ++++++++++++++++++-
.../common/rest/codec/query/QueryCodecCsvTest.java | 17 +++++++++++++++++
.../common/rest/codec/query/QueryCodecPipesTest.java | 17 +++++++++++++++++
.../common/rest/codec/query/QueryCodecSsvTest.java | 19 ++++++++++++++++++-
.../servicecomb/common/rest/definition/TestPath.java | 15 +++++++++++++++
.../rest/definition/path/QueryVarParamWriterTest.java | 13 +++++++++++++
.../rest/definition/path/URLPathBuilderTest.java | 17 +++++++++++++++++
.../common/rest/locator/TestServicePathManager.java | 11 +++++++++++
.../foundation/common/LegacyPropertyFactory.java | 3 ++-
16 files changed, 189 insertions(+), 22 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
index 548b5dc0f..df5eebc83 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
@@ -38,13 +38,12 @@ import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.core.invocation.InvocationCreator;
import org.apache.servicecomb.core.invocation.InvocationFactory;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.netflix.config.DynamicPropertyFactory;
-
import io.vertx.core.json.Json;
public abstract class RestProducerInvocationCreator implements InvocationCreator {
@@ -100,10 +99,10 @@ public abstract class RestProducerInvocationCreator implements InvocationCreator
}
protected void addParameterContext(Invocation invocation) {
- String headerContextMapper = DynamicPropertyFactory.getInstance()
- .getStringProperty(RestConst.HEADER_CONTEXT_MAPPER, null).get();
- String queryContextMapper = DynamicPropertyFactory.getInstance()
- .getStringProperty(RestConst.QUERY_CONTEXT_MAPPER, null).get();
+ String headerContextMapper = LegacyPropertyFactory
+ .getStringProperty(RestConst.HEADER_CONTEXT_MAPPER);
+ String queryContextMapper = LegacyPropertyFactory
+ .getStringProperty(RestConst.QUERY_CONTEXT_MAPPER);
Map<String, Object> headerContextMappers;
if (headerContextMapper != null) {
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
index dcb8aaf97..c59815a94 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
@@ -35,6 +35,7 @@ import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.protobuf.ProtoMapper;
import org.apache.servicecomb.foundation.protobuf.RootDeserializer;
import org.apache.servicecomb.foundation.protobuf.RootSerializer;
@@ -51,7 +52,6 @@ import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.netflix.config.DynamicPropertyFactory;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -75,8 +75,8 @@ public class BodyProcessorCreator implements ParamValueProcessorCreator<RequestB
private static final JavaType OBJECT_TYPE = SimpleType.constructUnsafe(Object.class);
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
- private static final boolean decodeAsObject = DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.rest.parameter.decodeAsObject", false).get();
+ private static final boolean decodeAsObject = LegacyPropertyFactory
+ .getBooleanProperty("servicecomb.rest.parameter.decodeAsObject", false);
private static final Object LOCK = new Object();
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/HeaderProcessorCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/HeaderProcessorCreator.java
index ab03afd49..a3b72403b 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/HeaderProcessorCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/HeaderProcessorCreator.java
@@ -24,13 +24,13 @@ import java.util.Enumeration;
import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.netflix.config.DynamicPropertyFactory;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
@@ -45,8 +45,8 @@ public class HeaderProcessorCreator implements ParamValueProcessorCreator<Parame
public static class HeaderProcessor extends AbstractParamProcessor {
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
- private final boolean ignoreRequiredCheck = DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck", false).get();
+ private final boolean ignoreRequiredCheck = LegacyPropertyFactory
+ .getBooleanProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck", false);
private final boolean repeatedType;
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/QueryProcessorCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/QueryProcessorCreator.java
index 1462e413a..8fef05686 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/QueryProcessorCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/QueryProcessorCreator.java
@@ -25,11 +25,11 @@ import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.query.QueryCodec;
import org.apache.servicecomb.common.rest.codec.query.QueryCodecsUtils;
import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.netflix.config.DynamicPropertyFactory;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.parameters.Parameter;
@@ -43,16 +43,16 @@ public class QueryProcessorCreator implements ParamValueProcessorCreator<Paramet
public static class QueryProcessor extends AbstractParamProcessor {
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
- private final boolean emptyAsNull = DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.rest.parameter.query.emptyAsNull", false).get();
+ private final boolean emptyAsNull = LegacyPropertyFactory
+ .getBooleanProperty("servicecomb.rest.parameter.query.emptyAsNull", false);
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
- private final boolean ignoreDefaultValue = DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", false).get();
+ private final boolean ignoreDefaultValue = LegacyPropertyFactory
+ .getBooleanProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", false);
// This configuration is used for temporary use only. Do not use it if you are sure how it works. And may be deleted in future.
- private final boolean ignoreRequiredCheck = DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", false).get();
+ private final boolean ignoreRequiredCheck = LegacyPropertyFactory
+ .getBooleanProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", false);
private final boolean repeatedType;
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
index ebbe2975a..dafb99949 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
@@ -27,6 +27,7 @@ import org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.jupiter.api.AfterAll;
@@ -34,6 +35,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
@@ -55,8 +57,20 @@ public class TestRestCodec {
private static List<RestParam> paramList = null;
+ static Environment environment = Mockito.mock(Environment.class);
+
@BeforeAll
public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+
Parameter hp = new HeaderParameter();
hp.setName("header");
hp.setSchema(new Schema());
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessorCreator.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessorCreator.java
index 2ea7c3823..d275b16b6 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessorCreator.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessorCreator.java
@@ -18,13 +18,26 @@
package org.apache.servicecomb.common.rest.codec.param;
import org.apache.servicecomb.common.rest.codec.param.HeaderProcessorCreator.HeaderProcessor;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
public class TestHeaderProcessorCreator {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
@Test
public void testCreate() {
ParamValueProcessorCreator creator =
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
index 73c547b03..be18fb837 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
@@ -18,11 +18,14 @@
package org.apache.servicecomb.common.rest.codec.param;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -35,6 +38,19 @@ import io.swagger.v3.oas.models.parameters.QueryParameter;
import jakarta.servlet.http.HttpServletRequest;
public class TestQueryProcessor {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
private ParamValueProcessor createProcessor(String name, Class<?> type,
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
index 6f59823b0..d1f98da4e 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessorCreator.java
@@ -18,10 +18,13 @@
package org.apache.servicecomb.common.rest.codec.param;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -31,6 +34,19 @@ import io.swagger.v3.oas.models.parameters.QueryParameter;
import jakarta.servlet.http.HttpServletRequest;
public class TestQueryProcessorCreator {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
@Test
public void testCreate() {
ParamValueProcessorCreator creator =
@@ -56,7 +72,8 @@ public class TestQueryProcessorCreator {
@Test
public void testCreateNullAsEmpty() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- ArchaiusUtils.setProperty("servicecomb.rest.parameter.query.emptyAsNull", "true");
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(true);
ParamValueProcessorCreator creator =
ParamValueProcessorCreatorManager.INSTANCE.findValue(QueryProcessorCreator.PARAMTYPE);
Parameter parameter = new QueryParameter();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecCsvTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecCsvTest.java
index 3d34e1097..890075cbe 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecCsvTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecCsvTest.java
@@ -19,11 +19,28 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Date;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
class QueryCodecCsvTest extends QueryCodecTestBase {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
@BeforeEach
void setUp() {
codec = new QueryCodecCsv();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecPipesTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecPipesTest.java
index 3b7f33459..83f2b8006 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecPipesTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecPipesTest.java
@@ -19,11 +19,28 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Date;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
class QueryCodecPipesTest extends QueryCodecTestBase {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
@BeforeEach
void setUp() {
codec = new QueryCodecPipes();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecSsvTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecSsvTest.java
index c719eae08..c6e521f67 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecSsvTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecSsvTest.java
@@ -19,11 +19,28 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Date;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
+
+public class QueryCodecSsvTest extends QueryCodecTestBase {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
-class QueryCodecSsvTest extends QueryCodecTestBase {
@BeforeEach
void setUp() {
codec = new QueryCodecSsv();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
index 51a4cf26e..db0b09f83 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
@@ -25,11 +25,14 @@ import org.apache.servicecomb.common.rest.definition.path.PathRegExp;
import org.apache.servicecomb.common.rest.definition.path.QueryVarParamWriter;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
@@ -37,6 +40,18 @@ import io.swagger.v3.oas.models.parameters.PathParameter;
import io.swagger.v3.oas.models.parameters.QueryParameter;
public class TestPath {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
@BeforeEach
public void setUp() {
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
index 55c69bf60..1aafc89fb 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
@@ -26,9 +26,12 @@ import java.util.Map;
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter.StyleEnum;
@@ -41,8 +44,18 @@ public class QueryVarParamWriterTest {
private static QueryVarParamWriter queryVarParamWriterDefault;
+ static Environment environment = Mockito.mock(Environment.class);
+
@BeforeAll
public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+
QueryParameter parameter = new QueryParameter();
parameter.setName("q");
parameter.setSchema(new Schema());
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
index 43f2b1396..bcff2ff15 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
@@ -23,8 +23,12 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.servicecomb.common.rest.definition.RestParam;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
@@ -32,6 +36,19 @@ import io.swagger.v3.oas.models.parameters.PathParameter;
import io.swagger.v3.oas.models.parameters.QueryParameter;
public class URLPathBuilderTest {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
+ }
+
@Test
public void testNormal() throws Exception {
Map<String, RestParam> paramMap = new LinkedHashMap<>();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
index 902ea583d..85476f627 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
@@ -30,17 +30,28 @@ import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
public class TestServicePathManager {
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void beforeClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
+ }
+
SCBEngine scbEngine;
@BeforeEach
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
index 6bda26c06..52f8372ba 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
@@ -23,7 +23,8 @@ import com.google.common.annotations.VisibleForTesting;
/**
* Provider a convenient way to get property value in static context.
*
- * NOTE: this way is not commented and only for legacy code without too much refactoring.
+ * NOTE: This way is not commented and only for legacy code without too much refactoring.
+ * And make sure to use this class when spring bean context is already initialized.
*/
public class LegacyPropertyFactory {
private static Environment environment;
[servicecomb-java-chassis] 24/25: [SCB-2008]fix test case error
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit cb657eb661306f42d02345accc43473a4301e328
Author: liubao <bi...@qq.com>
AuthorDate: Mon Oct 9 17:40:22 2023 +0800
[SCB-2008]fix test case error
---
.../springboot/springmvc/server/SpringmvcServer.java | 11 +++++++----
.../apache/servicecomb/config/apollo/ApolloClientTest.java | 1 -
.../servicecomb/edge/core/CommonHttpEdgeDispatcher.java | 10 ++++++----
.../servicecomb/edge/core/DefaultEdgeDispatcher.java | 4 +++-
.../servicecomb/edge/core/URLMappedEdgeDispatcher.java | 3 ++-
.../apache/servicecomb/config/DynamicPropertiesImpl.java | 2 +-
.../config/file/TestMicroserviceConfigLoader.java | 2 --
.../servicecomb/provider/rest/common/RestProducers.java | 14 +++++++++++---
8 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
index 6f938e0d5..ea39accb4 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java
@@ -39,10 +39,13 @@ public class SpringmvcServer {
}
private static void assertPropertyCorrect() {
- String result = LegacyPropertyFactory.getStringProperty("test.unresolved.placeholder");
- if (!"jdbc:postgresql://${ip}:${port}/pt".equals(result)) {
- LOGGER.error("tests for configuration error, stop");
- SCBEngine.getInstance().destroy();
+ // spring environment will fail for unresolved placeholder property
+ try {
+ LegacyPropertyFactory.getStringProperty("test.unresolved.placeholder");
+ } catch (IllegalArgumentException e) {
+ return;
}
+ LOGGER.error("tests for configuration error, stop");
+ SCBEngine.getInstance().destroy();
}
}
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
index 77a074e4f..65bc6632c 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
@@ -20,7 +20,6 @@ package org.apache.servicecomb.config.apollo;
import java.util.HashMap;
import java.util.Map;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.apollo.ApolloClient.ConfigRefresh;
import org.apache.servicecomb.config.apollo.ApolloDynamicPropertiesSource.UpdateHandler;
import org.junit.jupiter.api.Assertions;
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
index 5c3edc183..baed88dd4 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
@@ -79,15 +80,16 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
private Environment environment;
public CommonHttpEdgeDispatcher() {
- if (this.enabled()) {
- loadConfigurations();
- }
+
}
// though this is an SPI, but add as beans.
@Autowired
public void setEnvironment(Environment environment) {
this.environment = environment;
+ if (this.enabled()) {
+ loadConfigurations();
+ }
}
// Maybe future change to beans
@@ -107,7 +109,7 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
@Override
public int getOrder() {
- return environment.getProperty(KEY_ORDER, int.class, 40_000);
+ return LegacyPropertyFactory.getIntProperty(KEY_ORDER, 40_000);
}
@Override
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
index 9b1333ce9..08c33b2a8 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.edge.core;
import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
import org.apache.servicecomb.core.invocation.InvocationCreator;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
@@ -59,7 +60,8 @@ public class DefaultEdgeDispatcher extends AbstractEdgeDispatcher {
@Override
public int getOrder() {
- return environment.getProperty(KEY_ORDER, int.class, 20_000);
+ // can not use environment, add as beans is later than instantiate SPI
+ return LegacyPropertyFactory.getIntProperty(KEY_ORDER, 20_000);
}
@Override
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
index 0f2920e8e..195513714 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.core.invocation.InvocationCreator;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
@@ -81,7 +82,7 @@ public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
@Override
public int getOrder() {
- return environment.getProperty(KEY_ORDER, int.class, 30_000);
+ return LegacyPropertyFactory.getIntProperty(KEY_ORDER, 30_000);
}
@Override
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
index 6ce2ea2d1..63cf7679d 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
@@ -128,7 +128,7 @@ public class DynamicPropertiesImpl implements DynamicProperties {
}
if (booleanCallbacks.containsKey(entry.getKey())) {
for (Consumer<Boolean> callbacks : booleanCallbacks.get(entry.getKey())) {
- callbacks.accept((boolean) entry.getValue());
+ callbacks.accept((Boolean) entry.getValue());
}
}
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
index ff6b81260..0084976d0 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
@@ -25,8 +25,6 @@ import java.net.URL;
import java.util.List;
import java.util.stream.Collectors;
-import org.apache.servicecomb.config.file.ConfigModel;
-import org.apache.servicecomb.config.file.MicroserviceConfigLoader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
index 7a0df73c7..8aed65f3b 100644
--- a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
+++ b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
@@ -22,13 +22,14 @@ import java.util.List;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.core.provider.producer.ProducerMeta;
-import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
-public class RestProducers implements BeanPostProcessor {
+public class RestProducers implements BeanPostProcessor, EnvironmentAware {
private final List<ProducerMeta> producerMetaList = new ArrayList<>();
@SuppressWarnings("unchecked")
@@ -39,6 +40,8 @@ public class RestProducers implements BeanPostProcessor {
return producerMetaList;
}
+ private Environment environment;
+
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
@@ -67,10 +70,15 @@ public class RestProducers implements BeanPostProcessor {
}
if (restControllerCls != null &&
- LegacyPropertyFactory.getBooleanProperty(RestConst.PROVIDER_SCAN_REST_CONTROLLER, true)
+ environment.getProperty(RestConst.PROVIDER_SCAN_REST_CONTROLLER, boolean.class, true)
&& beanCls.getAnnotation(restControllerCls) != null) {
ProducerMeta producerMeta = new ProducerMeta(beanCls.getName(), bean);
producerMetaList.add(producerMeta);
}
}
+
+ @Override
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
}
[servicecomb-java-chassis] 20/25: [SCB-2008]remove archaius adapters
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit f4ac0ec8b9cac13db6c55f2df3e6d214883f78b5
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 19:20:30 2023 +0800
[SCB-2008]remove archaius adapters
---
.../core/ConfigurationSpringInitializer.java | 2 +-
.../ServiceCombConfigurationEventAdapter.java | 21 +----
.../config/ConcurrentMapConfigurationExt.java | 53 ------------
.../apache/servicecomb/config/ConfigMapping.java | 12 +--
.../scheduler/NeverStartPollingScheduler.java | 35 --------
.../config/archaius/sources/ConfigSourceMaker.java | 28 -------
.../sources/MicroserviceConfigurationSource.java | 49 -----------
.../event/DynamicConfigurationChangedEvent.java | 32 -------
.../event/RefreshGovernanceConfigurationEvent.java | 32 -------
.../sources => file}/AbstractConfigLoader.java | 2 +-
.../{archaius/sources => file}/ConfigModel.java | 2 +-
.../sources => file}/MicroserviceConfigLoader.java | 2 +-
.../sources => file}/YAMLConfigLoader.java | 2 +-
.../sources/TestYAMLConfigurationSource.java | 98 ----------------------
.../TestMicroserviceConfigLoader.java | 4 +-
15 files changed, 12 insertions(+), 362 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
index dc602b47d..6465457bd 100644
--- a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
+++ b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
@@ -27,7 +27,7 @@ import java.util.stream.Collectors;
import org.apache.servicecomb.config.ConfigMapping;
import org.apache.servicecomb.config.DynamicPropertiesSource;
import org.apache.servicecomb.config.YAMLUtil;
-import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
+import org.apache.servicecomb.config.file.MicroserviceConfigLoader;
import org.apache.servicecomb.foundation.bootstrap.BootStrapService;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.slf4j.Logger;
diff --git a/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombConfigurationEventAdapter.java b/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombConfigurationEventAdapter.java
index bb15d232f..e5ee61cd5 100644
--- a/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombConfigurationEventAdapter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombConfigurationEventAdapter.java
@@ -18,11 +18,7 @@
package org.apache.servicecomb.core.governance;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.servicecomb.config.event.RefreshGovernanceConfigurationEvent;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent;
import org.apache.servicecomb.governance.event.GovernanceEventManager;
@@ -35,19 +31,8 @@ public class ServiceCombConfigurationEventAdapter {
}
@Subscribe
- public void onConfigurationChangedEvent(RefreshGovernanceConfigurationEvent event) {
- Set<String> changedKeys = new HashSet<>();
- addMap(changedKeys, event.getEvent().getAdded());
- addMap(changedKeys, event.getEvent().getDeleted());
- addMap(changedKeys, event.getEvent().getChanged());
- addMap(changedKeys, event.getEvent().getComplete());
- GovernanceConfigurationChangedEvent newEvent = new GovernanceConfigurationChangedEvent(changedKeys);
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ GovernanceConfigurationChangedEvent newEvent = new GovernanceConfigurationChangedEvent(event.getChanged());
GovernanceEventManager.post(newEvent);
}
-
- private void addMap(Set<String> keys, Map<String, Object> changed) {
- if (changed != null) {
- keys.addAll(changed.keySet());
- }
- }
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConcurrentMapConfigurationExt.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConcurrentMapConfigurationExt.java
deleted file mode 100644
index 814409228..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConcurrentMapConfigurationExt.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-
-import com.netflix.config.ConcurrentMapConfiguration;
-
-/**
- * Disable delimiter parsing for string
- */
-@SuppressWarnings("unchecked")
-public class ConcurrentMapConfigurationExt extends ConcurrentMapConfiguration {
- public ConcurrentMapConfigurationExt() {
- super();
- setDelimiterParsingDisabled(true);
- }
-
- public ConcurrentMapConfigurationExt(Map<String, Object> mapToCopy) {
- super();
- setDelimiterParsingDisabled(true);
- map = new ConcurrentHashMap<>(mapToCopy);
- }
-
- public ConcurrentMapConfigurationExt(AbstractConfiguration config) {
- super();
- config.setDelimiterParsingDisabled(true);
- for (Iterator<String> i = config.getKeys(); i.hasNext(); ) {
- String name = i.next();
- Object value = config.getProperty(name);
- map.put(name, value);
- }
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigMapping.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigMapping.java
index 3063c8cdd..d80caaa51 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigMapping.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigMapping.java
@@ -27,8 +27,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.config.archaius.sources.AbstractConfigLoader;
+import org.apache.servicecomb.config.file.AbstractConfigLoader;
import org.apache.servicecomb.foundation.common.utils.JvmUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,15 +94,6 @@ public final class ConfigMapping {
return retMap;
}
- public static Map<String, Object> getConvertedMap(Configuration config) {
- if (configMap == null) {
- return new LinkedHashMap<>();
- }
- Map<String, Object> retMap = new LinkedHashMap<>();
- configMap.entrySet().forEach(entry -> putConfigsToRetMap(retMap, entry, config.getProperty(entry.getKey())));
- return retMap;
- }
-
public static Map<String, Object> getConvertedMap(Environment environment) {
if (configMap == null) {
return new LinkedHashMap<>();
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/scheduler/NeverStartPollingScheduler.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/scheduler/NeverStartPollingScheduler.java
deleted file mode 100644
index fb52d0663..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/scheduler/NeverStartPollingScheduler.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.scheduler;
-
-import com.netflix.config.AbstractPollingScheduler;
-
-/**
- * Created by on 2017/3/29.
- */
-public class NeverStartPollingScheduler extends AbstractPollingScheduler {
- @Override
- protected void schedule(Runnable runnable) {
- return;
- }
-
- @Override
- public void stop() {
- return;
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigSourceMaker.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigSourceMaker.java
deleted file mode 100644
index f822e30d9..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigSourceMaker.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.sources;
-
-public class ConfigSourceMaker {
-
- public static MicroserviceConfigurationSource yamlConfigSource() {
- MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
- loader.loadAndSort();
-
- return new MicroserviceConfigurationSource(loader.getConfigModels());
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigurationSource.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigurationSource.java
deleted file mode 100644
index e39c987a7..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigurationSource.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.sources;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.servicecomb.config.YAMLUtil;
-
-import com.netflix.config.PollResult;
-import com.netflix.config.PolledConfigurationSource;
-
-public class MicroserviceConfigurationSource implements PolledConfigurationSource {
- private final List<ConfigModel> configModels;
-
- public MicroserviceConfigurationSource(List<ConfigModel> configModels) {
- this.configModels = configModels;
- }
-
- public List<ConfigModel> getConfigModels() {
- return configModels;
- }
-
- public PollResult poll(boolean b, Object o) throws Exception {
- Map<String, Object> configurations = new LinkedHashMap<>();
-
- for (ConfigModel configModel : configModels) {
- configurations.putAll(YAMLUtil.retrieveItems("", configModel.getConfig()));
- }
-
- return PollResult.createFull(configurations);
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/DynamicConfigurationChangedEvent.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/DynamicConfigurationChangedEvent.java
deleted file mode 100644
index b466d2191..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/DynamicConfigurationChangedEvent.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.event;
-
-import com.netflix.config.WatchedUpdateResult;
-
-public class DynamicConfigurationChangedEvent {
- private final WatchedUpdateResult event;
-
- public DynamicConfigurationChangedEvent(WatchedUpdateResult event) {
- this.event = event;
- }
-
- public WatchedUpdateResult getEvent() {
- return this.event;
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/RefreshGovernanceConfigurationEvent.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/RefreshGovernanceConfigurationEvent.java
deleted file mode 100644
index a3e1d799f..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/event/RefreshGovernanceConfigurationEvent.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.event;
-
-import com.netflix.config.WatchedUpdateResult;
-
-public class RefreshGovernanceConfigurationEvent {
- private final WatchedUpdateResult event;
-
- public RefreshGovernanceConfigurationEvent(WatchedUpdateResult event) {
- this.event = event;
- }
-
- public WatchedUpdateResult getEvent() {
- return this.event;
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/AbstractConfigLoader.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/AbstractConfigLoader.java
similarity index 98%
rename from foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/AbstractConfigLoader.java
rename to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/AbstractConfigLoader.java
index 74051441c..085afc8c7 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/AbstractConfigLoader.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/AbstractConfigLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.archaius.sources;
+package org.apache.servicecomb.config.file;
import java.io.IOException;
import java.net.URL;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigModel.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/ConfigModel.java
similarity index 96%
rename from foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigModel.java
rename to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/ConfigModel.java
index bb702bf59..41732f9ab 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/ConfigModel.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/ConfigModel.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.archaius.sources;
+package org.apache.servicecomb.config.file;
import java.net.URL;
import java.util.Map;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigLoader.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/MicroserviceConfigLoader.java
similarity index 98%
rename from foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigLoader.java
rename to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/MicroserviceConfigLoader.java
index e9e210255..f33f9cc23 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/MicroserviceConfigLoader.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/MicroserviceConfigLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.archaius.sources;
+package org.apache.servicecomb.config.file;
import java.io.IOException;
import java.net.URL;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/YAMLConfigLoader.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/YAMLConfigLoader.java
similarity index 95%
rename from foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/YAMLConfigLoader.java
rename to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/YAMLConfigLoader.java
index f50451f6d..ac69e8d4d 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/archaius/sources/YAMLConfigLoader.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/file/YAMLConfigLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.archaius.sources;
+package org.apache.servicecomb.config.file;
import java.io.IOException;
import java.io.InputStream;
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
deleted file mode 100644
index 34fbea2cd..000000000
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestYAMLConfigurationSource.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.sources;
-
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler;
-import org.junit.Test;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.ConcurrentMapConfiguration;
-import com.netflix.config.DynamicConfiguration;
-import com.netflix.config.PollResult;
-import org.junit.jupiter.api.Assertions;
-
-/**
- * Created by on 2017/1/5.
- */
-public class TestYAMLConfigurationSource {
-
- @Test
- public void testPullFromClassPath() throws Exception {
- MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
- loader.loadAndSort();
-
- MicroserviceConfigurationSource configSource = new MicroserviceConfigurationSource(loader.getConfigModels());
- PollResult result = configSource.poll(true, null);
- Map<String, Object> configMap = result.getComplete();
- Assertions.assertNotNull(configMap);
- Assertions.assertEquals(23, configMap.size());
- Assertions.assertNotNull(configMap.get("trace.handler.sampler.percent"));
- Assertions.assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));
- }
-
- @Test
- public void testPullFroGivenURL() throws Exception {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL test1URL = loader.getResource("test1.yaml");
- URL test2URL = loader.getResource("test2.yaml");
- System.setProperty("servicecomb.configurationSource.additionalUrls", test1URL.toString() + "," + test2URL.toString());
- MicroserviceConfigLoader loader1 = new MicroserviceConfigLoader();
- loader1.loadAndSort();
-
- MicroserviceConfigurationSource configSource = new MicroserviceConfigurationSource(loader1.getConfigModels());
- PollResult result = configSource.poll(true, null);
- Map<String, Object> configMap = result.getComplete();
-
- Assertions.assertEquals(3, configSource.getConfigModels().size());
- Assertions.assertNotNull(configMap);
- Assertions.assertEquals(34, configMap.size());
- Assertions.assertNotNull(configMap.get("trace.handler.sampler.percent"));
- Assertions.assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));
-
- System.getProperties().remove("servicecomb.configurationSource.additionalUrls");
- }
-
- @Test
- public void testFullOperation() {
- // configuration from system properties
- ConcurrentMapConfiguration configFromSystemProperties =
- new ConcurrentMapConfiguration(new SystemConfiguration());
- // configuration from yaml file
- MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
- loader.loadAndSort();
-
- DynamicConfiguration configFromYamlFile =
- new DynamicConfiguration(new MicroserviceConfigurationSource(loader.getConfigModels()), new NeverStartPollingScheduler());
- // create a hierarchy of configuration that makes
- // 1) dynamic configuration source override system properties
- ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
- finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
- finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
- Assertions.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);
-
- Object o = finalConfig.getProperty("zq");
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
- Assertions.assertEquals(3, listO.size());
- }
-}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestMicroserviceConfigLoader.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
similarity index 95%
rename from foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestMicroserviceConfigLoader.java
rename to foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
index c9836bf4a..ff6b81260 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/archaius/sources/TestMicroserviceConfigLoader.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/file/TestMicroserviceConfigLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.archaius.sources;
+package org.apache.servicecomb.config.file;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -25,6 +25,8 @@ import java.net.URL;
import java.util.List;
import java.util.stream.Collectors;
+import org.apache.servicecomb.config.file.ConfigModel;
+import org.apache.servicecomb.config.file.MicroserviceConfigLoader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
[servicecomb-java-chassis] 21/25: [SCB-2008]priority property adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit bf0b2fc1d37cbcc3430454db16b74dea47e1c84c
Author: liubao <bi...@qq.com>
AuthorDate: Mon Oct 9 12:03:19 2023 +0800
[SCB-2008]priority property adapter
---
.../rest/RestProducerInvocationCreatorTest.java | 4 +-
.../common/rest/TestRestEngineSchemaListener.java | 4 +-
.../rest/definition/TestRestOperationMeta.java | 4 +-
.../filter/inner/RestServerCodecFilterTest.java | 2 +-
.../common/rest/locator/TestMicroservicePaths.java | 2 +-
.../rest/locator/TestServicePathManager.java | 4 +-
.../servicecomb/core/bootstrap/SCBBootstrap.java | 5 +-
.../core/bootstrap/SCBEngineForTest.java | 6 +-
.../core/TestSCBApplicationListener.java | 2 +-
.../filter/impl/ParameterValidatorFilterTest.java | 3 +-
.../servicecomb/config/cc/ConfigCenterConfig.java | 14 --
.../config/nacos/NacosDynamicPropertiesSource.java | 5 -
foundations/foundation-config/pom.xml | 4 -
.../org/apache/servicecomb/config/ConfigUtil.java | 16 ++
.../config/DynamicConfigurationExt.java | 34 ----
.../config/DynamicWatchedConfigurationExt.java | 75 -------
.../config/FoundationConfigConfiguration.java | 4 +-
.../config/priority/ConfigObjectFactory.java | 6 +-
.../config/priority/ConfigObjectProperty.java | 1 +
.../config/priority/DynamicProperty.java | 58 ++++++
.../config/priority/PriorityProperty.java | 11 +-
.../config/priority/PriorityPropertyFactory.java | 38 +---
.../config/priority/PriorityPropertyManager.java | 33 ++--
.../config/inject/TestConfigObjectFactory.java | 217 ++++++++++++++-------
.../config/priority/TestPriorityProperty.java | 147 +++++++-------
.../config/priority/TestPriorityPropertyBase.java | 17 +-
.../registry/config/ConfigurePropertyUtils.java | 55 ------
.../servicecomb/loadbalance/Configuration.java | 4 +-
.../loadbalance/TestLoadBalanceFilter.java | 2 +-
.../TestInstancePropertyDiscoveryFilter.java | 62 +++---
.../TestAuthenticationBootListener.java | 3 +-
.../tracing/zipkin/ZipkinTracingFilter.java | 3 -
.../pojo/reference/PojoReferenceMetaTest.java | 6 +-
.../pojo/reference/TestRpcReferenceProcessor.java | 6 +-
.../highway/HighwayServerCodecFilterTest.java | 3 +-
.../transport/rest/servlet/TestRestServlet.java | 2 +-
.../rest/vertx/TestRestServerVerticle.java | 2 +-
.../rest/vertx/TestVertxRestDispatcher.java | 2 +-
38 files changed, 405 insertions(+), 461 deletions(-)
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
index ea326b912..cc62f4c2e 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
@@ -82,9 +82,9 @@ public class RestProducerInvocationCreatorTest {
@BeforeAll
public static void beforeClass() {
- engine = SCBBootstrap.createSCBEngineForTest();
- engine.setStatus(SCBStatus.UP);
Environment environment = Mockito.mock(Environment.class);
+ engine = SCBBootstrap.createSCBEngineForTest(environment);
+ engine.setStatus(SCBStatus.UP);
LegacyPropertyFactory.setEnvironment(environment);
Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
.thenReturn(false);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
index 4f782eeb9..43f452a14 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
@@ -47,12 +47,12 @@ public class TestRestEngineSchemaListener {
@BeforeAll
public static void setup() {
- scbEngine = SCBBootstrap.createSCBEngineForTest();
+ Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
TransportManager transportManager = Mockito.mock(TransportManager.class);
scbEngine.setTransportManager(transportManager);
scbEngine.setExecutorManager(executorManager);
- Environment environment = Mockito.mock(Environment.class);
scbEngine.setEnvironment(environment);
LegacyPropertyFactory.setEnvironment(environment);
Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
index b9fc9372a..7df112fcd 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
@@ -166,12 +166,12 @@ public class TestRestOperationMeta {
@BeforeAll
public static void classSetup() {
- scbEngine = SCBBootstrap.createSCBEngineForTest();
+ Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
TransportManager transportManager = Mockito.mock(TransportManager.class);
scbEngine.setTransportManager(transportManager);
scbEngine.setExecutorManager(executorManager);
- Environment environment = Mockito.mock(Environment.class);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
index 8da1fa350..41f4826fc 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
@@ -97,8 +97,8 @@ public class RestServerCodecFilterTest {
@BeforeAll
public static void beforeClass() {
- engine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ engine = SCBBootstrap.createSCBEngineForTest(environment);
engine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
index e1d53e7f5..95538da15 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
@@ -46,8 +46,8 @@ public class TestMicroservicePaths {
@BeforeAll
public static void setup() {
- scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
LegacyPropertyFactory.setEnvironment(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
index 47b3ecb53..b6fe098c3 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
@@ -65,8 +65,8 @@ public class TestServicePathManager {
@Test
public void testBuildProducerPathsNoPrefix() {
- scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
@@ -90,8 +90,8 @@ public class TestServicePathManager {
@Test
public void testBuildProducerPathsHasPrefix() {
ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, "/root/rest");
- scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
diff --git a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
index 395760160..14a6c65b8 100644
--- a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
+++ b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
@@ -26,9 +26,10 @@ import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.registry.DiscoveryManager;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.registry.discovery.TelnetInstancePing;
+import org.springframework.core.env.Environment;
public class SCBBootstrap {
- public static SCBEngine createSCBEngineForTest() {
+ public static SCBEngine createSCBEngineForTest(Environment environment) {
RegistrationManager registrationManager = new RegistrationManager(Collections.emptyList());
DiscoveryManager discoveryManager = new DiscoveryManager(Collections.emptyList(),
List.of(new TelnetInstancePing()));
@@ -39,7 +40,7 @@ public class SCBBootstrap {
microserviceProperties.setName("test");
microserviceProperties.setVersion("0.0.1");
- SCBEngine result = new SCBEngineForTest();
+ SCBEngine result = new SCBEngineForTest(environment);
result.setDiscoveryManager(discoveryManager);
result.setRegistrationManager(registrationManager);
result.setBootListeners(Collections.emptyList());
diff --git a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBEngineForTest.java b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBEngineForTest.java
index 36eb26dc7..48d3fe01d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBEngineForTest.java
+++ b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBEngineForTest.java
@@ -30,21 +30,23 @@ import org.apache.servicecomb.core.filter.impl.EmptyFilter;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.event.SimpleEventBus;
import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
+import org.springframework.core.env.Environment;
/**
* not depend on remote service registry and spring context
*/
public class SCBEngineForTest extends SCBEngine {
- public SCBEngineForTest() {
+ public SCBEngineForTest(Environment environment) {
List<Filter> filters = Arrays.asList(
new EmptyFilter()
);
setFilterChainsManager(new FilterChainsManager()
.addFilters(filters));
- PriorityPropertyFactory propertyFactory = new PriorityPropertyFactory();
+ PriorityPropertyFactory propertyFactory = new PriorityPropertyFactory(environment);
ConfigObjectFactory configObjectFactory = new ConfigObjectFactory(propertyFactory);
setPriorityPropertyManager(new PriorityPropertyManager(configObjectFactory));
+ setEnvironment(environment);
}
@Override
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
index c6aad1f9d..99690c3c3 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
@@ -40,8 +40,8 @@ public class TestSCBApplicationListener {
@Test
public void onApplicationEvent_close() {
ContextClosedEvent contextClosedEvent = Mockito.mock(ContextClosedEvent.class);
- SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
diff --git a/core/src/test/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilterTest.java b/core/src/test/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilterTest.java
index 5d441ef26..f80490978 100644
--- a/core/src/test/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilterTest.java
+++ b/core/src/test/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilterTest.java
@@ -100,8 +100,9 @@ public class ParameterValidatorFilterTest {
@Before
public void setUp() throws Exception {
- SCBEngine engine = SCBBootstrap.createSCBEngineForTest();
environment = Mockito.mock(Environment.class);
+ SCBEngine engine = SCBBootstrap.createSCBEngineForTest(environment);
+
Mockito.when(environment.getProperty(ENABLE_EL, boolean.class, false)).thenReturn(false);
filter.setEnvironment(environment);
filter.afterPropertiesSet();
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
index 3476bb2e6..eaa047e98 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
@@ -24,31 +24,21 @@ import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.vertx.VertxConst;
import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-
public final class ConfigCenterConfig {
public static final String SSL_TAG = "cc.consumer";
- private static ConcurrentCompositeConfiguration finalConfig;
-
- private static final String AUTO_DISCOVERY_ENABLED = "servicecomb.service.registry.autodiscovery";
-
private static final String ADDRESS = "servicecomb.config.client.serverUri";
private static final String DOMAIN_NAME = "servicecomb.config.client.domainName";
private static final String REFRESH_INTERVAL = "servicecomb.config.client.refresh_interval";
- private static final String FIRST_REFRESH_INTERVAL = "servicecomb.config.client.first_refresh_interval";
-
private static final String FIRST_PULL_REQUIRED = "servicecomb.config.client.firstPullRequired";
public static final String FILE_SOURCE = "servicecomb.config.client.fileSource";
private static final int DEFAULT_REFRESH_INTERVAL = 15000;
- private static final int DEFAULT_FIRST_REFRESH_INTERVAL = 0;
-
private final Environment environment;
public ConfigCenterConfig(Environment environment) {
@@ -73,10 +63,6 @@ public final class ConfigCenterConfig {
REFRESH_INTERVAL, long.class, (long) DEFAULT_REFRESH_INTERVAL);
}
- public int getFirstRefreshInterval() {
- return environment.getProperty(FIRST_REFRESH_INTERVAL, int.class, DEFAULT_FIRST_REFRESH_INTERVAL);
- }
-
public Boolean isProxyEnable() {
return environment.getProperty(VertxConst.PROXY_ENABLE, boolean.class, false);
}
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
index 4b39760a9..bb6d32780 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
@@ -20,10 +20,8 @@ import static org.apache.servicecomb.config.nacos.ConfigurationAction.CREATE;
import static org.apache.servicecomb.config.nacos.ConfigurationAction.DELETE;
import static org.apache.servicecomb.config.nacos.ConfigurationAction.SET;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.servicecomb.config.ConfigMapping;
import org.apache.servicecomb.config.DynamicPropertiesSource;
@@ -34,7 +32,6 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.WatchedUpdateListener;
public class NacosDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
public static final String SOURCE_NAME = "kie";
@@ -43,8 +40,6 @@ public class NacosDynamicPropertiesSource implements DynamicPropertiesSource<Map
private final Map<String, Object> valueCache = new ConcurrentHashMap<>();
- private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
-
public NacosDynamicPropertiesSource() {
}
diff --git a/foundations/foundation-config/pom.xml b/foundations/foundation-config/pom.xml
index b609a9630..f79b84d72 100644
--- a/foundations/foundation-config/pom.xml
+++ b/foundations/foundation-config/pom.xml
@@ -43,10 +43,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- </dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index 4259badfc..73dc2348a 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -17,8 +17,10 @@
package org.apache.servicecomb.config;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.configuration.PropertyConverter;
@@ -48,4 +50,18 @@ public final class ConfigUtil {
}
return result;
}
+
+ public static Map<String, String> stringPropertiesWithPrefix(Environment environment, String prefix) {
+ Map<String, String> result = new HashMap<>();
+ for (PropertySource<?> propertySource : ((ConfigurableEnvironment) environment).getPropertySources()) {
+ if (propertySource instanceof EnumerablePropertySource) {
+ for (String key : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
+ if (key.startsWith(prefix)) {
+ result.put(key, environment.getProperty(key));
+ }
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicConfigurationExt.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicConfigurationExt.java
deleted file mode 100644
index a89e89bf2..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicConfigurationExt.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config;
-
-import com.netflix.config.AbstractPollingScheduler;
-import com.netflix.config.DynamicConfiguration;
-import com.netflix.config.PolledConfigurationSource;
-
-/**
- * Disable delimiter parsing for string
- */
-@SuppressWarnings("unchecked")
-public class DynamicConfigurationExt extends DynamicConfiguration {
- public DynamicConfigurationExt(PolledConfigurationSource source, AbstractPollingScheduler scheduler) {
- super();
- setDelimiterParsingDisabled(true);
- startPolling(source, scheduler);
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicWatchedConfigurationExt.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicWatchedConfigurationExt.java
deleted file mode 100644
index 0aa3b0491..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicWatchedConfigurationExt.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config;
-
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.netflix.config.ConcurrentMapConfiguration;
-import com.netflix.config.DynamicPropertyUpdater;
-import com.netflix.config.DynamicWatchedConfiguration;
-import com.netflix.config.WatchedConfigurationSource;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-/**
- * Same as DynamicWatchedConfiguration but Disable delimiter parsing for string
- *
- * @see DynamicWatchedConfiguration
- */
-@SuppressWarnings("unchecked")
-public class DynamicWatchedConfigurationExt extends ConcurrentMapConfiguration implements WatchedUpdateListener {
-
- private final boolean ignoreDeletesFromSource;
-
- private final DynamicPropertyUpdater updater;
-
- private static final Logger LOGGER = LoggerFactory.getLogger(DynamicWatchedConfigurationExt.class);
-
- private DynamicWatchedConfigurationExt(WatchedConfigurationSource source, boolean ignoreDeletesFromSource,
- DynamicPropertyUpdater updater) {
- this.ignoreDeletesFromSource = ignoreDeletesFromSource;
- this.updater = updater;
-
- setDelimiterParsingDisabled(true);
-
- // get a current snapshot of the config source data
- try {
- Map<String, Object> currentData = source.getCurrentData();
- WatchedUpdateResult result = WatchedUpdateResult.createFull(currentData);
-
- updateConfiguration(result);
- } catch (final Exception exc) {
- LOGGER.error("could not getCurrentData() from the WatchedConfigurationSource", exc);
- }
-
- // add a listener for subsequent config updates
- source.addUpdateListener(this);
- }
-
- public DynamicWatchedConfigurationExt(final WatchedConfigurationSource source) {
- this(source, false, new DynamicPropertyUpdater());
- }
-
- @Override
- public void updateConfiguration(final WatchedUpdateResult result) {
- updater.updateProperties(result, this, ignoreDeletesFromSource);
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
index 18906749f..a89cd16a4 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
@@ -40,8 +40,8 @@ public class FoundationConfigConfiguration {
}
@Bean
- public PriorityPropertyFactory priorityPropertyFactory() {
- return new PriorityPropertyFactory();
+ public PriorityPropertyFactory priorityPropertyFactory(Environment environment) {
+ return new PriorityPropertyFactory(environment);
}
@Bean
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
index c5b9cf855..ff18b827e 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
@@ -44,11 +44,11 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
public class ConfigObjectFactory {
private final PriorityPropertyFactory propertyFactory;
- private static final Map<Class<?>, JavaType> classCache = new ConcurrentHashMapEx<>();
+ private final Map<Class<?>, JavaType> classCache = new ConcurrentHashMapEx<>();
- private static final Map<JavaType, BeanDescription> javaTypeCache = new ConcurrentHashMapEx<>();
+ private final Map<JavaType, BeanDescription> javaTypeCache = new ConcurrentHashMapEx<>();
- private static final Map<BeanPropertyDefinition, Setter<Object, Object>> beanDescriptionCache = new ConcurrentHashMapEx<>();
+ private final Map<BeanPropertyDefinition, Setter<Object, Object>> beanDescriptionCache = new ConcurrentHashMapEx<>();
public ConfigObjectFactory(PriorityPropertyFactory propertyFactory) {
this.propertyFactory = propertyFactory;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
index e81465b0f..b575ec33c 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
@@ -36,6 +36,7 @@ public class ConfigObjectProperty {
public void updateValueWhenChanged(Object instance, @Nullable String changedKey) {
if (property.isChangedKey(changedKey)) {
+ property.updateValue();
setter.set(instance, property.getValue());
}
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/DynamicProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/DynamicProperty.java
new file mode 100644
index 000000000..48588b6ec
--- /dev/null
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/DynamicProperty.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.config.priority;
+
+import org.springframework.core.env.Environment;
+
+public class DynamicProperty {
+ private final Environment environment;
+
+ private final String propName;
+
+ public DynamicProperty(Environment environment, String propName) {
+ this.environment = environment;
+ this.propName = propName;
+ }
+
+ public Integer getInteger() {
+ return environment.getProperty(propName, Integer.class);
+ }
+
+ public Long getLong() {
+ return environment.getProperty(propName, Long.class);
+ }
+
+ public String getString() {
+ return environment.getProperty(propName);
+ }
+
+ public Boolean getBoolean() {
+ return environment.getProperty(propName, Boolean.class);
+ }
+
+ public Double getDouble() {
+ return environment.getProperty(propName, Double.class);
+ }
+
+ public Float getFloat() {
+ return environment.getProperty(propName, Float.class);
+ }
+
+ public String getName() {
+ return propName;
+ }
+}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java
index 3d03267ae..7ebbcfd8d 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java
@@ -23,8 +23,7 @@ import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.netflix.config.DynamicProperty;
+import org.springframework.core.env.Environment;
/**
* must create by PriorityPropertyManager<br>
@@ -44,19 +43,19 @@ public class PriorityProperty<T> {
private T finalValue;
- public PriorityProperty(PriorityPropertyType<T> propertyType) {
+ public PriorityProperty(Environment environment, PriorityPropertyType<T> propertyType) {
this.propertyType = propertyType;
this.joinedPriorityKeys = Arrays.toString(propertyType.getPriorityKeys());
this.internalValueReader = collectReader(propertyType.getType());
- this.properties = createProperties(propertyType.getPriorityKeys());
+ this.properties = createProperties(environment, propertyType.getPriorityKeys());
initValue();
}
- private DynamicProperty[] createProperties(String[] priorityKeys) {
+ private DynamicProperty[] createProperties(Environment environment, String[] priorityKeys) {
DynamicProperty[] properties = new DynamicProperty[priorityKeys.length];
for (int idx = 0; idx < priorityKeys.length; idx++) {
String key = priorityKeys[idx].trim();
- properties[idx] = DynamicProperty.getInstance(key);
+ properties[idx] = new DynamicProperty(environment, key);
}
return properties;
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
index 92ead1599..abd43f8d4 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
@@ -21,51 +21,29 @@ import java.lang.reflect.Type;
import java.util.Map;
import java.util.stream.Stream;
-import jakarta.annotation.PreDestroy;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
+import org.springframework.core.env.Environment;
-import com.netflix.config.ConfigurationManager;
+import com.google.common.annotations.VisibleForTesting;
public class PriorityPropertyFactory {
- private final AbstractConfiguration configuration;
-
- private final ConfigurationListener configurationListener = this::configurationListener;
-
- // same to com.netflix.config.DynamicProperty.ALL_PROPS
- // the set is finite
- // will not cause OOM exception
private final Map<PriorityPropertyType<?>, PriorityProperty<?>> properties = new ConcurrentHashMapEx<>();
- public PriorityPropertyFactory() {
- this.configuration = ConfigurationManager.getConfigInstance();
- this.configuration.addConfigurationListener(configurationListener);
- }
+ private final Environment environment;
- @PreDestroy
- public void onDestroy() {
- this.configuration.removeConfigurationListener(configurationListener);
+ public PriorityPropertyFactory(Environment environment) {
+ this.environment = environment;
}
+ @VisibleForTesting
public Stream<PriorityProperty<?>> getProperties() {
return properties.values().stream();
}
- private void configurationListener(ConfigurationEvent event) {
- if (event.isBeforeUpdate()) {
- return;
- }
-
- // just update all properties, it's very fast, no need to do any optimize
- getProperties().forEach(PriorityProperty::updateValue);
- }
-
@SuppressWarnings("unchecked")
public <T> PriorityProperty<T> getOrCreate(Type type, T invalidValue, T defaultValue, String... priorityKeys) {
PriorityPropertyType<T> propertyType = new PriorityPropertyType<>(type, invalidValue, defaultValue, priorityKeys);
- return (PriorityProperty<T>) properties.computeIfAbsent(propertyType, PriorityProperty::new);
+ return (PriorityProperty<T>) properties.computeIfAbsent(propertyType,
+ key -> new PriorityProperty<>(environment, key));
}
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
index 95b37a037..8ed1e7dea 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
@@ -24,18 +24,13 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.WeakHashMap;
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.ConfigurationManager;
+import com.google.common.eventbus.Subscribe;
public class PriorityPropertyManager {
- private final AbstractConfiguration configuration;
-
- private final ConfigurationListener configurationListener = this::configurationListener;
-
private final ConfigObjectFactory configObjectFactory;
// key is config object instance
@@ -43,10 +38,8 @@ public class PriorityPropertyManager {
private final Map<Object, List<ConfigObjectProperty>> configObjectMap = synchronizedMap(new WeakHashMap<>());
public PriorityPropertyManager(ConfigObjectFactory configObjectFactory) {
- this.configuration = ConfigurationManager.getConfigInstance();
- this.configuration.addConfigurationListener(configurationListener);
-
this.configObjectFactory = configObjectFactory;
+ EventManager.register(this);
}
public PriorityPropertyFactory getPropertyFactory() {
@@ -54,20 +47,20 @@ public class PriorityPropertyManager {
}
public void close() {
- configuration.removeConfigurationListener(configurationListener);
- }
- public synchronized void configurationListener(ConfigurationEvent event) {
- if (event.isBeforeUpdate()) {
- return;
- }
+ }
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
// just loop all properties, it's very fast, no need to do any optimize
for (Entry<Object, List<ConfigObjectProperty>> entry : configObjectMap.entrySet()) {
Object instance = entry.getKey();
- entry.getValue()
- .forEach(
- configObjectProperty -> configObjectProperty.updateValueWhenChanged(instance, event.getPropertyName()));
+ entry.getValue().forEach(
+ configObjectProperty -> {
+ for (String updatedKey : event.getChanged()) {
+ configObjectProperty.updateValueWhenChanged(instance, updatedKey);
+ }
+ });
}
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
index ec9412898..9e5915b0c 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
@@ -17,11 +17,15 @@
package org.apache.servicecomb.config.inject;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.config.priority.TestPriorityPropertyBase;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
public class TestConfigObjectFactory extends TestPriorityPropertyBase {
public static class ConfigNoAnnotation {
@@ -193,33 +197,33 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
@Test
public void noAnnotation_initValue() {
- ArchaiusUtils.setProperty("strValue", "strValue");
- ArchaiusUtils.setProperty("strValue1", "strValue1");
-
- ArchaiusUtils.setProperty("intValue", 1);
- ArchaiusUtils.setProperty("intValue1", 2);
- ArchaiusUtils.setProperty("intValueObj", 3);
- ArchaiusUtils.setProperty("intValueObj1", 4);
-
- ArchaiusUtils.setProperty("longValue", 5);
- ArchaiusUtils.setProperty("longValue1", 6);
- ArchaiusUtils.setProperty("longValueObj", 7);
- ArchaiusUtils.setProperty("longValueObj1", 8);
-
- ArchaiusUtils.setProperty("floatValue", 9.0);
- ArchaiusUtils.setProperty("floatValue1", 10.0);
- ArchaiusUtils.setProperty("floatValueObj", 11.0);
- ArchaiusUtils.setProperty("floatValueObj1", 12.0);
-
- ArchaiusUtils.setProperty("doubleValue", 13.0);
- ArchaiusUtils.setProperty("doubleValue1", 14.0);
- ArchaiusUtils.setProperty("doubleValueObj", 15.0);
- ArchaiusUtils.setProperty("doubleValueObj1", 16.0);
-
- ArchaiusUtils.setProperty("booleanValue", true);
- ArchaiusUtils.setProperty("booleanValue1", true);
- ArchaiusUtils.setProperty("booleanValueObj", true);
- ArchaiusUtils.setProperty("booleanValueObj1", true);
+ Mockito.when(environment.getProperty("strValue")).thenReturn("strValue");
+ Mockito.when(environment.getProperty("strValue1")).thenReturn("strValue1");
+
+ Mockito.when(environment.getProperty("intValue", Integer.class)).thenReturn(1);
+ Mockito.when(environment.getProperty("intValue1", Integer.class)).thenReturn(2);
+ Mockito.when(environment.getProperty("intValueObj", Integer.class)).thenReturn(3);
+ Mockito.when(environment.getProperty("intValueObj1", Integer.class)).thenReturn(4);
+
+ Mockito.when(environment.getProperty("longValue", Long.class)).thenReturn(5L);
+ Mockito.when(environment.getProperty("longValue1", Long.class)).thenReturn(6L);
+ Mockito.when(environment.getProperty("longValueObj", Long.class)).thenReturn(7L);
+ Mockito.when(environment.getProperty("longValueObj1", Long.class)).thenReturn(8L);
+
+ Mockito.when(environment.getProperty("floatValue", Float.class)).thenReturn(9.0F);
+ Mockito.when(environment.getProperty("floatValue1", Float.class)).thenReturn(10.0F);
+ Mockito.when(environment.getProperty("floatValueObj", Float.class)).thenReturn(11.0F);
+ Mockito.when(environment.getProperty("floatValueObj1", Float.class)).thenReturn(12.0F);
+
+ Mockito.when(environment.getProperty("doubleValue", Double.class)).thenReturn(13.0D);
+ Mockito.when(environment.getProperty("doubleValue1", Double.class)).thenReturn(14.0D);
+ Mockito.when(environment.getProperty("doubleValueObj", Double.class)).thenReturn(15.0D);
+ Mockito.when(environment.getProperty("doubleValueObj1", Double.class)).thenReturn(16.0D);
+
+ Mockito.when(environment.getProperty("booleanValue", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValue1", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValueObj", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValueObj1", Boolean.class)).thenReturn(true);
ConfigNoAnnotation config = priorityPropertyManager.createConfigObject(ConfigNoAnnotation.class);
@@ -256,33 +260,64 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
public void noAnnotation_updateValue() {
ConfigNoAnnotation config = priorityPropertyManager.createConfigObject(ConfigNoAnnotation.class);
- ArchaiusUtils.setProperty("strValue", "strValue");
- ArchaiusUtils.setProperty("strValue1", "strValue1");
-
- ArchaiusUtils.setProperty("intValue", 1);
- ArchaiusUtils.setProperty("intValue1", 2);
- ArchaiusUtils.setProperty("intValueObj", 3);
- ArchaiusUtils.setProperty("intValueObj1", 4);
-
- ArchaiusUtils.setProperty("longValue", 5);
- ArchaiusUtils.setProperty("longValue1", 6);
- ArchaiusUtils.setProperty("longValueObj", 7);
- ArchaiusUtils.setProperty("longValueObj1", 8);
-
- ArchaiusUtils.setProperty("floatValue", 9.0);
- ArchaiusUtils.setProperty("floatValue1", 10.0);
- ArchaiusUtils.setProperty("floatValueObj", 11.0);
- ArchaiusUtils.setProperty("floatValueObj1", 12.0);
-
- ArchaiusUtils.setProperty("doubleValue", 13.0);
- ArchaiusUtils.setProperty("doubleValue1", 14.0);
- ArchaiusUtils.setProperty("doubleValueObj", 15.0);
- ArchaiusUtils.setProperty("doubleValueObj1", 16.0);
-
- ArchaiusUtils.setProperty("booleanValue", true);
- ArchaiusUtils.setProperty("booleanValue1", true);
- ArchaiusUtils.setProperty("booleanValueObj", true);
- ArchaiusUtils.setProperty("booleanValueObj1", true);
+ Mockito.when(environment.getProperty("strValue")).thenReturn("strValue");
+ Mockito.when(environment.getProperty("strValue1")).thenReturn("strValue1");
+
+ Mockito.when(environment.getProperty("intValue", Integer.class)).thenReturn(1);
+ Mockito.when(environment.getProperty("intValue1", Integer.class)).thenReturn(2);
+ Mockito.when(environment.getProperty("intValueObj", Integer.class)).thenReturn(3);
+ Mockito.when(environment.getProperty("intValueObj1", Integer.class)).thenReturn(4);
+
+ Mockito.when(environment.getProperty("longValue", Long.class)).thenReturn(5L);
+ Mockito.when(environment.getProperty("longValue1", Long.class)).thenReturn(6L);
+ Mockito.when(environment.getProperty("longValueObj", Long.class)).thenReturn(7L);
+ Mockito.when(environment.getProperty("longValueObj1", Long.class)).thenReturn(8L);
+
+ Mockito.when(environment.getProperty("floatValue", Float.class)).thenReturn(9.0F);
+ Mockito.when(environment.getProperty("floatValue1", Float.class)).thenReturn(10.0F);
+ Mockito.when(environment.getProperty("floatValueObj", Float.class)).thenReturn(11.0F);
+ Mockito.when(environment.getProperty("floatValueObj1", Float.class)).thenReturn(12.0F);
+
+ Mockito.when(environment.getProperty("doubleValue", Double.class)).thenReturn(13.0D);
+ Mockito.when(environment.getProperty("doubleValue1", Double.class)).thenReturn(14.0D);
+ Mockito.when(environment.getProperty("doubleValueObj", Double.class)).thenReturn(15.0D);
+ Mockito.when(environment.getProperty("doubleValueObj1", Double.class)).thenReturn(16.0D);
+
+ Mockito.when(environment.getProperty("booleanValue", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValue1", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValueObj", Boolean.class)).thenReturn(true);
+ Mockito.when(environment.getProperty("booleanValueObj1", Boolean.class)).thenReturn(true);
+
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put("strValue", "strValue");
+ updated.put("strValue1", "strValue1");
+
+ updated.put("intValue", 0);
+ updated.put("intValue1", 1);
+ updated.put("intValueObj", 2);
+ updated.put("intValueObj1", 3);
+
+ updated.put("longValue", 5L);
+ updated.put("longValue1", 6L);
+ updated.put("longValueObj", 7L);
+ updated.put("longValueObj1", 8L);
+
+ updated.put("floatValue", 9.0F);
+ updated.put("floatValue1", 10.0F);
+ updated.put("floatValueObj", 11.0F);
+ updated.put("floatValueObj1", 12.0F);
+
+ updated.put("doubleValue", 13.0D);
+ updated.put("doubleValue1", 14.0D);
+ updated.put("doubleValueObj", 15.0D);
+ updated.put("doubleValueObj1", 16.0D);
+
+ updated.put("booleanValue", true);
+ updated.put("booleanValue1", true);
+ updated.put("booleanValueObj", true);
+ updated.put("booleanValueObj1", true);
+
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals("strValue", config.strValue);
Assertions.assertEquals("strValue1", config.getStrValue1());
@@ -370,16 +405,29 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
Assertions.assertEquals(0, config.longValue);
- ArchaiusUtils.setProperty("root.low-2.a.high-2.b", Long.MAX_VALUE);
+ Mockito.when(environment.getProperty("root.low-2.a.high-2.b", Long.class)).thenReturn(Long.MAX_VALUE);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put("root.low-2.a.high-2.b", Long.MAX_VALUE);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals(Long.MAX_VALUE, config.longValue);
- ArchaiusUtils.setProperty("root.low-2.a.high-1.b", Long.MAX_VALUE - 1);
+ Mockito.when(environment.getProperty("root.low-2.a.high-1.b", Long.class)).thenReturn(Long.MAX_VALUE - 1);
+ updated = new HashMap<>();
+ updated.put("root.low-2.a.high-1.b", Long.MAX_VALUE - 1);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
Assertions.assertEquals(Long.MAX_VALUE - 1, config.longValue);
- ArchaiusUtils.setProperty("root.low-1.a.high-2.b", Long.MAX_VALUE - 2);
+ Mockito.when(environment.getProperty("root.low-1.a.high-2.b", Long.class)).thenReturn(Long.MAX_VALUE - 2);
+ updated = new HashMap<>();
+ updated.put("root.low-1.a.high-2.b", Long.MAX_VALUE - 2);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals(Long.MAX_VALUE - 2, config.longValue);
- ArchaiusUtils.setProperty("root.low-1.a.high-1.b", Long.MAX_VALUE - 3);
+ Mockito.when(environment.getProperty("root.low-1.a.high-1.b", Long.class)).thenReturn(Long.MAX_VALUE - 3);
+ updated = new HashMap<>();
+ updated.put("root.low-1.a.high-1.b", Long.MAX_VALUE - 3);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals(Long.MAX_VALUE - 3, config.longValue);
}
@@ -390,11 +438,19 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
Assertions.assertEquals(0, config.floatValue, 0);
- ArchaiusUtils.setProperty("root.l1-2", String.valueOf(1f));
- Assertions.assertEquals(1f, config.floatValue, 0);
+ Mockito.when(environment.getProperty("root.l1-2", Float.class)).thenReturn(1F);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put("root.l1-2", 1F);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
+ Assertions.assertEquals(1F, config.floatValue, 0);
+
+ Mockito.when(environment.getProperty("root.l1-1", Float.class)).thenReturn(2F);
+ updated = new HashMap<>();
+ updated.put("root.l1-1", 2F);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
- ArchaiusUtils.setProperty("root.l1-1", String.valueOf(2f));
- Assertions.assertEquals(2f, config.floatValue, 0);
+ Assertions.assertEquals(2F, config.floatValue, 0);
}
@Test
@@ -403,7 +459,10 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
Assertions.assertEquals(0, config.intValue);
- ArchaiusUtils.setProperty("root.k.value", "1");
+ Mockito.when(environment.getProperty("root.k.value", Integer.class)).thenReturn(1);
+ Map<String, Object> updated = new HashMap<>();
+ updated.put("root.k.value", 1);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals(1, config.intValue);
}
@@ -411,16 +470,28 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
public void overridePrefix() {
ConfigWithAnnotation config = priorityPropertyManager.createConfigObject(ConfigWithAnnotation.class);
- ArchaiusUtils.setProperty("override.high", "high");
+ Mockito.when(environment.getProperty("override.high")).thenReturn("high");
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put("override.high", "high");
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals("high", config.strValue);
- ArchaiusUtils.setProperty("override.high", null);
+ Mockito.when(environment.getProperty("override.high")).thenReturn(null);
+ updated = new HashMap<>();
+ updated.put("override.high", null);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertNull(config.strValue);
- ArchaiusUtils.setProperty("override.low", "low");
+ Mockito.when(environment.getProperty("override.low")).thenReturn("low");
+ updated = new HashMap<>();
+ updated.put("override.low", "low");
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertEquals("low", config.strValue);
- ArchaiusUtils.setProperty("override.low", null);
+ Mockito.when(environment.getProperty("override.low")).thenReturn(null);
+ updated = new HashMap<>();
+ updated.put("override.low", null);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
Assertions.assertNull(config.strValue);
}
@@ -447,8 +518,14 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
Assertions.assertEquals(4, config.index);
Assertions.assertEquals("h", config.model.name);
- ArchaiusUtils.setProperty("root.index", "5");
- ArchaiusUtils.setProperty("root.model.name", "w");
+
+ Mockito.when(environment.getProperty("root.index", Integer.class)).thenReturn(5);
+ Mockito.when(environment.getProperty("root.model.name")).thenReturn("w");
+ Map<String, Object> updated = new HashMap<>();
+ updated.put("root.index", 5);
+ updated.put("root.model.name", "w");
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
+
Assertions.assertEquals(5, config.index);
Assertions.assertEquals("w", config.model.name);
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityProperty.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityProperty.java
index 4448a313d..85b3185d2 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityProperty.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityProperty.java
@@ -16,15 +16,9 @@
*/
package org.apache.servicecomb.config.priority;
-import java.util.Collections;
-
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
+import org.mockito.Mockito;
public class TestPriorityProperty extends TestPriorityPropertyBase {
String high = "ms.schema.op";
@@ -40,26 +34,26 @@ public class TestPriorityProperty extends TestPriorityPropertyBase {
PriorityProperty<Long> config = propertyFactory.getOrCreate(Long.class, -1L, -2L, keys);
Assertions.assertEquals(-2L, (long) config.getValue());
- ArchaiusUtils.setProperty(low, 1L);
+ updateLong(low, 1L, config);
Assertions.assertEquals(1L, (long) config.getValue());
- ArchaiusUtils.setProperty(middle, 2L);
+ updateLong(middle, 2L, config);
Assertions.assertEquals(2L, (long) config.getValue());
- ArchaiusUtils.setProperty(high, 3L);
+ updateLong(high, 3L, config);
Assertions.assertEquals(3L, (long) config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateLong(middle, null, config);
Assertions.assertEquals(3L, (long) config.getValue());
- ArchaiusUtils.setProperty(middle, 2L);
- ArchaiusUtils.setProperty(high, null);
+ updateLong(middle, 2L, config);
+ updateLong(high, null, config);
Assertions.assertEquals(2L, (long) config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateLong(middle, null, config);
Assertions.assertEquals(1L, (long) config.getValue());
- ArchaiusUtils.setProperty(low, null);
+ updateLong(low, null, config);
Assertions.assertEquals(-2L, (long) config.getValue());
}
@@ -68,54 +62,84 @@ public class TestPriorityProperty extends TestPriorityPropertyBase {
PriorityProperty<Integer> config = propertyFactory.getOrCreate(Integer.class, -1, -2, keys);
Assertions.assertEquals(-2L, (int) config.getValue());
- ArchaiusUtils.setProperty(low, 1);
+ updateInt(low, 1, config);
Assertions.assertEquals(1, (int) config.getValue());
- ArchaiusUtils.setProperty(middle, 2);
+ updateInt(middle, 2, config);
Assertions.assertEquals(2, (int) config.getValue());
- ArchaiusUtils.setProperty(high, 3);
+ updateInt(high, 3, config);
Assertions.assertEquals(3, (int) config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateInt(middle, null, config);
Assertions.assertEquals(3, (int) config.getValue());
- ArchaiusUtils.setProperty(middle, 2);
+ updateInt(middle, 2, config);
- ArchaiusUtils.setProperty(high, null);
+ updateInt(high, null, config);
Assertions.assertEquals(2, (int) config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateInt(middle, null, config);
Assertions.assertEquals(1, (int) config.getValue());
- ArchaiusUtils.setProperty(low, null);
+ updateInt(low, null, config);
Assertions.assertEquals(-2, (int) config.getValue());
}
+ private void updateFloat(String key, Float value, PriorityProperty<Float> config) {
+ Mockito.when(environment.getProperty(key, Float.class)).thenReturn(value);
+ config.updateValue();
+ }
+
+ private void updateStr(String key, String value, PriorityProperty<String> config) {
+ Mockito.when(environment.getProperty(key)).thenReturn(value);
+ config.updateValue();
+ }
+
+ private void updateInt(String key, Integer value, PriorityProperty<Integer> config) {
+ Mockito.when(environment.getProperty(key, Integer.class)).thenReturn(value);
+ config.updateValue();
+ }
+
+ private void updateLong(String key, Long value, PriorityProperty<Long> config) {
+ Mockito.when(environment.getProperty(key, Long.class)).thenReturn(value);
+ config.updateValue();
+ }
+
+ private void updateBoolean(String key, Boolean value, PriorityProperty<Boolean> config) {
+ Mockito.when(environment.getProperty(key, Boolean.class)).thenReturn(value);
+ config.updateValue();
+ }
+
+ private void updateDouble(String key, Double value, PriorityProperty<Double> config) {
+ Mockito.when(environment.getProperty(key, Double.class)).thenReturn(value);
+ config.updateValue();
+ }
+
@Test
public void testString() {
PriorityProperty<String> config = propertyFactory.getOrCreate(String.class, null, "def", keys);
Assertions.assertEquals("def", config.getValue());
- ArchaiusUtils.setProperty(low, 1);
+ updateStr(low, "1", config);
Assertions.assertEquals("1", config.getValue());
- ArchaiusUtils.setProperty(middle, 2);
+ updateStr(middle, "2", config);
Assertions.assertEquals("2", config.getValue());
- ArchaiusUtils.setProperty(high, 3);
+ updateStr(high, "3", config);
Assertions.assertEquals("3", config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateStr(middle, null, config);
Assertions.assertEquals("3", config.getValue());
- ArchaiusUtils.setProperty(middle, 2);
- ArchaiusUtils.setProperty(high, null);
+ updateStr(middle, "2", config);
+ updateStr(high, null, config);
Assertions.assertEquals("2", config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateStr(middle, null, config);
Assertions.assertEquals("1", config.getValue());
- ArchaiusUtils.setProperty(low, null);
+ updateStr(low, null, config);
Assertions.assertEquals("def", config.getValue());
}
@@ -124,26 +148,26 @@ public class TestPriorityProperty extends TestPriorityPropertyBase {
PriorityProperty<Boolean> config = propertyFactory.getOrCreate(Boolean.class, null, false, keys);
Assertions.assertFalse(config.getValue());
- ArchaiusUtils.setProperty(low, true);
+ updateBoolean(low, true, config);
Assertions.assertTrue(config.getValue());
- ArchaiusUtils.setProperty(middle, false);
+ updateBoolean(middle, false, config);
Assertions.assertFalse(config.getValue());
- ArchaiusUtils.setProperty(high, true);
+ updateBoolean(high, true, config);
Assertions.assertTrue(config.getValue());
- ArchaiusUtils.setProperty(middle, false);
+ updateBoolean(middle, false, config);
Assertions.assertTrue(config.getValue());
- ArchaiusUtils.setProperty(middle, false);
- ArchaiusUtils.setProperty(high, null);
+ updateBoolean(middle, false, config);
+ updateBoolean(high, null, config);
Assertions.assertFalse(config.getValue());
- ArchaiusUtils.setProperty(middle, null);
+ updateBoolean(middle, null, config);
Assertions.assertTrue(config.getValue());
- ArchaiusUtils.setProperty(low, null);
+ updateBoolean(low, null, config);
Assertions.assertFalse(config.getValue());
}
@@ -152,26 +176,26 @@ public class TestPriorityProperty extends TestPriorityPropertyBase {
PriorityProperty<Double> config = propertyFactory.getOrCreate(Double.class, null, -2.0, keys);
Assertions.assertEquals(-2, config.getValue(), 0);
- ArchaiusUtils.setProperty(low, 1);
+ updateDouble(low, 1D, config);
Assertions.assertEquals(1, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, 2);
+ updateDouble(middle, 2D, config);
Assertions.assertEquals(2, config.getValue(), 0);
- ArchaiusUtils.setProperty(high, 3);
+ updateDouble(high, 3D, config);
Assertions.assertEquals(3, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, null);
+ updateDouble(middle, null, config);
Assertions.assertEquals(3, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, 2);
- ArchaiusUtils.setProperty(high, null);
+ updateDouble(middle, 2D, config);
+ updateDouble(high, null, config);
Assertions.assertEquals(2, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, null);
+ updateDouble(middle, null, config);
Assertions.assertEquals(1, config.getValue(), 0);
- ArchaiusUtils.setProperty(low, null);
+ updateDouble(low, null, config);
Assertions.assertEquals(-2, config.getValue(), 0);
}
@@ -180,39 +204,26 @@ public class TestPriorityProperty extends TestPriorityPropertyBase {
PriorityProperty<Float> config = propertyFactory.getOrCreate(Float.class, null, -2.0f, keys);
Assertions.assertEquals(-2, config.getValue(), 0);
- ArchaiusUtils.setProperty(low, 1);
+ updateFloat(low, 1F, config);
Assertions.assertEquals(1, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, 2);
+ updateFloat(middle, 2F, config);
Assertions.assertEquals(2, config.getValue(), 0);
- ArchaiusUtils.setProperty(high, 3);
+ updateFloat(high, 3F, config);
Assertions.assertEquals(3, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, null);
+ updateFloat(middle, null, config);
Assertions.assertEquals(3, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, 2);
- ArchaiusUtils.setProperty(high, null);
+ updateFloat(middle, 2F, config);
+ updateFloat(high, null, config);
Assertions.assertEquals(2, config.getValue(), 0);
- ArchaiusUtils.setProperty(middle, null);
+ updateFloat(middle, null, config);
Assertions.assertEquals(1, config.getValue(), 0);
- ArchaiusUtils.setProperty(low, null);
+ updateFloat(low, null, config);
Assertions.assertEquals(-2, config.getValue(), 0);
}
-
- @Test
- public void globalRefresh() {
- PriorityProperty<String> property = propertyFactory.getOrCreate(String.class, null, null, keys);
-
- Assertions.assertNull(property.getValue());
-
- ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
- .getBackingConfigurationSource();
- config.addConfiguration(new MapConfiguration(Collections.singletonMap(high, "high-value")));
-
- Assertions.assertEquals("high-value", property.getValue());
- }
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
index 1b2d5f450..375a755ec 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyBase.java
@@ -16,17 +16,12 @@
*/
package org.apache.servicecomb.config.priority;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.config.Configurator;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
-import com.netflix.config.DynamicPropertyFactory;
-
public class TestPriorityPropertyBase {
protected PriorityPropertyManager priorityPropertyManager;
@@ -36,24 +31,14 @@ public class TestPriorityPropertyBase {
@BeforeEach
public void setup() {
- // avoid write too many logs
- Configurator.setRootLevel(Level.OFF);
-
environment = Mockito.mock(Environment.class);
LegacyPropertyFactory.setEnvironment(environment);
- // make sure create a DynamicPropertyFactory instance
- // otherwise will cause wrong order of configurationListeners
- DynamicPropertyFactory.getInstance();
-
- propertyFactory = new PriorityPropertyFactory();
+ propertyFactory = new PriorityPropertyFactory(environment);
priorityPropertyManager = new PriorityPropertyManager(new ConfigObjectFactory(propertyFactory));
-
- Configurator.setRootLevel(Level.INFO);
}
@AfterEach
public void teardown() {
- ArchaiusUtils.resetConfig();
}
}
diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
deleted file mode 100644
index ad9004d73..000000000
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.registry.config;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.configuration.Configuration;
-
-import com.netflix.config.DynamicPropertyFactory;
-
-public final class ConfigurePropertyUtils {
- private ConfigurePropertyUtils() {
- }
-
- /**
- * 获取key包含prefix前缀的所有配置项
- */
- public static Map<String, String> getPropertiesWithPrefix(String prefix) {
- Object config = DynamicPropertyFactory.getBackingConfigurationSource();
- if (!Configuration.class.isInstance(config)) {
- return new HashMap<>();
- }
-
- return getPropertiesWithPrefix((Configuration) config, prefix);
- }
-
- // caller ensure configuration is valid
- public static Map<String, String> getPropertiesWithPrefix(Configuration configuration, String prefix) {
- Map<String, String> propertiesMap = new HashMap<>();
-
- Iterator<String> keysIterator = configuration.getKeys(prefix);
- while (keysIterator.hasNext()) {
- String key = keysIterator.next();
- propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(configuration.getProperty(key)));
- }
- return propertiesMap;
- }
-}
diff --git a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/Configuration.java b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/Configuration.java
index 47226c0b0..61f7a2eee 100644
--- a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/Configuration.java
+++ b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/Configuration.java
@@ -19,8 +19,8 @@ package org.apache.servicecomb.loadbalance;
import java.util.Map;
+import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.registry.config.ConfigurePropertyUtils;
/**
* configuration items
@@ -188,7 +188,7 @@ public final class Configuration {
public Map<String, String> getFlowsplitFilterOptions(String microservice) {
String keyPrefix = String.format(TRANSACTIONCONTROL_OPTIONS_PREFIX_PATTERN, microservice);
- return ConfigurePropertyUtils.getPropertiesWithPrefix(keyPrefix);
+ return ConfigUtil.stringPropertiesWithPrefix(LegacyPropertyFactory.getEnvironment(), keyPrefix);
}
public static String getStringProperty(String defaultValue, String... keys) {
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
index a03c0e4dd..e7a0c0687 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
@@ -73,8 +73,8 @@ public class TestLoadBalanceFilter {
@Before
public void setUp() {
- scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/TestInstancePropertyDiscoveryFilter.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/TestInstancePropertyDiscoveryFilter.java
index b2902682e..0c498d25d 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/TestInstancePropertyDiscoveryFilter.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/TestInstancePropertyDiscoveryFilter.java
@@ -22,21 +22,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.BaseConfiguration;
import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.apache.servicecomb.registry.discovery.DiscoveryContext;
import org.apache.servicecomb.registry.discovery.DiscoveryTreeNode;
import org.apache.servicecomb.registry.discovery.StatefulDiscoveryInstance;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-
-import mockit.Expectations;
-import mockit.Injectable;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MutablePropertySources;
public class TestInstancePropertyDiscoveryFilter {
@@ -44,16 +42,27 @@ public class TestInstancePropertyDiscoveryFilter {
StatefulDiscoveryInstance instance;
- @BeforeClass
- public static void beforeCls() {
- AbstractConfiguration configuration = new BaseConfiguration();
- configuration.addProperty("servicecomb.loadbalance.test.flowsplitFilter.policy",
- "org.apache.servicecomb.loadbalance.filter.SimpleFlowsplitFilter");
- configuration.addProperty("servicecomb.loadbalance.test.flowsplitFilter.options.tag0", "value0");
- }
+ ConfigurableEnvironment environment;
+
+ EnumerablePropertySource<?> propertySource;
- @Before
+ @BeforeEach
public void setUp() {
+ environment = Mockito.mock(ConfigurableEnvironment.class);
+ LegacyPropertyFactory.setEnvironment(environment);
+ propertySource = Mockito.mock(EnumerablePropertySource.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.loadbalance.test.flowsplitFilter.policy",
+ "servicecomb.loadbalance.test.flowsplitFilter.options.tag0"
+ });
+ Mockito.when(environment.getProperty("servicecomb.loadbalance.test.flowsplitFilter.policy"))
+ .thenReturn("org.apache.servicecomb.loadbalance.filter.SimpleFlowsplitFilter");
+ Mockito.when(environment.getProperty("servicecomb.loadbalance.test.flowsplitFilter.options.tag0"))
+ .thenReturn("value0");
+
filter = new InstancePropertyDiscoveryFilter();
Map<String, String> properties = new HashMap<>();
properties.put("tag0", "value0");
@@ -82,20 +91,17 @@ public class TestInstancePropertyDiscoveryFilter {
@Test
@SuppressWarnings("unchecked")
- public void testGetFilteredListOfServers(@Injectable DiscoveryContext context, @Injectable DiscoveryTreeNode parent,
- @Injectable Invocation invocation) {
+ public void testGetFilteredListOfServers() {
+ DiscoveryContext context = new DiscoveryContext();
+ DiscoveryTreeNode parent = new DiscoveryTreeNode();
+
+ Invocation invocation = Mockito.mock(Invocation.class);
+ context.setInputParameters(invocation);
+
List<StatefulDiscoveryInstance> instances = new ArrayList<>();
instances.add(instance);
- new Expectations() {
- {
- context.getInputParameters();
- result = invocation;
- parent.data();
- result = instances;
- parent.name();
- result = "parent";
- }
- };
+ parent.data(instances);
+ parent.name("parent");
DiscoveryTreeNode node = filter.discovery(context, parent);
Assertions.assertEquals(1, ((List<StatefulDiscoveryInstance>) node.data()).size());
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
index a2be179f5..ca222f5b6 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
@@ -58,8 +58,7 @@ public class TestAuthenticationBootListener {
@BeforeEach
public void setUp() {
- engine = SCBBootstrap.createSCBEngineForTest();
- engine.setEnvironment(environment);
+ engine = SCBBootstrap.createSCBEngineForTest(environment);
engine.run();
}
diff --git a/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingFilter.java b/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingFilter.java
index 2f67b4b64..b7c62e442 100644
--- a/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingFilter.java
+++ b/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingFilter.java
@@ -21,8 +21,6 @@ import static org.apache.servicecomb.swagger.invocation.InvocationType.PROVIDER;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.core.filter.Filter;
@@ -41,7 +39,6 @@ public class ZipkinTracingFilter implements Filter {
private ZipkinProviderDelegate producer;
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
index 98ba2de92..1ecf03156 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
@@ -28,8 +28,12 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class PojoReferenceMetaTest {
+ static Environment environment = Mockito.mock(Environment.class);
+
@BeforeEach
public void setUp() {
}
@@ -40,7 +44,7 @@ public class PojoReferenceMetaTest {
@Test
public void testHasConsumerInterface() {
- SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
+ SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
PojoReferenceMeta pojoReferenceMeta = new PojoReferenceMeta();
pojoReferenceMeta.setMicroserviceName("test");
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
index b20c3785b..0c3754148 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/TestRpcReferenceProcessor.java
@@ -26,8 +26,12 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class TestRpcReferenceProcessor {
+ static Environment environment = Mockito.mock(Environment.class);
+
RpcReferenceProcessor consumers = new RpcReferenceProcessor();
@BeforeEach
@@ -46,7 +50,7 @@ public class TestRpcReferenceProcessor {
@Test
public void testReference() {
- SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
+ SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest(environment);
PersonReference bean = new PersonReference();
diff --git a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilterTest.java b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilterTest.java
index ee159fc1e..8856cb79b 100644
--- a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilterTest.java
+++ b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilterTest.java
@@ -89,8 +89,7 @@ public class HighwayServerCodecFilterTest {
.thenReturn(true);
LegacyPropertyFactory.setEnvironment(environment);
- engine = SCBBootstrap.createSCBEngineForTest();
- engine.setEnvironment(environment);
+ engine = SCBBootstrap.createSCBEngineForTest(environment);
engine.setStatus(SCBStatus.UP);
invocation = InvocationFactory.forProvider(endpoint, operationMeta, null);
}
diff --git a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestRestServlet.java b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestRestServlet.java
index 3fe2094f4..168efb4d0 100644
--- a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestRestServlet.java
+++ b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestRestServlet.java
@@ -56,7 +56,7 @@ public class TestRestServlet {
LegacyPropertyFactory.setEnvironment(environment);
restservlet = new RestServlet();
- SCBBootstrap.createSCBEngineForTest();
+ SCBBootstrap.createSCBEngineForTest(environment);
}
@After
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
index d3b502a6d..3d3545a8e 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
@@ -171,7 +171,7 @@ public class TestRestServerVerticle {
instance = new RestServerVerticle();
startPromise = Promise.promise();
- SCBBootstrap.createSCBEngineForTest();
+ SCBBootstrap.createSCBEngineForTest(environment);
}
@After
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
index aeab3878b..db5edd19f 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
@@ -68,7 +68,7 @@ public class TestVertxRestDispatcher {
dispatcher = new VertxRestDispatcher();
dispatcher.init(mainRouter);
- SCBBootstrap.createSCBEngineForTest().setTransportManager(transportManager);
+ SCBBootstrap.createSCBEngineForTest(environment).setTransportManager(transportManager);
}
@After
[servicecomb-java-chassis] 10/25: [SCB-2008]remove archaius dependency: kie adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 8d2d91a1f11ed664acb452662b7906da79517909
Author: liubao <bi...@qq.com>
AuthorDate: Tue Sep 26 17:01:00 2023 +0800
[SCB-2008]remove archaius dependency: kie adapter
---
.../apache/servicecomb/config/kie/KieConfig.java | 83 +++--------
.../config/kie/KieConfigConfiguration.java | 11 ++
...ceImpl.java => KieDynamicPropertiesSource.java} | 155 ++++++++-------------
.../servicecomb/config/kie/TransportUtils.java | 52 +++----
...comb.config.spi.ConfigCenterConfigurationSource | 18 ---
...comb.config.spi.ConfigCenterConfigurationSource | 18 ---
6 files changed, 120 insertions(+), 217 deletions(-)
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfig.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfig.java
index 872165f51..564b5c8ad 100644
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfig.java
+++ b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfig.java
@@ -17,22 +17,13 @@
package org.apache.servicecomb.config.kie;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.foundation.vertx.VertxConst;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
+import org.springframework.core.env.Environment;
public class KieConfig {
-
- public static final KieConfig INSTANCE = new KieConfig();
-
- private static ConcurrentCompositeConfiguration finalConfig;
-
public static final String SSL_TAG = "kie.consumer";
private static final String SERVER_URL_KEY = "servicecomb.kie.serverUri";
@@ -75,114 +66,86 @@ public class KieConfig {
private static final String CUSTOM_LABEL_VALUE_DEFAULT = "";
- private KieConfig() {
- }
-
- public static ConcurrentCompositeConfiguration getFinalConfig() {
- return finalConfig;
- }
+ private final Environment environment;
- public static void setFinalConfig(ConcurrentCompositeConfiguration finalConfig) {
- KieConfig.finalConfig = finalConfig;
+ public KieConfig(Environment environment) {
+ this.environment = environment;
}
@SuppressWarnings("unchecked")
public List<String> getFileSources() {
- Object property = finalConfig.getProperty(FILE_SOURCE);
- if (property instanceof String) {
- return new ArrayList<>(Arrays.asList(((String) property).split(",")));
- }
- if (property instanceof List) {
- return (List<String>) property;
- }
- return Collections.EMPTY_LIST;
- }
-
- public String getVersion() {
- return BootStrapProperties.readServiceVersion(finalConfig);
- }
-
- public String getServiceName() {
- return BootStrapProperties.readServiceName(finalConfig);
- }
-
- public String getEnvironment() {
- return BootStrapProperties.readServiceEnvironment(finalConfig);
- }
-
- public String getAppName() {
- return BootStrapProperties.readApplication(finalConfig);
+ return environment.getProperty(FILE_SOURCE, List.class, Collections.emptyList());
}
public String getDomainName() {
- return finalConfig.getString(DOMAIN_NAME, "default");
+ return environment.getProperty(DOMAIN_NAME, "default");
}
public String getServerUri() {
- return finalConfig.getString(SERVER_URL_KEY);
+ return environment.getProperty(SERVER_URL_KEY);
}
public int getRefreshInterval() {
- return finalConfig.getInt(REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL);
+ return environment.getProperty(REFRESH_INTERVAL, int.class, DEFAULT_REFRESH_INTERVAL);
}
public int getFirstRefreshInterval() {
- return finalConfig.getInt(FIRST_REFRESH_INTERVAL, DEFAULT_FIRST_REFRESH_INTERVAL);
+ return environment.getProperty(FIRST_REFRESH_INTERVAL, int.class, DEFAULT_FIRST_REFRESH_INTERVAL);
}
public boolean enableAppConfig() {
- return finalConfig.getBoolean(ENABLE_APP_CONFIG, true);
+ return environment.getProperty(ENABLE_APP_CONFIG, boolean.class, true);
}
public boolean enableServiceConfig() {
- return finalConfig.getBoolean(ENABLE_SERVICE_CONFIG, true);
+ return environment.getProperty(ENABLE_SERVICE_CONFIG, boolean.class, true);
}
public boolean enableVersionConfig() {
- return finalConfig.getBoolean(ENABLE_VERSION_CONFIG, true);
+ return environment.getProperty(ENABLE_VERSION_CONFIG, boolean.class, true);
}
public boolean enableCustomConfig() {
- return finalConfig.getBoolean(ENABLE_CUSTOM_CONFIG, true);
+ return environment.getProperty(ENABLE_CUSTOM_CONFIG, boolean.class, true);
}
public boolean enableLongPolling() {
- return finalConfig.getBoolean(ENABLE_LONG_POLLING, DEFAULT_ENABLE_LONG_POLLING);
+ return environment.getProperty(ENABLE_LONG_POLLING, boolean.class, DEFAULT_ENABLE_LONG_POLLING);
}
public int getPollingWaitTime() {
- return finalConfig.getInt(POLLING_WAIT_TIME, DEFAULT_POLLING_WAIT_TIME);
+ return environment.getProperty(POLLING_WAIT_TIME, int.class, DEFAULT_POLLING_WAIT_TIME);
}
public boolean firstPullRequired() {
- return finalConfig.getBoolean(FIRST_PULL_REQUIRED, false);
+ return environment.getProperty(FIRST_PULL_REQUIRED, boolean.class, false);
}
public String getCustomLabel() {
- return finalConfig.getString(CUSTOM_LABEL, CUSTOM_LABEL_DEFAULT);
+ return environment.getProperty(CUSTOM_LABEL, CUSTOM_LABEL_DEFAULT);
}
public String getCustomLabelValue() {
- return finalConfig.getString(CUSTOM_LABEL_VALUE, CUSTOM_LABEL_VALUE_DEFAULT);
+ return environment.getProperty(CUSTOM_LABEL_VALUE, CUSTOM_LABEL_VALUE_DEFAULT);
}
public Boolean isProxyEnable() {
- return finalConfig.getBoolean(VertxConst.PROXY_ENABLE, false);
+ return environment.getProperty(VertxConst.PROXY_ENABLE, boolean.class, false);
}
public String getProxyHost() {
- return finalConfig.getString(VertxConst.PROXY_HOST, "127.0.0.1");
+ return environment.getProperty(VertxConst.PROXY_HOST, "127.0.0.1");
}
public int getProxyPort() {
- return finalConfig.getInt(VertxConst.PROXY_PORT, 8080);
+ return environment.getProperty(VertxConst.PROXY_PORT, int.class, 8080);
}
public String getProxyUsername() {
- return finalConfig.getString(VertxConst.PROXY_USERNAME, null);
+ return environment.getProperty(VertxConst.PROXY_USERNAME);
}
public String getProxyPasswd() {
- return finalConfig.getString(VertxConst.PROXY_PASSWD, null);
+ return environment.getProperty(VertxConst.PROXY_PASSWD);
}
}
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigConfiguration.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigConfiguration.java
index 7b8e35bd6..50a362379 100644
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigConfiguration.java
+++ b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigConfiguration.java
@@ -18,10 +18,21 @@ package org.apache.servicecomb.config.kie;
import org.apache.servicecomb.config.kie.collect.KieClientInformationCollector;
import org.springframework.context.annotation.Bean;
+import org.springframework.core.env.Environment;
public class KieConfigConfiguration {
@Bean
public KieClientInformationCollector kieClientInformationCollector() {
return new KieClientInformationCollector();
}
+
+ @Bean
+ public KieConfig kieConfig(Environment environment) {
+ return new KieConfig(environment);
+ }
+
+ @Bean
+ public KieDynamicPropertiesSource kieDynamicPropertiesSource() {
+ return new KieDynamicPropertiesSource();
+ }
}
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigurationSourceImpl.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieDynamicPropertiesSource.java
similarity index 50%
rename from dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigurationSourceImpl.java
rename to dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieDynamicPropertiesSource.java
index fbf700e82..d18fca89d 100644
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieConfigurationSourceImpl.java
+++ b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/KieDynamicPropertiesSource.java
@@ -14,18 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.servicecomb.config.kie;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -33,126 +28,124 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.servicecomb.config.DynamicPropertiesSource;
+import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.config.common.ConfigConverter;
import org.apache.servicecomb.config.common.ConfigurationChangedEvent;
import org.apache.servicecomb.config.kie.client.KieClient;
import org.apache.servicecomb.config.kie.client.KieConfigManager;
import org.apache.servicecomb.config.kie.client.model.KieAddressManager;
import org.apache.servicecomb.config.kie.client.model.KieConfiguration;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.http.client.auth.RequestAuthHeaderProvider;
import org.apache.servicecomb.http.client.common.HttpTransport;
import org.apache.servicecomb.http.client.common.HttpTransportFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
import com.google.common.eventbus.Subscribe;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-public class KieConfigurationSourceImpl implements ConfigCenterConfigurationSource {
- private static final Logger LOGGER = LoggerFactory.getLogger(KieConfigurationSourceImpl.class);
+public class KieDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
+ public static final String SOURCE_NAME = "kie";
- private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
+ private final Map<String, Object> data = new ConcurrentHashMapEx<>();
private KieConfigManager kieConfigManager;
private ConfigConverter configConverter;
- @Override
- public int getOrder() {
- return ORDER_BASE * 2;
- }
+ private KieConfig kieConfig;
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- KieConfig.setFinalConfig((ConcurrentCompositeConfiguration) localConfiguration);
+ private MicroserviceProperties microserviceProperties;
- if (StringUtils.isEmpty(KieConfig.INSTANCE.getServerUri())) {
- LOGGER.info("Kie server is not configured.");
- return false;
- }
- return true;
+ @Autowired
+ public void setKieConfig(KieConfig kieConfig) {
+ this.kieConfig = kieConfig;
}
- @Override
- public void init(Configuration localConfiguration) {
- configConverter = new ConfigConverter(KieConfig.INSTANCE.getFileSources());
+ @Autowired
+ public void setMicroserviceProperties(MicroserviceProperties microserviceProperties) {
+ this.microserviceProperties = microserviceProperties;
+ }
+
+ private void init(Environment environment) {
+ configConverter = new ConfigConverter(kieConfig.getFileSources());
KieAddressManager kieAddressManager = configKieAddressManager();
RequestConfig.Builder requestBuilder = HttpTransportFactory.defaultRequestConfig();
- if (KieConfig.INSTANCE.enableLongPolling()
- && KieConfig.INSTANCE.getPollingWaitTime() >= 0) {
- requestBuilder.setConnectionRequestTimeout(KieConfig.INSTANCE.getPollingWaitTime() * 2 * 1000);
- requestBuilder.setSocketTimeout(KieConfig.INSTANCE.getPollingWaitTime() * 2 * 1000);
+ if (kieConfig.enableLongPolling()
+ && kieConfig.getPollingWaitTime() >= 0) {
+ requestBuilder.setConnectionRequestTimeout(kieConfig.getPollingWaitTime() * 2 * 1000);
+ requestBuilder.setSocketTimeout(kieConfig.getPollingWaitTime() * 2 * 1000);
}
HttpTransport httpTransport = createHttpTransport(kieAddressManager, requestBuilder.build(),
- localConfiguration);
+ environment);
KieConfiguration kieConfiguration = createKieConfiguration();
KieClient kieClient = new KieClient(kieAddressManager, httpTransport, kieConfiguration);
EventManager.register(this);
kieConfigManager = new KieConfigManager(kieClient, EventManager.getEventBus(), kieConfiguration, configConverter);
kieConfigManager.firstPull();
kieConfigManager.startConfigKieManager();
- updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null));
+ data.putAll(configConverter.getCurrentData());
}
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- updateConfiguration(
- WatchedUpdateResult.createIncremental(event.getAdded(), event.getUpdated(), event.getDeleted()));
+ data.putAll(event.getAdded());
+ data.putAll(event.getUpdated());
+ event.getDeleted().forEach((k, v) -> data.remove(k));
}
private KieConfiguration createKieConfiguration() {
- return new KieConfiguration().setAppName(KieConfig.INSTANCE.getAppName())
- .setFirstPullRequired(KieConfig.INSTANCE.firstPullRequired())
- .setCustomLabel(KieConfig.INSTANCE.getCustomLabel())
- .setCustomLabelValue(KieConfig.INSTANCE.getCustomLabelValue())
- .setEnableAppConfig(KieConfig.INSTANCE.enableAppConfig())
- .setEnableCustomConfig(KieConfig.INSTANCE.enableCustomConfig())
- .setEnableLongPolling(KieConfig.INSTANCE.enableLongPolling())
- .setEnableServiceConfig(KieConfig.INSTANCE.enableServiceConfig())
- .setEnableVersionConfig(KieConfig.INSTANCE.enableVersionConfig())
- .setEnvironment(KieConfig.INSTANCE.getEnvironment())
- .setVersion(KieConfig.INSTANCE.getVersion())
- .setPollingWaitInSeconds(KieConfig.INSTANCE.getPollingWaitTime())
- .setProject(KieConfig.INSTANCE.getDomainName())
- .setRefreshIntervalInMillis(KieConfig.INSTANCE.getRefreshInterval())
- .setServiceName(KieConfig.INSTANCE.getServiceName());
+ return new KieConfiguration().setAppName(microserviceProperties.getApplication())
+ .setFirstPullRequired(kieConfig.firstPullRequired())
+ .setCustomLabel(kieConfig.getCustomLabel())
+ .setCustomLabelValue(kieConfig.getCustomLabelValue())
+ .setEnableAppConfig(kieConfig.enableAppConfig())
+ .setEnableCustomConfig(kieConfig.enableCustomConfig())
+ .setEnableLongPolling(kieConfig.enableLongPolling())
+ .setEnableServiceConfig(kieConfig.enableServiceConfig())
+ .setEnableVersionConfig(kieConfig.enableVersionConfig())
+ .setEnvironment(microserviceProperties.getEnvironment())
+ .setVersion(microserviceProperties.getVersion())
+ .setPollingWaitInSeconds(kieConfig.getPollingWaitTime())
+ .setProject(kieConfig.getDomainName())
+ .setRefreshIntervalInMillis(kieConfig.getRefreshInterval())
+ .setServiceName(microserviceProperties.getName());
}
private HttpTransport createHttpTransport(KieAddressManager kieAddressManager, RequestConfig requestConfig,
- Configuration localConfiguration) {
+ Environment environment) {
List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class);
- if (KieConfig.INSTANCE.isProxyEnable()) {
+ if (kieConfig.isProxyEnable()) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().
setDefaultRequestConfig(requestConfig);
- HttpHost proxy = new HttpHost(KieConfig.INSTANCE.getProxyHost(),
- KieConfig.INSTANCE.getProxyPort(), "http"); // now only support http proxy
+ HttpHost proxy = new HttpHost(kieConfig.getProxyHost(),
+ kieConfig.getProxyPort(), "http"); // now only support http proxy
httpClientBuilder.setProxy(proxy);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxy),
- new UsernamePasswordCredentials(KieConfig.INSTANCE.getProxyUsername(),
- KieConfig.INSTANCE.getProxyPasswd()));
+ new UsernamePasswordCredentials(kieConfig.getProxyUsername(),
+ kieConfig.getProxyPasswd()));
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, KieConfig.SSL_TAG),
+ .createSSLProperties(kieAddressManager.sslEnabled(), environment, KieConfig.SSL_TAG),
getRequestAuthHeaderProvider(authHeaderProviders), httpClientBuilder);
}
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, KieConfig.SSL_TAG),
+ .createSSLProperties(kieAddressManager.sslEnabled(), environment, KieConfig.SSL_TAG),
getRequestAuthHeaderProvider(authHeaderProviders), requestConfig);
}
@@ -166,45 +159,17 @@ public class KieConfigurationSourceImpl implements ConfigCenterConfigurationSour
private KieAddressManager configKieAddressManager() {
return new KieAddressManager(
- Arrays.asList(KieConfig.INSTANCE.getServerUri().split(",")), EventManager.getEventBus());
- }
-
- private void updateConfiguration(WatchedUpdateResult result) {
- LOGGER.info("configuration changed keys, added=[{}], updated=[{}], deleted=[{}]",
- result.getAdded() == null ? "" : result.getAdded().keySet(),
- result.getChanged() == null ? "" : result.getChanged().keySet(),
- result.getDeleted() == null ? "" : result.getDeleted().keySet());
-
- for (WatchedUpdateListener l : listeners) {
- try {
- l.updateConfiguration(result);
- } catch (Throwable ex) {
- LOGGER.error("Error in invoking WatchedUpdateListener", ex);
- }
- }
- }
-
- @Override
- public void destroy() {
- if (kieConfigManager == null) {
- return;
- }
- kieConfigManager.stop();
+ Arrays.asList(kieConfig.getServerUri().split(",")), EventManager.getEventBus());
}
@Override
- public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.add(watchedUpdateListener);
+ public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
+ init(environment);
+ return new MapPropertySource(SOURCE_NAME, data);
}
@Override
- public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.remove(watchedUpdateListener);
- }
-
- @Override
- public Map<String, Object> getCurrentData() throws Exception {
- // data will updated by first pull, set empty to DynamicWatchedConfiguration first.
- return Collections.emptyMap();
+ public int getOrder() {
+ return 0;
}
}
diff --git a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/TransportUtils.java b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/TransportUtils.java
index 56afa18ed..8cabafec6 100644
--- a/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/TransportUtils.java
+++ b/dynamic-config/config-kie/src/main/java/org/apache/servicecomb/config/kie/TransportUtils.java
@@ -19,13 +19,13 @@ package org.apache.servicecomb.config.kie;
import static org.apache.servicecomb.foundation.ssl.SSLOption.DEFAULT_OPTION;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.foundation.ssl.SSLCustom;
import org.apache.servicecomb.foundation.ssl.SSLOption;
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
+import org.springframework.core.env.Environment;
public class TransportUtils {
- public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) {
+ public static SSLProperties createSSLProperties(boolean sslEnabled, Environment environment, String tag) {
SSLProperties sslProperties = new SSLProperties();
sslProperties.setEnabled(sslEnabled);
@@ -34,93 +34,93 @@ public class TransportUtils {
}
SSLOption option = new SSLOption();
- option.setEngine(getStringProperty(configuration,
+ option.setEngine(getStringProperty(environment,
DEFAULT_OPTION.getEngine(),
"ssl." + tag + ".engine",
"ssl.engine"));
option.setProtocols(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getProtocols(),
"ssl." + tag + ".protocols",
"ssl.protocols"));
option.setCiphers(
- getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
+ getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
option.setAuthPeer(
- getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
+ getBooleanProperty(environment, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
option.setCheckCNHost(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNHost(),
"ssl." + tag + ".checkCN.host",
"ssl.checkCN.host"));
option.setCheckCNWhite(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNWhite(),
"ssl." + tag + ".checkCN.white",
"ssl.checkCN.white"));
- option.setCheckCNWhiteFile(getStringProperty(configuration,
+ option.setCheckCNWhiteFile(getStringProperty(environment,
DEFAULT_OPTION.getCiphers(),
"ssl." + tag + ".checkCN.white.file",
"ssl.checkCN.white.file"));
- option.setAllowRenegociate(getBooleanProperty(configuration,
+ option.setAllowRenegociate(getBooleanProperty(environment,
DEFAULT_OPTION.isAllowRenegociate(),
"ssl." + tag + ".allowRenegociate",
"ssl.allowRenegociate"));
option.setStorePath(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getStorePath(),
"ssl." + tag + ".storePath",
"ssl.storePath"));
option.setClientAuth(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getClientAuth(),
"ssl." + tag + ".clientAuth",
"ssl.clientAuth"));
option.setTrustStore(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getTrustStore(),
"ssl." + tag + ".trustStore",
"ssl.trustStore"));
- option.setTrustStoreType(getStringProperty(configuration,
+ option.setTrustStoreType(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreType(),
"ssl." + tag + ".trustStoreType",
"ssl.trustStoreType"));
- option.setTrustStoreValue(getStringProperty(configuration,
+ option.setTrustStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreValue(),
"ssl." + tag + ".trustStoreValue",
"ssl.trustStoreValue"));
option.setKeyStore(
- getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
+ getStringProperty(environment, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
option.setKeyStoreType(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreType(),
"ssl." + tag + ".keyStoreType",
"ssl.keyStoreType"));
- option.setKeyStoreValue(getStringProperty(configuration,
+ option.setKeyStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreValue(),
"ssl." + tag + ".keyStoreValue",
"ssl.keyStoreValue"));
- option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
+ option.setCrl(getStringProperty(environment, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
option.setSslCustomClass(
- getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
+ getStringProperty(environment, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
sslProperties.setSslOption(option);
sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
return sslProperties;
}
- private static String getStringProperty(Configuration configuration, String defaultValue, String... keys) {
+ private static String getStringProperty(Environment environment, String defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getString(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key);
}
}
return defaultValue;
}
- private static boolean getBooleanProperty(Configuration configuration, boolean defaultValue, String... keys) {
+ private static boolean getBooleanProperty(Environment environment, boolean defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getBoolean(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key, boolean.class, false);
}
}
return defaultValue;
diff --git a/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
deleted file mode 100644
index 67520d4dc..000000000
--- a/dynamic-config/config-kie/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.config.kie.KieConfigurationSourceImpl
\ No newline at end of file
diff --git a/dynamic-config/config-nacos/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/dynamic-config/config-nacos/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
deleted file mode 100644
index 94965f147..000000000
--- a/dynamic-config/config-nacos/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.config.nacos.archaius.sources.NacosConfigurationSourceImpl
[servicecomb-java-chassis] 03/25: [SCB-2008]change DynamicPropertyFactory to Environment: in edge
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 97c4c7a99497cb0f655a0c1f57bd1539a8a27f01
Author: liubao <bi...@qq.com>
AuthorDate: Thu Sep 21 17:05:24 2023 +0800
[SCB-2008]change DynamicPropertyFactory to Environment: in edge
---
.../servicecomb/core/executor/ExecutorManager.java | 12 ++--
.../edge/core/CommonHttpEdgeDispatcher.java | 16 ++++-
.../edge/core/DefaultEdgeDispatcher.java | 19 ++++--
.../servicecomb/edge/core/EdgeBootListener.java | 26 +++-----
.../edge/core/URLMappedEdgeDispatcher.java | 16 ++++-
.../edge/core/TestEdgeBootListener.java | 77 ----------------------
.../edge/core/TestURLMappedEdgeDispatcher.java | 11 +++-
.../transport/rest/vertx/VertxHttpDispatcher.java | 1 +
8 files changed, 68 insertions(+), 110 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java b/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
index dd4eab35a..557ad73e1 100644
--- a/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
+++ b/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
@@ -31,14 +31,18 @@ public class ExecutorManager {
public static final String KEY_EXECUTORS_DEFAULT = "servicecomb.executors.default";
- public static final String EXECUTOR_GROUP_THREADPOOL = "servicecomb.executor.groupThreadPool";
+ public static final String EXECUTOR_GROUP_THREAD_POOL = "servicecomb.executor.groupThreadPool";
public static final String EXECUTOR_REACTIVE = "servicecomb.executor.reactive";
- public static final String EXECUTOR_DEFAULT = EXECUTOR_GROUP_THREADPOOL;
-
private final Map<String, Executor> executors = new ConcurrentHashMapEx<>();
+ static String EXECUTOR_DEFAULT = EXECUTOR_GROUP_THREAD_POOL;
+
+ public static void setExecutorDefault(String executorDefault) {
+ EXECUTOR_DEFAULT = executorDefault;
+ }
+
private Environment environment;
public ExecutorManager() {
@@ -108,7 +112,7 @@ public class ExecutorManager {
}
protected Executor findByKey(String configKey) {
- String id = environment.getProperty(configKey, String.class);
+ String id = environment.getProperty(configKey);
if (id == null) {
return null;
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
index 2f2d0c021..f131caf28 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
@@ -38,6 +38,8 @@ import org.apache.servicecomb.transport.rest.client.Http2TransportHttpClientOpti
import org.apache.servicecomb.transport.rest.client.HttpTransportHttpClientOptionsSPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.DynamicPropertyFactory;
@@ -74,12 +76,20 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
private Map<String, URLMappedConfigurationItem> configurations = new HashMap<>();
+ private Environment environment;
+
public CommonHttpEdgeDispatcher() {
if (this.enabled()) {
loadConfigurations();
}
}
+ // though this is an SPI, but add as beans.
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
// Maybe future change to beans
protected DiscoveryTree getDiscoveryTree() {
return BeanUtils.getBean(DiscoveryTree.class);
@@ -97,17 +107,17 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
@Override
public int getOrder() {
- return DynamicPropertyFactory.getInstance().getIntProperty(KEY_ORDER, 40_000).get();
+ return environment.getProperty(KEY_ORDER, int.class, 40_000);
}
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
+ return environment.getProperty(KEY_ENABLED, boolean.class, false);
}
@Override
public void init(Router router) {
- String pattern = DynamicPropertyFactory.getInstance().getStringProperty(KEY_PATTERN, PATTERN_ANY).get();
+ String pattern = environment.getProperty(KEY_PATTERN, PATTERN_ANY);
router.routeWithRegex(pattern).failureHandler(this::onFailure).handler(this::onRequest);
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
index b82bd8e6b..9b1333ce9 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/DefaultEdgeDispatcher.java
@@ -23,9 +23,10 @@ import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest;
import org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.DynamicPropertyFactory;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.ext.web.Router;
@@ -48,20 +49,28 @@ public class DefaultEdgeDispatcher extends AbstractEdgeDispatcher {
private int prefixSegmentCount;
+ private Environment environment;
+
+ // though this is an SPI, but add as beans.
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public int getOrder() {
- return DynamicPropertyFactory.getInstance().getIntProperty(KEY_ORDER, 20_000).get();
+ return environment.getProperty(KEY_ORDER, int.class, 20_000);
}
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
+ return environment.getProperty(KEY_ENABLED, boolean.class, false);
}
@Override
public void init(Router router) {
- String prefix = DynamicPropertyFactory.getInstance().getStringProperty(KEY_PREFIX, "api").get();
- prefixSegmentCount = DynamicPropertyFactory.getInstance().getIntProperty(KEY_PREFIX_SEGMENT_COUNT, 1).get();
+ String prefix = environment.getProperty(KEY_PREFIX, "api");
+ prefixSegmentCount = environment.getProperty(KEY_PREFIX_SEGMENT_COUNT, int.class, 1);
String regex = generateRouteRegex(prefix, false);
// cookies handler are enabled by default start from 3.8.3
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeBootListener.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeBootListener.java
index 0d832ec3f..538c83b8b 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeBootListener.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeBootListener.java
@@ -17,18 +17,24 @@
package org.apache.servicecomb.edge.core;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.transport.rest.vertx.TransportConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import com.netflix.config.DynamicPropertyFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
public class EdgeBootListener implements BootListener {
private static final Logger LOGGER = LoggerFactory.getLogger(EdgeBootListener.class);
+ private Environment environment;
+
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public void onBootEvent(BootEvent event) {
if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
@@ -36,18 +42,6 @@ public class EdgeBootListener implements BootListener {
}
TransportConfig.setRestServerVerticle(EdgeRestServerVerticle.class);
-
- String defaultExecutor = DynamicPropertyFactory.getInstance()
- .getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
- .get();
- if (defaultExecutor != null) {
- LOGGER.info("Edge service default executor is {}.", defaultExecutor);
- return;
- }
-
- // change default to reactive mode
- Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
- configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
- LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
+ ExecutorManager.setExecutorDefault(ExecutorManager.EXECUTOR_REACTIVE);
}
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
index 9cd8ac67e..868e12e09 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -29,6 +29,8 @@ import org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpSer
import org.apache.servicecomb.transport.rest.vertx.RestBodyHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
import com.netflix.config.ConcurrentCompositeConfiguration;
@@ -58,7 +60,15 @@ public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
private Map<String, URLMappedConfigurationItem> configurations = new HashMap<>();
+ private Environment environment;
+
public URLMappedEdgeDispatcher() {
+ }
+
+ // though this is an SPI, but add as beans.
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
if (this.enabled()) {
loadConfigurations();
}
@@ -71,18 +81,18 @@ public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
@Override
public int getOrder() {
- return DynamicPropertyFactory.getInstance().getIntProperty(KEY_ORDER, 30_000).get();
+ return environment.getProperty(KEY_ORDER, int.class, 30_000);
}
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_ENABLED, false).get();
+ return environment.getProperty(KEY_ENABLED, boolean.class, false);
}
@Override
public void init(Router router) {
// cookies handler are enabled by default start from 3.8.3
- String pattern = DynamicPropertyFactory.getInstance().getStringProperty(KEY_PATTERN, PATTERN_ANY).get();
+ String pattern = environment.getProperty(KEY_PATTERN, PATTERN_ANY);
router.routeWithRegex(pattern).failureHandler(this::onFailure)
.handler((PlatformHandler) URLMappedEdgeDispatcher.this::preCheck)
.handler(createBodyHandler())
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeBootListener.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeBootListener.java
deleted file mode 100644
index b9341c600..000000000
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestEdgeBootListener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.edge.core;
-
-import org.apache.servicecomb.core.BootListener.BootEvent;
-import org.apache.servicecomb.core.BootListener.EventType;
-import org.apache.servicecomb.core.executor.ExecutorManager;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
-
-import com.netflix.config.DynamicPropertyFactory;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-public class TestEdgeBootListener {
- EdgeBootListener listener = new EdgeBootListener();
-
- BootEvent bootEvent = new BootEvent();
-
- @BeforeEach
- public void setup() {
- ArchaiusUtils.resetConfig();
- }
-
- @AfterEach
- public void teardown() {
- ArchaiusUtils.resetConfig();
- System.clearProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT);
- }
-
- @Test
- public void onBootEvent_ignore() {
- System.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_DEFAULT);
-
- bootEvent.setEventType(EventType.AFTER_CONSUMER_PROVIDER);
- listener.onBootEvent(bootEvent);
-
- Assertions.assertEquals(ExecutorManager.EXECUTOR_DEFAULT,
- DynamicPropertyFactory.getInstance().getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null).get());
- }
-
- @Test
- public void onBootEvent_accept_notChange() {
- System.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_DEFAULT);
-
- bootEvent.setEventType(EventType.BEFORE_PRODUCER_PROVIDER);
- listener.onBootEvent(bootEvent);
-
- Assertions.assertEquals(ExecutorManager.EXECUTOR_DEFAULT,
- DynamicPropertyFactory.getInstance().getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null).get());
- }
-
- @Test
- public void onBootEvent_change() {
- bootEvent.setEventType(EventType.BEFORE_PRODUCER_PROVIDER);
- listener.onBootEvent(bootEvent);
-
- Assertions.assertEquals(ExecutorManager.EXECUTOR_REACTIVE,
- DynamicPropertyFactory.getInstance().getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null).get());
- }
-}
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
index db0064c2a..805374bd9 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestURLMappedEdgeDispatcher.java
@@ -26,12 +26,18 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
+
+import com.netflix.config.DynamicPropertyFactory;
import io.vertx.ext.web.RoutingContext;
public class TestURLMappedEdgeDispatcher {
+ Environment environment = Mockito.mock(Environment.class);
+
@BeforeEach
public void setUp() throws Exception {
+ DynamicPropertyFactory.getInstance();
}
@AfterEach
@@ -41,9 +47,10 @@ public class TestURLMappedEdgeDispatcher {
@Test
public void testConfigurations() {
- ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.enabled", true);
-
+ Mockito.when(environment.getProperty("servicecomb.http.dispatcher.edge.url.enabled", boolean.class, false))
+ .thenReturn(true);
URLMappedEdgeDispatcher dispatcher = new URLMappedEdgeDispatcher();
+ dispatcher.setEnvironment(environment);
Map<String, URLMappedConfigurationItem> items = dispatcher.getConfigurations();
Assertions.assertEquals(items.size(), 0);
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxHttpDispatcher.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxHttpDispatcher.java
index cb96d8c22..373d63094 100644
--- a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxHttpDispatcher.java
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxHttpDispatcher.java
@@ -22,6 +22,7 @@ import org.apache.servicecomb.foundation.common.utils.SPIOrder;
import io.vertx.ext.web.Router;
+// TODO: use spring beans.
public interface VertxHttpDispatcher extends SPIOrder, SPIEnabled {
@Override
default boolean enabled() {
[servicecomb-java-chassis] 19/25: [SCB-2008]remove ConfigUtil methods
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit d9a431d0859a00e60d22351e2d05874074326db8
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 17:48:46 2023 +0800
[SCB-2008]remove ConfigUtil methods
---
.../rest/definition/TestRestOperationMeta.java | 2 -
.../filter/inner/RestServerCodecFilterTest.java | 3 -
.../rest/locator/TestServicePathManager.java | 3 +-
.../org/apache/servicecomb/core/SCBEngine.java | 4 +-
.../core/TestConfigurationSpringInitializer.java | 5 +-
.../core/TestSCBApplicationListener.java | 2 -
.../producer/TestProducerBootListener.java | 68 +-----
.../servicecomb/config/apollo/ApolloClient.java | 38 +--
.../servicecomb/config/apollo/ApolloConfig.java | 33 +--
.../config/apollo/ApolloConfiguration.java | 6 +
.../apollo/ApolloDynamicPropertiesSource.java | 10 +-
.../config/apollo/ApolloClientTest.java | 8 +-
.../config/apollo/ApolloConfigTest.java | 44 ----
.../config/nacos/NacosDynamicPropertiesSource.java | 3 +-
.../org/apache/servicecomb/config/ConfigUtil.java | 255 ---------------------
.../spi/ConfigCenterConfigurationSource.java | 35 ---
.../spi/ConfigCenterConfigurationSourceLoader.java | 42 ----
.../config/MapBasedConfigurationSource.java | 103 ---------
.../priority/TestPriorityPropertyManager.java | 7 -
...comb.config.spi.ConfigCenterConfigurationSource | 18 --
.../registry/discovery/TestDiscoveryTree.java | 3 +-
.../servicecomb/loadbalance/TestConfiguration.java | 23 --
.../loadbalance/TestLoadBalanceFilter.java | 2 -
.../monitor/DefaultMonitorDataPublisher.java | 9 +-
.../dashboard/monitor/TransportUtils.java | 51 +++--
25 files changed, 87 insertions(+), 690 deletions(-)
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
index 86662b3a2..b9fc9372a 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
@@ -27,7 +27,6 @@ import java.util.Arrays;
import java.util.List;
import org.apache.servicecomb.common.rest.RestEngineSchemaListener;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
@@ -167,7 +166,6 @@ public class TestRestOperationMeta {
@BeforeAll
public static void classSetup() {
- ConfigUtil.installDynamicConfig();
scbEngine = SCBBootstrap.createSCBEngineForTest();
ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
TransportManager transportManager = Mockito.mock(TransportManager.class);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
index 8ac941cd8..8da1fa350 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
@@ -29,7 +29,6 @@ import java.util.concurrent.ExecutionException;
import org.apache.servicecomb.common.rest.HttpTransportContext;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
@@ -98,8 +97,6 @@ public class RestServerCodecFilterTest {
@BeforeAll
public static void beforeClass() {
- ConfigUtil.installDynamicConfig();
-
engine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
engine.setEnvironment(environment);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
index f7843353e..47b3ecb53 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.servicecomb.common.rest.RestEngineSchemaListener;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
@@ -55,7 +54,7 @@ public class TestServicePathManager {
@BeforeEach
public void setUp() {
- ConfigUtil.installDynamicConfig();
+
}
@AfterEach
diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index 4b04addf2..d74399002 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.config.priority.PriorityPropertyManager;
import org.apache.servicecomb.core.BootListener.BootEvent;
@@ -463,8 +462,7 @@ public class SCBEngine {
LOGGER.error("wait all invocation finished interrupted", e);
}
- //Step 5: destroy config center source
- ConfigUtil.destroyConfigCenterConfigurationSource();
+ //Step 5: destroy config source
// only be null for some test cases
if (priorityPropertyManager != null) {
priorityPropertyManager.close();
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
index a5fbd6f2c..27b38f601 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
@@ -21,7 +21,6 @@ import java.util.Map;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
-import org.apache.servicecomb.config.ConfigUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -40,14 +39,12 @@ public class TestConfigurationSpringInitializer {
public void beforeTest() {
Configurator.setRootLevel(Level.OFF);
- ConfigUtil.clearExtraConfig();
-
Configurator.setRootLevel(Level.INFO);
}
@AfterEach
public void afterTest() {
- ConfigUtil.clearExtraConfig();
+
}
@Test
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
index 37eebd201..c6aad1f9d 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBApplicationListener.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.core;
import static org.apache.servicecomb.core.SCBEngine.CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC;
import static org.apache.servicecomb.core.SCBEngine.DEFAULT_TURN_DOWN_STATUS_WAIT_SEC;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -32,7 +31,6 @@ import org.springframework.core.env.Environment;
public class TestSCBApplicationListener {
@BeforeEach
public void before() {
- ConfigUtil.installDynamicConfig();
}
@AfterAll
diff --git a/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerBootListener.java b/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerBootListener.java
index edecc74ef..e327759ef 100644
--- a/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerBootListener.java
+++ b/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerBootListener.java
@@ -17,26 +17,18 @@
package org.apache.servicecomb.core.provider.producer;
-import java.io.Closeable;
import java.util.Arrays;
import java.util.concurrent.Executor;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
import org.apache.servicecomb.core.BootListener.BootEvent;
import org.apache.servicecomb.core.BootListener.EventType;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.core.executor.GroupExecutor;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
-import org.junit.Test;
-
-import mockit.Expectations;
-import mockit.Mock;
-import mockit.MockUp;
-import mockit.Mocked;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
public class TestProducerBootListener {
ProducerBootListener producerBootListener = new ProducerBootListener();
@@ -51,57 +43,15 @@ public class TestProducerBootListener {
}
@Test
- public void onBootEvent_close(@Mocked SCBEngine scbEngine, @Mocked MicroserviceMeta microserviceMeta,
- @Mocked OperationMeta op1,
- @Mocked OperationMeta op2, @Mocked GroupExecutor closeable) {
- AtomicInteger count = new AtomicInteger();
- ExecutorService executorService = new MockUp<ExecutorService>() {
- @Mock
- void shutdown() {
- count.incrementAndGet();
- }
- }.getMockInstance();
- new MockUp<Closeable>(closeable) {
- @Mock
- void close() {
- count.incrementAndGet();
- }
- };
- new Expectations() {
- {
- scbEngine.getProducerMicroserviceMeta();
- result = microserviceMeta;
- microserviceMeta.getOperations();
- result = Arrays.asList(op1, op2);
- op1.getExecutor();
- result = executorService;
- op2.getExecutor();
- result = closeable;
- }
- };
- BootEvent event = new BootEvent();
- event.setScbEngine(scbEngine);
- event.setEventType(EventType.AFTER_CLOSE);
-
- producerBootListener.onBootEvent(event);
+ public void onBootEvent_close_unknown() {
+ SCBEngine scbEngine = Mockito.mock(SCBEngine.class);
+ MicroserviceMeta microserviceMeta = Mockito.mock(MicroserviceMeta.class);
+ OperationMeta op = Mockito.mock(OperationMeta.class);
- Assertions.assertEquals(2, count.get());
- }
-
- @Test
- public void onBootEvent_close_unknown(@Mocked SCBEngine scbEngine, @Mocked MicroserviceMeta microserviceMeta,
- @Mocked OperationMeta op1) {
Executor executor = new UnCloseableExecutor();
- new Expectations() {
- {
- scbEngine.getProducerMicroserviceMeta();
- result = microserviceMeta;
- microserviceMeta.getOperations();
- result = Arrays.asList(op1);
- op1.getExecutor();
- result = executor;
- }
- };
+ Mockito.when(scbEngine.getProducerMicroserviceMeta()).thenReturn(microserviceMeta);
+ Mockito.when(microserviceMeta.getOperations()).thenReturn(Arrays.asList(op));
+ Mockito.when(op.getExecutor()).thenReturn(executor);
try (LogCollector logCollector = new LogCollector()) {
BootEvent event = new BootEvent();
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
index acd4a4dff..4fe0cc92b 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
@@ -29,7 +29,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import com.google.common.annotations.VisibleForTesting;
import org.apache.servicecomb.config.apollo.ApolloDynamicPropertiesSource.UpdateHandler;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.slf4j.Logger;
@@ -41,6 +40,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.common.annotations.VisibleForTesting;
import io.netty.handler.codec.http.HttpResponseStatus;
@@ -48,34 +48,19 @@ public class ApolloClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ApolloClient.class);
- private static final ApolloConfig APOLLO_CONFIG = ApolloConfig.INSTANCE;
-
private static final Map<String, Object> originalConfigMap = new ConcurrentHashMap<>();
private static final ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(1);
- private final int refreshInterval = APOLLO_CONFIG.getRefreshInterval();
-
- private final int firstRefreshInterval = APOLLO_CONFIG.getFirstRefreshInterval();
-
- private final String serviceUri = APOLLO_CONFIG.getServerUri();
-
- private final String serviceName = APOLLO_CONFIG.getServiceName();
-
- private final String token = APOLLO_CONFIG.getToken();
-
- private final String env = APOLLO_CONFIG.getEnv();
-
- private final String clusters = APOLLO_CONFIG.getServerClusters();
-
- private final String namespace = APOLLO_CONFIG.getNamespace();
+ private final ApolloConfig apolloConfig;
private final UpdateHandler updateHandler;
private static RestTemplate rest = new RestTemplate();
- public ApolloClient(UpdateHandler updateHandler) {
+ public ApolloClient(UpdateHandler updateHandler, ApolloConfig apolloConfig) {
this.updateHandler = updateHandler;
+ this.apolloConfig = apolloConfig;
}
@VisibleForTesting
@@ -89,8 +74,9 @@ public class ApolloClient {
}
public void refreshApolloConfig() {
- EXECUTOR
- .scheduleWithFixedDelay(new ConfigRefresh(serviceUri), firstRefreshInterval, refreshInterval, TimeUnit.SECONDS);
+ EXECUTOR.scheduleWithFixedDelay(new ConfigRefresh(apolloConfig.getServerUri()),
+ apolloConfig.getFirstRefreshInterval(),
+ apolloConfig.getRefreshInterval(), TimeUnit.SECONDS);
}
class ConfigRefresh implements Runnable {
@@ -113,7 +99,7 @@ public class ApolloClient {
void refreshConfig() {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json;charset=UTF-8");
- headers.add("Authorization", token);
+ headers.add("Authorization", apolloConfig.getToken());
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> exchange = rest.exchange(composeAPI(), HttpMethod.GET, entity, String.class);
if (HttpResponseStatus.OK.code() == exchange.getStatusCode().value()) {
@@ -133,10 +119,10 @@ public class ApolloClient {
}
private String composeAPI() {
- String api = serviceUri + "/openapi/v1/envs/" + env +
- "/apps/" + serviceName +
- "/clusters/" + clusters +
- "/namespaces/" + namespace +
+ String api = serviceUri + "/openapi/v1/envs/" + apolloConfig.getEnv() +
+ "/apps/" + apolloConfig.getServiceName() +
+ "/clusters/" + apolloConfig.getServerClusters() +
+ "/namespaces/" + apolloConfig.getNamespace() +
"/releases/latest";
return api;
}
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
index 605912e36..97509b9ee 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
@@ -17,13 +17,9 @@
package org.apache.servicecomb.config.apollo;
-import org.apache.commons.configuration.Configuration;
+import org.springframework.core.env.Environment;
public class ApolloConfig {
- public static final ApolloConfig INSTANCE = new ApolloConfig();
-
- private static Configuration finalConfig;
-
private static final String SERVER_URL_KEY = "apollo.config.serverUri";
private static final String SERVER_NAMESPACE = "apollo.config.namespace";
@@ -44,46 +40,41 @@ public class ApolloConfig {
private static final int DEFAULT_FIRST_REFRESH_INTERVAL = 0;
- private ApolloConfig() {
- }
-
- public static void setConcurrentCompositeConfiguration(Configuration config) {
- finalConfig = config;
- }
+ private final Environment environment;
- public Configuration getConcurrentCompositeConfiguration() {
- return finalConfig;
+ public ApolloConfig(Environment environment) {
+ this.environment = environment;
}
public String getServiceName() {
- return finalConfig.getString(APOLLO_SERVICE_NAME);
+ return environment.getProperty(APOLLO_SERVICE_NAME);
}
public String getServerUri() {
- return finalConfig.getString(SERVER_URL_KEY);
+ return environment.getProperty(SERVER_URL_KEY);
}
public String getToken() {
- return finalConfig.getString(TOKEN);
+ return environment.getProperty(TOKEN);
}
public String getEnv() {
- return finalConfig.getString(SERVER_ENV);
+ return environment.getProperty(SERVER_ENV);
}
public String getNamespace() {
- return finalConfig.getString(SERVER_NAMESPACE);
+ return environment.getProperty(SERVER_NAMESPACE);
}
public String getServerClusters() {
- return finalConfig.getString(SERVER_CLUSTERS);
+ return environment.getProperty(SERVER_CLUSTERS);
}
public int getRefreshInterval() {
- return finalConfig.getInt(REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL);
+ return environment.getProperty(REFRESH_INTERVAL, int.class, DEFAULT_REFRESH_INTERVAL);
}
public int getFirstRefreshInterval() {
- return finalConfig.getInt(FIRST_REFRESH_INTERVAL, DEFAULT_FIRST_REFRESH_INTERVAL);
+ return environment.getProperty(FIRST_REFRESH_INTERVAL, int.class, DEFAULT_FIRST_REFRESH_INTERVAL);
}
}
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java
index 26dd7a2ee..ac500eafc 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.servicecomb.config.apollo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
@Configuration
public class ApolloConfiguration {
@@ -25,4 +26,9 @@ public class ApolloConfiguration {
public ApolloDynamicPropertiesSource apolloDynamicPropertiesSource() {
return new ApolloDynamicPropertiesSource();
}
+
+ @Bean
+ public ApolloConfig apolloConfig(Environment environment) {
+ return new ApolloConfig(environment);
+ }
}
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
index 01dc1a434..56dd7ed39 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
@@ -27,6 +27,7 @@ import org.apache.servicecomb.config.ConfigMapping;
import org.apache.servicecomb.config.DynamicPropertiesSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
@@ -41,13 +42,20 @@ public class ApolloDynamicPropertiesSource implements DynamicPropertiesSource<Ma
private final ApolloDynamicPropertiesSource.UpdateHandler updateHandler =
new ApolloDynamicPropertiesSource.UpdateHandler();
+ private ApolloConfig apolloConfig;
+
+ @Autowired
+ public void setApolloConfig(ApolloConfig apolloConfig) {
+ this.apolloConfig = apolloConfig;
+ }
+
@Override
public int getOrder() {
return 300;
}
private void init() {
- ApolloClient apolloClient = new ApolloClient(updateHandler);
+ ApolloClient apolloClient = new ApolloClient(updateHandler, apolloConfig);
apolloClient.refreshApolloConfig();
}
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
index c284a1fbf..77a074e4f 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
@@ -38,12 +38,11 @@ public class ApolloClientTest {
@BeforeAll
public static void setUpClass() {
- ApolloConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
}
@Test
public void refreshApolloConfig() {
- ApolloConfig apolloConfig = ApolloConfig.INSTANCE;
+ ApolloConfig apolloConfig = Mockito.mock(ApolloConfig.class);
RestTemplate rest = Mockito.mock(RestTemplate.class);
ApolloClient.setRest(rest);
@@ -56,7 +55,7 @@ public class ApolloClientTest {
ArgumentMatchers.<Class<String>>any())).thenReturn(responseEntity);
ApolloDynamicPropertiesSource impl = new ApolloDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
- ApolloClient apolloClient = new ApolloClient(updateHandler);
+ ApolloClient apolloClient = new ApolloClient(updateHandler, apolloConfig);
ConfigRefresh cr = apolloClient.new ConfigRefresh(apolloConfig.getServerUri());
cr.run();
@@ -65,13 +64,14 @@ public class ApolloClientTest {
@Test
public void testCompareChangedConfig() {
+ ApolloConfig apolloConfig = Mockito.mock(ApolloConfig.class);
boolean status = true;
Map<String, Object> before = new HashMap<>();
Map<String, Object> after = new HashMap<>();
ApolloDynamicPropertiesSource impl = new ApolloDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
- ApolloClient apolloClient = new ApolloClient(updateHandler);
+ ApolloClient apolloClient = new ApolloClient(updateHandler, apolloConfig);
ConfigRefresh cr = apolloClient.new ConfigRefresh("");
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java
deleted file mode 100644
index 01a550609..000000000
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.apollo;
-
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.apollo.ApolloConfig;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class ApolloConfigTest {
- @BeforeAll
- public static void setUpClass() {
- ApolloConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- }
-
- @Test
- public void getServiceName() {
- ApolloConfig instance = ApolloConfig.INSTANCE;
- Assertions.assertEquals("apollo-test", instance.getServiceName());
- Assertions.assertEquals("http://127.0.0.1:8070", instance.getServerUri());
- Assertions.assertEquals("DEV", instance.getEnv());
- Assertions.assertEquals("test-cluster", instance.getServerClusters());
- Assertions.assertEquals("application", instance.getNamespace());
- Assertions.assertEquals("xxx", instance.getToken());
- Assertions.assertEquals(30, instance.getRefreshInterval());
- Assertions.assertEquals(0, instance.getFirstRefreshInterval());
- }
-}
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
index 134a4e035..4b39760a9 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
@@ -27,7 +27,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.servicecomb.config.ConfigMapping;
import org.apache.servicecomb.config.DynamicPropertiesSource;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.EnumerablePropertySource;
@@ -40,7 +39,7 @@ import com.netflix.config.WatchedUpdateListener;
public class NacosDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
public static final String SOURCE_NAME = "kie";
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSource.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(NacosDynamicPropertiesSource.class);
private final Map<String, Object> valueCache = new ConcurrentHashMap<>();
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index 11c002c3e..4259badfc 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -17,279 +17,24 @@
package org.apache.servicecomb.config;
-import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER;
-
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import javax.annotation.Nonnull;
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.configuration.PropertyConverter;
-import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.commons.lang.reflect.FieldUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler;
-import org.apache.servicecomb.config.archaius.sources.ConfigModel;
-import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
-import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigurationSource;
-import org.apache.servicecomb.config.event.DynamicConfigurationChangedEvent;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSourceLoader;
-import org.apache.servicecomb.foundation.common.event.EventManager;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.ConcurrentMapConfiguration;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicProperty;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
public final class ConfigUtil {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
-
- private static final String IS_PRINT_URL = "servicecomb.config.log.verbose";
-
- private static Map<String, Object> localConfig = new HashMap<>();
-
- /**
- * <p>The configurations not read by ServiceComb.</p>
- * <p>
- * For example, this map can store the configurations read by SpringBoot from application.properties,
- * If users write the configurations of ServiceComb into application.yml instead of microservice.yaml,
- * this can help {@link ConfigUtil} load config correctly.
- * </p>
- */
- private static final Map<String, Map<String, Object>> EXTRA_CONFIG_MAP = new LinkedHashMap<>();
-
private ConfigUtil() {
}
- public static void setConfigs(Map<String, Object> config) {
- localConfig = config;
- }
-
- public static void addConfig(String key, Object value) {
- localConfig.put(key, value);
- }
-
- public static Object getProperty(String key) {
- AbstractConfiguration config = ConfigurationManager.getConfigInstance();
- return getProperty(config, key);
- }
-
- public static Object getProperty(Object config, String key) {
- if (config instanceof Configuration) {
- Configuration configuration = (Configuration) config;
- return configuration.getProperty(key);
- }
- return null;
- }
-
- /**
- * get comma separated list values from yaml string
- */
- public static List<String> getStringList(@Nonnull Configuration config, @Nonnull String key) {
- return parseArrayValue(config.getString(key)).stream()
- .map(v -> Objects.toString(v, null))
- .collect(Collectors.toList());
- }
-
public static List<String> parseArrayValue(String value) {
return PropertyConverter.split(value, ',', true);
}
- public static ConcurrentCompositeConfiguration createLocalConfig() {
- MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
- loader.loadAndSort();
- if (localConfig.size() > 0) {
- ConfigModel model = new ConfigModel();
- model.setConfig(localConfig);
- loader.getConfigModels().add(model);
- }
-
- boolean isPrintUrl = DynamicPropertyFactory.getInstance()
- .getBooleanProperty(IS_PRINT_URL, true).get();
- if (isPrintUrl) {
- LOGGER.info("create local config from paths=[{}]", StringUtils.join(loader.getConfigModels(), ","));
- }
-
- ConcurrentCompositeConfiguration config = ConfigUtil.createLocalConfig(loader.getConfigModels());
- return config;
- }
-
- private static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
- ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
-
- duplicateCseConfigToServicecomb(config,
- new ConcurrentMapConfigurationExt(new SystemConfiguration()),
- "configFromSystem");
- duplicateCseConfigToServicecomb(config,
- convertEnvVariable(new ConcurrentMapConfigurationExt(new EnvironmentConfiguration())),
- "configFromEnvironment");
- // If there is extra configurations, add it into config.
- EXTRA_CONFIG_MAP.entrySet()
- .stream()
- .filter(mapEntry -> !mapEntry.getValue().isEmpty())
- .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config,
- new ConcurrentMapConfigurationExt(configMapEntry.getValue()),
- configMapEntry.getKey()));
- // we have already copy the cse config to the serviceComb config when we load the config from local yaml files
- // hence, we do not need duplicate copy it.
- config.addConfiguration(new DynamicConfigurationExt(
- new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()),
- "configFromYamlFile");
- duplicateCseConfigToServicecombAtFront(config,
- new ConcurrentMapConfigurationExt(ConfigMapping.getConvertedMap(config)),
- "configFromMapping");
- return config;
- }
-
- public static AbstractConfiguration convertEnvVariable(AbstractConfiguration source) {
- Iterator<String> keys = source.getKeys();
- while (keys.hasNext()) {
- String key = keys.next();
- String[] separatedKey = key.split(CONFIG_KEY_SPLITER);
- if (separatedKey.length == 1) {
- continue;
- }
- String newKey = String.join(".", separatedKey);
- source.addProperty(newKey, source.getProperty(key));
- }
- return source;
- }
-
- private static void duplicateCseConfigToServicecomb(ConcurrentCompositeConfiguration compositeConfiguration,
- AbstractConfiguration source,
- String sourceName) {
-
- compositeConfiguration.addConfiguration(source, sourceName);
- }
-
- private static void duplicateCseConfigToServicecombAtFront(ConcurrentCompositeConfiguration compositeConfiguration,
- AbstractConfiguration source,
- String sourceName) {
-
- compositeConfiguration.addConfigurationAtFront(source, sourceName);
- }
-
- private static ConfigCenterConfigurationSource createConfigCenterConfigurationSource(
- Configuration localConfiguration) {
- ConfigCenterConfigurationSource configCenterConfigurationSource = ConfigCenterConfigurationSourceLoader
- .getConfigCenterConfigurationSource(localConfiguration);
-
- if (null == configCenterConfigurationSource) {
- LOGGER.info("none of config center source enabled.");
- return null;
- }
-
- LOGGER.info("use config center source {}", configCenterConfigurationSource.getClass().getName());
- return configCenterConfigurationSource;
- }
-
- private static void createDynamicWatchedConfiguration(
- ConcurrentCompositeConfiguration localConfiguration,
- ConfigCenterConfigurationSource configCenterConfigurationSource) {
- ConcurrentMapConfiguration injectConfig = new ConcurrentMapConfigurationExt();
- localConfiguration.addConfigurationAtFront(injectConfig, "extraInjectConfig");
- configCenterConfigurationSource.addUpdateListener(new ServiceCombPropertyUpdateListener(injectConfig));
-
- DynamicWatchedConfigurationExt configFromConfigCenter =
- new DynamicWatchedConfigurationExt(configCenterConfigurationSource);
- localConfiguration.addConfigurationAtFront(configFromConfigCenter, "configCenterConfig");
- }
-
- public static ConfigCenterConfigurationSource installDynamicConfig() {
- if (ConfigurationManager.isConfigurationInstalled()) {
- LOGGER.warn("Configuration installed by others, will ignore this configuration.");
- return null;
- }
-
- ConcurrentCompositeConfiguration compositeConfig = ConfigUtil.createLocalConfig();
- ConfigCenterConfigurationSource configCenterConfigurationSource =
- createConfigCenterConfigurationSource(compositeConfig);
- if (configCenterConfigurationSource != null) {
- // add listeners
- createDynamicWatchedConfiguration(compositeConfig, configCenterConfigurationSource);
- // then init data
- configCenterConfigurationSource.init(compositeConfig);
- }
-
- ConfigurationManager.install(compositeConfig);
-
- return configCenterConfigurationSource;
- }
-
- public static void destroyConfigCenterConfigurationSource() {
- SPIServiceUtils.getAllService(ConfigCenterConfigurationSource.class).forEach(source -> {
- try {
- source.destroy();
- } catch (Throwable e) {
- LOGGER.error("Failed to destroy {}", source.getClass().getName());
- }
- });
- }
-
- public static void addExtraConfig(String extraConfigName, Map<String, Object> extraConfig) {
- EXTRA_CONFIG_MAP.put(extraConfigName, extraConfig);
- }
-
- public static void clearExtraConfig() {
- EXTRA_CONFIG_MAP.clear();
- }
-
- private static class ServiceCombPropertyUpdateListener implements WatchedUpdateListener {
-
- private final ConcurrentMapConfiguration injectConfig;
-
- ServiceCombPropertyUpdateListener(ConcurrentMapConfiguration injectConfig) {
- this.injectConfig = injectConfig;
- }
-
- @Override
- public void updateConfiguration(WatchedUpdateResult watchedUpdateResult) {
- EventManager.post(new DynamicConfigurationChangedEvent(watchedUpdateResult));
- }
- }
-
- @SuppressWarnings("unchecked")
- public static ConcurrentHashMap<String, DynamicProperty> getAllDynamicProperties() {
- try {
- return (ConcurrentHashMap<String, DynamicProperty>) FieldUtils
- .readDeclaredStaticField(DynamicProperty.class, "ALL_PROPS", true);
- } catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- public static CopyOnWriteArraySet<Runnable> getCallbacks(DynamicProperty property) {
- try {
- return (CopyOnWriteArraySet<Runnable>) FieldUtils.readDeclaredField(property, "callbacks", true);
- } catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
- }
- }
-
public static Set<String> propertiesWithPrefix(Environment environment, String prefix) {
Set<String> result = new HashSet<>();
for (PropertySource<?> propertySource : ((ConfigurableEnvironment) environment).getPropertySources()) {
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
deleted file mode 100644
index 604e7f8b3..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.spi;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.foundation.common.utils.SPIOrder;
-
-import com.netflix.config.WatchedConfigurationSource;
-
-public interface ConfigCenterConfigurationSource extends WatchedConfigurationSource, SPIOrder {
- int ORDER_BASE = 100;
-
- boolean isValidSource(Configuration localConfiguration);
-
- void init(Configuration localConfiguration);
-
- default void destroy() {
-
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSourceLoader.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSourceLoader.java
deleted file mode 100644
index 2e5760e36..000000000
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/spi/ConfigCenterConfigurationSourceLoader.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.spi;
-
-import java.util.List;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-
-public class ConfigCenterConfigurationSourceLoader {
- private static final List<ConfigCenterConfigurationSource> configCenterConfigurationSources =
- SPIServiceUtils.getSortedService(ConfigCenterConfigurationSource.class);
-
- public static ConfigCenterConfigurationSource getConfigCenterConfigurationSource(Configuration localConfiguration) {
-
- ConfigCenterConfigurationSource configCenterConfigurationSource = null;
-
- for (ConfigCenterConfigurationSource item : configCenterConfigurationSources) {
- if (item.isValidSource(localConfiguration)) {
- configCenterConfigurationSource = item;
- break;
- }
- }
-
- return configCenterConfigurationSource;
- }
-}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
deleted file mode 100644
index 5f08c8a89..000000000
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/MapBasedConfigurationSource.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
-
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-public class MapBasedConfigurationSource implements ConfigCenterConfigurationSource {
-
- private static final Map<String, Object> properties = new ConcurrentHashMap<>();
-
- private static final Set<WatchedUpdateListener> listeners = new HashSet<>();
-
- static {
- properties.put("servicecomb.abc.key", "xyz");
- }
-
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- if (localConfiguration.getProperty("cse.config.client.serverUri") == null) {
- return false;
- }
- return true;
- }
-
- @Override
- public void init(Configuration localConfiguration) {
-
- }
-
- @Override
- public void addUpdateListener(WatchedUpdateListener listener) {
- listeners.add(listener);
- }
-
- @Override
- public void removeUpdateListener(WatchedUpdateListener listener) {
- listeners.remove(listener);
- }
-
- @Override
- public Map<String, Object> getCurrentData() throws Exception {
- return properties;
- }
-
- void addProperty(String property, Object value) {
- properties.put(property, value);
-
- Map<String, Object> adds = new HashMap<>();
- adds.put(property, value);
-
- listeners.forEach(
- listener -> listener.updateConfiguration(WatchedUpdateResult.createIncremental(adds, null, null)));
- }
-
- void setProperty(String property, Object value) {
- properties.replace(property, value);
-
- Map<String, Object> changeds = new HashMap<>();
- changeds.put(property, value);
-
- listeners.forEach(listener -> listener
- .updateConfiguration(WatchedUpdateResult.createIncremental(null, changeds, null)));
- }
-
- void deleteProperty(String property) {
- properties.remove(property);
-
- Map<String, Object> deletes = new HashMap<>();
- deletes.put(property, null);
-
- listeners.forEach(
- listener -> listener.updateConfiguration(WatchedUpdateResult.createIncremental(null, null, deletes)));
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
index 15e223b3e..291d86145 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
@@ -17,14 +17,11 @@
package org.apache.servicecomb.config.priority;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.inject.InjectProperties;
import org.apache.servicecomb.config.inject.InjectProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import com.netflix.config.DynamicProperty;
-
public class TestPriorityPropertyManager extends TestPriorityPropertyBase {
String high = "ms.schema.op";
@@ -75,10 +72,6 @@ public class TestPriorityPropertyManager extends TestPriorityPropertyBase {
waitKeyForGC(priorityPropertyManager);
Assertions.assertTrue(priorityPropertyManager.getConfigObjectMap().isEmpty());
- for (DynamicProperty property : ConfigUtil.getAllDynamicProperties().values()) {
- Assertions.assertTrue(ConfigUtil.getCallbacks(property).isEmpty());
- }
-
System.out.println("Token : " + (System.currentTimeMillis() - timeBegin));
}
}
diff --git a/foundations/foundation-config/src/test/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/foundations/foundation-config/src/test/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
deleted file mode 100644
index 54abbb2ca..000000000
--- a/foundations/foundation-config/src/test/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.config.MapBasedConfigurationSource
\ No newline at end of file
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
index 1d161792c..a30b892f8 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
@@ -24,7 +24,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.registry.DiscoveryManager;
@@ -44,7 +43,7 @@ public class TestDiscoveryTree {
@BeforeEach
public void before() {
- ConfigUtil.installDynamicConfig();
+
}
@AfterEach
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestConfiguration.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestConfiguration.java
index ff505fc99..81f24cd8b 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestConfiguration.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestConfiguration.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.loadbalance;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.After;
import org.junit.Before;
@@ -26,8 +25,6 @@ import org.junit.jupiter.api.Assertions;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-
/**
*
*/
@@ -70,26 +67,6 @@ public class TestConfiguration {
Assertions.assertNotNull(Configuration.INSTANCE.getSessionTimeoutInSeconds("test"));
}
-
- /**
- * The property key of timerIntervalInMilis changed from <code>servicecomb.loadbalance.stats.timerIntervalInMilis</code>
- * to <code>servicecomb.loadbalance.stats.timerIntervalInMillis</code>, check the compatibility
- */
- @Test
- public void testGetTimerIntervalInMillis() {
- System.setProperty(Configuration.TIMER_INTERVAL_IN_MILLIS, "100");
- ConcurrentCompositeConfiguration localConfiguration = ConfigUtil.createLocalConfig();
- Assertions.assertEquals("100", localConfiguration.getProperty(Configuration.TIMER_INTERVAL_IN_MILLIS));
-
- System.clearProperty(Configuration.TIMER_INTERVAL_IN_MILLIS);
- localConfiguration = ConfigUtil.createLocalConfig();
- Assertions.assertNull(localConfiguration.getProperty(Configuration.TIMER_INTERVAL_IN_MILLIS));
-
- System.setProperty("servicecomb.loadbalance.stats.timerIntervalInMilis", "100");
- localConfiguration = ConfigUtil.createLocalConfig();
- Assertions.assertEquals("100", localConfiguration.getProperty(Configuration.TIMER_INTERVAL_IN_MILLIS));
- }
-
@Test
public void testGetMaxSingleTestWindow() {
Assertions.assertEquals(60000, Configuration.INSTANCE.getMaxSingleTestWindow());
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
index bdc657b81..a03c0e4dd 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceFilter.java
@@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.Transport;
@@ -74,7 +73,6 @@ public class TestLoadBalanceFilter {
@Before
public void setUp() {
- ConfigUtil.installDynamicConfig();
scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
scbEngine.setEnvironment(environment);
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
index 330bd0d09..cd7d2fc10 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -72,7 +71,7 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
requestBuilder.setSocketTimeout(10000);
HttpTransport httpTransport = createHttpTransport(addressManager, requestBuilder.build(),
- ConfigUtil.createLocalConfig());
+ environment);
dashboardClient = new DashboardClient(addressManager, httpTransport);
}
@@ -90,7 +89,7 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
}
private HttpTransport createHttpTransport(DashboardAddressManager addressManager, RequestConfig requestConfig,
- Configuration localConfiguration) {
+ Environment environment) {
List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class);
if (monitorConstant.isProxyEnable()) {
@@ -108,14 +107,14 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(addressManager.sslEnabled(), localConfiguration, SSL_KEY),
+ .createSSLProperties(addressManager.sslEnabled(), environment, SSL_KEY),
getRequestAuthHeaderProvider(authHeaderProviders), httpClientBuilder);
}
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(monitorConstant.sslEnabled(), localConfiguration, SSL_KEY),
+ .createSSLProperties(monitorConstant.sslEnabled(), environment, SSL_KEY),
getRequestAuthHeaderProvider(authHeaderProviders), requestConfig);
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
index 0f49400fe..ed2aaec26 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/TransportUtils.java
@@ -23,9 +23,10 @@ import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.foundation.ssl.SSLCustom;
import org.apache.servicecomb.foundation.ssl.SSLOption;
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
+import org.springframework.core.env.Environment;
public class TransportUtils {
- public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) {
+ public static SSLProperties createSSLProperties(boolean sslEnabled, Environment environment, String tag) {
SSLProperties sslProperties = new SSLProperties();
sslProperties.setEnabled(sslEnabled);
@@ -34,93 +35,93 @@ public class TransportUtils {
}
SSLOption option = new SSLOption();
- option.setEngine(getStringProperty(configuration,
+ option.setEngine(getStringProperty(environment,
DEFAULT_OPTION.getEngine(),
"ssl." + tag + ".engine",
"ssl.engine"));
option.setProtocols(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getProtocols(),
"ssl." + tag + ".protocols",
"ssl.protocols"));
option.setCiphers(
- getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
+ getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
option.setAuthPeer(
- getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
+ getBooleanProperty(environment, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
option.setCheckCNHost(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNHost(),
"ssl." + tag + ".checkCN.host",
"ssl.checkCN.host"));
option.setCheckCNWhite(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNWhite(),
"ssl." + tag + ".checkCN.white",
"ssl.checkCN.white"));
- option.setCheckCNWhiteFile(getStringProperty(configuration,
+ option.setCheckCNWhiteFile(getStringProperty(environment,
DEFAULT_OPTION.getCiphers(),
"ssl." + tag + ".checkCN.white.file",
"ssl.checkCN.white.file"));
- option.setAllowRenegociate(getBooleanProperty(configuration,
+ option.setAllowRenegociate(getBooleanProperty(environment,
DEFAULT_OPTION.isAllowRenegociate(),
"ssl." + tag + ".allowRenegociate",
"ssl.allowRenegociate"));
option.setStorePath(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getStorePath(),
"ssl." + tag + ".storePath",
"ssl.storePath"));
option.setClientAuth(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getClientAuth(),
"ssl." + tag + ".clientAuth",
"ssl.clientAuth"));
option.setTrustStore(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getTrustStore(),
"ssl." + tag + ".trustStore",
"ssl.trustStore"));
- option.setTrustStoreType(getStringProperty(configuration,
+ option.setTrustStoreType(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreType(),
"ssl." + tag + ".trustStoreType",
"ssl.trustStoreType"));
- option.setTrustStoreValue(getStringProperty(configuration,
+ option.setTrustStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreValue(),
"ssl." + tag + ".trustStoreValue",
"ssl.trustStoreValue"));
option.setKeyStore(
- getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
+ getStringProperty(environment, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
option.setKeyStoreType(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreType(),
"ssl." + tag + ".keyStoreType",
"ssl.keyStoreType"));
- option.setKeyStoreValue(getStringProperty(configuration,
+ option.setKeyStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreValue(),
"ssl." + tag + ".keyStoreValue",
"ssl.keyStoreValue"));
- option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
+ option.setCrl(getStringProperty(environment, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
option.setSslCustomClass(
- getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
+ getStringProperty(environment, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
sslProperties.setSslOption(option);
sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
return sslProperties;
}
- private static String getStringProperty(Configuration configuration, String defaultValue, String... keys) {
+ private static String getStringProperty(Environment environment, String defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getString(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key);
}
}
return defaultValue;
}
- private static boolean getBooleanProperty(Configuration configuration, boolean defaultValue, String... keys) {
+ private static boolean getBooleanProperty(Environment environment, boolean defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getBoolean(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key, boolean.class, false);
}
}
return defaultValue;
[servicecomb-java-chassis] 17/25: [SCB-2008]adapt DynamicProperties
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit a1cc01d06b3354715e0f456acd4e01160c04ab70
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 15:43:15 2023 +0800
[SCB-2008]adapt DynamicProperties
---
.../edge/core/CommonHttpEdgeDispatcher.java | 10 +-
.../servicecomb/edge/core/EdgeAddHeaderFilter.java | 12 +-
.../edge/core/URLMappedEdgeDispatcher.java | 10 +-
.../config/ConfigurationChangedEvent.java | 32 ++--
.../servicecomb/config/DynamicPropertiesImpl.java | 165 +++++++++++++++------
.../config/FoundationConfigConfiguration.java | 4 +-
.../servicecomb/config/DynamicPropertiesTest.java | 62 +++++---
.../servicecomb/qps/QpsControllerManager.java | 11 +-
.../authentication/provider/AccessController.java | 13 +-
9 files changed, 189 insertions(+), 130 deletions(-)
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
index fbeb0585d..5c3edc183 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/CommonHttpEdgeDispatcher.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.edge.core;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.config.MicroserviceProperties;
@@ -128,13 +127,8 @@ public class CommonHttpEdgeDispatcher extends AbstractEdgeDispatcher {
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- Map<String, Object> changed = new HashMap<>();
- changed.putAll(event.getDeleted());
- changed.putAll(event.getAdded());
- changed.putAll(event.getUpdated());
-
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(KEY_MAPPING_PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(KEY_MAPPING_PREFIX)) {
loadConfigurations();
break;
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
index 65a20bc7e..0788397e5 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
@@ -18,10 +18,7 @@ package org.apache.servicecomb.edge.core;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
@@ -69,13 +66,8 @@ public class EdgeAddHeaderFilter implements ConsumerFilter {
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- Map<String, Object> changed = new HashMap<>();
- changed.putAll(event.getDeleted());
- changed.putAll(event.getAdded());
- changed.putAll(event.getUpdated());
-
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(PREFIX)) {
init();
break;
}
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
index 310381e8a..0f2920e8e 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/URLMappedEdgeDispatcher.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.edge.core;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.servicecomb.common.rest.RestProducerInvocationFlow;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
@@ -106,13 +105,8 @@ public class URLMappedEdgeDispatcher extends AbstractEdgeDispatcher {
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- Map<String, Object> changed = new HashMap<>();
- changed.putAll(event.getDeleted());
- changed.putAll(event.getAdded());
- changed.putAll(event.getUpdated());
-
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(KEY_MAPPING_PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(KEY_MAPPING_PREFIX)) {
loadConfigurations();
break;
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
index ba2590c17..9e58a5f97 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
@@ -18,8 +18,10 @@
package org.apache.servicecomb.config;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
public class ConfigurationChangedEvent {
private final Map<String, Object> added;
@@ -28,53 +30,49 @@ public class ConfigurationChangedEvent {
private final Map<String, Object> updated;
- private final boolean changed;
-
- private Map<String, Object> complete;
+ private Set<String> changed;
private ConfigurationChangedEvent(Map<String, Object> added, Map<String, Object> updated,
- Map<String, Object> deleted, boolean changed) {
+ Map<String, Object> deleted) {
this.added = added;
this.deleted = deleted;
this.updated = updated;
- this.changed = changed;
+ this.changed = new HashSet<>();
+ this.changed.addAll(added.keySet());
+ this.changed.addAll(updated.keySet());
+ this.changed.addAll(deleted.keySet());
}
public static ConfigurationChangedEvent createIncremental(Map<String, Object> latest, Map<String, Object> last) {
Map<String, Object> itemsCreated = new HashMap<>();
Map<String, Object> itemsDeleted = new HashMap<>();
Map<String, Object> itemsModified = new HashMap<>();
- boolean changed = false;
for (Map.Entry<String, Object> entry : latest.entrySet()) {
String itemKey = entry.getKey();
if (!last.containsKey(itemKey)) {
itemsCreated.put(itemKey, entry.getValue());
- changed = true;
} else if (!Objects.equals(last.get(itemKey), latest.get(itemKey))) {
itemsModified.put(itemKey, entry.getValue());
- changed = true;
}
}
for (String itemKey : last.keySet()) {
if (!latest.containsKey(itemKey)) {
itemsDeleted.put(itemKey, null);
- changed = true;
}
}
ConfigurationChangedEvent event = ConfigurationChangedEvent
- .createIncremental(itemsCreated, itemsModified, itemsDeleted, changed);
- event.complete = latest;
+ .createIncremental(itemsCreated, itemsModified, itemsDeleted);
return event;
}
public static ConfigurationChangedEvent createIncremental(Map<String, Object> added, Map<String, Object> updated,
- Map<String, Object> deleted, boolean changed) {
- return new ConfigurationChangedEvent(added, updated, deleted, changed);
+ Map<String, Object> deleted) {
+ return new ConfigurationChangedEvent(added, updated, deleted);
}
public static ConfigurationChangedEvent createIncremental(Map<String, Object> updated) {
- return new ConfigurationChangedEvent(new HashMap<>(), updated, new HashMap<>(), true);
+ return new ConfigurationChangedEvent(new HashMap<>(), updated, new HashMap<>());
}
public final Map<String, Object> getAdded() {
@@ -91,11 +89,7 @@ public class ConfigurationChangedEvent {
return deleted;
}
- public final Map<String, Object> getComplete() {
- return complete;
- }
-
- public final boolean isChanged() {
+ public final Set<String> getChanged() {
return changed;
}
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
index 3931061fc..6ce2ea2d1 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
@@ -17,108 +17,185 @@
package org.apache.servicecomb.config;
-import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
-import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.servicecomb.foundation.common.event.EventManager;
+import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicBooleanProperty;
-import com.netflix.config.DynamicDoubleProperty;
-import com.netflix.config.DynamicFloatProperty;
-import com.netflix.config.DynamicIntProperty;
-import com.netflix.config.DynamicLongProperty;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicStringProperty;
+import com.google.common.eventbus.Subscribe;
public class DynamicPropertiesImpl implements DynamicProperties {
- public DynamicPropertiesImpl() {
+ private final Map<String, Set<Consumer<String>>> stringCallbacks = new HashMap<>();
+
+ private final Map<String, Set<IntConsumer>> intCallbacks = new HashMap<>();
+
+ private final Map<String, Set<LongConsumer>> longCallbacks = new HashMap<>();
+
+ private final Map<String, Set<DoubleConsumer>> floatCallbacks = new HashMap<>();
+
+ private final Map<String, Set<DoubleConsumer>> doubleCallbacks = new HashMap<>();
+
+ private final Map<String, Set<Consumer<Boolean>>> booleanCallbacks = new HashMap<>();
+
+ private final Environment environment;
+
+ public DynamicPropertiesImpl(Environment environment) {
+ this.environment = environment;
+ EventManager.register(this);
}
- public DynamicPropertiesImpl(AbstractConfiguration... configurations) {
- ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration();
- Arrays.stream(configurations).forEach(configuration::addConfiguration);
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ for (Entry<String, Object> entry : event.getAdded().entrySet()) {
+ updateValue(entry);
+ }
- ConfigurationManager.install(configuration);
+ for (Entry<String, Object> entry : event.getUpdated().entrySet()) {
+ updateValue(entry);
+ }
+
+ for (Entry<String, Object> entry : event.getDeleted().entrySet()) {
+ updateDefault(entry);
+ }
+ }
+
+ private void updateDefault(Entry<String, Object> entry) {
+ if (stringCallbacks.containsKey(entry.getKey())) {
+ for (Consumer<String> callbacks : stringCallbacks.get(entry.getKey())) {
+ callbacks.accept(null);
+ }
+ }
+ if (intCallbacks.containsKey(entry.getKey())) {
+ for (IntConsumer callbacks : intCallbacks.get(entry.getKey())) {
+ callbacks.accept(0);
+ }
+ }
+ if (longCallbacks.containsKey(entry.getKey())) {
+ for (LongConsumer callbacks : longCallbacks.get(entry.getKey())) {
+ callbacks.accept(0L);
+ }
+ }
+ if (floatCallbacks.containsKey(entry.getKey())) {
+ for (DoubleConsumer callbacks : floatCallbacks.get(entry.getKey())) {
+ callbacks.accept(0F);
+ }
+ }
+ if (doubleCallbacks.containsKey(entry.getKey())) {
+ for (DoubleConsumer callbacks : doubleCallbacks.get(entry.getKey())) {
+ callbacks.accept(0D);
+ }
+ }
+ if (booleanCallbacks.containsKey(entry.getKey())) {
+ for (Consumer<Boolean> callbacks : booleanCallbacks.get(entry.getKey())) {
+ callbacks.accept(false);
+ }
+ }
+ }
+
+ private void updateValue(Entry<String, Object> entry) {
+ if (stringCallbacks.containsKey(entry.getKey())) {
+ for (Consumer<String> callbacks : stringCallbacks.get(entry.getKey())) {
+ callbacks.accept((String) entry.getValue());
+ }
+ }
+ if (intCallbacks.containsKey(entry.getKey())) {
+ for (IntConsumer callbacks : intCallbacks.get(entry.getKey())) {
+ callbacks.accept((int) entry.getValue());
+ }
+ }
+ if (longCallbacks.containsKey(entry.getKey())) {
+ for (LongConsumer callbacks : longCallbacks.get(entry.getKey())) {
+ callbacks.accept((long) entry.getValue());
+ }
+ }
+ if (floatCallbacks.containsKey(entry.getKey())) {
+ for (DoubleConsumer callbacks : floatCallbacks.get(entry.getKey())) {
+ callbacks.accept((float) entry.getValue());
+ }
+ }
+ if (doubleCallbacks.containsKey(entry.getKey())) {
+ for (DoubleConsumer callbacks : doubleCallbacks.get(entry.getKey())) {
+ callbacks.accept((double) entry.getValue());
+ }
+ }
+ if (booleanCallbacks.containsKey(entry.getKey())) {
+ for (Consumer<Boolean> callbacks : booleanCallbacks.get(entry.getKey())) {
+ callbacks.accept((boolean) entry.getValue());
+ }
+ }
}
@Override
public String getStringProperty(String propertyName, Consumer<String> consumer, String defaultValue) {
- DynamicStringProperty prop = propertyFactoryInstance().getStringProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ stringCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, defaultValue);
}
@Override
public String getStringProperty(String propertyName, String defaultValue) {
- return propertyFactoryInstance().getStringProperty(propertyName, defaultValue).get();
+ return environment.getProperty(propertyName, defaultValue);
}
@Override
public int getIntProperty(String propertyName, IntConsumer consumer, int defaultValue) {
- DynamicIntProperty prop = propertyFactoryInstance().getIntProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ intCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, int.class, defaultValue);
}
@Override
public int getIntProperty(String propertyName, int defaultValue) {
- return propertyFactoryInstance().getIntProperty(propertyName, defaultValue).get();
+ return environment.getProperty(propertyName, int.class, defaultValue);
}
@Override
public long getLongProperty(String propertyName, LongConsumer consumer, long defaultValue) {
- DynamicLongProperty prop = propertyFactoryInstance().getLongProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ longCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, long.class, defaultValue);
}
@Override
public long getLongProperty(String propertyName, long defaultValue) {
- return propertyFactoryInstance().getLongProperty(propertyName, defaultValue).get();
+ return environment.getProperty(propertyName, long.class, defaultValue);
}
@Override
public float getFloatProperty(String propertyName, DoubleConsumer consumer, float defaultValue) {
- DynamicFloatProperty prop = propertyFactoryInstance().getFloatProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ floatCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, float.class, defaultValue);
}
@Override
public float getFloatProperty(String propertyName, float defaultValue) {
- return propertyFactoryInstance().getFloatProperty(propertyName, defaultValue).get();
+ return environment.getProperty(propertyName, float.class, defaultValue);
}
@Override
public double getDoubleProperty(String propertyName, DoubleConsumer consumer, double defaultValue) {
- DynamicDoubleProperty prop = propertyFactoryInstance().getDoubleProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ doubleCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, double.class, defaultValue);
}
@Override
public double getDoubleProperty(String propertyName, double defaultValue) {
- return propertyFactoryInstance().getDoubleProperty(propertyName, defaultValue).get();
+ return environment.getProperty(propertyName, double.class, defaultValue);
}
@Override
public boolean getBooleanProperty(String propertyName, Consumer<Boolean> consumer, boolean defaultValue) {
- DynamicBooleanProperty prop = propertyFactoryInstance().getBooleanProperty(propertyName, defaultValue);
- prop.addCallback(() -> consumer.accept(prop.get()));
- return prop.get();
+ booleanCallbacks.computeIfAbsent(propertyName, key -> new HashSet<>()).add(consumer);
+ return environment.getProperty(propertyName, boolean.class, defaultValue);
}
@Override
public boolean getBooleanProperty(String propertyName, boolean defaultValue) {
- return propertyFactoryInstance().getBooleanProperty(propertyName, defaultValue).get();
- }
-
- private DynamicPropertyFactory propertyFactoryInstance() {
- return DynamicPropertyFactory.getInstance();
+ return environment.getProperty(propertyName, boolean.class, defaultValue);
}
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
index 91f49c8a1..18906749f 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
@@ -50,8 +50,8 @@ public class FoundationConfigConfiguration {
}
@Bean
- public DynamicPropertiesImpl dynamicProperties() {
- return new DynamicPropertiesImpl();
+ public DynamicPropertiesImpl dynamicProperties(Environment environment) {
+ return new DynamicPropertiesImpl(environment);
}
@Bean
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
index 9090a64ae..4b2de1c79 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
@@ -23,13 +23,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
+import java.util.HashMap;
import java.util.Objects;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentMapConfiguration;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DynamicPropertyFactory;
import com.seanyinx.github.unit.scaffolding.Poller;
@@ -38,7 +41,6 @@ import com.seanyinx.github.unit.scaffolding.Randomness;
import mockit.Deencapsulation;
public class DynamicPropertiesTest {
-
private static final String stringPropertyName = uniquify("stringPropertyName");
private static final String intPropertyName = uniquify("intPropertyName");
@@ -57,7 +59,7 @@ public class DynamicPropertiesTest {
private static final long longOldValue = Randomness.nextLong();
- private static final double floatOldValue = Randomness.nextDouble();
+ private static final float floatOldValue = Double.valueOf(Randomness.nextDouble()).floatValue();
private static final double doubleOldValue = Randomness.nextDouble();
@@ -65,9 +67,9 @@ public class DynamicPropertiesTest {
private static final double ERROR = 0.0000001;
- private static DynamicProperties dynamicProperties;
+ private static Environment environment;
- private static ConcurrentMapConfiguration configuration;
+ private static DynamicProperties dynamicProperties;
private final Poller poller = new Poller(2000, 100);
@@ -86,10 +88,9 @@ public class DynamicPropertiesTest {
@BeforeClass
public static void setUpClass() throws Exception {
- tearDown();
- configuration = new ConcurrentMapConfiguration();
+ environment = Mockito.mock(Environment.class);
writeInitialConfig();
- dynamicProperties = new DynamicPropertiesImpl(configuration);
+ dynamicProperties = new DynamicPropertiesImpl(environment);
}
@AfterClass
@@ -100,12 +101,13 @@ public class DynamicPropertiesTest {
}
private static void writeInitialConfig() throws Exception {
- configuration.setProperty(stringPropertyName, stringOldValue);
- configuration.setProperty(intPropertyName, String.valueOf(intOldValue));
- configuration.setProperty(longPropertyName, String.valueOf(longOldValue));
- configuration.setProperty(floatPropertyName, String.valueOf(floatOldValue));
- configuration.setProperty(doublePropertyName, String.valueOf(doubleOldValue));
- configuration.setProperty(booleanPropertyName, String.valueOf(booleanOldValue));
+ Mockito.when(environment.getProperty(stringPropertyName, (String) null)).thenReturn(stringOldValue);
+ Mockito.when(environment.getProperty(intPropertyName, int.class, 0)).thenReturn(intOldValue);
+ Mockito.when(environment.getProperty(longPropertyName, long.class, 0L)).thenReturn(longOldValue);
+ Mockito.when(environment.getProperty(floatPropertyName, float.class, 0F)).thenReturn(floatOldValue);
+ Mockito.when(environment.getProperty(doublePropertyName, double.class, 0D)).thenReturn(doubleOldValue);
+ Mockito.when(environment.getProperty(booleanPropertyName, boolean.class, false))
+ .thenReturn(booleanOldValue);
}
@Test
@@ -118,7 +120,10 @@ public class DynamicPropertiesTest {
String newValue = uniquify("newValue");
- configuration.setProperty(stringPropertyName, newValue);
+ Mockito.when(environment.getProperty(stringPropertyName, stringOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(stringPropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> Objects.equals(stringPropertyValue, newValue));
}
@@ -133,7 +138,10 @@ public class DynamicPropertiesTest {
int newValue = Randomness.nextInt();
- configuration.setProperty(intPropertyName, String.valueOf(newValue));
+ Mockito.when(environment.getProperty(intPropertyName, int.class, intOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(intPropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> intPropertyValue == newValue);
}
@@ -148,7 +156,10 @@ public class DynamicPropertiesTest {
long newValue = Randomness.nextLong();
- configuration.setProperty(longPropertyName, String.valueOf(newValue));
+ Mockito.when(environment.getProperty(longPropertyName, long.class, longOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(longPropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> longPropertyValue == newValue);
}
@@ -161,9 +172,12 @@ public class DynamicPropertiesTest {
property = dynamicProperties.getFloatProperty(floatPropertyName, value -> floatPropertyValue = value, 0);
assertThat(property, closeTo(floatOldValue, ERROR));
- double newValue = Randomness.nextDouble();
+ float newValue = Double.valueOf(Randomness.nextDouble()).floatValue();
- configuration.setProperty(floatPropertyName, String.valueOf(newValue));
+ Mockito.when(environment.getProperty(floatPropertyName, float.class, floatOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(floatPropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> Math.abs(floatPropertyValue - newValue) < ERROR);
}
@@ -178,7 +192,10 @@ public class DynamicPropertiesTest {
double newValue = Randomness.nextDouble();
- configuration.setProperty(doublePropertyName, String.valueOf(newValue));
+ Mockito.when(environment.getProperty(doublePropertyName, double.class, doubleOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(doublePropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> Math.abs(doublePropertyValue - newValue) < ERROR);
}
@@ -196,7 +213,10 @@ public class DynamicPropertiesTest {
boolean newValue = !booleanOldValue;
- configuration.setProperty(booleanPropertyName, String.valueOf(newValue));
+ Mockito.when(environment.getProperty(booleanPropertyName, boolean.class, booleanOldValue)).thenReturn(newValue);
+ HashMap<String, Object> updated = new HashMap<>();
+ updated.put(booleanPropertyName, newValue);
+ EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
poller.assertEventually(() -> booleanPropertyValue == newValue);
}
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
index 8e33088e3..0ef5b2716 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
@@ -17,10 +17,8 @@
package org.apache.servicecomb.qps;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
@@ -85,13 +83,8 @@ public class QpsControllerManager {
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- Map<String, Object> changed = new HashMap<>();
- changed.putAll(event.getDeleted());
- changed.putAll(event.getAdded());
- changed.putAll(event.getUpdated());
-
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(Config.CONFIG_PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(Config.CONFIG_PREFIX)) {
configQpsControllerMap.clear();
qualifiedNameControllerMap.clear();
initGlobalQpsController();
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
index 07edae566..b923b2939 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
@@ -138,19 +138,14 @@ public class AccessController {
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- Map<String, Object> changed = new HashMap<>();
- changed.putAll(event.getDeleted());
- changed.putAll(event.getAdded());
- changed.putAll(event.getUpdated());
-
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(KEY_WHITE_LIST_PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(KEY_WHITE_LIST_PREFIX)) {
loadConfigurations(KEY_WHITE_LIST_PREFIX);
break;
}
}
- for (Entry<String, Object> entry : changed.entrySet()) {
- if (entry.getKey().startsWith(KEY_BLACK_LIST_PREFIX)) {
+ for (String changed : event.getChanged()) {
+ if (changed.startsWith(KEY_BLACK_LIST_PREFIX)) {
loadConfigurations(KEY_BLACK_LIST_PREFIX);
break;
}
[servicecomb-java-chassis] 16/25: [SCB-2008]remove inspector module
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 13373278044e4a4030f3a18da5f58e32559604c6
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 14:23:37 2023 +0800
[SCB-2008]remove inspector module
---
coverage-reports/pom.xml | 6 -
dependencies/bom/pom.xml | 8 +-
distribution/pom.xml | 6 -
inspector/pom.xml | 72 ------
.../inspector/internal/InspectorBootListener.java | 62 -----
.../inspector/internal/InspectorConfig.java | 35 ---
.../inspector/internal/InspectorConfiguration.java | 33 ---
.../inspector/internal/InspectorImpl.java | 187 --------------
.../internal/model/DynamicPropertyView.java | 59 -----
.../internal/model/PriorityPropertyView.java | 52 ----
.../inspector/internal/swagger/SchemaFormat.java | 32 ---
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 --
inspector/src/main/resources/webroot/index.html | 84 -------
.../src/main/resources/webroot/static/css/main.css | 93 -------
.../webroot/static/dynamicProperties.html | 66 -----
.../webroot/static/images/ServiceComb-logo-3.jpg | Bin 80000 -> 0 bytes
.../webroot/static/images/download-all.png | Bin 208 -> 0 bytes
.../resources/webroot/static/images/download.png | Bin 178 -> 0 bytes
.../src/main/resources/webroot/static/js/main.js | 38 ---
.../webroot/static/priorityProperties.html | 89 -------
.../resources/webroot/static/schemas/schemas.css | 37 ---
.../resources/webroot/static/schemas/schemas.js | 111 ---------
.../main/resources/webroot/static/tree/tree.css | 117 ---------
.../src/main/resources/webroot/static/tree/tree.js | 110 ---------
.../src/main/resources/webroot/static/welcome.html | 22 --
.../internal/TestInspectorBootListener.java | 81 -------
.../inspector/internal/TestInspectorImpl.java | 269 ---------------------
inspector/src/test/resources/microservice.yaml | 23 --
inspector/src/test/resources/schema1.yaml | 61 -----
inspector/src/test/resources/schema2.yaml | 61 -----
pom.xml | 1 -
31 files changed, 1 insertion(+), 1832 deletions(-)
diff --git a/coverage-reports/pom.xml b/coverage-reports/pom.xml
index 78435f358..8e672de7e 100644
--- a/coverage-reports/pom.xml
+++ b/coverage-reports/pom.xml
@@ -177,12 +177,6 @@
<artifactId>handler-tracing-zipkin</artifactId>
</dependency>
- <!-- inspector -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>inspector</artifactId>
- </dependency>
-
<!-- metrics -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index 87ab51385..4268ac285 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -216,14 +216,8 @@
<artifactId>handler-tracing-zipkin</artifactId>
<version>${project.version}</version>
</dependency>
- <!-- ServiceComb: inspector -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>inspector</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!-- ServiceComb: metrics -->
+ <!-- ServiceComb: metrics -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>metrics-core</artifactId>
diff --git a/distribution/pom.xml b/distribution/pom.xml
index c77e2b01d..947433068 100644
--- a/distribution/pom.xml
+++ b/distribution/pom.xml
@@ -183,12 +183,6 @@
<artifactId>handler-tracing-zipkin</artifactId>
</dependency>
- <!-- inspector -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>inspector</artifactId>
- </dependency>
-
<!-- metrics -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/inspector/pom.xml b/inspector/pom.xml
deleted file mode 100644
index 15ebe52f0..000000000
--- a/inspector/pom.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>java-chassis-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <relativePath>../parents/default</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>inspector</artifactId>
- <name>Java Chassis::Inspector</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>transport-rest-vertx</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>provider-jaxrs</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>registry-local</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-test-scaffolding</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>transport-rest-servlet</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
deleted file mode 100644
index c694817f1..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorBootListener.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import org.apache.servicecomb.config.MicroserviceProperties;
-import org.apache.servicecomb.core.BootListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public class InspectorBootListener implements BootListener {
- private static final Logger LOGGER = LoggerFactory.getLogger(InspectorBootListener.class);
-
- private final InspectorConfig inspectorConfig;
-
- private MicroserviceProperties microserviceProperties;
-
- public InspectorBootListener(InspectorConfig inspectorConfig) {
- this.inspectorConfig = inspectorConfig;
- }
-
- @Autowired
- public void setMicroserviceProperties(MicroserviceProperties microserviceProperties) {
- this.microserviceProperties = microserviceProperties;
- }
-
- @Override
- public int getOrder() {
- return Short.MAX_VALUE;
- }
-
- @Override
- public void onAfterTransport(BootEvent event) {
- if (!inspectorConfig.isEnabled()) {
- LOGGER.info("inspector is not enabled.");
- return;
- }
- LOGGER.info("inspector is enabled.");
-
- // will not register this schemas to service registry
- InspectorImpl inspector = new InspectorImpl()
- .setServiceName(microserviceProperties.getName());
- // TODO: inspector get schemas
-// .setSchemas(RegistrationManager.INSTANCE.getMicroservice().getSchemaMap())
-// .correctBasePathForOnlineTest(event.getScbEngine());
- event.getScbEngine().getProducerProviderManager().registerSchema("inspector", inspector);
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfig.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfig.java
deleted file mode 100644
index 6aa6014b9..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfig.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import org.apache.servicecomb.config.inject.InjectProperties;
-import org.apache.servicecomb.config.inject.InjectProperty;
-
-@InjectProperties(prefix = "servicecomb.inspector")
-public class InspectorConfig {
- @InjectProperty(keys = "enabled", defaultValue = "true")
- private boolean enabled;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public InspectorConfig setEnabled(boolean enabled) {
- this.enabled = enabled;
- return this;
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
deleted file mode 100644
index 47ac953dc..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorConfiguration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class InspectorConfiguration {
- @Bean
- public InspectorBootListener inspectorBootListener(InspectorConfig inspectorConfig) {
- return new InspectorBootListener(inspectorConfig);
- }
-
- @Bean
- public InspectorConfig inspectorConfig() {
- return new InspectorConfig();
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
deleted file mode 100644
index cfe7de0a5..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/InspectorImpl.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.common.rest.resource.ClassPathStaticResourceHandler;
-import org.apache.servicecomb.common.rest.resource.StaticResourceHandler;
-import org.apache.servicecomb.core.CoreConst;
-import org.apache.servicecomb.core.SCBEngine;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.foundation.common.part.InputStreamPart;
-import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
-import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
-import org.apache.servicecomb.registry.definition.DefinitionConst;
-import org.apache.servicecomb.swagger.SwaggerUtils;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.VisibleForTesting;
-
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.models.OpenAPI;
-import jakarta.servlet.http.Part;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
-import jakarta.ws.rs.QueryParam;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response.Status;
-
-@Path("/inspector")
-public class InspectorImpl {
- private static final Logger LOGGER = LoggerFactory.getLogger(InspectorImpl.class);
-
- private final StaticResourceHandler resourceHandler = new ClassPathStaticResourceHandler();
-
- private Map<String, String> schemas;
-
- private String serviceName;
-
- @VisibleForTesting
- public Map<String, String> getSchemas() {
- return schemas;
- }
-
- public InspectorImpl setServiceName(String serviceName) {
- this.serviceName = serviceName;
- return this;
- }
-
- public InspectorImpl setSchemas(Map<String, String> schemas) {
- this.schemas = schemas;
- return this;
- }
-
- // when work in servlet mode, should concat url prefix
- // otherwise swagger ide can not run online test
- //
- // ServiceComb consumer has not this problem
- // ServiceComb consumer not care for producer deploy with or without servlet
- public InspectorImpl correctBasePathForOnlineTest(SCBEngine scbEngine) {
- Transport restTransport = scbEngine.getTransportManager().findTransport(CoreConst.RESTFUL);
- if (restTransport == null ||
- !restTransport.getClass().getName()
- .equals("org.apache.servicecomb.transport.rest.servlet.ServletRestTransport")) {
- return this;
- }
-
- String urlPrefix = ClassLoaderScopeContext.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX);
- if (StringUtils.isEmpty(urlPrefix)) {
- return this;
- }
-
- for (Entry<String, String> entry : schemas.entrySet()) {
- OpenAPI swagger = SwaggerUtils.parseSwagger(entry.getValue());
- if (SwaggerUtils.getBasePath(swagger).startsWith(urlPrefix)) {
- continue;
- }
-
- SwaggerUtils.setBasePath(swagger, urlPrefix + SwaggerUtils.getBasePath(swagger));
-
- entry.setValue(SwaggerUtils.swaggerToString(swagger));
- }
- return this;
- }
-
- @Path("/schemas")
- @GET
- public Collection<String> getSchemaIds() {
- return schemas.keySet();
- }
-
- @Path("/download/schemas")
- @GET
- @ApiResponse(responseCode = "200", description = "", content =
- @Content(schema = @Schema(type = "string", format = "binary")))
- public Response downloadSchemas(@QueryParam("format") SchemaFormat format) {
- if (format == null) {
- format = SchemaFormat.SWAGGER;
- }
-
- // normally, schema will not be too big, just save them in memory temporarily
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- try (ZipOutputStream zos = new ZipOutputStream(os)) {
- for (Entry<String, String> entry : schemas.entrySet()) {
- // begin writing a new ZIP entry, positions the stream to the start of the entry data
- zos.putNextEntry(new ZipEntry(entry.getKey() + format.getSuffix()));
-
- String content = entry.getValue();
- zos.write(content.getBytes(StandardCharsets.UTF_8));
- zos.closeEntry();
- }
- } catch (Throwable e) {
- String msg = "failed to create schemas zip file, format=" + format + ".";
- LOGGER.error(msg, e);
- return Response.failResp(new InvocationException(Status.INTERNAL_SERVER_ERROR, msg));
- }
-
- Part part = new InputStreamPart(null, new ByteArrayInputStream(os.toByteArray()))
- .setSubmittedFileName(serviceName + format.getSuffix() + ".zip");
- return Response.ok(part);
- }
-
- @Path("/schemas/{schemaId}")
- @GET
- @ApiResponse(responseCode = "200", description = "", content =
- @Content(schema = @Schema(type = "string", format = "binary")))
- public Response getSchemaContentById(@PathParam("schemaId") String schemaId,
- @QueryParam("format") SchemaFormat format, @QueryParam("download") boolean download) {
- String swaggerContent = schemas.get(schemaId);
- if (swaggerContent == null) {
- return Response.failResp(new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase()));
- }
-
- if (format == null) {
- format = SchemaFormat.SWAGGER;
- }
-
- byte[] bytes = swaggerContent.getBytes(StandardCharsets.UTF_8);
-
- Part part = new InputStreamPart(null, new ByteArrayInputStream(bytes))
- .setSubmittedFileName(schemaId + format.getSuffix());
-
- Response response = Response.ok(part);
- if (!download) {
- response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline");
- }
- response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
- return response;
- }
-
- @Path("/{path : .+}")
- @GET
- @ApiResponse(responseCode = "200", description = "", content =
- @Content(schema = @Schema(type = "string", format = "binary")))
- public Response getStaticResource(@PathParam("path") String path) {
- return resourceHandler.handle(path);
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/DynamicPropertyView.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/DynamicPropertyView.java
deleted file mode 100644
index bf7c68fc7..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/DynamicPropertyView.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal.model;
-
-public class DynamicPropertyView {
- private String key;
-
- private String value;
-
- private String changedTime = "";
-
- private int callbackCount;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getChangedTime() {
- return changedTime;
- }
-
- public void setChangedTime(String changedTime) {
- this.changedTime = changedTime;
- }
-
- public int getCallbackCount() {
- return callbackCount;
- }
-
- public void setCallbackCount(int callbackCount) {
- this.callbackCount = callbackCount;
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/PriorityPropertyView.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/PriorityPropertyView.java
deleted file mode 100644
index d1524946d..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/model/PriorityPropertyView.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal.model;
-
-import java.util.List;
-
-public class PriorityPropertyView {
- private List<DynamicPropertyView> dynamicProperties;
-
- private String defaultValue;
-
- private String value;
-
- public List<DynamicPropertyView> getDynamicProperties() {
- return dynamicProperties;
- }
-
- public void setDynamicProperties(
- List<DynamicPropertyView> dynamicProperties) {
- this.dynamicProperties = dynamicProperties;
- }
-
- public String getDefaultValue() {
- return defaultValue;
- }
-
- public void setDefaultValue(String defaultValue) {
- this.defaultValue = defaultValue;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-}
diff --git a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/swagger/SchemaFormat.java b/inspector/src/main/java/org/apache/servicecomb/inspector/internal/swagger/SchemaFormat.java
deleted file mode 100644
index 099350c3d..000000000
--- a/inspector/src/main/java/org/apache/servicecomb/inspector/internal/swagger/SchemaFormat.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal.swagger;
-
-public enum SchemaFormat {
- SWAGGER(".yaml"),
- HTML(".html");
-
- private final String suffix;
-
- SchemaFormat(String suffix) {
- this.suffix = suffix;
- }
-
- public String getSuffix() {
- return suffix;
- }
-}
diff --git a/inspector/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/inspector/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
deleted file mode 100644
index c98a4535b..000000000
--- a/inspector/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ /dev/null
@@ -1,18 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-org.apache.servicecomb.inspector.internal.InspectorConfiguration
diff --git a/inspector/src/main/resources/webroot/index.html b/inspector/src/main/resources/webroot/index.html
deleted file mode 100644
index 29b3ccb93..000000000
--- a/inspector/src/main/resources/webroot/index.html
+++ /dev/null
@@ -1,84 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title>ServiceComb inspector</title>
- <link rel="stylesheet" href="static/css/main.css">
- <link rel="stylesheet" href="static/schemas/schemas.css">
- <link rel="stylesheet" href="static/tree/tree.css">
- <link rel="icon" type="image/png" href="static/images/ServiceComb-logo-3.jpg"/>
-
- <link rel="preload" href="static/js/main.js" as="script">
- <link rel="preload" href="static/schemas/schemas.js" as="script">
-
- <script src="static/js/main.js"></script>
- <script src="static/tree/tree.js"></script>
- <script src="static/schemas/schemas.js"></script>
-</head>
-<body>
-<div class="left">
- <img id="scbLogo" src="static/images/ServiceComb-logo-3.jpg"/>
- <tree id="mainTree">
- <tree-node id="configs" no-action expanded="true">
- <tree-face>
- <tree-node-open-close></tree-node-open-close>
- <tree-label>configs</tree-label>
- </tree-face>
- <tree-children>
- <tree-node id="dynamicProperties">
- <tree-face>
- <tree-label onclick="frame.location = 'static/dynamicProperties.html'">dynamic properties</tree-label>
- </tree-face>
- </tree-node>
- <tree-node id="priorityProperties">
- <tree-face>
- <tree-label onclick="frame.location = 'static/priorityProperties.html'">priority properties</tree-label>
- </tree-face>
- </tree-node>
- </tree-children>
- </tree-node>
- <tree-node id="schemas" no-action expanded="true">
- <tree-face>
- <tree-node-open-close></tree-node-open-close>
- <tree-label>schemas</tree-label>
- <select id="schema-format">
- <option value="SWAGGER">swagger</option>
- <option value="HTML">html</option>
- </select>
- <div class="download download-all" onclick="clickDownloadAllSchemas(event)"></div>
- </tree-face>
- </tree-node>
- </tree>
-</div>
-<div class="content">
- <iframe src="static/welcome.html" allowfullscreen scrolling="no"></iframe>
-</div>
-
-<script>
- var mainTree = new Tree("mainTree")
- var frame = null;
-
- window.onload = function () {
- frame = window.frames[0];
- initSchemas();
- };
-</script>
-</body>
-</html>
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/css/main.css b/inspector/src/main/resources/webroot/static/css/main.css
deleted file mode 100644
index 17cd2f6e1..000000000
--- a/inspector/src/main/resources/webroot/static/css/main.css
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-* {
- box-sizing: border-box;
-}
-
-html,
-body {
- width: 100%;
- height: 100%;
- margin: 0px;
- display: flex;
-}
-
-.left {
- flex-direction: column;
- flex-shrink: 0;
- width: 300px;
- height: 100%;
- overflow-y: scroll;
-}
-
-.content {
- overflow: hidden;
- position: relative;
- height: 100%;
- width: 100%;
-}
-
-.content iframe {
- border: 0;
- height: 100%;
- left: 0;
- position: absolute;
- top: 0;
- width: 100%;
-}
-
-#scbLogo {
- margin: auto;
- display: block;
- width: 50%;
-}
-
-.table-container {
- width: 100%;
- margin: 10px;
- overflow-y: scroll;
-}
-
-.table {
- border-spacing: 0px;
- width: 100%;
- word-wrap: break-word;
- word-break: break-all;
-}
-
-.table.left-head th {
- text-align: left;
- white-space: nowrap;
-}
-
-.table tr:nth-of-type(even) {
- background: #f8f8f7
-}
-
-.table.fix-head thead th {
- position: sticky;
- position: -webkit-sticky;
- top: 0;
- z-index: 999;
- background: #f7f8f7;
-}
-
-.table th, .table td {
- border: 1px solid #dedede;
- padding: 8px;
-}
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/dynamicProperties.html b/inspector/src/main/resources/webroot/static/dynamicProperties.html
deleted file mode 100644
index 04e609044..000000000
--- a/inspector/src/main/resources/webroot/static/dynamicProperties.html
+++ /dev/null
@@ -1,66 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
-
- <link rel="stylesheet" href="css/main.css">
-
- <style>
- .table td:nth-last-child(-n+2) {
- white-space: nowrap;
- }
- </style>
- <script src="js/main.js"></script>
-</head>
-<body>
-
-<div class="table-container">
- <table class="table fix-head left-head" id="configs">
- <thead>
- <tr>
- <th>index</th>
- <th>key</th>
- <th>value</th>
- <th>changed time</th>
- <th>callback count</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
-</div>
-
-<script>
- ajaxJsonGet("../dynamicProperties", function (configs) {
- var html = "";
- for (var idx in configs) {
- var config = configs[idx];
- html += "<tr>" +
- "<td>" + idx + "</td>" +
- "<td>" + config.key + "</td>" +
- "<td>" + config.value + "</td>" +
- "<td>" + config.changedTime + "</td>" +
- "<td>" + config.callbackCount + "</td>" +
- "</tr>";
- }
- document.querySelector("#configs tbody").innerHTML = html;
- })
-</script>
-</body>
-</html>
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/images/ServiceComb-logo-3.jpg b/inspector/src/main/resources/webroot/static/images/ServiceComb-logo-3.jpg
deleted file mode 100644
index b2cb70678..000000000
Binary files a/inspector/src/main/resources/webroot/static/images/ServiceComb-logo-3.jpg and /dev/null differ
diff --git a/inspector/src/main/resources/webroot/static/images/download-all.png b/inspector/src/main/resources/webroot/static/images/download-all.png
deleted file mode 100644
index 97637b3c5..000000000
Binary files a/inspector/src/main/resources/webroot/static/images/download-all.png and /dev/null differ
diff --git a/inspector/src/main/resources/webroot/static/images/download.png b/inspector/src/main/resources/webroot/static/images/download.png
deleted file mode 100644
index b898f9d8a..000000000
Binary files a/inspector/src/main/resources/webroot/static/images/download.png and /dev/null differ
diff --git a/inspector/src/main/resources/webroot/static/js/main.js b/inspector/src/main/resources/webroot/static/js/main.js
deleted file mode 100644
index e68ff58cf..000000000
--- a/inspector/src/main/resources/webroot/static/js/main.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function ajaxGet(url, succCallback) {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function () {
- if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
- succCallback(xmlhttp.responseText);
- }
- }
- xmlhttp.open("GET", url, true);
- xmlhttp.send();
-}
-
-function ajaxJsonGet(url, succCallback) {
- ajaxGet(url, function (text) {
- succCallback(JSON.parse(text))
- });
-}
-
-function getBlobURL(code, type) {
- var blob = new Blob([code], {type: type})
- return URL.createObjectURL(blob)
-}
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/priorityProperties.html b/inspector/src/main/resources/webroot/static/priorityProperties.html
deleted file mode 100644
index e816fcd3e..000000000
--- a/inspector/src/main/resources/webroot/static/priorityProperties.html
+++ /dev/null
@@ -1,89 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
-
- <link rel="stylesheet" href="css/main.css">
-
- <style>
- .table td {
- min-width: 100px;
- }
-
- .table td:nth-last-child(-n+2) {
- white-space: nowrap;
- }
- </style>
- <script src="js/main.js"></script>
-</head>
-<body>
-
-<div class="table-container">
- <table class="table fix-head left-head" id="configs">
- <thead>
- <tr>
- <th>index</th>
- <th>value</th>
- <th>default value</th>
- <th>key</th>
- <th>value</th>
- <th>changed time</th>
- <th>callback count</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
-</div>
-
-<script>
- ajaxJsonGet("../priorityProperties", function (configs) {
- var html = "";
- for (var idx in configs) {
- var config = configs[idx];
- var dynamicProperties = config.dynamicProperties;
-
- var rowspan = ">";
- if (dynamicProperties.length != 1) {
- rowspan = " rowspan='" + dynamicProperties.length + "'>";
- }
- html += "<tr>" +
- "<td" + rowspan + idx + "</td>" +
- "<td" + rowspan + config.value + "</td>" +
- "<td" + rowspan + config.defaultValue + "</td>" +
- "<td>" + dynamicProperties[0].key + "</td>" +
- "<td>" + dynamicProperties[0].value + "</td>" +
- "<td>" + dynamicProperties[0].changedTime + "</td>" +
- "<td>" + dynamicProperties[0].callbackCount + "</td>" +
- "</tr>";
-
- for (var propIdx = 1; propIdx < dynamicProperties.length; propIdx++) {
- html += "<tr>" +
- "<td>" + dynamicProperties[propIdx].key + "</td>" +
- "<td>" + dynamicProperties[propIdx].value + "</td>" +
- "<td>" + dynamicProperties[propIdx].changedTime + "</td>" +
- "<td>" + dynamicProperties[propIdx].callbackCount + "</td>" +
- "</tr>";
- }
- }
- document.querySelector("#configs tbody").innerHTML = html;
- })
-</script>
-</body>
-</html>
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/schemas/schemas.css b/inspector/src/main/resources/webroot/static/schemas/schemas.css
deleted file mode 100644
index b8905caf0..000000000
--- a/inspector/src/main/resources/webroot/static/schemas/schemas.css
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#schema-format {
- margin-right: 4px;
- width: 80px;
- flex-shrink: 0;
-}
-
-#schemas .download {
- background-image: url(../images/download.png);
- background-size: 100% 100%;
- width: 15px;
- height: 18px;
- flex-shrink: 0;
- margin-right: 3px;
- align-self: center;
- cursor: pointer;
-}
-
-#schemas .download.download-all {
- background-image: url(../images/download-all.png);
-}
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/schemas/schemas.js b/inspector/src/main/resources/webroot/static/schemas/schemas.js
deleted file mode 100644
index 788428cb0..000000000
--- a/inspector/src/main/resources/webroot/static/schemas/schemas.js
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function initSchemas() {
- var eleFormat = document.getElementById("schema-format");
- eleFormat.onchange = function () {
- localStorage.setItem("schemaFormatIdx", eleFormat.selectedIndex);
- if (mainTree.config.activeNodeId != null && mainTree.config.activeNodeId.startsWith("schemas://")) {
- mainTree.clickActiveTreeNode();
- }
- };
- var formatIdx = localStorage.getItem("schemaFormatIdx");
- if (formatIdx != null) {
- eleFormat.selectedIndex = formatIdx;
- }
-
- ajaxJsonGet("schemas", initSchemasTree);
-}
-
-function initSchemasTree(schemas) {
- schemas = schemas.sort();
- var eleSchemas = document.getElementById("schemas");
- var childrenContent = "<tree-children>";
- for (var idx in schemas) {
- childrenContent += '<tree-node id="schemas://' + schemas[idx] + '">' +
- ' <tree-face>' +
- ' <tree-label onclick="clickShowSchema(event)">' + schemas[idx] + '</tree-label>' +
- ' <div class="download" onclick="clickDownloadSchema(event)"></div>' +
- ' </tree-face>' +
- '</tree-node>';
- }
- childrenContent += '</tree-children>';
- eleSchemas.insertAdjacentHTML("beforeend", childrenContent);
-
- mainTree.init();
-}
-
-function fetchAndshowSchemaAsSwagger(url) {
- ajaxGet(url, function (schema) {
- frame.editor.specActions.updateSpec(schema);
- });
-}
-
-function showSchemaAsSwagger(url) {
- if (frame.SwaggerEditorBundle != null) {
- // reuse swagger editor
- fetchAndshowSchemaAsSwagger(url);
- return;
- }
-
- ajaxGet(url, function (schema) {
- localStorage.setItem("swagger-editor-content", schema);
- });
- // this cdn return html as text/plain, so we must let iframe load it as html
- ajaxGet("https://cdn.jsdelivr.net/npm/swagger-editor-dist@3.6.24/index.html",
- function (html) {
- html = html.replace('<style>',
- '<base href="https://cdn.jsdelivr.net/npm/swagger-editor-dist@3.6.24/">\n'
- + ' <style>\n'
- + ' .swagger-ui .info .title {'
- + ' word-break: break-all;\n'
- + ' }\n');
- frame.location = getBlobURL(html, "text/html");
- });
-}
-
-function clickShowSchema(event) {
- var schemaId = event.target.innerText;
- localStorage.setItem("schemaId", schemaId);
-
- var eleFormat = document.getElementById("schema-format");
- var format = eleFormat.options[eleFormat.selectedIndex].value;
- var url = "schemas/" + schemaId + "?download=false&format=" + format;
- if (format == "SWAGGER") {
- showSchemaAsSwagger(url);
- return;
- }
-
- if (format == "HTML") {
- frame.location = url;
- }
-}
-
-function clickDownloadSchema(event) {
- var schemaId = event.target.previousElementSibling.innerText;
- var eleFormat = document.getElementById("schema-format");
- var format = eleFormat.options[eleFormat.selectedIndex].value;
-
- window.location = "schemas/" + schemaId + "?download=true&format=" + format;
-}
-
-function clickDownloadAllSchemas(event) {
- var eleFormat = document.getElementById("schema-format");
- var format = eleFormat.options[eleFormat.selectedIndex].value;
-
- window.location = "download/schemas?format=" + format;
-}
\ No newline at end of file
diff --git a/inspector/src/main/resources/webroot/static/tree/tree.css b/inspector/src/main/resources/webroot/static/tree/tree.css
deleted file mode 100644
index 6635a2144..000000000
--- a/inspector/src/main/resources/webroot/static/tree/tree.css
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-tree {
- display: block;
- font-family: serif;
-}
-
-tree-node {
- display: block;
- border-left: 1px solid #777;
- position: relative;
-}
-
-tree > tree-node {
- border-left: 0px;
-}
-
-tree-node:last-child:after {
- border-left: 1px solid white;
- display: block;
- height: 50%;
- position: absolute;
- left: -1px;
- top: 50%;
- content: '';
-}
-
-tree-node:before {
- position: absolute;
- display: block;
- top: 50%;
- height: 1px;
- width: 10px;
- background-color: #777;
- content: '';
-}
-
-tree > tree-node:before {
- display: none;
-}
-
-tree-face {
- display: flex;
- justify-content: space-between;
- padding: 2px 0 2px 4px;
-}
-
-tree-children tree-face {
- padding: 2px 0 2px 8px;
-}
-
-tree-node-open-close {
- display: block;
- flex-shrink: 0;
- align-self: center;
-
- background: gray;
- color: white;
- width: 16px;
- height: 16px;
- border-radius: 16px;
- line-height: 16px;
- text-align: center;
-}
-
-tree-node-open-close:before {
- content: "+";
-}
-
-tree-node[expanded=true] > tree-face > tree-node-open-close:before {
- content: "";
- display: block;
- width: 8px;
- height: 1px;
- margin: 8px 0 0 4px;
- background-color: white;
-}
-
-tree-node[expanded=false] > tree-children {
- display: none;
-}
-
-tree-label {
- display: block;
- width: 100%;
- margin-left: 4px;
- cursor: pointer;
- word-break: break-all;
-}
-
-tree-label:hover {
- color: #888;
-}
-
-tree-node.active > tree-face > tree-label {
- background-color: #ccc;
-}
-
-tree-children {
- margin-left: 10px;
- display: block;
-}
diff --git a/inspector/src/main/resources/webroot/static/tree/tree.js b/inspector/src/main/resources/webroot/static/tree/tree.js
deleted file mode 100644
index 2fda4cc8b..000000000
--- a/inspector/src/main/resources/webroot/static/tree/tree.js
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-function Tree(id) {
- var tree = this;
- this.eleTree = document.getElementById(id);
- this.eleTree.onclick = function (event) {
- tree.onTreeClicked(event);
- };
- this.activeTreeNode = null;
- this.configId = id + "-config";
-
- var defaultConfig = {
- activeNodeId: null,
- expanded: {}
- };
- this.config = Object.assign(defaultConfig,
- JSON.parse(localStorage.getItem(this.configId)));
-}
-
-Tree.prototype.init = function () {
- // restore expanded
- for (var id in this.config.expanded) {
- var ele = document.getElementById(id);
- if (ele != null) {
- ele.setAttribute("expanded", this.config.expanded[id]);
- }
- }
-
- // click active node
- this.clickActiveTreeNode();
-}
-
-Tree.prototype.clickActiveTreeNode = function () {
- if (this.config.activeNodeId != null) {
- var treeNode = document.getElementById(this.config.activeNodeId);
- if (treeNode != null) {
- treeNode.querySelector(":scope > tree-face > tree-label").click();
- return;
- }
- }
-
- var treeLabel = this.eleTree.querySelector("tree-node:not([no-action]) > tree-face > tree-label");
- if (treeLabel != null) {
- treeLabel.click();
- }
-}
-
-Tree.prototype.saveConfig = function () {
- localStorage.setItem(this.configId, JSON.stringify(this.config));
-}
-
-Tree.prototype.onTreeClicked = function (event) {
- if (event.target.localName == "tree-label") {
- this.onTreeLabelClicked(event);
- return;
- }
-
- if (event.target.localName == "tree-node-open-close") {
- this.onTreeNodeOpenCloseClicked(event);
- return;
- }
-}
-
-Tree.prototype.onTreeNodeOpenCloseClicked = function (event) {
- var treeNode = event.target.parentElement.parentElement;
- var expanded = treeNode.getAttribute("expanded") == "true";
- expanded = !expanded;
- treeNode.setAttribute("expanded", expanded);
-
- var id = treeNode.getAttribute("id");
- if (id != null) {
- this.config.expanded[id] = expanded;
- this.saveConfig();
- }
-}
-
-Tree.prototype.onTreeLabelClicked = function (event) {
- var treeNode = event.target.parentElement.parentElement;
- if (treeNode.hasAttribute("no-action")) {
- return;
- }
-
- // switch active status
- if (this.activeTreeNode != null) {
- this.activeTreeNode.classList.remove("active");
- }
- this.activeTreeNode = treeNode;
- this.activeTreeNode.classList.add("active");
-
- // save status
- var id = this.activeTreeNode.getAttribute("id");
- if (id != null) {
- this.config.activeNodeId = id;
- this.saveConfig();
- }
-}
diff --git a/inspector/src/main/resources/webroot/static/welcome.html b/inspector/src/main/resources/webroot/static/welcome.html
deleted file mode 100644
index 9e364d9bd..000000000
--- a/inspector/src/main/resources/webroot/static/welcome.html
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<!DOCTYPE html>
-<html lang="en">
-<body>
-welcome
-</body>
-</html>
\ No newline at end of file
diff --git a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
deleted file mode 100644
index 9203082dd..000000000
--- a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorBootListener.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import org.apache.servicecomb.core.BootListener.BootEvent;
-import org.apache.servicecomb.core.BootListener.EventType;
-import org.apache.servicecomb.core.SCBEngine;
-import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.core.definition.MicroserviceMeta;
-import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.springframework.core.env.Environment;
-
-import io.vertx.core.file.impl.FileResolverImpl;
-
-public class TestInspectorBootListener {
- Environment environment = Mockito.mock(Environment.class);
-
- @BeforeEach
- public void setUp() {
- Mockito.when(environment.getProperty("servicecomb.transport.eventloop.size", int.class, -1))
- .thenReturn(-1);
- Mockito.when(environment.getProperty(FileResolverImpl.DISABLE_CP_RESOLVING_PROP_NAME, boolean.class, true))
- .thenReturn(true);
- LegacyPropertyFactory.setEnvironment(environment);
- }
-
- @Test
- public void getOrder() {
- Assertions.assertEquals(Short.MAX_VALUE, new InspectorBootListener(null).getOrder());
- }
-
- @Test
- public void filterEvent() {
- BootEvent event = new BootEvent();
- InspectorBootListener listener = new InspectorBootListener(new InspectorConfig());
-
- try (LogCollector logCollector = new LogCollector()) {
- for (EventType eventType : EventType.values()) {
- if (!EventType.AFTER_TRANSPORT.equals(eventType)) {
- event.setEventType(eventType);
- listener.onBootEvent(event);
- }
- }
-
- Assertions.assertTrue(logCollector.getEvents().isEmpty());
- }
- }
-
- @Test
- public void disabled() {
- SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
- scbEngine.setProducerMicroserviceMeta(new MicroserviceMeta(scbEngine,
- "app", "ms", false));
-
- InspectorConfig inspectorConfig = new InspectorConfig()
- .setEnabled(false);
- new InspectorBootListener(inspectorConfig)
- .onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
-
- Assertions.assertNull(scbEngine.getProducerMicroserviceMeta().findSchemaMeta("inspector"));
- }
-}
diff --git a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
deleted file mode 100644
index b99d6a58d..000000000
--- a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.inspector.internal;
-
-import static org.apache.servicecomb.core.CoreConst.RESTFUL;
-import static org.apache.servicecomb.core.SCBEngine.CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC;
-import static org.apache.servicecomb.core.SCBEngine.DEFAULT_TURN_DOWN_STATUS_WAIT_SEC;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.core.SCBEngine;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
-import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
-import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
-import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
-import org.apache.servicecomb.inspector.internal.swagger.SchemaFormat;
-import org.apache.servicecomb.registry.definition.DefinitionConst;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.apache.servicecomb.transport.rest.servlet.ServletRestTransport;
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledForJreRange;
-import org.junit.jupiter.api.condition.JRE;
-import org.mockito.Mockito;
-import org.springframework.core.env.Environment;
-
-import io.vertx.core.file.impl.FileResolverImpl;
-import jakarta.servlet.http.Part;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.Response.Status;
-
-public class TestInspectorImpl {
- static Map<String, String> schemas = new LinkedHashMap<>();
-
- static InspectorImpl inspector;
-
- @BeforeAll
- public static void setup() throws IOException {
- schemas.put("schema1", IOUtils
- .toString(TestInspectorImpl.class.getClassLoader().getResource("schema1.yaml"), StandardCharsets.UTF_8));
- schemas.put("schema2", IOUtils
- .toString(TestInspectorImpl.class.getClassLoader().getResource("schema2.yaml"), StandardCharsets.UTF_8));
- }
-
- Environment environment = Mockito.mock(Environment.class);
-
- @BeforeEach
- public void setUp() {
- inspector = initInspector(null);
- LegacyPropertyFactory.setEnvironment(environment);
- }
-
- private InspectorImpl initInspector(String urlPrefix) {
- SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
- scbEngine.setEnvironment(environment);
- Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
- long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
- scbEngine.getTransportManager().clearTransportBeforeInit();
-
- if (StringUtils.isNotEmpty(urlPrefix)) {
- Map<String, Transport> transportMap = scbEngine.getTransportManager().getTransportMap();
- ServletRestTransport servletRestTransport = new ServletRestTransport();
- servletRestTransport.setEnvironment(environment);
- transportMap.put(RESTFUL, servletRestTransport);
- ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, urlPrefix);
- }
-
- scbEngine.run();
- InspectorImpl inspector = new InspectorImpl()
- .setSchemas(schemas);
- inspector.correctBasePathForOnlineTest(scbEngine);
- return inspector;
- }
-
- @AfterAll
- public static void teardown() {
- SCBEngine.getInstance().destroy();
- ClassLoaderScopeContext.clearClassLoaderScopeProperty();
- }
-
- private Map<String, String> unzip(InputStream is) throws IOException {
- Map<String, String> result = new LinkedHashMap<>();
- ZipInputStream zis = new ZipInputStream(is);
- for (; ; ) {
- ZipEntry zipEntry = zis.getNextEntry();
- if (zipEntry == null) {
- zis.close();
- return result;
- }
-
- result.put(zipEntry.getName(), IOUtils.toString(zis, StandardCharsets.UTF_8));
- }
- }
-
- @Test
- public void getSchemaIds() {
- MatcherAssert.assertThat(inspector.getSchemaIds(), Matchers.contains("schema1", "schema2"));
- }
-
- @Test
- public void downloadSchemas_default_to_swagger() throws IOException {
- testDownloadSchemasSwagger(null);
- }
-
- @Test
- public void downloadSchemas_swagger() throws IOException {
- testDownloadSchemasSwagger(SchemaFormat.SWAGGER);
- }
-
- private void testDownloadSchemasSwagger(SchemaFormat format) throws IOException {
- inspector.setServiceName("ms");
-
- Response response = inspector.downloadSchemas(format);
- Part part = response.getResult();
- Assertions.assertEquals("ms.yaml.zip", part.getSubmittedFileName());
-
- try (InputStream is = part.getInputStream()) {
- Map<String, String> unziped = unzip(is);
-
- Assertions.assertEquals(schemas.size(), unziped.size());
- Assertions.assertEquals(schemas.get("schema1"), unziped.get("schema1.yaml"));
- Assertions.assertEquals(schemas.get("schema2"), unziped.get("schema2.yaml"));
- }
- }
-
- @Test
- @EnabledForJreRange(min = JRE.JAVA_9)
- public void downloadSchemas_failed() {
- SchemaFormat format = Mockito.spy(SchemaFormat.SWAGGER);
- Mockito.doThrow(new RuntimeExceptionWithoutStackTrace("zip failed.")).when(format).getSuffix();
-
- try (LogCollector logCollector = new LogCollector()) {
- Response response = inspector.downloadSchemas(format);
-
- Assertions.assertEquals("failed to create schemas zip file, format=SWAGGER.",
- logCollector.getLastEvents().getMessage().getFormattedMessage());
-
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(Status.INTERNAL_SERVER_ERROR, invocationException.getStatus());
- Assertions.assertEquals("failed to create schemas zip file, format=SWAGGER.",
- ((CommonExceptionData) invocationException.getErrorData()).getMessage());
- Assertions.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
- Assertions.assertEquals(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), response.getReasonPhrase());
- }
- }
-
- @Test
- public void getSchemaContentById_notExist() {
- Response response = inspector.getSchemaContentById("notExist", null, false);
-
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(Status.NOT_FOUND, invocationException.getStatus());
- Assertions.assertEquals(Status.NOT_FOUND.getReasonPhrase(),
- ((CommonExceptionData) invocationException.getErrorData()).getMessage());
- Assertions.assertEquals(404, response.getStatusCode());
- Assertions.assertEquals("Not Found", response.getReasonPhrase());
- }
-
- @Test
- public void getSchemaContentById_view_swagger() throws IOException {
- testViewSwaggerById("schema1", null);
- testViewSwaggerById("schema1", SchemaFormat.SWAGGER);
- testViewSwaggerById("schema2", null);
- testViewSwaggerById("schema2", SchemaFormat.SWAGGER);
- }
-
- private void testViewSwaggerById(String schemaId, SchemaFormat format) throws IOException {
- Response response = inspector.getSchemaContentById(schemaId, format, false);
-
- Part part = response.getResult();
- Assertions.assertEquals(schemaId + ".yaml", part.getSubmittedFileName());
- Assertions.assertEquals("inline", response.getHeader(HttpHeaders.CONTENT_DISPOSITION));
- Assertions.assertEquals(MediaType.TEXT_HTML, response.getHeader(HttpHeaders.CONTENT_TYPE));
-
- try (InputStream is = part.getInputStream()) {
- Assertions.assertEquals(schemas.get(schemaId), IOUtils.toString(is, StandardCharsets.UTF_8));
- }
- }
-
- @Test
- public void getSchemaContentById_download_swagger() throws IOException {
- testDownloadSwaggerById("schema1", null);
- testDownloadSwaggerById("schema1", SchemaFormat.SWAGGER);
- testDownloadSwaggerById("schema2", null);
- testDownloadSwaggerById("schema2", SchemaFormat.SWAGGER);
- }
-
- private void testDownloadSwaggerById(String schemaId, SchemaFormat format) throws IOException {
- Response response = inspector.getSchemaContentById(schemaId, format, true);
-
- Part part = response.getResult();
- Assertions.assertEquals(schemaId + ".yaml", part.getSubmittedFileName());
- Assertions.assertNull(response.getHeader(HttpHeaders.CONTENT_DISPOSITION));
- Assertions.assertEquals(MediaType.TEXT_HTML, response.getHeader(HttpHeaders.CONTENT_TYPE));
-
- try (InputStream is = part.getInputStream()) {
- Assertions.assertEquals(schemas.get(schemaId), IOUtils.toString(is, StandardCharsets.UTF_8));
- }
- }
-
- @Test
- public void getStaticResource_notExist() throws IOException {
- Response response = inspector.getStaticResource("notExist");
-
- InvocationException invocationException = response.getResult();
- Assertions.assertEquals(Status.NOT_FOUND, invocationException.getStatus());
- Assertions.assertEquals(Status.NOT_FOUND.getReasonPhrase(),
- ((CommonExceptionData) invocationException.getErrorData()).getMessage());
- Assertions.assertEquals(404, response.getStatusCode());
- Assertions.assertEquals("Not Found", response.getReasonPhrase());
- }
-
- @Test
- public void getStaticResource() throws IOException {
- Response response = inspector.getStaticResource("index.html");
-
- Part part = response.getResult();
- Assertions.assertEquals("inline", response.getHeader(HttpHeaders.CONTENT_DISPOSITION));
- Assertions.assertEquals(MediaType.TEXT_HTML, response.getHeader(HttpHeaders.CONTENT_TYPE));
-
- try (InputStream is = part.getInputStream()) {
- Assertions.assertTrue(IOUtils.toString(is, StandardCharsets.UTF_8).endsWith("</html>"));
- }
- }
-
- @Test
- public void urlPrefix() {
- Mockito.when(environment.getProperty("servicecomb.transport.eventloop.size", int.class, -1))
- .thenReturn(-1);
- Mockito.when(environment.getProperty(FileResolverImpl.DISABLE_CP_RESOLVING_PROP_NAME, boolean.class, true))
- .thenReturn(true);
- InspectorImpl inspector = initInspector("/webroot/rest");
-
- Map<String, String> schemas = inspector.getSchemas();
- Assertions.assertTrue(schemas.get("schema1").indexOf("/webroot/rest/metrics") > 0);
- }
-}
diff --git a/inspector/src/test/resources/microservice.yaml b/inspector/src/test/resources/microservice.yaml
deleted file mode 100644
index 4db1321ba..000000000
--- a/inspector/src/test/resources/microservice.yaml
+++ /dev/null
@@ -1,23 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-servicecomb:
- filter-chains:
- consumer:
- default: empty
- producer:
- default: empty
\ No newline at end of file
diff --git a/inspector/src/test/resources/schema1.yaml b/inspector/src/test/resources/schema1.yaml
deleted file mode 100644
index 527b8fcd3..000000000
--- a/inspector/src/test/resources/schema1.yaml
+++ /dev/null
@@ -1,61 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-openapi: 3.0.1
-info:
- title: swagger definition for org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher
- version: 1.0.0
-servers:
- - url: /metrics
-paths:
- /:
- get:
- operationId: checkHealth
- responses:
- "200":
- description: response of 200
- content:
- application/json:
- schema:
- type: boolean
- /details:
- get:
- operationId: checkHealthDetails
- responses:
- "200":
- description: response of 200
- content:
- application/json:
- schema:
- type: object
- additionalProperties:
- $ref: '#/components/schemas/HealthCheckResult'
-components:
- schemas:
- HealthCheckResult:
- type: object
- properties:
- healthy:
- type: boolean
- information:
- type: string
- extraData:
- type: string
- timestamp:
- type: integer
- format: int64
- x-java-class: org.apache.servicecomb.foundation.metrics.health.HealthCheckResult
diff --git a/inspector/src/test/resources/schema2.yaml b/inspector/src/test/resources/schema2.yaml
deleted file mode 100644
index 527b8fcd3..000000000
--- a/inspector/src/test/resources/schema2.yaml
+++ /dev/null
@@ -1,61 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-openapi: 3.0.1
-info:
- title: swagger definition for org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher
- version: 1.0.0
-servers:
- - url: /metrics
-paths:
- /:
- get:
- operationId: checkHealth
- responses:
- "200":
- description: response of 200
- content:
- application/json:
- schema:
- type: boolean
- /details:
- get:
- operationId: checkHealthDetails
- responses:
- "200":
- description: response of 200
- content:
- application/json:
- schema:
- type: object
- additionalProperties:
- $ref: '#/components/schemas/HealthCheckResult'
-components:
- schemas:
- HealthCheckResult:
- type: object
- properties:
- healthy:
- type: boolean
- information:
- type: string
- extraData:
- type: string
- timestamp:
- type: integer
- format: int64
- x-java-class: org.apache.servicecomb.foundation.metrics.health.HealthCheckResult
diff --git a/pom.xml b/pom.xml
index 7868e523b..b5c2f97fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -151,7 +151,6 @@
<module>metrics</module>
<module>dynamic-config</module>
<module>spring-boot</module>
- <module>inspector</module>
<module>solutions</module>
<module>clients</module>
<module>governance</module>
[servicecomb-java-chassis] 11/25: [SCB-2008]remove archaius dependency: nacos adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 3e24ad182d9c76b8ac6d5f7faba637acdd0504c4
Author: liubao <bi...@qq.com>
AuthorDate: Wed Sep 27 11:26:01 2023 +0800
[SCB-2008]remove archaius dependency: nacos adapter
---
.../rest/filter/inner/RestServerCodecFilter.java | 2 +-
.../core/ConfigurationSpringInitializer.java | 192 ++-------------------
.../core/ServiceCombCoreConfiguration.java | 8 +-
.../core/TestConfigurationSpringInitializer.java | 92 +---------
.../nacos/{client => }/ConfigurationAction.java | 2 +-
.../config/nacos/{client => }/NacosClient.java | 38 ++--
.../config/nacos/{client => }/NacosConfig.java | 27 ++-
.../config/nacos/NacosConfigConfiguration.java} | 26 ++-
...Impl.java => NacosDynamicPropertiesSource.java} | 100 +++--------
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 ++
.../config/nacos/{client => }/NacosClientTest.java | 13 +-
.../sources/NacosConfigurationSourceImplTest.java | 74 --------
.../ConfigurationSpringBootInitializer.java | 2 +-
13 files changed, 116 insertions(+), 478 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
index fd6344676..614e4789f 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
@@ -116,7 +116,7 @@ public class RestServerCodecFilter implements ProviderFilter {
public static CompletableFuture<Response> encodeResponse(Response response, boolean download,
ProduceProcessor produceProcessor, HttpServletResponseEx responseEx) {
responseEx.setStatus(response.getStatusCode());
- copyHeadersToHttpResponse(response.getHeaders(), responseEx);
+ copyHeadersToHttpResponse(response.getHeaders(), responseEx);
if (download) {
return CompletableFuture.completedFuture(response);
diff --git a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
index b1fe6adc3..dc602b47d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
+++ b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
@@ -19,24 +19,16 @@ package org.apache.servicecomb.core;
import java.io.IOException;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.ConfigMapping;
-import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.DynamicPropertiesSource;
import org.apache.servicecomb.config.YAMLUtil;
import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
-import org.apache.servicecomb.config.event.DynamicConfigurationChangedEvent;
-import org.apache.servicecomb.config.event.RefreshGovernanceConfigurationEvent;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.apache.servicecomb.foundation.bootstrap.BootStrapService;
-import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,38 +36,18 @@ import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered;
-import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
-import org.springframework.core.env.PropertySource;
-
-import com.google.common.eventbus.Subscribe;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.WatchedUpdateResult;
/**
- * Adapt spring PropertySource and Archaius Configuration
- * spring vs archaius
- * (add) | dynamic(configcenter)
- * system property | system property
- * environment | environment
- * *properties/*.yml | (add)
- * (add) | microservice.yaml
- *
- * add dynamic configuration, microserive.yaml to spring, add *properties/*.yml to archaius
- *
- * NOTICE: we are not duplicate spring system property and environment property source, this will cause some problem
- * related to precedence of a KEY-VAlUE. That is cse.test in dynamic config may not override servicecomb.test in yml.
- * Users need to use the same key as what is in config file to override.
+ * Add dynamic configuration, microserive.yaml to spring
*/
public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderConfigurer implements EnvironmentAware {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationSpringInitializer.class);
- public static final String EXTRA_CONFIG_SOURCE_PREFIX = "extraConfig-";
-
public static final String MICROSERVICE_PROPERTY_SOURCE_NAME = "microservice.yaml";
public static final String MAPPING_PROPERTY_SOURCE_NAME = "mapping.yaml";
@@ -92,13 +64,12 @@ public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderCo
private final List<BootStrapService> bootStrapServices = SPIServiceUtils.getSortedService(BootStrapService.class);
- private final Map<String, Object> dynamicData = new ConcurrentHashMap<>();
+ private final List<DynamicPropertiesSource<?>> dynamicPropertiesSources;
- private ConfigCenterConfigurationSource configCenterConfigurationSource;
-
- public ConfigurationSpringInitializer() {
+ public ConfigurationSpringInitializer(List<DynamicPropertiesSource<?>> dynamicPropertiesSources) {
setOrder(Ordered.LOWEST_PRECEDENCE / 2);
setIgnoreUnresolvablePlaceholders(true);
+ this.dynamicPropertiesSources = dynamicPropertiesSources;
}
/**
@@ -112,49 +83,14 @@ public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderCo
return;
}
- syncFromSpring(environment);
- syncToSpring(environment);
+ addMicroserviceDefinitions(environment);
startupBootStrapService(environment);
- // watch configuration changes
- EventManager.register(this);
- configCenterConfigurationSource = ConfigUtil.installDynamicConfig(environment);
- addDynamicConfigurationToSpring(environment, configCenterConfigurationSource);
- }
-
- @Subscribe
- public void onConfigurationDataChanged(DynamicConfigurationChangedEvent event) {
- try {
- WatchedUpdateResult data = event.getEvent();
- if (data.getDeleted() != null) {
- data.getDeleted().forEach((k, v) -> dynamicData.remove(k));
- }
- if (data.getAdded() != null) {
- dynamicData.putAll(data.getAdded());
- }
- if (data.getChanged() != null) {
- dynamicData.putAll(data.getChanged());
- }
- } catch (Exception e) {
- LOGGER.error("", e);
- }
- EventManager.post(new RefreshGovernanceConfigurationEvent(event.getEvent()));
- }
-
- private void syncFromSpring(Environment environment) {
- String environmentName = generateNameForEnvironment(environment);
- LOGGER.info("Environment received, will get configurations from [{}].", environmentName);
-
- Map<String, Object> extraConfig = getAllProperties(environment);
- ConfigUtil.addExtraConfig(EXTRA_CONFIG_SOURCE_PREFIX + environmentName, extraConfig);
+ addDynamicConfigurationToSpring(environment);
}
- public static void syncToSpring(Environment environment) {
- if (isExternalInit()) {
- return;
- }
-
+ public static void addMicroserviceDefinitions(Environment environment) {
addMicroserviceYAMLToSpring(environment);
addMappingToSpring(environment);
}
@@ -229,17 +165,15 @@ public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderCo
propertySources.addFirst(new MapPropertySource(MAPPING_PROPERTY_SOURCE_NAME, mappings));
}
- private void addDynamicConfigurationToSpring(Environment environment,
- ConfigCenterConfigurationSource configCenterConfigurationSource) {
+ private void addDynamicConfigurationToSpring(Environment environment) {
if (!(environment instanceof ConfigurableEnvironment)) {
return;
}
- ConfigurableEnvironment ce = (ConfigurableEnvironment) environment;
- if (configCenterConfigurationSource == null) {
- return;
- }
try {
- ce.getPropertySources().addFirst(new MapPropertySource("dynamic-source", dynamicData));
+ for (DynamicPropertiesSource<?> dynamicPropertiesSource : dynamicPropertiesSources) {
+ ((ConfigurableEnvironment) environment).getPropertySources()
+ .addFirst(dynamicPropertiesSource.create(environment));
+ }
} catch (Exception e) {
if (environment.getProperty(CoreConst.PRINT_SENSITIVE_ERROR_MESSAGE, boolean.class,
false)) {
@@ -252,104 +186,6 @@ public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderCo
@Override
protected Properties mergeProperties() throws IOException {
- Properties properties = super.mergeProperties();
- if (isExternalInit()) {
- return properties;
- }
-
- AbstractConfiguration config = ConfigurationManager.getConfigInstance();
- Iterator<String> iterator = config.getKeys();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = config.getProperty(key);
- properties.put(key, value);
- }
- return properties;
- }
-
- /**
- * Try to get a name for identifying the environment.
- * @param environment the target that the name is generated for.
- * @return The generated name for the environment.
- */
- private String generateNameForEnvironment(Environment environment) {
- String environmentName = environment.getProperty("spring.config.name");
- if (!StringUtils.isEmpty(environmentName)) {
- return environmentName;
- }
-
- environmentName = environment.getProperty("spring.application.name");
- if (!StringUtils.isEmpty(environmentName)) {
- return environmentName;
- }
-
- return environment.getClass().getName() + "@" + environment.hashCode();
- }
-
- /**
- * Traversal all {@link PropertySource} of {@link ConfigurableEnvironment}, and try to get all properties.
- */
- private Map<String, Object> getAllProperties(Environment environment) {
- Map<String, Object> configFromSpringBoot = new HashMap<>();
-
- if (!(environment instanceof ConfigurableEnvironment)) {
- return configFromSpringBoot;
- }
-
- ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment;
-
- if (ignoreResolveFailure()) {
- configurableEnvironment.setIgnoreUnresolvableNestedPlaceholders(true);
- }
-
- for (PropertySource<?> propertySource : configurableEnvironment.getPropertySources()) {
- if (MICROSERVICE_PROPERTY_SOURCE_NAME.equals(propertySource.getName())
- || MAPPING_PROPERTY_SOURCE_NAME.equals(propertySource.getName())) {
- continue;
- }
- getProperties(configurableEnvironment, propertySource, configFromSpringBoot);
- }
- return configFromSpringBoot;
- }
-
- /**
- * Get property names from {@link EnumerablePropertySource}, and get property value from {@link ConfigurableEnvironment#getProperty(String)}
- */
- private void getProperties(ConfigurableEnvironment environment, PropertySource<?> propertySource,
- Map<String, Object> configFromSpringBoot) {
- if (propertySource instanceof CompositePropertySource) {
- // recursively get EnumerablePropertySource
- CompositePropertySource compositePropertySource = (CompositePropertySource) propertySource;
- compositePropertySource.getPropertySources().forEach(ps -> getProperties(environment, ps, configFromSpringBoot));
- return;
- }
- if (propertySource instanceof EnumerablePropertySource) {
- EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
- for (String propertyName : enumerablePropertySource.getPropertyNames()) {
- try {
- Object propertyValue = environment.getProperty(propertyName, Object.class);
- if (propertyValue == null) {
- LOGGER.error(
- "The value of a configuration item is null, please check whether there is any impact, config item key: {}",
- propertyName);
- continue;
- }
- configFromSpringBoot.put(propertyName, propertyValue);
- } catch (Exception e) {
- throw new RuntimeException(
- "set up spring property source failed.If you still want to start up the application and ignore errors, you can set servicecomb.config.ignoreResolveFailure to true.",
- e);
- }
- }
- return;
- }
-
- LOGGER.debug("a none EnumerablePropertySource is ignored, propertySourceName = [{}]", propertySource.getName());
- }
-
- private boolean ignoreResolveFailure() {
- return ConfigUtil
- .createLocalConfig()
- .getBoolean("servicecomb.config.ignoreResolveFailure", false);
+ return super.mergeProperties();
}
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
index 55338ea25..74b8f075f 100644
--- a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
+++ b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
@@ -16,6 +16,9 @@
*/
package org.apache.servicecomb.core;
+import java.util.List;
+
+import org.apache.servicecomb.config.DynamicPropertiesSource;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.core.bootup.FilterChainCollector;
import org.apache.servicecomb.core.bootup.ServiceInformationCollector;
@@ -33,8 +36,9 @@ import org.springframework.core.env.Environment;
@SuppressWarnings("unused")
public class ServiceCombCoreConfiguration {
@Bean
- public ConfigurationSpringInitializer configurationSpringInitializer() {
- return new ConfigurationSpringInitializer();
+ public ConfigurationSpringInitializer configurationSpringInitializer(
+ List<DynamicPropertiesSource<?>> dynamicPropertiesSources) {
+ return new ConfigurationSpringInitializer(dynamicPropertiesSources);
}
@Bean
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
index e663bf21f..e6c448657 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
@@ -16,9 +16,9 @@
*/
package org.apache.servicecomb.core;
-import com.netflix.config.ConfigurationManager;
-import mockit.Deencapsulation;
-import org.apache.commons.configuration.Configuration;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.servicecomb.config.ConfigUtil;
@@ -34,16 +34,8 @@ import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
-import org.springframework.core.env.PropertySource;
-import org.springframework.core.env.StandardEnvironment;
-import org.springframework.core.env.SystemEnvironmentPropertySource;
import org.springframework.jndi.JndiPropertySource;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
public class TestConfigurationSpringInitializer {
@BeforeEach
public void beforeTest() {
@@ -61,23 +53,6 @@ public class TestConfigurationSpringInitializer {
ArchaiusUtils.resetConfig();
}
- @Test
- public void testAll() {
- ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();
- ConfigUtil.installDynamicConfig();
-
- Object o = ConfigUtil.getProperty("zq");
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
- Assertions.assertEquals(3, listO.size());
- Assertions.assertNull(ConfigUtil.getProperty("notExist"));
-
- Configuration instance = ConfigurationManager.getConfigInstance();
- ConfigUtil.installDynamicConfig();
- // must not reinstall
- Assertions.assertEquals(instance, ConfigurationManager.getConfigInstance());
- }
-
@Test
public void testSetEnvironment() {
ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
@@ -146,18 +121,6 @@ public class TestConfigurationSpringInitializer {
}
return value;
}).when(environment).getProperty(ArgumentMatchers.anyString(), ArgumentMatchers.eq(Object.class));
-
- new ConfigurationSpringInitializer().setEnvironment(environment);
-
- Map<String, Map<String, Object>> extraLocalConfig = getExtraConfigMapFromConfigUtil();
- Assertions.assertFalse(extraLocalConfig.isEmpty());
- Map<String, Object> extraProperties = extraLocalConfig
- .get(ConfigurationSpringInitializer.EXTRA_CONFIG_SOURCE_PREFIX + environment.getClass().getName() + "@"
- + environment.hashCode());
- Assertions.assertNotNull(extraLocalConfig);
- for (Entry<String, String> entry : propertyMap.entrySet()) {
- Assertions.assertEquals(entry.getValue(), extraProperties.get(entry.getKey()));
- }
}
@Test
@@ -191,54 +154,5 @@ public class TestConfigurationSpringInitializer {
propertySources2.addFirst(new MapPropertySource("mapPropertySource2", map2));
Mockito.when(environment2.getProperty("key2", Object.class)).thenReturn("value2");
Mockito.when(environment2.getProperty("key2")).thenReturn("value2");
-
- ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();
- configurationSpringInitializer.setEnvironment(environment0);
- configurationSpringInitializer.setEnvironment(environment1);
- configurationSpringInitializer.setEnvironment(environment2);
-
- Map<String, Map<String, Object>> extraConfig = getExtraConfigMapFromConfigUtil();
- Assertions.assertEquals(3, extraConfig.size());
-
- Map<String, Object> extraProperties = extraConfig
- .get(ConfigurationSpringInitializer.EXTRA_CONFIG_SOURCE_PREFIX + "application");
- Assertions.assertEquals(1, extraProperties.size());
- Assertions.assertEquals("application", extraProperties.get("spring.config.name"));
-
- extraProperties = extraConfig.get(ConfigurationSpringInitializer.EXTRA_CONFIG_SOURCE_PREFIX + "bootstrap");
- Assertions.assertEquals(1, extraProperties.size());
- Assertions.assertEquals("bootstrap", extraProperties.get("spring.application.name"));
-
- extraProperties = extraConfig.get(
- ConfigurationSpringInitializer.EXTRA_CONFIG_SOURCE_PREFIX + environment2.getClass().getName() + "@"
- + environment2.hashCode());
- Assertions.assertEquals(1, extraProperties.size());
- Assertions.assertEquals("value2", extraProperties.get("key2"));
- }
-
- @Test
- public void should_throw_exception_when_given_ignoreResolveFailure_false() {
- Assertions.assertThrows(RuntimeException.class, () -> {
- StandardEnvironment environment = newStandardEnvironment();
-
- ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();
- configurationSpringInitializer.setEnvironment(environment);
- });
- }
-
- private Map<String, Map<String, Object>> getExtraConfigMapFromConfigUtil() {
- return Deencapsulation
- .getField(ConfigUtil.class, "EXTRA_CONFIG_MAP");
- }
-
- private StandardEnvironment newStandardEnvironment() {
- Map<String, Object> envProperties = new HashMap<>();
- envProperties.put("IFS-X", "${IFS-X}");
- PropertySource<Map<String, Object>> systemEnvironmentPropertySource = new SystemEnvironmentPropertySource("system-env", envProperties);
-
- StandardEnvironment environment = new StandardEnvironment();
- environment.getPropertySources()
- .addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, systemEnvironmentPropertySource);
- return environment;
}
}
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/ConfigurationAction.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/ConfigurationAction.java
similarity index 94%
rename from dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/ConfigurationAction.java
rename to dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/ConfigurationAction.java
index 3defe34f0..a4dc8f53c 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/ConfigurationAction.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/ConfigurationAction.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.nacos.client;
+package org.apache.servicecomb.config.nacos;
public enum ConfigurationAction {
CREATE,
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosClient.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosClient.java
similarity index 77%
rename from dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosClient.java
rename to dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosClient.java
index 6e02f492c..7d79c52b7 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosClient.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosClient.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.nacos.client;
+package org.apache.servicecomb.config.nacos;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.CREATE;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.DELETE;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.SET;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.CREATE;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.DELETE;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.SET;
import java.util.HashMap;
import java.util.Map;
@@ -28,10 +28,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.config.nacos.archaius.sources.NacosConfigurationSourceImpl.UpdateHandler;
+import org.apache.servicecomb.config.nacos.NacosDynamicPropertiesSource.UpdateHandler;
import org.apache.servicecomb.config.parser.Parser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
@@ -45,19 +46,26 @@ public class NacosClient {
private final UpdateHandler updateHandler;
+ private NacosConfig nacosConfig;
+
public NacosClient(UpdateHandler updateHandler) {
this.updateHandler = updateHandler;
}
+ @Autowired
+ public void setNacosConfig(NacosConfig nacosConfig) {
+ this.nacosConfig = nacosConfig;
+ }
+
public void refreshNacosConfig() {
new ConfigRefresh().refreshConfig();
}
class ConfigRefresh {
- Parser contentParser = Parser.findParser(NacosConfig.INSTANCE.getContentType());
+ Parser contentParser = Parser.findParser(nacosConfig.getContentType());
- String keyPrefix = NacosConfig.INSTANCE.getGroup() + "." +
- NacosConfig.INSTANCE.getDataId();
+ String keyPrefix = nacosConfig.getGroup() + "." +
+ nacosConfig.getDataId();
ConfigRefresh() {
}
@@ -65,16 +73,16 @@ public class NacosClient {
@SuppressWarnings("unchecked")
void refreshConfig() {
Properties properties = new Properties();
- properties.put("serverAddr", NacosConfig.INSTANCE.getServerAddr());
- properties.put("namespace", NacosConfig.INSTANCE.getNameSpace());
+ properties.put("serverAddr", nacosConfig.getServerAddr());
+ properties.put("namespace", nacosConfig.getNameSpace());
try {
ConfigService configService = NacosFactory.createConfigService(properties);
- String content = configService.getConfig(NacosConfig.INSTANCE.getDataId(),
- NacosConfig.INSTANCE.getGroup(), 5000);
+ String content = configService.getConfig(nacosConfig.getDataId(),
+ nacosConfig.getGroup(), 5000);
processContent(content);
- configService.addListener(NacosConfig.INSTANCE.getDataId(),
- NacosConfig.INSTANCE.getGroup(), new Listener() {
+ configService.addListener(nacosConfig.getDataId(),
+ nacosConfig.getGroup(), new Listener() {
@Override
public void receiveConfigInfo(String configInfo) {
LOGGER.info("receive from nacos:" + configInfo);
@@ -96,7 +104,7 @@ public class NacosClient {
return;
}
- refreshConfigItems(contentParser.parse(content, keyPrefix, NacosConfig.INSTANCE.getAddPrefix()));
+ refreshConfigItems(contentParser.parse(content, keyPrefix, nacosConfig.getAddPrefix()));
}
private void refreshConfigItems(Map<String, Object> map) {
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosConfig.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfig.java
similarity index 69%
rename from dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosConfig.java
rename to dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfig.java
index 4fb31111c..3e6a40e55 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/client/NacosConfig.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfig.java
@@ -15,15 +15,11 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.nacos.client;
+package org.apache.servicecomb.config.nacos;
-import org.apache.commons.configuration.Configuration;
+import org.springframework.core.env.Environment;
public class NacosConfig {
- public static final NacosConfig INSTANCE = new NacosConfig();
-
- private static Configuration finalConfig;
-
public static final String DATA_ID = "servicecomb.nacos.dataId";
public static final String SERVER_ADDR = "servicecomb.nacos.serverAddr";
@@ -36,34 +32,33 @@ public class NacosConfig {
public static final String CONTENT_TYPE = "servicecomb.nacos.contentType";
- private NacosConfig() {
- }
+ private final Environment environment;
- public static void setConcurrentCompositeConfiguration(Configuration config) {
- finalConfig = config;
+ public NacosConfig(Environment environment) {
+ this.environment = environment;
}
public String getServerAddr() {
- return finalConfig.getString(SERVER_ADDR);
+ return environment.getProperty(SERVER_ADDR);
}
public String getDataId() {
- return finalConfig.getString(DATA_ID);
+ return environment.getProperty(DATA_ID);
}
public String getGroup() {
- return finalConfig.getString(GROUP);
+ return environment.getProperty(GROUP);
}
public String getNameSpace() {
- return finalConfig.getString(NAME_SPACE, "public");
+ return environment.getProperty(NAME_SPACE, "public");
}
public String getContentType() {
- return finalConfig.getString(CONTENT_TYPE, "yaml");
+ return environment.getProperty(CONTENT_TYPE, "yaml");
}
public boolean getAddPrefix() {
- return finalConfig.getBoolean(ADD_PREFIX, true);
+ return environment.getProperty(ADD_PREFIX, boolean.class, true);
}
}
diff --git a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosConfigTest.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfigConfiguration.java
similarity index 54%
rename from dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosConfigTest.java
rename to dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfigConfiguration.java
index 8b82d0d67..bad19c3dc 100644
--- a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosConfigTest.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosConfigConfiguration.java
@@ -14,25 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.config.nacos;
-package org.apache.servicecomb.config.nacos.client;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.env.Environment;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class NacosConfigTest {
- @BeforeAll
- public static void setUpClass() {
- NacosConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
+public class NacosConfigConfiguration {
+ @Bean
+ public NacosConfig nacosConfig(Environment environment) {
+ return new NacosConfig(environment);
}
- @Test
- public void getServiceName() {
- NacosConfig instance = NacosConfig.INSTANCE;
- Assertions.assertEquals("DEFAULT_GROUP", instance.getGroup());
- Assertions.assertEquals("127.0.0.1:8848", instance.getServerAddr());
- Assertions.assertEquals("example", instance.getDataId());
+ @Bean
+ public NacosDynamicPropertiesSource nacosDynamicPropertiesSource() {
+ return new NacosDynamicPropertiesSource();
}
}
diff --git a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImpl.java b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
similarity index 51%
rename from dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImpl.java
rename to dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
index 528553c1e..134a4e035 100644
--- a/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImpl.java
+++ b/dynamic-config/config-nacos/src/main/java/org/apache/servicecomb/config/nacos/NacosDynamicPropertiesSource.java
@@ -14,41 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.config.nacos;
-package org.apache.servicecomb.config.nacos.archaius.sources;
-
-import static com.netflix.config.WatchedUpdateResult.createIncremental;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.CREATE;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.DELETE;
-import static org.apache.servicecomb.config.nacos.client.ConfigurationAction.SET;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.CREATE;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.DELETE;
+import static org.apache.servicecomb.config.nacos.ConfigurationAction.SET;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.ConfigMapping;
-import org.apache.servicecomb.config.nacos.client.ConfigurationAction;
-import org.apache.servicecomb.config.nacos.client.NacosClient;
-import org.apache.servicecomb.config.nacos.client.NacosConfig;
+import org.apache.servicecomb.config.DynamicPropertiesSource;
import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.annotations.VisibleForTesting;
import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-public class NacosConfigurationSourceImpl implements ConfigCenterConfigurationSource {
+public class NacosDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
+ public static final String SOURCE_NAME = "kie";
+
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSource.class);
private final Map<String, Object> valueCache = new ConcurrentHashMap<>();
private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
- public NacosConfigurationSourceImpl() {
+ public NacosDynamicPropertiesSource() {
}
private final UpdateHandler updateHandler = new UpdateHandler();
@@ -58,60 +56,12 @@ public class NacosConfigurationSourceImpl implements ConfigCenterConfigurationSo
return updateHandler;
}
- @Override
- public int getOrder() {
- return ORDER_BASE * 4;
- }
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- if (localConfiguration.getProperty(NacosConfig.SERVER_ADDR) == null) {
- LOGGER.warn("Nacos configuration source is not configured!");
- return false;
- }
- return true;
- }
-
- @Override
- public void init(Configuration localConfiguration) {
- NacosConfig.setConcurrentCompositeConfiguration(localConfiguration);
- init();
- }
-
- private void init() {
+ private void init(Environment environment) {
NacosClient nacosClient = new NacosClient(updateHandler);
nacosClient.refreshNacosConfig();
}
- @Override
- public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.add(watchedUpdateListener);
- }
-
- @Override
- public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.remove(watchedUpdateListener);
- }
-
- private void updateConfiguration(WatchedUpdateResult result) {
- for (WatchedUpdateListener l : listeners) {
- try {
- l.updateConfiguration(result);
- } catch (Throwable ex) {
- LOGGER.error("Error in invoking WatchedUpdateListener", ex);
- }
- }
- }
-
- @Override
- public Map<String, Object> getCurrentData() throws Exception {
- return valueCache;
- }
-
- public List<WatchedUpdateListener> getCurrentListeners() {
- return listeners;
- }
-
public class UpdateHandler {
public void handle(ConfigurationAction action, Map<String, Object> config) {
if (config == null || config.isEmpty()) {
@@ -120,21 +70,10 @@ public class NacosConfigurationSourceImpl implements ConfigCenterConfigurationSo
Map<String, Object> configuration = ConfigMapping.getConvertedMap(config);
if (CREATE.equals(action)) {
valueCache.putAll(configuration);
-
- updateConfiguration(createIncremental(ImmutableMap.copyOf(configuration),
- null,
- null));
} else if (SET.equals(action)) {
valueCache.putAll(configuration);
-
- updateConfiguration(createIncremental(null,
- ImmutableMap.copyOf(configuration),
- null));
} else if (DELETE.equals(action)) {
configuration.keySet().forEach(valueCache::remove);
- updateConfiguration(createIncremental(null,
- null,
- ImmutableMap.copyOf(configuration)));
} else {
LOGGER.error("action: {} is invalid.", action.name());
return;
@@ -142,4 +81,15 @@ public class NacosConfigurationSourceImpl implements ConfigCenterConfigurationSo
LOGGER.warn("Config value cache changed: action:{}; item:{}", action.name(), configuration.keySet());
}
}
+
+ @Override
+ public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
+ init(environment);
+ return new MapPropertySource(SOURCE_NAME, valueCache);
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
}
diff --git a/dynamic-config/config-nacos/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/dynamic-config/config-nacos/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 000000000..3f7419678
--- /dev/null
+++ b/dynamic-config/config-nacos/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+org.apache.servicecomb.config.nacos.NacosConfigConfiguration
diff --git a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosClientTest.java b/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
similarity index 78%
rename from dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosClientTest.java
rename to dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
index 3a49bbc47..125d80a30 100644
--- a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/client/NacosClientTest.java
+++ b/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
@@ -15,23 +15,16 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.nacos.client;
+package org.apache.servicecomb.config.nacos;
import java.util.HashMap;
import java.util.Map;
-import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.nacos.archaius.sources.NacosConfigurationSourceImpl;
-import org.apache.servicecomb.config.nacos.archaius.sources.NacosConfigurationSourceImpl.UpdateHandler;
+import org.apache.servicecomb.config.nacos.NacosDynamicPropertiesSource.UpdateHandler;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class NacosClientTest {
- @BeforeAll
- public static void setUpClass() {
- NacosConfig.setConcurrentCompositeConfiguration(ConfigUtil.createLocalConfig());
- }
@Test
public void testCompareChangedConfig() {
@@ -39,7 +32,7 @@ public class NacosClientTest {
Map<String, Object> before = new HashMap<>();
Map<String, Object> after = new HashMap<>();
- NacosConfigurationSourceImpl impl = new NacosConfigurationSourceImpl();
+ NacosDynamicPropertiesSource impl = new NacosDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
NacosClient nacosClient = new NacosClient(updateHandler);
diff --git a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImplTest.java b/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImplTest.java
deleted file mode 100644
index aa51be7d8..000000000
--- a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/archaius/sources/NacosConfigurationSourceImplTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.nacos.archaius.sources;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.config.nacos.archaius.sources.NacosConfigurationSourceImpl.UpdateHandler;
-import org.apache.servicecomb.config.nacos.client.ConfigurationAction;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-import com.netflix.config.WatchedUpdateListener;
-
-public class NacosConfigurationSourceImplTest {
- @Test
- public void testCreate() throws Exception {
- NacosConfigurationSourceImpl nacosConfigurationSource = new NacosConfigurationSourceImpl();
- nacosConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getAdded().isEmpty()));
- UpdateHandler updateHandler = nacosConfigurationSource.getUpdateHandler();
- Map<String, Object> createItems = new HashMap<>();
- createItems.put("nacosTestKey", "testValue");
- updateHandler.handle(ConfigurationAction.CREATE, createItems);
- }
-
- @Test
- public void testUpdate() throws Exception {
- NacosConfigurationSourceImpl nacosConfigurationSource = new NacosConfigurationSourceImpl();
- nacosConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getChanged().isEmpty()));
- UpdateHandler updateHandler = nacosConfigurationSource.getUpdateHandler();
- Map<String, Object> updateItems = new HashMap<>();
- updateItems.put("nacosTestKey", "testValue");
- updateHandler.handle(ConfigurationAction.SET, updateItems);
-
- }
-
- @Test
- public void testDelete() throws Exception {
- NacosConfigurationSourceImpl nacosConfigurationSource = new NacosConfigurationSourceImpl();
- nacosConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getDeleted().isEmpty()));
- UpdateHandler updateHandler = nacosConfigurationSource.getUpdateHandler();
- Map<String, Object> deleteItems = new HashMap<>();
- deleteItems.put("nacosTestKey", "testValue");
-
- nacosConfigurationSource.getCurrentData().put("nacosTestKey", "testValue");
- updateHandler.handle(ConfigurationAction.DELETE, deleteItems);
- Assertions.assertTrue(nacosConfigurationSource.getCurrentData().isEmpty());
- }
-
- @Test
- public void testRemoveUpdateListener() {
- NacosConfigurationSourceImpl nacosConfigurationSource = new NacosConfigurationSourceImpl();
- WatchedUpdateListener watchedUpdateListener = Mockito.mock(WatchedUpdateListener.class);
- nacosConfigurationSource.addUpdateListener(watchedUpdateListener);
- nacosConfigurationSource.removeUpdateListener(watchedUpdateListener);
- Assertions.assertTrue(nacosConfigurationSource.getCurrentListeners().isEmpty());
- }
-}
diff --git a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot/starter/ConfigurationSpringBootInitializer.java b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot/starter/ConfigurationSpringBootInitializer.java
index fd36ab455..115fc686f 100644
--- a/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot/starter/ConfigurationSpringBootInitializer.java
+++ b/spring-boot/spring-boot-starters/java-chassis-spring-boot-starter/src/main/java/org/apache/servicecomb/springboot/starter/ConfigurationSpringBootInitializer.java
@@ -29,6 +29,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
public class ConfigurationSpringBootInitializer implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
- ConfigurationSpringInitializer.syncToSpring(environment);
+ ConfigurationSpringInitializer.addMicroserviceDefinitions(environment);
}
}
[servicecomb-java-chassis] 08/25: [SCB-2008]remove archaius dependency: apollo adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit c8c6479228f37466e54a4e07975d46ffb56f4210
Author: liubao <bi...@qq.com>
AuthorDate: Mon Sep 25 17:32:59 2023 +0800
[SCB-2008]remove archaius dependency: apollo adapter
---
.../config/apollo/ApolloConfiguration.java | 28 ++++++++++++++++++++++
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 ++++++++++++++
.../config/apollo/ApolloClientTest.java | 17 ++++++-------
3 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java
new file mode 100644
index 000000000..26dd7a2ee
--- /dev/null
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfiguration.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.config.apollo;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ApolloConfiguration {
+ @Bean
+ public ApolloDynamicPropertiesSource apolloDynamicPropertiesSource() {
+ return new ApolloDynamicPropertiesSource();
+ }
+}
diff --git a/dynamic-config/config-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/dynamic-config/config-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 000000000..31e450534
--- /dev/null
+++ b/dynamic-config/config-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+org.apache.servicecomb.config.apollo.ApolloConfiguration
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
index a531a2ea3..c284a1fbf 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
@@ -21,11 +21,8 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.config.apollo.ApolloClient;
-import org.apache.servicecomb.config.apollo.ApolloConfig;
-import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl;
-import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler;
import org.apache.servicecomb.config.apollo.ApolloClient.ConfigRefresh;
+import org.apache.servicecomb.config.apollo.ApolloDynamicPropertiesSource.UpdateHandler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -53,11 +50,11 @@ public class ApolloClientTest {
ResponseEntity<String> responseEntity = new ResponseEntity<>(
"{\"apollo\":\"mocked\", \"configurations\":{\"timeout\":1000}}", HttpStatus.OK);
Mockito.when(rest.exchange(
- ArgumentMatchers.anyString(),
- ArgumentMatchers.any(HttpMethod.class),
- ArgumentMatchers.<HttpEntity<String>>any(),
- ArgumentMatchers.<Class<String>>any())).thenReturn(responseEntity);
- ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
+ ArgumentMatchers.anyString(),
+ ArgumentMatchers.any(HttpMethod.class),
+ ArgumentMatchers.<HttpEntity<String>>any(),
+ ArgumentMatchers.<Class<String>>any())).thenReturn(responseEntity);
+ ApolloDynamicPropertiesSource impl = new ApolloDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
ConfigRefresh cr = apolloClient.new ConfigRefresh(apolloConfig.getServerUri());
@@ -72,7 +69,7 @@ public class ApolloClientTest {
Map<String, Object> before = new HashMap<>();
Map<String, Object> after = new HashMap<>();
- ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
+ ApolloDynamicPropertiesSource impl = new ApolloDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
[servicecomb-java-chassis] 22/25: [SCB-2008]remove un-maintained jsr305 usages
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 1a9b3ffd7cb8222e54d9ff8a04974cc7dae5dfae
Author: liubao <bi...@qq.com>
AuthorDate: Mon Oct 9 14:59:59 2023 +0800
[SCB-2008]remove un-maintained jsr305 usages
---
.../common/rest/RestProducerInvocationCreator.java | 4 +-
.../rest/RestVertxProducerInvocationCreator.java | 6 +-
.../rest/codec/query/AbstractQueryCodec.java | 7 +-
.../common/rest/codec/query/QueryCodec.java | 12 ++--
.../common/rest/codec/query/QueryCodecMulti.java | 4 +-
.../rest/codec/query/QueryCodecWithDelimiter.java | 7 +-
.../common/rest/codec/query/QueryCodecs.java | 8 +--
.../common/rest/codec/query/QueryCodecsUtils.java | 3 -
.../rest/definition/path/URLPathBuilder.java | 4 +-
.../rest/filter/inner/RestServerCodecFilter.java | 5 +-
.../core/exception/DefaultExceptionProcessor.java | 15 ++--
.../core/exception/ExceptionConverter.java | 7 +-
.../core/exception/ExceptionProcessor.java | 18 +++--
.../servicecomb/core/exception/Exceptions.java | 14 ++--
.../ConnectTimeoutExceptionConverter.java | 6 +-
.../converter/DefaultExceptionConverter.java | 8 +--
.../IllegalArgumentExceptionConverter.java | 7 +-
.../converter/InvocationExceptionConverter.java | 7 +-
.../converter/ServiceCombExceptionConverter.java | 9 ++-
.../converter/TimeoutExceptionConverter.java | 7 +-
.../servicecomb/core/filter/ConsumerFilter.java | 3 -
.../org/apache/servicecomb/core/filter/Filter.java | 3 -
.../servicecomb/core/filter/ProviderFilter.java | 3 -
.../servicecomb/core/filter/impl/EmptyFilter.java | 3 -
.../core/filter/impl/ParameterValidatorFilter.java | 3 -
.../core/filter/impl/ProviderOperationFilter.java | 3 -
.../core/filter/impl/ScheduleFilter.java | 3 -
.../core/provider/consumer/InvokerUtils.java | 6 +-
.../servicecomb/core/exception/ExceptionsTest.java | 6 +-
.../servicecomb/core/filter/SimpleRetryFilter.java | 3 -
...CustomExceptionToProducerResponseConverter.java | 9 ++-
.../service/encrypt/filter/DecodeBodyFilter.java | 3 -
.../encrypt/filter/EdgeSignatureRequestFilter.java | 3 -
.../filter/EdgeSignatureResponseFilter.java | 3 -
.../edge/service/encrypt/filter/UserIdFilter.java | 3 -
.../demo/edge/service/handler/AuthHandler.java | 3 -
.../springboot/pojo/server/handler/MyHandler.java | 3 -
.../demo/springmvc/filter/ProviderTestFilter.java | 3 -
dependencies/default/pom.xml | 18 -----
.../servicecomb/edge/core/EdgeAddHeaderFilter.java | 3 -
.../edge/core/EdgeServerCodecFilter.java | 4 --
.../config/priority/ConfigObjectProperty.java | 4 +-
.../servicecomb/config/DynamicPropertiesTest.java | 8 +--
.../internal/parser/ContentFileReader.java | 4 +-
foundations/foundation-test-scaffolding/pom.xml | 4 --
.../test/scaffolding/config/ArchaiusUtils.java | 83 ----------------------
.../faultinjection/ConsumerAbortFaultFilter.java | 3 -
.../faultinjection/ConsumerDelayFaultFilter.java | 3 -
.../servicecomb/qps/ConsumerFlowControlFilter.java | 3 -
.../servicecomb/qps/ProviderFlowControlFilter.java | 3 -
.../governance/ConsumerInstanceBulkheadFilter.java | 5 +-
.../ConsumerInstanceIsolationFilter.java | 3 -
.../handler/governance/ProviderBulkheadFilter.java | 3 -
.../governance/ProviderCircuitBreakerFilter.java | 3 -
.../governance/ProviderRateLimitingFilter.java | 3 -
.../servicecomb/loadbalance/LoadBalanceFilter.java | 3 -
.../consumer/ConsumerAuthFilter.java | 3 -
.../provider/ProviderAuthFilter.java | 3 -
.../router/custom/RouterAddHeaderFilter.java | 3 -
.../provider/pojo/FilterInvocationCaller.java | 4 +-
.../provider/pojo/definition/PojoConsumerMeta.java | 3 -
.../transport/highway/HighwayClientFilter.java | 3 -
.../highway/HighwayServerCodecFilter.java | 3 -
.../rest/client/RestClientCodecFilter.java | 3 -
.../transport/rest/client/RestClientEncoder.java | 15 ++--
.../client/RestClientRequestParametersImpl.java | 6 +-
.../rest/client/RestClientSenderFilter.java | 3 -
.../RestServletProducerInvocationCreator.java | 6 +-
68 files changed, 80 insertions(+), 359 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
index df5eebc83..60eb56c6f 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreator.java
@@ -23,8 +23,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
@@ -62,7 +60,7 @@ public abstract class RestProducerInvocationCreator implements InvocationCreator
protected ProduceProcessor produceProcessor;
public RestProducerInvocationCreator(MicroserviceMeta microserviceMeta, Endpoint endpoint,
- @Nonnull HttpServletRequestEx requestEx, @Nonnull HttpServletResponseEx responseEx) {
+ HttpServletRequestEx requestEx, HttpServletResponseEx responseEx) {
this.microserviceMeta = microserviceMeta;
this.endpoint = endpoint;
this.requestEx = requestEx;
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestVertxProducerInvocationCreator.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestVertxProducerInvocationCreator.java
index a809f0968..83f14c64e 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestVertxProducerInvocationCreator.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestVertxProducerInvocationCreator.java
@@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.common.rest;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
@@ -29,9 +27,9 @@ import io.vertx.ext.web.RoutingContext;
public class RestVertxProducerInvocationCreator extends RestProducerInvocationCreator {
private final RoutingContext routingContext;
- public RestVertxProducerInvocationCreator(@Nonnull RoutingContext routingContext,
+ public RestVertxProducerInvocationCreator(RoutingContext routingContext,
MicroserviceMeta microserviceMeta, Endpoint endpoint,
- @Nonnull HttpServletRequestEx requestEx, @Nonnull HttpServletResponseEx responseEx) {
+ HttpServletRequestEx requestEx, HttpServletResponseEx responseEx) {
super(microserviceMeta, endpoint, requestEx, responseEx);
this.routingContext = routingContext;
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
index 2817f9da8..5e0d19630 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
@@ -20,9 +20,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
public abstract class AbstractQueryCodec implements QueryCodec {
@@ -39,7 +36,7 @@ public abstract class AbstractQueryCodec implements QueryCodec {
@Override
@SuppressWarnings("unchecked")
- public void encode(URLPathStringBuilder builder, String name, @Nullable Object value) throws Exception {
+ public void encode(URLPathStringBuilder builder, String name, Object value) throws Exception {
if (value == null) {
// not write query key to express "null"
return;
@@ -58,5 +55,5 @@ public abstract class AbstractQueryCodec implements QueryCodec {
encode(builder, name, Collections.singletonList(value));
}
- abstract void encode(URLPathStringBuilder builder, String name, @Nonnull Collection<Object> values) throws Exception;
+ abstract void encode(URLPathStringBuilder builder, String name, Collection<Object> values) throws Exception;
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodec.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodec.java
index 7a6478789..3282cc190 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodec.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodec.java
@@ -20,25 +20,23 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import jakarta.servlet.http.HttpServletRequest;
-
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
import org.springframework.core.Ordered;
+import jakarta.servlet.http.HttpServletRequest;
+
/**
* bigger order will override the same name codec
*/
public interface QueryCodec extends Ordered {
- static String encodeValue(@Nonnull Object value) throws UnsupportedEncodingException {
+ static String encodeValue(Object value) throws UnsupportedEncodingException {
return URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.name());
}
// can not replaced by value.toString() because of date serialize
- static String convertToString(@Nonnull Object value) throws Exception {
+ static String convertToString(Object value) throws Exception {
return RestObjectMapperFactory.getRestObjectMapper().convertToString(value);
}
@@ -49,7 +47,7 @@ public interface QueryCodec extends Ordered {
String getCodecName();
- void encode(URLPathStringBuilder builder, String name, @Nullable Object value) throws Exception;
+ void encode(URLPathStringBuilder builder, String name, Object value) throws Exception;
Object decode(QueryProcessor processor, HttpServletRequest request);
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMulti.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMulti.java
index 6ea0ec4a8..551ccee01 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMulti.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMulti.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Collection;
import java.util.Map;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
@@ -39,7 +37,7 @@ public class QueryCodecMulti extends AbstractQueryCodec {
}
@Override
- public void encode(URLPathStringBuilder builder, String name, @Nonnull Collection<Object> values) throws Exception {
+ public void encode(URLPathStringBuilder builder, String name, Collection<Object> values) throws Exception {
for (Object value : values) {
if (value == null) {
continue;
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecWithDelimiter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecWithDelimiter.java
index ddd389757..f3452bf37 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecWithDelimiter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecWithDelimiter.java
@@ -19,12 +19,11 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Collection;
import java.util.StringJoiner;
-import javax.annotation.Nonnull;
-import jakarta.servlet.http.HttpServletRequest;
-
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
+import jakarta.servlet.http.HttpServletRequest;
+
/**
* can not support value with delimiter<br>
* a csv example, a collection with two values:<br>
@@ -44,7 +43,7 @@ public class QueryCodecWithDelimiter extends AbstractQueryCodec {
}
@Override
- public void encode(URLPathStringBuilder builder, String name, @Nonnull Collection<Object> values) throws Exception {
+ public void encode(URLPathStringBuilder builder, String name, Collection<Object> values) throws Exception {
String joined = join(values);
if (joined == null) {
return;
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecs.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecs.java
index bad8f6889..41c5098ef 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecs.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecs.java
@@ -21,9 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +45,7 @@ public class QueryCodecs {
defaultCodec = codecs.get(QueryCodecMulti.CODEC_NAME);
}
- private void register(@Nonnull QueryCodec codec) {
+ private void register(QueryCodec codec) {
QueryCodec exists = codecs.put(codec.getCodecName(), codec);
if (exists != null) {
LOGGER.info("override QueryCodec, exists={}, new={}.",
@@ -56,8 +53,7 @@ public class QueryCodecs {
}
}
- @Nonnull
- public QueryCodec find(@Nullable String name) {
+ public QueryCodec find(String name) {
if (name == null) {
return defaultCodec;
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecsUtils.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecsUtils.java
index b1185673b..4b54210c7 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecsUtils.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecsUtils.java
@@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.common.rest.codec.query;
-import javax.annotation.Nonnull;
-
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.Parameter.StyleEnum;
@@ -29,7 +27,6 @@ public class QueryCodecsUtils {
QueryCodecsUtils.queryCodecs = queryCodecs;
}
- @Nonnull
public static QueryCodec find(Parameter.StyleEnum styleEnum, Boolean explode) {
return queryCodecs.find(formatName(styleEnum, explode));
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
index 8d9e07ead..c7eacf891 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
@@ -21,8 +21,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator;
import org.apache.servicecomb.common.rest.definition.RestParam;
@@ -129,7 +127,7 @@ public class URLPathBuilder {
return this;
}
- public URLPathStringBuilder appendQuery(@Nonnull String name, @Nonnull String encodedValue) {
+ public URLPathStringBuilder appendQuery(String name, String encodedValue) {
if (queryPrefixNotWrite) {
stringBuilder.append('?');
queryPrefixNotWrite = false;
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
index 614e4789f..2d74f4c8e 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
@@ -25,8 +25,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.HttpTransportContext;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.codec.RestCodec;
@@ -59,7 +57,6 @@ public class RestServerCodecFilter implements ProviderFilter {
public static final String NAME = "rest-server-codec";
- @Nonnull
@Override
public String getName() {
return NAME;
@@ -116,7 +113,7 @@ public class RestServerCodecFilter implements ProviderFilter {
public static CompletableFuture<Response> encodeResponse(Response response, boolean download,
ProduceProcessor produceProcessor, HttpServletResponseEx responseEx) {
responseEx.setStatus(response.getStatusCode());
- copyHeadersToHttpResponse(response.getHeaders(), responseEx);
+ copyHeadersToHttpResponse(response.getHeaders(), responseEx);
if (download) {
return CompletableFuture.completedFuture(response);
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
index d79ddf010..306ad3395 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java
@@ -29,9 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.apache.servicecomb.config.inject.InjectProperties;
import org.apache.servicecomb.config.inject.InjectProperty;
import org.apache.servicecomb.core.Invocation;
@@ -105,13 +102,13 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
}
@Override
- public InvocationException convert(@Nonnull Invocation invocation, Throwable throwable) {
+ public InvocationException convert(Invocation invocation, Throwable throwable) {
StatusType genericStatus = CONSUMER.equals(invocation.getInvocationType()) ? BAD_REQUEST : INTERNAL_SERVER_ERROR;
return convert(invocation, throwable, genericStatus);
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, Throwable throwable, StatusType genericStatus) {
+ public InvocationException convert(Invocation invocation, Throwable throwable, StatusType genericStatus) {
Throwable unwrapped = ExceptionFactory.unwrap(throwable);
try {
ExceptionConverter<Throwable> converter =
@@ -149,7 +146,7 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
}
@Override
- public void logConsumerException(@Nonnull Invocation invocation, @Nonnull InvocationException exception) {
+ public void logConsumerException(Invocation invocation, InvocationException exception) {
if (isIgnoreLog(invocation, exception)) {
return;
}
@@ -171,7 +168,7 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
}
@Override
- public boolean isIgnoreLog(@Nonnull Invocation invocation, @Nonnull InvocationException exception) {
+ public boolean isIgnoreLog(Invocation invocation, InvocationException exception) {
if (!isPrintRateLimit() && exception.getStatusCode() == TOO_MANY_REQUESTS.getStatusCode()) {
return true;
}
@@ -180,7 +177,7 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
}
@Override
- public Response toProducerResponse(@Nullable Invocation invocation, Throwable exception) {
+ public Response toProducerResponse(Invocation invocation, Throwable exception) {
InvocationException invocationException = convert(invocation, exception, INTERNAL_SERVER_ERROR);
if (invocation != null) {
logProducerException(invocation, invocationException);
@@ -190,7 +187,7 @@ public class DefaultExceptionProcessor implements ExceptionProcessor {
}
@Override
- public void logProducerException(@Nonnull Invocation invocation, @Nonnull InvocationException exception) {
+ public void logProducerException(Invocation invocation, InvocationException exception) {
if (isIgnoreLog(invocation, exception)) {
return;
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionConverter.java
index 38be81e8a..b64245647 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionConverter.java
@@ -20,13 +20,12 @@ import static jakarta.ws.rs.core.Response.Status.Family.CLIENT_ERROR;
import static org.apache.servicecomb.core.exception.ExceptionCodes.GENERIC_CLIENT;
import static org.apache.servicecomb.core.exception.ExceptionCodes.GENERIC_SERVER;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.utils.SPIOrder;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import jakarta.ws.rs.core.Response.StatusType;
+
public interface ExceptionConverter<T extends Throwable> extends SPIOrder {
static boolean isClient(StatusType status) {
return CLIENT_ERROR.equals(status.getFamily());
@@ -50,5 +49,5 @@ public interface ExceptionConverter<T extends Throwable> extends SPIOrder {
* @param genericStatus if can not determine the status type, then use this input value
* @return converted invocation exception
*/
- InvocationException convert(@Nullable Invocation invocation, T throwable, StatusType genericStatus);
+ InvocationException convert(Invocation invocation, T throwable, StatusType genericStatus);
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionProcessor.java b/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionProcessor.java
index dac16812e..ffb3619bb 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionProcessor.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/ExceptionProcessor.java
@@ -17,15 +17,13 @@
package org.apache.servicecomb.core.exception;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.core.Ordered;
+import jakarta.ws.rs.core.Response.StatusType;
+
/**
* will select the min order instance
*/
@@ -37,17 +35,17 @@ public interface ExceptionProcessor extends Ordered {
boolean isPrintStackTrace();
- InvocationException convert(@Nonnull Invocation invocation, Throwable throwable);
+ InvocationException convert(Invocation invocation, Throwable throwable);
- InvocationException convert(@Nullable Invocation invocation, Throwable throwable, StatusType genericStatus);
+ InvocationException convert(Invocation invocation, Throwable throwable, StatusType genericStatus);
- boolean isIgnoreLog(@Nonnull Invocation invocation, @Nonnull InvocationException exception);
+ boolean isIgnoreLog(Invocation invocation, InvocationException exception);
Response toConsumerResponse(Invocation invocation, Throwable throwable);
- void logConsumerException(@Nonnull Invocation invocation, @Nonnull InvocationException exception);
+ void logConsumerException(Invocation invocation, InvocationException exception);
- Response toProducerResponse(@Nullable Invocation invocation, Throwable exception);
+ Response toProducerResponse(Invocation invocation, Throwable exception);
- void logProducerException(@Nonnull Invocation invocation, @Nonnull InvocationException exception);
+ void logProducerException(Invocation invocation, InvocationException exception);
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/Exceptions.java b/core/src/main/java/org/apache/servicecomb/core/exception/Exceptions.java
index 719d9f461..0fb8ad418 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/Exceptions.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/Exceptions.java
@@ -26,16 +26,14 @@ import static org.apache.servicecomb.swagger.invocation.InvocationType.CONSUMER;
import java.util.Comparator;
import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.beans.factory.annotation.Autowired;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class Exceptions {
private static ExceptionProcessor processor = new DefaultExceptionProcessor();
@@ -102,7 +100,7 @@ public class Exceptions {
return producer(GENERIC_SERVER, msg, cause);
}
- public static StatusType getGenericStatus(@Nonnull Invocation invocation) {
+ public static StatusType getGenericStatus(Invocation invocation) {
return CONSUMER.equals(invocation.getInvocationType()) ? BAD_REQUEST : INTERNAL_SERVER_ERROR;
}
@@ -110,15 +108,15 @@ public class Exceptions {
return processor.toConsumerResponse(invocation, throwable);
}
- public static Response toProducerResponse(@Nullable Invocation invocation, Throwable exception) {
+ public static Response toProducerResponse(Invocation invocation, Throwable exception) {
return processor.toProducerResponse(invocation, exception);
}
- public static InvocationException convert(@Nonnull Invocation invocation, Throwable throwable) {
+ public static InvocationException convert(Invocation invocation, Throwable throwable) {
return processor.convert(invocation, throwable);
}
- public static InvocationException convert(@Nullable Invocation invocation, Throwable throwable,
+ public static InvocationException convert(Invocation invocation, Throwable throwable,
StatusType genericStatus) {
return processor.convert(invocation, throwable, genericStatus);
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/ConnectTimeoutExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/ConnectTimeoutExceptionConverter.java
index 4b93eafe5..72507d0a3 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/ConnectTimeoutExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/ConnectTimeoutExceptionConverter.java
@@ -18,9 +18,6 @@ package org.apache.servicecomb.core.exception.converter;
import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
@@ -28,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.netty.channel.ConnectTimeoutException;
+import jakarta.ws.rs.core.Response.StatusType;
public class ConnectTimeoutExceptionConverter implements ExceptionConverter<ConnectTimeoutException> {
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectTimeoutExceptionConverter.class);
@@ -45,7 +43,7 @@ public class ConnectTimeoutExceptionConverter implements ExceptionConverter<Conn
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, ConnectTimeoutException throwable,
+ public InvocationException convert(Invocation invocation, ConnectTimeoutException throwable,
StatusType genericStatus) {
// throwable.getMessage:
// connection timed out: /1.1.1.1:8080
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/DefaultExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/DefaultExceptionConverter.java
index bb62a67b3..d0338d436 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/DefaultExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/DefaultExceptionConverter.java
@@ -16,13 +16,9 @@
*/
package org.apache.servicecomb.core.exception.converter;
-import javax.annotation.Nullable;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import jakarta.ws.rs.core.Response.StatusType;
@@ -39,8 +35,6 @@ import jakarta.ws.rs.core.Response.StatusType;
* </pre>
*/
public class DefaultExceptionConverter implements ExceptionConverter<Throwable> {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionConverter.class);
-
public static final int ORDER = Integer.MAX_VALUE;
@Override
@@ -54,7 +48,7 @@ public class DefaultExceptionConverter implements ExceptionConverter<Throwable>
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, Throwable throwable, StatusType genericStatus) {
+ public InvocationException convert(Invocation invocation, Throwable throwable, StatusType genericStatus) {
String msg = String.format("Unexpected exception when processing %s. %s",
invocation == null ? "none" : invocation.getMicroserviceQualifiedName(), throwable.getMessage());
return new InvocationException(genericStatus, ExceptionConverter.getGenericCode(genericStatus),
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/IllegalArgumentExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/IllegalArgumentExceptionConverter.java
index 2d3247445..f80f1a825 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/IllegalArgumentExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/IllegalArgumentExceptionConverter.java
@@ -16,13 +16,12 @@
*/
package org.apache.servicecomb.core.exception.converter;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class IllegalArgumentExceptionConverter implements ExceptionConverter<IllegalArgumentException> {
public static final int ORDER = Short.MAX_VALUE;
@@ -37,7 +36,7 @@ public class IllegalArgumentExceptionConverter implements ExceptionConverter<Ill
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, IllegalArgumentException throwable,
+ public InvocationException convert(Invocation invocation, IllegalArgumentException throwable,
StatusType genericStatus) {
return new InvocationException(genericStatus, ExceptionConverter.getGenericCode(genericStatus),
"Parameters not valid or types not match.", throwable);
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/InvocationExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/InvocationExceptionConverter.java
index 8e5abfbe6..830aec319 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/InvocationExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/InvocationExceptionConverter.java
@@ -16,13 +16,12 @@
*/
package org.apache.servicecomb.core.exception.converter;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class InvocationExceptionConverter implements ExceptionConverter<InvocationException> {
public static final int ORDER = Byte.MAX_VALUE;
@@ -37,7 +36,7 @@ public class InvocationExceptionConverter implements ExceptionConverter<Invocati
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, InvocationException throwable,
+ public InvocationException convert(Invocation invocation, InvocationException throwable,
StatusType genericStatus) {
return throwable;
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/ServiceCombExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/ServiceCombExceptionConverter.java
index f6d0a2f90..9a69f4c98 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/ServiceCombExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/ServiceCombExceptionConverter.java
@@ -19,15 +19,14 @@ package org.apache.servicecomb.core.exception.converter;
import java.util.concurrent.TimeoutException;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.Status;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import jakarta.ws.rs.core.Response.Status;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class ServiceCombExceptionConverter implements ExceptionConverter<ServiceCombException> {
public static final int ORDER = Byte.MAX_VALUE;
@@ -44,7 +43,7 @@ public class ServiceCombExceptionConverter implements ExceptionConverter<Service
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, ServiceCombException throwable,
+ public InvocationException convert(Invocation invocation, ServiceCombException throwable,
StatusType genericStatus) {
if (throwable.getCause() instanceof TimeoutException) {
return timeoutExceptionConverter.convert(invocation, (TimeoutException) throwable.getCause(), genericStatus);
diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/converter/TimeoutExceptionConverter.java b/core/src/main/java/org/apache/servicecomb/core/exception/converter/TimeoutExceptionConverter.java
index a5f070bed..31d48a829 100644
--- a/core/src/main/java/org/apache/servicecomb/core/exception/converter/TimeoutExceptionConverter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/exception/converter/TimeoutExceptionConverter.java
@@ -20,15 +20,14 @@ import static jakarta.ws.rs.core.Response.Status.REQUEST_TIMEOUT;
import java.util.concurrent.TimeoutException;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class TimeoutExceptionConverter implements ExceptionConverter<TimeoutException> {
private static final Logger LOGGER = LoggerFactory.getLogger(TimeoutExceptionConverter.class);
@@ -45,7 +44,7 @@ public class TimeoutExceptionConverter implements ExceptionConverter<TimeoutExce
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, TimeoutException throwable,
+ public InvocationException convert(Invocation invocation, TimeoutException throwable,
StatusType genericStatus) {
// throwable.getMessage:
// The timeout period of 30000ms has been exceeded while executing GET /xxx for server 1.1.1.1:8080
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/ConsumerFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/ConsumerFilter.java
index 9f89c7025..bd658be71 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/ConsumerFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/ConsumerFilter.java
@@ -16,12 +16,9 @@
*/
package org.apache.servicecomb.core.filter;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.swagger.invocation.InvocationType;
public interface ConsumerFilter extends Filter {
- @Nonnull
@Override
default boolean enabledForInvocationType(InvocationType invocationType) {
return invocationType == InvocationType.CONSUMER;
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/Filter.java b/core/src/main/java/org/apache/servicecomb/core/filter/Filter.java
index 5c58aca97..48e4e8ffc 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/Filter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/Filter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.core.filter;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
@@ -70,7 +68,6 @@ public interface Filter {
return 0;
}
- @Nonnull
default String getName() {
throw new IllegalStateException("must provide unique filter name.");
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/ProviderFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/ProviderFilter.java
index 49ba1e481..7e1dbc318 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/ProviderFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/ProviderFilter.java
@@ -16,12 +16,9 @@
*/
package org.apache.servicecomb.core.filter;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.swagger.invocation.InvocationType;
public interface ProviderFilter extends Filter {
- @Nonnull
@Override
default boolean enabledForInvocationType(InvocationType invocationType) {
return invocationType == InvocationType.PROVIDER;
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/impl/EmptyFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/impl/EmptyFilter.java
index 2277b70f1..f611616b4 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/impl/EmptyFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/impl/EmptyFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.core.filter.impl;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -27,7 +25,6 @@ import org.apache.servicecomb.swagger.invocation.Response;
// just for test
public class EmptyFilter implements Filter {
- @Nonnull
@Override
public String getName() {
return "empty";
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilter.java
index ea5cf5ffd..bce1b014d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ParameterValidatorFilter.java
@@ -20,8 +20,6 @@ import java.lang.reflect.Method;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -63,7 +61,6 @@ public class ParameterValidatorFilter implements ProviderFilter, InitializingBea
this.environment = environment;
}
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ProviderOperationFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ProviderOperationFilter.java
index 1e450ebf4..bfd06f80e 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ProviderOperationFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ProviderOperationFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.core.filter.impl;
import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.core.filter.Filter;
@@ -35,7 +33,6 @@ import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
public class ProviderOperationFilter implements ProviderFilter {
public static final String NAME = "producer-operation";
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
index 1f2c119c2..eaec70975 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/impl/ScheduleFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.core.filter.impl;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.core.filter.Filter;
@@ -33,7 +31,6 @@ import org.apache.servicecomb.swagger.invocation.Response;
public class ScheduleFilter implements ProviderFilter {
public static final String NAME = "schedule";
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index c0fb69ffd..1d00932b2 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -35,8 +35,6 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.definition.InvocationRuntimeType;
@@ -255,11 +253,11 @@ public final class InvokerUtils {
}
}
- public static boolean isSyncMethod(@Nonnull Method method) {
+ public static boolean isSyncMethod(Method method) {
return !isAsyncMethod(method);
}
- public static boolean isAsyncMethod(@Nonnull Method method) {
+ public static boolean isAsyncMethod(Method method) {
// currently only support CompletableFuture for async method definition
return method.getReturnType().equals(CompletableFuture.class);
}
diff --git a/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java b/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java
index 978c8e23b..90ffc3c94 100644
--- a/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java
+++ b/core/src/test/java/org/apache/servicecomb/core/exception/ExceptionsTest.java
@@ -23,9 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
@@ -34,6 +31,7 @@ import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.jupiter.api.Test;
import io.vertx.core.json.Json;
+import jakarta.ws.rs.core.Response.StatusType;
class ExceptionsTest {
@Test
@@ -82,7 +80,7 @@ class ExceptionsTest {
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, Throwable throwable, StatusType genericStatus) {
+ public InvocationException convert(Invocation invocation, Throwable throwable, StatusType genericStatus) {
throw new RuntimeExceptionWithoutStackTrace("mock exception when convert");
}
}
diff --git a/core/src/test/java/org/apache/servicecomb/core/filter/SimpleRetryFilter.java b/core/src/test/java/org/apache/servicecomb/core/filter/SimpleRetryFilter.java
index b162bfb1f..4eeb73026 100644
--- a/core/src/test/java/org/apache/servicecomb/core/filter/SimpleRetryFilter.java
+++ b/core/src/test/java/org/apache/servicecomb/core/filter/SimpleRetryFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.core.filter;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.Exceptions;
import org.apache.servicecomb.swagger.invocation.InvocationType;
@@ -29,7 +27,6 @@ import org.apache.servicecomb.swagger.invocation.Response;
public class SimpleRetryFilter implements ConsumerFilter {
protected int maxRetry = 3;
- @Nonnull
@Override
public String getName() {
return "simple-retry";
diff --git a/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/error/CustomExceptionToProducerResponseConverter.java b/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/error/CustomExceptionToProducerResponseConverter.java
index ea328b627..9fd5aeec7 100644
--- a/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/error/CustomExceptionToProducerResponseConverter.java
+++ b/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/error/CustomExceptionToProducerResponseConverter.java
@@ -17,14 +17,13 @@
package org.apache.servicecomb.demo.edge.business.error;
-import javax.annotation.Nullable;
-import jakarta.ws.rs.core.Response.Status;
-import jakarta.ws.rs.core.Response.StatusType;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionConverter;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import jakarta.ws.rs.core.Response.Status;
+import jakarta.ws.rs.core.Response.StatusType;
+
public class CustomExceptionToProducerResponseConverter implements
ExceptionConverter<IllegalStateException> {
@Override
@@ -38,7 +37,7 @@ public class CustomExceptionToProducerResponseConverter implements
}
@Override
- public InvocationException convert(@Nullable Invocation invocation, IllegalStateException e,
+ public InvocationException convert(Invocation invocation, IllegalStateException e,
StatusType genericStatus) {
IllegalStateErrorData data = new IllegalStateErrorData();
data.setId(500);
diff --git a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
index 9e971e860..997ed53e6 100644
--- a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
+++ b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.demo.edge.service.encrypt.filter;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
@@ -45,7 +43,6 @@ public class DecodeBodyFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER - 1790;
}
- @Nonnull
@Override
public String getName() {
return "test-edge-decode-body";
diff --git a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
index bbefe0bff..4e33f979a 100644
--- a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
+++ b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
@@ -22,8 +22,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -49,7 +47,6 @@ public class EdgeSignatureRequestFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER - 1800;
}
- @Nonnull
@Override
public String getName() {
return "test-edge-signature-request";
diff --git a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
index 5d4d9ea38..0b0ae444a 100644
--- a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
+++ b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.demo.edge.service.encrypt.filter;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -48,7 +46,6 @@ public class EdgeSignatureResponseFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1991;
}
- @Nonnull
@Override
public String getName() {
return "test-edge-signature-request";
diff --git a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java
index 49820941e..f6a54cacb 100644
--- a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java
+++ b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.demo.edge.service.encrypt.filter;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -37,7 +35,6 @@ public class UserIdFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER - 1790;
}
- @Nonnull
@Override
public String getName() {
return "test-edge-user-id";
diff --git a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
index a7838f2f8..3d1028998 100644
--- a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
+++ b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.demo.edge.service.handler;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -59,7 +57,6 @@ public class AuthHandler implements ConsumerFilter {
return true;
}
- @Nonnull
@Override
public String getName() {
return "test-auth";
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/java/org/apache/servicecomb/demo/springboot/pojo/server/handler/MyHandler.java b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/java/org/apache/servicecomb/demo/springboot/pojo/server/handler/MyHandler.java
index 1f7673d6a..1ec59f40b 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/java/org/apache/servicecomb/demo/springboot/pojo/server/handler/MyHandler.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/java/org/apache/servicecomb/demo/springboot/pojo/server/handler/MyHandler.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.demo.springboot.pojo.server.handler;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -44,7 +42,6 @@ public class MyHandler implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 100;
}
- @Nonnull
@Override
public String getName() {
return "test-my-filter";
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/filter/ProviderTestFilter.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/filter/ProviderTestFilter.java
index 936f26838..8c0e1f3f4 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/filter/ProviderTestFilter.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/filter/ProviderTestFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.demo.springmvc.filter;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -36,7 +34,6 @@ public class ProviderTestFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 1800;
}
- @Nonnull
@Override
public String getName() {
return "test-provider";
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index b52f04889..a4881cacf 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -191,18 +191,6 @@
<version>${protobuf.version}</version>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- <version>${archaius.version}</version>
- <exclusions>
- <exclusion>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>annotations</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
<dependency>
<groupId>com.netflix.governator</groupId>
<artifactId>governator-annotations</artifactId>
@@ -214,12 +202,6 @@
<version>${governator-api.version}</version>
</dependency>
- <dependency>
- <groupId>com.netflix.hystrix</groupId>
- <artifactId>hystrix-core</artifactId>
- <version>${hystrix.version}</version>
- </dependency>
-
<dependency>
<groupId>com.netflix.netflix-commons</groupId>
<artifactId>netflix-eventbus</artifactId>
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
index 0788397e5..5ba63b04a 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeAddHeaderFilter.java
@@ -22,8 +22,6 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
-import javax.annotation.Nonnull;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.core.Invocation;
@@ -83,7 +81,6 @@ public class EdgeAddHeaderFilter implements ConsumerFilter {
}
}
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeServerCodecFilter.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeServerCodecFilter.java
index 416672ea5..cef9257b3 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeServerCodecFilter.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/EdgeServerCodecFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.edge.core;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.filter.inner.RestServerCodecFilter;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
@@ -31,13 +29,11 @@ import org.apache.servicecomb.swagger.invocation.context.TransportContext;
public class EdgeServerCodecFilter extends RestServerCodecFilter {
public static final String NAME = "edge-server-codec";
- @Nonnull
@Override
public String getName() {
return NAME;
}
- @Nonnull
@Override
public boolean enabledForInvocationType(InvocationType invocationType) {
return invocationType == InvocationType.CONSUMER;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
index b575ec33c..be17eee86 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java
@@ -17,8 +17,6 @@
package org.apache.servicecomb.config.priority;
-import javax.annotation.Nullable;
-
import org.apache.servicecomb.foundation.common.utils.bean.Setter;
/**
@@ -34,7 +32,7 @@ public class ConfigObjectProperty {
this.property = property;
}
- public void updateValueWhenChanged(Object instance, @Nullable String changedKey) {
+ public void updateValueWhenChanged(Object instance, String changedKey) {
if (property.isChangedKey(changedKey)) {
property.updateValue();
setter.set(instance, property.getValue());
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
index 4b2de1c79..ecf7bf779 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/DynamicPropertiesTest.java
@@ -33,13 +33,9 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.env.Environment;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicPropertyFactory;
import com.seanyinx.github.unit.scaffolding.Poller;
import com.seanyinx.github.unit.scaffolding.Randomness;
-import mockit.Deencapsulation;
-
public class DynamicPropertiesTest {
private static final String stringPropertyName = uniquify("stringPropertyName");
@@ -95,9 +91,7 @@ public class DynamicPropertiesTest {
@AfterClass
public static void tearDown() throws Exception {
- Deencapsulation.setField(ConfigurationManager.class, "instance", null);
- Deencapsulation.setField(ConfigurationManager.class, "customConfigurationInstalled", false);
- Deencapsulation.setField(DynamicPropertyFactory.class, "config", null);
+
}
private static void writeInitialConfig() throws Exception {
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/parser/ContentFileReader.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/parser/ContentFileReader.java
index 632de7bc0..3a1aad264 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/parser/ContentFileReader.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/parser/ContentFileReader.java
@@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.foundation.protobuf.internal.parser;
-import javax.annotation.Nullable;
-
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
@@ -25,6 +23,7 @@ import io.protostuff.compiler.parser.FileReader;
public class ContentFileReader implements FileReader {
private final FileReader importReader;
+
private final String content;
private boolean contentReaded;
@@ -34,7 +33,6 @@ public class ContentFileReader implements FileReader {
this.content = content;
}
- @Nullable
@Override
public CharStream read(String contentOrName) {
if (!contentReaded) {
diff --git a/foundations/foundation-test-scaffolding/pom.xml b/foundations/foundation-test-scaffolding/pom.xml
index 44523a196..201d814b0 100644
--- a/foundations/foundation-test-scaffolding/pom.xml
+++ b/foundations/foundation-test-scaffolding/pom.xml
@@ -31,10 +31,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- </dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
diff --git a/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/config/ArchaiusUtils.java b/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/config/ArchaiusUtils.java
deleted file mode 100644
index be347046d..000000000
--- a/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/config/ArchaiusUtils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.foundation.test.scaffolding.config;
-
-import java.lang.reflect.Field;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.springframework.util.ReflectionUtils;
-
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicProperty;
-import com.netflix.config.DynamicPropertyFactory;
-
-public final class ArchaiusUtils {
- private static final Field FIELD_INSTANCE = ReflectionUtils.findField(ConfigurationManager.class, "instance");
-
- private static final Field FIELD_CUSTOM_CONFIGURATION_INSTALLED =
- ReflectionUtils.findField(ConfigurationManager.class, "customConfigurationInstalled");
-
- private static final Field FIELD_CONFIG = ReflectionUtils.findField(DynamicPropertyFactory.class, "config");
-
- private static final Field FIELD_INITIALIZED_WITH_DEFAULT_CONFIG =
- ReflectionUtils.findField(DynamicPropertyFactory.class, "initializedWithDefaultConfig");
-
- private static final Field FIELD_DYNAMIC_PROPERTY_SUPPORTIMPL =
- ReflectionUtils.findField(DynamicProperty.class, "dynamicPropertySupportImpl");
-
- private static final Field FIELD_DYNAMIC_PROPERTY_ALL_PROPS = ReflectionUtils
- .findField(DynamicProperty.class, "ALL_PROPS");
-
- static {
- FIELD_INSTANCE.setAccessible(true);
- FIELD_CUSTOM_CONFIGURATION_INSTALLED.setAccessible(true);
- FIELD_CONFIG.setAccessible(true);
- FIELD_INITIALIZED_WITH_DEFAULT_CONFIG.setAccessible(true);
- FIELD_DYNAMIC_PROPERTY_SUPPORTIMPL.setAccessible(true);
- FIELD_DYNAMIC_PROPERTY_ALL_PROPS.setAccessible(true);
- }
-
- private ArchaiusUtils() {
- }
-
- @SuppressWarnings("unchecked")
- public static void resetConfig() {
- ReflectionUtils.setField(FIELD_INSTANCE, null, null);
- ReflectionUtils.setField(FIELD_CUSTOM_CONFIGURATION_INSTALLED, null, false);
- ReflectionUtils.setField(FIELD_CONFIG, null, null);
- ReflectionUtils.setField(FIELD_INITIALIZED_WITH_DEFAULT_CONFIG, null, false);
- ReflectionUtils.setField(FIELD_DYNAMIC_PROPERTY_SUPPORTIMPL, null, null);
- ((ConcurrentHashMap<String, DynamicProperty>) ReflectionUtils.getField(FIELD_DYNAMIC_PROPERTY_ALL_PROPS, null))
- .clear();
- }
-
- public static void setProperty(String key, Object value) {
- // ensure have instance
- DynamicPropertyFactory.getInstance();
-
- ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
- .getBackingConfigurationSource();
- if (value != null) {
- config.getConfiguration(0).setProperty(key, value);
- return;
- }
-
- config.getConfiguration(0).clearProperty(key);
- }
-}
diff --git a/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerAbortFaultFilter.java b/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerAbortFaultFilter.java
index 25c8f7799..c13f1b8c2 100644
--- a/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerAbortFaultFilter.java
+++ b/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerAbortFaultFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.faultinjection;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -43,7 +41,6 @@ public class ConsumerAbortFaultFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1020;
}
- @Nonnull
@Override
public String getName() {
return "consumer-abort-fault";
diff --git a/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerDelayFaultFilter.java b/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerDelayFaultFilter.java
index 7503be81f..248ed748c 100644
--- a/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerDelayFaultFilter.java
+++ b/handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/ConsumerDelayFaultFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.faultinjection;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -40,7 +38,6 @@ public class ConsumerDelayFaultFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1030;
}
- @Nonnull
@Override
public String getName() {
return "consumer-delay-fault";
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
index 749514aae..b5fe884d9 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ConsumerFlowControlFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.qps;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -50,7 +48,6 @@ public class ConsumerFlowControlFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER - 1990;
}
- @Nonnull
@Override
public String getName() {
return "consumer-flow-control";
diff --git a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
index c941f2900..ef9610d30 100644
--- a/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
+++ b/handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderFlowControlFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.qps;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
@@ -46,7 +44,6 @@ public class ProviderFlowControlFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 1990;
}
- @Nonnull
@Override
public String getName() {
return "provider-flow-control";
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceBulkheadFilter.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceBulkheadFilter.java
index 33db08c5a..8d8fd4c94 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceBulkheadFilter.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceBulkheadFilter.java
@@ -21,9 +21,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-import jakarta.ws.rs.core.Response.Status;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -43,6 +40,7 @@ import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadFullException;
import io.github.resilience4j.decorators.Decorators;
import io.github.resilience4j.decorators.Decorators.DecorateCompletionStage;
+import jakarta.ws.rs.core.Response.Status;
public class ConsumerInstanceBulkheadFilter implements ConsumerFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerInstanceBulkheadFilter.class);
@@ -59,7 +57,6 @@ public class ConsumerInstanceBulkheadFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1060;
}
- @Nonnull
@Override
public String getName() {
return "instance-bulkhead";
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceIsolationFilter.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceIsolationFilter.java
index a2eca3457..875e53b75 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceIsolationFilter.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ConsumerInstanceIsolationFilter.java
@@ -22,8 +22,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
import org.apache.servicecomb.core.filter.Filter;
@@ -69,7 +67,6 @@ public class ConsumerInstanceIsolationFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1050;
}
- @Nonnull
@Override
public String getName() {
return "instance-isolation";
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderBulkheadFilter.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderBulkheadFilter.java
index 4bfaf3af9..c526916b0 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderBulkheadFilter.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderBulkheadFilter.java
@@ -21,8 +21,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -58,7 +56,6 @@ public class ProviderBulkheadFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 1880;
}
- @Nonnull
@Override
public String getName() {
return "provider-bulkhead";
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderCircuitBreakerFilter.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderCircuitBreakerFilter.java
index a85b53372..0c5e2ed33 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderCircuitBreakerFilter.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderCircuitBreakerFilter.java
@@ -21,8 +21,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -58,7 +56,6 @@ public class ProviderCircuitBreakerFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 1890;
}
- @Nonnull
@Override
public String getName() {
return "provider-circuit-breaker";
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderRateLimitingFilter.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderRateLimitingFilter.java
index f72e2c279..63db4cd7d 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderRateLimitingFilter.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderRateLimitingFilter.java
@@ -21,8 +21,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterNode;
@@ -58,7 +56,6 @@ public class ProviderRateLimitingFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER - 1900;
}
- @Nonnull
@Override
public String getName() {
return "provider-rate-limiting";
diff --git a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalanceFilter.java b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalanceFilter.java
index 14579612c..32911bc7c 100644
--- a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalanceFilter.java
+++ b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalanceFilter.java
@@ -21,8 +21,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
@@ -113,7 +111,6 @@ public class LoadBalanceFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER;
}
- @Nonnull
@Override
public String getName() {
return "load-balance";
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/consumer/ConsumerAuthFilter.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/consumer/ConsumerAuthFilter.java
index 27d54e504..6957dc1b7 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/consumer/ConsumerAuthFilter.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/consumer/ConsumerAuthFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.authentication.consumer;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
@@ -46,7 +44,6 @@ public class ConsumerAuthFilter implements ConsumerFilter {
return Filter.CONSUMER_LOAD_BALANCE_ORDER + 1010;
}
- @Nonnull
@Override
public String getName() {
return "consumer-public-key";
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderAuthFilter.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderAuthFilter.java
index ddfda036e..053745016 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderAuthFilter.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderAuthFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.authentication.provider;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
@@ -45,7 +43,6 @@ public class ProviderAuthFilter implements ProviderFilter {
return Filter.PROVIDER_SCHEDULE_FILTER_ORDER + 1010;
}
- @Nonnull
@Override
public String getName() {
return "provider-public-key";
diff --git a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterAddHeaderFilter.java b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterAddHeaderFilter.java
index 4d044f2e9..bf7dbeb7e 100644
--- a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterAddHeaderFilter.java
+++ b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterAddHeaderFilter.java
@@ -23,8 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.Filter;
@@ -92,7 +90,6 @@ public class RouterAddHeaderFilter implements Filter {
return true;
}
- @Nonnull
@Override
public String getName() {
return "router-add-header";
diff --git a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
index 2d53510c3..a646d2ded 100644
--- a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
+++ b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/FilterInvocationCaller.java
@@ -21,8 +21,6 @@ import static org.apache.servicecomb.core.provider.consumer.InvokerUtils.isAsync
import java.lang.reflect.Method;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
@@ -38,7 +36,7 @@ public class FilterInvocationCaller implements InvocationCaller {
return isAsyncMethod(method) ? future : InvokerUtils.toSync(future, invocation.getWaitTime());
}
- protected CompletableFuture<Object> doCall(@Nonnull PojoInvocation invocation) {
+ protected CompletableFuture<Object> doCall(PojoInvocation invocation) {
return InvokerUtils.invoke(invocation)
.thenApply(response -> {
if (response.isSucceed()) {
diff --git a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerMeta.java b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerMeta.java
index 336f0d46d..1de414759 100644
--- a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerMeta.java
+++ b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/definition/PojoConsumerMeta.java
@@ -20,8 +20,6 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
@@ -67,7 +65,6 @@ public class PojoConsumerMeta {
return schemaMeta;
}
- @Nonnull
public PojoConsumerOperationMeta ensureFindOperationMeta(Method method) {
PojoConsumerOperationMeta pojoConsumerOperationMeta = operationMetas.get(method);
if (pojoConsumerOperationMeta == null) {
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
index c50ebfcd9..82d0348c4 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.transport.highway;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf;
import org.apache.servicecomb.codec.protobuf.definition.ProtobufManager;
import org.apache.servicecomb.core.CoreConst;
@@ -41,7 +39,6 @@ public class HighwayClientFilter implements ConsumerFilter {
public static final String NAME = "highway-client";
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
index d59b2da8f..87d620156 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
@@ -20,8 +20,6 @@ import static org.apache.servicecomb.core.exception.Exceptions.toProducerRespons
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf;
import org.apache.servicecomb.codec.protobuf.definition.ResponseRootSerializer;
import org.apache.servicecomb.core.CoreConst;
@@ -39,7 +37,6 @@ import io.vertx.core.buffer.Buffer;
public class HighwayServerCodecFilter implements ProviderFilter {
public static final String NAME = "highway-server-codec";
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientCodecFilter.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientCodecFilter.java
index 340f84595..9f3c89152 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientCodecFilter.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientCodecFilter.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.transport.rest.client;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Invocation;
@@ -42,7 +40,6 @@ public class RestClientCodecFilter implements ConsumerFilter {
protected RestClientDecoder decoder;
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientEncoder.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientEncoder.java
index c3c460c87..b9c1e16a1 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientEncoder.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientEncoder.java
@@ -26,9 +26,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.apache.servicecomb.common.rest.codec.RestCodec;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.common.rest.codec.query.QueryCodec;
@@ -103,7 +100,7 @@ public class RestClientEncoder {
.argsToRest(invocation.getSwaggerArguments(), transportContext.getRestOperationMeta(), requestParameters);
}
- protected void writeCookies(@Nullable Map<String, String> cookieMap) {
+ protected void writeCookies(Map<String, String> cookieMap) {
if (CollectionUtils.isEmpty(cookieMap)) {
return;
}
@@ -130,7 +127,7 @@ public class RestClientEncoder {
RestObjectMapperFactory.getRestObjectMapper().writeValueAsString(invocation.getContext()));
}
- protected void writeForm(@Nullable Map<String, Object> formMap) throws Exception {
+ protected void writeForm(Map<String, Object> formMap) throws Exception {
if (requestParameters.getUploads() == null) {
writeUrlEncodedForm(formMap);
return;
@@ -139,7 +136,7 @@ public class RestClientEncoder {
writeChunkedForm(formMap);
}
- protected void writeUrlEncodedForm(@Nullable Map<String, Object> formMap) throws Exception {
+ protected void writeUrlEncodedForm(Map<String, Object> formMap) throws Exception {
if (formMap == null) {
return;
}
@@ -150,7 +147,7 @@ public class RestClientEncoder {
requestParameters.setBodyBuffer(bodyBuffer);
}
- protected Buffer genUrlEncodedFormBuffer(@Nonnull Map<String, Object> formMap) throws Exception {
+ protected Buffer genUrlEncodedFormBuffer(Map<String, Object> formMap) throws Exception {
// 2x faster than UriComponentsBuilder
ByteBuf byteBuf = Unpooled.buffer(RestClientEncoder.FORM_BUFFER_SIZE);
for (Entry<String, Object> entry : formMap.entrySet()) {
@@ -169,7 +166,7 @@ public class RestClientEncoder {
return Buffer.buffer(byteBuf);
}
- protected void writeChunkedForm(@Nullable Map<String, Object> formMap) throws Exception {
+ protected void writeChunkedForm(Map<String, Object> formMap) throws Exception {
String boundary = transportContext.getOrCreateBoundary();
httpClientRequest.setChunked(true);
@@ -183,7 +180,7 @@ public class RestClientEncoder {
requestParameters.setBodyBuffer(bodyBuffer);
}
- protected Buffer genChunkedFormBuffer(@Nonnull Map<String, Object> formMap, String boundary) throws Exception {
+ protected Buffer genChunkedFormBuffer(Map<String, Object> formMap, String boundary) throws Exception {
ByteBuf byteBuf = Unpooled.buffer(RestClientEncoder.FORM_BUFFER_SIZE);
for (Entry<String, Object> entry : formMap.entrySet()) {
writeCharSequence(byteBuf, "\r\n--");
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientRequestParametersImpl.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientRequestParametersImpl.java
index b09eb02fb..53d9de772 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientRequestParametersImpl.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientRequestParametersImpl.java
@@ -20,9 +20,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import javax.annotation.Nonnull;
-import jakarta.servlet.http.Part;
-
import org.apache.servicecomb.foundation.common.utils.PartUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +29,7 @@ import com.google.common.collect.Multimap;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
+import jakarta.servlet.http.Part;
public class RestClientRequestParametersImpl implements RestClientRequestParameters {
private static final Logger LOGGER = LoggerFactory.getLogger(RestClientRequestParametersImpl.class);
@@ -46,7 +44,7 @@ public class RestClientRequestParametersImpl implements RestClientRequestParamet
protected Buffer bodyBuffer;
- public RestClientRequestParametersImpl(@Nonnull MultiMap headers) {
+ public RestClientRequestParametersImpl(MultiMap headers) {
this.headers = headers;
}
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientSenderFilter.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientSenderFilter.java
index 34764effb..8ee02c360 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientSenderFilter.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestClientSenderFilter.java
@@ -18,8 +18,6 @@ package org.apache.servicecomb.transport.rest.client;
import java.util.concurrent.CompletableFuture;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.filter.ConsumerFilter;
@@ -31,7 +29,6 @@ import org.apache.servicecomb.swagger.invocation.Response;
public class RestClientSenderFilter implements ConsumerFilter {
public static final String NAME = "rest-client-sender";
- @Nonnull
@Override
public String getName() {
return NAME;
diff --git a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocationCreator.java b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocationCreator.java
index a12ee8cc0..1b31cf953 100644
--- a/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocationCreator.java
+++ b/transports/transport-rest/transport-rest-servlet/src/main/java/org/apache/servicecomb/transport/rest/servlet/RestServletProducerInvocationCreator.java
@@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.transport.rest.servlet;
-import javax.annotation.Nonnull;
-
import org.apache.servicecomb.common.rest.HttpTransportContext;
import org.apache.servicecomb.common.rest.RestProducerInvocationCreator;
import org.apache.servicecomb.core.Endpoint;
@@ -27,8 +25,8 @@ import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
public class RestServletProducerInvocationCreator extends RestProducerInvocationCreator {
- public RestServletProducerInvocationCreator(@Nonnull MicroserviceMeta microserviceMeta, @Nonnull Endpoint endpoint,
- @Nonnull HttpServletRequestEx requestEx, @Nonnull HttpServletResponseEx responseEx) {
+ public RestServletProducerInvocationCreator(MicroserviceMeta microserviceMeta, Endpoint endpoint,
+ HttpServletRequestEx requestEx, HttpServletResponseEx responseEx) {
super(microserviceMeta, endpoint, requestEx, responseEx);
}
[servicecomb-java-chassis] 07/25: [SCB-2008]remove archaius dependency: apollo adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 55f827169e15eeaa7f597bd11074ce23ff127fc9
Author: liubao <bi...@qq.com>
AuthorDate: Mon Sep 25 17:24:12 2023 +0800
[SCB-2008]remove archaius dependency: apollo adapter
---
.../core/ConfigurationSpringInitializer.java | 2 +-
.../config/{client => apollo}/ApolloClient.java | 10 +-
.../config/{client => apollo}/ApolloConfig.java | 2 +-
.../apollo/ApolloDynamicPropertiesSource.java | 79 +++++++++++
.../{client => apollo}/ConfigurationAction.java | 2 +-
.../sources/ApolloConfigurationSourceImpl.java | 147 ---------------------
...comb.config.spi.ConfigCenterConfigurationSource | 18 ---
.../{client => apollo}/ApolloClientTest.java | 6 +-
.../{client => apollo}/ApolloConfigTest.java | 3 +-
.../sources/ApolloConfigurationSourceImplTest.java | 78 -----------
.../servicecomb/config/BootStrapProperties.java | 142 ++++++--------------
.../org/apache/servicecomb/config/ConfigUtil.java | 5 +-
.../config/DynamicPropertiesSource.java | 11 +-
.../config/BootStrapPropertiesTest.java | 12 +-
.../tracing/zipkin/TracingConfiguration.java | 5 +-
.../servicecomb/registry/lightweight/Self.java | 17 ++-
.../model/AbstractPropertiesLoader.java | 20 +--
.../model/InstancePropertiesLoader.java | 9 +-
.../lightweight/model/MicroserviceFactory.java | 23 ++--
.../lightweight/model/MicroserviceInstance.java | 23 ++--
.../config/TestAbstractPropertiesLoader.java | 14 +-
.../servicecomb/localregistry/RegistryBean.java | 2 +-
22 files changed, 205 insertions(+), 425 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
index f814f1209..b1fe6adc3 100644
--- a/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
+++ b/core/src/main/java/org/apache/servicecomb/core/ConfigurationSpringInitializer.java
@@ -119,7 +119,7 @@ public class ConfigurationSpringInitializer extends PropertySourcesPlaceholderCo
// watch configuration changes
EventManager.register(this);
- configCenterConfigurationSource = ConfigUtil.installDynamicConfig();
+ configCenterConfigurationSource = ConfigUtil.installDynamicConfig(environment);
addDynamicConfigurationToSpring(environment, configCenterConfigurationSource);
}
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
similarity index 94%
rename from dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
rename to dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
index 80820abdb..acd4a4dff 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloClient.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloClient.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config.apollo;
-import static org.apache.servicecomb.config.client.ConfigurationAction.CREATE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.DELETE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.SET;
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.CREATE;
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.DELETE;
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.SET;
import java.io.IOException;
import java.util.HashMap;
@@ -30,7 +30,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.google.common.annotations.VisibleForTesting;
-import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler;
+import org.apache.servicecomb.config.apollo.ApolloDynamicPropertiesSource.UpdateHandler;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloConfig.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
similarity index 98%
rename from dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloConfig.java
rename to dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
index b8de462e3..605912e36 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ApolloConfig.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloConfig.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config.apollo;
import org.apache.commons.configuration.Configuration;
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
new file mode 100644
index 000000000..01dc1a434
--- /dev/null
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ApolloDynamicPropertiesSource.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.config.apollo;
+
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.CREATE;
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.DELETE;
+import static org.apache.servicecomb.config.apollo.ConfigurationAction.SET;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicecomb.config.ConfigMapping;
+import org.apache.servicecomb.config.DynamicPropertiesSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
+
+public class ApolloDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
+ public static final String SOURCE_NAME = "apollo";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApolloDynamicPropertiesSource.class);
+
+ private final Map<String, Object> valueCache = new ConcurrentHashMap<>();
+
+ private final ApolloDynamicPropertiesSource.UpdateHandler updateHandler =
+ new ApolloDynamicPropertiesSource.UpdateHandler();
+
+ @Override
+ public int getOrder() {
+ return 300;
+ }
+
+ private void init() {
+ ApolloClient apolloClient = new ApolloClient(updateHandler);
+ apolloClient.refreshApolloConfig();
+ }
+
+ public class UpdateHandler {
+ public void handle(ConfigurationAction action, Map<String, Object> config) {
+ if (config == null || config.isEmpty()) {
+ return;
+ }
+ Map<String, Object> configuration = ConfigMapping.getConvertedMap(config);
+ if (CREATE.equals(action)) {
+ valueCache.putAll(configuration);
+ } else if (SET.equals(action)) {
+ valueCache.putAll(configuration);
+ } else if (DELETE.equals(action)) {
+ configuration.keySet().forEach(valueCache::remove);
+ } else {
+ LOGGER.error("action: {} is invalid.", action.name());
+ return;
+ }
+ LOGGER.warn("Config value cache changed: action:{}; item:{}", action.name(), configuration.keySet());
+ }
+ }
+
+ @Override
+ public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
+ init();
+ return new MapPropertySource(SOURCE_NAME, valueCache);
+ }
+}
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ConfigurationAction.java
similarity index 94%
copy from dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java
copy to dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ConfigurationAction.java
index 5daf1972c..1a0047152 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java
+++ b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/apollo/ConfigurationAction.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config.apollo;
public enum ConfigurationAction {
CREATE,
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java b/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
deleted file mode 100644
index 3b261249f..000000000
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImpl.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.sources;
-
-import static com.netflix.config.WatchedUpdateResult.createIncremental;
-import static org.apache.servicecomb.config.client.ConfigurationAction.CREATE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.DELETE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.SET;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.config.ConfigMapping;
-import org.apache.servicecomb.config.client.ApolloClient;
-import org.apache.servicecomb.config.client.ApolloConfig;
-import org.apache.servicecomb.config.client.ConfigurationAction;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ImmutableMap;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-
-public class ApolloConfigurationSourceImpl implements ConfigCenterConfigurationSource {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSource.class);
-
- private final Map<String, Object> valueCache = new ConcurrentHashMap<>();
-
- private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
-
- private static final String APOLLO_CONFIG_URL_KEY = "apollo.config.serverUri";
-
- public ApolloConfigurationSourceImpl() {
- }
-
- private final UpdateHandler updateHandler = new UpdateHandler();
-
- @VisibleForTesting
- UpdateHandler getUpdateHandler() {
- return updateHandler;
- }
-
- @Override
- public int getOrder() {
- return ORDER_BASE * 3;
- }
-
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- if (localConfiguration.getProperty(APOLLO_CONFIG_URL_KEY) == null) {
- LOGGER.warn("Apollo configuration source is not configured!");
- return false;
- }
- return true;
- }
-
- @Override
- public void init(Configuration localConfiguration) {
- ApolloConfig.setConcurrentCompositeConfiguration(localConfiguration);
- init();
- }
-
- private void init() {
- ApolloClient apolloClient = new ApolloClient(updateHandler);
- apolloClient.refreshApolloConfig();
- }
-
- @Override
- public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.add(watchedUpdateListener);
- }
-
- @Override
- public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.remove(watchedUpdateListener);
- }
-
- private void updateConfiguration(WatchedUpdateResult result) {
- for (WatchedUpdateListener l : listeners) {
- try {
- l.updateConfiguration(result);
- } catch (Throwable ex) {
- LOGGER.error("Error in invoking WatchedUpdateListener", ex);
- }
- }
- }
-
- @Override
- public Map<String, Object> getCurrentData() throws Exception {
- return valueCache;
- }
-
- public List<WatchedUpdateListener> getCurrentListeners() {
- return listeners;
- }
-
- public class UpdateHandler {
- public void handle(ConfigurationAction action, Map<String, Object> config) {
- if (config == null || config.isEmpty()) {
- return;
- }
- Map<String, Object> configuration = ConfigMapping.getConvertedMap(config);
- if (CREATE.equals(action)) {
- valueCache.putAll(configuration);
-
- updateConfiguration(createIncremental(ImmutableMap.copyOf(configuration),
- null,
- null));
- } else if (SET.equals(action)) {
- valueCache.putAll(configuration);
-
- updateConfiguration(createIncremental(null,
- ImmutableMap.copyOf(configuration),
- null));
- } else if (DELETE.equals(action)) {
- configuration.keySet().forEach(valueCache::remove);
- updateConfiguration(createIncremental(null,
- null,
- ImmutableMap.copyOf(configuration)));
- } else {
- LOGGER.error("action: {} is invalid.", action.name());
- return;
- }
- LOGGER.warn("Config value cache changed: action:{}; item:{}", action.name(), configuration.keySet());
- }
- }
-}
diff --git a/dynamic-config/config-apollo/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/dynamic-config/config-apollo/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
deleted file mode 100644
index fa6f9b758..000000000
--- a/dynamic-config/config-apollo/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
similarity index 94%
rename from dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java
rename to dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
index 66ae6c18f..a531a2ea3 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloClientTest.java
@@ -15,15 +15,17 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config.apollo;
import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.apollo.ApolloClient;
+import org.apache.servicecomb.config.apollo.ApolloConfig;
import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl;
import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler;
-import org.apache.servicecomb.config.client.ApolloClient.ConfigRefresh;
+import org.apache.servicecomb.config.apollo.ApolloClient.ConfigRefresh;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloConfigTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java
similarity index 94%
rename from dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloConfigTest.java
rename to dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java
index dfcdbbeb9..01a550609 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloConfigTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/apollo/ApolloConfigTest.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.client;
+package org.apache.servicecomb.config.apollo;
import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.apollo.ApolloConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImplTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImplTest.java
deleted file mode 100644
index b01640c9b..000000000
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/archaius/sources/ApolloConfigurationSourceImplTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.config.archaius.sources;
-
-import static org.apache.servicecomb.config.client.ConfigurationAction.CREATE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.DELETE;
-import static org.apache.servicecomb.config.client.ConfigurationAction.SET;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-import com.netflix.config.WatchedUpdateListener;
-
-public class ApolloConfigurationSourceImplTest {
- @Test
- public void testCreate() throws Exception {
-
- ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
- apolloConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getAdded().isEmpty()));
- UpdateHandler updateHandler = apolloConfigurationSource.getUpdateHandler();
- Map<String, Object> createItems = new HashMap<>();
- createItems.put("testKey", "testValue");
- updateHandler.handle(CREATE, createItems);
- }
-
- @Test
- public void testUpdate() throws Exception {
-
- ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
- apolloConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getChanged().isEmpty()));
- UpdateHandler updateHandler = apolloConfigurationSource.getUpdateHandler();
- Map<String, Object> updateItems = new HashMap<>();
- updateItems.put("testKey", "testValue");
- updateHandler.handle(SET, updateItems);
- }
-
- @Test
- public void testDelete() throws Exception {
- ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
- apolloConfigurationSource.addUpdateListener(result -> Assertions.assertFalse(result.getDeleted().isEmpty()));
- UpdateHandler updateHandler = apolloConfigurationSource.getUpdateHandler();
- Map<String, Object> deleteItems = new HashMap<>();
- deleteItems.put("testKey", "testValue");
-
- apolloConfigurationSource.getCurrentData().put("testKey", "testValue");
- updateHandler.handle(DELETE, deleteItems);
- Assertions.assertTrue(apolloConfigurationSource.getCurrentData().isEmpty());
- }
-
- @Test
- public void testRemoveUpdateListener() {
- ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
- WatchedUpdateListener watchedUpdateListener = Mockito.mock(WatchedUpdateListener.class);
- apolloConfigurationSource.addUpdateListener(watchedUpdateListener);
- apolloConfigurationSource.removeUpdateListener(watchedUpdateListener);
- Assertions.assertTrue(apolloConfigurationSource.getCurrentListeners().isEmpty());
- }
-}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
index 7c18f5811..81ed8ed00 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
@@ -17,16 +17,14 @@
package org.apache.servicecomb.config;
-import java.util.LinkedHashMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
+import java.util.Set;
-import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertyConverter;
-import org.apache.commons.configuration.SubsetConfiguration;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.core.env.Environment;
/**
@@ -108,49 +106,31 @@ public class BootStrapProperties {
public static final String DEFAULT_MICROSERVICE_INSTANCE_INITIAL_STATUS = "UP";
- private static final Configuration configuration = ConfigUtil.createLocalConfig();
-
- public static String readApplication(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_APPLICATION,
+ public static String readApplication(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_APPLICATION,
OLD_CONFIG_SERVICE_APPLICATION, DEFAULT_APPLICATION);
}
- public static String readApplication() {
- return readApplication(BootStrapProperties.configuration);
- }
-
- public static String readServiceName(Configuration configuration) {
- String result = readStringValue(configuration, CONFIG_SERVICE_NAME, OLD_CONFIG_SERVICE_NAME,
+ public static String readServiceName(Environment environment) {
+ String result = readStringValue(environment, CONFIG_SERVICE_NAME, OLD_CONFIG_SERVICE_NAME,
DEFAULT_MICROSERVICE_NAME);
checkMicroserviceName(result);
return result;
}
- public static String readServiceName() {
- return readServiceName(BootStrapProperties.configuration);
- }
-
- public static String readServiceVersion(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_VERSION, OLD_CONFIG_SERVICE_VERSION,
+ public static String readServiceVersion(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_VERSION, OLD_CONFIG_SERVICE_VERSION,
DEFAULT_MICROSERVICE_VERSION);
}
- public static String readServiceVersion() {
- return readServiceVersion(BootStrapProperties.configuration);
- }
-
- public static String readServiceRole(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_ROLE, OLD_CONFIG_SERVICE_ROLE, DEFAULT_MICROSERVICE_ROLE);
- }
-
- public static String readServiceRole() {
- return readServiceRole(BootStrapProperties.configuration);
+ public static String readServiceRole(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_ROLE, OLD_CONFIG_SERVICE_ROLE, DEFAULT_MICROSERVICE_ROLE);
}
- public static String readServiceDescription(Configuration configuration) {
- String[] descriptionArray = configuration.getStringArray(CONFIG_SERVICE_DESCRIPTION);
+ public static String readServiceDescription(Environment environment) {
+ String[] descriptionArray = environment.getProperty(CONFIG_SERVICE_DESCRIPTION, String[].class);
if (null == descriptionArray || descriptionArray.length < 1) {
- descriptionArray = configuration.getStringArray(OLD_CONFIG_SERVICE_DESCRIPTION);
+ descriptionArray = environment.getProperty(OLD_CONFIG_SERVICE_DESCRIPTION, String[].class);
}
if (null == descriptionArray || descriptionArray.length < 1) {
@@ -165,34 +145,18 @@ public class BootStrapProperties {
return rawDescriptionBuilder.substring(0, rawDescriptionBuilder.length() - 1);
}
- public static String readServiceDescription() {
- return readServiceDescription(BootStrapProperties.configuration);
- }
-
- public static String readServiceEnvironment(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_ENVIRONMENT, OLD_CONFIG_SERVICE_ENVIRONMENT,
+ public static String readServiceEnvironment(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_ENVIRONMENT, OLD_CONFIG_SERVICE_ENVIRONMENT,
DEFAULT_MICROSERVICE_ENVIRONMENT);
}
- public static String readServiceEnvironment() {
- return readServiceEnvironment(BootStrapProperties.configuration);
- }
-
- public static String readServiceExtendedClass(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_EXTENDED_CLASS, OLD_CONFIG_SERVICE_EXTENDED_CLASS,
+ public static String readServiceExtendedClass(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_EXTENDED_CLASS, OLD_CONFIG_SERVICE_EXTENDED_CLASS,
null);
}
- public static String readServiceExtendedClass() {
- return readServiceExtendedClass(BootStrapProperties.configuration);
- }
-
- public static Map<String, String> readServiceProperties(Configuration configuration) {
- return readProperties(configuration, CONFIG_SERVICE_PROPERTIES, OLD_CONFIG_SERVICE_PROPERTIES);
- }
-
- public static Map<String, String> readServiceProperties() {
- return readServiceProperties(BootStrapProperties.configuration);
+ public static Map<String, String> readServiceProperties(Environment environment) {
+ return readProperties(environment, CONFIG_SERVICE_PROPERTIES, OLD_CONFIG_SERVICE_PROPERTIES);
}
public static List<Object> readServicePaths(Configuration configuration) {
@@ -203,73 +167,41 @@ public class BootStrapProperties {
return result;
}
- public static List<Object> readServicePaths() {
- return readServicePaths(BootStrapProperties.configuration);
- }
-
- public static Map<String, String> readServiceInstanceProperties(Configuration configuration) {
- return readProperties(configuration, CONFIG_SERVICE_INSTANCE_PROPERTIES, OLD_CONFIG_SERVICE_INSTANCE_PROPERTIES);
- }
-
- public static Map<String, String> readServiceInstanceProperties() {
- return readServiceInstanceProperties(BootStrapProperties.configuration);
+ public static Map<String, String> readServiceInstanceProperties(Environment environment) {
+ return readProperties(environment, CONFIG_SERVICE_INSTANCE_PROPERTIES, OLD_CONFIG_SERVICE_INSTANCE_PROPERTIES);
}
- public static String readServiceInstanceExtendedClass(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_INSTANCE_EXTENDED_CLASS,
+ public static String readServiceInstanceExtendedClass(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_INSTANCE_EXTENDED_CLASS,
OLD_CONFIG_SERVICE_INSTANCE_EXTENDED_CLASS,
null);
}
- public static String readServiceInstanceExtendedClass() {
- return readServiceInstanceExtendedClass(BootStrapProperties.configuration);
- }
-
- public static String readServiceInstanceInitialStatus(Configuration configuration) {
- return readStringValue(configuration, CONFIG_SERVICE_INSTANCE_INITIAL_STATUS,
+ public static String readServiceInstanceInitialStatus(Environment environment) {
+ return readStringValue(environment, CONFIG_SERVICE_INSTANCE_INITIAL_STATUS,
OLD_CONFIG_SERVICE_INSTANCE_INITIAL_STATUS,
DEFAULT_MICROSERVICE_INSTANCE_INITIAL_STATUS);
}
- public static String readServiceInstanceInitialStatus() {
- return readServiceInstanceInitialStatus(BootStrapProperties.configuration);
- }
-
- private static String readStringValue(Configuration configuration, String newKey, String oldKey,
+ private static String readStringValue(Environment environment, String newKey, String oldKey,
String defaultValue) {
- String result = configuration.getString(newKey, null);
+ String result = environment.getProperty(newKey);
if (result == null) {
- return configuration.getString(oldKey, defaultValue);
+ return environment.getProperty(oldKey, defaultValue);
}
return result;
}
- private static Map<String, String> readProperties(Configuration configuration, String newKey, String oldKey) {
- AbstractConfiguration subset = (AbstractConfiguration) configuration.subset(newKey);
- if (subset.isEmpty()) {
- subset = (AbstractConfiguration) configuration.subset(oldKey);
+ private static Map<String, String> readProperties(Environment environment, String newKey, String oldKey) {
+ Set<String> keys = ConfigUtil.propertiesWithPrefix(environment, newKey);
+ if (keys.isEmpty()) {
+ keys = ConfigUtil.propertiesWithPrefix(environment, oldKey);
}
- return toStringMap(subset);
- }
-
- private static Map<String, String> toStringMap(AbstractConfiguration configuration) {
- AbstractConfiguration root = findRoot(configuration);
- Map<String, String> map = new LinkedHashMap<>();
- configuration.getKeys().forEachRemaining(key -> {
- Object value = configuration.getProperty(key);
- // support placeholder
- value = PropertyConverter.interpolate(value, root);
- map.put(key, Objects.toString(value, null));
- });
- return map;
- }
-
- private static AbstractConfiguration findRoot(AbstractConfiguration configuration) {
- if (configuration instanceof SubsetConfiguration) {
- return findRoot((AbstractConfiguration) ((SubsetConfiguration) configuration).getParent());
+ Map<String, String> result = new HashMap<>(keys.size());
+ for (String key : keys) {
+ result.put(key, environment.getProperty(key));
}
-
- return configuration;
+ return result;
}
private static void checkMicroserviceName(String name) {
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index c9c3908fd..11c002c3e 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -53,6 +53,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import com.netflix.config.ConcurrentCompositeConfiguration;
@@ -289,9 +290,9 @@ public final class ConfigUtil {
}
}
- public static Set<String> propertiesWithPrefix(ConfigurableEnvironment environment, String prefix) {
+ public static Set<String> propertiesWithPrefix(Environment environment, String prefix) {
Set<String> result = new HashSet<>();
- for (PropertySource<?> propertySource : environment.getPropertySources()) {
+ for (PropertySource<?> propertySource : ((ConfigurableEnvironment) environment).getPropertySources()) {
if (propertySource instanceof EnumerablePropertySource) {
for (String key : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
if (key.startsWith(prefix)) {
diff --git a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesSource.java
similarity index 71%
rename from dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java
rename to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesSource.java
index 5daf1972c..8833d26af 100644
--- a/dynamic-config/config-apollo/src/main/java/org/apache/servicecomb/config/client/ConfigurationAction.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesSource.java
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.config;
-package org.apache.servicecomb.config.client;
+import org.springframework.core.Ordered;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
-public enum ConfigurationAction {
- CREATE,
- SET,
- DELETE
+public interface DynamicPropertiesSource<T> extends Ordered {
+ EnumerablePropertySource<T> create(Environment environment);
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
index 7187bb8e3..1513ae6ad 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
@@ -21,16 +21,20 @@ import static org.apache.servicecomb.foundation.test.scaffolding.AssertUtils.ass
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
+import java.util.Map.Entry;
-import org.apache.commons.configuration.MapConfiguration;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.ConfigurableEnvironment;
class BootStrapPropertiesTest {
private Map<String, String> readInstanceProperties(String yaml) {
Map<String, Object> properties = YAMLUtil.yaml2Properties(yaml);
- MapConfiguration configuration = new MapConfiguration(properties);
-
- return BootStrapProperties.readServiceInstanceProperties(configuration);
+ ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+ for (Entry<String, Object> entry : properties.entrySet()) {
+ Mockito.when(environment.getProperty(entry.getKey())).thenReturn(entry.getValue().toString());
+ }
+ return BootStrapProperties.readServiceInstanceProperties(environment);
}
@Test
diff --git a/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/TracingConfiguration.java b/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/TracingConfiguration.java
index 2ab531b80..5d972825b 100644
--- a/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/TracingConfiguration.java
+++ b/handlers/handler-tracing-zipkin/src/main/java/org/apache/servicecomb/tracing/zipkin/TracingConfiguration.java
@@ -31,6 +31,7 @@ import org.apache.servicecomb.config.DynamicProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
import brave.Tracing;
import brave.context.slf4j.MDCScopeDecorator;
@@ -86,9 +87,9 @@ public class TracingConfiguration {
@Bean
Tracing tracing(Sender sender, DynamicProperties dynamicProperties,
- CurrentTraceContext currentTraceContext) {
+ CurrentTraceContext currentTraceContext, Environment environment) {
return Tracing.newBuilder()
- .localServiceName(BootStrapProperties.readServiceName())
+ .localServiceName(BootStrapProperties.readServiceName(environment))
.currentTraceContext(currentTraceContext) // puts trace IDs into logs
.addSpanHandler(AsyncZipkinSpanHandler.create(sender))
.build();
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/Self.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/Self.java
index 76cc82588..c9b863eae 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/Self.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/Self.java
@@ -19,15 +19,15 @@ package org.apache.servicecomb.registry.lightweight;
import java.util.UUID;
-import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.registry.lightweight.model.Microservice;
import org.apache.servicecomb.registry.lightweight.model.MicroserviceFactory;
import org.apache.servicecomb.registry.lightweight.model.MicroserviceInstance;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.google.common.annotations.VisibleForTesting;
-import com.netflix.config.ConfigurationManager;
public class Self implements InitializingBean, BootListener {
private Microservice microservice;
@@ -39,14 +39,21 @@ public class Self implements InitializingBean, BootListener {
private final MicroserviceInfo microserviceInfo = new MicroserviceInfo();
+ private Environment environment;
+
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
@Override
public void afterPropertiesSet() {
- init(ConfigurationManager.getConfigInstance());
+ init(environment);
}
@VisibleForTesting
- public Self init(AbstractConfiguration configuration) {
- microservice = new MicroserviceFactory().create(configuration);
+ public Self init(Environment environment) {
+ microservice = new MicroserviceFactory().create(environment);
microservice.serviceId(String.format("%s/%s/%s/%s",
microservice.getEnvironment(),
microservice.getAppId(),
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/AbstractPropertiesLoader.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/AbstractPropertiesLoader.java
index ce93adda9..5153e09a6 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/AbstractPropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/AbstractPropertiesLoader.java
@@ -20,11 +20,11 @@ package org.apache.servicecomb.registry.lightweight.model;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.registry.api.PropertyExtended;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
/**
* Loading microservice properties
@@ -32,24 +32,24 @@ import org.slf4j.LoggerFactory;
public abstract class AbstractPropertiesLoader {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPropertiesLoader.class);
- public Map<String, String> loadProperties(Configuration configuration) {
+ public Map<String, String> loadProperties(Environment environment) {
Map<String, String> propertiesMap = new HashMap<>();
- loadPropertiesFromConfigMap(configuration, propertiesMap);
- loadPropertiesFromExtendedClass(configuration, propertiesMap);
+ loadPropertiesFromConfigMap(environment, propertiesMap);
+ loadPropertiesFromExtendedClass(environment, propertiesMap);
return propertiesMap;
}
- protected abstract Map<String, String> readProperties(Configuration configuration);
+ protected abstract Map<String, String> readProperties(Environment environment);
- protected abstract String readPropertiesExtendedClass(Configuration configuration);
+ protected abstract String readPropertiesExtendedClass(Environment environment);
- private void loadPropertiesFromConfigMap(Configuration configuration, Map<String, String> propertiesMap) {
- propertiesMap.putAll(readProperties(configuration));
+ private void loadPropertiesFromConfigMap(Environment environment, Map<String, String> propertiesMap) {
+ propertiesMap.putAll(readProperties(environment));
}
- private void loadPropertiesFromExtendedClass(Configuration configuration, Map<String, String> propertiesMap) {
- String extendedPropertyClass = readPropertiesExtendedClass(configuration);
+ private void loadPropertiesFromExtendedClass(Environment environment, Map<String, String> propertiesMap) {
+ String extendedPropertyClass = readPropertiesExtendedClass(environment);
if (StringUtils.isEmpty(extendedPropertyClass)) {
return;
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
index a483549e2..33bfff41c 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/InstancePropertiesLoader.java
@@ -21,6 +21,7 @@ import java.util.Map;
import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.BootStrapProperties;
+import org.springframework.core.env.Environment;
public final class InstancePropertiesLoader extends AbstractPropertiesLoader {
@@ -31,12 +32,12 @@ public final class InstancePropertiesLoader extends AbstractPropertiesLoader {
@Override
- protected Map<String, String> readProperties(Configuration configuration) {
- return BootStrapProperties.readServiceInstanceProperties(configuration);
+ protected Map<String, String> readProperties(Environment environment) {
+ return BootStrapProperties.readServiceInstanceProperties(environment);
}
@Override
- protected String readPropertiesExtendedClass(Configuration configuration) {
- return BootStrapProperties.readServiceInstanceExtendedClass(configuration);
+ protected String readPropertiesExtendedClass(Environment environment) {
+ return BootStrapProperties.readServiceInstanceExtendedClass(environment);
}
}
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
index a542ced1b..b4612b2ac 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceFactory.java
@@ -28,15 +28,16 @@ import org.apache.commons.configuration.EnvironmentConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.foundation.common.Version;
+import org.springframework.core.env.Environment;
public class MicroserviceFactory {
- public Microservice create(Configuration configuration) {
- Microservice microservice = createMicroserviceFromConfiguration(configuration);
- microservice.setInstance(MicroserviceInstance.createFromDefinition(configuration));
+ public Microservice create(Environment environment) {
+ Microservice microservice = createMicroserviceFromConfiguration(environment);
+ microservice.setInstance(MicroserviceInstance.createFromDefinition(environment));
return microservice;
}
- private Microservice createMicroserviceFromConfiguration(Configuration configuration) {
+ private Microservice createMicroserviceFromConfiguration(Environment environment) {
Microservice microservice = new Microservice();
EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
@@ -44,30 +45,30 @@ public class MicroserviceFactory {
!StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
} else {
- microservice.setAppId(BootStrapProperties.readApplication(configuration));
+ microservice.setAppId(BootStrapProperties.readApplication(environment));
}
if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) &&
!StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
} else {
- microservice.setServiceName(BootStrapProperties.readServiceName(configuration));
+ microservice.setServiceName(BootStrapProperties.readServiceName(environment));
}
String version;
if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) &&
!StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
} else {
- version = BootStrapProperties.readServiceVersion(configuration);
+ version = BootStrapProperties.readServiceVersion(environment);
}
// just check version format
new Version(version);
microservice.setVersion(version);
- microservice.setDescription(BootStrapProperties.readServiceDescription(configuration));
- microservice.setLevel(BootStrapProperties.readServiceRole(configuration));
- Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(configuration);
+ microservice.setDescription(BootStrapProperties.readServiceDescription(environment));
+ microservice.setLevel(BootStrapProperties.readServiceRole(environment));
+ Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(environment);
microservice.setProperties(propertiesMap);
- microservice.setEnvironment(BootStrapProperties.readServiceEnvironment(configuration));
+ microservice.setEnvironment(BootStrapProperties.readServiceEnvironment(environment));
// set alias name when allow cross app
if (microservice.allowCrossApp()) {
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceInstance.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceInstance.java
index 740ddd619..2d9192817 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceInstance.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroserviceInstance.java
@@ -22,15 +22,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.registry.api.DataCenterInfo;
import org.apache.servicecomb.registry.api.MicroserviceInstanceStatus;
import org.apache.servicecomb.registry.definition.DefinitionConst;
+import org.springframework.core.env.Environment;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.netflix.config.DynamicPropertyFactory;
/**
* Created by on 2016/12/5.
@@ -177,36 +176,32 @@ public class MicroserviceInstance {
}
// Some properties of microservice instance are dynamic changed, not cover them all now.
- public static MicroserviceInstance createFromDefinition(Configuration configuration) {
+ public static MicroserviceInstance createFromDefinition(Environment environment) {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
// default hard coded values
microserviceInstance.setStage(DefinitionConst.DEFAULT_STAGE);
microserviceInstance.setStatus(MicroserviceInstanceStatus
- .valueOf(BootStrapProperties.readServiceInstanceInitialStatus()));
+ .valueOf(BootStrapProperties.readServiceInstanceInitialStatus(environment)));
HealthCheck healthCheck = new HealthCheck();
healthCheck.setMode(HealthCheckMode.HEARTBEAT);
microserviceInstance.setHealthCheck(healthCheck);
// load properties
- Map<String, String> propertiesMap = InstancePropertiesLoader.INSTANCE.loadProperties(configuration);
+ Map<String, String> propertiesMap = InstancePropertiesLoader.INSTANCE.loadProperties(environment);
microserviceInstance.setProperties(propertiesMap);
// load data center information
- loadDataCenterInfo(microserviceInstance);
+ loadDataCenterInfo(environment, microserviceInstance);
return microserviceInstance;
}
- private static void loadDataCenterInfo(MicroserviceInstance microserviceInstance) {
- String dataCenterName = DynamicPropertyFactory.getInstance()
- .getStringProperty("servicecomb.datacenter.name", null)
- .get();
+ private static void loadDataCenterInfo(Environment environment, MicroserviceInstance microserviceInstance) {
+ String dataCenterName = environment.getProperty("servicecomb.datacenter.name");
if (StringUtils.isEmpty(dataCenterName)) {
return;
}
- String region = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.datacenter.region", null).get();
- String availableZone = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.datacenter.availableZone", null).get();
+ String region = environment.getProperty("servicecomb.datacenter.region");
+ String availableZone = environment.getProperty("servicecomb.datacenter.availableZone");
DataCenterInfo dataCenterInfo = new DataCenterInfo();
dataCenterInfo.setName(dataCenterName);
dataCenterInfo.setRegion(region);
diff --git a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
index 6a85fb26b..9f7692e87 100644
--- a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
@@ -17,25 +17,23 @@
package org.apache.servicecomb.registry.config;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.BootStrapProperties;
-
-import com.netflix.config.DynamicConfiguration;
-
import org.apache.servicecomb.registry.lightweight.model.AbstractPropertiesLoader;
import org.apache.servicecomb.registry.lightweight.model.MicroservicePropertiesLoader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class TestAbstractPropertiesLoader {
@Test
public void testExtendedClassCompatible() {
- Configuration configuration = new DynamicConfiguration();
- configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_EXTENDED_CLASS, "invalidClass");
-
+ Environment environment = Mockito.mock(Environment.class);
+ Mockito.when(environment.getProperty(BootStrapProperties.CONFIG_SERVICE_EXTENDED_CLASS))
+ .thenReturn("invalidClass");
AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE;
try {
- loader.loadProperties(configuration);
+ loader.loadProperties(environment);
Assertions.fail("Must throw exception");
} catch (Error e) {
Assertions.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
diff --git a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/RegistryBean.java b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/RegistryBean.java
index 3e224c9df..3a3ac85d4 100644
--- a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/RegistryBean.java
+++ b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/RegistryBean.java
@@ -120,7 +120,7 @@ public class RegistryBean {
if (!StringUtils.isEmpty(configAppId)) {
return configAppId;
}
- return BootStrapProperties.readApplication();
+ return BootStrapProperties.DEFAULT_APPLICATION;
}
public String getId() {
[servicecomb-java-chassis] 04/25: [SCB-2008]allows not injectable property in model
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit f2c562ddf92d01905bf828735404e263f0cb40ea
Author: liubao <bi...@qq.com>
AuthorDate: Fri Sep 22 16:46:19 2023 +0800
[SCB-2008]allows not injectable property in model
---
.../config/ConfigurationChangedEvent.java | 97 ++++++++++++++++++++++
.../config/priority/ConfigObjectFactory.java | 9 +-
.../config/priority/PriorityPropertyManager.java | 2 +
.../config/inject/TestConfigObjectFactory.java | 29 +++++++
.../priority/TestPriorityPropertyManager.java | 9 +-
.../registry/sc/MicroserviceHandler.java | 3 +
6 files changed, 141 insertions(+), 8 deletions(-)
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
new file mode 100644
index 000000000..ff56ae202
--- /dev/null
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigurationChangedEvent.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class ConfigurationChangedEvent {
+ private final Map<String, Object> added;
+
+ private final Map<String, Object> deleted;
+
+ private final Map<String, Object> updated;
+
+ private final boolean changed;
+
+ private Map<String, Object> complete;
+
+ private ConfigurationChangedEvent(Map<String, Object> added, Map<String, Object> updated,
+ Map<String, Object> deleted, boolean changed) {
+ this.added = added;
+ this.deleted = deleted;
+ this.updated = updated;
+ this.changed = changed;
+ }
+
+ public static ConfigurationChangedEvent createIncremental(Map<String, Object> latest, Map<String, Object> last) {
+ Map<String, Object> itemsCreated = new HashMap<>();
+ Map<String, Object> itemsDeleted = new HashMap<>();
+ Map<String, Object> itemsModified = new HashMap<>();
+ boolean changed = false;
+
+ for (Map.Entry<String, Object> entry : latest.entrySet()) {
+ String itemKey = entry.getKey();
+ if (!last.containsKey(itemKey)) {
+ itemsCreated.put(itemKey, entry.getValue());
+ changed = true;
+ } else if (!Objects.equals(last.get(itemKey), latest.get(itemKey))) {
+ itemsModified.put(itemKey, entry.getValue());
+ changed = true;
+ }
+ }
+ for (String itemKey : last.keySet()) {
+ if (!latest.containsKey(itemKey)) {
+ itemsDeleted.put(itemKey, null);
+ changed = true;
+ }
+ }
+ ConfigurationChangedEvent event = ConfigurationChangedEvent
+ .createIncremental(itemsCreated, itemsModified, itemsDeleted, changed);
+ event.complete = latest;
+ return event;
+ }
+
+ private static ConfigurationChangedEvent createIncremental(Map<String, Object> added, Map<String, Object> updated,
+ Map<String, Object> deleted, boolean changed) {
+ return new ConfigurationChangedEvent(added, updated, deleted, changed);
+ }
+
+ public final Map<String, Object> getAdded() {
+ return added;
+ }
+
+
+ public final Map<String, Object> getUpdated() {
+ return updated;
+ }
+
+
+ public final Map<String, Object> getDeleted() {
+ return deleted;
+ }
+
+ public final Map<String, Object> getComplete() {
+ return complete;
+ }
+
+ public final boolean isChanged() {
+ return changed;
+ }
+}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
index aa4248f7e..c5b9cf855 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
@@ -100,10 +100,13 @@ public class ConfigObjectFactory {
continue;
}
- Setter<Object, Object> setter = beanDescriptionCache.computeIfAbsent(propertyDefinition,
- LambdaMetafactoryUtils::createObjectSetter);
PriorityProperty<?> priorityProperty = createPriorityProperty(propertyDefinition.getField().getAnnotated(),
prefix, parameters);
+ if (priorityProperty == null) {
+ continue;
+ }
+ Setter<Object, Object> setter = beanDescriptionCache.computeIfAbsent(propertyDefinition,
+ LambdaMetafactoryUtils::createObjectSetter);
setter.set(instance, priorityProperty.getValue());
properties.add(new ConfigObjectProperty(setter, priorityProperty));
}
@@ -138,7 +141,7 @@ public class ConfigObjectFactory {
case "java.lang.Boolean":
return createBooleanProperty(field, keys, null);
default:
- throw new IllegalStateException("not support, field=" + field);
+ return null;
}
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
index c1e47ac30..95b37a037 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
@@ -28,6 +28,7 @@ import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
+import com.google.common.annotations.VisibleForTesting;
import com.netflix.config.ConfigurationManager;
public class PriorityPropertyManager {
@@ -70,6 +71,7 @@ public class PriorityPropertyManager {
}
}
+ @VisibleForTesting
public Map<Object, List<ConfigObjectProperty>> getConfigObjectMap() {
return configObjectMap;
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
index b80bb60bf..ec9412898 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestConfigObjectFactory.java
@@ -423,4 +423,33 @@ public class TestConfigObjectFactory extends TestPriorityPropertyBase {
ArchaiusUtils.setProperty("override.low", null);
Assertions.assertNull(config.strValue);
}
+
+ @InjectProperties(prefix = "root")
+ public static class ConfigWithPojo {
+
+ @InjectProperties(prefix = "root.model")
+ public static class Model {
+ @InjectProperty(defaultValue = "h")
+ public String name;
+ }
+
+ @InjectProperty(defaultValue = "4")
+ public int index;
+
+ public Model model;
+ }
+
+ @Test
+ public void configWithPojoWork() {
+ ConfigWithPojo config = priorityPropertyManager.createConfigObject(ConfigWithPojo.class);
+ ConfigWithPojo.Model model = priorityPropertyManager.createConfigObject(ConfigWithPojo.Model.class);
+ config.model = model;
+
+ Assertions.assertEquals(4, config.index);
+ Assertions.assertEquals("h", config.model.name);
+ ArchaiusUtils.setProperty("root.index", "5");
+ ArchaiusUtils.setProperty("root.model.name", "w");
+ Assertions.assertEquals(5, config.index);
+ Assertions.assertEquals("w", config.model.name);
+ }
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
index 294a506df..15e223b3e 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/priority/TestPriorityPropertyManager.java
@@ -20,7 +20,6 @@ package org.apache.servicecomb.config.priority;
import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.inject.InjectProperties;
import org.apache.servicecomb.config.inject.InjectProperty;
-import org.apache.servicecomb.config.inject.TestConfigObjectFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -37,7 +36,7 @@ public class TestPriorityPropertyManager extends TestPriorityPropertyBase {
@InjectProperties(prefix = "root")
public static class ConfigWithAnnotation {
- @InjectProperty(prefix = "override", keys = {"high", "low"})
+ @InjectProperty(prefix = "override", keys = {"high", "low"}, defaultValue = "abc")
public String strValue;
}
@@ -65,9 +64,9 @@ public class TestPriorityPropertyManager extends TestPriorityPropertyBase {
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
- TestConfigObjectFactory.ConfigWithAnnotation configConfigObject = priorityPropertyManager.createConfigObject(
- TestConfigObjectFactory.ConfigWithAnnotation.class);
- Assertions.assertEquals("abc", configConfigObject.strDef);
+ ConfigWithAnnotation configConfigObject = priorityPropertyManager.createConfigObject(
+ ConfigWithAnnotation.class);
+ Assertions.assertEquals("abc", configConfigObject.strValue);
PriorityProperty<Long> configPriorityProperty = propertyFactory.getOrCreate(Long.class, -1L, -2L, keys);
Assertions.assertEquals(-2L, (long) configPriorityProperty.getValue());
}
diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
index cdd21cdab..ec495c710 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/registry/sc/MicroserviceHandler.java
@@ -107,6 +107,9 @@ public class MicroserviceHandler {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
String hostName = StringUtils.isEmpty(scConfigurationProperties.getHostname()) ? NetUtils.getHostName()
: scConfigurationProperties.getHostname();
+ if (hostName.length() > 64) {
+ hostName = hostName.substring(0, 64);
+ }
microserviceInstance.setHostName(hostName);
if (StringUtils.isNotEmpty(dataCenterProperties.getName())) {
[servicecomb-java-chassis] 12/25: [SCB-2008]remove archaius dependency: fix tests
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 58c0369830220f84208cc93084e9d036fd4cebc2
Author: liubao <bi...@qq.com>
AuthorDate: Sat Oct 7 16:12:34 2023 +0800
[SCB-2008]remove archaius dependency: fix tests
---
.../rest/RestProducerInvocationCreatorTest.java | 8 +--
.../common/rest/TestRestEngineSchemaListener.java | 6 +-
.../common/rest/codec/TestRestCodec.java | 2 +
.../common/rest/codec/param/TestBodyProcessor.java | 6 ++
.../rest/codec/param/TestBodyProcessorCreator.java | 13 +++++
.../rest/codec/param/TestHeaderProcessor.java | 15 ++++-
.../rest/codec/query/QueryCodecMultiTest.java | 14 +++++
.../common/rest/locator/TestMicroservicePaths.java | 6 +-
.../core/executor/TestExecutorManager.java | 14 ++---
.../servicecomb/demo/CodeFirstRestTemplate.java | 4 +-
.../servicecomb/config/nacos/NacosClientTest.java | 4 ++
.../servicecomb/config/BootStrapProperties.java | 6 +-
.../config/FoundationConfigConfiguration.java | 5 ++
.../config/InMemoryDynamicPropertiesSource.java | 25 ++++-----
.../config/BootStrapPropertiesTest.java | 64 ++++++----------------
.../huaweicloud/servicestage/TestCasEnvConfig.java | 55 -------------------
.../model/MicroservicePropertiesLoader.java | 10 ++--
.../config/TestAbstractPropertiesLoader.java | 12 +++-
.../registry/lightweight/StoreServiceTest.java | 39 ++++++++++++-
.../servicecomb/registry/lightweight/TestBase.java | 59 --------------------
20 files changed, 161 insertions(+), 206 deletions(-)
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
index 6e184dfc5..88f340566 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
@@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.catchThrowable;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
import org.apache.servicecomb.common.rest.locator.OperationLocator;
import org.apache.servicecomb.common.rest.locator.ServicePathManager;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
@@ -37,6 +36,7 @@ import org.apache.servicecomb.core.definition.InvocationRuntimeType;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -83,12 +83,12 @@ public class RestProducerInvocationCreatorTest {
@BeforeAll
public static void beforeClass() {
- ArchaiusUtils.resetConfig();
- ConfigUtil.installDynamicConfig();
-
engine = SCBBootstrap.createSCBEngineForTest();
engine.setStatus(SCBStatus.UP);
Environment environment = Mockito.mock(Environment.class);
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
engine.setEnvironment(environment);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
index 4450e91dd..7efbbeee8 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
@@ -26,12 +26,12 @@ import java.util.List;
import org.apache.servicecomb.common.rest.locator.OperationLocator;
import org.apache.servicecomb.common.rest.locator.ServicePathManager;
import org.apache.servicecomb.common.rest.locator.TestPathSchema;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.jupiter.api.AfterAll;
@@ -48,7 +48,6 @@ public class TestRestEngineSchemaListener {
@BeforeAll
public static void setup() {
- ConfigUtil.installDynamicConfig();
scbEngine = SCBBootstrap.createSCBEngineForTest();
ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
TransportManager transportManager = Mockito.mock(TransportManager.class);
@@ -56,6 +55,9 @@ public class TestRestEngineSchemaListener {
scbEngine.setExecutorManager(executorManager);
Environment environment = Mockito.mock(Environment.class);
scbEngine.setEnvironment(environment);
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
List<BootListener> listeners = new ArrayList<>();
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
index dafb99949..6939974ff 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
@@ -62,6 +62,8 @@ public class TestRestCodec {
@BeforeAll
public static void beforeClass() {
LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
.thenReturn(false);
Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
index 340b7f15c..3debd1645 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
@@ -30,12 +30,14 @@ import org.apache.servicecomb.common.rest.codec.param.BodyProcessorCreator.BodyP
import org.apache.servicecomb.common.rest.codec.param.BodyProcessorCreator.RawJsonBodyProcessor;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -54,6 +56,7 @@ import jakarta.ws.rs.core.MediaType;
public class TestBodyProcessor {
+ Environment environment = Mockito.mock(Environment.class);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
@@ -112,6 +115,9 @@ public class TestBodyProcessor {
@BeforeEach
public void before() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
headers = new HeadersMultiMap();
value = "value";
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessorCreator.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessorCreator.java
index 0de4a04c4..22d7e8d39 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessorCreator.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessorCreator.java
@@ -21,9 +21,13 @@ import java.util.HashMap;
import org.apache.servicecomb.common.rest.codec.param.BodyProcessorCreator.BodyProcessor;
import org.apache.servicecomb.common.rest.codec.param.BodyProcessorCreator.RawJsonBodyProcessor;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.swagger.generator.SwaggerConst;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
@@ -32,6 +36,15 @@ import io.swagger.v3.oas.models.parameters.RequestBody;
@SuppressWarnings({"rawtypes", "unchecked"})
public class TestBodyProcessorCreator {
+ Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeEach
+ public void before() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
+ }
+
@Test
public void testCreateNormal() {
ParamValueProcessorCreator creator =
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
index 5195aa5cd..39bed2e80 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
@@ -26,16 +26,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import jakarta.servlet.http.HttpServletRequest;
-
import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.common.rest.codec.param.HeaderProcessorCreator.HeaderProcessor;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -44,6 +45,7 @@ import com.fasterxml.jackson.databind.util.StdDateFormat;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
+import jakarta.servlet.http.HttpServletRequest;
public class TestHeaderProcessor {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
@@ -71,6 +73,15 @@ public class TestHeaderProcessor {
return new HeaderProcessor(headerParameter, javaType);
}
+ Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeEach
+ void setUp() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.header.ignoreRequiredCheck"
+ , boolean.class, false)).thenReturn(false);
+ }
+
@Test
public void testGetValueNormal() throws Exception {
Mockito.when(request.getHeader("h1")).thenReturn("h1v");
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMultiTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMultiTest.java
index 759b74d69..3c56d1b1c 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMultiTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/query/QueryCodecMultiTest.java
@@ -19,13 +19,27 @@ package org.apache.servicecomb.common.rest.codec.query;
import java.util.Date;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
class QueryCodecMultiTest extends QueryCodecTestBase {
+ Environment environment = Mockito.mock(Environment.class);
+
@BeforeEach
void setUp() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.emptyAsNull", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreDefaultValue", boolean.class, false))
+ .thenReturn(false);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.query.ignoreRequiredCheck", boolean.class, false))
+ .thenReturn(false);
codec = new QueryCodecMulti();
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
index b4af7c80a..442368b0a 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
@@ -25,12 +25,12 @@ import java.util.List;
import org.apache.servicecomb.common.rest.RestEngineSchemaListener;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.transport.TransportManager;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.jupiter.api.AfterAll;
@@ -47,12 +47,14 @@ public class TestMicroservicePaths {
@BeforeAll
public static void setup() {
- ConfigUtil.installDynamicConfig();
scbEngine = SCBBootstrap.createSCBEngineForTest();
Environment environment = Mockito.mock(Environment.class);
+ LegacyPropertyFactory.setEnvironment(environment);
scbEngine.setEnvironment(environment);
Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
+ Mockito.when(environment.getProperty("servicecomb.rest.parameter.decodeAsObject", boolean.class, false))
+ .thenReturn(false);
List<BootListener> listeners = new ArrayList<>();
listeners.add(new RestEngineSchemaListener());
ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
diff --git a/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java b/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
index ea4d8662f..2fc689efb 100644
--- a/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
+++ b/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
@@ -21,7 +21,6 @@ import java.util.concurrent.Executor;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -43,12 +42,10 @@ public class TestExecutorManager {
@Before
public void setup() {
executorManager.setEnvironment(environment);
- ArchaiusUtils.resetConfig();
}
@After
public void teardown() {
- ArchaiusUtils.resetConfig();
}
@Test
@@ -70,7 +67,7 @@ public class TestExecutorManager {
String microserviceQualifiedName = "microserviceName.schemaId.opId";
String opBeanId = "opBeanId";
Mockito.when(environment.getProperty(
- ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName, String.class)).thenReturn(opBeanId);
+ ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName)).thenReturn(opBeanId);
new Expectations(BeanUtils.class) {
{
operationMeta.getMicroserviceQualifiedName();
@@ -90,7 +87,7 @@ public class TestExecutorManager {
String microserviceQualifiedName = "microserviceName.schemaId.opId";
String opBeanId = "opBeanId";
Mockito.when(environment.getProperty(
- ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName, String.class)).thenReturn(opBeanId);
+ ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName)).thenReturn(opBeanId);
new Expectations(BeanUtils.class) {
{
operationMeta.getMicroserviceQualifiedName();
@@ -115,8 +112,8 @@ public class TestExecutorManager {
String microserviceName = "serviceName";
String schemaName = "schemaId";
String opBeanId = "opBeanId";
- Mockito.when(environment.getProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceName + "." + schemaName
- , String.class)).thenReturn(opBeanId);
+ Mockito.when(environment.getProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceName + "." + schemaName))
+ .thenReturn(opBeanId);
new Expectations(BeanUtils.class) {
{
operationMeta.getSchemaId();
@@ -135,8 +132,7 @@ public class TestExecutorManager {
@Mocked SchemaMeta schemaMeta,
@Mocked OperationMeta operationMeta) {
String beanId = "beanId";
- Mockito.when(environment.getProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT
- , String.class)).thenReturn(beanId);
+ Mockito.when(environment.getProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT)).thenReturn(beanId);
new Expectations(BeanUtils.class) {
{
BeanUtils.getBean(beanId);
diff --git a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
index 25e118c01..dfdafb0d8 100644
--- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
+++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CodeFirstRestTemplate.java
@@ -21,13 +21,13 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import org.apache.servicecomb.config.InMemoryDynamicPropertiesSource;
import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.core.CoreConst;
import org.apache.servicecomb.demo.compute.Person;
import org.apache.servicecomb.demo.ignore.InputModelForTestIgnore;
import org.apache.servicecomb.demo.ignore.OutputModelForTestIgnore;
import org.apache.servicecomb.demo.server.User;
-import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
import org.springframework.beans.factory.annotation.Autowired;
@@ -50,7 +50,7 @@ public class CodeFirstRestTemplate {
}
protected void changeTransport(String microserviceName, String transport) {
- ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
+ InMemoryDynamicPropertiesSource.DYNAMIC.put("servicecomb.references.transport." + microserviceName, transport);
TestMgr.setMsg(microserviceName, transport);
}
diff --git a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java b/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
index 125d80a30..119bc73ca 100644
--- a/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
+++ b/dynamic-config/config-nacos/src/test/java/org/apache/servicecomb/config/nacos/NacosClientTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.servicecomb.config.nacos.NacosDynamicPropertiesSource.UpdateHandler;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
public class NacosClientTest {
@@ -35,6 +36,9 @@ public class NacosClientTest {
NacosDynamicPropertiesSource impl = new NacosDynamicPropertiesSource();
UpdateHandler updateHandler = impl.new UpdateHandler();
NacosClient nacosClient = new NacosClient(updateHandler);
+ NacosConfig nacosConfig = Mockito.mock(NacosConfig.class);
+ Mockito.when(nacosConfig.getContentType()).thenReturn("yaml");
+ nacosClient.setNacosConfig(nacosConfig);
NacosClient.ConfigRefresh cr = nacosClient.new ConfigRefresh();
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
index 81ed8ed00..6e9d9abcd 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
@@ -193,13 +193,15 @@ public class BootStrapProperties {
}
private static Map<String, String> readProperties(Environment environment, String newKey, String oldKey) {
- Set<String> keys = ConfigUtil.propertiesWithPrefix(environment, newKey);
+ String prefix = newKey;
+ Set<String> keys = ConfigUtil.propertiesWithPrefix(environment, prefix);
if (keys.isEmpty()) {
+ prefix = oldKey;
keys = ConfigUtil.propertiesWithPrefix(environment, oldKey);
}
Map<String, String> result = new HashMap<>(keys.size());
for (String key : keys) {
- result.put(key, environment.getProperty(key));
+ result.put(key.substring(prefix.length() + 1), environment.getProperty(key));
}
return result;
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
index 9e521b091..91f49c8a1 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
@@ -75,4 +75,9 @@ public class FoundationConfigConfiguration {
public LegacyPropertyFactory legacyPropertyFactory(Environment environment) {
return new LegacyPropertyFactory(environment);
}
+
+ @Bean
+ public InMemoryDynamicPropertiesSource inMemoryDynamicPropertiesSource() {
+ return new InMemoryDynamicPropertiesSource();
+ }
}
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
similarity index 55%
copy from service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java
copy to foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
index 23adef899..515d5ae82 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/InMemoryDynamicPropertiesSource.java
@@ -14,28 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.config;
-package org.apache.servicecomb.registry.lightweight.model;
-
+import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
-import org.apache.servicecomb.config.BootStrapProperties;
-
-public final class MicroservicePropertiesLoader extends AbstractPropertiesLoader {
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
- public static final MicroservicePropertiesLoader INSTANCE = new MicroservicePropertiesLoader();
+public class InMemoryDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
+ public static final String SOURCE_NAME = "in-memory";
- private MicroservicePropertiesLoader() {
- }
+ public static final Map<String, Object> DYNAMIC = new HashMap<>();
@Override
- protected Map<String, String> readProperties(Configuration configuration) {
- return BootStrapProperties.readServiceProperties(configuration);
+ public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
+ return new MapPropertySource(SOURCE_NAME, DYNAMIC);
}
@Override
- protected String readPropertiesExtendedClass(Configuration configuration) {
- return BootStrapProperties.readServiceExtendedClass(configuration);
+ public int getOrder() {
+ return -100;
}
}
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
index 1513ae6ad..996cbcdb8 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/BootStrapPropertiesTest.java
@@ -20,20 +20,33 @@ package org.apache.servicecomb.config;
import static org.apache.servicecomb.foundation.test.scaffolding.AssertUtils.assertPrettyJson;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.MutablePropertySources;
-class BootStrapPropertiesTest {
+public class BootStrapPropertiesTest {
private Map<String, String> readInstanceProperties(String yaml) {
Map<String, Object> properties = YAMLUtil.yaml2Properties(yaml);
ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ EnumerablePropertySource propertySource = new MapPropertySource("yaml", properties);
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+
+ List<String> keys = new ArrayList<>();
for (Entry<String, Object> entry : properties.entrySet()) {
Mockito.when(environment.getProperty(entry.getKey())).thenReturn(entry.getValue().toString());
+ keys.add(entry.getKey());
}
+
return BootStrapProperties.readServiceInstanceProperties(environment);
}
@@ -72,51 +85,6 @@ class BootStrapPropertiesTest {
+ "}");
}
- @Test
- void should_resolve_placeholder_for_instance_properties() {
- Map<String, String> properties = readInstanceProperties(""
- + "k1: new\n"
- + "servicecomb:\n"
- + " instance:\n"
- + " properties:\n"
- + " k: ${k1}");
-
- assertPrettyJson(properties).isEqualTo(""
- + "{\n"
- + " \"k\" : \"new\"\n"
- + "}");
- }
-
- @Test
- void should_resolve_boolean_to_string() {
- Map<String, String> properties = readInstanceProperties(""
- + "k: true\n"
- + "servicecomb:\n"
- + " instance:\n"
- + " properties:\n"
- + " k: ${k}");
-
- assertPrettyJson(properties).isEqualTo(""
- + "{\n"
- + " \"k\" : \"true\"\n"
- + "}");
- }
-
- @Test
- void should_resolve_number_to_string() {
- Map<String, String> properties = readInstanceProperties(""
- + "k: 1\n"
- + "servicecomb:\n"
- + " instance:\n"
- + " properties:\n"
- + " k: ${k}");
-
- assertPrettyJson(properties).isEqualTo(""
- + "{\n"
- + " \"k\" : \"1\"\n"
- + "}");
- }
-
@Test
void should_read_by_old_prefix_when_new_prefix_not_exists() {
Map<String, String> properties = readInstanceProperties(""
@@ -127,8 +95,8 @@ class BootStrapPropertiesTest {
assertPrettyJson(properties).isEqualTo(""
+ "{\n"
- + " \"k\" : \"v\",\n"
- + " \"k1\" : \"v1\"\n"
+ + " \"k1\" : \"v1\",\n"
+ + " \"k\" : \"v\"\n"
+ "}");
}
diff --git a/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java b/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
deleted file mode 100644
index 10ebf6f39..000000000
--- a/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.huaweicloud.servicestage;
-
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class TestCasEnvConfig {
-
- @BeforeAll
- public static void init() {
- System.setProperty("CAS_APPLICATION_ID", "application-id");
- System.setProperty("CAS_ENVIRONMENT_ID", "env-id");
- System.setProperty("SERVICECOMB_SERVICE_PROPS", "component:ConsumerService,other:A");
- System.setProperty("SERVICECOMB_INSTANCE_PROPS", "route:gray");
- }
-
- @Test
- public void testConfig() {
- CasEnvConfig instance = CasEnvConfig.INSTANCE;
- Assertions.assertEquals(3, instance.getNonEmptyInstanceProperties().size());
- Assertions.assertEquals("application-id", instance.getNonEmptyInstanceProperties().get("CAS_APPLICATION_ID"));
- Assertions.assertEquals("env-id", instance.getNonEmptyInstanceProperties().get("CAS_ENVIRONMENT_ID"));
- Assertions.assertEquals("gray", instance.getNonEmptyInstanceProperties().get("route"));
-
-
- Assertions.assertEquals(2, instance.getNonEmptyServiceProperties().size());
- Assertions.assertEquals("ConsumerService", instance.getNonEmptyServiceProperties().get("component"));
- Assertions.assertEquals("A", instance.getNonEmptyServiceProperties().get("other"));
- }
-
- @AfterAll
- public static void destroy() {
- System.getProperties().remove("CAS_ENVIRONMENT_ID");
- System.getProperties().remove("CAS_APPLICATION_ID");
- System.getProperties().remove("SERVICECOMB_SERVICE_PROPS");
- System.getProperties().remove("SERVICECOMB_INSTANCE_PROPS");
- }
-}
diff --git a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java
index 23adef899..ed6d181fb 100644
--- a/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/main/java/org/apache/servicecomb/registry/lightweight/model/MicroservicePropertiesLoader.java
@@ -19,8 +19,8 @@ package org.apache.servicecomb.registry.lightweight.model;
import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.BootStrapProperties;
+import org.springframework.core.env.Environment;
public final class MicroservicePropertiesLoader extends AbstractPropertiesLoader {
@@ -30,12 +30,12 @@ public final class MicroservicePropertiesLoader extends AbstractPropertiesLoader
}
@Override
- protected Map<String, String> readProperties(Configuration configuration) {
- return BootStrapProperties.readServiceProperties(configuration);
+ protected Map<String, String> readProperties(Environment environment) {
+ return BootStrapProperties.readServiceProperties(environment);
}
@Override
- protected String readPropertiesExtendedClass(Configuration configuration) {
- return BootStrapProperties.readServiceExtendedClass(configuration);
+ protected String readPropertiesExtendedClass(Environment environment) {
+ return BootStrapProperties.readServiceExtendedClass(environment);
}
}
diff --git a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
index 9f7692e87..4e3ceafdc 100644
--- a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
+++ b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/config/TestAbstractPropertiesLoader.java
@@ -23,12 +23,20 @@ import org.apache.servicecomb.registry.lightweight.model.MicroservicePropertiesL
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.springframework.core.env.Environment;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MutablePropertySources;
public class TestAbstractPropertiesLoader {
@Test
public void testExtendedClassCompatible() {
- Environment environment = Mockito.mock(Environment.class);
+ ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ EnumerablePropertySource<?> propertySource = Mockito.mock(EnumerablePropertySource.class);
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {});
+
Mockito.when(environment.getProperty(BootStrapProperties.CONFIG_SERVICE_EXTENDED_CLASS))
.thenReturn("invalidClass");
AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE;
diff --git a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
index 05a49928d..bab02249c 100644
--- a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
+++ b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
@@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CompletableFuture;
+import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.foundation.test.scaffolding.time.MockTicker;
import org.apache.servicecomb.registry.api.MicroserviceInstanceStatus;
import org.apache.servicecomb.registry.lightweight.model.Microservice;
@@ -30,12 +31,28 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MutablePropertySources;
import com.google.common.eventbus.EventBus;
import io.vertx.core.json.Json;
-class StoreServiceTest extends TestBase {
+public class StoreServiceTest {
+ static Endpoint endpoint = Mockito.mock(Endpoint.class);
+
+ static class MockRegisterRequest extends RegisterRequest {
+ @Override
+ public Endpoint selectFirstEndpoint() {
+ return endpoint;
+ }
+ }
+
+ static ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+
+ Self self;
+
EventBus eventBus = new EventBus();
MockTicker ticker = new MockTicker();
@@ -48,6 +65,26 @@ class StoreServiceTest extends TestBase {
@BeforeEach
void setUp() {
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ EnumerablePropertySource<?> propertySource = Mockito.mock(EnumerablePropertySource.class);
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {});
+ Mockito.when(environment.getProperty("servicecomb.service.application")).thenReturn("app");
+ Mockito.when(environment.getProperty("servicecomb.service.name")).thenReturn("svc");
+ Mockito.when(environment.getProperty("servicecomb.service.version")).thenReturn("1.0.0.0");
+ Mockito.when(environment.getProperty("servicecomb.instance.initialStatus")).thenReturn("UP");
+
+ self = new Self() {
+ @Override
+ protected RegisterRequest createRegisterRequest() {
+ return new MockRegisterRequest();
+ }
+ }
+ .init(environment)
+ .addSchema("schema-1", "s1")
+ .addEndpoint("rest://1.1.1.1:80");
+
Mockito.when(discoveryClient.getInfoAsync(ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(CompletableFuture.completedFuture(self.getMicroserviceInfo()));
Mockito.when(discoveryClient.getInstanceAsync(ArgumentMatchers.any(), ArgumentMatchers.any()))
diff --git a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/TestBase.java b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/TestBase.java
deleted file mode 100644
index bc96fa160..000000000
--- a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/TestBase.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.registry.lightweight;
-
-import java.util.Map;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.servicecomb.config.YAMLUtil;
-import org.apache.servicecomb.core.Endpoint;
-import org.mockito.Mockito;
-
-public class TestBase {
- static Endpoint endpoint = Mockito.mock(Endpoint.class);
-
- static class MockRegisterRequest extends RegisterRequest {
- @Override
- public Endpoint selectFirstEndpoint() {
- return endpoint;
- }
- }
-
- static AbstractConfiguration configuration = build();
-
- static AbstractConfiguration build() {
- Map<String, Object> map = YAMLUtil.yaml2Properties(""
- + "servicecomb:\n"
- + " service:\n"
- + " application: app\n"
- + " name: svc\n"
- + " version: 1.0.0.0");
- return new MapConfiguration(map);
- }
-
- Self self = new Self() {
- @Override
- protected RegisterRequest createRegisterRequest() {
- return new MockRegisterRequest();
- }
- }
- .init(configuration)
- .addSchema("schema-1", "s1")
- .addEndpoint("rest://1.1.1.1:80");
-}
[servicecomb-java-chassis] 09/25: [SCB-2008]remove archaius dependency: cc adapter
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 42d07fd84b0e383df924d41c2a0de752d68636ce
Author: liubao <bi...@qq.com>
AuthorDate: Mon Sep 25 18:22:24 2023 +0800
[SCB-2008]remove archaius dependency: cc adapter
---
.../config/{ => cc}/ConfigCenterConfig.java | 66 +++-------
.../config/{ => cc}/ConfigCenterConfiguration.java | 14 +-
.../ConfigCenterDefaultDeploymentProvider.java | 2 +-
.../ConfigCenterDynamicPropertiesSource.java} | 141 ++++++++-------------
.../ConfigCenterInformationCollector.java | 2 +-
.../config/{ => cc}/TransportUtils.java | 54 ++++----
...comb.config.spi.ConfigCenterConfigurationSource | 18 ---
...vicecomb.core.bootup.BootUpInformationCollector | 2 +-
...pache.servicecomb.deployment.DeploymentProvider | 2 +-
...rk.boot.autoconfigure.AutoConfiguration.imports | 2 +-
.../ConfigCenterAddressManagerTest.java | 3 +-
.../ConfigCenterConfigurationSourceImplTest.java | 2 +-
.../TestConfigCenterDefaultDeploymentProvider.java | 3 +-
13 files changed, 121 insertions(+), 190 deletions(-)
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
similarity index 57%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
index 837f6e0c7..0522f5b43 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfig.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfig.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config;
+package org.apache.servicecomb.config.cc;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider;
import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.foundation.vertx.VertxConst;
+import org.springframework.core.env.Environment;
import com.netflix.config.ConcurrentCompositeConfiguration;
public final class ConfigCenterConfig {
- public static final ConfigCenterConfig INSTANCE = new ConfigCenterConfig();
-
public static final String SSL_TAG = "cc.consumer";
private static ConcurrentCompositeConfiguration finalConfig;
@@ -51,76 +47,52 @@ public final class ConfigCenterConfig {
private static final int DEFAULT_FIRST_REFRESH_INTERVAL = 0;
- private ConfigCenterConfig() {
- }
-
- public static void setConcurrentCompositeConfiguration(ConcurrentCompositeConfiguration config) {
- finalConfig = config;
- }
+ private final Environment environment;
- public static ConcurrentCompositeConfiguration getConcurrentCompositeConfiguration() {
- return finalConfig;
+ public ConfigCenterConfig(Environment environment) {
+ this.environment = environment;
}
-
public String getDomainName() {
- return finalConfig.getString(DOMAIN_NAME, "default");
+ return environment.getProperty(DOMAIN_NAME, "default");
}
public boolean firstPullRequired() {
- return finalConfig.getBoolean(FIRST_PULL_REQUIRED, false);
+ return environment.getProperty(FIRST_PULL_REQUIRED, boolean.class, false);
}
@SuppressWarnings("unchecked")
public List<String> getFileSources() {
- Object property = finalConfig.getProperty(FILE_SOURCE);
- if (property instanceof String) {
- return new ArrayList<>(Arrays.asList(((String) property).split(",")));
- }
- if (property instanceof List) {
- return (List<String>) property;
- }
- return Collections.EMPTY_LIST;
+ return environment.getProperty(FILE_SOURCE, List.class, Collections.emptyList());
}
public long getRefreshInterval() {
- return finalConfig.getLong(REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL);
+ return environment.getProperty(
+ REFRESH_INTERVAL, long.class, (long) DEFAULT_REFRESH_INTERVAL);
}
public int getFirstRefreshInterval() {
- return finalConfig.getInt(FIRST_REFRESH_INTERVAL, DEFAULT_FIRST_REFRESH_INTERVAL);
+ return environment.getProperty(FIRST_REFRESH_INTERVAL, int.class, DEFAULT_FIRST_REFRESH_INTERVAL);
}
public Boolean isProxyEnable() {
- return finalConfig.getBoolean(VertxConst.PROXY_ENABLE, false);
+ return environment.getProperty(VertxConst.PROXY_ENABLE, boolean.class, false);
}
public String getProxyHost() {
- return finalConfig.getString(VertxConst.PROXY_HOST, "127.0.0.1");
+ return environment.getProperty(VertxConst.PROXY_HOST, "127.0.0.1");
}
public int getProxyPort() {
- return finalConfig.getInt(VertxConst.PROXY_PORT, 8080);
+ return environment.getProperty(VertxConst.PROXY_PORT, int.class, 8080);
}
public String getProxyUsername() {
- return finalConfig.getString(VertxConst.PROXY_USERNAME, null);
+ return environment.getProperty(VertxConst.PROXY_USERNAME);
}
public String getProxyPasswd() {
- return finalConfig.getString(VertxConst.PROXY_PASSWD, null);
- }
-
- public String getServiceName() {
- return BootStrapProperties.readServiceName(finalConfig);
- }
-
- public String getAppName() {
- return BootStrapProperties.readApplication(finalConfig);
- }
-
- public String getServiceVersion() {
- return BootStrapProperties.readServiceVersion(finalConfig);
+ return environment.getProperty(VertxConst.PROXY_PASSWD);
}
public List<String> getServerUri() {
@@ -129,10 +101,6 @@ public final class ConfigCenterConfig {
}
public boolean getAutoDiscoveryEnabled() {
- return finalConfig.getBoolean(AUTO_DISCOVERY_ENABLED, false);
- }
-
- public String getEnvironment() {
- return BootStrapProperties.readServiceEnvironment(finalConfig);
+ return environment.getProperty(AUTO_DISCOVERY_ENABLED, boolean.class, false);
}
}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java
similarity index 73%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java
index bb95c43a2..97578fb2d 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfiguration.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterConfiguration.java
@@ -14,14 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.config;
+package org.apache.servicecomb.config.cc;
-import org.apache.servicecomb.config.collect.ConfigCenterInformationCollector;
import org.springframework.context.annotation.Bean;
+import org.springframework.core.env.Environment;
public class ConfigCenterConfiguration {
@Bean
public ConfigCenterInformationCollector configCenterInformationCollector() {
return new ConfigCenterInformationCollector();
}
+
+ @Bean
+ public ConfigCenterDynamicPropertiesSource configCenterDynamicPropertiesSource() {
+ return new ConfigCenterDynamicPropertiesSource();
+ }
+
+ @Bean
+ public ConfigCenterConfig configCenterConfig(Environment environment) {
+ return new ConfigCenterConfig(environment);
+ }
}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java
similarity index 97%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java
index 34cfa7332..e6e836c47 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterDefaultDeploymentProvider.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDefaultDeploymentProvider.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.collect;
+package org.apache.servicecomb.config.cc;
import java.util.List;
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
similarity index 59%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
index 74834aaef..089741159 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImpl.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterDynamicPropertiesSource.java
@@ -14,16 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.config.cc;
-package org.apache.servicecomb.config;
-
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
-import org.apache.commons.configuration.Configuration;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -31,19 +27,19 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.servicecomb.config.DynamicPropertiesSource;
+import org.apache.servicecomb.config.MicroserviceProperties;
import org.apache.servicecomb.config.center.client.ConfigCenterAddressManager;
import org.apache.servicecomb.config.center.client.ConfigCenterClient;
-import org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration;
import org.apache.servicecomb.config.center.client.ConfigCenterManager;
+import org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration;
import org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest;
import org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse;
-import org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider;
import org.apache.servicecomb.config.common.ConfigConverter;
import org.apache.servicecomb.config.common.ConfigurationChangedEvent;
-import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.apache.servicecomb.deployment.Deployment;
-import org.apache.servicecomb.deployment.SystemBootstrapInfo;
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.http.client.auth.RequestAuthHeaderProvider;
@@ -51,52 +47,50 @@ import org.apache.servicecomb.http.client.common.HttpTransport;
import org.apache.servicecomb.http.client.common.HttpTransportFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
import com.google.common.eventbus.Subscribe;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.WatchedUpdateListener;
-import com.netflix.config.WatchedUpdateResult;
-public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigurationSource {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfigurationSourceImpl.class);
+public class ConfigCenterDynamicPropertiesSource implements DynamicPropertiesSource<Map<String, Object>> {
+ public static final String SOURCE_NAME = "config-center";
- private final List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<>();
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterDynamicPropertiesSource.class);
+
+ private final Map<String, Object> data = new ConcurrentHashMapEx<>();
private ConfigCenterManager configCenterManager;
private ConfigConverter configConverter;
- @Override
- public int getOrder() {
- return ORDER_BASE * 2;
+ private ConfigCenterConfig configCenterConfig;
+
+ private MicroserviceProperties microserviceProperties;
+
+ @Autowired
+ public void setConfigCenterConfig(ConfigCenterConfig configCenterConfig) {
+ this.configCenterConfig = configCenterConfig;
}
- @Override
- public boolean isValidSource(Configuration localConfiguration) {
- ConfigCenterConfig.setConcurrentCompositeConfiguration((ConcurrentCompositeConfiguration) localConfiguration);
- SystemBootstrapInfo address = Deployment
- .getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER);
-
- if (address == null) {
- LOGGER.info("config center server is not configured.");
- return false;
- }
- return true;
+ @Autowired
+ public void setMicroserviceProperties(MicroserviceProperties microserviceProperties) {
+ this.microserviceProperties = microserviceProperties;
}
- @Override
- public void init(Configuration localConfiguration) {
- configConverter = new ConfigConverter(ConfigCenterConfig.INSTANCE.getFileSources());
+ private void init(Environment environment) {
+ configConverter = new ConfigConverter(configCenterConfig.getFileSources());
ConfigCenterAddressManager kieAddressManager = configKieAddressManager();
HttpTransport httpTransport = createHttpTransport(kieAddressManager,
HttpTransportFactory.defaultRequestConfig().build(),
- localConfiguration);
+ environment);
ConfigCenterClient configCenterClient = new ConfigCenterClient(kieAddressManager, httpTransport);
EventManager.register(this);
- ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration();
+ org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration();
QueryConfigurationsRequest queryConfigurationsRequest = firstPull(configCenterClient);
@@ -104,6 +98,7 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur
configConverter, configCenterConfiguration);
configCenterManager.setQueryConfigurationsRequest(queryConfigurationsRequest);
configCenterManager.startConfigCenterManager();
+ data.putAll(configConverter.getCurrentData());
}
private QueryConfigurationsRequest firstPull(ConfigCenterClient configCenterClient) {
@@ -113,11 +108,10 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur
.queryConfigurations(queryConfigurationsRequest);
if (response.isChanged()) {
configConverter.updateData(response.getConfigurations());
- updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null));
queryConfigurationsRequest.setRevision(response.getRevision());
}
} catch (Exception e) {
- if (ConfigCenterConfig.INSTANCE.firstPullRequired()) {
+ if (configCenterConfig.firstPullRequired()) {
throw e;
}
LOGGER.warn("first pull failed, and ignore {}", e.getMessage());
@@ -127,52 +121,54 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur
@Subscribe
public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
- updateConfiguration(
- WatchedUpdateResult.createIncremental(event.getAdded(), event.getUpdated(), event.getDeleted()));
+ data.putAll(event.getAdded());
+ data.putAll(event.getUpdated());
+ event.getDeleted().forEach((k, v) -> data.remove(k));
}
private QueryConfigurationsRequest createQueryConfigurationsRequest() {
QueryConfigurationsRequest request = new QueryConfigurationsRequest();
- request.setApplication(ConfigCenterConfig.INSTANCE.getAppName());
- request.setServiceName(ConfigCenterConfig.INSTANCE.getServiceName());
- request.setVersion(ConfigCenterConfig.INSTANCE.getServiceVersion());
- request.setEnvironment(ConfigCenterConfig.INSTANCE.getEnvironment());
+ request.setApplication(microserviceProperties.getApplication());
+ request.setServiceName(microserviceProperties.getName());
+ request.setVersion(microserviceProperties.getVersion());
+ request.setEnvironment(microserviceProperties.getEnvironment());
// 需要设置为 null, 并且 query 参数为 revision=null 才会返回 revision 信息。 revision = 是不行的。
request.setRevision(null);
return request;
}
- private ConfigCenterConfiguration createConfigCenterConfiguration(){
- return new ConfigCenterConfiguration().setRefreshIntervalInMillis(ConfigCenterConfig.INSTANCE.getRefreshInterval());
+ private org.apache.servicecomb.config.center.client.model.ConfigCenterConfiguration createConfigCenterConfiguration() {
+ return new ConfigCenterConfiguration().setRefreshIntervalInMillis(configCenterConfig.getRefreshInterval());
}
- private HttpTransport createHttpTransport(ConfigCenterAddressManager kieAddressManager, RequestConfig requestConfig,
- Configuration localConfiguration) {
+ private HttpTransport createHttpTransport(ConfigCenterAddressManager kieAddressManager,
+ RequestConfig requestConfig,
+ Environment environment) {
List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class);
- if (ConfigCenterConfig.INSTANCE.isProxyEnable()) {
+ if (configCenterConfig.isProxyEnable()) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().
setDefaultRequestConfig(requestConfig);
- HttpHost proxy = new HttpHost(ConfigCenterConfig.INSTANCE.getProxyHost(),
- ConfigCenterConfig.INSTANCE.getProxyPort(), "http"); // now only support http proxy
+ HttpHost proxy = new HttpHost(configCenterConfig.getProxyHost(),
+ configCenterConfig.getProxyPort(), "http"); // now only support http proxy
httpClientBuilder.setProxy(proxy);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxy),
- new UsernamePasswordCredentials(ConfigCenterConfig.INSTANCE.getProxyUsername(),
- ConfigCenterConfig.INSTANCE.getProxyPasswd()));
+ new UsernamePasswordCredentials(configCenterConfig.getProxyUsername(),
+ configCenterConfig.getProxyPasswd()));
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, ConfigCenterConfig.SSL_TAG),
+ .createSSLProperties(kieAddressManager.sslEnabled(), environment, ConfigCenterConfig.SSL_TAG),
getRequestAuthHeaderProvider(authHeaderProviders), httpClientBuilder);
}
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(kieAddressManager.sslEnabled(), localConfiguration, ConfigCenterConfig.SSL_TAG),
+ .createSSLProperties(kieAddressManager.sslEnabled(), environment, ConfigCenterConfig.SSL_TAG),
getRequestAuthHeaderProvider(authHeaderProviders), requestConfig);
}
@@ -185,47 +181,20 @@ public class ConfigCenterConfigurationSourceImpl implements ConfigCenterConfigur
}
private ConfigCenterAddressManager configKieAddressManager() {
- return new ConfigCenterAddressManager(ConfigCenterConfig.INSTANCE.getDomainName(),
+ return new ConfigCenterAddressManager(configCenterConfig.getDomainName(),
Deployment
.getSystemBootStrapInfo(ConfigCenterDefaultDeploymentProvider.SYSTEM_KEY_CONFIG_CENTER).getAccessURL(),
EventManager.getEventBus());
}
- private void updateConfiguration(WatchedUpdateResult result) {
- LOGGER.info("configuration changed keys, added=[{}], updated=[{}], deleted=[{}]",
- result.getAdded() == null ? "" : result.getAdded().keySet(),
- result.getChanged() == null ? "" : result.getChanged().keySet(),
- result.getDeleted() == null ? "" : result.getDeleted().keySet());
- for (WatchedUpdateListener l : listeners) {
- try {
- l.updateConfiguration(result);
- } catch (Throwable ex) {
- LOGGER.error("Error in invoking WatchedUpdateListener", ex);
- }
- }
- }
-
@Override
- public void destroy() {
- if (configCenterManager == null) {
- return;
- }
- configCenterManager.stop();
+ public EnumerablePropertySource<Map<String, Object>> create(Environment environment) {
+ init(environment);
+ return new MapPropertySource(SOURCE_NAME, data);
}
@Override
- public void addUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.add(watchedUpdateListener);
- }
-
- @Override
- public void removeUpdateListener(WatchedUpdateListener watchedUpdateListener) {
- listeners.remove(watchedUpdateListener);
- }
-
- @Override
- public Map<String, Object> getCurrentData() throws Exception {
- // data will updated by first pull, set empty to DynamicWatchedConfiguration first.
- return Collections.emptyMap();
+ public int getOrder() {
+ return 200;
}
}
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
similarity index 96%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
index 89568debc..76cc6fa19 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/collect/ConfigCenterInformationCollector.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/ConfigCenterInformationCollector.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.collect;
+package org.apache.servicecomb.config.cc;
import org.apache.servicecomb.core.bootup.BootUpInformationCollector;
import org.apache.servicecomb.deployment.Deployment;
diff --git a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java
similarity index 66%
rename from dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java
rename to dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java
index 21a510ac4..6a91ea6a2 100644
--- a/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/TransportUtils.java
+++ b/dynamic-config/config-cc/src/main/java/org/apache/servicecomb/config/cc/TransportUtils.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config;
+package org.apache.servicecomb.config.cc;
import static org.apache.servicecomb.foundation.ssl.SSLOption.DEFAULT_OPTION;
-import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.foundation.ssl.SSLCustom;
import org.apache.servicecomb.foundation.ssl.SSLOption;
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
+import org.springframework.core.env.Environment;
public class TransportUtils {
- public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) {
+ public static SSLProperties createSSLProperties(boolean sslEnabled, Environment environment, String tag) {
SSLProperties sslProperties = new SSLProperties();
sslProperties.setEnabled(sslEnabled);
@@ -34,93 +34,93 @@ public class TransportUtils {
}
SSLOption option = new SSLOption();
- option.setEngine(getStringProperty(configuration,
+ option.setEngine(getStringProperty(environment,
DEFAULT_OPTION.getEngine(),
"ssl." + tag + ".engine",
"ssl.engine"));
option.setProtocols(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getProtocols(),
"ssl." + tag + ".protocols",
"ssl.protocols"));
option.setCiphers(
- getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
+ getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
option.setAuthPeer(
- getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
+ getBooleanProperty(environment, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
option.setCheckCNHost(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNHost(),
"ssl." + tag + ".checkCN.host",
"ssl.checkCN.host"));
option.setCheckCNWhite(
- getBooleanProperty(configuration,
+ getBooleanProperty(environment,
DEFAULT_OPTION.isCheckCNWhite(),
"ssl." + tag + ".checkCN.white",
"ssl.checkCN.white"));
- option.setCheckCNWhiteFile(getStringProperty(configuration,
+ option.setCheckCNWhiteFile(getStringProperty(environment,
DEFAULT_OPTION.getCiphers(),
"ssl." + tag + ".checkCN.white.file",
"ssl.checkCN.white.file"));
- option.setAllowRenegociate(getBooleanProperty(configuration,
+ option.setAllowRenegociate(getBooleanProperty(environment,
DEFAULT_OPTION.isAllowRenegociate(),
"ssl." + tag + ".allowRenegociate",
"ssl.allowRenegociate"));
option.setStorePath(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getStorePath(),
"ssl." + tag + ".storePath",
"ssl.storePath"));
option.setClientAuth(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getClientAuth(),
"ssl." + tag + ".clientAuth",
"ssl.clientAuth"));
option.setTrustStore(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getTrustStore(),
"ssl." + tag + ".trustStore",
"ssl.trustStore"));
- option.setTrustStoreType(getStringProperty(configuration,
+ option.setTrustStoreType(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreType(),
"ssl." + tag + ".trustStoreType",
"ssl.trustStoreType"));
- option.setTrustStoreValue(getStringProperty(configuration,
+ option.setTrustStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getTrustStoreValue(),
"ssl." + tag + ".trustStoreValue",
"ssl.trustStoreValue"));
option.setKeyStore(
- getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
+ getStringProperty(environment, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
option.setKeyStoreType(
- getStringProperty(configuration,
+ getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreType(),
"ssl." + tag + ".keyStoreType",
"ssl.keyStoreType"));
- option.setKeyStoreValue(getStringProperty(configuration,
+ option.setKeyStoreValue(getStringProperty(environment,
DEFAULT_OPTION.getKeyStoreValue(),
"ssl." + tag + ".keyStoreValue",
"ssl.keyStoreValue"));
- option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
+ option.setCrl(getStringProperty(environment, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
option.setSslCustomClass(
- getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
+ getStringProperty(environment, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
sslProperties.setSslOption(option);
sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
return sslProperties;
}
- private static String getStringProperty(Configuration configuration, String defaultValue, String... keys) {
+ private static String getStringProperty(Environment environment, String defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getString(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key);
}
}
return defaultValue;
}
- private static boolean getBooleanProperty(Configuration configuration, boolean defaultValue, String... keys) {
+ private static boolean getBooleanProperty(Environment environment, boolean defaultValue, String... keys) {
for (String key : keys) {
- if (configuration.containsKey(key)) {
- return configuration.getBoolean(key);
+ if (environment.getProperty(key) != null) {
+ return environment.getProperty(key, boolean.class, false);
}
}
return defaultValue;
diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
deleted file mode 100644
index d38ec076a..000000000
--- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.servicecomb.config.ConfigCenterConfigurationSourceImpl
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector
index 58062576e..f49c5aacf 100644
--- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector
+++ b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.core.bootup.BootUpInformationCollector
@@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-org.apache.servicecomb.config.collect.ConfigCenterInformationCollector
\ No newline at end of file
+org.apache.servicecomb.config.cc.ConfigCenterInformationCollector
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
index 39efa46f7..bd9118aff 100644
--- a/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
+++ b/dynamic-config/config-cc/src/main/resources/META-INF/services/org.apache.servicecomb.deployment.DeploymentProvider
@@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-org.apache.servicecomb.config.collect.ConfigCenterDefaultDeploymentProvider
\ No newline at end of file
+org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider
\ No newline at end of file
diff --git a/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index d917e1e79..febb89438 100644
--- a/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ b/dynamic-config/config-cc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -15,4 +15,4 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-org.apache.servicecomb.config.ConfigCenterConfiguration
+org.apache.servicecomb.config.cc.ConfigCenterConfiguration
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java
similarity index 96%
rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java
rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java
index f47cc35be..1642d11ff 100644
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/center/client/ConfigCenterAddressManagerTest.java
+++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterAddressManagerTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.center.client;
+package org.apache.servicecomb.config.cc;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.servicecomb.config.center.client.ConfigCenterAddressManager;
import org.apache.servicecomb.http.client.event.RefreshEndpointEvent;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java
similarity index 98%
rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java
rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java
index 4a9b64a88..f9424c9a2 100644
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/ConfigCenterConfigurationSourceImplTest.java
+++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/ConfigCenterConfigurationSourceImplTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config;
+package org.apache.servicecomb.config.cc;
import java.lang.reflect.Field;
diff --git a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
similarity index 96%
rename from dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
rename to dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
index 540ac2c52..be3c4b207 100644
--- a/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/collect/TestConfigCenterDefaultDeploymentProvider.java
+++ b/dynamic-config/config-cc/src/test/java/org/apache/servicecomb/config/cc/TestConfigCenterDefaultDeploymentProvider.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.servicecomb.config.collect;
+package org.apache.servicecomb.config.cc;
import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.cc.ConfigCenterDefaultDeploymentProvider;
import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.deployment.SystemBootstrapInfo;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
[servicecomb-java-chassis] 05/25: [SCB-2008]change DynamicPropertyFactory to Environment: in public key
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit afddef34770073169acd77ad57bba7019ac8292f
Author: liubao <bi...@qq.com>
AuthorDate: Sun Sep 24 17:36:38 2023 +0800
[SCB-2008]change DynamicPropertyFactory to Environment: in public key
---
.../org/apache/servicecomb/config/ConfigUtil.java | 19 +++
.../AuthenticationConfiguration.java | 7 +
.../authentication/provider/AccessController.java | 59 ++++---
.../provider/ProviderTokenManager.java | 7 +-
.../authentication/TestAccessController.java | 184 ++++++++++++++++-----
.../provider/TestProviderTokenManager.java | 14 ++
6 files changed, 228 insertions(+), 62 deletions(-)
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
index 3c52615a7..c9c3908fd 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java
@@ -20,11 +20,13 @@ package org.apache.servicecomb.config;
import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_KEY_SPLITER;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
@@ -49,6 +51,9 @@ import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.PropertySource;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConcurrentMapConfiguration;
@@ -283,4 +288,18 @@ public final class ConfigUtil {
throw new IllegalStateException(e);
}
}
+
+ public static Set<String> propertiesWithPrefix(ConfigurableEnvironment environment, String prefix) {
+ Set<String> result = new HashSet<>();
+ for (PropertySource<?> propertySource : environment.getPropertySources()) {
+ if (propertySource instanceof EnumerablePropertySource) {
+ for (String key : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
+ if (key.startsWith(prefix)) {
+ result.add(key);
+ }
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/AuthenticationConfiguration.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/AuthenticationConfiguration.java
index 0029e0239..172a640a8 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/AuthenticationConfiguration.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/AuthenticationConfiguration.java
@@ -18,11 +18,13 @@ package org.apache.servicecomb.authentication;
import org.apache.servicecomb.authentication.consumer.ConsumerAuthFilter;
import org.apache.servicecomb.authentication.consumer.ConsumerTokenManager;
+import org.apache.servicecomb.authentication.provider.AccessController;
import org.apache.servicecomb.authentication.provider.ProviderAuthFilter;
import org.apache.servicecomb.authentication.provider.ProviderTokenManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
@Configuration
@ConditionalOnProperty(value = AuthenticationConfiguration.ACCESS_CONTROL_ENABLED,
@@ -56,4 +58,9 @@ public class AuthenticationConfiguration {
public ProviderTokenManager providerTokenManager() {
return new ProviderTokenManager();
}
+
+ @Bean
+ public AccessController accessController(Environment environment) {
+ return new AccessController(environment);
+ }
}
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
index 4315ba0db..07edae566 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/AccessController.java
@@ -17,17 +17,21 @@
package org.apache.servicecomb.authentication.provider;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
+import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.Environment;
-import com.netflix.config.ConcurrentCompositeConfiguration;
-import com.netflix.config.DynamicPropertyFactory;
+import com.google.common.eventbus.Subscribe;
/**
* Add black / white list control to service access
@@ -55,13 +59,17 @@ public class AccessController {
private static final String KEY_RULE_POSTFIX = ".rule";
+ private final Environment environment;
+
private Map<String, ConfigurationItem> whiteList = new HashMap<>();
private Map<String, ConfigurationItem> blackList = new HashMap<>();
- public AccessController() {
+ public AccessController(Environment environment) {
+ this.environment = environment;
loadConfigurations(KEY_BLACK_LIST_PREFIX);
loadConfigurations(KEY_WHITE_LIST_PREFIX);
+ EventManager.register(this);
}
public boolean isAllowed(DiscoveryInstance microservice) {
@@ -128,40 +136,45 @@ public class AccessController {
return value.equals(pattern);
}
- private void loadConfigurations(String prefix) {
- ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory
- .getBackingConfigurationSource();
- loadConfigurations(config, prefix);
- config.addConfigurationListener(event -> {
- if (event.getPropertyName().startsWith(prefix)) {
- LOG.info("Access rule have been changed. Reload configurations. Event=" + event.getType());
- loadConfigurations(config, prefix);
+ @Subscribe
+ public void onConfigurationChangedEvent(ConfigurationChangedEvent event) {
+ Map<String, Object> changed = new HashMap<>();
+ changed.putAll(event.getDeleted());
+ changed.putAll(event.getAdded());
+ changed.putAll(event.getUpdated());
+
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(KEY_WHITE_LIST_PREFIX)) {
+ loadConfigurations(KEY_WHITE_LIST_PREFIX);
+ break;
+ }
+ }
+ for (Entry<String, Object> entry : changed.entrySet()) {
+ if (entry.getKey().startsWith(KEY_BLACK_LIST_PREFIX)) {
+ loadConfigurations(KEY_BLACK_LIST_PREFIX);
+ break;
}
- });
+ }
}
- private void loadConfigurations(ConcurrentCompositeConfiguration config, String prefix) {
+ private void loadConfigurations(String prefix) {
Map<String, ConfigurationItem> configurations = new HashMap<>();
- Iterator<String> configsItems = config.getKeys(prefix);
- while (configsItems.hasNext()) {
- String pathKey = configsItems.next();
+ Set<String> configsItems = ConfigUtil.propertiesWithPrefix((ConfigurableEnvironment) environment, prefix);
+ for (String pathKey : configsItems) {
if (pathKey.endsWith(KEY_RULE_POSTFIX)) {
ConfigurationItem configurationItem = new ConfigurationItem();
- String rule = DynamicPropertyFactory.getInstance()
- .getStringProperty(pathKey, null).get();
+ String rule = environment.getProperty(pathKey);
if (StringUtils.isEmpty(rule)) {
continue;
}
configurationItem.rule = rule;
String pathKeyItem = pathKey
.substring(prefix.length() + 1, pathKey.length() - KEY_RULE_POSTFIX.length());
- configurationItem.propertyName = DynamicPropertyFactory.getInstance()
- .getStringProperty(String.format(KEY_PROPERTY_NAME, prefix, pathKeyItem), null).get();
+ configurationItem.propertyName = environment.getProperty(String.format(KEY_PROPERTY_NAME, prefix, pathKeyItem));
if (StringUtils.isEmpty(configurationItem.propertyName)) {
continue;
}
- configurationItem.category = DynamicPropertyFactory.getInstance()
- .getStringProperty(String.format(KEY_CATEGORY, prefix, pathKeyItem), null).get();
+ configurationItem.category = environment.getProperty(String.format(KEY_CATEGORY, prefix, pathKeyItem));
if (StringUtils.isEmpty(configurationItem.category)) {
continue;
}
diff --git a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderTokenManager.java b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderTokenManager.java
index 0fb40ebad..ebedacb7b 100644
--- a/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderTokenManager.java
+++ b/handlers/handler-publickey-auth/src/main/java/org/apache/servicecomb/authentication/provider/ProviderTokenManager.java
@@ -43,7 +43,7 @@ public class ProviderTokenManager {
.expireAfterAccess(getExpiredTime(), TimeUnit.MILLISECONDS)
.build();
- private final AccessController accessController = new AccessController();
+ private AccessController accessController;
private MicroserviceInstanceCache microserviceInstanceCache;
@@ -52,6 +52,11 @@ public class ProviderTokenManager {
this.microserviceInstanceCache = microserviceInstanceCache;
}
+ @Autowired
+ public void setAccessController(AccessController accessController) {
+ this.accessController = accessController;
+ }
+
public boolean valid(String token) {
try {
RSAAuthenticationToken rsaToken = RSAAuthenticationToken.fromStr(token);
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
index cb2124ae1..ad4b47326 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAccessController.java
@@ -20,25 +20,46 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.authentication.provider.AccessController;
+import org.apache.servicecomb.config.ConfigurationChangedEvent;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.EnumerablePropertySource;
+import org.springframework.core.env.MutablePropertySources;
public class TestAccessController {
- @AfterEach
+ ConfigurableEnvironment environment;
+
+ EnumerablePropertySource<?> propertySource;
+
+ @BeforeEach
public void tearDown() {
- ArchaiusUtils.resetConfig();
+ environment = Mockito.mock(ConfigurableEnvironment.class);
+ propertySource = Mockito.mock(EnumerablePropertySource.class);
}
@Test
public void testIsValidOfWhiteByServiceName() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.white.list1.propertyName",
+ "servicecomb.publicKey.accessControl.white.list1.category",
+ "servicecomb.publicKey.accessControl.white.list1.rule"
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.propertyName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("trust*");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trustCustomer");
Assertions.assertTrue(controller.isAllowed(service));
@@ -47,7 +68,11 @@ public class TestAccessController {
Mockito.when(service.getServiceName()).thenReturn("nottrustCustomer");
Assertions.assertFalse(controller.isAllowed(service));
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "*trust");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("*trust");
+ Map<String, Object> latest = new HashMap<>();
+ latest.put("servicecomb.publicKey.accessControl.white.list1.rule", "*trust");
+ controller.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("Customer_trust");
Assertions.assertTrue(controller.isAllowed(service));
@@ -56,7 +81,11 @@ public class TestAccessController {
Mockito.when(service.getServiceName()).thenReturn("Customer_trust_not");
Assertions.assertFalse(controller.isAllowed(service));
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("trust");
+ latest.put("servicecomb.publicKey.accessControl.white.list1.rule", "trust");
+ controller.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
+
service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trust");
Assertions.assertTrue(controller.isAllowed(service));
@@ -68,10 +97,22 @@ public class TestAccessController {
@Test
public void testIsValidOfBlackByServiceName() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust*");
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.black.list1.propertyName",
+ "servicecomb.publicKey.accessControl.black.list1.category",
+ "servicecomb.publicKey.accessControl.black.list1.rule"
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.propertyName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("trust*");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trustCustomer");
@@ -81,7 +122,11 @@ public class TestAccessController {
Mockito.when(service.getServiceName()).thenReturn("nottrustCustomer");
Assertions.assertTrue(controller.isAllowed(service));
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*trust");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("*trust");
+ Map<String, Object> latest = new HashMap<>();
+ latest.put("servicecomb.publicKey.accessControl.black.list1.rule", "*trust");
+ controller.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("Customer_trust");
Assertions.assertFalse(controller.isAllowed(service));
@@ -91,6 +136,11 @@ public class TestAccessController {
Assertions.assertTrue(controller.isAllowed(service));
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("trust");
+ latest = new HashMap<>();
+ latest.put("servicecomb.publicKey.accessControl.black.list1.rule", "trust");
+ controller.onConfigurationChangedEvent(ConfigurationChangedEvent.createIncremental(latest, new HashMap<>()));
service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trust");
Assertions.assertFalse(controller.isAllowed(service));
@@ -102,14 +152,31 @@ public class TestAccessController {
@Test
public void testIsValidOfBlackAndWhiteByServiceName() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*hacker");
-
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.black.list1.propertyName",
+ "servicecomb.publicKey.accessControl.black.list1.category",
+ "servicecomb.publicKey.accessControl.black.list1.rule",
+ "servicecomb.publicKey.accessControl.white.list1.propertyName",
+ "servicecomb.publicKey.accessControl.white.list1.category",
+ "servicecomb.publicKey.accessControl.white.list1.rule"
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.propertyName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("trust*");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.propertyName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("*hacker");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trustCustomer");
Assertions.assertTrue(controller.isAllowed(service));
@@ -121,10 +188,22 @@ public class TestAccessController {
@Test
public void testIsValidOfBlackByProperties() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "tag");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "test");
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.black.list1.propertyName",
+ "servicecomb.publicKey.accessControl.black.list1.category",
+ "servicecomb.publicKey.accessControl.black.list1.rule",
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.propertyName"))
+ .thenReturn("tag");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("test");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Map<String, String> map = new HashMap<>();
map.put("tag", "test");
@@ -139,10 +218,22 @@ public class TestAccessController {
@Test
public void testIsValidOfWhiteByProperties() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "tag");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "test");
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.white.list1.propertyName",
+ "servicecomb.publicKey.accessControl.white.list1.category",
+ "servicecomb.publicKey.accessControl.white.list1.rule",
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.propertyName"))
+ .thenReturn("tag");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("test");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Map<String, String> map = new HashMap<>();
map.put("tag", "test");
@@ -156,14 +247,31 @@ public class TestAccessController {
@Test
public void testIsValidOfBlackAndWhiteByServiceNameAndVersion() {
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "version");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
- ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "0.0.1");
-
- AccessController controller = new AccessController();
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ mutablePropertySources.addLast(propertySource);
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ Mockito.when(propertySource.getPropertyNames()).thenReturn(new String[] {
+ "servicecomb.publicKey.accessControl.black.list1.propertyName",
+ "servicecomb.publicKey.accessControl.black.list1.category",
+ "servicecomb.publicKey.accessControl.black.list1.rule",
+ "servicecomb.publicKey.accessControl.white.list1.propertyName",
+ "servicecomb.publicKey.accessControl.white.list1.category",
+ "servicecomb.publicKey.accessControl.white.list1.rule"
+ });
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.propertyName"))
+ .thenReturn("serviceName");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.white.list1.rule"))
+ .thenReturn("trust*");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.propertyName"))
+ .thenReturn("version");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.category"))
+ .thenReturn("property");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.black.list1.rule"))
+ .thenReturn("0.0.1");
+
+ AccessController controller = new AccessController(environment);
DiscoveryInstance service = Mockito.mock(DiscoveryInstance.class);
Mockito.when(service.getServiceName()).thenReturn("trustCustomer");
Mockito.when(service.getVersion()).thenReturn("0.0.1");
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
index f50023ac9..4e584c7ca 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
@@ -17,6 +17,7 @@
package org.apache.servicecomb.authentication.provider;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.endsWith;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +39,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MutablePropertySources;
import com.google.common.cache.Cache;
@@ -80,6 +84,10 @@ public class TestProviderTokenManager {
return 500;
}
});
+ ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ tokenManager.setAccessController(new AccessController(environment));
MicroserviceInstanceCache microserviceInstanceCache = Mockito.mock(MicroserviceInstanceCache.class);
DiscoveryInstance microserviceInstance = Mockito.mock(DiscoveryInstance.class);
Mockito.when(microserviceInstance.getInstanceId()).thenReturn("");
@@ -113,6 +121,7 @@ public class TestProviderTokenManager {
String serviceId = "test";
String instanceId = "test";
ConsumerTokenManager consumerTokenManager = new ConsumerTokenManager();
+
MicroserviceProperties microserviceProperties = Mockito.mock(MicroserviceProperties.class);
Mockito.when(microserviceProperties.getName()).thenReturn("test");
Mockito.when(microserviceProperties.getApplication()).thenReturn("test");
@@ -130,6 +139,11 @@ public class TestProviderTokenManager {
// use cache token
Assertions.assertEquals(token, consumerTokenManager.getToken());
ProviderTokenManager rsaProviderTokenManager = new ProviderTokenManager();
+ ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
+ MutablePropertySources mutablePropertySources = new MutablePropertySources();
+ Mockito.when(environment.getPropertySources()).thenReturn(mutablePropertySources);
+ rsaProviderTokenManager.setAccessController(new AccessController(environment));
+
rsaProviderTokenManager.setMicroserviceInstanceCache(microserviceInstanceCache);
//first validate need to verify use RSA
Assertions.assertTrue(rsaProviderTokenManager.valid(token));
[servicecomb-java-chassis] 01/25: [SCB-2008]change DynamicPropertyFactory to Environment: in huawei cloud
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 7395e9221449005362c31a80c5f53c225d90dcf4
Author: liubao <bi...@qq.com>
AuthorDate: Thu Sep 21 14:18:30 2023 +0800
[SCB-2008]change DynamicPropertyFactory to Environment: in huawei cloud
---
.../darklaunch/DarklaunchServerListFilter.java | 10 +-
.../dashboard/monitor/DashboardConfiguration.java | 7 ++
.../huaweicloud/dashboard/monitor/DataFactory.java | 12 ++-
.../monitor/DefaultMonitorDataPublisher.java | 20 ++--
.../monitor/MetricsMonitorDataProvider.java | 22 ++++-
.../dashboard/monitor/MonitorBootListener.java | 10 +-
.../dashboard/monitor/data/MonitorConstant.java | 109 ++++++++-------------
.../huaweicloud/servicestage/CasEnvConfig.java | 39 ++++----
8 files changed, 116 insertions(+), 113 deletions(-)
diff --git a/huawei-cloud/darklaunch/src/main/java/org/apache/servicecomb/darklaunch/DarklaunchServerListFilter.java b/huawei-cloud/darklaunch/src/main/java/org/apache/servicecomb/darklaunch/DarklaunchServerListFilter.java
index 5c53515d5..d380a8f25 100644
--- a/huawei-cloud/darklaunch/src/main/java/org/apache/servicecomb/darklaunch/DarklaunchServerListFilter.java
+++ b/huawei-cloud/darklaunch/src/main/java/org/apache/servicecomb/darklaunch/DarklaunchServerListFilter.java
@@ -22,12 +22,10 @@ import java.util.List;
import java.util.Random;
import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.loadbalance.ServerListFilterExt;
import org.apache.servicecomb.loadbalance.ServiceCombServer;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicStringProperty;
-
public class DarklaunchServerListFilter implements ServerListFilterExt {
private static final String POLICY_SERVICE_COMB = "servicecomb.darklaunch.policy.%s";
@@ -51,10 +49,8 @@ public class DarklaunchServerListFilter implements ServerListFilterExt {
@Override
public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> serverList, Invocation invocation) {
- DynamicStringProperty ruleStr = DynamicPropertyFactory.getInstance().getStringProperty(
- String.format(POLICY_SERVICE_COMB, invocation.getMicroserviceName()), null
- );
- DarklaunchRule rule = DarklaunchRule.parse(ruleStr.get());
+ DarklaunchRule rule = DarklaunchRule.parse(LegacyPropertyFactory
+ .getStringProperty(String.format(POLICY_SERVICE_COMB, invocation.getMicroserviceName())));
if (rule == null) {
return serverList;
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DashboardConfiguration.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DashboardConfiguration.java
index bbe27342f..2949ec34c 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DashboardConfiguration.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DashboardConfiguration.java
@@ -16,11 +16,18 @@
*/
package org.apache.servicecomb.huaweicloud.dashboard.monitor;
+import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
import org.springframework.context.annotation.Bean;
+import org.springframework.core.env.Environment;
public class DashboardConfiguration {
@Bean
public MonitorInformationCollector monitorInformationCollector() {
return new MonitorInformationCollector();
}
+
+ @Bean
+ public MonitorConstant monitorConstant(Environment environment) {
+ return new MonitorConstant(environment);
+ }
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DataFactory.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DataFactory.java
index 12ba9052a..4889683c1 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DataFactory.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DataFactory.java
@@ -23,13 +23,12 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-import javax.inject.Inject;
-
import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataProvider;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import io.netty.util.concurrent.DefaultThreadFactory;
@@ -40,12 +39,15 @@ public class DataFactory {
private boolean hasStart = false;
- @Inject
+ @Autowired
private List<MonitorDataProvider> dataProviders;
- @Inject
+ @Autowired
private MonitorDataPublisher publisher;
+ @Autowired
+ private MonitorConstant monitorConstant;
+
private ScheduledExecutorService executorService = null;
@@ -81,7 +83,7 @@ public class DataFactory {
} catch (Throwable e) {
LOGGER.error("send monitor data error.", e);
}
- }, MonitorConstant.getInterval(), MonitorConstant.getInterval(), TimeUnit.MILLISECONDS);
+ }, monitorConstant.getInterval(), monitorConstant.getInterval(), TimeUnit.MILLISECONDS);
hasStart = true;
}
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
index de350f787..8846a760e 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/DefaultMonitorDataPublisher.java
@@ -44,12 +44,20 @@ import org.apache.servicecomb.http.client.common.HttpTransportFactory;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataProvider;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataPublisher;
+import org.springframework.beans.factory.annotation.Autowired;
public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
private static final String SSL_KEY = "mc.consumer";
private DashboardClient dashboardClient;
+ private MonitorConstant monitorConstant;
+
+ @Autowired
+ public void setMonitorConstant(MonitorConstant monitorConstant) {
+ this.monitorConstant = monitorConstant;
+ }
+
@Override
public void init() {
DashboardAddressManager addressManager = createDashboardAddressManager();
@@ -83,16 +91,16 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
Configuration localConfiguration) {
List<AuthHeaderProvider> authHeaderProviders = SPIServiceUtils.getOrLoadSortedService(AuthHeaderProvider.class);
- if (MonitorConstant.isProxyEnable()) {
+ if (monitorConstant.isProxyEnable()) {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().
setDefaultRequestConfig(requestConfig);
- HttpHost proxy = new HttpHost(MonitorConstant.getProxyHost(),
- MonitorConstant.getProxyPort(), "http"); // now only support http proxy
+ HttpHost proxy = new HttpHost(monitorConstant.getProxyHost(),
+ monitorConstant.getProxyPort(), "http"); // now only support http proxy
httpClientBuilder.setProxy(proxy);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxy),
- new UsernamePasswordCredentials(MonitorConstant.getProxyUsername(),
- MonitorConstant.getProxyPasswd()));
+ new UsernamePasswordCredentials(monitorConstant.getProxyUsername(),
+ monitorConstant.getProxyPasswd()));
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return HttpTransportFactory
@@ -105,7 +113,7 @@ public class DefaultMonitorDataPublisher implements MonitorDataPublisher {
return HttpTransportFactory
.createHttpTransport(
TransportUtils
- .createSSLProperties(MonitorConstant.sslEnabled(), localConfiguration, SSL_KEY),
+ .createSSLProperties(monitorConstant.sslEnabled(), localConfiguration, SSL_KEY),
getRequestAuthHeaderProvider(authHeaderProviders), requestConfig);
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProvider.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProvider.java
index d20f23f8a..5379c6684 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProvider.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProvider.java
@@ -35,9 +35,9 @@ import org.apache.servicecomb.metrics.core.publish.model.invocation.OperationPer
import org.apache.servicecomb.metrics.core.publish.model.invocation.PerfInfo;
import org.apache.servicecomb.registry.sc.SCRegistration;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import com.google.common.eventbus.Subscribe;
-import com.netflix.config.DynamicPropertyFactory;
import com.netflix.spectator.api.Meter;
/**
@@ -57,6 +57,10 @@ public class MetricsMonitorDataProvider implements MonitorDataProvider {
private SCRegistration scRegistration;
+ private Environment environment;
+
+ private MonitorConstant monitorConstant;
+
public MetricsMonitorDataProvider() {
EventManager.register(this);
}
@@ -66,16 +70,24 @@ public class MetricsMonitorDataProvider implements MonitorDataProvider {
this.scRegistration = scRegistration;
}
+ @Autowired
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
+ @Autowired
+ public void setMonitorConstant(MonitorConstant monitorConstant) {
+ this.monitorConstant = monitorConstant;
+ }
+
@Override
public boolean enabled() {
- return DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.monitor.provider.metrics.enabled", true)
- .get();
+ return environment.getProperty("servicecomb.monitor.provider.metrics.enabled", boolean.class, true);
}
@Override
public String getURL() {
- return String.format(MonitorConstant.MONITORS_URI, scRegistration.getMicroserviceInstance().getServiceName());
+ return String.format(monitorConstant.getMonitorUri(), scRegistration.getMicroserviceInstance().getServiceName());
}
@Override
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorBootListener.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorBootListener.java
index 530e5330c..06dd4aa6d 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorBootListener.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MonitorBootListener.java
@@ -17,19 +17,21 @@
package org.apache.servicecomb.huaweicloud.dashboard.monitor;
-import javax.inject.Inject;
-
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.huaweicloud.dashboard.monitor.data.MonitorConstant;
+import org.springframework.beans.factory.annotation.Autowired;
public class MonitorBootListener implements BootListener {
- @Inject
+ @Autowired
private DataFactory dataFactory;
+ @Autowired
+ private MonitorConstant monitorConstant;
+
@Override
public void onBootEvent(BootEvent event) {
- if (!MonitorConstant.isMonitorEnabled()) {
+ if (!monitorConstant.isMonitorEnabled()) {
return;
}
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/data/MonitorConstant.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/data/MonitorConstant.java
index 9bf37e298..19b207878 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/data/MonitorConstant.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/data/MonitorConstant.java
@@ -17,22 +17,9 @@
package org.apache.servicecomb.huaweicloud.dashboard.monitor.data;
-import com.netflix.config.DynamicBooleanProperty;
-import com.netflix.config.DynamicIntProperty;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicStringProperty;
+import org.springframework.core.env.Environment;
public class MonitorConstant {
- public static final String DOMAIN_NAME = getDomainName();
-
- public static final String CURRENT_VERSION = getApiVersion();
-
- public static final String VERSION_V1 = "v1";
-
- public static final String PREFIX_V2 = String.format("/v2/%s/csemonitor", DOMAIN_NAME);
-
- public static final String MONITORS_URI;
-
public static final String SYSTEM_KEY_DASHBOARD_SERVICE = "DashboardService";
public static final String MONITOR_URI = "servicecomb.monitor.client.serverUri";
@@ -53,99 +40,89 @@ public class MonitorConstant {
public static final int DEFAULT_INTERVAL = 10000;
- public static final int MAX_RETRY_TIMES = 3;
+ private final String DOMAIN_NAME;
- static {
- if (VERSION_V1.equals(CURRENT_VERSION)) {
- MONITORS_URI = "/csemonitor/v1/metric?service=%s";
- } else {
- MONITORS_URI = PREFIX_V2 + "/metric?service=%s";
- }
- }
+ private final String CURRENT_VERSION;
+
+ private final String VERSION_V1;
+
+ private final String PREFIX_V2;
+
+ private final String monitorsUri;
+
+ private Environment environment;
- public static final String TRANSACTION_URI;
+ public MonitorConstant(Environment environment) {
+ this.environment = environment;
+ this.VERSION_V1 = "v1";
+ this.DOMAIN_NAME = getDomainName();
+ this.PREFIX_V2 = String.format("/v2/%s/csemonitor", DOMAIN_NAME);
+ this.CURRENT_VERSION = getApiVersion();
- static {
if (VERSION_V1.equals(CURRENT_VERSION)) {
- TRANSACTION_URI = "/csemonitor/v1/transaction";
+ monitorsUri = "/csemonitor/v1/metric?service=%s";
} else {
- TRANSACTION_URI = PREFIX_V2 + "/transaction";
+ monitorsUri = PREFIX_V2 + "/metric?service=%s";
}
}
- public static String getTanentName() {
- DynamicStringProperty property = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.config.client.tenantName", "default");
- return property.getValue();
+ public String getMonitorUri() {
+ return this.monitorsUri;
}
- public static String getDomainName() {
- DynamicStringProperty property = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.config.client.domainName", "default");
- return property.getValue();
+ public String getDomainName() {
+ return environment.getProperty("servicecomb.config.client.domainName", "default");
}
- public static String getApiVersion() {
- DynamicStringProperty property = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.monitor.client.api.version", "v2");
- return property.getValue();
+ public String getApiVersion() {
+ return environment.getProperty("servicecomb.monitor.client.api.version", "v2");
}
- public static String getServerUrl() {
- DynamicStringProperty property = DynamicPropertyFactory.getInstance().
- getStringProperty("servicecomb.monitor.client.serverUri", null);
- return property.getValue();
+ public String getServerUrl() {
+ return environment.getProperty("servicecomb.monitor.client.serverUri");
}
- public static boolean sslEnabled() {
- DynamicBooleanProperty property = DynamicPropertyFactory.getInstance().
- getBooleanProperty("servicecomb.monitor.client.sslEnabled", true);
- return property.getValue();
+ public boolean sslEnabled() {
+ return environment.getProperty("servicecomb.monitor.client.sslEnabled", boolean.class, true);
}
- public static boolean isMonitorEnabled() {
- DynamicBooleanProperty property = DynamicPropertyFactory.getInstance().
- getBooleanProperty("servicecomb.monitor.client.enabled", false);
- return property.getValue();
+ public boolean isMonitorEnabled() {
+ return environment.getProperty("servicecomb.monitor.client.enabled", boolean.class, false);
}
- public static int getConnectionTimeout() {
- DynamicIntProperty property = DynamicPropertyFactory.getInstance().
- getIntProperty("servicecomb.monitor.client.timeout", DEFAULT_TIMEOUT);
- return property.getValue();
+ public int getConnectionTimeout() {
+ return environment.getProperty("servicecomb.monitor.client.timeout", int.class, DEFAULT_TIMEOUT);
}
- public static int getInterval() {
- DynamicIntProperty property = DynamicPropertyFactory.getInstance().
- getIntProperty("servicecomb.monitor.client.interval", DEFAULT_INTERVAL);
- int val = property.getValue();
- return Math.max(val, MIN_INTERVAL_MILLISECONDS);
+ public int getInterval() {
+ return Math.max(environment.getProperty("servicecomb.monitor.client.interval", int.class, DEFAULT_INTERVAL),
+ MIN_INTERVAL_MILLISECONDS);
}
- public static Boolean isProxyEnable() {
+ public Boolean isProxyEnable() {
return Boolean.parseBoolean(getProperty("false", PROXY_ENABLE));
}
- public static String getProxyHost() {
+ public String getProxyHost() {
return getProperty("127.0.0.1", PROXY_HOST);
}
- public static int getProxyPort() {
+ public int getProxyPort() {
return Integer.parseInt(getProperty("8080", PROXY_PORT));
}
- public static String getProxyUsername() {
+ public String getProxyUsername() {
return getProperty(null, PROXY_USERNAME);
}
- public static String getProxyPasswd() {
+ public String getProxyPasswd() {
return getProperty(null, PROXY_PASSWD);
}
- private static String getProperty(String defaultValue, String... keys) {
+ private String getProperty(String defaultValue, String... keys) {
String property = null;
for (String key : keys) {
- property = DynamicPropertyFactory.getInstance().getStringProperty(key, null).get();
+ property = environment.getProperty(key);
if (property != null) {
break;
}
diff --git a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
index 93c93fbcf..baadb927b 100644
--- a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
+++ b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
@@ -25,8 +25,7 @@ import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
-
-import com.netflix.config.DynamicPropertyFactory;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
public class CasEnvConfig {
private static final String APPLICATION_ID = "CAS_APPLICATION_ID";
@@ -51,36 +50,36 @@ public class CasEnvConfig {
return rs;
}
return Arrays.stream(value.split(",")).map(v -> v.split(":"))
- .filter(v -> v.length == 2)
- .collect(Collectors.toMap(v -> v[0], v -> v[1]));
+ .filter(v -> v.length == 2)
+ .collect(Collectors.toMap(v -> v[0], v -> v[1]));
}
public Map<String, String> getNonEmptyInstanceProperties() {
Map<String, String> map = new HashMap<>();
- map.put(APPLICATION_ID, DynamicPropertyFactory
- .getInstance().getStringProperty(APPLICATION_ID, EMPTY).get());
- map.put(COMPONENT_NAME, DynamicPropertyFactory
- .getInstance().getStringProperty(COMPONENT_NAME, EMPTY).get());
- map.put(INSTANCE_VERSION, DynamicPropertyFactory
- .getInstance().getStringProperty(INSTANCE_VERSION, EMPTY).get());
- map.put(INSTANCE_ID, DynamicPropertyFactory
- .getInstance().getStringProperty(INSTANCE_ID, EMPTY).get());
- map.put(ENVIRONMENT_ID, DynamicPropertyFactory
- .getInstance().getStringProperty(ENVIRONMENT_ID, EMPTY).get());
+ map.put(APPLICATION_ID, LegacyPropertyFactory
+ .getStringProperty(APPLICATION_ID, EMPTY));
+ map.put(COMPONENT_NAME, LegacyPropertyFactory
+ .getStringProperty(COMPONENT_NAME, EMPTY));
+ map.put(INSTANCE_VERSION, LegacyPropertyFactory
+ .getStringProperty(INSTANCE_VERSION, EMPTY));
+ map.put(INSTANCE_ID, LegacyPropertyFactory
+ .getStringProperty(INSTANCE_ID, EMPTY));
+ map.put(ENVIRONMENT_ID, LegacyPropertyFactory
+ .getStringProperty(ENVIRONMENT_ID, EMPTY));
Map<String, String> instanceProps = map.entrySet().stream()
- .filter(entry -> StringUtils.isNotEmpty(entry.getValue()))
- .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ .filter(entry -> StringUtils.isNotEmpty(entry.getValue()))
+ .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
- instanceProps.putAll(parseProps(DynamicPropertyFactory
- .getInstance().getStringProperty(INSTANCE_PROPS, EMPTY).get()));
+ instanceProps.putAll(parseProps(LegacyPropertyFactory
+ .getStringProperty(INSTANCE_PROPS, EMPTY)));
return instanceProps;
}
public Map<String, String> getNonEmptyServiceProperties() {
- return parseProps(DynamicPropertyFactory
- .getInstance().getStringProperty(SERVICE_PROPS, EMPTY).get());
+ return parseProps(LegacyPropertyFactory
+ .getStringProperty(SERVICE_PROPS, EMPTY));
}
}
[servicecomb-java-chassis] 15/25: [SCB-2008]remove archaius dependency: remove Archaius dependency
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit ccd96f16451fd8b2ea9c295d4da1613e16f23d83
Author: liubao <bi...@qq.com>
AuthorDate: Sun Oct 8 14:11:48 2023 +0800
[SCB-2008]remove archaius dependency: remove Archaius dependency
---
.../producer/TestProducerProviderManager.java | 2 +-
.../core/tracing/BraveTraceIdGeneratorTest.java | 2 +-
foundations/foundation-common/pom.xml | 4 ----
.../foundation/common/LegacyPropertyFactory.java | 2 +-
.../foundation/common/utils/KeyPairUtils.java | 15 +++++++--------
.../foundation/common/utils/TestRSAUtil.java | 21 ++++++++++++++++++---
foundations/foundation-metrics/pom.xml | 4 ----
handlers/handler-loadbalance/pom.xml | 4 ----
.../TestAuthenticationBootListener.java | 22 +++++++++++++++++-----
.../authentication/TestRSAAuthenticationToken.java | 20 ++++++++++++++++++++
.../provider/TestProviderTokenManager.java | 22 +++++++++++++++++++---
.../provider/rest/common/RestProducers.java | 10 ++++------
.../provider/rest/common/TestRestProducers.java | 14 ++++++++++++++
.../rest/vertx/TestRestServerVerticle.java | 4 ++--
14 files changed, 104 insertions(+), 42 deletions(-)
diff --git a/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerProviderManager.java b/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerProviderManager.java
index 6025b3a9b..f36229b0e 100644
--- a/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerProviderManager.java
+++ b/core/src/test/java/org/apache/servicecomb/core/provider/producer/TestProducerProviderManager.java
@@ -17,7 +17,7 @@
package org.apache.servicecomb.core.provider.producer;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestProducerProviderManager {
@Test
diff --git a/core/src/test/java/org/apache/servicecomb/core/tracing/BraveTraceIdGeneratorTest.java b/core/src/test/java/org/apache/servicecomb/core/tracing/BraveTraceIdGeneratorTest.java
index 55fa45387..e858dd954 100644
--- a/core/src/test/java/org/apache/servicecomb/core/tracing/BraveTraceIdGeneratorTest.java
+++ b/core/src/test/java/org/apache/servicecomb/core/tracing/BraveTraceIdGeneratorTest.java
@@ -17,8 +17,8 @@
package org.apache.servicecomb.core.tracing;
-import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
public class BraveTraceIdGeneratorTest {
diff --git a/foundations/foundation-common/pom.xml b/foundations/foundation-common/pom.xml
index d949af1af..709915470 100644
--- a/foundations/foundation-common/pom.xml
+++ b/foundations/foundation-common/pom.xml
@@ -115,9 +115,5 @@
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- </dependency>
</dependencies>
</project>
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
index 52f8372ba..ada58bdf3 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/LegacyPropertyFactory.java
@@ -63,7 +63,7 @@ public class LegacyPropertyFactory {
}
public static String getStringProperty(String key, String defaultValue) {
- return environment.getProperty(key, String.class, defaultValue);
+ return environment.getProperty(key, defaultValue);
}
public static Environment getEnvironment() {
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/KeyPairUtils.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/KeyPairUtils.java
index 361e62fa0..d77067df8 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/KeyPairUtils.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/KeyPairUtils.java
@@ -31,23 +31,22 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.netflix.config.DynamicPropertyFactory;
-
public class KeyPairUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(KeyPairUtils.class);
- private static final String KEY_GENERATOR_ALGORITHM = DynamicPropertyFactory.getInstance()
- .getStringProperty("servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA").get();;
+ private static final String KEY_GENERATOR_ALGORITHM = LegacyPropertyFactory.getStringProperty(
+ "servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA");
- private static final String SIGN_ALG = DynamicPropertyFactory.getInstance()
- .getStringProperty("servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA").get();
+ private static final String SIGN_ALG = LegacyPropertyFactory.getStringProperty(
+ "servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA");
- private static final int KEY_SIZE = DynamicPropertyFactory.getInstance()
- .getIntProperty("servicecomb.publicKey.accessControl.keySize", 2048).get();
+ private static final int KEY_SIZE = LegacyPropertyFactory.getIntProperty(
+ "servicecomb.publicKey.accessControl.keySize", 2048);
private static final Base64.Encoder encoder = Base64.getEncoder();
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestRSAUtil.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestRSAUtil.java
index 7c5926c7a..6bd9b386e 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestRSAUtil.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestRSAUtil.java
@@ -16,15 +16,30 @@
*/
package org.apache.servicecomb.foundation.common.utils;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
+
public class TestRSAUtil {
+ @BeforeAll
+ public static void setUpClass() {
+ Environment environment = Mockito.mock(Environment.class);
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA"))
+ .thenReturn("RSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA"))
+ .thenReturn("SHA256withRSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keySize", int.class, 2048))
+ .thenReturn(2048);
+ }
@Test
public void testSignVerify()
diff --git a/foundations/foundation-metrics/pom.xml b/foundations/foundation-metrics/pom.xml
index d63cce0d2..ba0193e70 100644
--- a/foundations/foundation-metrics/pom.xml
+++ b/foundations/foundation-metrics/pom.xml
@@ -31,10 +31,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-common</artifactId>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- </dependency>
<dependency>
<groupId>com.netflix.spectator</groupId>
<artifactId>spectator-reg-servo</artifactId>
diff --git a/handlers/handler-loadbalance/pom.xml b/handlers/handler-loadbalance/pom.xml
index e89e1b720..370489f02 100644
--- a/handlers/handler-loadbalance/pom.xml
+++ b/handlers/handler-loadbalance/pom.xml
@@ -52,10 +52,6 @@
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
</dependency>
- <dependency>
- <groupId>com.netflix.archaius</groupId>
- <artifactId>archaius-core</artifactId>
- </dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
index 99f6877f5..a2be179f5 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestAuthenticationBootListener.java
@@ -22,16 +22,17 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.core.BootListener.BootEvent;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.token.Keypair4Auth;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -40,14 +41,25 @@ import org.springframework.core.env.Environment;
public class TestAuthenticationBootListener {
private SCBEngine engine;
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void setUpClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA"))
+ .thenReturn("RSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA"))
+ .thenReturn("SHA256withRSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keySize", int.class, 2048))
+ .thenReturn(2048);
+ Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
+ long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
+ }
+
@BeforeEach
public void setUp() {
- ConfigUtil.installDynamicConfig();
engine = SCBBootstrap.createSCBEngineForTest();
- Environment environment = Mockito.mock(Environment.class);
engine.setEnvironment(environment);
- Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
- long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
engine.run();
}
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestRSAAuthenticationToken.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestRSAAuthenticationToken.java
index 586e83521..e9ec7e2b2 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestRSAAuthenticationToken.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/TestRSAAuthenticationToken.java
@@ -16,18 +16,38 @@
*/
package org.apache.servicecomb.authentication;
+import static org.apache.servicecomb.core.SCBEngine.CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC;
+import static org.apache.servicecomb.core.SCBEngine.DEFAULT_TURN_DOWN_STATUS_WAIT_SEC;
+
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.KeyPairUtils;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class TestRSAAuthenticationToken {
+ static Environment environment = Mockito.mock(Environment.class);
+ @BeforeAll
+ public static void setUpClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA"))
+ .thenReturn("RSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA"))
+ .thenReturn("SHA256withRSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keySize", int.class, 2048))
+ .thenReturn(2048);
+ Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
+ long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
+ }
@Test
public void testRSAAuthenticationToken()
diff --git a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
index f058ef6bc..5c9777be4 100644
--- a/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
+++ b/handlers/handler-publickey-auth/src/test/java/org/apache/servicecomb/authentication/provider/TestProviderTokenManager.java
@@ -16,6 +16,8 @@
*/
package org.apache.servicecomb.authentication.provider;
+import static org.apache.servicecomb.core.SCBEngine.CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC;
+import static org.apache.servicecomb.core.SCBEngine.DEFAULT_TURN_DOWN_STATUS_WAIT_SEC;
import static org.mockito.ArgumentMatchers.any;
import java.util.HashMap;
@@ -23,8 +25,8 @@ import java.util.Map;
import org.apache.servicecomb.authentication.RSAAuthenticationToken;
import org.apache.servicecomb.authentication.consumer.ConsumerTokenManager;
-import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.config.MicroserviceProperties;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.KeyPairEntry;
import org.apache.servicecomb.foundation.common.utils.KeyPairUtils;
import org.apache.servicecomb.foundation.token.Keypair4Auth;
@@ -33,21 +35,35 @@ import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.apache.servicecomb.registry.discovery.MicroserviceInstanceCache;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import com.google.common.cache.Cache;
public class TestProviderTokenManager {
-
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void setUpClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keyGeneratorAlgorithm", "RSA"))
+ .thenReturn("RSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.signAlgorithm", "SHA256withRSA"))
+ .thenReturn("SHA256withRSA");
+ Mockito.when(environment.getProperty("servicecomb.publicKey.accessControl.keySize", int.class, 2048))
+ .thenReturn(2048);
+ Mockito.when(environment.getProperty(CFG_KEY_TURN_DOWN_STATUS_WAIT_SEC,
+ long.class, DEFAULT_TURN_DOWN_STATUS_WAIT_SEC)).thenReturn(DEFAULT_TURN_DOWN_STATUS_WAIT_SEC);
+ }
@BeforeEach
public void setUp() {
- ConfigUtil.installDynamicConfig();
}
@AfterEach
diff --git a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
index cf0f5fba3..7a0df73c7 100644
--- a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
+++ b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestProducers.java
@@ -22,13 +22,12 @@ import java.util.List;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.core.provider.producer.ProducerMeta;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
-import com.netflix.config.DynamicPropertyFactory;
-
public class RestProducers implements BeanPostProcessor {
private final List<ProducerMeta> producerMetaList = new ArrayList<>();
@@ -36,9 +35,6 @@ public class RestProducers implements BeanPostProcessor {
private final Class<? extends Annotation> restControllerCls = (Class<? extends Annotation>) ReflectUtils
.getClassByName("org.springframework.web.bind.annotation.RestController");
- private final boolean scanRestController = restControllerCls != null &&
- DynamicPropertyFactory.getInstance().getBooleanProperty(RestConst.PROVIDER_SCAN_REST_CONTROLLER, true).get();
-
public List<ProducerMeta> getProducerMetaList() {
return producerMetaList;
}
@@ -70,7 +66,9 @@ public class RestProducers implements BeanPostProcessor {
return;
}
- if (scanRestController && beanCls.getAnnotation(restControllerCls) != null) {
+ if (restControllerCls != null &&
+ LegacyPropertyFactory.getBooleanProperty(RestConst.PROVIDER_SCAN_REST_CONTROLLER, true)
+ && beanCls.getAnnotation(restControllerCls) != null) {
ProducerMeta producerMeta = new ProducerMeta(beanCls.getName(), bean);
producerMetaList.add(producerMeta);
}
diff --git a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestProducers.java b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestProducers.java
index bf54f656e..9e70423e2 100644
--- a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestProducers.java
+++ b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestProducers.java
@@ -17,15 +17,29 @@
package org.apache.servicecomb.provider.rest.common;
+import org.apache.servicecomb.common.rest.RestConst;
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.foundation.test.scaffolding.spring.SpringUtils;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
public class TestRestProducers {
@RestSchema(schemaId = "test")
public static class RestSchemaForTest {
}
+ static Environment environment = Mockito.mock(Environment.class);
+
+ @BeforeAll
+ public static void setUpClass() {
+ LegacyPropertyFactory.setEnvironment(environment);
+ Mockito.when(environment.getProperty(RestConst.PROVIDER_SCAN_REST_CONTROLLER, boolean.class, true))
+ .thenReturn(true);
+ }
+
RestProducers producer = new RestProducers();
@Test
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
index ed2247da3..d3b502a6d 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
@@ -106,7 +106,7 @@ public class TestRestServerVerticle {
.thenReturn(true);
Mockito.when(environment.getProperty(SERVICECOMB_CORS_CONFIG_BASE + ".enabled", boolean.class, false))
.thenReturn(false);
- Mockito.when(environment.getProperty(PUBLISH_ADDRESS, String.class, ""))
+ Mockito.when(environment.getProperty(PUBLISH_ADDRESS, ""))
.thenReturn("");
Mockito.when(environment.getProperty(
RestConst.UPLOAD_MAX_SIZE, long.class, -1L))
@@ -266,7 +266,7 @@ public class TestRestServerVerticle {
Mockito.when(environment.getProperty("servicecomb.cors.enabled", boolean.class,
false))
.thenReturn(true);
- Mockito.when(environment.getProperty("servicecomb.cors.origin", String.class,
+ Mockito.when(environment.getProperty("servicecomb.cors.origin",
"*"))
.thenReturn("*");
Mockito.when(environment.getProperty("servicecomb.cors.allowedMethod"))