Skip to content

Commit

Permalink
[Feature][Standalone]Support using JDBC registry plugin in standalone…
Browse files Browse the repository at this point in the history
… mode. apache#15103
  • Loading branch information
qifanlili committed Nov 8, 2023
1 parent 2622685 commit 32be7c7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "jdbc")
public class JdbcRegistryConfiguration {

@Bean
@Bean("sqlSessionFactory")
@ConditionalOnProperty(prefix = "registry.hikari-config", name = "jdbc-url")
public SqlSessionFactory jdbcRegistrySqlSessionFactory(JdbcRegistryProperties jdbcRegistryProperties) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
Expand Down
15 changes: 15 additions & 0 deletions dolphinscheduler-standalone-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Introduction

This module is used to start the dolphinscheduler in standalone mode. Currently Zookeeper and JDBC plugin are enabled as registries, depending on the properties configuration.

# How to use

1. Select the type of registry you want. The default is Zookeeper

- If you have chosen Zookeeper as the registry, you can refer to the dollinscheduler-registry-plugins dollinscheduler-registry-Zookeeper readme.md documentation for configuration. (note: the default is of type Zookeeper, and a mock Zookeeper server is created, without the need to actually install ZK)
- If you choose JDBC as the Registry, you can refer to the readme.md documentation for configuration




##
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.dolphinscheduler.registry;

import org.springframework.stereotype.Component;

@Component
public class JdbcStandaloneRegistry implements StandaloneRegistry {

@Override
public void init() {

}

@Override
public boolean supports(String registryType) {
return "jdbc".equalsIgnoreCase(registryType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.dolphinscheduler.registry;

public interface StandaloneRegistry {

void init();

boolean supports(String registryType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.dolphinscheduler.registry;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.test.TestingServer;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ZookeeperStandaloneRegistry implements StandaloneRegistry {

@Override
public void init() {
try {
TestingServer zookeeperServer = new TestingServer(true);
System.setProperty("registry.zookeeper.connect-string", "localhost:2181");
} catch (Exception ex) {
log.error("Zookeeper TestingServer create failed", ex);
}
}

@Override
public boolean supports(String registryType) {
return "zookeeper".equalsIgnoreCase(registryType);
}
}

0 comments on commit 32be7c7

Please sign in to comment.