Skip to content

Commit

Permalink
Remove apollo in ShardingSphere driver and move to ShardingSphere plu…
Browse files Browse the repository at this point in the history
…gin repository (#28585)

* Remove apollo in ShardingSphere driver and move to ShardingSphere plugin repository

* Remove dbcp in pom
  • Loading branch information
strongduanmu authored Sep 26, 2023
1 parent 267ddcd commit 78213ea
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ShardingSphere-JDBC 提供了 JDBC 驱动,可以仅通过配置变更即可使
- 配置文件加载规则:
- `absolutepath:` 前缀表示从绝对路径中加载配置文件
- `classpath:` 前缀表示从类路径中加载配置文件
- `apollo:` 前缀表示从 apollo 中加载配置文件

## 操作步骤

Expand All @@ -35,16 +34,6 @@ ShardingSphere-JDBC 提供了 JDBC 驱动,可以仅通过配置变更即可使
</dependency>
```

如果使用 apollo 配置方式,还需要引入 `apollo-client` 依赖:

```xml
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${apollo-client.version}</version>
</dependency>
```

2. 使用驱动

* 使用原生驱动:
Expand Down Expand Up @@ -103,8 +92,3 @@ jdbc:shardingsphere:classpath:config.yaml
```
jdbc:shardingsphere:absolutepath:/path/to/config.yaml
```

加载 apollo 指定 namespace 中的 yaml 配置文件的 JDBC URL:
```
jdbc:shardingsphere:apollo:TEST.test_namespace
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ShardingSphere-JDBC provides a JDBC Driver, which can be used only through confi
- Configuration file loading rule:
- `absolutepath:` prefix means to load the configuration file from the absolute path
- `classpath:` prefix indicates that the configuration file is loaded from the classpath
- `apollo:` prefix means to load the configuration file from apollo

## Procedure

Expand All @@ -35,16 +34,6 @@ ShardingSphere-JDBC provides a JDBC Driver, which can be used only through confi
</dependency>
```

If you use the apollo configuration method, you also need to introduce the `apollo-client` dependency:

```xml
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${apollo-client.version}</version>
</dependency>
```

2. Use drive

* Use native drivers:
Expand Down Expand Up @@ -103,8 +92,3 @@ Load JDBC URL of config.yaml profile in absolute path
```
jdbc:shardingsphere:absolutepath:/path/to/config.yaml
```

Load JDBC URL of the yaml configuration file in the specified namespace of apollo:
```
jdbc:shardingsphere:apollo:TEST.test_namespace
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSph
spring.datasource.url=jdbc:shardingsphere:classpath:xxx.yaml
```

`spring.datasource.url` 中的 YAML 配置文件当前支持通过三种方式获取,绝对路径 `absolutepath:`、Apollo 配置中心 `apollo:` 以及 CLASSPATH `classpath:`,具体可参考 `org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider` 的实现。
`spring.datasource.url` 中的 YAML 配置文件当前支持通过两种方式获取,绝对路径 `absolutepath:` 以及 CLASSPATH `classpath:`,具体可参考 `org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider` 的实现。

### 使用数据源

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSph
spring.datasource.url=jdbc:shardingsphere:classpath:xxx.yaml
```

The YAML configuration file in 'spring.datasource.url' currently support in three ways, the absolute path 'absolutepath:', Apollo configuration center 'apollo:', and CLASSPATH 'classpath:', which can be referred to `org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider`'s implementation for details.
The YAML configuration file in 'spring.datasource.url' currently support in two ways, the absolute path 'absolutepath:' and CLASSPATH 'classpath:', which can be referred to `org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider`'s implementation for details.

### Use Data Source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ registry {
}

config {
# file、apollo、zk
# file、zk
type = "file"

apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
Expand Down
5 changes: 0 additions & 5 deletions infra/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
<artifactId>shardingsphere-infra-data-source-pool-hikari</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-data-source-pool-dbcp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-parser-sql-engine</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions jdbc/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,5 @@
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
</dependency>

</dependencies>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@

org.apache.shardingsphere.driver.jdbc.core.driver.spi.AbsolutePathURLProvider
org.apache.shardingsphere.driver.jdbc.core.driver.spi.ClasspathURLProvider
org.apache.shardingsphere.driver.jdbc.core.driver.spi.ApolloURLProvider
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,18 @@

package org.apache.shardingsphere.driver.jdbc.core.driver;

import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import org.apache.shardingsphere.driver.jdbc.exception.syntax.URLProviderNotFoundException;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.apache.shardingsphere.test.mock.StaticMockSettings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ConfigService.class)
class ShardingSphereURLManagerTest {

private final int fooDriverConfigLength = 999;
Expand All @@ -62,14 +52,4 @@ void assertToAbsolutePathConfigurationFile() {
byte[] actual = ShardingSphereURLManager.getContent("jdbc:shardingsphere:absolutepath:" + absolutePath, urlPrefix);
assertThat(actual.length, is(fooDriverConfigLength));
}

@Test
void assertToApolloConfigurationFile() {
ConfigFile configFile = mock(ConfigFile.class);
when(configFile.getContent()).thenReturn("config content");
when(ConfigService.getConfigFile(anyString(), any(ConfigFileFormat.class))).thenReturn(configFile);
String url = "jdbc:shardingsphere:apollo:namespace";
byte[] content = ShardingSphereURLManager.getContent(url, urlPrefix);
assertThat("config content".getBytes(StandardCharsets.UTF_8), is(content));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ registry {
}

config {
# file、apollo、zk
# file、zk
type = "file"

apollo {
app.id = "fescar-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
Expand Down
14 changes: 0 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<curator.version>5.4.0</curator.version>
<jetcd.version>0.7.5</jetcd.version>
<grpc.version>1.51.0</grpc.version>
<apollo-client.version>1.9.0</apollo-client.version>

<elasticjob.version>3.0.3</elasticjob.version>

Expand All @@ -111,7 +110,6 @@
<hbase.client.version>1.7.1</hbase.client.version>

<hikari-cp.version>4.0.3</hikari-cp.version>
<commons-dbcp2.version>2.9.0</commons-dbcp2.version>

<junit.version>5.9.2</junit.version>
<hamcrest.version>2.2</hamcrest.version>
Expand Down Expand Up @@ -412,12 +410,6 @@
<artifactId>grpc-all</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${apollo-client.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
Expand Down Expand Up @@ -530,12 +522,6 @@
<version>${hikari-cp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons-dbcp2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
5 changes: 0 additions & 5 deletions proxy/bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@
<artifactId>HikariCP</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down

0 comments on commit 78213ea

Please sign in to comment.