├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── formatter.xml ├── pom.xml ├── zebra-admin-web ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── dianping │ │ └── zebra │ │ └── administrator │ │ ├── GlobalConstants.java │ │ ├── config │ │ ├── ZooKeeperConnection.java │ │ └── ZookeeperService.java │ │ ├── controller │ │ ├── AbstractController.java │ │ ├── base │ │ │ └── HomeController.java │ │ ├── group │ │ │ └── JdbcrefController.java │ │ ├── shard │ │ │ └── ShardController.java │ │ └── zookeeperConfig │ │ │ └── ZookeeperConfigController.java │ │ ├── dao │ │ ├── JdbcrefMapper.java │ │ ├── ShardMapper.java │ │ └── ZookeeperConfigMapper.java │ │ ├── dto │ │ ├── ResultDto.java │ │ ├── ZKResponse.java │ │ ├── jdbcref │ │ │ ├── DBAddressDto.java │ │ │ ├── DBConfigInfoDto.java │ │ │ ├── DataSourceDetilDto.java │ │ │ ├── GroupConfigDto.java │ │ │ ├── JdbcrefConfigDto.java │ │ │ ├── JdbcrefDetilDto.java │ │ │ ├── JdbcrefDto.java │ │ │ └── JdbcrefOverviewDto.java │ │ ├── shard │ │ │ ├── ShardConfigDto.java │ │ │ ├── ShardDto.java │ │ │ ├── ShardOverviewDto.java │ │ │ └── TableShardConfigDto.java │ │ └── zookeeperConfig │ │ │ └── ZookeeperConfigDto.java │ │ ├── entity │ │ ├── DimensionConfig.java │ │ ├── DimensionConfigs.java │ │ ├── DsConfigEntity.java │ │ ├── GroupConfigEntity.java │ │ ├── JdbcrefEntity.java │ │ ├── ShardConfig.java │ │ ├── ShardEntity.java │ │ ├── SingleConfigEntity.java │ │ ├── TableShardConfig.java │ │ └── ZookeeperConfigEntity.java │ │ ├── exception │ │ ├── ZebraException.java │ │ └── ZebraRuntimeException.java │ │ ├── service │ │ ├── JdbcrefService.java │ │ ├── ShardService.java │ │ ├── ZookeeperConfigService.java │ │ └── impl │ │ │ ├── BaseServiceImpl.java │ │ │ ├── JdbcrefServiceImpl.java │ │ │ ├── ShardServiceImpl.java │ │ │ └── ZookeeperConfigServiceImpl.java │ │ └── util │ │ ├── JaxbUtils.java │ │ ├── JdbcUrlUtils.java │ │ └── ShardRuleUtils.java │ ├── resources │ ├── META-INF │ │ └── app.properties │ ├── config │ │ ├── spring │ │ │ └── local │ │ │ │ ├── appcontext-core.xml │ │ │ │ ├── appcontext-dao.xml │ │ │ │ └── appcontext-db.xml │ │ └── sqlmap │ │ │ ├── JdbcrefMapper.xml │ │ │ ├── ShardMapper.xml │ │ │ └── ZookeeperConfigMapper.xml │ └── log4j2.xml │ └── webapp │ ├── WEB-INF │ ├── springMVC-servlet.xml │ └── web.xml │ ├── app │ ├── .babelrc │ ├── .editorconfig │ ├── .gitignore │ ├── .postcssrc.js │ ├── README.md │ ├── build │ │ ├── build.js │ │ ├── check-versions.js │ │ ├── utils.js │ │ ├── vue-loader.conf.js │ │ ├── webpack.base.conf.js │ │ ├── webpack.dev.conf.js │ │ └── webpack.prod.conf.js │ ├── config │ │ ├── dev.env.js │ │ ├── index.js │ │ └── prod.env.js │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── App.vue │ │ ├── components │ │ │ ├── base │ │ │ │ ├── assist.js │ │ │ │ └── collapse-transition.js │ │ │ ├── icon │ │ │ │ └── icon.vue │ │ │ ├── modal │ │ │ │ └── mixins-scrollbar.js │ │ │ ├── select │ │ │ │ └── dropdown.vue │ │ │ └── submenu │ │ │ │ ├── mixin.js │ │ │ │ └── submenu.vue │ │ ├── js │ │ │ └── util.js │ │ ├── main.js │ │ ├── page │ │ │ ├── home │ │ │ │ └── home.vue │ │ │ ├── jdbcref │ │ │ │ ├── jdbcref.vue │ │ │ │ ├── jdbcrefConfigForm.vue │ │ │ │ ├── jdbcrefInfo.vue │ │ │ │ ├── jdbcrefMenu.vue │ │ │ │ └── jdbcrefOverview.vue │ │ │ ├── shard │ │ │ │ ├── shard.vue │ │ │ │ ├── shardInfo.vue │ │ │ │ └── shardOverview.vue │ │ │ ├── side.vue │ │ │ ├── top.vue │ │ │ └── zebraconfig │ │ │ │ └── envConfig.vue │ │ └── router │ │ │ └── route.js │ └── static │ │ ├── bootstrap │ │ └── dist │ │ │ ├── css │ │ │ └── bootstrap.min.css │ │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ └── js │ │ │ └── bootstrap.min.js │ │ ├── css │ │ └── mystyle.css │ │ ├── font-awesome │ │ ├── css │ │ │ ├── font-awesome.css │ │ │ └── font-awesome.min.css │ │ └── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ └── fontawesome-webfont.woff2 │ │ ├── image │ │ ├── background.png │ │ ├── background1.png │ │ ├── depview.png │ │ ├── zebra-20181109.png │ │ ├── zebra-dal.png │ │ └── zebra-nav.png │ │ └── jquery │ │ └── dist │ │ └── jquery.min.js │ └── pack │ ├── index.html │ └── static │ ├── bootstrap │ └── dist │ │ ├── css │ │ └── bootstrap.min.css │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ │ └── js │ │ └── bootstrap.min.js │ ├── css │ ├── app.1860438f36ce029ed659db72387c6dd7.css │ ├── app.1860438f36ce029ed659db72387c6dd7.css.map │ └── mystyle.css │ ├── font-awesome │ ├── css │ │ ├── font-awesome.css │ │ └── font-awesome.min.css │ └── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ └── fontawesome-webfont.woff2 │ ├── fonts │ ├── ionicons.05acfdb.woff │ ├── ionicons.24712f6.ttf │ └── ionicons.2c2ae06.eot │ ├── image │ ├── background.png │ ├── background1.png │ ├── depview.png │ ├── zebra-20181109.png │ ├── zebra-dal.png │ └── zebra-nav.png │ ├── img │ └── ionicons.621bd38.svg │ ├── jquery │ └── dist │ │ └── jquery.min.js │ └── js │ ├── app.42aa6a7ea30d253328e7.js │ ├── app.42aa6a7ea30d253328e7.js.map │ ├── manifest.fdb8a97301ced9d7d749.js │ ├── manifest.fdb8a97301ced9d7d749.js.map │ ├── vendor.c1764846c6267a38d817.js │ └── vendor.c1764846c6267a38d817.js.map ├── zebra-cat-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dianping │ │ │ └── zebra │ │ │ └── monitor │ │ │ ├── Version.java │ │ │ ├── filter │ │ │ └── CatFilter.java │ │ │ ├── monitor │ │ │ ├── GroupDataSourceMonitor.java │ │ │ └── SingleDataSourceMonitor.java │ │ │ └── util │ │ │ ├── Reflects.java │ │ │ ├── SqlMonitorUtils.java │ │ │ └── Stringizers.java │ └── resources │ │ └── META-INF │ │ └── zebra-filter.properties │ └── test │ ├── java │ └── com │ │ └── dianping │ │ └── zebra │ │ └── monitor │ │ ├── filter │ │ └── CatFilterTest.java │ │ └── monitor │ │ ├── GroupDataSourceMonitorTest.java │ │ └── SingleDataSourceMonitorTest.java │ └── resources │ ├── META-INF │ ├── app.properties │ └── zebra-filter.properties │ ├── app.properties │ ├── region │ ├── center.json │ └── idc.json │ ├── sample.ds.v2.properties │ ├── sample.ds.v3.properties │ └── zebra.system.properties ├── zebra-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dianping │ │ │ └── zebra │ │ │ ├── Constants.java │ │ │ ├── annotation │ │ │ └── Internal.java │ │ │ ├── config │ │ │ ├── ConfigService.java │ │ │ ├── ConfigServiceFactory.java │ │ │ ├── ExtensionLoader.java │ │ │ ├── LionKey.java │ │ │ ├── PropertyConfigService.java │ │ │ ├── RemoteConfigService.java │ │ │ ├── Scope.java │ │ │ ├── ServiceConfigBuilder.java │ │ │ ├── Spi.java │ │ │ └── ZookeeperConfigService.java │ │ │ ├── exception │ │ │ ├── ZebraConfigException.java │ │ │ └── ZebraException.java │ │ │ ├── filter │ │ │ ├── DefaultFilterManager.java │ │ │ ├── DefaultJdbcFilter.java │ │ │ ├── DefaultJdbcFilterChain.java │ │ │ ├── FilterManager.java │ │ │ ├── FilterManagerFactory.java │ │ │ ├── JdbcFilter.java │ │ │ ├── JdbcOperationCallback.java │ │ │ ├── SQLProcessContext.java │ │ │ └── wall │ │ │ │ └── WallFilter.java │ │ │ ├── group │ │ │ ├── config │ │ │ │ ├── AbstractConfigManager.java │ │ │ │ ├── AdvancedPropertyChangeEvent.java │ │ │ │ ├── DataSourceConfigManager.java │ │ │ │ ├── DataSourceConfigManagerFactory.java │ │ │ │ ├── DataSourceConfigRefresh.java │ │ │ │ ├── DefaultDataSourceConfigManager.java │ │ │ │ ├── DefaultSystemConfigManager.java │ │ │ │ ├── HidePasswordVisitor.java │ │ │ │ ├── ReadOrWriteRole.java │ │ │ │ ├── SystemConfigManager.java │ │ │ │ ├── SystemConfigManagerFactory.java │ │ │ │ ├── datasource │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── IEntity.java │ │ │ │ │ ├── IVisitor.java │ │ │ │ │ ├── entity │ │ │ │ │ │ ├── Any.java │ │ │ │ │ │ ├── DataSourceConfig.java │ │ │ │ │ │ ├── GroupConfig.java │ │ │ │ │ │ ├── GroupDataSourceConfig.java │ │ │ │ │ │ ├── SingleConfig.java │ │ │ │ │ │ └── SingleDataSourceConfig.java │ │ │ │ │ └── transform │ │ │ │ │ │ ├── BaseVisitor.java │ │ │ │ │ │ ├── DefaultLinker.java │ │ │ │ │ │ ├── DefaultMerger.java │ │ │ │ │ │ ├── DefaultSaxMaker.java │ │ │ │ │ │ ├── DefaultSaxParser.java │ │ │ │ │ │ ├── DefaultXmlBuilder.java │ │ │ │ │ │ ├── ILinker.java │ │ │ │ │ │ ├── IMaker.java │ │ │ │ │ │ └── IParser.java │ │ │ │ └── system │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── IEntity.java │ │ │ │ │ ├── IVisitor.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── SqlFlowControl.java │ │ │ │ │ └── SystemConfig.java │ │ │ │ │ └── transform │ │ │ │ │ ├── DefaultLinker.java │ │ │ │ │ ├── DefaultSaxMaker.java │ │ │ │ │ ├── DefaultSaxParser.java │ │ │ │ │ ├── DefaultXmlBuilder.java │ │ │ │ │ ├── ILinker.java │ │ │ │ │ ├── IMaker.java │ │ │ │ │ └── IParser.java │ │ │ ├── datasources │ │ │ │ ├── FailOverDataSource.java │ │ │ │ └── LoadBalancedDataSource.java │ │ │ ├── exception │ │ │ │ ├── MasterDsNotFoundException.java │ │ │ │ ├── SlaveDsDisConnectedException.java │ │ │ │ ├── WeakReferenceGCException.java │ │ │ │ └── sorter │ │ │ │ │ ├── ExceptionSorter.java │ │ │ │ │ └── MySqlExceptionSorter.java │ │ │ ├── jdbc │ │ │ │ ├── GroupConnection.java │ │ │ │ ├── GroupDataSource.java │ │ │ │ ├── GroupPreparedStatement.java │ │ │ │ ├── GroupResultSet.java │ │ │ │ ├── GroupStatement.java │ │ │ │ └── param │ │ │ │ │ ├── ArrayParamContext.java │ │ │ │ │ ├── AsciiParamContext.java │ │ │ │ │ ├── BigDecimalParamContext.java │ │ │ │ │ ├── BinaryStreamParamContext.java │ │ │ │ │ ├── BlobParamContext.java │ │ │ │ │ ├── BooleanParamContext.java │ │ │ │ │ ├── ByteArrayParamContext.java │ │ │ │ │ ├── ByteParamContext.java │ │ │ │ │ ├── CharacterStreamParamContext.java │ │ │ │ │ ├── ClobParamContext.java │ │ │ │ │ ├── DateParamContext.java │ │ │ │ │ ├── DoubleParamContext.java │ │ │ │ │ ├── FloatParamContext.java │ │ │ │ │ ├── IntParamContext.java │ │ │ │ │ ├── LongParamContext.java │ │ │ │ │ ├── NCharacterStreamParamContext.java │ │ │ │ │ ├── NClobParamContext.java │ │ │ │ │ ├── NStringParamContext.java │ │ │ │ │ ├── NullParamContext.java │ │ │ │ │ ├── ObjectParamContext.java │ │ │ │ │ ├── ParamContext.java │ │ │ │ │ ├── RefParamContext.java │ │ │ │ │ ├── RowIdParamContext.java │ │ │ │ │ ├── SQLXMLParamContext.java │ │ │ │ │ ├── ShortParamContext.java │ │ │ │ │ ├── StringParamContext.java │ │ │ │ │ ├── TimeParamContext.java │ │ │ │ │ ├── TimestampParamContext.java │ │ │ │ │ ├── URLParamContext.java │ │ │ │ │ └── UnicodeStreamParamContext.java │ │ │ ├── monitor │ │ │ │ ├── GroupDataSourceMBean.java │ │ │ │ └── SingleDataSourceMBean.java │ │ │ ├── router │ │ │ │ ├── BackupDataSourceRouter.java │ │ │ │ ├── CenterAwareRouter.java │ │ │ │ ├── DataSourceRouter.java │ │ │ │ ├── IdcAwareRouter.java │ │ │ │ ├── LocalContextReadWriteStrategy.java │ │ │ │ ├── ReadWriteStrategy.java │ │ │ │ ├── ReadWriteStrategyWrapper.java │ │ │ │ ├── RegionAwareRouter.java │ │ │ │ ├── RouterContext.java │ │ │ │ ├── RouterTarget.java │ │ │ │ ├── RouterType.java │ │ │ │ ├── WeightDataSourceRouter.java │ │ │ │ ├── ZebraForceMasterHelper.java │ │ │ │ └── region │ │ │ │ │ ├── AbstractZebraRegionManager.java │ │ │ │ │ ├── LocalRegionManager.java │ │ │ │ │ ├── RemoteRegionManager.java │ │ │ │ │ ├── TrieNode.java │ │ │ │ │ ├── ZebraRegionManager.java │ │ │ │ │ └── ZebraRegionManagerLoader.java │ │ │ └── util │ │ │ │ ├── DaoContextHolder.java │ │ │ │ ├── DataSourceState.java │ │ │ │ ├── SmoothReload.java │ │ │ │ └── SqlAliasManager.java │ │ │ ├── log │ │ │ ├── EmptyLogger.java │ │ │ ├── Log4j2Logger.java │ │ │ ├── Log4jLogger.java │ │ │ ├── Logger.java │ │ │ ├── LoggerFactory.java │ │ │ ├── LoggerLoader.java │ │ │ ├── Resources.java │ │ │ ├── SimpleLogger.java │ │ │ ├── Slf4jLogger.java │ │ │ └── ZebraRolloverStrategy.java │ │ │ ├── shard │ │ │ ├── api │ │ │ │ └── ShardDataSourceHelper.java │ │ │ ├── config │ │ │ │ ├── ExceptionalDimensionConfig.java │ │ │ │ ├── RouterRuleConfig.java │ │ │ │ ├── ShardDataSourceCustomConfig.java │ │ │ │ ├── TableShardDimensionConfig.java │ │ │ │ └── TableShardRuleConfig.java │ │ │ ├── exception │ │ │ │ ├── ShardBatchInsertException.java │ │ │ │ ├── ShardIdGenException.java │ │ │ │ ├── ShardParseException.java │ │ │ │ └── ShardRouterException.java │ │ │ ├── idgen │ │ │ │ ├── IdGenerator.java │ │ │ │ ├── IdRange.java │ │ │ │ ├── IdTimeService.java │ │ │ │ └── impl │ │ │ │ │ ├── DefaultIdTimeService.java │ │ │ │ │ ├── MySqlIdGenerator.java │ │ │ │ │ └── SnowFlakeIdGenerator.java │ │ │ ├── jdbc │ │ │ │ ├── DataSourceRepository.java │ │ │ │ ├── ShardConnection.java │ │ │ │ ├── ShardDataSource.java │ │ │ │ ├── ShardDataSourceConfigAdapter.java │ │ │ │ ├── ShardDatabaseMetaData.java │ │ │ │ ├── ShardPreparedStatement.java │ │ │ │ ├── ShardResultSet.java │ │ │ │ ├── ShardStatement.java │ │ │ │ ├── parallel │ │ │ │ │ ├── PreparedStatementExecuteQueryCallable.java │ │ │ │ │ ├── PreparedStatementExecuteUpdateCallable.java │ │ │ │ │ ├── SQLThreadPoolExecutor.java │ │ │ │ │ ├── StatementExecuteQueryCallable.java │ │ │ │ │ ├── StatementExecuteUpdateCallable.java │ │ │ │ │ ├── TaskExecuteResult.java │ │ │ │ │ └── UpdateResult.java │ │ │ │ └── unsupport │ │ │ │ │ ├── UnsupportedShardConnection.java │ │ │ │ │ ├── UnsupportedShardPreparedStatement.java │ │ │ │ │ ├── UnsupportedShardResultSet.java │ │ │ │ │ └── UnsupportedShardStatement.java │ │ │ ├── merge │ │ │ │ ├── ColumnData.java │ │ │ │ ├── DataMerger.java │ │ │ │ ├── MergeContext.java │ │ │ │ ├── RowData.java │ │ │ │ ├── ShardResultSetAdaptor.java │ │ │ │ ├── ShardResultSetMerger.java │ │ │ │ ├── distinct │ │ │ │ │ └── DistinctDataMerger.java │ │ │ │ ├── groupby │ │ │ │ │ ├── Aggregator.java │ │ │ │ │ ├── GroupByDataMerger.java │ │ │ │ │ ├── MultiKey.java │ │ │ │ │ └── aggregate │ │ │ │ │ │ ├── AggregateException.java │ │ │ │ │ │ ├── CountAggregator.java │ │ │ │ │ │ ├── MaxAggregator.java │ │ │ │ │ │ ├── MinAggregator.java │ │ │ │ │ │ └── SumAggregator.java │ │ │ │ └── orderby │ │ │ │ │ └── OrderByDataMerger.java │ │ │ ├── parser │ │ │ │ ├── DefaultSQLRewrite.java │ │ │ │ ├── MultiSQLParsedResult.java │ │ │ │ ├── SQLHint.java │ │ │ │ ├── SQLInExprWrapper.java │ │ │ │ ├── SQLParsedResult.java │ │ │ │ ├── SQLParser.java │ │ │ │ ├── SQLRewrite.java │ │ │ │ ├── SQLRewriteInParam.java │ │ │ │ ├── ShardLimitSqlSplitRewrite.java │ │ │ │ ├── ShardLimitSqlWithConditionRewrite.java │ │ │ │ ├── SqlToCountSqlRewrite.java │ │ │ │ └── visitor │ │ │ │ │ ├── AbstractMySQLASTVisitor.java │ │ │ │ │ ├── MySQLDeleteASTVisitor.java │ │ │ │ │ ├── MySQLInsertASTVisitor.java │ │ │ │ │ ├── MySQLReplaceASTVisitor.java │ │ │ │ │ ├── MySQLSelectASTVisitor.java │ │ │ │ │ └── MySQLUpdateASTVisitor.java │ │ │ ├── resultset │ │ │ │ ├── Blob.java │ │ │ │ └── Clob.java │ │ │ ├── router │ │ │ │ ├── DefaultShardRouter.java │ │ │ │ ├── RouterBuilder.java │ │ │ │ ├── RouterContext.java │ │ │ │ ├── RouterResult.java │ │ │ │ ├── ShardRouter.java │ │ │ │ ├── builder │ │ │ │ │ ├── AbstractRouterBuilder.java │ │ │ │ │ ├── RemoteRouterBuilder.java │ │ │ │ │ ├── XmlDataSourceRouterConfigLoader.java │ │ │ │ │ └── XmlResourceRouterBuilder.java │ │ │ │ └── rule │ │ │ │ │ ├── RouterRule.java │ │ │ │ │ ├── ShardEvalContext.java │ │ │ │ │ ├── ShardEvalResult.java │ │ │ │ │ ├── ShardRange.java │ │ │ │ │ ├── TableShardRule.java │ │ │ │ │ ├── dimension │ │ │ │ │ ├── AbstractDimensionRule.java │ │ │ │ │ ├── DefaultDimensionRule.java │ │ │ │ │ ├── DimensionRule.java │ │ │ │ │ └── ExceptionalDimensionRule.java │ │ │ │ │ ├── engine │ │ │ │ │ ├── GroovyRuleEngine.java │ │ │ │ │ ├── RuleEngine.java │ │ │ │ │ └── RuleEngineBase.java │ │ │ │ │ └── tableset │ │ │ │ │ ├── DefaultTableSetsManager.java │ │ │ │ │ ├── TableSets.java │ │ │ │ │ └── TableSetsManager.java │ │ │ └── util │ │ │ │ ├── IdDecorator.java │ │ │ │ ├── LRUCache.java │ │ │ │ ├── ShardColumnValueUtil.java │ │ │ │ ├── ShardDateParseUtil.java │ │ │ │ └── ShardRuleParser.java │ │ │ ├── single │ │ │ ├── jdbc │ │ │ │ ├── AbstractDataSource.java │ │ │ │ ├── C3p0DataSourceAdapter.java │ │ │ │ ├── C3p0SingleDataSource.java │ │ │ │ ├── CountPunisher.java │ │ │ │ ├── DataSourceLifeCycle.java │ │ │ │ ├── Dbcp2SingleDataSource.java │ │ │ │ ├── DbcpSingleDataSource.java │ │ │ │ ├── DruidSingleDataSource.java │ │ │ │ ├── HiKariCPSingleDataSource.java │ │ │ │ ├── SingleConnection.java │ │ │ │ ├── SingleDataSource.java │ │ │ │ ├── SinglePreparedStatement.java │ │ │ │ ├── SingleResultSet.java │ │ │ │ ├── SingleStatement.java │ │ │ │ └── TomcatJdbcSingleDataSource.java │ │ │ ├── manager │ │ │ │ ├── DefaultSingleDataSourceManager.java │ │ │ │ ├── SingleDataSourceManager.java │ │ │ │ └── SingleDataSourceManagerFactory.java │ │ │ └── pool │ │ │ │ ├── AbstractDataSourcePool.java │ │ │ │ ├── C3p0DataSourcePool.java │ │ │ │ ├── DataSourcePool.java │ │ │ │ ├── DataSourcePoolFactory.java │ │ │ │ ├── Dbcp2DataSourcePool.java │ │ │ │ ├── DbcpDataSourcePool.java │ │ │ │ ├── DruidDataSourcePool.java │ │ │ │ ├── HikariCPDataSourcePool.java │ │ │ │ └── TomcatJdbcDataSourcePool.java │ │ │ └── util │ │ │ ├── AppPropertiesUtils.java │ │ │ ├── FileUtils.java │ │ │ ├── JDBCUtils.java │ │ │ ├── JaxbUtils.java │ │ │ ├── JdbcDriverClassHelper.java │ │ │ ├── NetworkUtils.java │ │ │ ├── Splitters.java │ │ │ ├── SqlType.java │ │ │ ├── SqlUtils.java │ │ │ ├── StringUtils.java │ │ │ └── json │ │ │ ├── JsonArray.java │ │ │ ├── JsonObject.java │ │ │ └── JsonTokener.java │ └── resources │ │ ├── META-INF │ │ ├── services │ │ │ ├── com.dianping.zebra.config.ConfigService │ │ │ └── com.dianping.zebra.group.router.ReadWriteStrategy │ │ └── zebra-filter.properties │ │ ├── zebra_log4j.xml │ │ └── zebra_log4j2.xml │ └── test │ ├── java │ └── com │ │ └── dianping │ │ └── zebra │ │ ├── config │ │ └── LocalConfigServiceTest.java │ │ ├── filter │ │ ├── DefaultFilterManagerTest.java │ │ ├── FilterChainTest.java │ │ ├── MockFilterHelper.java │ │ ├── mock │ │ │ └── FinalSqlTest.java │ │ └── wall │ │ │ ├── SqlFlowIdGenerator.java │ │ │ └── WallFilterTest.java │ │ ├── group │ │ ├── AllTests.java │ │ ├── config │ │ │ ├── ConfigManagerTest.java │ │ │ ├── DataSourceConfigManagerTest.java │ │ │ ├── HidePasswordVisitorTest.java │ │ │ ├── SystemConfigManagerTest.java │ │ │ └── SystemConfigTest.java │ │ ├── datasources │ │ │ ├── FailoverDataSourceTest.java │ │ │ └── LoadBalancedDataSourceTest.java │ │ ├── exception │ │ │ └── DalStatusExtensionTest.java │ │ ├── jdbc │ │ │ ├── CatLoggerTest.java │ │ │ ├── DPGroupConnectionTestCase.java │ │ │ ├── DPGroupPreparedStatementTest.java │ │ │ ├── DPGroupStatementTest.java │ │ │ ├── DataSourceEntry.java │ │ │ ├── GroupDataSourceC3P0FieldTest.java │ │ │ ├── GroupDataSourceTest.java │ │ │ ├── H2DatabaseTestCase.java │ │ │ ├── InnerSingleDatabaseTestCase.java │ │ │ ├── LockTest.java │ │ │ └── MultiDatabaseTestCase.java │ │ ├── performance │ │ │ ├── C3p0Case.java │ │ │ ├── PerformanceTest.java │ │ │ ├── TestRunner.java │ │ │ ├── ZebraBaseCase.java │ │ │ └── ZebraCase.java │ │ ├── router │ │ │ ├── CenterAwareRouterTest.java │ │ │ ├── CustomizedReadWriteStrategyWrapperTest.java │ │ │ ├── GroupDataSourceRouterTest.java │ │ │ ├── IdcAwareRouterTest.java │ │ │ ├── LocalContextReadWriteStrategyTest.java │ │ │ ├── ReadWriteStrategyServiceLoaderTest.java │ │ │ ├── RegionAwareRouterTest.java │ │ │ └── region │ │ │ │ └── LocalRegionManagerTest.java │ │ └── util │ │ │ ├── AppPropertiesUtilsTest.java │ │ │ ├── SmoothReloadTest.java │ │ │ └── SqlUtilsTest.java │ │ ├── shard │ │ ├── AllTests.java │ │ ├── config │ │ │ └── XmlDataSourceRouterConfigLoaderTest.java │ │ ├── jdbc │ │ │ ├── MultiDBLifeCycleTest.java │ │ │ ├── MultiDBPreparedStatementLifeCycleGroupTest.java │ │ │ ├── MultiDBPreparedStatementLifeCycleJoinTest.java │ │ │ ├── MultiDBPreparedStatementLifeCycleLimitTest.java │ │ │ ├── MultiDBPreparedStatementLifeCycleOrderbyTest.java │ │ │ ├── MultiDBPreparedStatementLifeCycleTest.java │ │ │ ├── MultiShardKeyRepeatTest.java │ │ │ ├── MultiShardKeyTest.java │ │ │ ├── ResultSetTest.java │ │ │ ├── ShardConcurrencyTest.java │ │ │ ├── ShardConnectionTest.java │ │ │ ├── ShardDataSourceTest.java │ │ │ ├── ShardDefaultStrategyTest.java │ │ │ ├── ShardPreparedStatementMultiKeyTest.java │ │ │ ├── ShardPreparedStatementTest.java │ │ │ ├── ShardRangeCrossTest.java │ │ │ ├── ShardRangeDefaultTest.java │ │ │ ├── ShardReplaceTest.java │ │ │ ├── ShardStatementTest.java │ │ │ ├── ShardSupportedCaseTest.java │ │ │ ├── SingleDBLifeCycleTest.java │ │ │ ├── SingleDBPreparedStatementGroupFollowNoteIntegrationTest.java │ │ │ ├── SingleDBPreparedStatementLifeCycleTest.java │ │ │ ├── SpecialSQLTest.java │ │ │ ├── base │ │ │ │ ├── BaseTestCase.java │ │ │ │ ├── DBDataEntry.java │ │ │ │ ├── MockDataSource.java │ │ │ │ ├── MultiCreateTableScriptEntry.java │ │ │ │ ├── MultiDBBaseTestCase.java │ │ │ │ ├── SingleCreateTableScriptEntry.java │ │ │ │ └── SingleDBBaseTestCase.java │ │ │ ├── merge │ │ │ │ ├── DistinctTest.java │ │ │ │ └── LimitTest.java │ │ │ ├── parallel │ │ │ │ ├── MockCallable.java │ │ │ │ ├── ParallelPerformanceTest.java │ │ │ │ ├── ParallelPerformanceTest2.java │ │ │ │ └── SQLThreadPoolExecutorTest.java │ │ │ └── specification │ │ │ │ ├── ConnectionTest.java │ │ │ │ ├── DataSourceTest.java │ │ │ │ └── StatementTest.java │ │ ├── parser │ │ │ ├── SQLHintTest.java │ │ │ ├── SQLParserResultTest.java │ │ │ └── SQLRewriteTest.java │ │ ├── router │ │ │ ├── DataSourceRouterImplTest.java │ │ │ ├── XmlDataSourceRouterFactoryTest.java │ │ │ ├── dimension │ │ │ │ └── DefaultDimensionRuleTest.java │ │ │ └── rule │ │ │ │ ├── DefaultTableSetsManagerTest.java │ │ │ │ ├── GroovyRuleEngineTest.java │ │ │ │ ├── SimpleDataSourceProviderTest.java │ │ │ │ └── engine │ │ │ │ └── RuleEngineBaseTest.java │ │ └── util │ │ │ ├── ShardColumnValueUtilTest.java │ │ │ └── ShardDateParseUtilTest.java │ │ ├── single │ │ ├── AllTests.java │ │ └── jdbc │ │ │ ├── AbstractSingleDataSourceTest.java │ │ │ ├── C3p0SingleDataSourceFieldTest.java │ │ │ ├── DataSourcePropertyPrinterTest.java │ │ │ ├── Dbcp2SingleDataSourceFieldTest.java │ │ │ ├── DbcpSingleDataSourceFieldTest.java │ │ │ ├── DruidSingleDataSourceTest.java │ │ │ ├── SingleDataSourceTest.java │ │ │ └── TomcatJdbcSingleDataSourceFieldTest.java │ │ └── util │ │ ├── ConfigServiceMock.java │ │ └── SqlExecuteHelper.java │ └── resources │ ├── app.properties │ ├── concurrency-gds0.properties │ ├── concurrency-gds1.properties │ ├── ctx-multidb-lifecycle-group.xml │ ├── ctx-multidb-lifecycle.xml │ ├── ctx-multidb-multikey-lifecycle.xml │ ├── ctx-multidb-shardtest.xml │ ├── ctx-singledb-group-follownote-integrationtest.xml │ ├── ctx-singledb-lifecycle.xml │ ├── ctx-specialsql.xml │ ├── datasets.xml │ ├── datasets1.xml │ ├── datasets2.xml │ ├── db-datafiles │ ├── createtable-multidb-join-lifecycle.xml │ ├── createtable-multidb-lifecycle-group.xml │ ├── createtable-multidb-lifecycle.xml │ ├── createtable-multidb-shardtest.xml │ ├── createtable-singledb-group-follownote-integrationtest.xml │ ├── createtable-singledb-lifecycle.xml │ ├── createtable-specialsql.xml │ ├── data-join-lifecycle.xml │ ├── data-limitdb-lifecycle.xml │ ├── data-multidb-lifecycle-group.xml │ ├── data-multidb-lifecycle.xml │ ├── data-multidb-shardtest.xml │ ├── data-singledb-group-follownote-integrationtest.xml │ ├── data-singledb-lifecycle.xml │ └── data-specialsql.xml │ ├── db-router-rule.xml │ ├── db-router-xml-rule-zeropadding.xml │ ├── db-router-xml-rule.xml │ ├── defaultStrategy-gds.properties │ ├── group01.properties │ ├── group02.properties │ ├── log4j.properties │ ├── mockdb-config │ ├── testConcurrency │ │ ├── createtable-multidb-concurrency.xml │ │ ├── ctx-multidb-concurrency.xml │ │ ├── data-multidb-concurrency.xml │ │ └── router-multidb-concurrency.xml │ ├── testDefaultStrategy │ │ ├── createtable-multidb-defaultstrategy.xml │ │ ├── ctx-multidb-defaultstrategy.xml │ │ ├── data-multidb-defaultstrategy.xml │ │ └── router-multidb-defaultstrategy.xml │ ├── testMultiShardKey │ │ ├── createtable-multidb-multisk.xml │ │ ├── ctx-multidb-multisk.xml │ │ ├── ctx-multidb-multisk_repeat.xml │ │ ├── data-multidb-multisk.xml │ │ ├── router-multidb-multisk.xml │ │ └── router-multidb-multisk_repeat.xml │ ├── testRangeCross │ │ ├── createtable-multidb-rangetest.xml │ │ ├── ctx-multidb-rangetest.xml │ │ ├── data-multidb-rangetest.xml │ │ └── router-rule-multidb-rangetest.xml │ ├── testRangeDefault │ │ ├── createtable-multidb-rangetest.xml │ │ ├── ctx-multidb-rangetest.xml │ │ ├── data-multidb-rangetest.xml │ │ └── router-rule-multidb-rangetest.xml │ └── testReplace │ │ ├── createtable-multidb-replacetest.xml │ │ ├── ctx-multidb-replacetest.xml │ │ ├── data-multidb-replacetest.xml │ │ └── router-multidb-replacetest.xml │ ├── model │ ├── datasources.xml │ └── system.xml │ ├── multisk-gds0.properties │ ├── multisk-gds1.properties │ ├── performance │ ├── appcontext-aop-core-c3p0.xml │ └── appcontext-aop-core.xml │ ├── rangetest-gds0.properties │ ├── rangetest-gds1.properties │ ├── region │ ├── center.json │ └── idc.json │ ├── replicate │ └── config.xml │ ├── router-rule-multidb-lifecycle-group.xml │ ├── router-rule-multidb-lifecycle.xml │ ├── router-rule-multidb-multikey-lifecycle.xml │ ├── router-rule-multidb-shardtest.xml │ ├── router-rule-singledb-group-follownote-integrationtest.xml │ ├── router-rule-singledb-lifecycle.xml │ ├── router-rule-specialsql.xml │ ├── sample.ds.error.properties │ ├── sample.ds.router.properties │ ├── sample.ds.v2.properties │ ├── sample.ds.v3.properties │ ├── sample │ └── applicationContext.xml │ ├── schema.sql │ ├── shardtest-gds0.properties │ ├── shardtest-gds1.properties │ └── zebra.system.properties ├── zebra-dao ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── dianping │ └── zebra │ └── dao │ ├── AsyncDaoCallableExecutor.java │ ├── AsyncDaoCallback.java │ ├── AsyncDaoException.java │ ├── AsyncDaoRunnableExecutor.java │ ├── AsyncMapperExecutor.java │ ├── AsyncMapperProxy.java │ ├── annotation │ └── TargetMethod.java │ ├── datasource │ ├── ZebraRouting.java │ ├── ZebraRoutingAdvice.java │ ├── ZebraRoutingDataSource.java │ ├── ZebraRoutingDataSourceUtil.java │ └── ZebraRoutingPointcut.java │ ├── dialect │ ├── Dialect.java │ └── MySQLDialect.java │ ├── mybatis │ ├── FixedSqlSessionFactoryBean.java │ ├── ZebraClassPathMapperScanner.java │ ├── ZebraMapperFactoryBean.java │ └── ZebraMapperScannerConfigurer.java │ ├── plugin │ └── page │ │ ├── MysqlCountOutputVisitor.java │ │ ├── PageInterceptor.java │ │ ├── PageModel.java │ │ └── SqlSourceWrapper.java │ └── util │ └── ReflectionUtils.java └── zebra-sample ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── dianping │ │ └── zebra │ │ └── sample │ │ ├── dao │ │ ├── group │ │ │ └── UserDao.java │ │ └── shard │ │ │ └── FeedDao.java │ │ └── entity │ │ ├── group │ │ └── UserEntity.java │ │ └── shard │ │ └── FeedEntity.java └── resources │ └── mapper │ ├── group │ └── UserMapper.xml │ └── shard │ └── FeedMapper.xml └── test ├── java └── com │ └── dianping │ └── zebra │ └── sample │ ├── jdbc │ └── GroupDataSourceSample.java │ └── mybatis │ ├── GroupDataSourceSample.java │ ├── ShardDataSourceSample.java │ └── SingleDataSourceSample.java └── resources ├── app.properties ├── region ├── center.json └── idc.json ├── spring ├── group │ └── group-db-config.xml ├── shard │ ├── router-local-rule.xml │ └── shard-local-config.xml └── single │ └── single-db-config.xml ├── sql ├── zebra.properties ├── zebra.system.properties └── zookeeper.properties /.gitignore: -------------------------------------------------------------------------------- 1 | /ws/* 2 | 3 | # should not ignored # 4 | !*.java 5 | !*.gitignore 6 | !*.xml 7 | !*.jsp 8 | !*.html 9 | !*.htm 10 | !*.js 11 | !*.css 12 | !*.jpg 13 | !*.gif 14 | !*.properties 15 | 16 | 17 | # Compiled source # 18 | ################### 19 | *.com 20 | *.class 21 | *.dll 22 | *.exe 23 | *.o 24 | *.so 25 | 26 | # Packages # 27 | ############ 28 | # it's better to unpack these files and commit the raw source 29 | # git has its own built in compression methods 30 | *.7z 31 | *.dmg 32 | *.gz 33 | *.iso 34 | *.rar 35 | *.tar 36 | *.zip 37 | *.war 38 | *.ear 39 | 40 | # Logs and databases # 41 | ###################### 42 | *.logger 43 | *.log 44 | *.sqlite 45 | 46 | # OS generated files # 47 | ###################### 48 | .DS_Store 49 | .DS_Store? 50 | ._* 51 | .Spotlight-V100 52 | .Trashes 53 | Icon? 54 | ehthumbs.db 55 | Thumbs.db 56 | 57 | # eclipse generated files # 58 | ###################### 59 | .project 60 | .classpath 61 | .settings/ 62 | 63 | # temp folder # 64 | ###################### 65 | target/ 66 | classes/ 67 | bin/ 68 | node_modules/ 69 | *.*~ 70 | 71 | # Intellij project files # 72 | ###################### 73 | *.iml 74 | *.ipr 75 | *.iws 76 | .idea/ 77 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | before_install: echo "MAVEN_OPTS='-Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M'" > ~/.mavenrc 3 | sudo: required 4 | script: 5 | mvn test -B -fae 6 | 7 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/GlobalConstants.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator; 2 | 3 | public class GlobalConstants { 4 | 5 | public static final String DEFAULR_CHARSET = "UTF-8"; 6 | 7 | public static final String GROUP_CONFIG_NAME_PATTERN = "zebra.group.%s"; 8 | 9 | public static final String DS_CONFIG_PATTERN = "zebra.ds.%s"; 10 | 11 | public static final String SHARD_CONFIG_NAME_PATTERN = "zebra.shard.%s"; 12 | 13 | public static final String DS_NAME = "%s-n%s"; 14 | 15 | public static final String JDBC_URL = "jdbc:mysql://%s/%s?characterEncoding=UTF8&socketTimeout=60000&allowMultiQueries=true"; 16 | 17 | public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver"; 18 | 19 | public static final String PROPERTIES = "initialPoolSize=3&maxPoolSize=20&minPoolSize=3&" + 20 | "idleConnectionTestPeriod=60&acquireRetryAttempts=50&acquireRetryDelay=300&" + 21 | "maxStatements=0&numHelperThreads=6&maxAdministrativeTaskTime=5&" + 22 | "preferredTestQuery=SELECT 1&checkoutTimeout=1000"; 23 | } 24 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/controller/AbstractController.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.controller; 2 | 3 | import com.google.gson.Gson; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | /** 8 | * @author Created by tong.xin on 18/1/19. 9 | */ 10 | public abstract class AbstractController { 11 | protected Logger logger = LoggerFactory.getLogger(this.getClass().getName()); 12 | protected static final Gson defaultGson = new Gson(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/controller/base/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.controller.base; 2 | 3 | import com.dianping.zebra.administrator.controller.AbstractController; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Created by tong.xin on 18/1/19. 10 | */ 11 | 12 | @RestController 13 | @RequestMapping(value = "/home") 14 | public class HomeController extends AbstractController { 15 | 16 | @RequestMapping(method = RequestMethod.GET) 17 | public void index() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dao/JdbcrefMapper.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dao; 2 | 3 | import com.dianping.zebra.administrator.entity.JdbcrefEntity; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Created by tong.xin on 18/3/7. 10 | */ 11 | public interface JdbcrefMapper { 12 | 13 | void create(JdbcrefEntity entity); 14 | 15 | List findByEnv(@Param("env") String enc); 16 | 17 | String findOwnByJdbcref(@Param("env") int env, @Param("jdbcref") String jdbcref); 18 | 19 | List findByJdbcrefs(@Param("list") List jdbcrefs, @Param("env") int env); 20 | 21 | int selectCountByEnv(@Param("env") int env); 22 | 23 | List selectAllByEnv(@Param("env") int env); 24 | 25 | void removeJdbcref(@Param("jdbcref") String jdbcref, @Param("env") String env); 26 | 27 | void addJdbcref(JdbcrefEntity jdbcrefEntity); 28 | } 29 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dao/ShardMapper.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dao; 2 | 3 | import com.dianping.zebra.administrator.entity.ShardEntity; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Created by tong.xin on 18/3/7. 10 | */ 11 | public interface ShardMapper { 12 | void create(ShardEntity entity); 13 | 14 | List findByEnv(@Param("env") String env); 15 | 16 | void createRule(ShardEntity shardEntity); 17 | 18 | void deleteRuleName(@Param("ruleName") String ruleName, @Param("env") String env); 19 | } 20 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dao/ZookeeperConfigMapper.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dao; 2 | 3 | import com.dianping.zebra.administrator.entity.ZookeeperConfigEntity; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by taochen on 2018/11/8. 10 | */ 11 | public interface ZookeeperConfigMapper { 12 | 13 | List findZKConfig(); 14 | 15 | List getZKName(); 16 | 17 | void addZKConfig(ZookeeperConfigEntity zkEntity); 18 | 19 | void deleteZKConfig(@Param("id") Integer id); 20 | 21 | void updateZKConfig(ZookeeperConfigEntity zkEntity); 22 | 23 | String getHostByName(@Param("ZKName") String ZKName); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/ResultDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto; 2 | 3 | /** 4 | * @author Created by tong.xin on 18/1/19. 5 | */ 6 | public class ResultDto { 7 | String status; 8 | 9 | String message; 10 | 11 | T result; 12 | 13 | public ResultDto() { 14 | 15 | } 16 | 17 | public ResultDto(String status, String message) { 18 | this.status = status; 19 | this.message = message; 20 | } 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public String getMessage() { 31 | return message; 32 | } 33 | 34 | public void setMessage(String message) { 35 | this.message = message; 36 | } 37 | 38 | public T getResult() { 39 | return result; 40 | } 41 | 42 | public void setResult(T result) { 43 | this.result = result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/ZKResponse.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto; 2 | 3 | /** 4 | * Created by taochen on 2018/11/4. 5 | */ 6 | public class ZKResponse { 7 | 8 | private String status; 9 | private Object result; 10 | private String message; 11 | 12 | public boolean isSuccess() { 13 | return "success".equalsIgnoreCase(status); 14 | } 15 | 16 | public boolean isExist() { 17 | return isSuccess() && result != null; 18 | } 19 | 20 | public String getStatus() { 21 | return status; 22 | } 23 | 24 | public void setStatus(String status) { 25 | this.status = status; 26 | } 27 | 28 | public Object getResult() { 29 | return result; 30 | } 31 | 32 | public void setResult(Object result) { 33 | this.result = result; 34 | } 35 | 36 | public String getMessage() { 37 | return message; 38 | } 39 | 40 | public void setMessage(String message) { 41 | this.message = message; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "ZKResponse{" + 47 | "status='" + status + '\'' + 48 | ", result='" + result + '\'' + 49 | ", message='" + message + '\'' + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/jdbcref/DBAddressDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.jdbcref; 2 | 3 | /** 4 | * Created by taochen on 2018/11/13. 5 | */ 6 | public class DBAddressDto { 7 | //ip+port 8 | private String address; 9 | 10 | private int readWeight; 11 | 12 | private int writeWeight; 13 | 14 | private String userName; 15 | 16 | private String password; 17 | 18 | public String getAddress() { 19 | return address; 20 | } 21 | 22 | public void setAddress(String address) { 23 | this.address = address; 24 | } 25 | 26 | public int getReadWeight() { 27 | return readWeight; 28 | } 29 | 30 | public void setReadWeight(int readWeight) { 31 | this.readWeight = readWeight; 32 | } 33 | 34 | public int getWriteWeight() { 35 | return writeWeight; 36 | } 37 | 38 | public void setWriteWeight(int writeWeight) { 39 | this.writeWeight = writeWeight; 40 | } 41 | 42 | public String getUserName() { 43 | return userName; 44 | } 45 | 46 | public void setUserName(String userName) { 47 | this.userName = userName; 48 | } 49 | 50 | public String getPassword() { 51 | return password; 52 | } 53 | 54 | public void setPassword(String password) { 55 | this.password = password; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/jdbcref/DBConfigInfoDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.jdbcref; 2 | 3 | /** 4 | * Created by taochen on 2018/11/12. 5 | */ 6 | public class DBConfigInfoDto { 7 | private int readDBNum; 8 | 9 | private int writeDBNum; 10 | 11 | public int getReadDBNum() { 12 | return readDBNum; 13 | } 14 | 15 | public void setReadDBNum(int readDBNum) { 16 | this.readDBNum = readDBNum; 17 | } 18 | 19 | public int getWriteDBNum() { 20 | return writeDBNum; 21 | } 22 | 23 | public void setWriteDBNum(int writeDBNum) { 24 | this.writeDBNum = writeDBNum; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/jdbcref/GroupConfigDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.jdbcref; 2 | 3 | import com.dianping.zebra.administrator.entity.SingleConfigEntity; 4 | 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by taochen on 2018/11/10. 10 | */ 11 | public class GroupConfigDto { 12 | 13 | private List singleConfigs = new LinkedList<>(); 14 | 15 | public void addSingleConfig(SingleConfigEntity config) { 16 | singleConfigs.add(config); 17 | } 18 | 19 | public void addAllSingleConfig(List configs) { 20 | singleConfigs.addAll(configs); 21 | } 22 | 23 | public List getSingleConfigs() { 24 | return singleConfigs; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/jdbcref/JdbcrefDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.jdbcref; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * @author Created by tong.xin on 18/3/7. 7 | */ 8 | public class JdbcrefDto { 9 | private String jdbcref; 10 | 11 | private String env; 12 | 13 | private DBConfigInfoDto groupConfig; 14 | 15 | private String owner; 16 | 17 | private Date updateTime; 18 | 19 | public String getJdbcref() { 20 | return jdbcref; 21 | } 22 | 23 | public void setJdbcref(String jdbcref) { 24 | this.jdbcref = jdbcref; 25 | } 26 | 27 | public String getEnv() { 28 | return env; 29 | } 30 | 31 | public void setEnv(String env) { 32 | this.env = env; 33 | } 34 | 35 | public DBConfigInfoDto getGroupConfig() { 36 | return groupConfig; 37 | } 38 | 39 | public void setGroupConfig(DBConfigInfoDto groupConfig) { 40 | this.groupConfig = groupConfig; 41 | } 42 | 43 | public String getOwner() { 44 | return owner; 45 | } 46 | 47 | public void setOwner(String owner) { 48 | this.owner = owner; 49 | } 50 | 51 | public Date getUpdateTime() { 52 | return updateTime; 53 | } 54 | 55 | public void setUpdateTime(Date updateTime) { 56 | this.updateTime = updateTime; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/jdbcref/JdbcrefOverviewDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.jdbcref; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author Created by tong.xin on 18/3/7. 8 | */ 9 | public class JdbcrefOverviewDto { 10 | List jdbcrefList = new LinkedList<>();; 11 | 12 | private int total; 13 | 14 | public List getJdbcrefList() { 15 | return jdbcrefList; 16 | } 17 | 18 | public void addJdbcrefDto(JdbcrefDto jdbcrefDto) { 19 | this.jdbcrefList.add(jdbcrefDto); 20 | } 21 | 22 | public int getTotal() { 23 | return total; 24 | } 25 | 26 | public void setTotal(int total) { 27 | this.total = total; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/shard/ShardConfigDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.shard; 2 | 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Created by taochen on 2018/11/13. 8 | */ 9 | 10 | public class ShardConfigDto { 11 | 12 | private String ruleName; 13 | 14 | private String env; 15 | 16 | private List tableShardConfigs; 17 | 18 | public List getTableShardConfigs() { 19 | return tableShardConfigs; 20 | } 21 | 22 | public void setTableShardConfigs(List tableShardConfigs) { 23 | this.tableShardConfigs = tableShardConfigs; 24 | } 25 | 26 | public String getRuleName() { 27 | return ruleName; 28 | } 29 | 30 | public void setRuleName(String ruleName) { 31 | this.ruleName = ruleName; 32 | } 33 | 34 | public String getEnv() { 35 | return env; 36 | } 37 | 38 | public void setEnv(String env) { 39 | this.env = env; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/shard/ShardDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.shard; 2 | 3 | /** 4 | * @author Created by tong.xin on 18/3/7. 5 | */ 6 | public class ShardDto { 7 | private String ruleName; 8 | 9 | private String ZKName; 10 | 11 | private String owner; 12 | 13 | private String desc; 14 | 15 | private String updateTime; 16 | 17 | public String getRuleName() { 18 | return ruleName; 19 | } 20 | 21 | public void setRuleName(String ruleName) { 22 | this.ruleName = ruleName; 23 | } 24 | 25 | public String getZKName() { 26 | return ZKName; 27 | } 28 | 29 | public void setZKName(String ZKName) { 30 | this.ZKName = ZKName; 31 | } 32 | 33 | public String getOwner() { 34 | return owner; 35 | } 36 | 37 | public void setOwner(String owner) { 38 | this.owner = owner; 39 | } 40 | 41 | public String getDesc() { 42 | return desc; 43 | } 44 | 45 | public void setDesc(String desc) { 46 | this.desc = desc; 47 | } 48 | 49 | public String getUpdateTime() { 50 | return updateTime; 51 | } 52 | 53 | public void setUpdateTime(String updateTime) { 54 | this.updateTime = updateTime; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/shard/ShardOverviewDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.shard; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author Created by tong.xin on 18/3/7. 8 | */ 9 | public class ShardOverviewDto { 10 | List shardList = new LinkedList<>();; 11 | 12 | private int total; 13 | 14 | public List getShardList() { 15 | return shardList; 16 | } 17 | 18 | public void addShardDto(ShardDto shardDto) { 19 | this.shardList.add(shardDto); 20 | } 21 | 22 | public int getTotal() { 23 | return total; 24 | } 25 | 26 | public void setTotal(int total) { 27 | this.total = total; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/shard/TableShardConfigDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.shard; 2 | 3 | import com.dianping.zebra.administrator.entity.DimensionConfig; 4 | import com.dianping.zebra.shard.config.TableShardDimensionConfig; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by taochen on 2018/11/13. 10 | */ 11 | public class TableShardConfigDto { 12 | private String tableName; 13 | 14 | private List dimensionConfigs; 15 | 16 | public String getTableName() { 17 | return tableName; 18 | } 19 | 20 | public void setTableName(String tableName) { 21 | this.tableName = tableName; 22 | } 23 | 24 | public List getDimensionConfigs() { 25 | return dimensionConfigs; 26 | } 27 | 28 | public void setDimensionConfigs(List dimensionConfigs) { 29 | this.dimensionConfigs = dimensionConfigs; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/dto/zookeeperConfig/ZookeeperConfigDto.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.dto.zookeeperConfig; 2 | 3 | /** 4 | * Created by taochen on 2018/11/16. 5 | */ 6 | public class ZookeeperConfigDto { 7 | private String host; 8 | 9 | private String name; 10 | 11 | private String description; 12 | 13 | public String getHost() { 14 | return host; 15 | } 16 | 17 | public void setHost(String host) { 18 | this.host = host; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getDescription() { 30 | return description; 31 | } 32 | 33 | public void setDescription(String description) { 34 | this.description = description; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/entity/DimensionConfigs.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.entity; 2 | 3 | import javax.xml.bind.annotation.XmlAccessType; 4 | import javax.xml.bind.annotation.XmlAccessorType; 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlRootElement; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by taochen on 2018/11/13. 11 | */ 12 | @XmlRootElement(name = "dimensionConfigs") 13 | @XmlAccessorType(XmlAccessType.FIELD) 14 | public class DimensionConfigs { 15 | 16 | @XmlElement(name = "dimensionConfigs") 17 | private List dimensionConfigs; 18 | 19 | 20 | public List getDimensionConfig() { 21 | return dimensionConfigs; 22 | } 23 | 24 | public void setDimensionConfig(List dimensionConfigs) { 25 | this.dimensionConfigs = dimensionConfigs; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/entity/GroupConfigEntity.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.entity; 2 | 3 | import javax.xml.bind.annotation.XmlAccessType; 4 | import javax.xml.bind.annotation.XmlAccessorType; 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlRootElement; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by taochen on 2018/11/10. 11 | */ 12 | 13 | @XmlRootElement(name = "groupConfig") 14 | @XmlAccessorType(XmlAccessType.FIELD) 15 | public class GroupConfigEntity { 16 | 17 | @XmlElement(name = "singleConfig") 18 | private List singleConfigs; 19 | 20 | public List getSingleConfigs() { 21 | return singleConfigs; 22 | } 23 | 24 | public void setSingleConfigs(List singleConfigs) { 25 | this.singleConfigs = singleConfigs; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/entity/ShardConfig.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.entity; 2 | 3 | import javax.xml.bind.annotation.XmlAccessType; 4 | import javax.xml.bind.annotation.XmlAccessorType; 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlRootElement; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by taochen on 2018/11/13. 11 | */ 12 | @XmlRootElement(name = "tableShardConfigs") 13 | @XmlAccessorType(XmlAccessType.FIELD) 14 | public class ShardConfig { 15 | 16 | @XmlElement(name = "tableShardConfigs") 17 | private List tableShardConfigs; 18 | 19 | public List getTableShardConfigs() { 20 | return tableShardConfigs; 21 | } 22 | 23 | public void setTableShardConfigs(List tableShardConfigs) { 24 | this.tableShardConfigs = tableShardConfigs; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/entity/TableShardConfig.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.entity; 2 | 3 | import javax.xml.bind.annotation.XmlAccessType; 4 | import javax.xml.bind.annotation.XmlAccessorType; 5 | import javax.xml.bind.annotation.XmlElement; 6 | import javax.xml.bind.annotation.XmlRootElement; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by taochen on 2018/11/13. 11 | */ 12 | @XmlRootElement(name = "tableShardConfig") 13 | @XmlAccessorType(XmlAccessType.FIELD) 14 | public class TableShardConfig { 15 | private String tableName; 16 | 17 | @XmlElement(name = "dimensionConfigs") 18 | private DimensionConfigs dimensionConfigs; 19 | 20 | public String getTableName() { 21 | return tableName; 22 | } 23 | 24 | public void setTableName(String tableName) { 25 | this.tableName = tableName; 26 | } 27 | 28 | public DimensionConfigs getDimensionConfigs() { 29 | return dimensionConfigs; 30 | } 31 | 32 | public void setDimensionConfigs(DimensionConfigs dimensionConfigs) { 33 | this.dimensionConfigs = dimensionConfigs; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/entity/ZookeeperConfigEntity.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.entity; 2 | 3 | /** 4 | * Created by taochen on 2018/11/7. 5 | */ 6 | public class ZookeeperConfigEntity { 7 | private int id; 8 | 9 | private String host; 10 | 11 | private String name; 12 | 13 | private String description; 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getHost() { 24 | return host; 25 | } 26 | 27 | public void setHost(String host) { 28 | this.host = host; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public void setDescription(String description) { 36 | this.description = description; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/exception/ZebraException.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.exception; 2 | 3 | public class ZebraException extends Exception{ 4 | 5 | private static final long serialVersionUID = -2179018904519319909L; 6 | 7 | public ZebraException(String message) { 8 | super(message); 9 | } 10 | 11 | public ZebraException(String message, Throwable e) { 12 | super(message, e); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/exception/ZebraRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.exception; 2 | 3 | public class ZebraRuntimeException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = -511024199002140052L; 6 | 7 | public ZebraRuntimeException(String message) { 8 | super(message); 9 | } 10 | 11 | public ZebraRuntimeException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/service/JdbcrefService.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.service; 2 | 3 | import com.dianping.zebra.administrator.dto.jdbcref.DBConfigInfoDto; 4 | import com.dianping.zebra.administrator.dto.jdbcref.JdbcrefConfigDto; 5 | import com.dianping.zebra.administrator.entity.DsConfigEntity; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author canhuang 11 | * @date 2018/3/25 12 | */ 13 | public interface JdbcrefService { 14 | 15 | int selectCount(int env); 16 | 17 | List selectAllByEnv(int env); 18 | 19 | DBConfigInfoDto getGroupConfig(String jdbcref, String env); 20 | 21 | DsConfigEntity getDsConfig(String dsName, String env); 22 | 23 | void removeJdbcref(String jdbcref, String env); 24 | 25 | void saveJdbcrefConfig(JdbcrefConfigDto jdbcrefConfigDto) throws Exception; 26 | 27 | void dsOffLine(String dsName, String env); 28 | 29 | void dsOnLine(String dsName, String env); 30 | } 31 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/service/ShardService.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.service; 2 | 3 | import com.dianping.zebra.administrator.dto.shard.ShardConfigDto; 4 | 5 | /** 6 | * @author canhuang 7 | * @date 2018/3/25 8 | */ 9 | public interface ShardService { 10 | 11 | void addRuleName(String ruleName, String zkAddr, String owner, String desc); 12 | 13 | void saveRuleNameConfig(ShardConfigDto shardConfigDto); 14 | 15 | void deleteRuleNameConfig(String ruleName, String env); 16 | } 17 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/service/ZookeeperConfigService.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.service; 2 | 3 | import com.dianping.zebra.administrator.dto.zookeeperConfig.ZookeeperConfigDto; 4 | import com.dianping.zebra.administrator.entity.ZookeeperConfigEntity; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by taochen on 2018/11/8. 10 | */ 11 | public interface ZookeeperConfigService { 12 | 13 | List findZKConfig(); 14 | 15 | List getZKName(); 16 | 17 | String getZKHostByName(String name); 18 | 19 | void addZKConfig(ZookeeperConfigDto zkConfigDto); 20 | 21 | void updateConfig(ZookeeperConfigEntity zkEntity); 22 | 23 | void deleteZKConfig(Integer id); 24 | } 25 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/service/impl/BaseServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.service.impl; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * @author canhuang 8 | * @date 2018/3/25 9 | */ 10 | public class BaseServiceImpl { 11 | 12 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/java/com/dianping/zebra/administrator/util/ShardRuleUtils.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.administrator.util; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author tong.xin on 2018/11/13. 7 | */ 8 | public class ShardRuleUtils { 9 | public static void parseDbIndex(String dbIndex) { 10 | //todo 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/META-INF/app.properties: -------------------------------------------------------------------------------- 1 | app.name=zebra-admin-web -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/config/spring/local/appcontext-core.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/config/spring/local/appcontext-dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/config/sqlmap/JdbcrefMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | 11 | DELETE from `Jdbcref` WHERE `Jdbcref`=#{jdbcref} AND `Env`=#{env} 12 | 13 | 14 | 15 | INSERT INTO Jdbcref(Jdbcref,Status,Env,Owner,Description) VALUES(#{jdbcref},#{status},#{env},#{owner},#{description}) 16 | 17 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/config/sqlmap/ShardMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | INSERT IGNORE INTO `Shard` 8 | ( 9 | `RuleName`, 10 | `Status`, 11 | `Env`, 12 | `Description`, 13 | `Owner`, 14 | `UpdateTime` 15 | ) 16 | VALUES 17 | ( 18 | #{ruleName}, 19 | #{status}, 20 | #{env}, 21 | #{description}, 22 | #{owner}, 23 | NOW()) 24 | 25 | 26 | 29 | 30 | 37 | 38 | 39 | DELETE FROM `Shard` WHERE RuleName=#{ruleName} AND env=#{env} 40 | 41 | 42 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/resources/config/sqlmap/ZookeeperConfigMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | 13 | 14 | 15 | INSERT INTO ZookeeperConfig(`Host`,`Name`,`Description`) VALUES(#{host},#{name},#{description}) 16 | 17 | 18 | 19 | DELETE FROM ZookeeperConfig WHERE Id=#{id} 20 | 21 | 22 | 23 | UPDATE `ZookeeperConfig` SET `Host`=#{host},`Name`=#{name},`Description`=#{description} 24 | 25 | 26 | 29 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | contextConfigLocation 9 | 10 | classpath*:config/spring/local/appcontext-*.xml, 11 | 12 | 13 | 14 | 15 | org.springframework.web.context.ContextLoaderListener 16 | 17 | 18 | 19 | mvc-dispatcher 20 | org.springframework.web.servlet.DispatcherServlet 21 | 22 | contextConfigLocation 23 | /WEB-INF/springMVC-servlet.xml 24 | 25 | 1 26 | 27 | 28 | 29 | mvc-dispatcher 30 | /a/* 31 | /i/* 32 | 33 | 34 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | !*.java 3 | !*.gitignore 4 | !*.xml 5 | !*.jsp 6 | !*.html 7 | !*.htm 8 | !*.js 9 | !*.css 10 | !*.jpg 11 | !*.gif 12 | !*.properties 13 | !*.idea 14 | !*.imi 15 | !*.vue 16 | 17 | # Compiled source # 18 | ################### 19 | *.com 20 | *.class 21 | *.dll 22 | *.exe 23 | *.o 24 | *.so 25 | 26 | # Packages # 27 | ############ 28 | # it's better to unpack these files and commit the raw source 29 | # git has its own built in compression methods 30 | *.7z 31 | *.dmg 32 | *.gz 33 | *.iso 34 | *.rar 35 | *.tar 36 | *.zip 37 | *.war 38 | *.ear 39 | 40 | # Logs and databases # 41 | ###################### 42 | *.log 43 | *.sqlite 44 | 45 | # OS generated files # 46 | ###################### 47 | .DS_Store 48 | .DS_Store? 49 | ._* 50 | .Spotlight-V100 51 | .Trashes 52 | Icon? 53 | ehthumbs.db 54 | Thumbs.db 55 | 56 | # eclipse generated files # 57 | ###################### 58 | .project 59 | .classpath 60 | .settings/ 61 | 62 | # temp folder # 63 | ###################### 64 | target/ 65 | classes/ 66 | bin/ 67 | *.*~ 68 | 69 | # Intellij project files # 70 | ###################### 71 | *.iml 72 | *.ipr 73 | *.iws 74 | .idea/ 75 | node_modules/ 76 | 77 | #vscode# 78 | .DS_Store 79 | node_modules/ 80 | /dist/ 81 | npm-debug.log* 82 | yarn-debug.log* 83 | yarn-error.log* 84 | 85 | # Editor directories and files 86 | .vscode 87 | *.suo 88 | *.ntvs* 89 | *.njsproj 90 | *.sln 91 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | "postcss-import": {}, 6 | "postcss-url": {}, 7 | // to edit target browsers: use "browserslist" field in package.json 8 | "autoprefixer": {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/README.md: -------------------------------------------------------------------------------- 1 | # zebra-admin-vue 2 | 3 | > ZebraAdmin 4 | 5 | ## Build Setup 6 | 7 | ``` bash 8 | # install dependencies 9 | npm install 10 | 11 | # serve with hot reload at localhost:8080 12 | npm run dev 13 | 14 | # build for production with minification 15 | npm run build 16 | 17 | # build for production and view the bundle analyzer report 18 | npm run build --report 19 | ``` 20 | 21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 22 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build. 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Zebra 管理平台 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/src/App.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 44 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/src/components/icon/icon.vue: -------------------------------------------------------------------------------- 1 | 4 | 34 | -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/src/components/modal/mixins-scrollbar.js: -------------------------------------------------------------------------------- 1 | // used for Modal & $Spin 2 | import { getScrollBarSize } from '../../utils/assist'; 3 | export default { 4 | methods: { 5 | checkScrollBar () { 6 | let fullWindowWidth = window.innerWidth; 7 | if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8 8 | const documentElementRect = document.documentElement.getBoundingClientRect(); 9 | fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left); 10 | } 11 | this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth; 12 | if (this.bodyIsOverflowing) { 13 | this.scrollBarWidth = getScrollBarSize(); 14 | } 15 | }, 16 | setScrollBar () { 17 | if (this.bodyIsOverflowing && this.scrollBarWidth !== undefined) { 18 | document.body.style.paddingRight = `${this.scrollBarWidth}px`; 19 | } 20 | }, 21 | resetScrollBar () { 22 | document.body.style.paddingRight = ''; 23 | }, 24 | addScrollEffect () { 25 | this.checkScrollBar(); 26 | this.setScrollBar(); 27 | document.body.style.overflow = 'hidden'; 28 | }, 29 | removeScrollEffect() { 30 | document.body.style.overflow = ''; 31 | this.resetScrollBar(); 32 | } 33 | } 34 | }; -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/src/components/submenu/mixin.js: -------------------------------------------------------------------------------- 1 | import { findComponentUpward, findComponentsUpward } from '../base/assist'; 2 | export default { 3 | data () { 4 | return { 5 | menu: findComponentUpward(this, 'Menu') 6 | }; 7 | }, 8 | computed: { 9 | hasParentSubmenu () { 10 | return findComponentUpward(this, 'Submenu'); 11 | }, 12 | parentSubmenuNum () { 13 | return findComponentsUpward(this, 'Submenu').length; 14 | }, 15 | mode () { 16 | return this.menu.mode; 17 | } 18 | } 19 | }; -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/font-awesome/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/background.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/background1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/background1.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/depview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/depview.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/zebra-20181109.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/zebra-20181109.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/zebra-dal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/zebra-dal.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/app/static/image/zebra-nav.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/app/static/image/zebra-nav.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/index.html: -------------------------------------------------------------------------------- 1 | Zebra 管理平台
-------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/font-awesome/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.05acfdb.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.05acfdb.woff -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.24712f6.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.24712f6.ttf -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.2c2ae06.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/fonts/ionicons.2c2ae06.eot -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/background.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/background1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/background1.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/depview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/depview.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/zebra-20181109.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/zebra-20181109.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/zebra-dal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/zebra-dal.png -------------------------------------------------------------------------------- /zebra-admin-web/src/main/webapp/pack/static/image/zebra-nav.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-admin-web/src/main/webapp/pack/static/image/zebra-nav.png -------------------------------------------------------------------------------- /zebra-cat-client/src/main/java/com/dianping/zebra/monitor/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.monitor; 20 | 21 | public final class Version { 22 | public static final String ZEBRA_VERSION = "2.9.1"; 23 | } 24 | -------------------------------------------------------------------------------- /zebra-cat-client/src/main/resources/META-INF/zebra-filter.properties: -------------------------------------------------------------------------------- 1 | zebra.filter.cat=com.dianping.zebra.monitor.filter.CatFilter -------------------------------------------------------------------------------- /zebra-cat-client/src/test/java/com/dianping/zebra/monitor/monitor/GroupDataSourceMonitorTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.monitor.monitor; 2 | 3 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 4 | import com.dianping.zebra.group.monitor.GroupDataSourceMBean; 5 | import com.dianping.zebra.group.monitor.SingleDataSourceMBean; 6 | import org.junit.Test; 7 | import org.mockito.Mockito; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class GroupDataSourceMonitorTest { 13 | @Test 14 | public void test_get_properties() { 15 | GroupDataSourceMBean bean = Mockito.mock(GroupDataSourceMBean.class); 16 | Mockito.when(bean.getConfig()).thenReturn(new GroupDataSourceConfig()); 17 | SingleDataSourceMBean single = Mockito.mock(SingleDataSourceMBean.class); 18 | 19 | Mockito.when(bean.getWriteSingleDataSourceMBean()).thenReturn(single); 20 | 21 | Map readers = new HashMap(); 22 | 23 | readers.put("db1", single); 24 | 25 | Mockito.when(bean.getReaderSingleDataSourceMBean()).thenReturn(readers); 26 | 27 | GroupDataSourceMonitor monitor = new GroupDataSourceMonitor(bean); 28 | 29 | System.out.println(monitor.getDescription()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /zebra-cat-client/src/test/java/com/dianping/zebra/monitor/monitor/SingleDataSourceMonitorTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.monitor.monitor; 2 | 3 | import com.dianping.zebra.group.config.datasource.entity.DataSourceConfig; 4 | import com.dianping.zebra.group.monitor.SingleDataSourceMBean; 5 | import com.dianping.zebra.group.util.DataSourceState; 6 | import org.junit.Test; 7 | import org.mockito.Mockito; 8 | 9 | public class SingleDataSourceMonitorTest { 10 | @Test 11 | public void test_get_properties() { 12 | SingleDataSourceMBean single = Mockito.mock(SingleDataSourceMBean.class); 13 | 14 | Mockito.when(single.getState()).thenReturn(DataSourceState.UP); 15 | 16 | DataSourceConfig config = new DataSourceConfig(); 17 | config.setId("test"); 18 | 19 | Mockito.when(single.getConfig()).thenReturn(config); 20 | 21 | SingleDataSourceMonitor monitor = new SingleDataSourceMonitor(single); 22 | 23 | System.out.println(monitor.getDescription()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/META-INF/app.properties: -------------------------------------------------------------------------------- 1 | app.name=zebra_ut -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/META-INF/zebra-filter.properties: -------------------------------------------------------------------------------- 1 | zebra.filter.cat=com.dianping.zebra.monitor.filter.CatFilter -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/app.properties: -------------------------------------------------------------------------------- 1 | app.name=zebra_ut -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/region/center.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "centers" : [ 4 | {"center":"center1","priority":2, "idcs":[ 5 | {"idc" : "idc1", "desc" : "机房1"}, 6 | {"idc" : "idc2", "desc" : "机房2"}, 7 | {"idc" : "idc3", "desc" : "机房3"} 8 | ]}, 9 | {"center":"center2","priority":1,"idcs":[ 10 | {"idc" : "idc4", "desc" : "机房4"} 11 | ]} 12 | ]}, 13 | {"region" : "region2", "centers" : [ 14 | {"center":"center3","priority":1,"idcs":[ 15 | {"idc" : "idc5", "desc" : "机房5"}, 16 | {"idc" : "idc6", "desc" : "机房6"} 17 | ]} 18 | ]} 19 | ] 20 | } -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/region/idc.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "idcs" : [ 4 | {"idc" : "idc1", "net" : ["192.1", "192.2"], "desc" : "机房1"}, 5 | {"idc" : "idc2", "net" : ["192.3", "192.4"], "desc" : "机房2"}, 6 | {"idc" : "idc3", "net" : ["192.5"], "desc" : "机房3"}, 7 | {"idc" : "idc4", "net" : ["192.6"], "desc" : "机房4"} 8 | ]}, 9 | {"region" : "region2", "idcs" : [ 10 | {"idc" : "idc5", "net" : ["192.10", "192.11"], "desc" : "机房5"}, 11 | {"idc" : "idc6", "net" : ["192.20", "192.21"], "desc" : "机房6"} 12 | ]} 13 | ] 14 | } -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/sample.ds.v3.properties: -------------------------------------------------------------------------------- 1 | zebra_ut.zebra.pool.type=tomcat-jdbc 2 | zebra.default.filters=mock,stat,finalsql,wall 3 | groupds-security.global.security= 4 | groupds-security.global.switch=true 5 | groupds-security.sample.switch=true 6 | groupds-security.sample.security=zebra-* 7 | 8 | zebra.group.sample.ds.v3=\ 9 | \ 10 | db-n1\ 11 | 1\ 12 | -1\ 13 | \ 14 | \ 15 | db-n2\ 16 | -1\ 17 | 1\ 18 | \ 19 | 20 | 21 | zebra.ds.db-n1=\ 22 | jdbc:h2:mem:test;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 23 | sa\ 24 | \ 25 | org.h2.Driver\ 26 | true\ 27 | 28 | 29 | zebra.ds.db-n2=\ 30 | jdbc:h2:mem:test1;MVCC=TRUE\ 31 | sa\ 32 | \ 33 | org.h2.Driver\ 34 | true\ 35 | -------------------------------------------------------------------------------- /zebra-cat-client/src/test/resources/zebra.system.properties: -------------------------------------------------------------------------------- 1 | zebra_ut.zebra.system.retryTimes=3 2 | zebra.sql-blacklist.system.flowControl.72= -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/annotation/Internal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Indicate the method is for internal use only. 28 | * 29 | * @author damonzhu 30 | * 31 | */ 32 | @Retention(RetentionPolicy.CLASS) 33 | @Target({ ElementType.TYPE, ElementType.METHOD }) 34 | public @interface Internal { 35 | } 36 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/config/ConfigService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.config; 20 | 21 | import java.beans.PropertyChangeListener; 22 | import java.util.Map; 23 | 24 | public interface ConfigService { 25 | 26 | public void init(Map serviceConfigs); 27 | 28 | public void destroy(); 29 | 30 | public String getProperty(String key); 31 | 32 | public void addPropertyChangeListener(PropertyChangeListener listener); 33 | 34 | public void removePropertyChangeListener(PropertyChangeListener listener); 35 | } 36 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/config/Scope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.config; 20 | 21 | public enum Scope { 22 | SINGLETON, OTHERS 23 | } 24 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/config/Spi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.config; 20 | 21 | import java.lang.annotation.*; 22 | 23 | @Target({ ElementType.METHOD, ElementType.TYPE }) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Inherited 26 | public @interface Spi { 27 | String name() default ""; 28 | 29 | Scope scope() default Scope.SINGLETON; 30 | } 31 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/filter/FilterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.filter; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Created by Dozer on 9/2/14. 26 | */ 27 | public interface FilterManager { 28 | void addFilter(String name, JdbcFilter filter); 29 | 30 | void init(); 31 | 32 | void clear(); 33 | 34 | List loadFilters(String strConfig, String configType, Map serviceConfigs); 35 | } 36 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/filter/JdbcOperationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.filter; 20 | 21 | import java.sql.Connection; 22 | import java.sql.SQLException; 23 | 24 | public interface JdbcOperationCallback { 25 | T doAction(Connection conn) throws SQLException; 26 | } -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/DataSourceConfigManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config; 20 | 21 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 22 | 23 | import java.beans.PropertyChangeListener; 24 | 25 | public interface DataSourceConfigManager { 26 | 27 | public void addListerner(PropertyChangeListener listener); 28 | 29 | public GroupDataSourceConfig getGroupDataSourceConfig(); 30 | 31 | public void init(); 32 | 33 | public void close(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/datasource/IEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.datasource; 20 | 21 | public interface IEntity { 22 | void accept(IVisitor var1); 23 | 24 | void mergeAttributes(T var1); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/datasource/transform/ILinker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.datasource.transform; 20 | 21 | import com.dianping.zebra.group.config.datasource.entity.DataSourceConfig; 22 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 23 | 24 | public interface ILinker { 25 | boolean onDataSourceConfig(GroupDataSourceConfig var1, DataSourceConfig var2); 26 | } 27 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/datasource/transform/IParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.datasource.transform; 20 | 21 | import com.dianping.zebra.group.config.datasource.entity.DataSourceConfig; 22 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 23 | 24 | public interface IParser { 25 | GroupDataSourceConfig parse(IMaker var1, ILinker var2, T var3); 26 | 27 | void parseForDataSourceConfig(IMaker var1, ILinker var2, DataSourceConfig var3, T var4); 28 | } -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/system/IEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.system; 20 | 21 | public interface IEntity { 22 | public void accept(IVisitor visitor); 23 | 24 | public void mergeAttributes(T other); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/system/IVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.system; 20 | 21 | import com.dianping.zebra.group.config.system.entity.SqlFlowControl; 22 | import com.dianping.zebra.group.config.system.entity.SystemConfig; 23 | 24 | public interface IVisitor { 25 | 26 | public void visitSqlFlowControl(SqlFlowControl sqlFlowControl); 27 | 28 | public void visitSystemConfig(SystemConfig systemConfig); 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/system/transform/ILinker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.system.transform; 20 | 21 | import com.dianping.zebra.group.config.system.entity.SqlFlowControl; 22 | import com.dianping.zebra.group.config.system.entity.SystemConfig; 23 | 24 | public interface ILinker { 25 | 26 | public boolean onSqlFlowControl(SystemConfig parent, SqlFlowControl sqlFlowControl); 27 | } 28 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/system/transform/IMaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.system.transform; 20 | 21 | import com.dianping.zebra.group.config.system.entity.SqlFlowControl; 22 | import com.dianping.zebra.group.config.system.entity.SystemConfig; 23 | 24 | public interface IMaker { 25 | 26 | public SqlFlowControl buildSqlFlowControl(T node); 27 | 28 | public SystemConfig buildSystemConfig(T node); 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/config/system/transform/IParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.config.system.transform; 20 | 21 | import com.dianping.zebra.group.config.system.entity.SqlFlowControl; 22 | import com.dianping.zebra.group.config.system.entity.SystemConfig; 23 | 24 | public interface IParser { 25 | public SystemConfig parse(IMaker maker, ILinker linker, T node); 26 | 27 | public void parseForSqlFlowControl(IMaker maker, ILinker linker, SqlFlowControl parent, T node); 28 | } 29 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/exception/WeakReferenceGCException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.exception; 20 | 21 | /** 22 | * Created by Dozer on 10/14/14. 23 | */ 24 | public class WeakReferenceGCException extends RuntimeException { 25 | private static final long serialVersionUID = -8241429431083896757L; 26 | } 27 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/exception/sorter/ExceptionSorter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.exception.sorter; 20 | import java.sql.SQLException; 21 | /** 22 | * An interface to allow for exception evaluation. 23 | */ 24 | 25 | public interface ExceptionSorter { 26 | /** 27 | * Returns true or false whether or not the exception is fatal. 28 | * 29 | * @param e the exception 30 | * @return true or false if the exception is fatal. 31 | */ 32 | boolean isExceptionFatal(SQLException e); 33 | } -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/ArrayParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.Array; 19 | import java.sql.PreparedStatement; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * TODO Comment of ArrayParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class ArrayParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = 5772726703630477288L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public ArrayParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setArray(index, (Array) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/BigDecimalParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.math.BigDecimal; 19 | import java.sql.PreparedStatement; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * TODO Comment of BigDecimalParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class BigDecimalParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = -6915832597431575810L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public BigDecimalParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setBigDecimal(index, (BigDecimal) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/BooleanParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of BooleanParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class BooleanParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -4390286596448078383L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public BooleanParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setBoolean(index, (Boolean) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/ByteArrayParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of ByteArrayParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class ByteArrayParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -4010750314366977703L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public ByteArrayParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setBytes(index, (byte[]) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/ByteParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of ByteParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class ByteParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -9109030072336300120L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public ByteParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setByte(index, (Byte) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/DoubleParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of DoubleParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class DoubleParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -8295120306414575222L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public DoubleParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setDouble(index, (Double) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/FloatParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of FloatParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class FloatParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -8854468770215209575L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public FloatParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setFloat(index, (Float) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/IntParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of IntParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class IntParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -4094567388337032659L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public IntParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setInt(index, (Integer) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/LongParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of LongParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class LongParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -5706638948667220828L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public LongParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setLong(index, (Long) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/NStringParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of NStringParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class NStringParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = 4189680077757800337L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public NStringParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setNString(index, (String) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/RefParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.Ref; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * TODO Comment of RefParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class RefParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = -6226089996782874509L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public RefParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setRef(index, (Ref) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/RowIdParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.RowId; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * TODO Comment of RowIdParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class RowIdParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = 7121140907131100800L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public RowIdParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setRowId(index, (RowId) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/SQLXMLParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | import java.sql.SQLXML; 21 | 22 | /** 23 | * TODO Comment of SQLXMLParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class SQLXMLParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = -3225485567882941489L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public SQLXMLParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setSQLXML(index, (SQLXML) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/ShortParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of ShortParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class ShortParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = 99912191693491650L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public ShortParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setShort(index, (Short) values[0]); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/StringParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.sql.PreparedStatement; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * TODO Comment of StringParamContext 23 | * 24 | * @author Leo Liang 25 | */ 26 | public class StringParamContext extends ParamContext { 27 | 28 | private static final long serialVersionUID = -4522806074499008890L; 29 | 30 | /** 31 | * @param index 32 | * @param values 33 | */ 34 | public StringParamContext(int index, Object[] values) { 35 | super(index, values); 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 42 | */ 43 | @Override 44 | public void setParam(PreparedStatement stmt) throws SQLException { 45 | stmt.setString(index, (String) values[0]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/jdbc/param/URLParamContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-19 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.group.jdbc.param; 17 | 18 | import java.net.URL; 19 | import java.sql.PreparedStatement; 20 | import java.sql.SQLException; 21 | 22 | /** 23 | * TODO Comment of URLParamContext 24 | * 25 | * @author Leo Liang 26 | */ 27 | public class URLParamContext extends ParamContext { 28 | 29 | private static final long serialVersionUID = -4146564212387933157L; 30 | 31 | /** 32 | * @param index 33 | * @param values 34 | */ 35 | public URLParamContext(int index, Object[] values) { 36 | super(index, values); 37 | } 38 | 39 | /* 40 | * (non-Javadoc) 41 | * 42 | * @see com.dianping.zebra.jdbc.param.ParamContext#setParam(java.sql. PreparedStatement) 43 | */ 44 | @Override 45 | public void setParam(PreparedStatement stmt) throws SQLException { 46 | stmt.setURL(index, (URL) values[0]); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/monitor/GroupDataSourceMBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.monitor; 20 | 21 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 22 | 23 | import java.util.Map; 24 | 25 | public interface GroupDataSourceMBean { 26 | 27 | public Map getReaderSingleDataSourceMBean(); 28 | 29 | public SingleDataSourceMBean getWriteSingleDataSourceMBean(); 30 | 31 | public GroupDataSourceConfig getConfig(); 32 | } 33 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/router/DataSourceRouter.java: -------------------------------------------------------------------------------- 1 | /* * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.dianping.zebra.group.router; import java.util.regex.Pattern; /** * 对等DataSource选择器。 */ public interface DataSourceRouter { Pattern JDBC_URL_PATTERN = Pattern.compile("jdbc:mysql://([^:]+:\\d+)/([^\\?]+).*"); /** * 路由策略名称 */ String getName(); /** * 对等DataSource选择器。 在数据完全相同的一组DataSource中选择一个DataSource */ RouterTarget select(RouterContext routerContext); } -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/router/ReadWriteStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.router; 20 | 21 | import com.dianping.zebra.group.config.datasource.entity.GroupDataSourceConfig; 22 | 23 | /** 24 | * 25 | * @author hao.zhu 26 | * 27 | */ 28 | public interface ReadWriteStrategy { 29 | boolean shouldReadFromMaster(); 30 | 31 | void setGroupDataSourceConfig(GroupDataSourceConfig config); 32 | } 33 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/group/util/DataSourceState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.group.util; 20 | 21 | public enum DataSourceState { 22 | 23 | INITIAL, 24 | 25 | UP, 26 | 27 | DOWN, 28 | 29 | //TO_BE_DOWN, 30 | 31 | CLOSED, 32 | } 33 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/log/EmptyLogger.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.log; 2 | 3 | public class EmptyLogger implements Logger { 4 | public EmptyLogger(String loggerName) { 5 | 6 | } 7 | 8 | @Override 9 | public boolean isDebugEnabled() { 10 | return false; 11 | } 12 | 13 | @Override 14 | public void error(String msg, Throwable e) { 15 | 16 | } 17 | 18 | @Override 19 | public void error(String msg) { 20 | 21 | } 22 | 23 | @Override 24 | public void info(String msg) { 25 | 26 | } 27 | 28 | @Override 29 | public void debug(String msg) { 30 | 31 | } 32 | 33 | @Override 34 | public void debug(String msg, Throwable e) { 35 | 36 | } 37 | 38 | @Override 39 | public void warn(String msg) { 40 | 41 | } 42 | 43 | @Override 44 | public void warn(String msg, Throwable e) { 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/log/Log4jLogger.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.log; 2 | 3 | import org.apache.log4j.LogManager; 4 | import org.apache.log4j.xml.DOMConfigurator; 5 | 6 | public class Log4jLogger implements Logger { 7 | private org.apache.log4j.Logger logger; 8 | 9 | static { 10 | init(); 11 | } 12 | 13 | private static synchronized void init() { 14 | new DOMConfigurator().doConfigure(Log4jLogger.class.getResource("zebra_log4j.xml"), 15 | LogManager.getLoggerRepository()); 16 | } 17 | 18 | public Log4jLogger(String loggerName) { 19 | this.logger = org.apache.log4j.Logger.getLogger(loggerName); 20 | } 21 | 22 | @Override 23 | public void debug(String message) { 24 | logger.debug(message); 25 | } 26 | 27 | @Override 28 | public void debug(String msg, Throwable e) { 29 | 30 | } 31 | 32 | @Override 33 | public void info(String message) { 34 | logger.info(message); 35 | } 36 | 37 | @Override 38 | public void warn(String message) { 39 | logger.warn(message); 40 | } 41 | 42 | @Override 43 | public void warn(String message, Throwable t) { 44 | logger.warn(message, t); 45 | } 46 | 47 | @Override 48 | public void error(String message) { 49 | logger.error(message); 50 | } 51 | 52 | @Override 53 | public void error(String message, Throwable t) { 54 | logger.error(message, t); 55 | } 56 | 57 | @Override 58 | public boolean isDebugEnabled() { 59 | return logger.isDebugEnabled(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/log/Logger.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.log; 2 | 3 | public interface Logger { 4 | boolean isDebugEnabled(); 5 | 6 | void error(String msg, Throwable e); 7 | 8 | void error(String msg); 9 | 10 | void info(String msg); 11 | 12 | void debug(String msg); 13 | 14 | void debug(String msg, Throwable e); 15 | 16 | void warn(String msg); 17 | 18 | void warn(String msg, Throwable e); 19 | } 20 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/log/SimpleLogger.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.log; 2 | 3 | public class SimpleLogger implements Logger { 4 | public SimpleLogger(String loggerName) { 5 | 6 | } 7 | 8 | @Override 9 | public void debug(String message) { 10 | System.out.println(message); 11 | } 12 | 13 | @Override 14 | public void debug(String msg, Throwable e) { 15 | 16 | } 17 | 18 | @Override 19 | public void info(String message) { 20 | System.out.println(message); 21 | } 22 | 23 | @Override 24 | public void warn(String message) { 25 | System.out.println(message); 26 | } 27 | 28 | @Override 29 | public void warn(String message, Throwable t) { 30 | System.out.println(message); 31 | t.printStackTrace(System.out); 32 | } 33 | 34 | @Override 35 | public void error(String message) { 36 | System.err.println(message); 37 | } 38 | 39 | @Override 40 | public boolean isDebugEnabled() { 41 | return false; 42 | } 43 | 44 | @Override 45 | public void error(String message, Throwable t) { 46 | System.err.println(message); 47 | t.printStackTrace(System.err); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/log/Slf4jLogger.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.log; 2 | 3 | public class Slf4jLogger implements Logger { 4 | private org.slf4j.Logger logger; 5 | 6 | public Slf4jLogger(String loggerName) { 7 | this.logger = org.slf4j.LoggerFactory.getLogger(loggerName); 8 | } 9 | 10 | @Override 11 | public void debug(String message) { 12 | logger.debug(message); 13 | } 14 | 15 | @Override 16 | public void debug(String msg, Throwable e) { 17 | logger.debug(msg, e); 18 | } 19 | 20 | @Override 21 | public void info(String message) { 22 | logger.info(message); 23 | } 24 | 25 | @Override 26 | public void warn(String message) { 27 | logger.warn(message); 28 | } 29 | 30 | @Override 31 | public void warn(String message, Throwable t) { 32 | logger.warn(message, t); 33 | } 34 | 35 | @Override 36 | public void error(String message) { 37 | logger.error(message); 38 | } 39 | 40 | @Override 41 | public boolean isDebugEnabled() { 42 | return logger.isDebugEnabled(); 43 | } 44 | 45 | @Override 46 | public void error(String message, Throwable t) { 47 | logger.error(message, t); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/idgen/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.idgen; 20 | 21 | public interface IdGenerator { 22 | void init(); 23 | 24 | long nextId(); 25 | 26 | long nextId(String nameColumn); 27 | 28 | IdRange nextBatch(String nameColumn); 29 | 30 | IdRange nextBatch(String nameColumn, int batchSize); 31 | } 32 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/idgen/IdTimeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.idgen; 20 | 21 | public interface IdTimeService { 22 | long getCurrentTimeMillis(); 23 | } 24 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/idgen/impl/DefaultIdTimeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.idgen.impl; 20 | 21 | import com.dianping.zebra.shard.idgen.IdTimeService; 22 | 23 | public class DefaultIdTimeService implements IdTimeService { 24 | 25 | @Override 26 | public long getCurrentTimeMillis() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/merge/DataMerger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.merge; 20 | 21 | import java.sql.SQLException; 22 | import java.util.List; 23 | 24 | public interface DataMerger { 25 | 26 | public List process(List sourceData, MergeContext mergeContext) throws SQLException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/merge/groupby/Aggregator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-22 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.shard.merge.groupby; 17 | 18 | import com.dianping.zebra.shard.merge.groupby.aggregate.AggregateException; 19 | 20 | /** 21 | *

22 | * 聚合函数的数据处理器接口 23 | *

24 | * 25 | * @author Leo Liang 26 | * 27 | */ 28 | public interface Aggregator { 29 | 30 | /** 31 | * 根据旧值和当前值计算新值并返回
32 | * 33 | * 注意:如果旧值为null则应该根据当前值返回一个合适的初始值 34 | * 35 | * 36 | * @param oldValue 37 | * 旧值 38 | * @param currentValue 39 | * 当前值 40 | * @return 新的计算结果值 41 | * @throws AggregateException 42 | */ 43 | public Object process(Object oldValue, Object currentValue) throws AggregateException; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/merge/groupby/aggregate/AggregateException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: zebra-client 3 | * 4 | * File Created at 2011-6-24 5 | * $Id$ 6 | * 7 | * Copyright 2010 dianping.com. 8 | * All rights reserved. 9 | * 10 | * This software is the confidential and proprietary information of 11 | * Dianping Company. ("Confidential Information"). You shall not 12 | * disclose such Confidential Information and shall use it only in 13 | * accordance with the terms of the license agreement you entered into 14 | * with dianping.com. 15 | */ 16 | package com.dianping.zebra.shard.merge.groupby.aggregate; 17 | 18 | /** 19 | * AggregateDataProcessor处理中抛出的异常 20 | * 21 | * @author Leo Liang 22 | * 23 | */ 24 | public class AggregateException extends Exception { 25 | 26 | private static final long serialVersionUID = -4563750786940638103L; 27 | 28 | public AggregateException(String msg) { 29 | super(msg); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/parser/visitor/MySQLDeleteASTVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.parser.visitor; 20 | 21 | import com.dianping.zebra.shard.parser.SQLParsedResult; 22 | 23 | public class MySQLDeleteASTVisitor extends AbstractMySQLASTVisitor { 24 | 25 | public MySQLDeleteASTVisitor(SQLParsedResult result) { 26 | super(result); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/parser/visitor/MySQLInsertASTVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.parser.visitor; 20 | 21 | import com.dianping.zebra.shard.parser.SQLParsedResult; 22 | 23 | public class MySQLInsertASTVisitor extends AbstractMySQLASTVisitor { 24 | 25 | public MySQLInsertASTVisitor(SQLParsedResult result) { 26 | super(result); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/parser/visitor/MySQLReplaceASTVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.parser.visitor; 20 | 21 | import com.dianping.zebra.shard.parser.SQLParsedResult; 22 | 23 | public class MySQLReplaceASTVisitor extends AbstractMySQLASTVisitor { 24 | 25 | public MySQLReplaceASTVisitor(SQLParsedResult result) { 26 | super(result); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/parser/visitor/MySQLUpdateASTVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.parser.visitor; 20 | 21 | import com.dianping.zebra.shard.parser.SQLParsedResult; 22 | 23 | public class MySQLUpdateASTVisitor extends AbstractMySQLASTVisitor { 24 | 25 | public MySQLUpdateASTVisitor(SQLParsedResult result) { 26 | super(result); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/router/RouterBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.router; 20 | 21 | /** 22 | * @author danson.liu 23 | * 24 | */ 25 | public interface RouterBuilder { 26 | 27 | ShardRouter build(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/router/rule/engine/RuleEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.router.rule.engine; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * @author danson.liu 25 | * 26 | */ 27 | public interface RuleEngine { 28 | 29 | Object eval(Map valMap); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/shard/router/rule/tableset/TableSetsManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.shard.router.rule.tableset; 20 | 21 | import java.util.Map; 22 | import java.util.Set; 23 | 24 | /** 25 | * @author hao.zhu 26 | * 27 | */ 28 | public interface TableSetsManager { 29 | 30 | TableSets getTableSetsByPos(int dbPos); 31 | 32 | Map> getAllTableSets(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/single/jdbc/C3p0SingleDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.single.jdbc; 20 | 21 | import com.dianping.zebra.log.Logger; 22 | import com.dianping.zebra.log.LoggerFactory; 23 | 24 | public class C3p0SingleDataSource extends SingleDataSource { 25 | 26 | protected static final Logger LOGGER = LoggerFactory.getLogger(C3p0SingleDataSource.class); 27 | 28 | @Override 29 | protected Logger getLogger() { 30 | return LOGGER; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /zebra-client/src/main/java/com/dianping/zebra/single/jdbc/DataSourceLifeCycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.single.jdbc; 20 | 21 | import java.sql.SQLException; 22 | 23 | import com.dianping.zebra.group.util.DataSourceState; 24 | 25 | public interface DataSourceLifeCycle { 26 | 27 | DataSourceState getState(); 28 | 29 | void init(); 30 | 31 | void markClosed(); 32 | 33 | void markDown(); 34 | 35 | void markUp(); 36 | 37 | void close() throws SQLException; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /zebra-client/src/main/resources/META-INF/services/com.dianping.zebra.config.ConfigService: -------------------------------------------------------------------------------- 1 | com.dianping.zebra.config.ZookeeperConfigService 2 | com.dianping.zebra.config.PropertyConfigService 3 | com.dianping.zebra.config.RemoteConfigService -------------------------------------------------------------------------------- /zebra-client/src/main/resources/META-INF/services/com.dianping.zebra.group.router.ReadWriteStrategy: -------------------------------------------------------------------------------- 1 | com.dianping.zebra.group.router.LocalContextReadWriteStrategy -------------------------------------------------------------------------------- /zebra-client/src/main/resources/META-INF/zebra-filter.properties: -------------------------------------------------------------------------------- 1 | zebra.filter.wall=com.dianping.zebra.filter.wall.WallFilter -------------------------------------------------------------------------------- /zebra-client/src/main/resources/zebra_log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /zebra-client/src/main/resources/zebra_log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/filter/DefaultFilterManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.filter; 2 | 3 | /** 4 | * Created by Dozer on 9/2/14. 5 | */ 6 | 7 | import com.dianping.zebra.Constants; 8 | import junit.framework.Assert; 9 | import org.junit.Test; 10 | 11 | import com.dianping.zebra.filter.FilterManagerFactory; 12 | import com.dianping.zebra.filter.JdbcFilter; 13 | 14 | import java.util.List; 15 | 16 | public class DefaultFilterManagerTest { 17 | 18 | @Test 19 | public void test_load_by_empty_name() { 20 | List filters = FilterManagerFactory.getFilterManager().loadFilters("", Constants.CONFIG_MANAGER_TYPE_REMOTE, null); 21 | Assert.assertEquals(filters.size(), 0); 22 | } 23 | 24 | @Test 25 | public void test_load_by_name() { 26 | List filters = FilterManagerFactory.getFilterManager().loadFilters("wall", Constants.CONFIG_MANAGER_TYPE_REMOTE, null); 27 | Assert.assertEquals(filters.size(), 1); 28 | } 29 | 30 | @Test 31 | public void test_load_by_two_name() { 32 | List filters = FilterManagerFactory.getFilterManager().loadFilters("wall,no_exist", Constants.CONFIG_MANAGER_TYPE_REMOTE, null); 33 | Assert.assertEquals(filters.size(), 1); 34 | } 35 | 36 | @Test 37 | public void test_load_null() { 38 | List filters = FilterManagerFactory.getFilterManager().loadFilters(null, Constants.CONFIG_MANAGER_TYPE_REMOTE, null); 39 | Assert.assertEquals(filters.size(), 0); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/filter/MockFilterHelper.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.filter; 2 | 3 | /** 4 | * Created by Dozer on 9/10/14. 5 | */ 6 | 7 | import org.mockito.Mockito; 8 | 9 | import com.dianping.zebra.filter.DefaultJdbcFilter; 10 | import com.dianping.zebra.filter.FilterManager; 11 | import com.dianping.zebra.filter.FilterManagerFactory; 12 | import com.dianping.zebra.filter.JdbcFilter; 13 | 14 | public class MockFilterHelper { 15 | private static JdbcFilter mockedFilter = Mockito.spy(new DefaultJdbcFilter()); 16 | 17 | public static JdbcFilter getMockedFilter() { 18 | return mockedFilter; 19 | } 20 | 21 | public static void injectMockFilter() { 22 | FilterManager manager = FilterManagerFactory.getFilterManager(); 23 | manager.addFilter("mock", mockedFilter); 24 | } 25 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/filter/wall/SqlFlowIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.filter.wall; 2 | 3 | import java.security.NoSuchAlgorithmException; 4 | 5 | import com.dianping.zebra.util.StringUtils; 6 | import junit.framework.Assert; 7 | import org.junit.Test; 8 | 9 | public class SqlFlowIdGenerator { 10 | 11 | @Test 12 | public void test() throws NoSuchAlgorithmException { 13 | String token = String.format("/*%s*/%s", "dianpingm3-m1-write", "SwitchsInfo.getAllSwitchsInfo"); 14 | String resultId = StringUtils.md5(token).substring(0, 8); 15 | 16 | Assert.assertEquals("f14b190b", resultId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/jdbc/DataSourceEntry.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.jdbc; 2 | 3 | public class DataSourceEntry { 4 | private String dataSets; 5 | 6 | private String jdbcUrl; 7 | 8 | private boolean isWrite; 9 | 10 | public DataSourceEntry(String jdbcUrl, String dataSets, boolean isWrite) { 11 | this.jdbcUrl = jdbcUrl; 12 | this.dataSets = dataSets; 13 | this.isWrite = isWrite; 14 | } 15 | 16 | public String getDataSets() { 17 | return dataSets; 18 | } 19 | 20 | public String getJdbcUrl() { 21 | return jdbcUrl; 22 | } 23 | 24 | public boolean isWrite() { 25 | return isWrite; 26 | } 27 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/jdbc/GroupDataSourceC3P0FieldTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.jdbc; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | 7 | import com.dianping.zebra.group.jdbc.GroupDataSource; 8 | import com.dianping.zebra.single.jdbc.AbstractSingleDataSourceTest; 9 | import com.google.common.collect.Lists; 10 | import com.mchange.v2.c3p0.ComboPooledDataSource; 11 | 12 | public class GroupDataSourceC3P0FieldTest extends AbstractSingleDataSourceTest { 13 | 14 | @Test 15 | public void test() { 16 | assertField(GroupDataSource.class, ComboPooledDataSource.class, 17 | Lists.newArrayList("setJdbcUrl", "setPassword", "setUser","setIdentityToken")); 18 | } 19 | 20 | @Override 21 | protected List getNotSupportedMethod() { 22 | return Lists.newArrayList(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/router/LocalContextReadWriteStrategyTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.router; 2 | 3 | import junit.framework.Assert; 4 | 5 | import org.junit.After; 6 | import org.junit.Test; 7 | 8 | public class LocalContextReadWriteStrategyTest { 9 | 10 | @Test 11 | public void test_force_master() { 12 | LocalContextReadWriteStrategy.setReadFromMaster(); 13 | LocalContextReadWriteStrategy strategy = new LocalContextReadWriteStrategy(); 14 | 15 | Assert.assertTrue(strategy.shouldReadFromMaster()); 16 | } 17 | 18 | @After 19 | public void clearContext(){ 20 | LocalContextReadWriteStrategy.clearContext(); 21 | } 22 | 23 | @Test 24 | public void test_clear_context() { 25 | LocalContextReadWriteStrategy strategy = new LocalContextReadWriteStrategy(); 26 | Assert.assertFalse(strategy.shouldReadFromMaster()); 27 | 28 | LocalContextReadWriteStrategy.setReadFromMaster(); 29 | Assert.assertTrue(strategy.shouldReadFromMaster()); 30 | 31 | LocalContextReadWriteStrategy.clearContext(); 32 | Assert.assertFalse(strategy.shouldReadFromMaster()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/router/ReadWriteStrategyServiceLoaderTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.router; 2 | 3 | import java.util.ServiceLoader; 4 | 5 | import junit.framework.Assert; 6 | 7 | import org.junit.Test; 8 | 9 | public class ReadWriteStrategyServiceLoaderTest { 10 | 11 | @Test 12 | public void load_dpdl_readWriteStrategy(){ 13 | ServiceLoader strategies = ServiceLoader.load(ReadWriteStrategy.class); 14 | 15 | int size = 0; 16 | if (strategies != null) { 17 | for (ReadWriteStrategy strategy : strategies) { 18 | size++; 19 | 20 | if(size == 1){ 21 | Assert.assertEquals(true, strategy instanceof LocalContextReadWriteStrategy); 22 | } 23 | } 24 | 25 | Assert.assertEquals(1, size); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/util/AppPropertiesUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.util; 2 | 3 | import com.dianping.zebra.util.AppPropertiesUtils; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class AppPropertiesUtilsTest { 8 | 9 | @Test 10 | public void test(){ 11 | Assert.assertEquals("zebra_ut", AppPropertiesUtils.getAppName()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/group/util/SmoothReloadTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.group.util; 2 | 3 | import java.util.Random; 4 | 5 | import junit.framework.Assert; 6 | 7 | import org.junit.Test; 8 | 9 | public class SmoothReloadTest { 10 | 11 | @Test 12 | public void test_smooth_reload() { 13 | Random rnd = new Random(); 14 | long maxTime = rnd.nextInt(1000); 15 | 16 | SmoothReload sr = new SmoothReload(maxTime); 17 | long now = System.currentTimeMillis(); 18 | sr.waitForReload(); 19 | long interval = System.currentTimeMillis() - now; 20 | 21 | System.out.println(String.format("SmoothReload Actual Time: %d", interval)); 22 | System.out.println(String.format("SmoothReload Max Time: %d", maxTime)); 23 | 24 | Assert.assertTrue(interval >= 0); 25 | Assert.assertTrue(interval <= maxTime + SmoothReload.SLEEP_TIME); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/shard/config/XmlDataSourceRouterConfigLoaderTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.shard.config; 2 | 3 | import com.dianping.zebra.shard.router.builder.XmlDataSourceRouterConfigLoader; 4 | import org.junit.Test; 5 | 6 | public class XmlDataSourceRouterConfigLoaderTest { 7 | 8 | @Test 9 | public void testLoadConfig() throws Exception { 10 | XmlDataSourceRouterConfigLoader loader = new XmlDataSourceRouterConfigLoader(); 11 | RouterRuleConfig config = loader.loadConfig("router-rule-multidb-lifecycle.xml"); 12 | 13 | System.out.println(config); 14 | } 15 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/shard/jdbc/base/DBDataEntry.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.shard.jdbc.base; 2 | 3 | import java.util.List; 4 | 5 | public class DBDataEntry { 6 | private String dbName; 7 | private List scripts; 8 | 9 | private String username; 10 | private String password; 11 | 12 | /** 13 | * @return the dbName 14 | */ 15 | public String getDbName() { 16 | return dbName; 17 | } 18 | 19 | /** 20 | * @param dbName 21 | * the dbName to set 22 | */ 23 | public void setDbName(String dbName) { 24 | this.dbName = dbName; 25 | } 26 | 27 | /** 28 | * @return the scripts 29 | */ 30 | public List getScripts() { 31 | return scripts; 32 | } 33 | 34 | /** 35 | * @param scripts 36 | * the scripts to set 37 | */ 38 | public void setScripts(List scripts) { 39 | this.scripts = scripts; 40 | } 41 | 42 | public String getUsername() { 43 | return username; 44 | } 45 | 46 | public void setUsername(String username) { 47 | this.username = username; 48 | } 49 | 50 | public String getPassword() { 51 | return password; 52 | } 53 | 54 | public void setPassword(String password) { 55 | this.password = password; 56 | } 57 | 58 | public boolean isUseEncryption() { 59 | return !(null == username || "".equals(username) || null == password || "".equals(password)); 60 | } 61 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/shard/jdbc/base/SingleCreateTableScriptEntry.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.shard.jdbc.base; 2 | 3 | public class SingleCreateTableScriptEntry { 4 | private String tableName; 5 | private String createTableScript; 6 | 7 | /** 8 | * @return the tableName 9 | */ 10 | public String getTableName() { 11 | return tableName; 12 | } 13 | 14 | /** 15 | * @param tableName 16 | * the tableName to set 17 | */ 18 | public void setTableName(String tableName) { 19 | this.tableName = tableName; 20 | } 21 | 22 | /** 23 | * @return the createTableScript 24 | */ 25 | public String getCreateTableScript() { 26 | return createTableScript; 27 | } 28 | 29 | /** 30 | * @param createTableScript 31 | * the createTableScript to set 32 | */ 33 | public void setCreateTableScript(String createTableScript) { 34 | this.createTableScript = createTableScript; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/shard/jdbc/parallel/MockCallable.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.shard.jdbc.parallel; 2 | 3 | import java.sql.SQLException; 4 | import java.util.concurrent.Callable; 5 | import java.util.concurrent.CancellationException; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | public class MockCallable implements Callable { 9 | 10 | private MockType type; 11 | 12 | private long executeTime; 13 | 14 | private int result; 15 | 16 | public MockCallable(MockType type, long executeTime, int result) { 17 | this.type = type; 18 | this.executeTime = executeTime; 19 | this.result = result; 20 | } 21 | 22 | @Override 23 | public Integer call() throws Exception { 24 | switch (type) { 25 | case TIMEOUT: 26 | TimeUnit.MILLISECONDS.sleep(1010); 27 | break; 28 | case INTERRUPT: 29 | throw new InterruptedException(); 30 | case CANCEL: 31 | throw new CancellationException("Cancel"); 32 | case SQLEXCEPTION: 33 | throw new SQLException("SQLERROR"); 34 | case NORMAL: 35 | TimeUnit.MILLISECONDS.sleep(executeTime); 36 | return result; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | public static enum MockType { 43 | NORMAL, TIMEOUT, INTERRUPT, SQLEXCEPTION, CANCEL 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/shard/router/rule/engine/RuleEngineBaseTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.shard.router.rule.engine; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * Dozer @ 6/15/15 9 | * mail@dozer.cc 10 | * http://www.dozer.cc 11 | */ 12 | public class RuleEngineBaseTest { 13 | 14 | @Test 15 | public void testDate() throws Exception { 16 | RuleEngineBase target = new RuleEngineBase(); 17 | Date result = target.date("2015-01-01 19:02:02.0001"); 18 | System.out.println(result.toString()); 19 | } 20 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/single/AllTests.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.single; 2 | 3 | import com.dianping.zebra.single.jdbc.*; 4 | import org.junit.runner.RunWith; 5 | import org.junit.runners.Suite; 6 | 7 | @RunWith(Suite.class) 8 | @Suite.SuiteClasses({ 9 | // jdbc 10 | SingleDataSourceTest.class, 11 | C3p0SingleDataSourceFieldTest.class, 12 | DruidSingleDataSourceTest.class, 13 | TomcatJdbcSingleDataSourceFieldTest.class, 14 | //dbcp2和dbcp不能同时测试,需要切换jdk版本 15 | Dbcp2SingleDataSourceFieldTest.class, 16 | DbcpSingleDataSourceFieldTest.class, 17 | 18 | 19 | }) 20 | public class AllTests { 21 | 22 | } -------------------------------------------------------------------------------- /zebra-client/src/test/java/com/dianping/zebra/util/ConfigServiceMock.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.util; 2 | 3 | import com.dianping.zebra.config.ConfigService; 4 | 5 | import java.beans.PropertyChangeListener; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | /** 10 | * Dozer @ 2015-02 11 | * mail@dozer.cc 12 | * http://www.dozer.cc 13 | */ 14 | public class ConfigServiceMock implements ConfigService { 15 | private final Map configs = new ConcurrentHashMap(); 16 | 17 | @Override 18 | public void init(Map configs) { 19 | 20 | } 21 | 22 | @Override 23 | public String getProperty(String key) { 24 | String result = configs.get(key); 25 | System.out.println(String.format("Read Config: key = %s value = %s", key, result)); 26 | return result; 27 | } 28 | 29 | @Override 30 | public void addPropertyChangeListener(PropertyChangeListener listener) { 31 | 32 | } 33 | 34 | public ConfigServiceMock addProperty(String key, String value) { 35 | configs.put(key, value); 36 | return this; 37 | } 38 | 39 | @Override 40 | public void destroy() { 41 | // TODO Auto-generated method stub 42 | 43 | } 44 | 45 | @Override 46 | public void removePropertyChangeListener(PropertyChangeListener listener) { 47 | // TODO Auto-generated method stub 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/app.properties: -------------------------------------------------------------------------------- 1 | app.name=zebra_ut -------------------------------------------------------------------------------- /zebra-client/src/test/resources/concurrency-gds0.properties: -------------------------------------------------------------------------------- 1 | zebra.group.concurrency-gds0=\ 2 | \ 3 | gds0-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | gds0-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.gds0-n1=\ 15 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.gds0-n2=\ 21 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/concurrency-gds1.properties: -------------------------------------------------------------------------------- 1 | zebra.group.concurrency-gds1=\ 2 | \ 3 | gds1-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | gds1-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.gds1-n1=\ 15 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.gds1-n2=\ 21 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/ctx-specialsql.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/datasets.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/datasets1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/datasets2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/db-datafiles/data-join-lifecycle.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-client/src/test/resources/db-datafiles/data-join-lifecycle.xml -------------------------------------------------------------------------------- /zebra-client/src/test/resources/db-datafiles/data-limitdb-lifecycle.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meituan-Dianping/Zebra/33d74b831abe7e8e2d29f8c4e145e46ba17432dc/zebra-client/src/test/resources/db-datafiles/data-limitdb-lifecycle.xml -------------------------------------------------------------------------------- /zebra-client/src/test/resources/db-router-xml-rule-zeropadding.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/db-router-xml-rule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/defaultStrategy-gds.properties: -------------------------------------------------------------------------------- 1 | zebra.group.defaultStrategy-gds=\ 2 | \ 3 | defaultStrategy-gds-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | defaultStrategy-gds-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.defaultStrategy-gds-n1=\ 15 | jdbc:h2:mem:DefaultTestDb;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/group01.properties: -------------------------------------------------------------------------------- 1 | zebra.group.group01=\ 2 | \ 3 | group01-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | group01-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.group01-n1=\ 15 | jdbc:h2:mem:test01m;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.group01-n2=\ 21 | jdbc:h2:mem:test01s;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/group02.properties: -------------------------------------------------------------------------------- 1 | zebra.group.group02=\ 2 | \ 3 | group02-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | group02-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.group02-n1=\ 15 | jdbc:h2:mem:test02m;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.group02-n2=\ 21 | jdbc:h2:mem:test02s;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO,console 2 | log4j.additivity.org.apache=true 3 | 4 | log4j.appender.console=org.apache.log4j.ConsoleAppender 5 | log4j.appender.console.Threshold=DEBUG 6 | log4j.appender.console.ImmediateFlush=true 7 | log4j.appender.console.Target=System.out 8 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.console.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n 10 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testConcurrency/data-multidb-concurrency.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testConcurrency/router-multidb-concurrency.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testDefaultStrategy/createtable-multidb-defaultstrategy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 15 |
16 | 17 | 26 |
27 | 28 | 35 |
36 | 37 |
38 |
39 |
-------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testDefaultStrategy/data-multidb-defaultstrategy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 17 | 18 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testDefaultStrategy/router-multidb-defaultstrategy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testRangeCross/router-rule-multidb-rangetest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testRangeDefault/router-rule-multidb-rangetest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/mockdb-config/testReplace/router-multidb-replacetest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/model/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/multisk-gds0.properties: -------------------------------------------------------------------------------- 1 | zebra.group.multisk-gds0=\ 2 | \ 3 | multisk-gds0-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | multisk-gds0-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.multisk-gds0-n1=\ 15 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.multisk-gds0-n2=\ 21 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/multisk-gds1.properties: -------------------------------------------------------------------------------- 1 | zebra.group.multisk-gds1=\ 2 | \ 3 | multisk-gds1-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | multisk-gds1-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.multisk-gds1-n1=\ 15 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.multisk-gds1-n2=\ 21 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/performance/appcontext-aop-core.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/rangetest-gds0.properties: -------------------------------------------------------------------------------- 1 | zebra.group.rangetest-gds0=\ 2 | \ 3 | rangetest-gds0-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | rangetest-gds0-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.rangetest-gds0-n1=\ 15 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.rangetest-gds0-n2=\ 21 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/rangetest-gds1.properties: -------------------------------------------------------------------------------- 1 | zebra.group.rangetest-gds1=\ 2 | \ 3 | rangetest-gds1-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | rangetest-gds1-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.rangetest-gds1-n1=\ 15 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.rangetest-gds1-n2=\ 21 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/region/center.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "centers" : [ 4 | {"center":"center1","priority":2, "idcs":[ 5 | {"idc" : "idc1", "desc" : "机房1"}, 6 | {"idc" : "idc2", "desc" : "机房2"}, 7 | {"idc" : "idc3", "desc" : "机房3"} 8 | ]}, 9 | {"center":"center2","priority":1,"idcs":[ 10 | {"idc" : "idc4", "desc" : "机房4"} 11 | ]} 12 | ]}, 13 | {"region" : "region2", "centers" : [ 14 | {"center":"center3","priority":1,"idcs":[ 15 | {"idc" : "idc5", "desc" : "机房5"}, 16 | {"idc" : "idc6", "desc" : "机房6"} 17 | ]} 18 | ]} 19 | ] 20 | } -------------------------------------------------------------------------------- /zebra-client/src/test/resources/region/idc.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "idcs" : [ 4 | {"idc" : "idc1", "net" : ["192.1", "192.2"], "desc" : "机房1"}, 5 | {"idc" : "idc2", "net" : ["192.3", "192.4"], "desc" : "机房2"}, 6 | {"idc" : "idc3", "net" : ["192.5"], "desc" : "机房3"}, 7 | {"idc" : "idc4", "net" : ["192.6"], "desc" : "机房4"} 8 | ]}, 9 | {"region" : "region2", "idcs" : [ 10 | {"idc" : "idc5", "net" : ["192.10", "192.11"], "desc" : "机房5"}, 11 | {"idc" : "idc6", "net" : ["192.20", "192.21"], "desc" : "机房6"} 12 | ]} 13 | ] 14 | } -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-multidb-lifecycle-group.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-multidb-lifecycle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-multidb-multikey-lifecycle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-multidb-shardtest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-singledb-group-follownote-integrationtest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-singledb-lifecycle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/router-rule-specialsql.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/sample.ds.error.properties: -------------------------------------------------------------------------------- 1 | zebra.default.filters=mock,stat 2 | 3 | zebra.group.sample.ds.error=\ 4 | \ 5 | db-n1\ 6 | 1\ 7 | 0\ 8 | \ 9 | \ 10 | db-n2\ 11 | 1\ 12 | 1\ 13 | \ 14 | \ 15 | db-n3\ 16 | 0\ 17 | 1\ 18 | \ 19 | 20 | 21 | zebra.ds.db-n1=\ 22 | jdbc:h2:mem:testError;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 23 | org.h2.Driver\ 24 | true\ 25 | 26 | 27 | zebra.ds.db-n2=\ 28 | jdbc:mysql://127.0.0.1:3306/testError?characterEncoding=UTF8\ 29 | com.mysql.jdbc.Driver\ 30 | true\ 31 | 32 | 33 | zebra.ds.db-n3=\ 34 | jdbc:h2:mem:testError;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 35 | org.h2.Driver\ 36 | true\ 37 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/sample.ds.v3.properties: -------------------------------------------------------------------------------- 1 | zebra_ut.zebra.pool.type=tomcat-jdbc 2 | zebra.default.filters=mock,stat,finalsql,wall 3 | groupds-security.global.security= 4 | groupds-security.global.switch=true 5 | groupds-security.sample.switch=true 6 | groupds-security.sample.security=zebra-* 7 | 8 | zebra.group.sample.ds.v3=\ 9 | \ 10 | db-n1\ 11 | 1\ 12 | -1\ 13 | \ 14 | \ 15 | db-n2\ 16 | -1\ 17 | 1\ 18 | \ 19 | 20 | 21 | zebra.ds.db-n1=\ 22 | jdbc:h2:mem:test;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 23 | sa\ 24 | \ 25 | org.h2.Driver\ 26 | true\ 27 | 28 | 29 | zebra.ds.db-n2=\ 30 | jdbc:h2:mem:test1;MVCC=TRUE\ 31 | sa\ 32 | \ 33 | org.h2.Driver\ 34 | true\ 35 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create table if not exists PERSON ( 2 | ID int identity primary key, 3 | NAME varchar, 4 | LAST_NAME varchar, 5 | AGE smallint 6 | ) -------------------------------------------------------------------------------- /zebra-client/src/test/resources/shardtest-gds0.properties: -------------------------------------------------------------------------------- 1 | zebra.group.shardtest-gds0=\ 2 | \ 3 | shardtest-gds0-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | shardtest-gds0-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.shardtest-gds0-n1=\ 15 | jdbc:h2:mem:database0;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.shardtest-gds0-n2=\ 21 | jdbc:h2:mem:database0;MVCC=TRUE\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/shardtest-gds1.properties: -------------------------------------------------------------------------------- 1 | zebra.group.shardtest-gds1=\ 2 | \ 3 | shardtest-gds1-n1\ 4 | 1\ 5 | 0\ 6 | \ 7 | \ 8 | shardtest-gds1-n2\ 9 | 0\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.shardtest-gds1-n1=\ 15 | jdbc:h2:mem:database1;MVCC=TRUE;DB_CLOSE_DELAY=-1\ 16 | org.h2.Driver\ 17 | true\ 18 | 19 | 20 | zebra.ds.shardtest-gds1-n2=\ 21 | jdbc:h2:mem:database1;MVCC=TRUE\ 22 | org.h2.Driver\ 23 | true\ 24 | -------------------------------------------------------------------------------- /zebra-client/src/test/resources/zebra.system.properties: -------------------------------------------------------------------------------- 1 | zebra_ut.zebra.system.retryTimes=3 2 | zebra.sql-blacklist.system.flowControl.72= 3 | -------------------------------------------------------------------------------- /zebra-dao/src/main/java/com/dianping/zebra/dao/AsyncDaoCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.dao; 20 | 21 | public interface AsyncDaoCallback { 22 | 23 | void onSuccess(T result); 24 | 25 | void onException(Exception e); 26 | } 27 | -------------------------------------------------------------------------------- /zebra-dao/src/main/java/com/dianping/zebra/dao/AsyncDaoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.dao; 20 | 21 | public class AsyncDaoException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 8478794463509821167L; 24 | 25 | public AsyncDaoException(String message) { 26 | super(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /zebra-dao/src/main/java/com/dianping/zebra/dao/annotation/TargetMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.dao.annotation; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.METHOD) 28 | public @interface TargetMethod { 29 | String name(); 30 | } 31 | -------------------------------------------------------------------------------- /zebra-dao/src/main/java/com/dianping/zebra/dao/datasource/ZebraRouting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved. 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one or more 5 | * contributor license agreements. See the NOTICE file distributed with 6 | * this work for additional information regarding copyright ownership. 7 | * The ASF licenses this file to You under the Apache License, Version 2.0 8 | * (the "License"); you may not use this file except in compliance with 9 | * the License. You may obtain a copy of the License at 10 | * 11 | *    http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package com.dianping.zebra.dao.datasource; 20 | 21 | import java.lang.annotation.*; 22 | 23 | @Target({ ElementType.METHOD, ElementType.TYPE }) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Inherited 26 | public @interface ZebraRouting { 27 | String value(); 28 | } 29 | -------------------------------------------------------------------------------- /zebra-sample/src/main/java/com/dianping/zebra/sample/dao/group/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.dao.group; 2 | 3 | import com.dianping.zebra.sample.entity.group.UserEntity; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | /** 7 | * @author tong.xin on 2018/10/29. 8 | */ 9 | public interface UserDao { 10 | void insert(UserEntity user); 11 | 12 | UserEntity searchUserById(@Param("id") int id); 13 | } 14 | -------------------------------------------------------------------------------- /zebra-sample/src/main/java/com/dianping/zebra/sample/dao/shard/FeedDao.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.dao.shard; 2 | 3 | import com.dianping.zebra.sample.entity.shard.FeedEntity; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | /** 7 | * @author tong.xin on 2018/11/8. 8 | */ 9 | public interface FeedDao { 10 | void insert(FeedEntity feedEntity); 11 | 12 | FeedEntity searchFeedByUid(@Param("uid") String uid); 13 | } 14 | -------------------------------------------------------------------------------- /zebra-sample/src/main/java/com/dianping/zebra/sample/entity/group/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.entity.group; 2 | 3 | import java.sql.Timestamp; 4 | import java.util.Date; 5 | 6 | /** 7 | * @author tong.xin on 2018/10/29. 8 | */ 9 | public class UserEntity { 10 | protected int id; 11 | 12 | protected String name; 13 | 14 | protected String mis; 15 | 16 | protected String email; 17 | 18 | protected Timestamp updateTime; 19 | 20 | protected Date createTime; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getMis() { 39 | return mis; 40 | } 41 | 42 | public void setMis(String mis) { 43 | this.mis = mis; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public Timestamp getUpdateTime() { 55 | return updateTime; 56 | } 57 | 58 | public void setUpdateTime(Timestamp updateTime) { 59 | this.updateTime = updateTime; 60 | } 61 | 62 | public Date getCreateTime() { 63 | return createTime; 64 | } 65 | 66 | public void setCreateTime(Date createTime) { 67 | this.createTime = createTime; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /zebra-sample/src/main/java/com/dianping/zebra/sample/entity/shard/FeedEntity.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.entity.shard; 2 | 3 | import java.sql.Timestamp; 4 | 5 | /** 6 | * @author tong.xin on 2018/11/8. 7 | */ 8 | public class FeedEntity { 9 | private int id; 10 | 11 | private String uid; 12 | 13 | private Timestamp updateTime; 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getUid() { 24 | return uid; 25 | } 26 | 27 | public void setUid(String uid) { 28 | this.uid = uid; 29 | } 30 | 31 | public Timestamp getUpdateTime() { 32 | return updateTime; 33 | } 34 | 35 | public void setUpdateTime(Timestamp updateTime) { 36 | this.updateTime = updateTime; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /zebra-sample/src/main/resources/mapper/group/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 9 | INSERT INTO `User` 10 | ( 11 | `Name`, 12 | `Mis`, 13 | `Email`, 14 | `UpdateTime`, 15 | `CreateTime`) 16 | VALUES 17 | ( 18 | #{name}, 19 | #{mis}, 20 | #{email}, 21 | NOW(), 22 | NOW()) 23 | 24 | 25 | 28 | -------------------------------------------------------------------------------- /zebra-sample/src/main/resources/mapper/shard/FeedMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 9 | INSERT INTO `Feed` 10 | ( 11 | `Uid`, 12 | `UpdateTime` 13 | ) 14 | VALUES 15 | ( 16 | #{uid}, 17 | NOW()) 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /zebra-sample/src/test/java/com/dianping/zebra/sample/mybatis/GroupDataSourceSample.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.mybatis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | import com.dianping.zebra.sample.dao.group.UserDao; 10 | import com.dianping.zebra.sample.entity.group.UserEntity; 11 | 12 | /** 13 | * @author tong.xin on 2018/10/29. 14 | */ 15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration({"classpath*:spring/group/group-db-config.xml"}) 18 | public class GroupDataSourceSample { 19 | 20 | @Autowired 21 | private UserDao userDao; 22 | 23 | @Test 24 | public void test(){ 25 | UserEntity user = new UserEntity(); 26 | user.setName("test_man"); 27 | user.setMis("test_group"); 28 | user.setEmail("test_man@meituan.com"); 29 | 30 | try { 31 | userDao.insert(user); 32 | UserEntity searchUser = userDao.searchUserById(user.getId()); 33 | 34 | System.out.println(searchUser.getName()); 35 | System.out.println(searchUser.getMis()); 36 | System.out.println(searchUser.getEmail()); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /zebra-sample/src/test/java/com/dianping/zebra/sample/mybatis/ShardDataSourceSample.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.mybatis; 2 | 3 | import com.dianping.zebra.sample.dao.group.UserDao; 4 | import com.dianping.zebra.sample.dao.shard.FeedDao; 5 | import com.dianping.zebra.sample.entity.group.UserEntity; 6 | import com.dianping.zebra.sample.entity.shard.FeedEntity; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | /** 14 | * @author tong.xin on 2018/10/29. 15 | */ 16 | 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration({"classpath*:spring/shard/shard-local-config.xml"}) 19 | public class ShardDataSourceSample { 20 | 21 | @Autowired 22 | private FeedDao feedDao; 23 | 24 | @Test 25 | public void test(){ 26 | String uid = "123456"; 27 | FeedEntity feed = new FeedEntity(); 28 | feed.setUid(uid); 29 | 30 | try { 31 | feedDao.insert(feed); 32 | 33 | FeedEntity searchFeed = feedDao.searchFeedByUid(uid); 34 | 35 | System.out.println(searchFeed.getUid()); 36 | System.out.println(searchFeed.getUpdateTime()); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /zebra-sample/src/test/java/com/dianping/zebra/sample/mybatis/SingleDataSourceSample.java: -------------------------------------------------------------------------------- 1 | package com.dianping.zebra.sample.mybatis; 2 | 3 | import com.dianping.zebra.sample.dao.group.UserDao; 4 | import com.dianping.zebra.sample.entity.group.UserEntity; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | /** 12 | * @author tong.xin on 2018/10/29. 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration({ "classpath*:spring/single/single-db-config.xml" }) 16 | public class SingleDataSourceSample { 17 | 18 | @Autowired 19 | private UserDao userDao; 20 | 21 | @Test 22 | public void test() { 23 | UserEntity user = new UserEntity(); 24 | user.setName("test_man"); 25 | user.setMis("test_single"); 26 | user.setEmail("test_man@meituan.com"); 27 | 28 | try { 29 | userDao.insert(user); 30 | UserEntity searchUser = userDao.searchUserById(user.getId()); 31 | 32 | System.out.println(searchUser.getName()); 33 | System.out.println(searchUser.getMis()); 34 | System.out.println(searchUser.getEmail()); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/app.properties: -------------------------------------------------------------------------------- 1 | app.name=zebra_sample -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/region/center.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "centers" : [ 4 | {"center":"center1","priority":2, "idcs":[ 5 | {"idc" : "idc1", "desc" : "机房1"}, 6 | {"idc" : "idc2", "desc" : "机房2"}, 7 | {"idc" : "idc3", "desc" : "机房3"} 8 | ]}, 9 | {"center":"center2","priority":1,"idcs":[ 10 | {"idc" : "idc4", "desc" : "机房4"} 11 | ]} 12 | ]}, 13 | {"region" : "region2", "centers" : [ 14 | {"center":"center3","priority":1,"idcs":[ 15 | {"idc" : "idc5", "desc" : "机房5"}, 16 | {"idc" : "idc6", "desc" : "机房6"} 17 | ]} 18 | ]} 19 | ] 20 | } -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/region/idc.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions" : [ 3 | {"region" : "region1", "idcs" : [ 4 | {"idc" : "idc1", "net" : ["192.1", "192.2"], "desc" : "机房1"}, 5 | {"idc" : "idc2", "net" : ["192.3", "192.4"], "desc" : "机房2"}, 6 | {"idc" : "idc3", "net" : ["192.5"], "desc" : "机房3"}, 7 | {"idc" : "idc4", "net" : ["192.6"], "desc" : "机房4"} 8 | ]}, 9 | {"region" : "region2", "idcs" : [ 10 | {"idc" : "idc5", "net" : ["192.10", "192.11"], "desc" : "机房5"}, 11 | {"idc" : "idc6", "net" : ["192.20", "192.21"], "desc" : "机房6"} 12 | ]} 13 | ] 14 | } -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/spring/shard/router-local-rule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `user` ( 2 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 3 | `Name` varchar(32) DEFAULT NULL, 4 | `Mis` varchar(20) NOT NULL DEFAULT 'mtdp', 5 | `Email` varchar(64) DEFAULT NULL, 6 | `UpdateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 7 | `CreateTime` datetime DEFAULT NULL, 8 | PRIMARY KEY (`id`), 9 | UNIQUE KEY `IX_Alias` (`Mis`) 10 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 11 | 12 | CREATE TABLE `Feed0` ( 13 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 14 | `Uid` varchar(30) NOT NULL DEFAULT '', 15 | `UpdateTime` timestamp NULL DEFAULT NULL, 16 | PRIMARY KEY (`id`) 17 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 18 | 19 | CREATE TABLE `Feed1` ( 20 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 21 | `Uid` varchar(30) NOT NULL DEFAULT '', 22 | `UpdateTime` timestamp NULL DEFAULT NULL, 23 | PRIMARY KEY (`id`) 24 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 25 | 26 | CREATE TABLE `Feed2` ( 27 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 28 | `Uid` varchar(30) NOT NULL DEFAULT '', 29 | `UpdateTime` timestamp NULL DEFAULT NULL, 30 | PRIMARY KEY (`id`) 31 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 32 | 33 | CREATE TABLE `Feed3` ( 34 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 35 | `Uid` varchar(30) NOT NULL DEFAULT '', 36 | `UpdateTime` timestamp NULL DEFAULT NULL, 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/zebra.properties: -------------------------------------------------------------------------------- 1 | zebra.group.zebra=\ 2 | \ 3 | zebra-n1\ 4 | 0\ 5 | -1\ 6 | \ 7 | \ 8 | zebra-n2\ 9 | -1\ 10 | 1\ 11 | \ 12 | 13 | 14 | zebra.ds.zebra-n1=\ 15 | jdbc:mysql://127.0.0.1:3306/zebra?characterEncoding=UTF8&socketTimeout=60000\ 16 | com.mysql.jdbc.Driver\ 17 | true\ 18 | root\ 19 | idleConnectionTestPeriod=80&acquireRetryAttempts=50&acquireRetryDelay=300&maxStatements=1\ 20 | 123456\ 21 | 22 | 23 | zebra.ds.zebra-n2=\ 24 | jdbc:mysql://127.0.0.1:3306/zebra?characterEncoding=UTF8&socketTimeout=60000\ 25 | com.mysql.jdbc.Driver\ 26 | true\ 27 | root\ 28 | idleConnectionTestPeriod=80&acquireRetryAttempts=50&acquireRetryDelay=300&maxStatements=1\ 29 | 123456\ 30 | -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/zebra.system.properties: -------------------------------------------------------------------------------- 1 | zebra.system.retryTimes=0 -------------------------------------------------------------------------------- /zebra-sample/src/test/resources/zookeeper.properties: -------------------------------------------------------------------------------- 1 | zkserver=localhost:2181 --------------------------------------------------------------------------------