├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── BUILDING ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── REPORTING-BUGS.md ├── api ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alibaba │ │ │ └── nacos │ │ │ └── api │ │ │ ├── NacosFactory.java │ │ │ ├── PropertyKeyConst.java │ │ │ ├── annotation │ │ │ ├── NacosInjected.java │ │ │ └── NacosProperties.java │ │ │ ├── common │ │ │ └── Constants.java │ │ │ ├── config │ │ │ ├── ConfigFactory.java │ │ │ ├── ConfigService.java │ │ │ ├── annotation │ │ │ │ ├── NacosConfigListener.java │ │ │ │ ├── NacosConfigurationProperties.java │ │ │ │ ├── NacosIgnore.java │ │ │ │ ├── NacosProperty.java │ │ │ │ └── NacosValue.java │ │ │ ├── convert │ │ │ │ └── NacosConfigConverter.java │ │ │ ├── filter │ │ │ │ ├── IConfigContext.java │ │ │ │ ├── IConfigFilter.java │ │ │ │ ├── IConfigFilterChain.java │ │ │ │ ├── IConfigRequest.java │ │ │ │ ├── IConfigResponse.java │ │ │ │ └── IFilterConfig.java │ │ │ └── listener │ │ │ │ ├── AbstractListener.java │ │ │ │ ├── AbstractSharedListener.java │ │ │ │ └── Listener.java │ │ │ ├── exception │ │ │ └── NacosException.java │ │ │ └── naming │ │ │ ├── NamingFactory.java │ │ │ ├── NamingService.java │ │ │ ├── listener │ │ │ ├── Event.java │ │ │ ├── EventListener.java │ │ │ └── NamingEvent.java │ │ │ └── pojo │ │ │ ├── AbstractHealthChecker.java │ │ │ ├── Cluster.java │ │ │ ├── Instance.java │ │ │ ├── ListView.java │ │ │ ├── Service.java │ │ │ └── ServiceInfo.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── api │ └── annotation │ └── NacosPropertiesTest.java ├── client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alibaba │ │ │ └── nacos │ │ │ └── client │ │ │ ├── config │ │ │ ├── NacosConfigService.java │ │ │ ├── common │ │ │ │ └── GroupKey.java │ │ │ ├── filter │ │ │ │ └── impl │ │ │ │ │ ├── ConfigContext.java │ │ │ │ │ ├── ConfigFilterChainManager.java │ │ │ │ │ ├── ConfigRequest.java │ │ │ │ │ └── ConfigResponse.java │ │ │ ├── impl │ │ │ │ ├── CacheData.java │ │ │ │ ├── ClientWorker.java │ │ │ │ ├── EventDispatcher.java │ │ │ │ ├── HttpSimpleClient.java │ │ │ │ ├── Limiter.java │ │ │ │ ├── LocalConfigInfoProcessor.java │ │ │ │ ├── ServerHttpAgent.java │ │ │ │ ├── ServerListManager.java │ │ │ │ ├── SpasAdapter.java │ │ │ │ └── TimerService.java │ │ │ ├── listener │ │ │ │ └── impl │ │ │ │ │ └── PropertiesListener.java │ │ │ └── utils │ │ │ │ ├── ConcurrentDiskUtil.java │ │ │ │ ├── ContentUtils.java │ │ │ │ ├── IOUtils.java │ │ │ │ ├── JVMUtil.java │ │ │ │ ├── LogUtils.java │ │ │ │ ├── MD5.java │ │ │ │ ├── ParamUtils.java │ │ │ │ ├── SnapShotSwitch.java │ │ │ │ └── TenantUtil.java │ │ │ ├── identify │ │ │ ├── Base64.java │ │ │ ├── Constants.java │ │ │ ├── CredentialListener.java │ │ │ ├── CredentialService.java │ │ │ ├── CredentialWatcher.java │ │ │ ├── Credentials.java │ │ │ ├── STSConfig.java │ │ │ ├── SpasCredential.java │ │ │ └── SpasCredentialLoader.java │ │ │ ├── logger │ │ │ ├── Level.java │ │ │ ├── Logger.java │ │ │ ├── LoggerFactory.java │ │ │ ├── json │ │ │ │ ├── JSONArray.java │ │ │ │ ├── JSONAware.java │ │ │ │ ├── JSONObject.java │ │ │ │ ├── JSONStreamAware.java │ │ │ │ ├── JSONValue.java │ │ │ │ └── parser │ │ │ │ │ ├── ContainerFactory.java │ │ │ │ │ ├── ContentHandler.java │ │ │ │ │ ├── JSONParser.java │ │ │ │ │ ├── ParseException.java │ │ │ │ │ ├── Yylex.java │ │ │ │ │ └── Yytoken.java │ │ │ ├── log4j2 │ │ │ │ ├── Log4j2Logger.java │ │ │ │ └── Log4j2LoggerFactory.java │ │ │ ├── nop │ │ │ │ ├── NopLogger.java │ │ │ │ └── NopLoggerFactory.java │ │ │ ├── option │ │ │ │ ├── AbstractActiveOption.java │ │ │ │ ├── ActivateOption.java │ │ │ │ ├── Log4j2ActivateOption.java │ │ │ │ ├── Logback918ActivateOption.java │ │ │ │ ├── LogbackActivateOption.java │ │ │ │ ├── LogbackLoggerContextUtil.java │ │ │ │ └── Slf4jLog4j2AdapterActivateOption.java │ │ │ ├── slf4j │ │ │ │ ├── Slf4jLogger.java │ │ │ │ └── Slf4jLoggerFactory.java │ │ │ ├── support │ │ │ │ ├── AppenderInfo.java │ │ │ │ ├── ErrorLog.java │ │ │ │ ├── ILoggerFactory.java │ │ │ │ ├── LogLog.java │ │ │ │ ├── LogbackHelper.java │ │ │ │ ├── LoggerHelper.java │ │ │ │ ├── LoggerInfo.java │ │ │ │ └── LoggerSupport.java │ │ │ └── util │ │ │ │ ├── FormattingTuple.java │ │ │ │ ├── MessageFormatter.java │ │ │ │ └── MessageUtil.java │ │ │ ├── naming │ │ │ ├── NacosNamingService.java │ │ │ ├── backups │ │ │ │ └── FailoverReactor.java │ │ │ ├── beat │ │ │ │ ├── BeatInfo.java │ │ │ │ └── BeatReactor.java │ │ │ ├── cache │ │ │ │ ├── ConcurrentDiskUtil.java │ │ │ │ └── DiskCache.java │ │ │ ├── core │ │ │ │ ├── Balancer.java │ │ │ │ ├── EventDispatcher.java │ │ │ │ ├── HostReactor.java │ │ │ │ ├── ProtectMode.java │ │ │ │ └── PushRecver.java │ │ │ ├── net │ │ │ │ ├── HttpClient.java │ │ │ │ └── NamingProxy.java │ │ │ └── utils │ │ │ │ ├── Chooser.java │ │ │ │ ├── CollectionUtils.java │ │ │ │ ├── GenericPoller.java │ │ │ │ ├── IoUtils.java │ │ │ │ ├── JvmRandom.java │ │ │ │ ├── LogUtils.java │ │ │ │ ├── NetUtils.java │ │ │ │ ├── Pair.java │ │ │ │ ├── Poller.java │ │ │ │ ├── RandomUtils.java │ │ │ │ ├── StringUtils.java │ │ │ │ ├── ThreadLocalRandom.java │ │ │ │ └── UtilAndComs.java │ │ │ └── utils │ │ │ ├── AppNameUtils.java │ │ │ ├── EnvUtil.java │ │ │ ├── IPUtil.java │ │ │ ├── JSONUtils.java │ │ │ ├── ParamUtil.java │ │ │ └── StringUtils.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── client │ ├── AppTest.java │ └── NamingTest.java ├── common ├── license ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── alibaba │ │ └── nacos │ │ └── common │ │ └── util │ │ ├── Constants.java │ │ ├── IoUtils.java │ │ ├── Md5Utils.java │ │ ├── Pair.java │ │ ├── SystemUtils.java │ │ └── UuidUtil.java │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── common │ ├── AppTest.java │ └── SystemUtilsTest.java ├── config ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alibaba │ │ │ └── nacos │ │ │ └── config │ │ │ └── server │ │ │ ├── Config.java │ │ │ ├── aspect │ │ │ ├── CapacityManagementAspect.java │ │ │ └── RequestLogAspect.java │ │ │ ├── configuration │ │ │ ├── ClusterDataSourceConfiguration.java │ │ │ ├── DataBaseConfiguration.java │ │ │ ├── LocalDataSourceConfiguration.java │ │ │ └── NacosConfigConfiguration.java │ │ │ ├── constant │ │ │ ├── Constants.java │ │ │ └── CounterMode.java │ │ │ ├── controller │ │ │ ├── CapacityController.java │ │ │ ├── CommunicationController.java │ │ │ ├── ConfigController.java │ │ │ ├── ConfigServletInner.java │ │ │ ├── HealthController.java │ │ │ ├── HistoryController.java │ │ │ ├── ListenerController.java │ │ │ └── OpsController.java │ │ │ ├── exception │ │ │ ├── GlobalExceptionHandler.java │ │ │ └── NacosException.java │ │ │ ├── filter │ │ │ └── NacosWebFilter.java │ │ │ ├── manager │ │ │ ├── AbstractTask.java │ │ │ ├── TaskManager.java │ │ │ ├── TaskManagerMBean.java │ │ │ └── TaskProcessor.java │ │ │ ├── model │ │ │ ├── ACLInfo.java │ │ │ ├── AuthType.java │ │ │ ├── CacheItem.java │ │ │ ├── ConfigAdvanceInfo.java │ │ │ ├── ConfigAllInfo.java │ │ │ ├── ConfigHistoryInfo.java │ │ │ ├── ConfigInfo.java │ │ │ ├── ConfigInfo4Beta.java │ │ │ ├── ConfigInfo4Tag.java │ │ │ ├── ConfigInfoAggr.java │ │ │ ├── ConfigInfoBase.java │ │ │ ├── ConfigInfoBaseEx.java │ │ │ ├── ConfigInfoChanged.java │ │ │ ├── ConfigInfoEx.java │ │ │ ├── ConfigInfoWrapper.java │ │ │ ├── ConfigKey.java │ │ │ ├── GroupInfo.java │ │ │ ├── GroupkeyListenserStatus.java │ │ │ ├── HistoryContext.java │ │ │ ├── Page.java │ │ │ ├── RestPageResult.java │ │ │ ├── RestResult.java │ │ │ ├── SampleResult.java │ │ │ ├── SubInfo.java │ │ │ ├── SubscriberStatus.java │ │ │ ├── app │ │ │ │ ├── ApplicationInfo.java │ │ │ │ ├── ApplicationPublishRecord.java │ │ │ │ ├── GroupKey.java │ │ │ │ └── MonitorInfo.java │ │ │ └── capacity │ │ │ │ ├── Capacity.java │ │ │ │ ├── GroupCapacity.java │ │ │ │ └── TenantCapacity.java │ │ │ ├── monitor │ │ │ ├── MemoryMonitor.java │ │ │ └── ResponseMonitor.java │ │ │ ├── service │ │ │ ├── AggrWhitelist.java │ │ │ ├── BasicDataSourceServiceImpl.java │ │ │ ├── ClientIpWhiteList.java │ │ │ ├── ClientTrackService.java │ │ │ ├── ConfigDataChangeEvent.java │ │ │ ├── ConfigService.java │ │ │ ├── ConfigSubService.java │ │ │ ├── DataSourceService.java │ │ │ ├── DiskUtil.java │ │ │ ├── DynamicDataSource.java │ │ │ ├── LocalDataChangeEvent.java │ │ │ ├── LocalDataSourceServiceImpl.java │ │ │ ├── LongPollingService.java │ │ │ ├── PersistService.java │ │ │ ├── ServerListService.java │ │ │ ├── SwitchService.java │ │ │ ├── TimerTaskService.java │ │ │ ├── capacity │ │ │ │ ├── CapacityService.java │ │ │ │ ├── GroupCapacityPersistService.java │ │ │ │ └── TenantCapacityPersistService.java │ │ │ ├── dump │ │ │ │ ├── DumpService.java │ │ │ │ └── DumpTask.java │ │ │ ├── merge │ │ │ │ ├── MergeDataTask.java │ │ │ │ ├── MergeDatumService.java │ │ │ │ └── MergeTaskProcessor.java │ │ │ ├── notify │ │ │ │ ├── AsyncNotifyService.java │ │ │ │ ├── NotifyService.java │ │ │ │ ├── NotifySingleService.java │ │ │ │ ├── NotifyTask.java │ │ │ │ └── NotifyTaskProcessor.java │ │ │ └── trace │ │ │ │ └── ConfigTraceService.java │ │ │ └── utils │ │ │ ├── AccumulateStatCount.java │ │ │ ├── AppNameUtils.java │ │ │ ├── ContentUtils.java │ │ │ ├── GroupKey.java │ │ │ ├── GroupKey2.java │ │ │ ├── IPUtil.java │ │ │ ├── JSONUtils.java │ │ │ ├── LogUtil.java │ │ │ ├── MD5.java │ │ │ ├── MD5Util.java │ │ │ ├── PaginationHelper.java │ │ │ ├── ParamUtils.java │ │ │ ├── PropertyUtil.java │ │ │ ├── Protocol.java │ │ │ ├── RegexParser.java │ │ │ ├── RequestUtil.java │ │ │ ├── ResourceUtils.java │ │ │ ├── ResponseUtil.java │ │ │ ├── RunningConfigUtils.java │ │ │ ├── SimpleCache.java │ │ │ ├── SimpleFlowData.java │ │ │ ├── SimpleIPFlowData.java │ │ │ ├── SimpleReadWriteLock.java │ │ │ ├── SingletonRepository.java │ │ │ ├── StatConstants.java │ │ │ ├── StringUtils.java │ │ │ ├── SystemConfig.java │ │ │ ├── ThreadUtil.java │ │ │ ├── TimeUtils.java │ │ │ ├── TimeoutUtils.java │ │ │ ├── TraceLogUtil.java │ │ │ ├── UrlAnalysisUtils.java │ │ │ └── event │ │ │ └── EventDispatcher.java │ └── resources │ │ ├── META-INF │ │ ├── logback │ │ │ └── nacos-included.xml │ │ ├── nacos-db.sql │ │ └── schema.sql │ │ └── version │ │ └── version.txt │ └── test │ ├── java │ └── com │ │ └── alibaba │ │ └── nacos │ │ └── config │ │ └── server │ │ ├── configuration │ │ └── LocalDataSourceConfigurationTest.java │ │ ├── constant │ │ └── ConstantsTest.java │ │ ├── controller │ │ └── HealthControllerUnitTest.java │ │ ├── service │ │ ├── AggrWhitelistTest.java │ │ ├── ClientTrackServiceTest.java │ │ └── DiskServiceUnitTest.java │ │ └── utils │ │ ├── GroupKeyTest.java │ │ ├── SimpleReadWriteLockTest.java │ │ └── event │ │ └── EventDispatcherTest.java │ └── resources │ ├── application.xml-bk │ ├── application.xml-test4derby │ ├── jdbc.properties │ ├── log4j.properties │ └── user.properties ├── console ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── alibaba │ │ └── nacos │ │ └── Nacos.java │ └── resources │ ├── META-INF │ ├── nacos-default.properties │ └── schema.sql │ └── diamond-server-logback.xml ├── core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alibaba │ │ │ └── nacos │ │ │ └── core │ │ │ ├── env │ │ │ └── NacosDefaultPropertySourceEnvironmentPostProcessor.java │ │ │ └── listener │ │ │ ├── LoggingSpringApplicationRunListener.java │ │ │ └── StandaloneProfileApplicationListener.java │ └── resources │ │ ├── META-INF │ │ ├── logback │ │ │ └── nacos.xml │ │ ├── nacos-default.properties │ │ └── spring.factories │ │ └── banner.txt │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── core │ ├── env │ └── NacosDefaultPropertySourceEnvironmentPostProcessorTest.java │ └── listener │ └── StandaloneProfileApplicationListenerTest.java ├── distribution ├── LICENSE-BIN ├── NOTICE-BIN ├── bin │ ├── shutdown.cmd │ ├── shutdown.sh │ ├── startup.cmd │ └── startup.sh ├── conf │ ├── application.properties │ ├── application.properties.example │ ├── cluster.conf.example │ ├── nacos-logback.xml │ ├── nacos-mysql.sql │ └── schema.sql ├── pom.xml ├── release-client.xml ├── release-config.xml ├── release-core.xml ├── release-nacos.xml └── release-naming.xml ├── doc ├── Nacos_Logo.png └── arch.png ├── example ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── alibaba │ │ └── nacos │ │ └── example │ │ ├── App.java │ │ ├── ConfigExample.java │ │ └── NamingExample.java │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── example │ └── AppTest.java ├── naming ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alibaba │ │ │ └── nacos │ │ │ └── naming │ │ │ ├── NamingApp.java │ │ │ ├── acl │ │ │ ├── AuthChecker.java │ │ │ └── AuthInfo.java │ │ │ ├── boot │ │ │ └── RunningConfig.java │ │ │ ├── controllers │ │ │ ├── CatalogController.java │ │ │ ├── ClusterController.java │ │ │ ├── CmdbController.java │ │ │ ├── HealthController.java │ │ │ ├── InstanceController.java │ │ │ ├── OperatorController.java │ │ │ └── ServiceController.java │ │ │ ├── core │ │ │ ├── Cluster.java │ │ │ ├── DistroMapper.java │ │ │ ├── Domain.java │ │ │ ├── DomainsManager.java │ │ │ ├── IpAddress.java │ │ │ └── VirtualClusterDomain.java │ │ │ ├── exception │ │ │ ├── NacosException.java │ │ │ └── ResponseExceptionHandler.java │ │ │ ├── healthcheck │ │ │ ├── AbstractHealthCheckConfig.java │ │ │ ├── AbstractHealthCheckProcessor.java │ │ │ ├── ClientBeatCheckTask.java │ │ │ ├── ClientBeatProcessor.java │ │ │ ├── HealthCheckMode.java │ │ │ ├── HealthCheckReactor.java │ │ │ ├── HealthCheckStatus.java │ │ │ ├── HealthCheckTask.java │ │ │ ├── HealthCheckType.java │ │ │ ├── HttpHealthCheckProcessor.java │ │ │ ├── MysqlHealthCheckProcessor.java │ │ │ ├── RsInfo.java │ │ │ └── TcpSuperSenseProcessor.java │ │ │ ├── misc │ │ │ ├── DomainStatusSynchronizer.java │ │ │ ├── HttpClient.java │ │ │ ├── Loggers.java │ │ │ ├── Message.java │ │ │ ├── NamingProxy.java │ │ │ ├── NetUtils.java │ │ │ ├── ServerStatusSynchronizer.java │ │ │ ├── Switch.java │ │ │ ├── SwitchDomain.java │ │ │ ├── SwitchEntry.java │ │ │ ├── Synchronizer.java │ │ │ └── UtilsAndCommons.java │ │ │ ├── monitor │ │ │ └── PerformanceLoggerThread.java │ │ │ ├── push │ │ │ ├── ClientInfo.java │ │ │ ├── DataSource.java │ │ │ └── PushService.java │ │ │ ├── raft │ │ │ ├── Datum.java │ │ │ ├── GlobalExecutor.java │ │ │ ├── PeerSet.java │ │ │ ├── RaftCore.java │ │ │ ├── RaftListener.java │ │ │ ├── RaftPeer.java │ │ │ ├── RaftProxy.java │ │ │ └── RaftStore.java │ │ │ └── web │ │ │ ├── ApiCommands.java │ │ │ ├── AuthFilter.java │ │ │ ├── BaseServlet.java │ │ │ ├── DistroFilter.java │ │ │ ├── MockHttpRequest.java │ │ │ ├── NamingConfig.java │ │ │ ├── NeedAuth.java │ │ │ └── RaftCommands.java │ └── resources │ │ └── META-INF │ │ └── logback │ │ └── nacos-included.xml │ └── test │ └── java │ └── com │ └── alibaba │ └── nacos │ └── naming │ ├── BaseTest.java │ ├── controllers │ └── InstanceControllerTest.java │ ├── core │ ├── ClusterTest.java │ ├── DomainTest.java │ ├── DomainsManagerTest.java │ └── IpAddressTest.java │ ├── misc │ ├── SwitchTest.java │ └── UtilsAndCommonsTest.java │ ├── raft │ └── RaftStoreTest.java │ └── web │ └── APICommandsTest.java ├── pom.xml ├── style └── codeStyle.md └── test ├── pom.xml └── src └── test ├── java └── com │ └── alibaba │ └── nacos │ └── test │ ├── AppTest.java │ ├── config │ └── ConfigAPI_ITCase.java │ ├── naming │ ├── DeregisterInstance_ITCase.java │ ├── NamingBase.java │ ├── Params.java │ ├── RandomUtils.java │ ├── RegisterInstance_ITCase.java │ ├── RestAPI_ITCase.java │ ├── SelectInstances_ITCase.java │ ├── SelectOneHealthyInstance_ITCase.java │ ├── ServiceListTest.java │ ├── Starter_ITCase.java │ ├── SubscribeCluster_ITCase.java │ ├── Subscribe_ITCase.java │ └── Unsubscribe_ITCase.java │ └── smoke │ └── nacosSmoke_ITCase.java └── resources ├── application.properties ├── logback-test.xml └── schema.sql /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please do not create a Pull Request without creating an issue first. 2 | 3 | ## What is the purpose of the change 4 | 5 | XXXXX 6 | 7 | ## Brief changelog 8 | 9 | XX 10 | 11 | ## Verifying this change 12 | 13 | XXXX 14 | 15 | Follow this checklist to help us incorporate your contribution quickly and easily: 16 | 17 | * [ ] Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 18 | * [ ] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body. 19 | * [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 20 | * [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/alibaba/nacos/tree/master/test). 21 | * [ ] Run `mvn -B clean apache-rat:check findbugs:findbugs` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test` to make sure integration-test pass. 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Except this file !.gitignore 2 | .classpath 3 | .project 4 | .settings 5 | target 6 | .project 7 | .idea 8 | .DS_Store 9 | /logs 10 | *.iml 11 | node_modules 12 | test/derby.log 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | notifications: 2 | email: 3 | recipients: 4 | - xchaos8@126.com 5 | - nacos_dev@linux.alibaba.com 6 | - dev-nacos@googlegroups.com 7 | on_success: change 8 | on_failure: always 9 | 10 | language: java 11 | 12 | matrix: 13 | include: 14 | # On OSX, run with default JDK only. 15 | # - os: osx 16 | # On Linux, run with specific JDKs only. 17 | - os: linux 18 | env: CUSTOM_JDK="oraclejdk8" 19 | 20 | before_install: 21 | - echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc 22 | - cat ~/.mavenrc 23 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi 24 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi 25 | 26 | script: 27 | 28 | after_success: 29 | - mvn clean install -Pit-test 30 | - mvn sonar:sonar -Psonar-apache 31 | -------------------------------------------------------------------------------- /BUILDING: -------------------------------------------------------------------------------- 1 | Build Instructions for NACOS 2 | 3 | ==================================================== 4 | 5 | (1) Prerequisites 6 | 7 | JDK 1.8+ is required in order to compile and run Nacos. 8 | 9 | nacos utilizes Maven as a distribution management and packaging tool. Version 3.0.3 or later is required. 10 | Maven installation and configuration instructions can be found here: 11 | 12 | http://maven.apache.org/run-maven/index.html 13 | 14 | 15 | (2) Run test cases 16 | 17 | Execute the following command in order to compile and run test cases of each components: 18 | 19 | $ mvn test 20 | 21 | 22 | (3) Import projects to Eclipse IDE 23 | 24 | First, generate eclipse project files: 25 | 26 | $ mvn -U eclipse:eclipse 27 | 28 | Then, import to eclipse by specifying the root directory of the project via: 29 | 30 | [File] > [Import] > [Existing Projects into Workspace]. 31 | 32 | 33 | (4) Build distribution packages 34 | 35 | Execute the following command in order to build the tar.gz packages and install JAR into local repository: 36 | 37 | #build nacos 38 | $ mvn -Prelease-nacos -DskipTests clean install -U -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 (Sept 17, 2018) 2 | 3 | #### FEATURES: 4 | 5 | * separate nacos-api from nacos client implementation 6 | * Cluster node health check abnormality 7 | * Stand-alone mode gets the change history list exception 8 | * Pulling does not exist configuration print io exception 9 | * Optimized log framework 10 | * Service Discovery: Client support getting server status. 11 | * Service Discovery: Client support get all service names of server. 12 | * Service Discovery: Client support get all subscribed services. 13 | 14 | 15 | #### IMPROVEMENTS: 16 | 17 | #### BUG FIXES: 18 | 19 | #### BREAKING CHANGES: 20 | 21 | 22 | 23 | ## 0.1.0 (July 18, 2018) 24 | 25 | #### FEATURES: 26 | 27 | * Creating, deleting, modifying, and querying configurations: the core functionalities. 28 | * Multiple languages support: supports Java/Shell/HTTP OpenAPI. 29 | * Service Discovery: Basic service registry and discovery. 30 | * Service Discovery: Service load balancing using instance weights, protect threshold and instance health statuses. 31 | * Service Discovery: Supports four ways for health check: http, tcp, mysql and client heartbeat. 32 | * Service Discovery: CRUD operations on service instances through Java client and open API. 33 | * Service Discovery: Service subscribtion and push through Java client. 34 | * Nacos official website is coming. https://nacos.io/ 35 | 36 | 37 | 38 | #### IMPROVEMENTS: 39 | 40 | #### BUG FIXES: 41 | 42 | #### BREAKING CHANGES: 43 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How To Contribute 2 | 3 | We are always very happy to have contributions, whether for trivial cleanups or big new features. 4 | We want to have high quality, well documented codes for each programming language. 5 | 6 | Nor is code the only way to contribute to the project. We strongly value documentation, integration with other project, and gladly accept improvements for these aspects. 7 | 8 | ## Contributing code 9 | 10 | To submit a change for inclusion, please do the following: 11 | 12 | #### If the change is non-trivial please include some unit tests that cover the new functionality. 13 | #### If you are introducing a completely new feature or API it is a good idea to start a wiki and get consensus on the basic design first. 14 | #### It is our job to follow up on patches in a timely fashion. Nag us if we aren't doing our job (sometimes we drop things). 15 | 16 | ## Becoming a Committer 17 | 18 | We are always interested in adding new contributors. What we look for are series of contributions, good taste and ongoing interest in the project. If you are interested in becoming a committer, please let one of the existing committers know and they can help you walk through the process. 19 | 20 | Nowadays,we have several important contribution points: 21 | #### Wiki & JavaDoc 22 | #### Nacos Console 23 | #### Nacos SDK(C++\.Net\Php\Python\Go\Node.js) 24 | 25 | ##### Prerequisite 26 | If you want to contribute the above listing points, you must abide our some prerequisites: 27 | 28 | ###### Readability - API must have Javadoc,some very important methods also must have javadoc 29 | ###### Testability - 80% above unit test coverage about main process 30 | ###### Maintainability - Comply with our [PMD spec](style/codeStyle.xml), and at least 3 month update frequency 31 | ###### Deployability - We encourage you to deploy into [maven repository](http://search.maven.org/) 32 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Nacos 2 | Copyright 2018-2019 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Alibaba MiddleWare Group. 6 | 7 | ------ 8 | This product has a bundle Spring Boot: 9 | The Spring Boot Project 10 | ================= 11 | 12 | Please visit the Spring Boot web site for more information: 13 | 14 | * https://spring.io/projects/spring-boot 15 | 16 | Copyright 2014 The Spring Boot Project 17 | 18 | The Spring Boot Project licenses this file to you under the Apache License, 19 | version 2.0 (the "License"); you may not use this file except in compliance 20 | with the License. You may obtain a copy of the License at: 21 | 22 | http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | Unless required by applicable law or agreed to in writing, software 25 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 26 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 27 | License for the specific language governing permissions and limitations 28 | under the License. 29 | 30 | Also, please refer to each LICENSE..txt file, which is located in 31 | the 'license' directory of the distribution file, for the license terms of the 32 | components that this product depends on. -------------------------------------------------------------------------------- /REPORTING-BUGS.md: -------------------------------------------------------------------------------- 1 | # How to Reporting bugs 2 | 3 | If any part of the Nacos project has bugs or documentation mistakes, please let us know by [opening an issue][Nacos-issue]. We treat bugs and mistakes very seriously and believe no issue is too small, anyOne is implement. Before creating a bug report, please check that an issue reporting the same problem does not already exist. 4 | 5 | To make the bug report accurate and easy to understand, please try to create bug reports that are: 6 | 7 | - Specific. Include as much details as possible: which version, what environment, what configuration, etc. If the bug is related to running the Nacos server, please attach the Nacos log (the starting log with Nacos configuration is especially important). 8 | 9 | - Reproducible. Include the steps to reproduce the problem. We understand some issues might be hard to reproduce, please includes the steps that might lead to the problem. If possible, please attach the affected Nacos data dir and stack strace to the bug report. 10 | 11 | - Unique. Do not duplicate existing bug report. 12 | 13 | 14 | It may be worthwhile to read [Elika Etemad’s article on filing good bug reports][filing-good-bugs] before creating a bug report. 15 | 16 | We might ask for further information to locate a bug. A duplicated bug report will be closed. 17 | 18 | [etcd-issue]: https://github.com/etcd-io/etcd/issues/new 19 | [filing-good-bugs]: http://fantasai.inkedblade.net/style/talks/filing-good-bugs/ 20 | 21 | 22 | # 如何提交错误报告 23 | 24 | 如果Nacos项目的任何部分存在问题或文档问题,请通过[opening an issue][Nacos-issue]告诉我们。我们非常认真地对待错误和错误,在产品面前没有不重要的问题。不过在创建错误报告之前,请检查是否存在报告相同问题的issues。 25 | 26 | 为了使错误报告准确且易于理解,请尝试创建以下错误报告: 27 | 28 | - 具体到细节。包括尽可能多的细节:哪个版本,什么环境,什么配置等。如果错误与运行Nacos服务器有关,请附加Nacos日志(具有Nacos配置的起始日志尤为重要)。 29 | 30 | - 可复现。包括重现问题的步骤。我们理解某些问题可能难以重现,请包括可能导致问题的步骤。如果可能,请将受影响的Nacos数据目录和堆栈strace附加到错误报告中。 31 | 32 | - 不重复。不要复制现有的错误报告。 33 | 34 | 在创建错误报告之前,最好阅读下[Elika Etemad关于提交好错误报告的文章] [归档好错误],相信 会给你启发。 35 | 36 | 我们可能会要求您提供更多信息以查找错误。将关闭重复的错误报告。 37 | 38 | [etcd-issue]:https://github.com/etcd-io/etcd/issues/new 39 | [filing-good-bugs]:http://fantasai.inkedblade.net/style/talks/filing-good-bugs/ -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api; 17 | 18 | /** 19 | * properties key 20 | * @author Nacos 21 | * 22 | */ 23 | public class PropertyKeyConst { 24 | 25 | public final static String ENDPOINT = "endpoint"; 26 | public final static String NAMESPACE = "namespace"; 27 | public final static String ACCESS_KEY = "accessKey"; 28 | public final static String SECRET_KEY = "secretKey"; 29 | public final static String SERVER_ADDR = "serverAddr"; 30 | public final static String CONTEXT_PATH = "contextPath"; 31 | public final static String CLUSTER_NAME = "clusterName"; 32 | public final static String ENCODE = "encode"; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/annotation/NacosInjected.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.api.annotation; 18 | 19 | import com.alibaba.nacos.api.config.ConfigService; 20 | import com.alibaba.nacos.api.naming.NamingService; 21 | 22 | import java.lang.annotation.*; 23 | 24 | /** 25 | * An annotation to inject {@link ConfigService} or {@link NamingService} instance into the target Bean. 26 | * 27 | * @author Mercy 28 | * @see ConfigService 29 | * @see NamingService 30 | * @see NacosProperties 31 | * @since 0.2.1 32 | */ 33 | @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE}) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Documented 36 | public @interface NacosInjected { 37 | 38 | /** 39 | * The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties. 40 | * 41 | * @return the default value is {@link NacosProperties} 42 | */ 43 | NacosProperties properties() default @NacosProperties; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosIgnore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.api.config.annotation; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * An annotation for ignore field from annotated 23 | * {@link NacosConfigurationProperties} Properties Object. 24 | * 25 | * @author Mercy 26 | * @see NacosConfigurationProperties 27 | * @see NacosProperty 28 | * @since 0.2.0 29 | */ 30 | @Target({ElementType.FIELD}) 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Documented 33 | public @interface NacosIgnore { 34 | } 35 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.api.config.annotation; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * An annotation for Nacos Property name of Nacos Configuration to 23 | * bind a field from annotated {@link NacosConfigurationProperties} 24 | * Properties Object. 25 | * 26 | * @author Mercy 27 | * @see NacosConfigurationProperties 28 | * @see NacosIgnore 29 | * @since 0.2.0 30 | */ 31 | @Target({ElementType.FIELD}) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Documented 34 | public @interface NacosProperty { 35 | 36 | /** 37 | * The property name of Nacos Configuration to bind a field 38 | * 39 | * @return property name 40 | */ 41 | String value(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.api.config.annotation; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * Annotation which extends value to support auto-refresh 23 | * 24 | * @author hxy1991 25 | * @since 0.2.0 26 | */ 27 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Documented 30 | public @interface NacosValue { 31 | 32 | /** 33 | * The actual value expression: e.g. "#{systemProperties.myProp}". 34 | * 35 | * @return value expression 36 | */ 37 | String value(); 38 | 39 | /** 40 | * It indicates that the currently bound property is auto-refreshed when Nacos configuration is changed. 41 | * 42 | * @return default value is false 43 | */ 44 | boolean autoRefreshed() default false; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/convert/NacosConfigConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.api.config.convert; 18 | 19 | /** 20 | * Nacos Configuration content Converter 21 | * 22 | * @param the target type that wanted 23 | * @author Mercy 24 | * @since 0.2.0 25 | */ 26 | public interface NacosConfigConverter { 27 | 28 | /** 29 | * Can convert to be target type or not 30 | * 31 | * @param targetType the type of target 32 | * @return If can , return true, or false 33 | */ 34 | boolean canConvert(Class targetType); 35 | 36 | /** 37 | * Convert the Naocs's configuration of type S to target type T. 38 | * 39 | * @param config the Naocs's configuration to convert, which must be an instance of S (never {@code null}) 40 | * @return the converted object, which must be an instance of T (potentially {@code null}) 41 | */ 42 | T convert(String config); 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IConfigContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | 18 | /** 19 | * Config Context Interface 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface IConfigContext { 25 | /** 26 | * get context by key 27 | * 28 | * @param key 29 | * @return context 30 | */ 31 | public Object getParameter(String key); 32 | 33 | /** 34 | * set context 35 | * 36 | * @param key 37 | * key 38 | * @param value 39 | * value 40 | */ 41 | public void setParameter(String key, Object value); 42 | } 43 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IConfigFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | 18 | import com.alibaba.nacos.api.exception.NacosException; 19 | 20 | /** 21 | * Config Filter Interface 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public interface IConfigFilter { 27 | /** 28 | * Init Fuction 29 | * 30 | * @param filterConfig 31 | * Filter Config 32 | */ 33 | void init(IFilterConfig filterConfig); 34 | 35 | /** 36 | * do filter 37 | * 38 | * @param request 39 | * request 40 | * @param response 41 | * response 42 | * @param filterChain 43 | * filter Chain 44 | * @throws NacosException 45 | * exception 46 | */ 47 | void doFilter(IConfigRequest request, IConfigResponse response, IConfigFilterChain filterChain) 48 | throws NacosException; 49 | 50 | /** 51 | * deploy 52 | */ 53 | void deploy(); 54 | 55 | /** 56 | * order 57 | * 58 | * @return 59 | */ 60 | int getOrder(); 61 | 62 | /** 63 | * filterName 64 | * 65 | * @return 66 | */ 67 | String getFilterName(); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IConfigFilterChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | 18 | import com.alibaba.nacos.api.exception.NacosException; 19 | 20 | /** 21 | * Config Filter Chain Interface 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public interface IConfigFilterChain { 27 | /** 28 | * Filter aciton 29 | * 30 | * @param request 31 | * request 32 | * @param response 33 | * response 34 | * @throws NacosException 35 | * NacosException 36 | */ 37 | public void doFilter(IConfigRequest request, IConfigResponse response) throws NacosException; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IConfigRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | 18 | /** 19 | * Config Request Interface 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface IConfigRequest { 25 | /** 26 | * get param 27 | * 28 | * @param key 29 | * key 30 | * @return value 31 | */ 32 | public Object getParameter(String key); 33 | 34 | /** 35 | * get config context 36 | * 37 | * @return 38 | */ 39 | public IConfigContext getConfigContext(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IConfigResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | 18 | /** 19 | * Config Response Interface 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface IConfigResponse { 25 | /** 26 | * get param 27 | * 28 | * @param key 29 | * key 30 | * @return value 31 | */ 32 | public Object getParameter(String key); 33 | 34 | /** 35 | * get context 36 | * 37 | * @return configContext 38 | */ 39 | public IConfigContext getConfigContext(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/filter/IFilterConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.filter; 17 | /** 18 | * Filter Config Interface 19 | * @author Nacos 20 | * 21 | */ 22 | public interface IFilterConfig { 23 | 24 | /** 25 | * get filter name 26 | * 27 | * @return 28 | */ 29 | public String getFilterName(); 30 | 31 | /** 32 | * get param 33 | * 34 | * @param name 35 | * @return param 36 | */ 37 | public Object getInitParameter(String name); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/listener/AbstractListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.listener; 17 | 18 | import java.util.concurrent.Executor; 19 | 20 | /** 21 | * Listner Adapter,use default notify thread 22 | * 23 | * @author water.lyl 24 | * 25 | */ 26 | @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") 27 | public abstract class AbstractListener implements Listener { 28 | 29 | /** 30 | * use default Executor 31 | */ 32 | public Executor getExecutor() { 33 | return null; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/listener/AbstractSharedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.listener; 17 | 18 | import java.util.concurrent.Executor; 19 | 20 | /** 21 | * shared listener 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") 27 | public abstract class AbstractSharedListener implements Listener { 28 | private volatile String dataId; 29 | private volatile String group; 30 | 31 | final public void fillContext(String dataId, String group) { 32 | this.dataId = dataId; 33 | this.group = group; 34 | } 35 | 36 | @Override 37 | final public void receiveConfigInfo(String configInfo) { 38 | innerReceive(dataId, group, configInfo); 39 | } 40 | 41 | @Override 42 | public Executor getExecutor() { 43 | return null; 44 | } 45 | 46 | /** 47 | * receive 48 | * 49 | * @param dataId 50 | * data ID 51 | * @param group 52 | * group 53 | * @param configInfo 54 | * content 55 | */ 56 | public abstract void innerReceive(String dataId, String group, String configInfo); 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/config/listener/Listener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.config.listener; 17 | 18 | import java.util.concurrent.Executor; 19 | 20 | 21 | /** 22 | * Listener for watch config 23 | * 24 | * @author Nacos 25 | * 26 | */ 27 | public interface Listener { 28 | 29 | /** 30 | * Executor to excute this receive 31 | * 32 | * @return Executor 33 | */ 34 | public Executor getExecutor(); 35 | 36 | 37 | /** 38 | * 接收配置信息 39 | * 40 | * @param configInfo 配置值 41 | */ 42 | public void receiveConfigInfo(final String configInfo); 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/naming/NamingFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.naming; 17 | 18 | import java.lang.reflect.Constructor; 19 | import java.util.Properties; 20 | 21 | import com.alibaba.nacos.api.exception.NacosException; 22 | 23 | /** 24 | * @author dungu.zpf 25 | */ 26 | public class NamingFactory { 27 | 28 | public static NamingService createNamingService(String serverList) throws NacosException { 29 | try { 30 | Class driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService"); 31 | Constructor constructor = driverImplClass.getConstructor(String.class); 32 | NamingService vendorImpl = (NamingService) constructor.newInstance(serverList); 33 | return vendorImpl; 34 | } catch (Throwable e) { 35 | throw new NacosException(-400, e.getMessage()); 36 | } 37 | } 38 | 39 | public static NamingService createNamingService(Properties properties) throws NacosException { 40 | try { 41 | Class driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService"); 42 | Constructor constructor = driverImplClass.getConstructor(Properties.class); 43 | NamingService vendorImpl = (NamingService) constructor.newInstance(properties); 44 | return vendorImpl; 45 | } catch (Throwable e) { 46 | throw new NacosException(-400, e.getMessage()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/naming/listener/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.naming.listener; 17 | 18 | /** 19 | * event interface 20 | * @author dungu.zpf 21 | */ 22 | public interface Event { 23 | } 24 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/naming/listener/EventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.naming.listener; 17 | 18 | /** 19 | * event listener 20 | * @author Nacos 21 | * 22 | */ 23 | public interface EventListener { 24 | /** 25 | * callback event 26 | * @param event 27 | */ 28 | void onEvent(Event event); 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/naming/listener/NamingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.naming.listener; 17 | 18 | import java.util.List; 19 | 20 | import com.alibaba.nacos.api.naming.pojo.Instance; 21 | 22 | /** 23 | * @author dungu.zpf 24 | */ 25 | public class NamingEvent implements Event { 26 | 27 | private String serviceName; 28 | 29 | private List instances; 30 | 31 | public NamingEvent(String serviceName, List instances) { 32 | this.serviceName = serviceName; 33 | this.instances = instances; 34 | } 35 | 36 | public String getServiceName() { 37 | return serviceName; 38 | } 39 | 40 | public void setServiceName(String serviceName) { 41 | this.serviceName = serviceName; 42 | } 43 | 44 | public List getInstances() { 45 | return instances; 46 | } 47 | 48 | public void setInstances(List instances) { 49 | this.instances = instances; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/java/com/alibaba/nacos/api/naming/pojo/ListView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.api.naming.pojo; 17 | 18 | import com.alibaba.fastjson.JSON; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * @author dungu.zpf 24 | */ 25 | public class ListView { 26 | 27 | private List data; 28 | private int count; 29 | 30 | public List getData() { 31 | return data; 32 | } 33 | 34 | public void setData(List data) { 35 | this.data = data; 36 | } 37 | 38 | public int getCount() { 39 | return count; 40 | } 41 | 42 | public void setCount(int count) { 43 | this.count = count; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return JSON.toJSONString(this); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | version=${project.version} -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/config/filter/impl/ConfigContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.config.filter.impl; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import com.alibaba.nacos.api.config.filter.IConfigContext; 22 | 23 | /** 24 | * Config Context 25 | * 26 | * @author Nacos 27 | * 28 | */ 29 | public class ConfigContext implements IConfigContext { 30 | 31 | private Map param = new HashMap(); 32 | 33 | @Override 34 | public Object getParameter(String key) { 35 | return param.get(key); 36 | } 37 | 38 | @Override 39 | public void setParameter(String key, Object value) { 40 | param.put(key, value); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/config/impl/TimerService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.config.impl; 17 | 18 | import java.util.concurrent.Executors; 19 | import java.util.concurrent.ScheduledExecutorService; 20 | import java.util.concurrent.ScheduledFuture; 21 | import java.util.concurrent.ThreadFactory; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | 25 | /** 26 | * Time Service 27 | * @author Nacos 28 | * 29 | */ 30 | public class TimerService { 31 | 32 | static public ScheduledFuture scheduleWithFixedDelay(Runnable command, long initialDelay, 33 | long delay, TimeUnit unit) { 34 | return scheduledExecutor.scheduleWithFixedDelay(command, initialDelay, delay, unit); 35 | } 36 | 37 | @SuppressWarnings("PMD.ThreadPoolCreationRule") 38 | static ScheduledExecutorService scheduledExecutor = Executors 39 | .newSingleThreadScheduledExecutor(new ThreadFactory() { 40 | public Thread newThread(Runnable r) { 41 | Thread t = new Thread(r); 42 | t.setName("com.alibaba.nacos.client.Timer"); 43 | t.setDaemon(true); 44 | return t; 45 | } 46 | }); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/config/utils/JVMUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.config.utils; 17 | 18 | import com.alibaba.nacos.client.logger.Logger; 19 | 20 | /** 21 | * Get jvm config 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 27 | public class JVMUtil { 28 | 29 | /** 30 | * whether is multi instance 31 | * 32 | * @return whether multi 33 | */ 34 | public static Boolean isMultiInstance() { 35 | return isMultiInstance; 36 | } 37 | 38 | private static Boolean isMultiInstance = false; 39 | private static String TRUE = "true"; 40 | static final public Logger log = LogUtils.logger(JVMUtil.class); 41 | 42 | static { 43 | String multiDeploy = System.getProperty("isMultiInstance", "false"); 44 | if (TRUE.equals(multiDeploy)) { 45 | isMultiInstance = true; 46 | } 47 | log.info("isMultiInstance:{}", isMultiInstance); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/config/utils/SnapShotSwitch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.config.utils; 17 | 18 | import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor; 19 | 20 | /** 21 | * Snapshot switch 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public class SnapShotSwitch { 27 | 28 | /** 29 | * whether use local cache 30 | */ 31 | private static Boolean isSnapShot = true; 32 | 33 | public static Boolean getIsSnapShot() { 34 | return isSnapShot; 35 | } 36 | 37 | public static void setIsSnapShot(Boolean isSnapShot) { 38 | SnapShotSwitch.isSnapShot = isSnapShot; 39 | LocalConfigInfoProcessor.cleanAllSnapshot(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/config/utils/TenantUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.config.utils; 17 | 18 | import com.alibaba.nacos.client.utils.StringUtils; 19 | 20 | /** 21 | * Tenant Util 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public class TenantUtil { 27 | 28 | static String userTenant = ""; 29 | 30 | static { 31 | userTenant = System.getProperty("tenant.id", ""); 32 | if (StringUtils.isBlank(userTenant)) { 33 | userTenant = System.getProperty("acm.namespace", ""); 34 | } 35 | } 36 | 37 | public static String getUserTenant() { 38 | return userTenant; 39 | } 40 | 41 | public static void setUserTenant(String userTenant) { 42 | TenantUtil.userTenant = userTenant; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/identify/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.identify; 17 | 18 | /** 19 | * Identify Constants 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public class Constants { 25 | public static final String ACCESS_KEY = "accessKey"; 26 | 27 | public static final String SECRET_KEY = "secretKey"; 28 | 29 | public static final String PROPERTIES_FILENAME = "spas.properties"; 30 | 31 | public static final String CREDENTIAL_PATH = "/home/admin/.spas_key/"; 32 | 33 | public static final String CREDENTIAL_DEFAULT = "default"; 34 | 35 | public static final String DOCKER_CREDENTIAL_PATH = "/etc/instanceInfo"; 36 | 37 | public static final String DOCKER_ACCESS_KEY = "env_spas_accessKey"; 38 | 39 | public static final String DOCKER_SECRET_KEY = "env_spas_secretKey"; 40 | 41 | public static final String ENV_ACCESS_KEY = "spas_accessKey"; 42 | 43 | public static final String ENV_SECRET_KEY = "spas_secretKey"; 44 | 45 | public static final String NO_APP_NAME = ""; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/identify/CredentialListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.identify; 17 | 18 | /** 19 | * Credential Listener 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface CredentialListener { 25 | /** 26 | * update Credential 27 | */ 28 | public void onUpdateCredential(); 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/identify/SpasCredential.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.identify; 17 | 18 | /** 19 | * Spas Credential Interface 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface SpasCredential { 25 | /** 26 | * get AccessKey 27 | * 28 | * @return AccessKey 29 | */ 30 | public String getAccessKey(); 31 | 32 | /** 33 | * get SecretKey 34 | * 35 | * @return SecretKey 36 | */ 37 | public String getSecretKey(); 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/identify/SpasCredentialLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.identify; 17 | 18 | /** 19 | * Spas Credential Loader 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface SpasCredentialLoader { 25 | /** 26 | * get Credential 27 | * 28 | * @return Credential 29 | */ 30 | SpasCredential getCredential(); 31 | } 32 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/Level.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger; 17 | 18 | /** 19 | * 阿里中间件日志级别 20 | * 21 | * @author zhuyong 2014年3月20日 上午9:57:27 22 | */ 23 | public enum Level { 24 | /** 25 | * log level 26 | */ 27 | DEBUG("DEBUG"), INFO("INFO"), WARN("WARN"), ERROR("ERROR"), OFF("OFF"); 28 | 29 | private String name; 30 | 31 | Level(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getName() { 36 | return this.name; 37 | } 38 | 39 | public static Level codeOf(String level) { 40 | for (Level l : Level.values()) { 41 | if (l.name.equals(level)) { 42 | return l; 43 | } 44 | } 45 | 46 | return OFF; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/json/JSONAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.json; 17 | 18 | /** 19 | * Beans that support customized output of JSON text shall implement this interface. 20 | * @author FangYidong 21 | */ 22 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 23 | public interface JSONAware { 24 | /** 25 | * format change 26 | * 27 | * @return JSON text 28 | */ 29 | String toJSONString(); 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/json/JSONStreamAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.json; 17 | 18 | import java.io.IOException; 19 | import java.io.Writer; 20 | 21 | /** 22 | * Beans that support customized output of JSON text to a writer shall implement 23 | * this interface. 24 | * 25 | * @author FangYidong 26 | */ 27 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 28 | public interface JSONStreamAware { 29 | /** 30 | * write JSON string to out. 31 | * 32 | * @param out 33 | * out writer 34 | * @throws IOException 35 | * Exception 36 | */ 37 | void writeJSONString(Writer out) throws IOException; 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/json/parser/ContainerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.json.parser; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * Container factory for creating containers for JSON object and JSON array. 23 | * 24 | * @see com.alibaba.nacos.client.logger.json.parser.JSONParser#parse(java.io.Reader, ContainerFactory) 25 | * 26 | * @author FangYidong 27 | */ 28 | public interface ContainerFactory { 29 | /** 30 | * create json container 31 | * @return A Map instance to store JSON object, or null if you want to use com.alibaba.nacos.client.logger.jsonJSONObject. 32 | */ 33 | Map createObjectContainer(); 34 | 35 | /** 36 | * create array json container 37 | * @return A List instance to store JSON array, or null if you want to use com.alibaba.nacos.client.logger.jsonJSONArray. 38 | */ 39 | List creatArrayContainer(); 40 | } 41 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/log4j2/Log4j2LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.log4j2; 17 | 18 | import org.apache.logging.log4j.LogManager; 19 | 20 | import com.alibaba.nacos.client.logger.Logger; 21 | import com.alibaba.nacos.client.logger.nop.NopLogger; 22 | import com.alibaba.nacos.client.logger.support.ILoggerFactory; 23 | import com.alibaba.nacos.client.logger.support.LogLog; 24 | 25 | /** 26 | * Log4j2Logger Factory 27 | * @author Nacos 28 | * 29 | */ 30 | public class Log4j2LoggerFactory implements ILoggerFactory { 31 | 32 | public Log4j2LoggerFactory() throws ClassNotFoundException { 33 | Class.forName("org.apache.logging.log4j.core.Logger"); 34 | } 35 | 36 | @Override 37 | public Logger getLogger(Class clazz) { 38 | try { 39 | return new Log4j2Logger(LogManager.getLogger(clazz)); 40 | } catch (Throwable t) { 41 | LogLog.error("Failed to get Log4j2Logger", t); 42 | return new NopLogger(); 43 | } 44 | } 45 | 46 | @Override 47 | public Logger getLogger(String name) { 48 | try { 49 | return new Log4j2Logger(LogManager.getLogger(name)); 50 | } catch (Throwable t) { 51 | LogLog.error("Failed to get Log4j2Logger", t); 52 | return new NopLogger(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/nop/NopLoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.nop; 17 | 18 | import com.alibaba.nacos.client.logger.Logger; 19 | import com.alibaba.nacos.client.logger.support.ILoggerFactory; 20 | /** 21 | * NopLogger Factory 22 | * @author Nacos 23 | * 24 | */ 25 | public class NopLoggerFactory implements ILoggerFactory { 26 | 27 | @Override 28 | public Logger getLogger(Class clazz) { 29 | return new NopLogger(); 30 | } 31 | 32 | @Override 33 | public Logger getLogger(String name) { 34 | return new NopLogger(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/option/LogbackLoggerContextUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.option; 17 | 18 | import org.slf4j.ILoggerFactory; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import ch.qos.logback.classic.LoggerContext; 22 | import ch.qos.logback.core.LogbackException; 23 | /** 24 | * Logback Context Util 25 | * @author Nacos 26 | * 27 | */ 28 | public class LogbackLoggerContextUtil { 29 | 30 | private static LoggerContext loggerContext = null; 31 | 32 | public static LoggerContext getLoggerContext() { 33 | if (loggerContext == null) { 34 | ILoggerFactory lcObject = LoggerFactory.getILoggerFactory(); 35 | 36 | if (!(lcObject instanceof LoggerContext)) { 37 | throw new LogbackException( 38 | "Expected LOGBACK binding with SLF4J, but another log system has taken the place: " 39 | + lcObject.getClass().getSimpleName()); 40 | } 41 | 42 | loggerContext = (LoggerContext) lcObject; 43 | } 44 | 45 | return loggerContext; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/slf4j/Slf4jLoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.slf4j; 17 | 18 | 19 | import com.alibaba.nacos.client.logger.Logger; 20 | import com.alibaba.nacos.client.logger.nop.NopLogger; 21 | import com.alibaba.nacos.client.logger.support.ILoggerFactory; 22 | import com.alibaba.nacos.client.logger.support.LogLog; 23 | /** 24 | * Slf4jLogger Factory 25 | * @author Nacos 26 | * 27 | */ 28 | public class Slf4jLoggerFactory implements ILoggerFactory { 29 | 30 | public Slf4jLoggerFactory() throws ClassNotFoundException { 31 | Class.forName("org.slf4j.impl.StaticLoggerBinder"); 32 | } 33 | 34 | public Logger getLogger(String name) { 35 | try { 36 | return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(name)); 37 | } catch (Throwable t) { 38 | LogLog.error("Failed to get Slf4jLogger", t); 39 | return new NopLogger(); 40 | } 41 | } 42 | 43 | public Logger getLogger(Class clazz) { 44 | try { 45 | return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(clazz)); 46 | } catch (Throwable t) { 47 | LogLog.error("Failed to get Slf4jLogger", t); 48 | return new NopLogger(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/support/AppenderInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.support; 17 | 18 | import java.util.HashMap; 19 | 20 | /** 21 | * @author zhuyong on 2017/6/30. 22 | */ 23 | public class AppenderInfo extends HashMap { 24 | 25 | private static String name = "name"; 26 | private static String type = "type"; 27 | private static String file = "file"; 28 | 29 | public String getName() { 30 | return (String) get(AppenderInfo.name); 31 | } 32 | 33 | public void setName(String name) { 34 | put(AppenderInfo.name, name); 35 | } 36 | 37 | public void setType(String type) { 38 | put(AppenderInfo.type, type); 39 | } 40 | 41 | public void setFile(String file) { 42 | put(AppenderInfo.file, file); 43 | } 44 | 45 | public void withDetail(String name, Object value) { 46 | put(name, value); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/support/ErrorLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /* 17 | * Copyright 2014 Alibaba.com All right reserved. This software is the 18 | * confidential and proprietary information of Alibaba.com ("Confidential 19 | * Information"). You shall not disclose such Confidential Information and shall 20 | * use it only in accordance with the terms of the license agreement you entered 21 | * into with Alibaba.com. 22 | */ 23 | package com.alibaba.nacos.client.logger.support; 24 | 25 | /** 26 | * 兼容老的ErrorLog,后续请使用{@link LoggerHelper} 27 | * 28 | * @author zhuyong 2014年7月1日 上午11:41:22 29 | */ 30 | public class ErrorLog { 31 | 32 | public static String buildErrorMsg(String msg, String errorCode, String errorType) { 33 | return LoggerHelper.getErrorCodeStr(null, errorCode, errorType, msg); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/support/ILoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.support; 17 | 18 | import com.alibaba.nacos.client.logger.Logger; 19 | 20 | /** 21 | * logger factory interface 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public interface ILoggerFactory { 27 | /** 28 | * get logger 29 | * 30 | * @param clazz 31 | * class 32 | * @return logger 33 | */ 34 | Logger getLogger(Class clazz); 35 | 36 | /** 37 | * get logger 38 | * 39 | * @param name 40 | * logger name 41 | * @return logger 42 | */ 43 | Logger getLogger(String name); 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/support/LoggerInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.support; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | 21 | /** 22 | * @author zhuyong on 2017/06/29 23 | */ 24 | public class LoggerInfo extends HashMap { 25 | 26 | private static String level = "level"; 27 | private static String effectiveLevel = "effectiveLevel"; 28 | private static String additivity = "additivity"; 29 | private static String appenders = "appenders"; 30 | 31 | public LoggerInfo(String name, boolean additivity) { 32 | put(LoggerInfo.additivity, additivity); 33 | } 34 | 35 | public void setLevel(String level) { 36 | put(LoggerInfo.level, level); 37 | } 38 | 39 | public void setEffectiveLevel(String effectiveLevel) { 40 | put(LoggerInfo.effectiveLevel, effectiveLevel); 41 | } 42 | 43 | public String getLevel() { 44 | return (String) get(level); 45 | } 46 | 47 | public List getAppenders() { 48 | return (List) get(appenders); 49 | } 50 | 51 | public void setAppenders(List appenders) { 52 | put(LoggerInfo.appenders, appenders); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/logger/util/MessageUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.logger.util; 17 | /** 18 | * Error msg format 19 | * @author Nacos 20 | * 21 | */ 22 | public class MessageUtil { 23 | 24 | public static String formatMessage(String format, Object[] argArray) { 25 | FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); 26 | return ft.getMessage(); 27 | } 28 | 29 | public static String getMessage(String message) { 30 | return getMessage(null, message); 31 | } 32 | 33 | public static String getMessage(String context, String message) { 34 | return getMessage(context, null, message); 35 | } 36 | 37 | public static String getMessage(String context, String errorCode, String message) { 38 | if (context == null) { 39 | context = ""; 40 | } 41 | 42 | if (errorCode == null) { 43 | errorCode = ""; 44 | } 45 | return "[" + context + "] [] [" + errorCode + "] " + message; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/beat/BeatInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.beat; 17 | 18 | import com.alibaba.fastjson.JSON; 19 | 20 | /** 21 | * @author dungu.zpf 22 | */ 23 | public class BeatInfo { 24 | 25 | private int port; 26 | private String ip; 27 | private String dom; 28 | private String cluster; 29 | 30 | @Override 31 | public String toString() { 32 | return JSON.toJSONString(this); 33 | } 34 | 35 | public String getDom() { 36 | return dom; 37 | } 38 | 39 | public void setDom(String dom) { 40 | this.dom = dom; 41 | } 42 | 43 | public String getCluster() { 44 | return cluster; 45 | } 46 | 47 | public void setCluster(String cluster) { 48 | this.cluster = cluster; 49 | } 50 | 51 | public String getIp() { 52 | return ip; 53 | } 54 | 55 | public void setIp(String ip) { 56 | this.ip = ip; 57 | } 58 | 59 | public int getPort() { 60 | return port; 61 | } 62 | 63 | public void setPort(int port) { 64 | this.port = port; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/core/ProtectMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.core; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class ProtectMode { 22 | 23 | private float protectThreshold; 24 | 25 | public ProtectMode() { 26 | this.protectThreshold = 0.8F; 27 | } 28 | 29 | public float getProtectThreshold() { 30 | return protectThreshold; 31 | } 32 | 33 | public void setProtectThreshold(float protectThreshold) { 34 | this.protectThreshold = protectThreshold; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/utils/GenericPoller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.utils; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | /** 23 | * @author dungu.zpf 24 | */ 25 | public class GenericPoller implements Poller { 26 | 27 | private AtomicInteger index = new AtomicInteger(0); 28 | private List items = new ArrayList(); 29 | 30 | public GenericPoller(List items){ 31 | this.items = items; 32 | } 33 | 34 | public T next() { 35 | return items.get(Math.abs(index.getAndIncrement() % items.size())); 36 | } 37 | 38 | public Poller refresh(List items) { 39 | return new GenericPoller(items); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/utils/NetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.utils; 17 | 18 | import java.net.InetAddress; 19 | import java.net.UnknownHostException; 20 | 21 | /** 22 | * @author xuanyin.zy 23 | */ 24 | public class NetUtils { 25 | private static String LOCAL_IP; 26 | 27 | public static String localIP() { 28 | try { 29 | if (!StringUtils.isEmpty(LOCAL_IP)) { 30 | return LOCAL_IP; 31 | } 32 | 33 | String ip = System.getProperty("com.taobao.vipserver.localIP", InetAddress.getLocalHost().getHostAddress()); 34 | 35 | return LOCAL_IP = ip; 36 | } catch (UnknownHostException e) { 37 | return "resolve_failed"; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/utils/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.utils; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class Pair { 22 | 23 | private T item; 24 | private double weight; 25 | 26 | public Pair(T item,double weight){ 27 | this.item = item; 28 | this.weight = weight; 29 | } 30 | 31 | public T item(){ 32 | return item; 33 | } 34 | 35 | public double weight(){ 36 | return weight; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/utils/Poller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.utils; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author dungu.zpf 22 | */ 23 | public interface Poller { 24 | /** 25 | * Get next element selected by poller 26 | * 27 | * @return next element 28 | */ 29 | T next(); 30 | 31 | /** 32 | * Update items stored in poller 33 | * 34 | * @param items new item list 35 | * @return new poller instance 36 | */ 37 | Poller refresh(List items); 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/naming/utils/UtilAndComs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.naming.utils; 17 | 18 | /** 19 | * @author xuanyin.zy 20 | */ 21 | public class UtilAndComs { 22 | 23 | public static final String VERSION = "Nacos-Java-Client:v0.2.1"; 24 | 25 | public static final String ENCODING = "UTF-8"; 26 | 27 | public static final String ENV_LIST_KEY = "envList"; 28 | 29 | public static final String ALL_IPS = "000--00-ALL_IPS--00--000"; 30 | 31 | public static final String FAILOVER_SWITCH = "00-00---000-VIPSRV_FAILOVER_SWITCH-000---00-00"; 32 | 33 | public static final String NACOS_URL_BASE = "/nacos/v1/ns"; 34 | 35 | public static final String NACOS_URL_INSTANCE = NACOS_URL_BASE + "/instance"; 36 | 37 | public static final String DEFAULT_NAMESPACE_ID = "default"; 38 | 39 | public static final int REQUEST_DOMAIN_RETRY_COUNT = 3; 40 | 41 | public static final String DEFAULT_NAMING_ID = "default"; 42 | 43 | public static final String NACOS_NAMING_LOG_NAME = "com.alibaba.nacos.naming.log.filename"; 44 | 45 | public static final String NACOS_NAMING_LOG_LEVEL = "com.alibaba.nacos.naming.log.level"; 46 | 47 | public static final String SERVER_ADDR_IP_SPLITER = ":"; 48 | } 49 | -------------------------------------------------------------------------------- /client/src/main/java/com/alibaba/nacos/client/utils/IPUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client.utils; 17 | 18 | import java.util.regex.Matcher; 19 | import java.util.regex.Pattern; 20 | /** 21 | * ip tool 22 | * @author Nacos 23 | * 24 | */ 25 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 26 | public class IPUtil { 27 | 28 | public static boolean isIPV4(String addr) { 29 | if (null == addr) { 30 | return false; 31 | } 32 | String rexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$"; 33 | 34 | Pattern pat = Pattern.compile(rexp); 35 | 36 | Matcher mat = pat.matcher(addr); 37 | 38 | boolean ipAddress = mat.find(); 39 | return ipAddress; 40 | } 41 | 42 | public static boolean isIPV6(String addr) { 43 | if (null == addr) { 44 | return false; 45 | } 46 | String rexp = "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$"; 47 | 48 | Pattern pat = Pattern.compile(rexp); 49 | 50 | Matcher mat = pat.matcher(addr); 51 | 52 | boolean ipAddress = mat.find(); 53 | return ipAddress; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | version=${project.version} -------------------------------------------------------------------------------- /client/src/test/java/com/alibaba/nacos/client/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client; 17 | 18 | import junit.framework.Test; 19 | import junit.framework.TestCase; 20 | import junit.framework.TestSuite; 21 | 22 | /** 23 | * Unit test for simple App. 24 | */ 25 | public class AppTest 26 | extends TestCase 27 | { 28 | /** 29 | * Create the test case 30 | * 31 | * @param testName name of the test case 32 | */ 33 | public AppTest( String testName ) 34 | { 35 | super( testName ); 36 | } 37 | 38 | /** 39 | * @return the suite of tests being tested 40 | */ 41 | public static Test suite() 42 | { 43 | return new TestSuite( AppTest.class ); 44 | } 45 | 46 | /** 47 | * Rigourous Test :-) 48 | */ 49 | public void testApp() 50 | { 51 | assertTrue( true ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /client/src/test/java/com/alibaba/nacos/client/NamingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.client; 17 | 18 | import org.junit.Test; 19 | 20 | /** 21 | * @author dungu.zpf 22 | */ 23 | public class NamingTest { 24 | 25 | @Test 26 | public void testServiceList() { 27 | 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /common/license: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ -------------------------------------------------------------------------------- /common/src/main/java/com/alibaba/nacos/common/util/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.common.util; 18 | 19 | /** 20 | * Nacos common constants 21 | * 22 | * @author Mercy 23 | * @since 0.2.2 24 | */ 25 | public interface Constants { 26 | 27 | /** 28 | * Spring Profile : "standalone" 29 | */ 30 | String STANDALONE_SPRING_PROFILE = "standalone"; 31 | } 32 | -------------------------------------------------------------------------------- /common/src/main/java/com/alibaba/nacos/common/util/IoUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.common.util; 17 | 18 | import org.apache.commons.io.IOUtils; 19 | 20 | import java.io.*; 21 | import java.util.zip.GZIPInputStream; 22 | 23 | /** 24 | * IO related tool methods 25 | * 26 | * @author nacos 27 | */ 28 | public class IoUtils { 29 | 30 | public static byte[] tryDecompress(InputStream raw) throws Exception { 31 | 32 | try { 33 | GZIPInputStream gis 34 | = new GZIPInputStream(raw); 35 | ByteArrayOutputStream out 36 | = new ByteArrayOutputStream(); 37 | 38 | IOUtils.copy(gis, out); 39 | 40 | return out.toByteArray(); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | } 44 | 45 | return null; 46 | } 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /common/src/main/java/com/alibaba/nacos/common/util/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.common.util; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | 20 | /** 21 | * @author nacos 22 | */ 23 | public class Pair { 24 | private String key; 25 | private String value; 26 | 27 | public Pair(String key, String value) { 28 | this.key = key; 29 | this.value = value; 30 | } 31 | 32 | public Pair() { 33 | this(StringUtils.EMPTY, StringUtils.EMPTY); 34 | } 35 | 36 | public String getKey() { 37 | return key; 38 | } 39 | 40 | public void setKey(String key) { 41 | this.key = key; 42 | } 43 | 44 | public String getValue() { 45 | return value; 46 | } 47 | 48 | public void setValue(String value) { 49 | this.value = value; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /common/src/main/java/com/alibaba/nacos/common/util/UuidUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.common.util; 17 | 18 | import java.util.UUID; 19 | 20 | /** 21 | * @author dungu.zpf 22 | */ 23 | public class UuidUtil { 24 | 25 | public static String generateUuid() { 26 | return UUID.randomUUID().toString(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/src/test/java/com/alibaba/nacos/common/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.common; 17 | 18 | import junit.framework.Test; 19 | import junit.framework.TestCase; 20 | import junit.framework.TestSuite; 21 | 22 | /** 23 | * Unit test for simple App. 24 | */ 25 | public class AppTest 26 | extends TestCase 27 | { 28 | /** 29 | * Create the test case 30 | * 31 | * @param testName name of the test case 32 | */ 33 | public AppTest( String testName ) 34 | { 35 | super( testName ); 36 | } 37 | 38 | /** 39 | * @return the suite of tests being tested 40 | */ 41 | public static Test suite() 42 | { 43 | return new TestSuite( AppTest.class ); 44 | } 45 | 46 | /** 47 | * Rigourous Test :-) 48 | */ 49 | public void testApp() 50 | { 51 | assertTrue( true ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | import java.net.UnknownHostException; 22 | 23 | /** 24 | * Config main 25 | * 26 | * @author Nacos 27 | */ 28 | @SpringBootApplication 29 | public class Config { 30 | 31 | public static void main(String[] args) throws UnknownHostException { 32 | SpringApplication.run(Config.class, args); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/configuration/NacosConfigConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.config.server.configuration; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | /** 22 | * Nacos Config {@link Configuration} includes required Spring components. 23 | * 24 | * @author Mercy 25 | * @since 0.2.2 26 | */ 27 | @Configuration 28 | public class NacosConfigConfiguration { 29 | } 30 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/constant/CounterMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.constant; 17 | 18 | /** 19 | * counter mode 20 | * 21 | * @author hexu.hxy 22 | * @date 2018/3/13 23 | */ 24 | public enum CounterMode { 25 | /** 26 | * 增加 27 | */ 28 | INCREMENT, 29 | /** 30 | * 减少 31 | */ 32 | DECREMENT; 33 | 34 | public CounterMode reverse() { 35 | if (INCREMENT == this) { 36 | return DECREMENT; 37 | } 38 | return INCREMENT; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/manager/AbstractTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.manager; 17 | 18 | /** 19 | * task manage 20 | * 21 | * @author huali 22 | * 23 | */ 24 | public abstract class AbstractTask { 25 | /** 26 | * 一个任务两次处理的间隔,单位是毫秒 27 | */ 28 | private long taskInterval; 29 | 30 | /** 31 | * 任务上次被处理的时间,用毫秒表示 32 | */ 33 | private long lastProcessTime; 34 | /** 35 | * merge task 36 | * @param task task 37 | */ 38 | public abstract void merge(AbstractTask task); 39 | 40 | public void setTaskInterval(long interval){ 41 | this.taskInterval = interval; 42 | } 43 | 44 | public long getTaskInterval(){ 45 | return this.taskInterval; 46 | } 47 | 48 | public void setLastProcessTime(long lastProcessTime){ 49 | this.lastProcessTime = lastProcessTime; 50 | } 51 | 52 | public long getLastProcessTime(){ 53 | return this.lastProcessTime; 54 | } 55 | 56 | /** 57 | * TaskManager 判断当前是否需要处理这个Task,子类可以Override这个函数实现自己的逻辑 58 | * @return 59 | */ 60 | public boolean shouldProcess(){ 61 | return (System.currentTimeMillis() - this.lastProcessTime >= this.taskInterval); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/manager/TaskManagerMBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.manager; 17 | 18 | /** 19 | * tasks 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 25 | public interface TaskManagerMBean { 26 | 27 | /** 28 | * get task info 29 | * 30 | * @return info 31 | */ 32 | public String getTaskInfos(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/manager/TaskProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.manager; 17 | 18 | /** 19 | * task processor 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public interface TaskProcessor { 25 | /** 26 | * process task 27 | * 28 | * @param taskType 29 | * task type 30 | * @param task 31 | * task 32 | * @return process task result 33 | */ 34 | boolean process(String taskType, AbstractTask task); 35 | } 36 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/ACLInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * acl info 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 27 | public class ACLInfo { 28 | 29 | private Boolean isOpen; 30 | private List ips; 31 | 32 | public List getIps() { 33 | return ips; 34 | } 35 | 36 | public void setIps(List ips) { 37 | this.ips = ips; 38 | } 39 | 40 | public Boolean getIsOpen() { 41 | return isOpen; 42 | } 43 | 44 | public void setIsOpen(Boolean isOpen) { 45 | this.isOpen = isOpen; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/AuthType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | /** 19 | * auth type 20 | * 21 | * @author Nacos 22 | * 23 | */ 24 | public enum AuthType { 25 | /** 26 | * auth type 27 | */ 28 | GROUP, GROUP_DATAID, TENANT_GROUP, TENANT 29 | } 30 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/ConfigInfo4Beta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | /** 19 | * beta Info 20 | * @author Nacos 21 | * 22 | */ 23 | public class ConfigInfo4Beta extends ConfigInfo { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 296578467953931353L; 29 | 30 | private String betaIps; 31 | 32 | 33 | public ConfigInfo4Beta() { 34 | } 35 | 36 | public ConfigInfo4Beta(String dataId, String group, String appName, String content, String betaIps) { 37 | super(dataId, group, appName, content); 38 | this.betaIps = betaIps; 39 | } 40 | 41 | public String getBetaIps() { 42 | return betaIps; 43 | } 44 | 45 | public void setBetaIps(String betaIps) { 46 | this.betaIps = betaIps; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return super.hashCode(); 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) { 56 | return super.equals(obj); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/ConfigInfo4Tag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | /** 18 | * tag info 19 | * @author Nacos 20 | * 21 | */ 22 | public class ConfigInfo4Tag extends ConfigInfo { 23 | 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = 296578467953931353L; 28 | 29 | private String tag; 30 | 31 | 32 | public ConfigInfo4Tag() { 33 | } 34 | 35 | public ConfigInfo4Tag(String dataId, String group, String tag, String appName, String content) { 36 | super(dataId, group, appName, content); 37 | this.tag = tag; 38 | } 39 | 40 | public String getTag() { 41 | return tag; 42 | } 43 | 44 | public void setTag(String tag) { 45 | this.tag = tag; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return super.hashCode(); 51 | } 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | return super.equals(obj); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/ConfigInfoWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | /** 18 | * ConfigInfo Wrapper 19 | * @author Nacos 20 | * 21 | */ 22 | public class ConfigInfoWrapper extends ConfigInfo { 23 | private static final long serialVersionUID = 4511997359365712505L; 24 | 25 | private long lastModified; 26 | 27 | public ConfigInfoWrapper() { 28 | } 29 | 30 | public long getLastModified() { 31 | return lastModified; 32 | } 33 | 34 | public void setLastModified(long lastModified) { 35 | this.lastModified = lastModified; 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return super.hashCode(); 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | return super.equals(obj); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/ConfigKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * config key 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public class ConfigKey implements Serializable { 27 | 28 | /** 29 | * 30 | */ 31 | private static final long serialVersionUID = -1748953484511867580L; 32 | 33 | private String appName; 34 | private String dataId; 35 | private String group; 36 | 37 | public ConfigKey() { 38 | }; 39 | 40 | public ConfigKey(String appName, String dataId, String group) { 41 | this.appName = appName; 42 | this.dataId = dataId; 43 | this.group = group; 44 | } 45 | 46 | public String getAppName() { 47 | return appName; 48 | } 49 | 50 | public void setAppName(String appName) { 51 | this.appName = appName; 52 | } 53 | 54 | public String getDataId() { 55 | return dataId; 56 | } 57 | 58 | public void setDataId(String dataId) { 59 | this.dataId = dataId; 60 | } 61 | 62 | public String getGroup() { 63 | return group; 64 | } 65 | 66 | public void setGroup(String group) { 67 | this.group = group; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/GroupkeyListenserStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.Map; 20 | 21 | /** 22 | * litener status 23 | * 24 | * @author Nacos 25 | * 26 | */ 27 | public class GroupkeyListenserStatus implements Serializable{ 28 | 29 | /** 30 | * 随机数 31 | */ 32 | private static final long serialVersionUID = -2094829323598842474L; 33 | 34 | private int collectStatus; 35 | 36 | private Map lisentersGroupkeyStatus; 37 | 38 | public int getCollectStatus() { 39 | return collectStatus; 40 | } 41 | 42 | public void setCollectStatus(int collectStatus) { 43 | this.collectStatus = collectStatus; 44 | } 45 | 46 | public Map getLisentersGroupkeyStatus() { 47 | return lisentersGroupkeyStatus; 48 | } 49 | 50 | public void setLisentersGroupkeyStatus( 51 | Map lisentersGroupkeyStatus) { 52 | this.lisentersGroupkeyStatus = lisentersGroupkeyStatus; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/RestResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * rest result class 22 | * 23 | * @author Nacos 24 | * 25 | * @param data type 26 | */ 27 | 28 | public class RestResult implements Serializable { 29 | 30 | /** 31 | * 32 | */ 33 | private static final long serialVersionUID = 6095433538316185017L; 34 | 35 | private int code; 36 | private String message; 37 | private T data; 38 | 39 | public RestResult() { 40 | } 41 | 42 | public RestResult(int code, String message, T data) { 43 | this.code = code; 44 | this.setMessage(message); 45 | this.data = data; 46 | } 47 | 48 | public RestResult(int code, T data) { 49 | this.code = code; 50 | this.data = data; 51 | } 52 | 53 | public RestResult(int code, String message) { 54 | this.code = code; 55 | this.setMessage(message); 56 | } 57 | 58 | public int getCode() { 59 | return code; 60 | } 61 | 62 | public void setCode(int code) { 63 | this.code = code; 64 | } 65 | 66 | public String getMessage() { 67 | return message; 68 | } 69 | 70 | public void setMessage(String message) { 71 | this.message = message; 72 | } 73 | 74 | public T getData() { 75 | return data; 76 | } 77 | 78 | public void setData(T data) { 79 | this.data = data; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/SampleResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.Map; 20 | /** 21 | * sample result 22 | * @author Nacos 23 | * 24 | */ 25 | public class SampleResult implements Serializable{ 26 | 27 | /** 28 | * 随机数 29 | */ 30 | private static final long serialVersionUID = 2587823382317389453L; 31 | 32 | private Map lisentersGroupkeyStatus; 33 | 34 | public Map getLisentersGroupkeyStatus() { 35 | return lisentersGroupkeyStatus; 36 | } 37 | 38 | public void setLisentersGroupkeyStatus( 39 | Map lisentersGroupkeyStatus) { 40 | this.lisentersGroupkeyStatus = lisentersGroupkeyStatus; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/SubInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model; 17 | 18 | import java.sql.Timestamp; 19 | 20 | /** 21 | * sub 数据结构体 22 | * @author Nacos 23 | * 24 | */ 25 | public class SubInfo { 26 | 27 | private String appName; 28 | private String dataId; 29 | private String group; 30 | private String localIp; 31 | private Timestamp date; 32 | public String getAppName() { 33 | return appName; 34 | } 35 | public String getDataId() { 36 | return dataId; 37 | } 38 | public String getGroup() { 39 | return group; 40 | } 41 | public Timestamp getDate() { 42 | return new Timestamp(date.getTime()); 43 | } 44 | public void setAppName(String appName) { 45 | this.appName = appName; 46 | } 47 | public void setDataId(String dataId) { 48 | this.dataId = dataId; 49 | } 50 | public void setGroup(String group) { 51 | this.group = group; 52 | } 53 | public void setDate(Timestamp date) { 54 | this.date = new Timestamp(date.getTime()); 55 | } 56 | public String getLocalIp() { 57 | return localIp; 58 | } 59 | public void setLocalIp(String localIp) { 60 | this.localIp = localIp; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/app/ApplicationPublishRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model.app; 17 | /** 18 | * Application Publish Record 19 | * @author Nacos 20 | * 21 | */ 22 | public class ApplicationPublishRecord { 23 | 24 | private String appName; 25 | private GroupKey configInfo; 26 | 27 | public ApplicationPublishRecord(String appName, String dataId, String groupId){ 28 | this.appName = appName; 29 | this.configInfo = new GroupKey(dataId, groupId); 30 | } 31 | 32 | public String getAppName() { 33 | return appName; 34 | } 35 | 36 | public void setAppName(String appName) { 37 | this.appName = appName; 38 | } 39 | 40 | public GroupKey getConfigInfo() { 41 | return configInfo; 42 | } 43 | 44 | public void setConfigInfo(GroupKey configInfo) { 45 | this.configInfo = configInfo; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/app/GroupKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model.app; 17 | 18 | import com.alibaba.nacos.config.server.utils.GroupKey2; 19 | 20 | /** 21 | * config key util 22 | * 23 | * @author Nacos 24 | * 25 | */ 26 | public class GroupKey extends GroupKey2 { 27 | 28 | private String dataId; 29 | private String group; 30 | 31 | public GroupKey(String dataId, String group) { 32 | this.dataId = dataId; 33 | this.group = group; 34 | } 35 | 36 | public GroupKey(String groupKeyString) { 37 | String[] groupKeys = parseKey(groupKeyString); 38 | this.dataId = groupKeys[0]; 39 | this.group = groupKeys[1]; 40 | } 41 | 42 | public String getDataId() { 43 | return dataId; 44 | } 45 | 46 | public void setDataId(String dataId) { 47 | this.dataId = dataId; 48 | } 49 | 50 | public String getGroup() { 51 | return group; 52 | } 53 | 54 | public void setGroup(String group) { 55 | this.group = group; 56 | } 57 | 58 | public String toString() { 59 | return dataId + "+" + group; 60 | } 61 | 62 | 63 | public String getGroupkeyString() { 64 | return getKey(dataId, group); 65 | } 66 | 67 | //TODO : equal as we use Set 68 | 69 | } 70 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/capacity/GroupCapacity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model.capacity; 17 | 18 | /** 19 | * Group Capacity 20 | * @author hexu.hxy 21 | * @date 2018/3/13 22 | */ 23 | public class GroupCapacity extends Capacity { 24 | private String group; 25 | 26 | public String getGroup() { 27 | return group; 28 | } 29 | 30 | public void setGroup(String group) { 31 | this.group = group; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/model/capacity/TenantCapacity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.model.capacity; 17 | 18 | /** 19 | * Tenant Capacity 20 | * @author hexu.hxy 21 | * @date 2018/3/13 22 | */ 23 | public class TenantCapacity extends Capacity { 24 | private String tenant; 25 | 26 | public String getTenant() { 27 | return tenant; 28 | } 29 | 30 | public void setTenant(String tenant) { 31 | this.tenant = tenant; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/service/DataSourceService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.service; 17 | 18 | import org.springframework.jdbc.core.JdbcTemplate; 19 | import org.springframework.transaction.support.TransactionTemplate; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * datasource interface 25 | * 26 | * @author Nacos 27 | * 28 | */ 29 | public interface DataSourceService { 30 | /** 31 | * reload 32 | * 33 | * @throws IOException 34 | * exception 35 | */ 36 | void reload() throws IOException; 37 | 38 | /** 39 | * check master db 40 | * 41 | * @return is master 42 | */ 43 | boolean checkMasterWritable(); 44 | 45 | /** 46 | * get jdbc template 47 | * 48 | * @return JdbcTemplate 49 | */ 50 | JdbcTemplate getJdbcTemplate(); 51 | 52 | /** 53 | * get transaction template 54 | * 55 | * @return TransactionTemplate 56 | */ 57 | TransactionTemplate getTransactionTemplate(); 58 | 59 | /** 60 | * get current db url 61 | * 62 | * @return 63 | */ 64 | String getCurrentDBUrl(); 65 | 66 | /** 67 | * get heath 68 | * 69 | * @return heath info 70 | */ 71 | String getHealth(); 72 | } 73 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/service/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.service; 17 | 18 | import org.springframework.context.ApplicationContext; 19 | import org.springframework.context.ApplicationContextAware; 20 | import org.springframework.stereotype.Component; 21 | 22 | import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE; 23 | 24 | /** 25 | * datasource adapter 26 | * @author Nacos 27 | * 28 | */ 29 | @Component 30 | public class DynamicDataSource implements ApplicationContextAware { 31 | private ApplicationContext applicationContext; 32 | 33 | public void setApplicationContext(ApplicationContext applicationContext) { 34 | this.applicationContext = applicationContext; 35 | } 36 | 37 | public ApplicationContext getApplicationContext() { 38 | return applicationContext; 39 | } 40 | 41 | public DataSourceService getDataSource() { 42 | DataSourceService dataSourceService = null; 43 | 44 | if (STANDALONE_MODE) { 45 | dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService"); 46 | } else { 47 | dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService"); 48 | } 49 | 50 | return dataSourceService; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/service/LocalDataChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.service; 17 | 18 | import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 本地数据发生变更的事件。 24 | * @author Nacos 25 | */ 26 | public class LocalDataChangeEvent implements Event { 27 | final public String groupKey; 28 | final public boolean isBeta; 29 | final public List betaIps; 30 | final public String tag; 31 | 32 | 33 | public LocalDataChangeEvent(String groupKey) { 34 | this.groupKey = groupKey; 35 | this.isBeta = false; 36 | this.betaIps = null; 37 | this.tag = null; 38 | } 39 | 40 | public LocalDataChangeEvent(String groupKey, boolean isBeta, List betaIps) { 41 | this.groupKey = groupKey; 42 | this.isBeta = isBeta; 43 | this.betaIps = betaIps; 44 | this.tag = null; 45 | } 46 | 47 | public LocalDataChangeEvent(String groupKey, boolean isBeta, List betaIps, String tag) { 48 | this.groupKey = groupKey; 49 | this.isBeta = isBeta; 50 | this.betaIps = betaIps; 51 | this.tag = tag; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/service/TimerTaskService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.service; 17 | 18 | import java.util.concurrent.Executors; 19 | import java.util.concurrent.ScheduledExecutorService; 20 | import java.util.concurrent.ThreadFactory; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | 24 | 25 | /** 26 | * 定时任务服务 27 | * @author Nacos 28 | */ 29 | public class TimerTaskService { 30 | @SuppressWarnings("PMD.ThreadPoolCreationRule") 31 | private static ScheduledExecutorService scheduledExecutorService = Executors 32 | .newScheduledThreadPool(10, new ThreadFactory() { 33 | AtomicInteger count = new AtomicInteger(0); 34 | 35 | @Override 36 | public Thread newThread(Runnable r) { 37 | Thread t = new Thread(r); 38 | t.setDaemon(true); 39 | t.setName("com.alibaba.nacos.server.Timer-" + count.getAndIncrement()); 40 | return t; 41 | } 42 | }); 43 | 44 | static public void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, 45 | TimeUnit unit) { 46 | scheduledExecutorService.scheduleWithFixedDelay(command, initialDelay, delay, unit); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/AccumulateStatCount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import java.util.concurrent.atomic.AtomicLong; 19 | 20 | 21 | /** 22 | * Accumulate Stat Count 23 | * @author Nacos 24 | * 25 | */ 26 | public class AccumulateStatCount { 27 | 28 | final AtomicLong total = new AtomicLong(0); 29 | long lastStatValue = 0; 30 | 31 | 32 | public long increase() { 33 | return total.incrementAndGet(); 34 | } 35 | 36 | public long stat() { 37 | long tmp = total.get() - lastStatValue; 38 | lastStatValue += tmp; 39 | return tmp; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/IPUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import java.util.regex.Matcher; 19 | import java.util.regex.Pattern; 20 | /** 21 | * ip util 22 | * @author Nacos 23 | * 24 | */ 25 | @SuppressWarnings("PMD.ClassNamingShouldBeCamelRule") 26 | public class IPUtil { 27 | 28 | public static boolean isIPV4(String addr) { 29 | if (null == addr) { 30 | return false; 31 | } 32 | String rexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$"; 33 | 34 | Pattern pat = Pattern.compile(rexp); 35 | 36 | Matcher mat = pat.matcher(addr); 37 | 38 | boolean ipAddress = mat.find(); 39 | return ipAddress; 40 | } 41 | 42 | public static boolean isIPV6(String addr) { 43 | if (null == addr) { 44 | return false; 45 | } 46 | String rexp = "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$"; 47 | 48 | Pattern pat = Pattern.compile(rexp); 49 | 50 | Matcher mat = pat.matcher(addr); 51 | 52 | boolean ipAddress = mat.find(); 53 | return ipAddress; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/Protocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | /** 19 | * 用来处理协议相关的操作 20 | * 21 | * @author zhidao 22 | * @version 1.0 2011/05/03 23 | * 24 | */ 25 | public class Protocol { 26 | /** 27 | * 解析类于2.0.4(major.minor.bug-fix这样的版本为数字) 28 | * 29 | * @param version 30 | * @return 31 | */ 32 | public static int getVersionNumber(String version) { 33 | if (version == null) { 34 | return -1; 35 | } 36 | String[] vs = version.split("\\."); 37 | int sum = 0; 38 | for (int i = 0; i < vs.length; i++) { 39 | try { 40 | sum = sum * 10 + Integer.parseInt(vs[i]); 41 | } 42 | catch (Exception e) { 43 | // ignore 44 | } 45 | } 46 | return sum; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/RequestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | 20 | /** 21 | * Request util 22 | * @author Nacos 23 | * 24 | */ 25 | public class RequestUtil { 26 | 27 | public static final String CLIENT_APPNAME_HEADER = "Client-AppName"; 28 | 29 | public static String getRemoteIp(HttpServletRequest request) { 30 | String nginxHeader = request.getHeader("X-Real-IP"); 31 | return (nginxHeader == null) ? request.getRemoteAddr() : nginxHeader; 32 | } 33 | 34 | public static String getAppName(HttpServletRequest request) { 35 | return request.getHeader("Client-AppName"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/ResponseUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog; 22 | 23 | /** 24 | * write response 25 | * 26 | * @author Nacos 27 | * 28 | */ 29 | public class ResponseUtil { 30 | 31 | public static void writeErrMsg(HttpServletResponse response, int httpCode, 32 | String msg) { 33 | response.setStatus(httpCode); 34 | try { 35 | response.getWriter().println(msg); 36 | } catch (IOException e) { 37 | defaultLog.error("ResponseUtil:writeErrMsg wrong", e); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/SimpleCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import java.util.concurrent.ConcurrentHashMap; 19 | import java.util.concurrent.ConcurrentMap; 20 | 21 | 22 | /** 23 | * 一个带TTL的简单Cache,对于过期的entry没有清理 24 | * 25 | * @author fengHan, jiuRen 26 | * 27 | * @param 28 | */ 29 | public class SimpleCache { 30 | 31 | final ConcurrentMap> cache = new ConcurrentHashMap>(); 32 | 33 | private static class CacheEntry { 34 | final long expireTime; 35 | final E value; 36 | 37 | public CacheEntry(E value, long expire) { 38 | this.expireTime = expire; 39 | this.value = value; 40 | } 41 | } 42 | 43 | public void put(String key, E e, long ttlMs) { 44 | if (key == null || e == null) { 45 | return; 46 | } 47 | CacheEntry entry = new CacheEntry(e, System.currentTimeMillis() + ttlMs); 48 | cache.put(key, entry); 49 | } 50 | 51 | public E get(String key) { 52 | CacheEntry entry = cache.get(key); 53 | if (entry != null && entry.expireTime > System.currentTimeMillis()) { 54 | return entry.value; 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/SimpleReadWriteLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | 19 | /** 20 | * 最简单的读写锁实现。要求加锁和解锁必须成对调用。 21 | * @author Nacos 22 | * 23 | */ 24 | public class SimpleReadWriteLock { 25 | 26 | public synchronized boolean tryReadLock() { 27 | if (isWriteLocked()) { 28 | return false; 29 | } else { 30 | status++; 31 | return true; 32 | } 33 | } 34 | 35 | public synchronized void releaseReadLock() { 36 | status--; 37 | } 38 | 39 | public synchronized boolean tryWriteLock() { 40 | if (!isFree()) { 41 | return false; 42 | } else { 43 | status = -1; 44 | return true; 45 | } 46 | } 47 | 48 | public synchronized void releaseWriteLock() { 49 | status = 0; 50 | } 51 | 52 | private boolean isWriteLocked() { 53 | return status < 0; 54 | } 55 | private boolean isFree() { 56 | return status == 0; 57 | } 58 | 59 | /** 60 | * 零表示没有锁;负数表示加写锁;正数表示加读锁,数值表示读锁的个数。 61 | */ 62 | private int status = 0; 63 | } 64 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/SingletonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import java.util.concurrent.ConcurrentHashMap; 19 | 20 | 21 | /** 22 | * 避免多个相同内容的实例的工具类。比如,可以用来缓存客户端IP。 23 | * @author Nacos 24 | */ 25 | public class SingletonRepository { 26 | 27 | public SingletonRepository() { 28 | // 初始化大小2^16, 这个容器本身大概占用50k的内存,避免不停扩容 29 | shared = new ConcurrentHashMap(1 << 16); 30 | } 31 | 32 | public T getSingleton(T obj) { 33 | T previous = shared.putIfAbsent(obj, obj); 34 | return (null == previous) ? obj : previous; 35 | } 36 | 37 | public int size() { 38 | return shared.size(); 39 | } 40 | 41 | /** 42 | * 必须小心使用。 43 | * @param obj obj 44 | */ 45 | public void remove(Object obj) { 46 | shared.remove(obj); 47 | } 48 | 49 | private final ConcurrentHashMap shared; 50 | 51 | /** 52 | * DataId和Group的缓存。 53 | */ 54 | static public class DataIdGroupIdCache { 55 | static public String getSingleton(String str) { 56 | return cache.getSingleton(str); 57 | } 58 | 59 | static SingletonRepository cache = new SingletonRepository(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/StatConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | /** 19 | * Stat constant 20 | * @author Nacos 21 | * 22 | */ 23 | public class StatConstants { 24 | private StatConstants() { 25 | } 26 | 27 | public static final String APP_NAME = "nacos"; 28 | 29 | public static final String STAT_AVERAGE_HTTP_GET_OK = "AverageHttpGet_OK"; 30 | 31 | public static final String STAT_AVERAGE_HTTP_GET_NOT_MODIFIED = "AverageHttpGet_Not_Modified"; 32 | 33 | public static final String STAT_AVERAGE_HTTP_GET_OTHER = "AverageHttpGet_Other_Status"; 34 | 35 | public static final String STAT_AVERAGE_HTTP_POST_CHECK = "AverageHttpPost_Check"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/ThreadUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | /** 19 | * Thread util 20 | * @author Nacos 21 | * 22 | */ 23 | public class ThreadUtil { 24 | 25 | /** 26 | * 通过内核数,算出合适的线程数;1.5-2倍cpu内核数 27 | * @return thread count 28 | */ 29 | public static int getSuitableThreadCount() { 30 | final int coreCount = Runtime.getRuntime().availableProcessors(); 31 | int workerCount = 1; 32 | while (workerCount < coreCount * THREAD_MULTIPLER) { 33 | workerCount <<= 1; 34 | } 35 | return workerCount; 36 | } 37 | 38 | private final static int THREAD_MULTIPLER = 2; 39 | } 40 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/TimeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | 19 | import org.apache.commons.lang3.time.FastDateFormat; 20 | 21 | import java.sql.Timestamp; 22 | import java.util.Calendar; 23 | import java.util.Date; 24 | 25 | /** 26 | * Time util 27 | * 28 | * @author Nacos 29 | */ 30 | public class TimeUtils { 31 | 32 | public static Timestamp getCurrentTime() { 33 | Date date = new Date(); 34 | return new Timestamp(date.getTime()); 35 | } 36 | 37 | static public String getCurrentTimeStr() { 38 | Calendar c = Calendar.getInstance(); 39 | c.setTime(new Date()); 40 | FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); 41 | return format.format(c.getTime()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /config/src/main/java/com/alibaba/nacos/config/server/utils/TraceLogUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.config.server.utils; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | * Trace Util 23 | * @author Nacos 24 | * 25 | */ 26 | public class TraceLogUtil { 27 | /** 28 | * 记录server各个接口的请求记录 29 | */ 30 | public static Logger requestLog = LoggerFactory.getLogger("com.alibaba.nacos.config.request"); 31 | 32 | /** 33 | * 记录各个client的轮询请求记录 34 | */ 35 | public static Logger pollingLog = LoggerFactory.getLogger("com.alibaba.nacos.config.polling"); 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /config/src/main/resources/version/version.txt: -------------------------------------------------------------------------------- 1 | ${pom.version} -------------------------------------------------------------------------------- /config/src/test/resources/application.xml-bk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/nacos/8f7c743a0078a46d9228bd91d9e3fd28610d8823/config/src/test/resources/application.xml-bk -------------------------------------------------------------------------------- /config/src/test/resources/application.xml-test4derby: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/nacos/8f7c743a0078a46d9228bd91d9e3fd28610d8823/config/src/test/resources/application.xml-test4derby -------------------------------------------------------------------------------- /config/src/test/resources/jdbc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/nacos/8f7c743a0078a46d9228bd91d9e3fd28610d8823/config/src/test/resources/jdbc.properties -------------------------------------------------------------------------------- /config/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG, ServerDailyRollingFile,stdout 2 | log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender 3 | log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd_HH 4 | log4j.appender.ServerDailyRollingFile.File=${webapp.root}/WEB-INF/logs/nacos-server.log 5 | log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=[%p] [%t] %d{MM-dd HH:mm:ss,SSS} [%c{1}] - %m%n 7 | log4j.appender.ServerDailyRollingFile.Append=true 8 | 9 | log4j.logger.opLog=INFO, opFile 10 | log4j.appender.opFile=org.apache.log4j.DailyRollingFileAppender 11 | log4j.appender.opFile.DatePattern='.'yyyy-MM-dd_HH 12 | log4j.appender.opFile.File=${webapp.root}/WEB-INF/logs/operation.log 13 | log4j.appender.opFile.layout=org.apache.log4j.PatternLayout 14 | log4j.appender.opFile.layout.ConversionPattern=[%p] [%t] %d{MM-dd HH:mm:ss,SSS} [%c{1}] - %m%n 15 | log4j.appender.opFile.Append=true 16 | 17 | log4j.logger.com.taobao.config = warn 18 | log4j.logger.org.apache.http.wire=warn 19 | log4j.logger.java.sql = warn 20 | log4j.logger.com.ibatis.common.jdbc=warn -------------------------------------------------------------------------------- /config/src/test/resources/user.properties: -------------------------------------------------------------------------------- 1 | admin=admin -------------------------------------------------------------------------------- /console/src/main/java/com/alibaba/nacos/Nacos.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.nacos; 18 | 19 | import java.net.UnknownHostException; 20 | import org.springframework.boot.SpringApplication; 21 | import org.springframework.boot.autoconfigure.SpringBootApplication; 22 | import org.springframework.boot.web.servlet.ServletComponentScan; 23 | 24 | /** 25 | * @author nacos 26 | */ 27 | @SpringBootApplication(scanBasePackages = "com.alibaba.nacos") 28 | @ServletComponentScan 29 | public class Nacos { 30 | 31 | public static void main(String[] args) throws UnknownHostException { 32 | SpringApplication.run(Nacos.class, args); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /console/src/main/resources/META-INF/nacos-default.properties: -------------------------------------------------------------------------------- 1 | # Console Default Properties 2 | 3 | spring.mvc.view.prefix=/jsp/ 4 | # 响应页面默认后缀 5 | spring.mvc.view.suffix=.jsp 6 | spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration 7 | #logging.level.root=DEBUG 8 | 9 | # P0 key,For Debug. whether use address-server; true:use; false:not use;default:true 10 | useAddressServer=true 11 | 12 | # whether open interInterFaceFilter; true:open; false:close; if open, others can't call inner interface. default:false 13 | openInnerInterfaceFilter=false 14 | 15 | # quickStart stip dumpAll;only dump change config 16 | isQuickStart=false 17 | 18 | # server notify each otherd 19 | notifyConnectTimeout=200 20 | 21 | # server notify each other 22 | notifySocketTimeout=8000 23 | 24 | # whether health check 25 | isHealthCheck=true 26 | 27 | # health check max fail count 28 | maxHealthCheckFailCount=12 29 | 30 | # whether open spas; true:open; false:close 31 | OPEN_SPAS=true 32 | 33 | 34 | db.num=2 35 | db.url.0=jdbc:mysql://11.162.196.161:3306/diamond_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 36 | db.url.1=jdbc:mysql://11.163.152.91:3306/diamond_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 37 | db.user=diamond_devtest 38 | db.password=4b9622f3f70c7677835ac5a6719e7caf 39 | 40 | 41 | 42 | 43 | enableAccessControl=false 44 | 45 | -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/logback/nacos.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ${CONSOLE_LOG_PATTERN} 11 | utf8 12 | 13 | 14 | 15 | 17 | ${user.home}/nacos/logs/nacos.log 18 | true 19 | 20 | ${user.home}/nacos/logs/nacos.log.%d{yyyy-MM-dd}.%i 21 | 50MB 22 | 15 23 | 512MB 24 | true 25 | 26 | 27 | %date %level %msg%n%n 28 | GBK 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/nacos-default.properties: -------------------------------------------------------------------------------- 1 | # Nacos Default Properties 2 | 3 | ## Web Server 4 | server.port=8848 5 | server.tomcat.uri-encoding=UTF-8 6 | 7 | ## HTTP Encoding 8 | spring.http.encoding.force=true 9 | spring.http.encoding.enabled=true 10 | 11 | ## i18n 12 | spring.messages.encoding=UTF-8 13 | 14 | ## Exclude Spring Boot Auto-Configuration class(es) 15 | spring.autoconfigure.exclude=\ 16 | org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ 17 | org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # ApplicationListener 2 | org.springframework.context.ApplicationListener=\ 3 | com.alibaba.nacos.core.listener.StandaloneProfileApplicationListener 4 | 5 | # EnvironmentPostProcessor 6 | org.springframework.boot.env.EnvironmentPostProcessor=\ 7 | com.alibaba.nacos.core.env.NacosDefaultPropertySourceEnvironmentPostProcessor 8 | 9 | # SpringApplicationRunListener 10 | org.springframework.boot.SpringApplicationRunListener=\ 11 | com.alibaba.nacos.core.listener.LoggingSpringApplicationRunListener -------------------------------------------------------------------------------- /core/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 2 | ,--. 3 | ,--.'| 4 | ,--,: : | 5 | ,`--.'`| ' : ,---. 6 | | : : | | ' ,'\ .--.--. 7 | : | \ | : ,--.--. ,---. / / | / / ' 8 | | : ' '; | / \ / \. ; ,. :| : /`./ 9 | ' ' ;. ;.--. .-. | / / '' | |: :| : ;_ 10 | | | | \ | \__\/: . .. ' / ' | .; : \ \ `. 11 | ' : | ; .' ," .--.; |' ; :__| : | `----. \ 12 | | | '`--' / / ,. |' | '.'|\ \ / / /`--' / 13 | ' : | ; : .' \ : : `----' '--'. / 14 | ; |.' | , .-./\ \ / `--'---' 15 | '---' `--`---' `----' 16 | -------------------------------------------------------------------------------- /distribution/NOTICE-BIN: -------------------------------------------------------------------------------- 1 | Nacos 2 | Copyright 2018-2019 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Alibaba MiddleWare Group. 6 | 7 | ------ 8 | This product has a bundle netty: 9 | The Spring oot Project 10 | ================= 11 | 12 | Please visit the Netty web site for more information: 13 | 14 | * http://netty.io/ 15 | 16 | Copyright 2014 The Netty Project 17 | 18 | The Netty Project licenses this file to you under the Apache License, 19 | version 2.0 (the "License"); you may not use this file except in compliance 20 | with the License. You may obtain a copy of the License at: 21 | 22 | http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | Unless required by applicable law or agreed to in writing, software 25 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 26 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 27 | License for the specific language governing permissions and limitations 28 | under the License. 29 | 30 | Also, please refer to each LICENSE..txt file, which is located in 31 | the 'license' directory of the distribution file, for the license terms of the 32 | components that this product depends on. 33 | 34 | ------ 35 | This product has a bundle commons-lang, which includes software from the Spring Framework, 36 | under the Apache License 2.0 (see: StringUtils.containsWhitespace()) -------------------------------------------------------------------------------- /distribution/bin/shutdown.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | rem Licensed under the Apache License, Version 2.0 (the "License"); 4 | rem you may not use this file except in compliance with the License. 5 | rem You may obtain a copy of the License at 6 | rem 7 | rem http://www.apache.org/licenses/LICENSE-2.0 8 | rem 9 | rem Unless required by applicable law or agreed to in writing, software 10 | rem distributed under the License is distributed on an "AS IS" BASIS, 11 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | rem See the License for the specific language governing permissions and 13 | rem limitations under the License. 14 | if not exist "%JAVA_HOME%\bin\jps.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1 15 | 16 | setlocal 17 | 18 | set "PATH=%JAVA_HOME%\bin;%PATH%" 19 | 20 | echo killing nacos server 21 | 22 | for /f "tokens=1" %%i in ('jps -m ^| find "nacos"') do ( taskkill /F /PID %%i ) 23 | 24 | echo Done! 25 | -------------------------------------------------------------------------------- /distribution/bin/shutdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 1999-2018 Alibaba Group Holding Ltd. 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | pid=`ps ax | grep -i 'nacos' |grep java | grep -v grep | awk '{print $1}'` 17 | if [ -z "$pid" ] ; then 18 | echo "No nacosServer running." 19 | exit -1; 20 | fi 21 | 22 | echo "The nacosServer(${pid}) is running..." 23 | 24 | kill ${pid} 25 | 26 | echo "Send shutdown request to nacosServer(${pid}) OK" -------------------------------------------------------------------------------- /distribution/conf/application.properties: -------------------------------------------------------------------------------- 1 | # spring 2 | 3 | server.contextPath=/nacos 4 | server.servlet.contextPath=/nacos 5 | server.port=8848 6 | 7 | 8 | #db.num=2 9 | #db.url.0=jdbc:mysql://11.162.196.16:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 10 | #db.url.1=jdbc:mysql://11.163.152.9:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 11 | #db.user=nacos_devtest 12 | #db.password=youdontknow -------------------------------------------------------------------------------- /distribution/conf/application.properties.example: -------------------------------------------------------------------------------- 1 | # spring 2 | 3 | server.contextPath=/nacos 4 | server.servlet.contextPath=/nacos 5 | server.port=8848 6 | 7 | 8 | db.num=2 9 | db.url.0=jdbc:mysql://11.162.196.16:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 10 | db.url.1=jdbc:mysql://11.163.152.9:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 11 | db.user=nacos_devtest 12 | db.password=nacos -------------------------------------------------------------------------------- /distribution/conf/cluster.conf.example: -------------------------------------------------------------------------------- 1 | #it is ip 2 | #example 3 | 10.10.109.214 4 | 11.16.128.34 5 | 11.16.128.36 -------------------------------------------------------------------------------- /distribution/release-core.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | core 18 | false 19 | 20 | dir 21 | tar.gz 22 | zip 23 | 24 | 25 | 26 | ../ 27 | 28 | README.md 29 | 30 | 31 | 32 | 33 | 34 | conf/** 35 | 36 | 37 | 38 | 39 | 40 | bin/* 41 | 42 | 0755 43 | 44 | 45 | 46 | 47 | 48 | LICENSE-BIN 49 | LICENSE 50 | 51 | 52 | NOTICE-BIN 53 | NOTICE 54 | 55 | 56 | 57 | 58 | 59 | true 60 | 61 | com.alibaba.nacos:nacos-core 62 | 63 | 64 | lib/ 65 | false 66 | 67 | 68 | lib/ 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /distribution/release-nacos.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | server-${project.version} 18 | true 19 | 20 | dir 21 | tar.gz 22 | zip 23 | 24 | 25 | 26 | 27 | 28 | conf/** 29 | 30 | 31 | 32 | 33 | 34 | bin/* 35 | 36 | 0755 37 | 38 | 39 | 40 | 41 | LICENSE-BIN 42 | LICENSE 43 | 44 | 45 | NOTICE-BIN 46 | NOTICE 47 | 48 | 49 | 50 | ../console/target/nacos-server.jar 51 | /target/ 52 | 53 | 54 | 55 | 56 | 57 | true 58 | 59 | com.alibaba.nacos:nacos-console 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /doc/Nacos_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/nacos/8f7c743a0078a46d9228bd91d9e3fd28610d8823/doc/Nacos_Logo.png -------------------------------------------------------------------------------- /doc/arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/nacos/8f7c743a0078a46d9228bd91d9e3fd28610d8823/doc/arch.png -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 17 | 18 | 19 | com.alibaba.nacos 20 | nacos-all 21 | 0.2.2-SNAPSHOT 22 | ../pom.xml 23 | 24 | 25 | 4.0.0 26 | 27 | nacos-example 28 | jar 29 | 30 | nacos-example ${project.version} 31 | http://maven.apache.org 32 | 33 | 34 | UTF-8 35 | 36 | 37 | 38 | 39 | junit 40 | junit 41 | test 42 | 43 | 44 | ${project.groupId} 45 | nacos-common 46 | 47 | 48 | ${project.groupId} 49 | nacos-core 50 | 51 | 52 | com.alibaba.nacos 53 | nacos-client 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /example/src/main/java/com/alibaba/nacos/example/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.example; 17 | 18 | 19 | import java.util.Properties; 20 | 21 | import com.alibaba.nacos.api.exception.NacosException; 22 | import com.alibaba.nacos.api.naming.NamingFactory; 23 | import com.alibaba.nacos.api.naming.NamingService; 24 | 25 | /** 26 | * Hello world! 27 | * 28 | * @author xxc 29 | */ 30 | public class App { 31 | public static void main(String[] args) throws NacosException { 32 | Properties properties = new Properties(); 33 | properties.setProperty("serverAddr", "21.34.53.5:8848,21.34.53.6:8848"); 34 | properties.setProperty("namespace", "quickStart"); 35 | NamingService naming = NamingFactory.createNamingService(properties); 36 | naming.registerInstance("nacos.test.3", "11.11.11.11", 8888, "TEST1"); 37 | naming.registerInstance("nacos.test.3", "2.2.2.2", 9999, "DEFAULT"); 38 | System.out.println(naming.getAllInstances("nacos.test.3")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /example/src/test/java/com/alibaba/nacos/example/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.example; 17 | 18 | import junit.framework.Test; 19 | import junit.framework.TestCase; 20 | import junit.framework.TestSuite; 21 | 22 | /** 23 | * Unit test for simple App. 24 | */ 25 | public class AppTest 26 | extends TestCase 27 | { 28 | /** 29 | * Create the test case 30 | * 31 | * @param testName name of the test case 32 | */ 33 | public AppTest( String testName ) 34 | { 35 | super( testName ); 36 | } 37 | 38 | /** 39 | * @return the suite of tests being tested 40 | */ 41 | public static Test suite() 42 | { 43 | return new TestSuite( AppTest.class ); 44 | } 45 | 46 | /** 47 | * Rigourous Test :-) 48 | */ 49 | public void testApp() 50 | { 51 | assertTrue( true ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/NamingApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | /** 22 | * Hello world! 23 | * 24 | * @author xxc 25 | */ 26 | @SpringBootApplication 27 | public class NamingApp { 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(NamingApp.class, args); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.controllers; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class CatalogController { 22 | } 23 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.controllers; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class ClusterController { 22 | } 23 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/controllers/CmdbController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.controllers; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class CmdbController { 22 | } 23 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/controllers/HealthController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.controllers; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class HealthController { 22 | } 23 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.controllers; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class OperatorController { 22 | } 23 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/exception/ResponseExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.exception; 17 | 18 | import org.springframework.http.HttpStatus; 19 | import org.springframework.http.ResponseEntity; 20 | import org.springframework.web.bind.MissingServletRequestParameterException; 21 | import org.springframework.web.bind.annotation.ControllerAdvice; 22 | import org.springframework.web.bind.annotation.ExceptionHandler; 23 | 24 | /** 25 | * @author dungu.zpf 26 | */ 27 | @ControllerAdvice 28 | public class ResponseExceptionHandler { 29 | 30 | @ExceptionHandler(NacosException.class) 31 | private ResponseEntity handleNacosException(NacosException e) { 32 | return ResponseEntity.status(e.getErrorCode()).body(e.getMessage()); 33 | } 34 | 35 | @ExceptionHandler(IllegalArgumentException.class) 36 | public ResponseEntity handleParameterError(IllegalArgumentException ex) { 37 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage()); 38 | } 39 | 40 | @ExceptionHandler(MissingServletRequestParameterException.class) 41 | public ResponseEntity handleMissingParams(MissingServletRequestParameterException ex) { 42 | String name = ex.getParameterName(); 43 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Parameter '" + name + "' is missing"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.healthcheck; 17 | 18 | /** 19 | * Health check mode 20 | * 21 | * @author dungu.zpf 22 | */ 23 | public enum HealthCheckMode { 24 | /** 25 | * Health check sent from server. 26 | */ 27 | server, 28 | /** 29 | * Health check sent from client. 30 | */ 31 | client, 32 | /** 33 | * Health check disabled. 34 | */ 35 | none 36 | } 37 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckReactor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.healthcheck; 17 | 18 | import java.util.concurrent.*; 19 | 20 | /** 21 | * @author nacos 22 | */ 23 | public class HealthCheckReactor { 24 | private static final ScheduledExecutorService EXECUTOR = Executors 25 | .newScheduledThreadPool(Runtime.getRuntime().availableProcessors() / 2, new ThreadFactory() { 26 | @Override 27 | public Thread newThread(Runnable r) { 28 | Thread thread = new Thread(r); 29 | thread.setDaemon(true); 30 | thread.setName("com.alibaba.nacos.naming.health"); 31 | return thread; 32 | } 33 | }); 34 | 35 | public static ScheduledFuture scheduleCheck(HealthCheckTask task) { 36 | task.setStartTime(System.currentTimeMillis()); 37 | 38 | return EXECUTOR.schedule(task, task.getCheckRTNormalized(), TimeUnit.MILLISECONDS); 39 | } 40 | 41 | public static ScheduledFuture scheduleCheck(ClientBeatCheckTask task) { 42 | return EXECUTOR.schedule(task, 5000, TimeUnit.MILLISECONDS); 43 | } 44 | 45 | public static ScheduledFuture scheduleNow(Runnable task) { 46 | return EXECUTOR.schedule(task, 0, TimeUnit.MILLISECONDS); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.healthcheck; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public enum HealthCheckType { 22 | /** 23 | * TCP type 24 | */ 25 | TCP, 26 | /** 27 | * HTTP type 28 | */ 29 | HTTP, 30 | /** 31 | * MySQL type 32 | */ 33 | MYSQL 34 | } 35 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/misc/Loggers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.misc; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | * @author nacos 23 | */ 24 | public class Loggers { 25 | 26 | public static final Logger PUSH = LoggerFactory.getLogger("com.alibaba.nacos.naming.push"); 27 | 28 | public static final Logger CHECK_RT = LoggerFactory.getLogger("com.alibaba.nacos.naming.rt"); 29 | 30 | public static final Logger SRV_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.main"); 31 | 32 | public static final Logger EVT_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.event"); 33 | 34 | public static final Logger RAFT = LoggerFactory.getLogger("com.alibaba.nacos.naming.raft"); 35 | 36 | public static final Logger PERFORMANCE_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.performance"); 37 | 38 | public static final Logger ROLE_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.router"); 39 | 40 | public static final Logger DEBUG_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.debug"); 41 | 42 | public static final Logger TENANT = LoggerFactory.getLogger("com.alibaba.nacos.naming.tenant"); 43 | } 44 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/misc/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.misc; 17 | 18 | /** 19 | * @author nacos 20 | */ 21 | public class Message { 22 | public String getData() { 23 | return data; 24 | } 25 | 26 | public void setData(String data) { 27 | this.data = data; 28 | } 29 | 30 | private String data; 31 | } 32 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.misc; 17 | 18 | import com.alibaba.nacos.naming.boot.RunningConfig; 19 | 20 | import java.net.InetAddress; 21 | import java.net.UnknownHostException; 22 | 23 | /** 24 | * @author nacos 25 | */ 26 | public class NetUtils { 27 | 28 | public static String localIP() { 29 | try { 30 | return InetAddress.getLocalHost().getHostAddress() + ":" + RunningConfig.getServerPort(); 31 | } catch (UnknownHostException e) { 32 | return "resolve_failed"; 33 | } 34 | } 35 | 36 | public static String num2ip(int ip) { 37 | int[] b = new int[4]; 38 | String x = ""; 39 | 40 | b[0] = (int) ((ip >> 24) & 0xff); 41 | b[1] = (int) ((ip >> 16) & 0xff); 42 | b[2] = (int) ((ip >> 8) & 0xff); 43 | b[3] = (int) (ip & 0xff); 44 | x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]); 45 | 46 | return x; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/misc/Synchronizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.misc; 17 | 18 | /** 19 | * @author nacos 20 | */ 21 | public interface Synchronizer { 22 | /** 23 | * Send message to server 24 | * 25 | * @param serverIP target server address 26 | * @param msg message to send 27 | */ 28 | void send(String serverIP, Message msg); 29 | 30 | /** 31 | * Get message from server using message key 32 | * 33 | * @param serverIP source server address 34 | * @param key message key 35 | * @return message 36 | */ 37 | Message get(String serverIP, String key); 38 | } 39 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/push/DataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.push; 17 | 18 | /** 19 | * @author nacos 20 | */ 21 | public interface DataSource { 22 | /** 23 | * Get push data for a specified client 24 | * 25 | * @param client target client 26 | * @return data to push 27 | * @throws Exception 28 | */ 29 | String getData(PushService.PushClient client) throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/raft/Datum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.raft; 17 | 18 | /** 19 | * @author nacos 20 | */ 21 | public class Datum { 22 | public String key; 23 | 24 | public String value; 25 | 26 | public long timestamp; 27 | } 28 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/raft/RaftListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.raft; 17 | 18 | /** 19 | * @author nacos 20 | */ 21 | public interface RaftListener { 22 | 23 | /** 24 | * Determine if the listener was registered with this key 25 | * 26 | * @param key candidate key 27 | * @return true if the listener was registered with this key 28 | */ 29 | boolean interests(String key); 30 | 31 | /** 32 | * Determine if the listener is to be removed by matching the 'key' 33 | * 34 | * @param key key to match 35 | * @return true if match success 36 | */ 37 | boolean matchUnlistenKey(String key); 38 | 39 | /** 40 | * Action to do if data of target key has changed 41 | * 42 | * @param key target key 43 | * @param value data of the key 44 | * @throws Exception 45 | */ 46 | void onChange(String key, String value) throws Exception; 47 | 48 | /** 49 | * Action to do if data of target key has been removed 50 | * 51 | * @param key target key 52 | * @param value data of the key 53 | * @throws Exception 54 | */ 55 | void onDelete(String key, String value) throws Exception; 56 | } 57 | -------------------------------------------------------------------------------- /naming/src/main/java/com/alibaba/nacos/naming/web/NeedAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.web; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | /** 22 | * Innovated By: Xuanyin.zy 23 | */ 24 | public @Retention(RetentionPolicy.RUNTIME) @interface NeedAuth { 25 | } 26 | -------------------------------------------------------------------------------- /naming/src/test/java/com/alibaba/nacos/naming/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming; 17 | 18 | import com.alibaba.nacos.naming.core.DomainsManager; 19 | import com.alibaba.nacos.naming.misc.NetUtils; 20 | import com.alibaba.nacos.naming.raft.PeerSet; 21 | import com.alibaba.nacos.naming.raft.RaftCore; 22 | import com.alibaba.nacos.naming.raft.RaftPeer; 23 | import org.junit.Before; 24 | import org.mockito.Mock; 25 | import org.mockito.Mockito; 26 | import org.mockito.MockitoAnnotations; 27 | 28 | /** 29 | * @author dungu.zpf 30 | */ 31 | public class BaseTest { 32 | 33 | @Mock 34 | public DomainsManager domainsManager; 35 | 36 | @Mock 37 | public PeerSet peerSet; 38 | 39 | @Before 40 | public void before() { 41 | MockitoAnnotations.initMocks(this); 42 | 43 | RaftPeer peer = new RaftPeer(); 44 | peer.ip = NetUtils.localIP(); 45 | RaftCore.setPeerSet(peerSet); 46 | Mockito.when(peerSet.local()).thenReturn(peer); 47 | Mockito.when(peerSet.getLeader()).thenReturn(peer); 48 | Mockito.when(peerSet.isLeader(NetUtils.localIP())).thenReturn(true); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /naming/src/test/java/com/alibaba/nacos/naming/core/IpAddressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.core; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author dungu.zpf 24 | */ 25 | public class IpAddressTest { 26 | 27 | private IpAddress ipAddress; 28 | 29 | @Before 30 | public void before() { 31 | ipAddress = new IpAddress(); 32 | } 33 | 34 | @Test 35 | public void updateIp() { 36 | ipAddress.setIp("1.1.1.1"); 37 | ipAddress.setPort(1234); 38 | ipAddress.setWeight(5); 39 | 40 | Assert.assertEquals("1.1.1.1", ipAddress.getIp()); 41 | Assert.assertEquals(1234, ipAddress.getPort()); 42 | Assert.assertEquals(5, ipAddress.getWeight(), 0.001); 43 | } 44 | 45 | @Test 46 | public void fromJson() { 47 | ipAddress = IpAddress.fromJSON("2.2.2.2:8888_2_TEST1"); 48 | Assert.assertEquals("2.2.2.2", ipAddress.getIp()); 49 | Assert.assertEquals(8888, ipAddress.getPort()); 50 | Assert.assertEquals(2, ipAddress.getWeight(), 0.001); 51 | Assert.assertEquals("TEST1", ipAddress.getClusterName()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /naming/src/test/java/com/alibaba/nacos/naming/misc/SwitchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.misc; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author dungu.zpf 24 | */ 25 | public class SwitchTest { 26 | 27 | @Before 28 | public void before() { 29 | 30 | SwitchDomain domain = new SwitchDomain(); 31 | Switch.setDom(domain); 32 | } 33 | 34 | @Test 35 | public void udpateSwitch() { 36 | 37 | Switch.setCheckTimes(5); 38 | Assert.assertEquals(5, Switch.getCheckTimes()); 39 | 40 | Switch.setAdWeight("1.1.1.1", 20); 41 | Assert.assertEquals(20, Switch.getAdWeight("1.1.1.1").intValue()); 42 | 43 | Switch.setCacheMillis("nacos.domain.1", 5000); 44 | Assert.assertEquals(5000, Switch.getCacheMillis("nacos.domain.1")); 45 | 46 | Switch.setAllDomNameCache(false); 47 | Assert.assertTrue(!Switch.isAllDomNameCache()); 48 | 49 | Switch.setClientBeatInterval(1000L); 50 | Assert.assertEquals(1000L, Switch.getClientBeatInterval()); 51 | 52 | Switch.setDisableAddIP(true); 53 | Assert.assertTrue(Switch.getDisableAddIP()); 54 | 55 | Switch.setDistroEnabled(true); 56 | Assert.assertTrue(Switch.isDistroEnabled()); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /naming/src/test/java/com/alibaba/nacos/naming/misc/UtilsAndCommonsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.nacos.naming.misc; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.mock.env.MockEnvironment; 22 | 23 | import static com.alibaba.nacos.naming.misc.UtilsAndCommons.DEFAULT_NACOS_NAMING_CONTEXT; 24 | import static com.alibaba.nacos.naming.misc.UtilsAndCommons.NACOS_NAMING_CONTEXT; 25 | 26 | /** 27 | * {@link UtilsAndCommons} 28 | * 29 | * @author Mercy 30 | * @since 0.2.2 31 | */ 32 | public class UtilsAndCommonsTest { 33 | 34 | @Test 35 | public void testControllerPathsDefaultValues() { 36 | 37 | MockEnvironment environment = new MockEnvironment(); 38 | 39 | Assert.assertEquals(DEFAULT_NACOS_NAMING_CONTEXT, environment.resolvePlaceholders(NACOS_NAMING_CONTEXT)); 40 | 41 | 42 | Assert.assertEquals("/nacos/v1/ns", DEFAULT_NACOS_NAMING_CONTEXT); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /naming/src/test/java/com/alibaba/nacos/naming/raft/RaftStoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.naming.raft; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * @author dungu.zpf 23 | */ 24 | public class RaftStoreTest { 25 | 26 | @Test 27 | public void wrietDatum() throws Exception { 28 | 29 | Datum datum = new Datum(); 30 | datum.key = "1.2.3.4"; 31 | datum.value = "value1"; 32 | 33 | RaftStore.write(datum); 34 | 35 | RaftStore.load("1.2.3.4"); 36 | 37 | Datum result = RaftCore.getDatum("1.2.3.4"); 38 | 39 | Assert.assertNotNull(result); 40 | Assert.assertEquals("value1", result.value); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /style/codeStyle.md: -------------------------------------------------------------------------------- 1 | # Nacos 2 | 3 | ## Nacos Code Style 4 | Nacos code style Comply with Alibaba Java Coding Guidelines. 5 | 6 | Nacos的编码规范遵从于《阿里巴巴JAVA开发规约》。 7 | 8 | 9 | ## Guidelines 10 | [Alibaba-Java-Coding-Guidelines](https://alibaba.github.io/Alibaba-Java-Coding-Guidelines/) 11 | 12 | [阿里巴巴JAVA开发规约](https://github.com/alibaba/p3c/blob/master/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%EF%BC%88%E8%AF%A6%E5%B0%BD%E7%89%88%EF%BC%89.pdf) 13 | 14 | 15 | ## IDE Plugin Install(not necessary) 16 | 17 | *It is not necessary to install, if you want to find a problem when you are coding.* 18 | 19 | *不是必须安装,如果你需要在开发的时候实时发现问题的话,你需要安装。* 20 | 21 | ### idea IDE 22 | [p3c-idea-plugin-install](https://github.com/alibaba/p3c/blob/master/idea-plugin/README.md) 23 | 24 | [p3c插件idea IDE上安装方法](https://github.com/alibaba/p3c/blob/master/idea-plugin/README_cn.md) 25 | 26 | ### eclipse IDE 27 | [p3c-eclipse-plugin-install](https://github.com/alibaba/p3c/blob/master/eclipse-plugin/README.md) 28 | 29 | [p3c插件eclipse IDE上安装方法](https://github.com/alibaba/p3c/blob/master/eclipse-plugin/README_cn.md) 30 | 31 | ### Acknowledgement [Alibaba p3c](https://github.com/alibaba/p3c) -------------------------------------------------------------------------------- /test/src/test/java/com/alibaba/nacos/test/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.test; 17 | 18 | import junit.framework.Test; 19 | import junit.framework.TestCase; 20 | import junit.framework.TestSuite; 21 | 22 | /** 23 | * Unit test for simple App. 24 | */ 25 | public class AppTest 26 | extends TestCase 27 | { 28 | /** 29 | * Create the test case 30 | * 31 | * @param testName name of the test case 32 | */ 33 | public AppTest( String testName ) 34 | { 35 | super( testName ); 36 | } 37 | 38 | /** 39 | * @return the suite of tests being tested 40 | */ 41 | public static Test suite() 42 | { 43 | return new TestSuite( AppTest.class ); 44 | } 45 | 46 | /** 47 | * Rigourous Test :-) 48 | */ 49 | public void testApp() 50 | { 51 | assertTrue( true ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/src/test/java/com/alibaba/nacos/test/naming/Params.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.test.naming; 17 | 18 | import org.springframework.util.LinkedMultiValueMap; 19 | import org.springframework.util.MultiValueMap; 20 | 21 | /** 22 | * @author dungu.zpf 23 | */ 24 | public class Params { 25 | 26 | private MultiValueMap paramMap; 27 | 28 | public static Params newParams() { 29 | Params params = new Params(); 30 | params.paramMap = new LinkedMultiValueMap(); 31 | return params; 32 | } 33 | 34 | public Params appendParam(String name, String value) { 35 | this.paramMap.add(name, value); 36 | return this; 37 | } 38 | 39 | public MultiValueMap done() { 40 | return paramMap; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/src/test/java/com/alibaba/nacos/test/naming/Starter_ITCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.nacos.test.naming; 17 | 18 | /** 19 | * @author dungu.zpf 20 | */ 21 | public class Starter_ITCase { 22 | } 23 | -------------------------------------------------------------------------------- /test/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | # spring 2 | server.port=8848 3 | nacos.standalone=true -------------------------------------------------------------------------------- /test/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | --------------------------------------------------------------------------------