Skip to content

Commit

Permalink
Add Config Center (#3020)
Browse files Browse the repository at this point in the history
* Initialize config server module.

* Initialize config server module.

* Add TypeBasedSPI dependency.

* Modify Config Center related.

* Add Config Center Zookeeper related.

* Modify CuratorZookeeperConfigCenter and format pom.xml.

* Add Integration Test for Registry Center and Config Center.

* Modify Integration Test for Registry Center.

* Modify Config Center related functions.

* Modify Config Center related functions.

* Modify pom.xml.

* Modify services org.apache.shardingsphere.orchestration.config.api.ConfigCenter

* Modify pom.xml file.

* Add Unit test cases.

* format java file.

* Add Unit Test for ConfigCenterServiceLoader.

* Modify ConfigCenter.
  • Loading branch information
wgy8283335 authored and terrymanu committed Sep 17, 2019
1 parent f69444d commit 7d84bb5
Show file tree
Hide file tree
Showing 21 changed files with 1,314 additions and 1 deletion.
1 change: 1 addition & 0 deletions sharding-orchestration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<module>sharding-orchestration-core</module>
<module>sharding-orchestration-reg</module>
<module>sharding-orchestration-zookeeper-curator-integration-test</module>
<module>sharding-orchestration-config</module>
</modules>
</project>
36 changes: 36 additions & 0 deletions sharding-orchestration/sharding-orchestration-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>sharding-orchestration</artifactId>
<groupId>org.apache.shardingsphere</groupId>
<version>4.0.0-RC3-SNAPSHOT</version>
</parent>
<artifactId>sharding-orchestration-config</artifactId>
<name>${project.artifactId}</name>
<packaging>pom</packaging>

<modules>
<module>sharding-orchestration-config-api</module>
<module>sharding-orchestration-config-zookeeper-curator</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>sharding-orchestration-config</artifactId>
<groupId>org.apache.shardingsphere</groupId>
<version>4.0.0-RC3-SNAPSHOT</version>
</parent>
<artifactId>sharding-orchestration-config-api</artifactId>
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-core-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.orchestration.config.api;

import org.apache.shardingsphere.orchestration.config.listener.DataChangedEventListener;
import org.apache.shardingsphere.spi.TypeBasedSPI;

import java.util.List;

/**
* Config center.
*
* @author wangguangyuan
*/
public interface ConfigCenter extends TypeBasedSPI {

/**
* Initialize config center.
*
* @param config config center configuration
*/
void init(ConfigCenterConfiguration config);

/**
* Get data from config center.
*
* <p>Maybe use cache if existed.</p>
*
* @param key key of data
* @return value of data
*/
String get(String key);

/**
* Get data from config center directly.
*
* <p>Cannot use cache.</p>
*
* @param key key of data
* @return value of data
*/
String getDirectly(String key);

/**
* Judge data is existed or not.
*
* @param key key of data
* @return data is existed or not
*/
boolean isExisted(String key);

/**
* Get node's sub-nodes list.
*
* @param key key of data
* @return sub-nodes name list
*/
List<String> getChildrenKeys(String key);

/**
* Persist data.
*
* @param key key of data
* @param value value of data
*/
void persist(String key, String value);

/**
* Update data.
*
* @param key key of data
* @param value value of data
*/
void update(String key, String value);

/**
* Persist ephemeral data.
*
* @param key key of data
* @param value value of data
*/
void persistEphemeral(String key, String value);

/**
* Watch key or path of the config server.
*
* @param key key of data
* @param dataChangedEventListener data changed event listener
*/
void watch(String key, DataChangedEventListener dataChangedEventListener);

/**
* Close.
*/
void close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.orchestration.config.api;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.api.config.TypeBasedSPIConfiguration;

import java.util.Properties;

/**
* Config center configuration.
*
* @author wangguangyuan
*/
@Getter
@Setter
public final class ConfigCenterConfiguration extends TypeBasedSPIConfiguration {

/**
* Server list of config center.
*/
private String serverLists;

/**
* Namespace of config center.
*/
private String namespace;

/**
* Digest of config center.
*/
private String digest;

/**
* Operation timeout time in milliseconds.
*/
private int operationTimeoutMilliseconds = 500;

/**
* Max number of times to retry.
*/
private int maxRetries = 3;

/**
* Time interval in milliseconds on each retry.
*/
private int retryIntervalMilliseconds = 500;

/**
* Time to live in seconds of ephemeral keys.
*/
private int timeToLiveSeconds = 60;

public ConfigCenterConfiguration(final String type) {
super(type);
}

public ConfigCenterConfiguration(final String type, final Properties properties) {
super(type, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.orchestration.config.exception;

/**
* Config center exception.
*
* @author wangguangyuan
*/
public final class ConfigCenterException extends RuntimeException {

private static final long serialVersionUID = -6417179023552012152L;

public ConfigCenterException(final String errorMessage, final Object... args) {
super(String.format(errorMessage, args));
}

public ConfigCenterException(final Exception cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.orchestration.config.listener;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
* Data changed event.
*
* @author wangguangyuan
*/
@RequiredArgsConstructor
@Getter
public final class DataChangedEvent {

private final String key;

private final String value;

private final ChangedType changedType;

/**
* Data changed type.
*/
public enum ChangedType {

UPDATED, DELETED, IGNORED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.orchestration.config.listener;

/**
* Listener for data changed event.
*
* @author wangguangyuan
*/
public interface DataChangedEventListener {

/**
* Fire when data changed.
*
* @param dataChangedEvent data changed event
*/
void onChange(DataChangedEvent dataChangedEvent);
}
Loading

0 comments on commit 7d84bb5

Please sign in to comment.