dongzl commented on a change in pull request #3620: Apollo as a ConfigCenter. URL: https://github.com/apache/incubator-shardingsphere/pull/3620#discussion_r352270277
########## File path: sharding-orchestration/sharding-orchestration-center/src/main/java/org/apache/shardingsphere/orchestration/center/instance/ApolloInstance.java ########## @@ -0,0 +1,209 @@ +/* + * 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.center.instance; + +import com.ctrip.framework.apollo.Config; +import com.ctrip.framework.apollo.ConfigChangeListener; +import com.ctrip.framework.apollo.ConfigService; +import com.ctrip.framework.apollo.core.ConfigConsts; +import com.ctrip.framework.apollo.enums.PropertyChangeType; +import com.ctrip.framework.apollo.model.ConfigChange; +import com.ctrip.framework.apollo.model.ConfigChangeEvent; +import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient; +import com.ctrip.framework.apollo.openapi.client.constant.ApolloOpenApiConstants; +import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO; +import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO; +import com.google.common.collect.Sets; +import com.google.common.primitives.Ints; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.orchestration.center.api.ConfigCenter; +import org.apache.shardingsphere.orchestration.center.configuration.InstanceConfiguration; +import org.apache.shardingsphere.orchestration.center.instance.node.ConfigTreeNode; +import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent; +import org.apache.shardingsphere.orchestration.center.listener.DataChangedEventListener; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Registry center for Apollo. + * + * @author dongzonglei + */ +@Slf4j +public final class ApolloInstance implements ConfigCenter { + + private static final String SHARDING_SPHERE_KEY_ROOT = "/"; + + private static final String SHARDING_SPHERE_KEY_SEPARATOR = "/"; + + private static final String APOLLO_KEY_SEPARATOR = "."; + + private static final String APOLLO_KEY_APP_ID = "app.id"; + + private static final String APOLLO_KEY_ENV = "env"; + + private static final String APOLLO_KEY_CLUSTER = ConfigConsts.APOLLO_CLUSTER_KEY; + + private static final String APOLLO_KEY_META = ConfigConsts.APOLLO_META_KEY; + + private String namespace; + + private String appId; + + private String env; + + private String clusterName; + + private String administrator; + + private Config apolloConfig; + + private ApolloOpenApiClient client; + + private ConfigTreeNode tree = new ConfigTreeNode(null, "/", Sets.<ConfigTreeNode>newHashSet()); + + @Getter + @Setter + private Properties properties = new Properties(); + + @Override + public void init(final InstanceConfiguration config) { + initApolloConfig(config); + initApolloOpenApiClient(); + initKeysRelationship(); + } + + private void initApolloConfig(final InstanceConfiguration config) { Review comment: This is only a `private` method and inner used. The `public` method is `init(final InstanceConfiguration config)`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
