qifanlili commented on code in PR #15139:
URL: 
https://github.com/apache/dolphinscheduler/pull/15139#discussion_r1386457075


##########
dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/StandaloneServer.java:
##########
@@ -17,28 +17,50 @@
 
 package org.apache.dolphinscheduler;
 
-import org.apache.curator.test.TestingServer;
+import org.apache.dolphinscheduler.registry.StandaloneRegistry;
+
+import java.util.List;
+import java.util.Optional;
 
 import lombok.extern.slf4j.Slf4j;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
 
 @SpringBootApplication
 @Slf4j
 public class StandaloneServer {
 
+    @Value("${registry.type}")
+    private String registryType;
+
+    @Autowired
+    private List<StandaloneRegistry> registries;
+
     public static void main(String[] args) throws Exception {
         try {
-            // We cannot use try-with-resources to close "TestingServer", 
since SpringApplication.run() will not block
-            // the main thread.
-            TestingServer zookeeperServer = new TestingServer(true);
-            System.setProperty("registry.zookeeper.connect-string", 
zookeeperServer.getConnectString());
-            SpringApplication.run(StandaloneServer.class, args);
+            ConfigurableApplicationContext context = 
SpringApplication.run(StandaloneServer.class, args);
+            StandaloneServer standaloneServer = 
context.getBean(StandaloneServer.class);
+            standaloneServer.registry();
         } catch (Exception ex) {
             log.error("StandaloneServer start failed", ex);
             System.exit(1);
         }
     }
 
-}
+    private void registry() {
+        Optional<StandaloneRegistry> registry = registries.stream()
+                .filter(r -> r.supports(registryType))
+                .findFirst();
+
+        if (registry.isPresent()) {
+            registry.get().init();
+        } else {
+            log.error("Unsupported registry type: {}", registryType);
+        }
+    }
+
+}

Review Comment:
   > Please add a blank line here.
   
   Thanks for the tip! I haven't made a habit of using “mvn spotless: apply”



##########
dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/StandaloneServer.java:
##########
@@ -17,28 +17,50 @@
 
 package org.apache.dolphinscheduler;
 
-import org.apache.curator.test.TestingServer;
+import org.apache.dolphinscheduler.registry.StandaloneRegistry;
+
+import java.util.List;
+import java.util.Optional;
 
 import lombok.extern.slf4j.Slf4j;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
 
 @SpringBootApplication
 @Slf4j
 public class StandaloneServer {
 
+    @Value("${registry.type}")
+    private String registryType;
+
+    @Autowired
+    private List<StandaloneRegistry> registries;
+
     public static void main(String[] args) throws Exception {
         try {
-            // We cannot use try-with-resources to close "TestingServer", 
since SpringApplication.run() will not block
-            // the main thread.
-            TestingServer zookeeperServer = new TestingServer(true);
-            System.setProperty("registry.zookeeper.connect-string", 
zookeeperServer.getConnectString());
-            SpringApplication.run(StandaloneServer.class, args);
+            ConfigurableApplicationContext context = 
SpringApplication.run(StandaloneServer.class, args);
+            StandaloneServer standaloneServer = 
context.getBean(StandaloneServer.class);
+            standaloneServer.registry();
         } catch (Exception ex) {
             log.error("StandaloneServer start failed", ex);
             System.exit(1);
         }
     }
 
-}
+    private void registry() {
+        Optional<StandaloneRegistry> registry = registries.stream()
+                .filter(r -> r.supports(registryType))
+                .findFirst();
+
+        if (registry.isPresent()) {
+            registry.get().init();
+        } else {
+            log.error("Unsupported registry type: {}", registryType);
+        }
+    }
+
+}

Review Comment:
   > Please add a blank line here.
   
   Thanks for the tip! I haven't made a habit of using “mvn spotless: apply”



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to