You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/11/21 05:59:26 UTC

[GitHub] [incubator-shardingsphere] wgy8283335 commented on a change in pull request #3537: Config Center for Apollo.

wgy8283335 commented on a change in pull request #3537: Config Center for Apollo.
URL: https://github.com/apache/incubator-shardingsphere/pull/3537#discussion_r348885292
 
 

 ##########
 File path: sharding-orchestration/sharding-orchestration-center/src/main/java/org/apache/shardingsphere/orchestration/center/instance/ApolloInstance.java
 ##########
 @@ -0,0 +1,226 @@
+/*
+ * 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.listener.DataChangedEvent;
+import org.apache.shardingsphere.orchestration.center.listener.DataChangedEventListener;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+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 String namespace;
+    
+    private String appId;
+    
+    private String env;
+    
+    private String clusterName;
+    
+    private String modifiyDataUserId;
+    
+    private Config apolloConfig;
+    
+    private ApolloOpenApiClient client;
+    
+    private Map<String, Set<String>> keyAndChildrenMap = new HashMap<>();
+    
+    @Getter
+    @Setter
+    private Properties properties = new Properties();
+    
+    @Override
+    public void init(final InstanceConfiguration config) {
+        initApolloConfig(config);
+        initApolloOpenApiClient();
+        initKeysRelationship();
+    }
+    
+    private void initApolloConfig(final InstanceConfiguration config) {
+        namespace = config.getNamespace();
+        appId = properties.getProperty("appId", "APOLLO_SHARDING_SPHERE");
+        env = properties.getProperty("env", "DEV");
+        clusterName = properties.getProperty("clusterName", ConfigConsts.CLUSTER_NAME_DEFAULT);
+        System.setProperty("app.id", appId);
 
 Review comment:
   why not use enum ConfigConsts class?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services