From 6d645889dcfbd278479ecc4e3d43bd28487b7ace Mon Sep 17 00:00:00 2001 From: BUAAserein <18376359@buaa.edu.cn> Date: Mon, 21 Oct 2024 23:57:51 +0800 Subject: [PATCH 1/2] refactor registry --- .../streampark/common/utils/OSUtils.java | 49 --- .../streampark-console-registry/pom.xml | 1 - .../registry/api/ConnectStrategy.java | 31 -- .../api/ConnectStrategyProperties.java | 33 -- .../registry/api/ConnectionListener.java | 28 -- .../registry/api/ConnectionState.java | 28 -- .../streampark/registry/api/Registry.java | 41 +-- .../registry/api/RegistryClient.java | 125 +------- .../streampark/registry/api/StrategyType.java | 25 -- .../registry/api/enums/RegistryNodeType.java | 1 - .../registry/api/enums/ServerStatusEnum.java | 25 -- .../api/lifecycle/ServerLifeCycle.java | 1 - .../lifecycle/ServerLifeCycleException.java | 29 -- .../api/lifecycle/ServerLifeCycleManager.java | 35 +-- .../registry/api/model/BaseHeartBeat.java | 43 --- .../registry/api/model/BaseHeartBeatTask.java | 3 +- .../registry/api/model/ConsoleHeartBeat.java | 14 +- .../registry/api/model/HeartBeat.java | 4 - .../streampark/registry/api/model/Server.java | 46 --- .../api/sql/ClasspathSqlScriptParser.java | 147 --------- .../registry/api/sql/SqlScriptParser.java | 27 -- .../registry/api/sql/SqlScriptRunner.java | 65 ---- .../registry/api/thread/BaseDaemonThread.java | 6 - .../streampark-registry-core/pom.xml | 8 - .../registry/core/JdbcRegistry.java | 108 +------ .../core/JdbcRegistryAutoConfiguration.java | 25 +- .../streampark/registry/core/LockUtils.java | 34 -- .../core/client/IJdbcRegistryClient.java | 106 ------- .../core/client/JdbcRegistryClient.java | 129 -------- .../client/JdbcRegistryClientIdentify.java | 33 -- .../JdbcRegistryClientHeartbeatMapper.java | 33 -- .../JdbcRegistryDataChanceEventMapper.java | 2 +- .../core/mapper/JdbcRegistryDataMapper.java | 11 - .../core/mapper/JdbcRegistryLockMapper.java | 39 --- .../model/DO/JdbcRegistryClientHeartbeat.java | 46 --- .../core/model/DO/JdbcRegistryData.java | 2 - .../model/DO/JdbcRegistryDataChanceEvent.java | 3 - .../core/model/DO/JdbcRegistryLock.java | 45 --- .../registry/core/model/DTO/DataType.java | 25 -- .../DTO/JdbcRegistryClientHeartbeatDTO.java | 100 ------ .../DTO/JdbcRegistryDataChanceEventDTO.java | 4 - .../core/model/DTO/JdbcRegistryDataDTO.java | 6 - .../core/model/DTO/JdbcRegistryLockDTO.java | 63 ---- .../JdbcRegistryClientRepository.java | 66 ---- .../JdbcRegistryDataRepository.java | 9 - .../JdbcRegistryLockRepository.java | 55 ---- .../core/server/ConnectionStateListener.java | 27 -- .../core/server/IJdbcRegistryDataManager.java | 5 +- .../core/server/IJdbcRegistryLockManager.java | 37 --- .../core/server/IJdbcRegistryServer.java | 44 +-- .../core/server/JdbcRegistryDataManager.java | 28 +- .../core/server/JdbcRegistryLockManager.java | 150 --------- .../core/server/JdbcRegistryServer.java | 292 ++---------------- .../core/server/JdbcRegistryServerState.java | 11 - .../main/resources/mysql_registry_init.sql | 28 -- .../resources/postgresql_registry_init.sql | 27 -- .../registry/core/JdbcRegistryTestCase.java | 64 ---- .../registry/core/LockUtilsTest.java | 38 --- .../core/MysqlJdbcRegistryTestCase.java | 77 ----- .../core/PostgresqlJdbcRegistryTestCase.java | 73 ----- .../streampark-registry-it/pom.xml | 62 ---- .../plugin/registry/RegistryTestCase.java | 260 ---------------- .../assembly/script/schema/mysql-schema.sql | 28 -- .../assembly/script/schema/pgsql-schema.sql | 27 -- .../assembly/script/upgrade/mysql/2.2.0.sql | 26 -- .../assembly/script/upgrade/pgsql/2.2.0.sql | 27 -- .../console/StreamParkConsoleBootstrap.java | 1 - .../console/core/config/ConsoleConfig.java | 4 - .../core/registry/ConsoleConnectStrategy.java | 24 -- .../ConsoleConnectionStateListener.java | 54 ---- .../core/registry/ConsoleRegistryClient.java | 41 +-- .../registry/ConsoleRegistryDataListener.java | 4 + .../core/registry/ConsoleStopStrategy.java | 52 ---- .../core/task/ConsoleHeartBeatTask.java | 9 +- .../src/main/resources/db/schema-h2.sql | 28 -- streampark.ipr | 145 +++++++++ 76 files changed, 226 insertions(+), 3226 deletions(-) delete mode 100644 streampark-common/src/main/java/org/apache/streampark/common/utils/OSUtils.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategy.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategyProperties.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionListener.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionState.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/StrategyType.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/ServerStatusEnum.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleException.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeat.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/Server.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/ClasspathSqlScriptParser.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptParser.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptRunner.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/LockUtils.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/IJdbcRegistryClient.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClient.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClientIdentify.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryClientHeartbeatMapper.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryLockMapper.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryClientHeartbeat.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryLock.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/DataType.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryClientHeartbeatDTO.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryLockDTO.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryClientRepository.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryLockRepository.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/ConnectionStateListener.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryLockManager.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryLockManager.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/JdbcRegistryTestCase.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/LockUtilsTest.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/MysqlJdbcRegistryTestCase.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/PostgresqlJdbcRegistryTestCase.java delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-it/pom.xml delete mode 100644 streampark-console/streampark-console-registry/streampark-registry-it/src/test/java/org/apache/streampark/plugin/registry/RegistryTestCase.java delete mode 100644 streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectStrategy.java delete mode 100644 streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectionStateListener.java delete mode 100644 streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleStopStrategy.java create mode 100644 streampark.ipr diff --git a/streampark-common/src/main/java/org/apache/streampark/common/utils/OSUtils.java b/streampark-common/src/main/java/org/apache/streampark/common/utils/OSUtils.java deleted file mode 100644 index d5d0f76829..0000000000 --- a/streampark-common/src/main/java/org/apache/streampark/common/utils/OSUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.streampark.common.utils; - -import lombok.experimental.UtilityClass; -import lombok.extern.slf4j.Slf4j; -import oshi.SystemInfo; -import oshi.hardware.HardwareAbstractionLayer; - -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; - -@Slf4j -@UtilityClass -public class OSUtils { - - private static final SystemInfo SI = new SystemInfo(); - - private static final HardwareAbstractionLayer hal = SI.getHardware(); - - public static long getTotalSystemMemory() { - return hal.getMemory().getTotal(); - } - - public static long getSystemAvailableMemoryUsed() { - return hal.getMemory().getAvailable(); - } - - public static int getProcessID() { - RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); - return Integer.parseInt(runtimeMXBean.getName().split("@")[0]); - } - -} diff --git a/streampark-console/streampark-console-registry/pom.xml b/streampark-console/streampark-console-registry/pom.xml index c29bb01546..e9fbc9273e 100644 --- a/streampark-console/streampark-console-registry/pom.xml +++ b/streampark-console/streampark-console-registry/pom.xml @@ -30,7 +30,6 @@ streampark-registry-api streampark-registry-core - streampark-registry-it diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategy.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategy.java deleted file mode 100644 index 7aeaac4bc6..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategy.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.streampark.registry.api; - -/** - * This interface defined a method to be executed when the server disconnected from registry. - */ -public interface ConnectStrategy { - - void disconnect(); - - void reconnect(); - - StrategyType getStrategyType(); - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategyProperties.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategyProperties.java deleted file mode 100644 index 30a384a78c..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectStrategyProperties.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.streampark.registry.api; - -import lombok.Getter; -import lombok.Setter; - -import java.time.Duration; - -@Getter -@Setter -public class ConnectStrategyProperties { - - private StrategyType strategy = StrategyType.STOP; - - private Duration maxWaitingTime = Duration.ofSeconds(0); - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionListener.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionListener.java deleted file mode 100644 index ebdc56eb31..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.streampark.registry.api; - -/** - * when the connect state between client and registry center changed, - * the {@code onUpdate} function is triggered - */ -@FunctionalInterface -public interface ConnectionListener { - - void onUpdate(ConnectionState newState); -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionState.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionState.java deleted file mode 100644 index dfcdbc10f7..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/ConnectionState.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.streampark.registry.api; - -/** - * Connection state between client and registry center(Etcd, MySql, Zookeeper) - */ -public enum ConnectionState { - CONNECTED, - RECONNECTED, - SUSPENDED, - DISCONNECTED -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/Registry.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/Registry.java index 2f349be1d0..17b7524970 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/Registry.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/Registry.java @@ -17,10 +17,7 @@ package org.apache.streampark.registry.api; -import lombok.NonNull; - import java.io.Closeable; -import java.time.Duration; import java.util.Collection; /** @@ -33,21 +30,6 @@ public interface Registry extends Closeable { */ void start(); - /** - * Whether the registry is connected - * - * @return true if connected, false otherwise. - */ - boolean isConnected(); - - /** - * Connect to the registry, will wait in the given timeout - * - * @param timeout max timeout, if timeout <= 0 will wait indefinitely. - * @throws RegistryException cannot connect in the given timeout - */ - void connectUntilTimeout(@NonNull Duration timeout) throws RegistryException; - /** * Subscribe the path, when the path has expose {@link Event}, the listener will be triggered. *

@@ -58,11 +40,6 @@ public interface Registry extends Closeable { */ void subscribe(String path, SubscribeListener listener); - /** - * Add a connection listener to collection. - */ - void addConnectionStateListener(ConnectionListener listener); - /** * Get the value of the key, if key not exist will throw {@link RegistryException} */ @@ -73,9 +50,8 @@ public interface Registry extends Closeable { * * @param key the key, cannot be null * @param value the value, cannot be null - * @param deleteOnDisconnect if true, when the connection state is disconnected, the key will be deleted */ - void put(String key, String value, boolean deleteOnDisconnect); + void put(String key, String value); /** * Delete the key from the registry @@ -94,19 +70,4 @@ public interface Registry extends Closeable { * @return true if the key exists */ boolean exists(String key); - - /** - * Acquire the lock of the prefix {@param key} - */ - boolean acquireLock(String key); - - /** - * Acquire the lock of the prefix {@param key}, if acquire in the given timeout return true, else return false. - */ - boolean acquireLock(String key, long timeout); - - /** - * Release the lock of the prefix {@param key} - */ - boolean releaseLock(String key); } diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java index 0dbd96adc3..63f26d2dde 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java @@ -17,29 +17,16 @@ package org.apache.streampark.registry.api; -import org.apache.streampark.common.IStoppable; import org.apache.streampark.common.constants.Constants; -import org.apache.streampark.common.utils.JSONUtils; import org.apache.streampark.registry.api.enums.RegistryNodeType; -import org.apache.streampark.registry.api.model.ConsoleHeartBeat; -import org.apache.streampark.registry.api.model.Server; - -import org.apache.commons.lang3.StringUtils; import com.google.common.base.Strings; -import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.io.IOException; -import java.time.Duration; -import java.util.ArrayList; import java.util.Collection; -import java.util.Date; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; import static com.google.common.base.Preconditions.checkArgument; @@ -48,89 +35,18 @@ @Slf4j public class RegistryClient { - private IStoppable stoppable; - private static final String EMPTY = ""; private final Registry registry; public RegistryClient(Registry registry) { this.registry = registry; + // TODO: remove this if (!registry.exists(RegistryNodeType.CONSOLE_SERVER.getRegistryPath())) { - registry.put(RegistryNodeType.CONSOLE_SERVER.getRegistryPath(), EMPTY, false); + registry.put(RegistryNodeType.CONSOLE_SERVER.getRegistryPath(), EMPTY); } } - public boolean isConnected() { - return registry.isConnected(); - - } - - public void connectUntilTimeout(@NonNull Duration duration) throws RegistryException { - registry.connectUntilTimeout(duration); - } - - public List getServerList(RegistryNodeType registryNodeType) { - Map serverMaps = getServerMaps(registryNodeType); - - List serverList = new ArrayList<>(); - for (Map.Entry entry : serverMaps.entrySet()) { - String serverPath = entry.getKey(); - String heartBeatJson = entry.getValue(); - if (StringUtils.isEmpty(heartBeatJson)) { - log.error("The heartBeatJson is empty, serverPath: {}", serverPath); - continue; - } - Server server = new Server(); - switch (registryNodeType) { - case CONSOLE_SERVER: - ConsoleHeartBeat consoleHeartBeat = - JSONUtils.parseObject(heartBeatJson, ConsoleHeartBeat.class); - server.setCreateTime(new Date(consoleHeartBeat.getStartupTime())); - server.setLastHeartbeatTime(new Date(consoleHeartBeat.getReportTime())); - server.setId(consoleHeartBeat.getProcessId()); - server.setHost(consoleHeartBeat.getHost()); - server.setPort(consoleHeartBeat.getPort()); - break; - default: - log.warn("unknown registry node type: {}", registryNodeType); - } - - server.setResInfo(heartBeatJson); - // todo: add host, port in heartBeat Info, so that we don't need to parse this again - server.setZkDirectory(registryNodeType.getRegistryPath() + "/" + serverPath); - serverList.add(server); - } - return serverList; - } - - /** - * Return server host:port -> value - */ - public Map getServerMaps(RegistryNodeType nodeType) { - Map serverMap = new HashMap<>(); - try { - Collection serverList = getServerNodes(nodeType); - for (String server : serverList) { - serverMap.putIfAbsent(server, get(nodeType.getRegistryPath() + Constants.SINGLE_SLASH + server)); - } - } catch (Exception e) { - log.error("get server list failed", e); - } - - return serverMap; - } - - public boolean checkNodeExists(String host, RegistryNodeType nodeType) { - return getServerMaps(nodeType).keySet() - .stream() - .anyMatch(it -> it.contains(host)); - } - - public Collection getConsoleNodesDirectly() { - return getChildrenKeys(RegistryNodeType.CONSOLE_SERVER.getRegistryPath()); - } - /** * get host ip:port, path format: parentPath/ip:port * @@ -151,11 +67,11 @@ public void close() throws IOException { registry.close(); } - public void persistEphemeral(String key, String value) { - registry.put(key, value, true); + public void put(String key, String value) { + registry.put(key, value); } - public void remove(String key) { + public void delete(String key) { registry.delete(key); } @@ -167,35 +83,10 @@ public void subscribe(String path, SubscribeListener listener) { registry.subscribe(path, listener); } - public void addConnectionStateListener(ConnectionListener listener) { - registry.addConnectionStateListener(listener); - } - public boolean exists(String key) { return registry.exists(key); } - public boolean getLock(String key) { - return registry.acquireLock(key); - } - - public boolean releaseLock(String key) { - return registry.releaseLock(key); - } - - public void setStoppable(IStoppable stoppable) { - this.stoppable = stoppable; - } - - public IStoppable getStoppable() { - return stoppable; - } - - public boolean isConsolePath(String path) { - return path != null - && path.startsWith(RegistryNodeType.CONSOLE_SERVER.getRegistryPath() + Constants.SINGLE_SLASH); - } - public Collection getChildrenKeys(final String key) { return registry.children(key); } @@ -211,4 +102,10 @@ public Set getServerNodeSet(RegistryNodeType nodeType) { private Collection getServerNodes(RegistryNodeType nodeType) { return getChildrenKeys(nodeType.getRegistryPath()); } + + public boolean checkNodeExists(String host, RegistryNodeType nodeType) { + return getServerNodes(nodeType) + .stream() + .anyMatch(it -> it.contains(host)); + } } diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/StrategyType.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/StrategyType.java deleted file mode 100644 index 450a4a2721..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/StrategyType.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.streampark.registry.api; - -public enum StrategyType { - - STOP, - WAITING, - ; -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/RegistryNodeType.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/RegistryNodeType.java index 8d7086334d..f8352d94db 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/RegistryNodeType.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/RegistryNodeType.java @@ -26,7 +26,6 @@ public enum RegistryNodeType { ALL_SERVERS("nodes", "/nodes"), CONSOLE_SERVER("ConsoleServer", "/nodes/console-server"), - CONSOLE_NODE_LOCK("ConsoleNodeLock", "/lock/console"), ; private final String name; diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/ServerStatusEnum.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/ServerStatusEnum.java deleted file mode 100644 index def84ca4a3..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/enums/ServerStatusEnum.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.streampark.registry.api.enums; - -public enum ServerStatusEnum { - - NORMAL, - BUSY, - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycle.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycle.java index 3ad4b0fc7b..6070c0073a 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycle.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycle.java @@ -26,7 +26,6 @@ public enum ServerLifeCycle { RUNNING(0, "The current server is running"), - WAITING(1, "The current server is waiting, this means it cannot work"), STOPPED(2, "The current server is stopped"), ; diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleException.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleException.java deleted file mode 100644 index 8fcbf82790..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.streampark.registry.api.lifecycle; - -public class ServerLifeCycleException extends Exception { - - public ServerLifeCycleException(String message) { - super(message); - } - - public ServerLifeCycleException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleManager.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleManager.java index d70133617f..1c16660de5 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleManager.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/lifecycle/ServerLifeCycleManager.java @@ -29,7 +29,7 @@ public class ServerLifeCycleManager { private static volatile ServerLifeCycle serverLifeCycle = ServerLifeCycle.RUNNING; @Getter - private static long serverStartupTime = System.currentTimeMillis(); + private final static long serverStartupTime = System.currentTimeMillis(); public static boolean isRunning() { return serverLifeCycle == ServerLifeCycle.RUNNING; @@ -39,39 +39,6 @@ public static boolean isStopped() { return serverLifeCycle == ServerLifeCycle.STOPPED; } - /** - * Change the current server state to {@link ServerLifeCycle#WAITING}, only {@link ServerLifeCycle#RUNNING} can change to {@link ServerLifeCycle#WAITING}. - * - * @throws ServerLifeCycleException if change failed. - */ - public static synchronized void toWaiting() throws ServerLifeCycleException { - if (isStopped()) { - throw new ServerLifeCycleException("The current server is already stopped, cannot change to waiting"); - } - - if (serverLifeCycle == ServerLifeCycle.WAITING) { - log.warn("The current server is already at waiting status, cannot change to waiting"); - return; - } - serverLifeCycle = ServerLifeCycle.WAITING; - } - - /** - * Recover from {@link ServerLifeCycle#WAITING} to {@link ServerLifeCycle#RUNNING}. - */ - public static synchronized void recoverFromWaiting() throws ServerLifeCycleException { - if (isStopped()) { - throw new ServerLifeCycleException("The current server is already stopped, cannot recovery"); - } - - if (serverLifeCycle == ServerLifeCycle.RUNNING) { - log.warn("The current server status is already running, cannot recover form waiting"); - return; - } - serverStartupTime = System.currentTimeMillis(); - serverLifeCycle = ServerLifeCycle.RUNNING; - } - public static synchronized boolean toStopped() { if (serverLifeCycle == ServerLifeCycle.STOPPED) { return false; diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeat.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeat.java deleted file mode 100644 index ca9c98fab4..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeat.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.streampark.registry.api.model; - -import org.apache.streampark.registry.api.enums.ServerStatusEnum; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.experimental.SuperBuilder; - -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor -@AllArgsConstructor -public class BaseHeartBeat implements HeartBeat { - - protected int processId; - protected long startupTime; - protected long reportTime; - protected ServerStatusEnum serverStatusEnum; - - protected String host; - protected int port; - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeatTask.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeatTask.java index 0585bc83aa..e343a2d719 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeatTask.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/BaseHeartBeatTask.java @@ -61,8 +61,7 @@ public void run() { } T heartBeat = getHeartBeat(); // if first time or heartBeat status changed, write heartBeatInfo into registry - if (System.currentTimeMillis() - lastWriteTime >= heartBeatInterval - || !lastHeartBeat.getServerStatusEnum().equals(heartBeat.getServerStatusEnum())) { + if (System.currentTimeMillis() - lastWriteTime >= heartBeatInterval) { lastHeartBeat = heartBeat; writeHeartBeat(heartBeat); lastWriteTime = System.currentTimeMillis(); diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/ConsoleHeartBeat.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/ConsoleHeartBeat.java index 8f6a9529b9..d73aed411b 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/ConsoleHeartBeat.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/ConsoleHeartBeat.java @@ -17,11 +17,23 @@ package org.apache.streampark.registry.api.model; +import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; +@Getter +@Setter @SuperBuilder @NoArgsConstructor -public class ConsoleHeartBeat extends BaseHeartBeat implements HeartBeat { +@AllArgsConstructor +public class ConsoleHeartBeat implements HeartBeat { + + protected long startupTime; + protected long reportTime; + + protected String host; + protected int port; } diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/HeartBeat.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/HeartBeat.java index 490ac12ed1..c326c089a4 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/HeartBeat.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/HeartBeat.java @@ -17,10 +17,6 @@ package org.apache.streampark.registry.api.model; -import org.apache.streampark.registry.api.enums.ServerStatusEnum; - public interface HeartBeat { - ServerStatusEnum getServerStatusEnum(); - } diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/Server.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/Server.java deleted file mode 100644 index 2571169fae..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/model/Server.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.streampark.registry.api.model; - -import lombok.Getter; -import lombok.Setter; - -import java.util.Date; - -@Getter -@Setter -public class Server { - - private int id; - - private String host; - - private int port; - - private String zkDirectory; - - /** - * resource info: CPU and memory - */ - private String resInfo; - - private Date createTime; - - private Date lastHeartbeatTime; - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/ClasspathSqlScriptParser.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/ClasspathSqlScriptParser.java deleted file mode 100644 index 3b414802dd..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/ClasspathSqlScriptParser.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.streampark.registry.api.sql; - -import org.apache.commons.lang3.StringUtils; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.Reader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -@Slf4j -public class ClasspathSqlScriptParser implements SqlScriptParser { - - private final String sqlScriptPath; - - private final Charset charset; - - public ClasspathSqlScriptParser(String sqlScriptPath) { - this.sqlScriptPath = sqlScriptPath; - this.charset = StandardCharsets.UTF_8; - } - - @Override - public List getAllSql() throws IOException { - Resource sqlScriptResource = new ClassPathResource(sqlScriptPath); - if (!sqlScriptResource.exists()) { - log.warn("The sql script file {} doesn't exist", sqlScriptPath); - return Collections.emptyList(); - } - List result = new ArrayList<>(); - try ( - InputStream inputStream = sqlScriptResource.getInputStream(); - Reader sqlScriptReader = new InputStreamReader(inputStream, charset); - LineNumberReader lineNumberReader = new LineNumberReader(sqlScriptReader)) { - String sql; - do { - sql = parseNextSql(lineNumberReader); - if (StringUtils.isNotBlank(sql)) { - result.add(sql); - } - } while (StringUtils.isNotBlank(sql)); - } - return result; - } - - private String parseNextSql(LineNumberReader lineNumberReader) throws IOException { - String line; - while ((line = lineNumberReader.readLine()) != null) { - String trimLine = line.trim(); - if (StringUtils.isEmpty(trimLine) || isComment(trimLine)) { - // Skip the empty line, comment line - continue; - } - if (trimLine.startsWith("/*")) { - skipLicenseHeader(lineNumberReader); - continue; - } - if (trimLine.startsWith("delimiter")) { - // begin to parse processor, until delimiter ; - String[] split = trimLine.split(" "); - if (split[1].equals(";")) { - continue; - } - return parseProcedure(lineNumberReader, split[1]); - } - // begin to parse sql until; - List sqlLines = new ArrayList<>(); - sqlLines.add(line); - while (!line.endsWith(";")) { - line = lineNumberReader.readLine(); - if (line == null) { - break; - } - if (StringUtils.isBlank(line)) { - continue; - } - sqlLines.add(line); - } - return String.join("\n", sqlLines); - } - return null; - } - - private void skipLicenseHeader(LineNumberReader lineNumberReader) throws IOException { - String line; - while ((line = lineNumberReader.readLine()) != null) { - String trimLine = line.trim(); - if (StringUtils.isEmpty(trimLine) || isComment(trimLine)) { - // Skip the empty line, comment line - continue; - } - if (line.startsWith("*/")) { - break; - } - } - } - - private String parseProcedure(LineNumberReader lineNumberReader, String delimiter) throws IOException { - List sqlLines = new ArrayList<>(); - // begin to parse processor, until delimiter ; - String line; - while (true) { - line = lineNumberReader.readLine(); - if (line == null) { - break; - } - if (StringUtils.isBlank(line)) { - continue; - } - if (line.trim().startsWith(delimiter)) { - break; - } - sqlLines.add(line); - } - return String.join("\n", sqlLines); - } - - private boolean isComment(String line) { - return line.startsWith("--") || line.startsWith("//"); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptParser.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptParser.java deleted file mode 100644 index bcf43710f6..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptParser.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.streampark.registry.api.sql; - -import java.io.IOException; -import java.util.List; - -public interface SqlScriptParser { - - List getAllSql() throws IOException; - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptRunner.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptRunner.java deleted file mode 100644 index 450e4e4280..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/sql/SqlScriptRunner.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.streampark.registry.api.sql; - -import org.apache.commons.lang3.StringUtils; - -import lombok.extern.slf4j.Slf4j; - -import javax.sql.DataSource; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; - -@Slf4j -public class SqlScriptRunner { - - private final DataSource dataSource; - - private final SqlScriptParser sqlScriptParser; - - /** - * @param dataSource DataSource which used to execute the sql script. - * @param sqlScriptFilePath Sqk script file path, the path should under classpath. - */ - public SqlScriptRunner(DataSource dataSource, String sqlScriptFilePath) { - this.dataSource = dataSource; - this.sqlScriptParser = new ClasspathSqlScriptParser(sqlScriptFilePath); - } - - public void execute() throws SQLException, IOException { - List allSql = sqlScriptParser.getAllSql(); - try (Connection connection = dataSource.getConnection()) { - for (String sql : allSql) { - if (StringUtils.isBlank(sql)) { - continue; - } - try (Statement statement = connection.createStatement()) { - // Since some sql doesn't have result so we believe if there is no exception then we think the sql - // execute success. - statement.execute(sql); - log.info("Execute sql: {} success", sql); - } - } - } - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/thread/BaseDaemonThread.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/thread/BaseDaemonThread.java index d156273a8c..c142d44e5e 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/thread/BaseDaemonThread.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/thread/BaseDaemonThread.java @@ -22,12 +22,6 @@ */ public abstract class BaseDaemonThread extends Thread { - protected BaseDaemonThread(Runnable runnable) { - super(runnable); - this.setDaemon(true); - this.setUncaughtExceptionHandler(DefaultUncaughtExceptionHandler.getInstance()); - } - protected BaseDaemonThread(String threadName) { super(); this.setName(threadName); diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/pom.xml b/streampark-console/streampark-console-registry/streampark-registry-core/pom.xml index a4877f6990..29ee505352 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/pom.xml +++ b/streampark-console/streampark-console-registry/streampark-registry-core/pom.xml @@ -79,14 +79,6 @@ hibernate-validator - - org.apache.streampark - streampark-registry-it - ${project.version} - test-jar - test - - org.testcontainers mysql diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistry.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistry.java index 58f5f972ef..9101f3ecfa 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistry.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistry.java @@ -17,25 +17,18 @@ package org.apache.streampark.registry.core; -import org.apache.streampark.registry.api.ConnectionListener; -import org.apache.streampark.registry.api.ConnectionState; import org.apache.streampark.registry.api.Event; import org.apache.streampark.registry.api.Registry; import org.apache.streampark.registry.api.RegistryException; import org.apache.streampark.registry.api.SubscribeListener; -import org.apache.streampark.registry.core.client.JdbcRegistryClient; -import org.apache.streampark.registry.core.model.DTO.DataType; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; -import org.apache.streampark.registry.core.server.ConnectionStateListener; import org.apache.streampark.registry.core.server.IJdbcRegistryServer; import org.apache.streampark.registry.core.server.JdbcRegistryDataChangeListener; import org.apache.commons.lang3.StringUtils; -import lombok.NonNull; import lombok.extern.slf4j.Slf4j; -import java.time.Duration; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -50,15 +43,10 @@ @Slf4j public final class JdbcRegistry implements Registry { - private final JdbcRegistryProperties jdbcRegistryProperties; - private final JdbcRegistryClient jdbcRegistryClient; - private final IJdbcRegistryServer jdbcRegistryServer; - JdbcRegistry(JdbcRegistryProperties jdbcRegistryProperties, IJdbcRegistryServer jdbcRegistryServer) { - this.jdbcRegistryProperties = jdbcRegistryProperties; + JdbcRegistry(IJdbcRegistryServer jdbcRegistryServer) { this.jdbcRegistryServer = jdbcRegistryServer; - this.jdbcRegistryClient = new JdbcRegistryClient(jdbcRegistryProperties, jdbcRegistryServer); log.info("Initialize Jdbc Registry..."); } @@ -66,41 +54,14 @@ public final class JdbcRegistry implements Registry { public void start() { log.info("Starting Jdbc Registry..."); jdbcRegistryServer.start(); - jdbcRegistryClient.start(); log.info("Started Jdbc Registry..."); } - @Override - public boolean isConnected() { - return jdbcRegistryClient.isConnectivity(); - } - - @Override - public void connectUntilTimeout(@NonNull Duration timeout) throws RegistryException { - long beginTimeMillis = System.currentTimeMillis(); - long endTimeMills = timeout.getSeconds() <= 0 ? Long.MAX_VALUE : beginTimeMillis + timeout.toMillis(); - while (true) { - if (System.currentTimeMillis() > endTimeMills) { - throw new RegistryException( - String.format("Cannot connect to jdbc registry in %s s", timeout.getSeconds())); - } - if (jdbcRegistryClient.isConnectivity()) { - return; - } - try { - Thread.sleep(jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis()); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RegistryException("Cannot connect to jdbc registry due to interrupted exception", e); - } - } - } - @Override public void subscribe(String path, SubscribeListener listener) { checkNotNull(path); checkNotNull(listener); - jdbcRegistryClient.subscribeJdbcRegistryDataChange(new JdbcRegistryDataChangeListener() { + jdbcRegistryServer.subscribeJdbcRegistryDataChange(new JdbcRegistryDataChangeListener() { @Override public void onJdbcRegistryDataChanged(String key, String value) { @@ -145,34 +106,12 @@ public void onJdbcRegistryDataAdded(String key, String value) { }); } - @Override - public void addConnectionStateListener(ConnectionListener listener) { - checkNotNull(listener); - jdbcRegistryClient.subscribeConnectionStateChange(new ConnectionStateListener() { - - @Override - public void onConnected() { - listener.onUpdate(ConnectionState.CONNECTED); - } - - @Override - public void onDisConnected() { - listener.onUpdate(ConnectionState.DISCONNECTED); - } - - @Override - public void onReconnected() { - listener.onUpdate(ConnectionState.RECONNECTED); - } - }); - } - @Override public String get(String key) { try { // get the key value // Directly get from the db? - Optional jdbcRegistryDataOptional = jdbcRegistryClient.getJdbcRegistryDataByKey(key); + Optional jdbcRegistryDataOptional = jdbcRegistryServer.getJdbcRegistryDataByKey(key); if (!jdbcRegistryDataOptional.isPresent()) { throw new RegistryException("key: " + key + " not exist"); } @@ -185,10 +124,9 @@ public String get(String key) { } @Override - public void put(String key, String value, boolean deleteOnDisconnect) { + public void put(String key, String value) { try { - DataType dataType = deleteOnDisconnect ? DataType.EPHEMERAL : DataType.PERSISTENT; - jdbcRegistryClient.putJdbcRegistryData(key, value, dataType); + jdbcRegistryServer.putJdbcRegistryData(key, value); } catch (Exception ex) { throw new RegistryException(String.format("put key:%s, value:%s error", key, value), ex); } @@ -197,7 +135,7 @@ public void put(String key, String value, boolean deleteOnDisconnect) { @Override public void delete(String key) { try { - jdbcRegistryClient.deleteJdbcRegistryDataByKey(key); + jdbcRegistryServer.deleteJdbcRegistryDataByKey(key); } catch (Exception e) { throw new RegistryException(String.format("Delete key: %s error", key), e); } @@ -206,7 +144,7 @@ public void delete(String key) { @Override public Collection children(String key) { try { - List children = jdbcRegistryClient.listJdbcRegistryDataChildren(key); + List children = jdbcRegistryServer.listJdbcRegistryDataChildren(key); return children .stream() .map(JdbcRegistryDataDTO::getDataKey) @@ -222,48 +160,18 @@ public Collection children(String key) { @Override public boolean exists(String key) { try { - return jdbcRegistryClient.existJdbcRegistryDataKey(key); + return jdbcRegistryServer.getJdbcRegistryDataByKey(key).isPresent(); } catch (Exception e) { throw new RegistryException(String.format("Check key: %s exist error", key), e); } } - @Override - public boolean acquireLock(String key) { - try { - jdbcRegistryClient.acquireJdbcRegistryLock(key); - return true; - } catch (RegistryException e) { - throw e; - } catch (Exception e) { - throw new RegistryException(String.format("Acquire lock: %s error", key), e); - } - } - - @Override - public boolean acquireLock(String key, long timeout) { - try { - return jdbcRegistryClient.acquireJdbcRegistryLock(key, timeout); - } catch (RegistryException e) { - throw e; - } catch (Exception e) { - throw new RegistryException(String.format("Acquire lock: %s error", key), e); - } - } - - @Override - public boolean releaseLock(String key) { - jdbcRegistryClient.releaseJdbcRegistryLock(key); - return true; - } - @Override public void close() { log.info("Closing Jdbc Registry..."); // remove the current Ephemeral node, if can connect to jdbc try { jdbcRegistryServer.close(); - jdbcRegistryClient.close(); } catch (Exception e) { log.error("Close Jdbc Registry error", e); } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistryAutoConfiguration.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistryAutoConfiguration.java index bb67990553..b96084d6c9 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistryAutoConfiguration.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/JdbcRegistryAutoConfiguration.java @@ -17,14 +17,10 @@ package org.apache.streampark.registry.core; -import org.apache.streampark.registry.core.mapper.JdbcRegistryClientHeartbeatMapper; import org.apache.streampark.registry.core.mapper.JdbcRegistryDataChanceEventMapper; import org.apache.streampark.registry.core.mapper.JdbcRegistryDataMapper; -import org.apache.streampark.registry.core.mapper.JdbcRegistryLockMapper; -import org.apache.streampark.registry.core.repository.JdbcRegistryClientRepository; import org.apache.streampark.registry.core.repository.JdbcRegistryDataChanceEventRepository; import org.apache.streampark.registry.core.repository.JdbcRegistryDataRepository; -import org.apache.streampark.registry.core.repository.JdbcRegistryLockRepository; import org.apache.streampark.registry.core.server.IJdbcRegistryServer; import org.apache.streampark.registry.core.server.JdbcRegistryServer; @@ -57,22 +53,17 @@ public JdbcRegistryAutoConfiguration() { @Bean public IJdbcRegistryServer jdbcRegistryServer(JdbcRegistryDataRepository jdbcRegistryDataRepository, - JdbcRegistryLockRepository jdbcRegistryLockRepository, - JdbcRegistryClientRepository jdbcRegistryClientRepository, JdbcRegistryDataChanceEventRepository jdbcRegistryDataChanceEventRepository, JdbcRegistryProperties jdbcRegistryProperties) { return new JdbcRegistryServer( jdbcRegistryDataRepository, - jdbcRegistryLockRepository, - jdbcRegistryClientRepository, jdbcRegistryDataChanceEventRepository, jdbcRegistryProperties); } @Bean - public JdbcRegistry jdbcRegistry(JdbcRegistryProperties jdbcRegistryProperties, - IJdbcRegistryServer jdbcRegistryServer) { - JdbcRegistry jdbcRegistry = new JdbcRegistry(jdbcRegistryProperties, jdbcRegistryServer); + public JdbcRegistry jdbcRegistry(IJdbcRegistryServer jdbcRegistryServer) { + JdbcRegistry jdbcRegistry = new JdbcRegistry(jdbcRegistryServer); jdbcRegistry.start(); return jdbcRegistry; } @@ -99,22 +90,10 @@ public JdbcRegistryDataMapper jdbcRegistryDataMapper(SqlSessionTemplate jdbcRegi return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryDataMapper.class); } - @Bean - public JdbcRegistryLockMapper jdbcRegistryLockMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) { - jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryLockMapper.class); - return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryLockMapper.class); - } - @Bean public JdbcRegistryDataChanceEventMapper jdbcRegistryDataChanceEventMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) { jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryDataChanceEventMapper.class); return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryDataChanceEventMapper.class); } - @Bean - public JdbcRegistryClientHeartbeatMapper jdbcRegistryClientHeartbeatMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) { - jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryClientHeartbeatMapper.class); - return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryClientHeartbeatMapper.class); - } - } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/LockUtils.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/LockUtils.java deleted file mode 100644 index 0f4f86c181..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/LockUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.streampark.registry.core; - -import org.apache.streampark.common.utils.NetworkUtils; -import org.apache.streampark.common.utils.OSUtils; - -import lombok.experimental.UtilityClass; - -@UtilityClass -public class LockUtils { - - private static final String LOCK_OWNER_PREFIX = NetworkUtils.getHost() + "_" + OSUtils.getProcessID() + "_"; - - public static String getLockOwner() { - return LOCK_OWNER_PREFIX + Thread.currentThread().getName(); - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/IJdbcRegistryClient.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/IJdbcRegistryClient.java deleted file mode 100644 index b6f487090b..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/IJdbcRegistryClient.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.streampark.registry.core.client; - -import org.apache.streampark.registry.core.model.DTO.DataType; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; -import org.apache.streampark.registry.core.server.ConnectionStateListener; -import org.apache.streampark.registry.core.server.JdbcRegistryDataChangeListener; - -import java.util.List; -import java.util.Optional; - -public interface IJdbcRegistryClient extends AutoCloseable { - - /** - * Start the jdbc registry client, once started, the client will connect to the jdbc registry server, and then it can be used. - */ - void start(); - - /** - * Get identify of the client. - */ - JdbcRegistryClientIdentify getJdbcRegistryClientIdentify(); - - /** - * Check the connectivity of the client. - */ - boolean isConnectivity(); - - /** - * Subscribe the jdbc registry connection state change event. - */ - void subscribeConnectionStateChange(ConnectionStateListener connectionStateListener); - - /** - * Subscribe the {@link JdbcRegistryDataDTO} change event. - */ - void subscribeJdbcRegistryDataChange(JdbcRegistryDataChangeListener jdbcRegistryDataChangeListener); - - /** - * Get the {@link JdbcRegistryDataDTO} by key. - */ - Optional getJdbcRegistryDataByKey(String key); - - /** - * Put the {@link JdbcRegistryDataDTO} to the jdbc registry server. - *

- * If the key is already exist, then update the {@link JdbcRegistryDataDTO}. If the key is not exist, then insert a new {@link JdbcRegistryDataDTO}. - */ - void putJdbcRegistryData(String key, String value, DataType dataType); - - /** - * Delete the {@link JdbcRegistryDataDTO} by key. - */ - void deleteJdbcRegistryDataByKey(String key); - - /** - * List all the {@link JdbcRegistryDataDTO} children by key. - *

- * e.g. key = "/streampark/master", and data exist in db is "/streampark/master/master1", "/streampark/master/master2" - *

- * then the return value will be ["master1", "master2"] - */ - List listJdbcRegistryDataChildren(String key); - - /** - * Check the key exist in the jdbc registry server. - */ - boolean existJdbcRegistryDataKey(String key); - - /** - * Acquire the jdbc registry lock by key. this is a blocking method. if you want to stop the blocking, you can use interrupt the thread. - */ - void acquireJdbcRegistryLock(String lockKey) throws IllegalArgumentException; - - /** - * Acquire the jdbc registry lock by key until timeout. - */ - boolean acquireJdbcRegistryLock(String lockKey, long timeout); - - /** - * Release the jdbc registry lock by key, if the lockKey is not exist will do nothing. - */ - void releaseJdbcRegistryLock(String lockKey); - - /** - * Close the jdbc registry client, once the client been closed, it cannot work anymore. - */ - @Override - void close(); -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClient.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClient.java deleted file mode 100644 index 2775953e7a..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClient.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.streampark.registry.core.client; - -import org.apache.streampark.common.utils.NetworkUtils; -import org.apache.streampark.common.utils.OSUtils; -import org.apache.streampark.common.utils.UUIDUtils; -import org.apache.streampark.registry.core.JdbcRegistryProperties; -import org.apache.streampark.registry.core.model.DTO.DataType; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; -import org.apache.streampark.registry.core.server.ConnectionStateListener; -import org.apache.streampark.registry.core.server.IJdbcRegistryServer; -import org.apache.streampark.registry.core.server.JdbcRegistryDataChangeListener; -import org.apache.streampark.registry.core.server.JdbcRegistryServer; -import org.apache.streampark.registry.core.server.JdbcRegistryServerState; - -import lombok.extern.slf4j.Slf4j; - -import java.util.List; -import java.util.Optional; - -/** - * The client of jdbc registry, used to interact with the {@link JdbcRegistryServer}. - */ -@Slf4j -public class JdbcRegistryClient implements IJdbcRegistryClient { - - private static final String DEFAULT_CLIENT_NAME = NetworkUtils.getHost() + "_" + OSUtils.getProcessID(); - - private final JdbcRegistryProperties jdbcRegistryProperties; - - private final JdbcRegistryClientIdentify jdbcRegistryClientIdentify; - - private final IJdbcRegistryServer jdbcRegistryServer; - - public JdbcRegistryClient(JdbcRegistryProperties jdbcRegistryProperties, IJdbcRegistryServer jdbcRegistryServer) { - this.jdbcRegistryProperties = jdbcRegistryProperties; - this.jdbcRegistryServer = jdbcRegistryServer; - this.jdbcRegistryClientIdentify = - new JdbcRegistryClientIdentify(UUIDUtils.generateUUID(), DEFAULT_CLIENT_NAME); - } - - @Override - public void start() { - jdbcRegistryServer.registerClient(this); - } - - @Override - public JdbcRegistryClientIdentify getJdbcRegistryClientIdentify() { - return jdbcRegistryClientIdentify; - } - - @Override - public void subscribeConnectionStateChange(ConnectionStateListener connectionStateListener) { - jdbcRegistryServer.subscribeConnectionStateChange(connectionStateListener); - } - - @Override - public void subscribeJdbcRegistryDataChange(JdbcRegistryDataChangeListener jdbcRegistryDataChangeListener) { - jdbcRegistryServer.subscribeJdbcRegistryDataChange(jdbcRegistryDataChangeListener); - } - - @Override - public Optional getJdbcRegistryDataByKey(String key) { - return jdbcRegistryServer.getJdbcRegistryDataByKey(key); - } - - @Override - public void putJdbcRegistryData(String key, String value, DataType dataType) { - jdbcRegistryServer.putJdbcRegistryData(jdbcRegistryClientIdentify.getClientId(), key, value, dataType); - } - - @Override - public void deleteJdbcRegistryDataByKey(String key) { - jdbcRegistryServer.deleteJdbcRegistryDataByKey(key); - } - - @Override - public List listJdbcRegistryDataChildren(String key) { - return jdbcRegistryServer.listJdbcRegistryDataChildren(key); - } - - @Override - public boolean existJdbcRegistryDataKey(String key) { - return jdbcRegistryServer.existJdbcRegistryDataKey(key); - } - - @Override - public void acquireJdbcRegistryLock(String key) { - jdbcRegistryServer.acquireJdbcRegistryLock(jdbcRegistryClientIdentify.getClientId(), key); - } - - @Override - public boolean acquireJdbcRegistryLock(String key, long timeout) { - return jdbcRegistryServer.acquireJdbcRegistryLock(jdbcRegistryClientIdentify.getClientId(), key, timeout); - } - - @Override - public void releaseJdbcRegistryLock(String key) { - jdbcRegistryServer.releaseJdbcRegistryLock(jdbcRegistryClientIdentify.getClientId(), key); - } - - @Override - public void close() { - jdbcRegistryServer.deregisterClient(this); - log.info("Closed JdbcRegistryClient: {}", jdbcRegistryClientIdentify); - } - - @Override - public boolean isConnectivity() { - return jdbcRegistryServer.getServerState() == JdbcRegistryServerState.STARTED; - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClientIdentify.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClientIdentify.java deleted file mode 100644 index 7481c3a30f..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/client/JdbcRegistryClientIdentify.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.streampark.registry.core.client; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.ToString; - -@ToString -@Getter -@AllArgsConstructor -public class JdbcRegistryClientIdentify { - - private final Long clientId; - - private final String clientName; - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryClientHeartbeatMapper.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryClientHeartbeatMapper.java deleted file mode 100644 index f1a27c299e..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryClientHeartbeatMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.streampark.registry.core.mapper; - -import org.apache.streampark.registry.core.model.DO.JdbcRegistryClientHeartbeat; - -import org.apache.ibatis.annotations.Select; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -import java.util.List; - -public interface JdbcRegistryClientHeartbeatMapper extends BaseMapper { - - @Select("select * from t_jdbc_registry_client_heartbeat") - List selectAll(); - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataChanceEventMapper.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataChanceEventMapper.java index b66982ed95..f5975c1582 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataChanceEventMapper.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataChanceEventMapper.java @@ -36,6 +36,6 @@ public interface JdbcRegistryDataChanceEventMapper extends BaseMapper #{id} order by id asc limit 1000") List selectJdbcRegistryDataChangeEventWhereIdAfter(@Param("id") long id); - @Delete("delete from t_jdbc_registry_data_change_event where create_time > #{createTime}") + @Delete("delete from t_jdbc_registry_data_change_event where create_time < #{createTime}") void deleteJdbcRegistryDataChangeEventBeforeCreateTime(@Param("createTime") Date createTime); } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataMapper.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataMapper.java index c0eb45dff0..dde0061af7 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataMapper.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryDataMapper.java @@ -37,15 +37,4 @@ public interface JdbcRegistryDataMapper extends BaseMapper { @Delete("delete from t_jdbc_registry_data where data_key = #{key}") void deleteByKey(@Param("key") String key); - - @Delete({""}) - void deleteByClientIds(@Param("clientIds") List clientIds, @Param("dataType") String dataType); - } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryLockMapper.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryLockMapper.java deleted file mode 100644 index 84f8d7e45b..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/mapper/JdbcRegistryLockMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.streampark.registry.core.mapper; - -import org.apache.streampark.registry.core.model.DO.JdbcRegistryLock; - -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Param; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -import java.util.List; - -public interface JdbcRegistryLockMapper extends BaseMapper { - - @Delete({""}) - void deleteByClientIds(@Param("clientIds") List clientIds); -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryClientHeartbeat.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryClientHeartbeat.java deleted file mode 100644 index 3875acab8e..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryClientHeartbeat.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.streampark.registry.core.model.DO; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Date; - -@TableName(value = "t_jdbc_registry_client_heartbeat") -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcRegistryClientHeartbeat { - - @TableId(value = "id", type = IdType.INPUT) - private Long id; - private String clientName; - private Long lastHeartbeatTime; - private String connectionConfig; - private Date createTime; - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryData.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryData.java index 29e3c8810b..42d87e28c2 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryData.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryData.java @@ -40,8 +40,6 @@ public class JdbcRegistryData { private Long id; private String dataKey; private String dataValue; - private String dataType; - private long clientId; private Date createTime; private Date lastUpdateTime; diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryDataChanceEvent.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryDataChanceEvent.java index 8088a3bb4a..f9c016484f 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryDataChanceEvent.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryDataChanceEvent.java @@ -38,11 +38,8 @@ public class JdbcRegistryDataChanceEvent { @TableId(value = "id", type = IdType.AUTO) private Long id; - private String eventType; - private String jdbcRegistryData; - private Date createTime; } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryLock.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryLock.java deleted file mode 100644 index f77783c011..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DO/JdbcRegistryLock.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.streampark.registry.core.model.DO; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Date; - -@TableName(value = "t_jdbc_registry_lock") -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcRegistryLock { - - @TableId(value = "id", type = IdType.AUTO) - private Long id; - private String lockKey; - private String lockOwner; - private Long clientId; - private Date createTime; -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/DataType.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/DataType.java deleted file mode 100644 index cd33dc186b..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/DataType.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.streampark.registry.core.model.DTO; - -public enum DataType { - - EPHEMERAL(), - PERSISTENT(), - ; -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryClientHeartbeatDTO.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryClientHeartbeatDTO.java deleted file mode 100644 index 462ba92f9b..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryClientHeartbeatDTO.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.streampark.registry.core.model.DTO; - -import org.apache.streampark.common.utils.JSONUtils; -import org.apache.streampark.registry.core.model.DO.JdbcRegistryClientHeartbeat; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.SneakyThrows; - -import java.util.Date; - -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcRegistryClientHeartbeatDTO { - - private Long id; - - // clientName - private String clientName; - - private Long lastHeartbeatTime; - - private ClientConfig clientConfig; - - private Date createTime; - - public static JdbcRegistryClientHeartbeatDTO fromJdbcRegistryClientHeartbeat(JdbcRegistryClientHeartbeat jdbcRegistryClientHeartbeat) { - return JdbcRegistryClientHeartbeatDTO.builder() - .id(jdbcRegistryClientHeartbeat.getId()) - .clientName(jdbcRegistryClientHeartbeat.getClientName()) - .lastHeartbeatTime(jdbcRegistryClientHeartbeat.getLastHeartbeatTime()) - .clientConfig( - JSONUtils.parseObject(jdbcRegistryClientHeartbeat.getConnectionConfig(), ClientConfig.class)) - .createTime(jdbcRegistryClientHeartbeat.getCreateTime()) - .build(); - } - - public static JdbcRegistryClientHeartbeat toJdbcRegistryClientHeartbeat(JdbcRegistryClientHeartbeatDTO jdbcRegistryClientHeartbeatDTO) { - return JdbcRegistryClientHeartbeat.builder() - .id(jdbcRegistryClientHeartbeatDTO.getId()) - .clientName(jdbcRegistryClientHeartbeatDTO.getClientName()) - .lastHeartbeatTime(jdbcRegistryClientHeartbeatDTO.getLastHeartbeatTime()) - .connectionConfig(JSONUtils.toJsonString(jdbcRegistryClientHeartbeatDTO.getClientConfig())) - .createTime(jdbcRegistryClientHeartbeatDTO.getCreateTime()) - .build(); - } - - public boolean isDead() { - // check if the client connection is expired. - return System.currentTimeMillis() - lastHeartbeatTime > clientConfig.getSessionTimeout(); - } - - @SneakyThrows - @Override - public JdbcRegistryClientHeartbeatDTO clone() { - return JdbcRegistryClientHeartbeatDTO.builder() - .id(id) - .clientName(clientName) - .lastHeartbeatTime(lastHeartbeatTime) - .clientConfig(clientConfig) - .createTime(createTime) - .build(); - } - - @Getter - @Setter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class ClientConfig { - - @Builder.Default - private long sessionTimeout = 60 * 1000L; - - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataChanceEventDTO.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataChanceEventDTO.java index 8803e83fcb..62a3ce8e4f 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataChanceEventDTO.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataChanceEventDTO.java @@ -37,18 +37,14 @@ public class JdbcRegistryDataChanceEventDTO { private Long id; - private EventType eventType; - private JdbcRegistryDataDTO jdbcRegistryData; - private Date createTime; public enum EventType { ADD, UPDATE, DELETE; - } public static JdbcRegistryDataChanceEventDTO fromJdbcRegistryDataChanceEvent(JdbcRegistryDataChanceEvent jdbcRegistryDataChanceEvent) { diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataDTO.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataDTO.java index 06df011a7c..2464ebb0cc 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataDTO.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryDataDTO.java @@ -37,8 +37,6 @@ public class JdbcRegistryDataDTO { private Long id; private String dataKey; private String dataValue; - private String dataType; - private Long clientId; private Date createTime; private Date lastUpdateTime; @@ -47,8 +45,6 @@ public static JdbcRegistryDataDTO fromJdbcRegistryData(JdbcRegistryData jdbcRegi .id(jdbcRegistryData.getId()) .dataKey(jdbcRegistryData.getDataKey()) .dataValue(jdbcRegistryData.getDataValue()) - .dataType(jdbcRegistryData.getDataType()) - .clientId(jdbcRegistryData.getClientId()) .createTime(jdbcRegistryData.getCreateTime()) .lastUpdateTime(jdbcRegistryData.getLastUpdateTime()) .build(); @@ -59,8 +55,6 @@ public static JdbcRegistryData toJdbcRegistryData(JdbcRegistryDataDTO jdbcRegist .id(jdbcRegistryData.getId()) .dataKey(jdbcRegistryData.getDataKey()) .dataValue(jdbcRegistryData.getDataValue()) - .dataType(jdbcRegistryData.getDataType()) - .clientId(jdbcRegistryData.getClientId()) .createTime(jdbcRegistryData.getCreateTime()) .lastUpdateTime(jdbcRegistryData.getLastUpdateTime()) .build(); diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryLockDTO.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryLockDTO.java deleted file mode 100644 index e274f52ecd..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/model/DTO/JdbcRegistryLockDTO.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.streampark.registry.core.model.DTO; - -import org.apache.streampark.registry.core.model.DO.JdbcRegistryLock; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Date; - -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class JdbcRegistryLockDTO { - - private Long id; - private String lockKey; - private String lockOwner; - private Long clientId; - private Date createTime; - - public static JdbcRegistryLockDTO fromJdbcRegistryLock(JdbcRegistryLock jdbcRegistryLock) { - return JdbcRegistryLockDTO.builder() - .id(jdbcRegistryLock.getId()) - .lockKey(jdbcRegistryLock.getLockKey()) - .lockOwner(jdbcRegistryLock.getLockOwner()) - .clientId(jdbcRegistryLock.getClientId()) - .createTime(jdbcRegistryLock.getCreateTime()) - .build(); - } - - public static JdbcRegistryLock toJdbcRegistryLock(JdbcRegistryLockDTO jdbcRegistryLock) { - return JdbcRegistryLock.builder() - .id(jdbcRegistryLock.getId()) - .lockKey(jdbcRegistryLock.getLockKey()) - .lockOwner(jdbcRegistryLock.getLockOwner()) - .clientId(jdbcRegistryLock.getClientId()) - .createTime(jdbcRegistryLock.getCreateTime()) - .build(); - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryClientRepository.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryClientRepository.java deleted file mode 100644 index c3ae1797b3..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryClientRepository.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.streampark.registry.core.repository; - -import org.apache.streampark.registry.core.mapper.JdbcRegistryClientHeartbeatMapper; -import org.apache.streampark.registry.core.model.DO.JdbcRegistryClientHeartbeat; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryClientHeartbeatDTO; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; -import org.springframework.util.CollectionUtils; - -import java.util.List; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; - -@Repository -public class JdbcRegistryClientRepository { - - @Autowired - private JdbcRegistryClientHeartbeatMapper jdbcRegistryClientHeartbeatMapper; - - public List queryAll() { - return jdbcRegistryClientHeartbeatMapper.selectAll() - .stream() - .map(JdbcRegistryClientHeartbeatDTO::fromJdbcRegistryClientHeartbeat) - .collect(Collectors.toList()); - } - - public void deleteByIds(List clientIds) { - if (CollectionUtils.isEmpty(clientIds)) { - return; - } - jdbcRegistryClientHeartbeatMapper.deleteBatchIds(clientIds); - } - - public boolean updateById(JdbcRegistryClientHeartbeatDTO jdbcRegistryClientHeartbeatDTO) { - JdbcRegistryClientHeartbeat jdbcRegistryClientHeartbeat = - JdbcRegistryClientHeartbeatDTO.toJdbcRegistryClientHeartbeat(jdbcRegistryClientHeartbeatDTO); - return jdbcRegistryClientHeartbeatMapper.updateById(jdbcRegistryClientHeartbeat) == 1; - } - - public void insert(JdbcRegistryClientHeartbeatDTO jdbcRegistryClient) { - checkNotNull(jdbcRegistryClient.getId()); - JdbcRegistryClientHeartbeat jdbcRegistryClientHeartbeat = - JdbcRegistryClientHeartbeatDTO.toJdbcRegistryClientHeartbeat(jdbcRegistryClient); - jdbcRegistryClientHeartbeatMapper.insert(jdbcRegistryClientHeartbeat); - - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryDataRepository.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryDataRepository.java index 0ceedafb15..8bf5297e7e 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryDataRepository.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryDataRepository.java @@ -19,12 +19,10 @@ import org.apache.streampark.registry.core.mapper.JdbcRegistryDataMapper; import org.apache.streampark.registry.core.model.DO.JdbcRegistryData; -import org.apache.streampark.registry.core.model.DTO.DataType; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; -import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Optional; @@ -49,13 +47,6 @@ public Optional selectByKey(String key) { .map(JdbcRegistryDataDTO::fromJdbcRegistryData); } - public void deleteEphemeralDateByClientIds(List clientIds) { - if (CollectionUtils.isEmpty(clientIds)) { - return; - } - jdbcRegistryDataMapper.deleteByClientIds(clientIds, DataType.EPHEMERAL.name()); - } - public void deleteByKey(String key) { jdbcRegistryDataMapper.deleteByKey(key); } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryLockRepository.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryLockRepository.java deleted file mode 100644 index b9771bc448..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/repository/JdbcRegistryLockRepository.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.streampark.registry.core.repository; - -import org.apache.streampark.registry.core.mapper.JdbcRegistryLockMapper; -import org.apache.streampark.registry.core.model.DO.JdbcRegistryLock; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryLockDTO; - -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkNotNull; - -@Repository -public class JdbcRegistryLockRepository { - - @Autowired - private JdbcRegistryLockMapper jdbcRegistryLockMapper; - - public void deleteByClientIds(List clientIds) { - if (CollectionUtils.isEmpty(clientIds)) { - return; - } - jdbcRegistryLockMapper.deleteByClientIds(clientIds); - } - - public void insert(JdbcRegistryLockDTO jdbcRegistryLock) { - checkNotNull(jdbcRegistryLock); - JdbcRegistryLock jdbcRegistryLockDO = JdbcRegistryLockDTO.toJdbcRegistryLock(jdbcRegistryLock); - jdbcRegistryLockMapper.insert(jdbcRegistryLockDO); - jdbcRegistryLock.setId(jdbcRegistryLockDO.getId()); - } - - public void deleteById(Long id) { - jdbcRegistryLockMapper.deleteById(id); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/ConnectionStateListener.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/ConnectionStateListener.java deleted file mode 100644 index e0053c7970..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/ConnectionStateListener.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.streampark.registry.core.server; - -public interface ConnectionStateListener { - - void onConnected(); - - void onDisConnected(); - - void onReconnected(); -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryDataManager.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryDataManager.java index 4ecca0738d..9324c618d7 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryDataManager.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryDataManager.java @@ -17,7 +17,6 @@ package org.apache.streampark.registry.core.server; -import org.apache.streampark.registry.core.model.DTO.DataType; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; import java.util.List; @@ -25,8 +24,6 @@ public interface IJdbcRegistryDataManager { - boolean existKey(String key); - /** * Get the {@link JdbcRegistryDataDTO} by key. */ @@ -46,7 +43,7 @@ public interface IJdbcRegistryDataManager { *

* If the key is already exist, then update the {@link JdbcRegistryDataDTO}. If the key is not exist, then insert a new {@link JdbcRegistryDataDTO}. */ - void putJdbcRegistryData(Long clientId, String key, String value, DataType dataType); + void putJdbcRegistryData(String key, String value); /** * Delete the {@link JdbcRegistryDataDTO} by key. diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryLockManager.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryLockManager.java deleted file mode 100644 index 7d8f9d291c..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryLockManager.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.streampark.registry.core.server; - -public interface IJdbcRegistryLockManager { - - /** - * Acquire the jdbc registry lock by key. this is a blocking method. if you want to stop the blocking, you can use interrupt the thread. - */ - void acquireJdbcRegistryLock(Long clientId, String lockKey) throws InterruptedException; - - /** - * Acquire the jdbc registry lock by key until timeout. - */ - boolean acquireJdbcRegistryLock(Long clientId, String lockKey, long timeout); - - /** - * Release the jdbc registry lock by key, if the lockKey is not exist will do nothing. - */ - void releaseJdbcRegistryLock(Long clientId, String lockKey); - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryServer.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryServer.java index 3f03e74601..e2d8d6ff5c 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryServer.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/IJdbcRegistryServer.java @@ -17,9 +17,7 @@ package org.apache.streampark.registry.core.server; -import org.apache.streampark.registry.core.client.IJdbcRegistryClient; import org.apache.streampark.registry.core.model.DO.JdbcRegistryData; -import org.apache.streampark.registry.core.model.DTO.DataType; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; import java.util.List; @@ -32,36 +30,11 @@ public interface IJdbcRegistryServer extends AutoCloseable { void start(); - /** - * Register a client to the server, once the client connect to the server then the server will refresh the client's term interval. - */ - void registerClient(IJdbcRegistryClient jdbcRegistryClient); - - /** - * Deregister a client to the server, once the client id deregister, then the server will deleted the data related to the client and stop refresh the client's term. - */ - void deregisterClient(IJdbcRegistryClient jdbcRegistryClient); - - /** - * Get the {@link JdbcRegistryServerState} - */ - JdbcRegistryServerState getServerState(); - - /** - * Subscribe the jdbc registry connection state change - */ - void subscribeConnectionStateChange(ConnectionStateListener connectionStateListener); - /** * Subscribe the {@link JdbcRegistryData} change. */ void subscribeJdbcRegistryDataChange(JdbcRegistryDataChangeListener jdbcRegistryDataChangeListener); - /** - * Check the jdbc registry data key is exist or not. - */ - boolean existJdbcRegistryDataKey(String key); - /** * Get the {@link JdbcRegistryDataDTO} by key. */ @@ -81,28 +54,13 @@ public interface IJdbcRegistryServer extends AutoCloseable { *

* If the key is already exist, then update the {@link JdbcRegistryDataDTO}. If the key is not exist, then insert a new {@link JdbcRegistryDataDTO}. */ - void putJdbcRegistryData(Long clientId, String key, String value, DataType dataType); + void putJdbcRegistryData(String key, String value); /** * Delete the {@link JdbcRegistryDataDTO} by key. */ void deleteJdbcRegistryDataByKey(String key); - /** - * Acquire the jdbc registry lock by key. this is a blocking method. if you want to stop the blocking, you can use interrupt the thread. - */ - void acquireJdbcRegistryLock(Long clientId, String key); - - /** - * Acquire the jdbc registry lock by key until timeout. - */ - boolean acquireJdbcRegistryLock(Long clientId, String key, long timeout); - - /** - * Release the jdbc registry lock by key, if the lockKey is not exist will do nothing. - */ - void releaseJdbcRegistryLock(Long clientId, String key); - /** * Close the server, once the server been closed, it cannot work anymore. */ diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryDataManager.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryDataManager.java index 1b2ef8c495..470a73d074 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryDataManager.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryDataManager.java @@ -19,7 +19,6 @@ import org.apache.streampark.registry.core.JdbcRegistryProperties; import org.apache.streampark.registry.core.JdbcRegistryThreadFactory; -import org.apache.streampark.registry.core.model.DTO.DataType; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataChanceEventDTO; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; import org.apache.streampark.registry.core.repository.JdbcRegistryDataChanceEventRepository; @@ -128,12 +127,6 @@ public void subscribeRegistryRowChange(RegistryRowChangeListener getRegistryDataByKey(String key) { checkNotNull(key); @@ -151,27 +144,13 @@ public List listJdbcRegistryDataChildren(String key) { } @Override - public void putJdbcRegistryData(Long clientId, String key, String value, DataType dataType) { - checkNotNull(clientId); + public void putJdbcRegistryData(String key, String value) { checkNotNull(key); - checkNotNull(dataType); + checkNotNull(value); Optional jdbcRegistryDataOptional = jdbcRegistryDataRepository.selectByKey(key); if (jdbcRegistryDataOptional.isPresent()) { JdbcRegistryDataDTO jdbcRegistryData = jdbcRegistryDataOptional.get(); - if (!dataType.name().equals(jdbcRegistryData.getDataType())) { - throw new UnsupportedOperationException("The data type: " + jdbcRegistryData.getDataType() - + " of the key: " + key + " cannot be updated"); - } - - if (DataType.EPHEMERAL.name().equals(jdbcRegistryData.getDataType())) { - if (!jdbcRegistryData.getClientId().equals(clientId)) { - throw new UnsupportedOperationException( - "The EPHEMERAL data: " + key + " can only be updated by its owner: " - + jdbcRegistryData.getClientId() + " but not: " + clientId); - } - } - jdbcRegistryData.setDataValue(value); jdbcRegistryData.setLastUpdateTime(new Date()); jdbcRegistryDataRepository.updateById(jdbcRegistryData); @@ -184,10 +163,8 @@ public void putJdbcRegistryData(Long clientId, String key, String value, DataTyp jdbcRegistryDataChanceEventRepository.insert(jdbcRegistryDataChanceEvent); } else { JdbcRegistryDataDTO jdbcRegistryDataDTO = JdbcRegistryDataDTO.builder() - .clientId(clientId) .dataKey(key) .dataValue(value) - .dataType(dataType.name()) .createTime(new Date()) .lastUpdateTime(new Date()) .build(); @@ -260,5 +237,4 @@ private void doTriggerJdbcRegistryDataUpdatedListener(List } }); } - } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryLockManager.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryLockManager.java deleted file mode 100644 index ec0392f3af..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryLockManager.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.streampark.registry.core.server; - -import org.apache.streampark.registry.api.thread.ThreadUtils; -import org.apache.streampark.registry.core.JdbcRegistryProperties; -import org.apache.streampark.registry.core.LockUtils; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryLockDTO; -import org.apache.streampark.registry.core.repository.JdbcRegistryLockRepository; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.dao.DuplicateKeyException; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -@Slf4j -public class JdbcRegistryLockManager implements IJdbcRegistryLockManager { - - private final JdbcRegistryProperties jdbcRegistryProperties; - private final JdbcRegistryLockRepository jdbcRegistryLockRepository; - - // lockKey -> LockEntry - private final Map jdbcRegistryLockHolderMap = new HashMap<>(); - - public JdbcRegistryLockManager(JdbcRegistryProperties jdbcRegistryProperties, - JdbcRegistryLockRepository jdbcRegistryLockRepository) { - this.jdbcRegistryProperties = jdbcRegistryProperties; - this.jdbcRegistryLockRepository = jdbcRegistryLockRepository; - } - - @Override - public void acquireJdbcRegistryLock(Long clientId, String lockKey) { - String lockOwner = LockUtils.getLockOwner(); - while (true) { - LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey); - if (lockEntry != null && lockOwner.equals(lockEntry.getLockOwner())) { - return; - } - JdbcRegistryLockDTO jdbcRegistryLock = JdbcRegistryLockDTO.builder() - .lockKey(lockKey) - .clientId(clientId) - .lockOwner(lockOwner) - .createTime(new Date()) - .build(); - try { - jdbcRegistryLockRepository.insert(jdbcRegistryLock); - if (jdbcRegistryLock != null) { - jdbcRegistryLockHolderMap.put(lockKey, LockEntry.builder() - .lockKey(lockKey) - .lockOwner(lockOwner) - .jdbcRegistryLock(jdbcRegistryLock) - .build()); - return; - } - log.debug("{} acquire the lock {} success", lockOwner, lockKey); - } catch (DuplicateKeyException duplicateKeyException) { - // The lock is already exist, wait it release. - continue; - } - log.debug("Acquire the lock {} failed try again", lockKey); - // acquire failed, wait and try again - ThreadUtils.sleep(jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis()); - } - } - - @Override - public boolean acquireJdbcRegistryLock(Long clientId, String lockKey, long timeout) { - String lockOwner = LockUtils.getLockOwner(); - long start = System.currentTimeMillis(); - while (System.currentTimeMillis() - start <= timeout) { - LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey); - if (lockEntry != null && lockOwner.equals(lockEntry.getLockOwner())) { - return true; - } - JdbcRegistryLockDTO jdbcRegistryLock = JdbcRegistryLockDTO.builder() - .lockKey(lockKey) - .clientId(clientId) - .lockOwner(lockOwner) - .createTime(new Date()) - .build(); - try { - jdbcRegistryLockRepository.insert(jdbcRegistryLock); - if (jdbcRegistryLock != null) { - jdbcRegistryLockHolderMap.put(lockKey, LockEntry.builder() - .lockKey(lockKey) - .lockOwner(lockOwner) - .jdbcRegistryLock(jdbcRegistryLock) - .build()); - return true; - } - log.debug("{} acquire the lock {} success", lockOwner, lockKey); - } catch (DuplicateKeyException duplicateKeyException) { - // The lock is already exist, wait it release. - continue; - } - log.debug("Acquire the lock {} failed try again", lockKey); - // acquire failed, wait and try again - ThreadUtils.sleep(jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis()); - } - return false; - } - - @Override - public void releaseJdbcRegistryLock(Long clientId, String lockKey) { - LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey); - if (lockEntry == null) { - return; - } - if (!clientId.equals(lockEntry.getJdbcRegistryLock().getClientId())) { - throw new UnsupportedOperationException( - "The client " + clientId + " is not the lock owner of the lock: " + lockKey); - } - jdbcRegistryLockRepository.deleteById(lockEntry.getJdbcRegistryLock().getId()); - jdbcRegistryLockHolderMap.remove(lockKey); - } - - @Getter - @Setter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class LockEntry { - - private String lockKey; - private String lockOwner; - private JdbcRegistryLockDTO jdbcRegistryLock; - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServer.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServer.java index 596cbe58ed..4da98c5479 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServer.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServer.java @@ -17,33 +17,18 @@ package org.apache.streampark.registry.core.server; -import org.apache.streampark.registry.api.RegistryException; +import org.apache.streampark.registry.api.enums.RegistryNodeType; import org.apache.streampark.registry.core.JdbcRegistryProperties; import org.apache.streampark.registry.core.JdbcRegistryThreadFactory; -import org.apache.streampark.registry.core.client.IJdbcRegistryClient; -import org.apache.streampark.registry.core.client.JdbcRegistryClientIdentify; -import org.apache.streampark.registry.core.model.DTO.DataType; -import org.apache.streampark.registry.core.model.DTO.JdbcRegistryClientHeartbeatDTO; import org.apache.streampark.registry.core.model.DTO.JdbcRegistryDataDTO; -import org.apache.streampark.registry.core.repository.JdbcRegistryClientRepository; import org.apache.streampark.registry.core.repository.JdbcRegistryDataChanceEventRepository; import org.apache.streampark.registry.core.repository.JdbcRegistryDataRepository; -import org.apache.streampark.registry.core.repository.JdbcRegistryLockRepository; -import org.apache.commons.collections4.CollectionUtils; - -import com.google.common.collect.Lists; -import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -55,42 +40,17 @@ public class JdbcRegistryServer implements IJdbcRegistryServer { private final JdbcRegistryProperties jdbcRegistryProperties; - private final JdbcRegistryDataRepository jdbcRegistryDataRepository; - - private final JdbcRegistryLockRepository jdbcRegistryLockRepository; - - private final JdbcRegistryClientRepository jdbcRegistryClientRepository; - private final JdbcRegistryDataManager jdbcRegistryDataManager; - private final JdbcRegistryLockManager jdbcRegistryLockManager; - private JdbcRegistryServerState jdbcRegistryServerState; - private final List jdbcRegistryClients = new CopyOnWriteArrayList<>(); - - private final List connectionStateListeners = new CopyOnWriteArrayList<>(); - - private final Map jdbcRegistryClientDTOMap = - new ConcurrentHashMap<>(); - - private Long lastSuccessHeartbeat; - public JdbcRegistryServer(JdbcRegistryDataRepository jdbcRegistryDataRepository, - JdbcRegistryLockRepository jdbcRegistryLockRepository, - JdbcRegistryClientRepository jdbcRegistryClientRepository, JdbcRegistryDataChanceEventRepository jdbcRegistryDataChanceEventRepository, JdbcRegistryProperties jdbcRegistryProperties) { - this.jdbcRegistryDataRepository = checkNotNull(jdbcRegistryDataRepository); - this.jdbcRegistryLockRepository = checkNotNull(jdbcRegistryLockRepository); - this.jdbcRegistryClientRepository = checkNotNull(jdbcRegistryClientRepository); this.jdbcRegistryProperties = checkNotNull(jdbcRegistryProperties); this.jdbcRegistryDataManager = new JdbcRegistryDataManager( jdbcRegistryProperties, jdbcRegistryDataRepository, jdbcRegistryDataChanceEventRepository); - this.jdbcRegistryLockManager = new JdbcRegistryLockManager( - jdbcRegistryProperties, jdbcRegistryLockRepository); this.jdbcRegistryServerState = JdbcRegistryServerState.INIT; - lastSuccessHeartbeat = System.currentTimeMillis(); } @Override @@ -99,75 +59,37 @@ public void start() { // The server is already started or stopped, will not start again. return; } - // Purge the previous client to avoid the client is still in the registry. - purgePreviousJdbcRegistryClient(); - // Start the Purge thread - // The Purge thread will remove the client from the registry, and remove it's related data and lock. - // Connect to the database, load the data and lock. - purgeDeadJdbcRegistryClient(); - JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor() - .scheduleWithFixedDelay(this::purgeDeadJdbcRegistryClient, - jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis(), - jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis(), - TimeUnit.MILLISECONDS); jdbcRegistryDataManager.start(); jdbcRegistryServerState = JdbcRegistryServerState.STARTED; - doTriggerOnConnectedListener(); JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor() - .scheduleWithFixedDelay(this::refreshClientsHeartbeat, + .scheduleWithFixedDelay(this::checkServersHeartbeat, 0, jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis(), TimeUnit.MILLISECONDS); } - @SneakyThrows - @Override - public void registerClient(IJdbcRegistryClient jdbcRegistryClient) { - checkNotNull(jdbcRegistryClient); - - JdbcRegistryClientIdentify jdbcRegistryClientIdentify = jdbcRegistryClient.getJdbcRegistryClientIdentify(); - checkNotNull(jdbcRegistryClientIdentify); - - JdbcRegistryClientHeartbeatDTO registryClientDTO = JdbcRegistryClientHeartbeatDTO.builder() - .id(jdbcRegistryClientIdentify.getClientId()) - .clientName(jdbcRegistryClientIdentify.getClientName()) - .clientConfig( - new JdbcRegistryClientHeartbeatDTO.ClientConfig( - jdbcRegistryProperties.getSessionTimeout().toMillis())) - .createTime(new Date()) - .lastHeartbeatTime(System.currentTimeMillis()) - .build(); - - while (jdbcRegistryClientDTOMap.containsKey(jdbcRegistryClientIdentify)) { - log.warn("The client {} is already exist the registry.", jdbcRegistryClientIdentify.getClientId()); - Thread.sleep(jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis()); + private void checkServersHeartbeat() { + if (jdbcRegistryServerState == JdbcRegistryServerState.STOPPED) { + log.warn("The JdbcRegistryServer is STOPPED, will not refresh servers heartbeat."); + return; + } + // Check jdbc registry servers heartbeat + try { + long now = System.currentTimeMillis(); + List jdbcRegistryServers = + listJdbcRegistryDataChildren(RegistryNodeType.CONSOLE_SERVER.getRegistryPath()); + + for (JdbcRegistryDataDTO jdbcRegistryServer : jdbcRegistryServers) { + long lastUpdateTime = jdbcRegistryServer.getLastUpdateTime().getTime(); + if (now - lastUpdateTime > jdbcRegistryProperties.getSessionTimeout().toMillis()) { + deleteJdbcRegistryDataByKey(jdbcRegistryServer.getDataKey()); + log.info("{} has no heartbeat after {}s, will remove it from the servers.", + jdbcRegistryServer.getDataKey(), jdbcRegistryProperties.getSessionTimeout()); + } + } + } catch (Exception ex) { + log.error("Failed to check servers heartbeat", ex); } - jdbcRegistryClientRepository.insert(registryClientDTO); - jdbcRegistryClients.add(jdbcRegistryClient); - jdbcRegistryClientDTOMap.put(jdbcRegistryClientIdentify, registryClientDTO); - } - - @Override - public void deregisterClient(IJdbcRegistryClient jdbcRegistryClient) { - checkNotNull(jdbcRegistryClient); - jdbcRegistryClients.remove(jdbcRegistryClient); - jdbcRegistryClientDTOMap.remove(jdbcRegistryClient.getJdbcRegistryClientIdentify()); - - JdbcRegistryClientIdentify jdbcRegistryClientIdentify = jdbcRegistryClient.getJdbcRegistryClientIdentify(); - checkNotNull(jdbcRegistryClientIdentify); - - doPurgeJdbcRegistryClientInDB(Lists.newArrayList(jdbcRegistryClientIdentify.getClientId())); - } - - @Override - public JdbcRegistryServerState getServerState() { - return jdbcRegistryServerState; - } - - @Override - public void subscribeConnectionStateChange(ConnectionStateListener connectionStateListener) { - checkNotNull(connectionStateListener); - connectionStateListeners.add(connectionStateListener); } @Override @@ -194,11 +116,6 @@ public void onRegistryRowDeleted(JdbcRegistryDataDTO data) { }); } - @Override - public boolean existJdbcRegistryDataKey(String key) { - return jdbcRegistryDataManager.existKey(key); - } - @Override public Optional getJdbcRegistryDataByKey(String key) { return jdbcRegistryDataManager.getRegistryDataByKey(key); @@ -210,8 +127,8 @@ public List listJdbcRegistryDataChildren(String key) { } @Override - public void putJdbcRegistryData(Long clientId, String key, String value, DataType dataType) { - jdbcRegistryDataManager.putJdbcRegistryData(clientId, key, value, dataType); + public void putJdbcRegistryData(String key, String value) { + jdbcRegistryDataManager.putJdbcRegistryData(key, value); } @Override @@ -219,168 +136,9 @@ public void deleteJdbcRegistryDataByKey(String key) { jdbcRegistryDataManager.deleteJdbcRegistryDataByKey(key); } - @Override - public void acquireJdbcRegistryLock(Long clientId, String lockKey) { - try { - jdbcRegistryLockManager.acquireJdbcRegistryLock(clientId, lockKey); - } catch (Exception ex) { - throw new RegistryException("Acquire the lock: " + lockKey + " error", ex); - } - } - - @Override - public boolean acquireJdbcRegistryLock(Long clientId, String lockKey, long timeout) { - try { - return jdbcRegistryLockManager.acquireJdbcRegistryLock(clientId, lockKey, timeout); - } catch (Exception ex) { - throw new RegistryException("Acquire the lock: " + lockKey + " error", ex); - } - } - - @Override - public void releaseJdbcRegistryLock(Long clientId, String lockKey) { - try { - jdbcRegistryLockManager.releaseJdbcRegistryLock(clientId, lockKey); - } catch (Exception ex) { - throw new RegistryException("Release the lock: " + lockKey + " error", ex); - } - } - @Override public void close() { jdbcRegistryServerState = JdbcRegistryServerState.STOPPED; JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor().shutdown(); - List clientIds = jdbcRegistryClients.stream() - .map(IJdbcRegistryClient::getJdbcRegistryClientIdentify) - .map(JdbcRegistryClientIdentify::getClientId) - .collect(Collectors.toList()); - doPurgeJdbcRegistryClientInDB(clientIds); - jdbcRegistryClients.clear(); - jdbcRegistryClientDTOMap.clear(); } - - private void purgePreviousJdbcRegistryClient() { - if (jdbcRegistryServerState == JdbcRegistryServerState.STOPPED) { - return; - } - List previousJdbcRegistryClientIds = jdbcRegistryClientRepository.queryAll() - .stream() - .filter(jdbcRegistryClientHeartbeat -> jdbcRegistryClientHeartbeat.getClientName() - .equals(jdbcRegistryProperties.getJdbcRegistryClientName())) - .map(JdbcRegistryClientHeartbeatDTO::getId) - .collect(Collectors.toList()); - doPurgeJdbcRegistryClientInDB(previousJdbcRegistryClientIds); - - } - - private void purgeDeadJdbcRegistryClient() { - if (jdbcRegistryServerState == JdbcRegistryServerState.STOPPED) { - return; - } - List deadJdbcRegistryClientIds = jdbcRegistryClientRepository.queryAll() - .stream() - .filter(JdbcRegistryClientHeartbeatDTO::isDead) - .map(JdbcRegistryClientHeartbeatDTO::getId) - .collect(Collectors.toList()); - doPurgeJdbcRegistryClientInDB(deadJdbcRegistryClientIds); - - } - - private void doPurgeJdbcRegistryClientInDB(List jdbcRegistryClientIds) { - if (CollectionUtils.isEmpty(jdbcRegistryClientIds)) { - return; - } - log.info("Begin to delete dead jdbcRegistryClient: {}", jdbcRegistryClientIds); - jdbcRegistryDataRepository.deleteEphemeralDateByClientIds(jdbcRegistryClientIds); - jdbcRegistryLockRepository.deleteByClientIds(jdbcRegistryClientIds); - jdbcRegistryClientRepository.deleteByIds(jdbcRegistryClientIds); - log.info("Success delete dead jdbcRegistryClient: {}", jdbcRegistryClientIds); - } - - private void refreshClientsHeartbeat() { - if (CollectionUtils.isEmpty(jdbcRegistryClients)) { - return; - } - if (jdbcRegistryServerState == JdbcRegistryServerState.STOPPED) { - log.warn("The JdbcRegistryServer is STOPPED, will not refresh clients: {} heartbeat.", - CollectionUtils.collect(jdbcRegistryClients, IJdbcRegistryClient::getJdbcRegistryClientIdentify)); - return; - } - // Refresh the client's term - try { - long now = System.currentTimeMillis(); - for (IJdbcRegistryClient jdbcRegistryClient : jdbcRegistryClients) { - JdbcRegistryClientHeartbeatDTO jdbcRegistryClientHeartbeatDTO = - jdbcRegistryClientDTOMap.get(jdbcRegistryClient.getJdbcRegistryClientIdentify()); - if (jdbcRegistryClientHeartbeatDTO == null) { - // This may occur when the data in db has been deleted, but the client is still alive. - log.error( - "The client {} is not found in the registry, will not refresh it's term. (This may happen when the client is removed from the db)", - jdbcRegistryClient.getJdbcRegistryClientIdentify().getClientId()); - continue; - } - JdbcRegistryClientHeartbeatDTO clone = jdbcRegistryClientHeartbeatDTO.clone(); - clone.setLastHeartbeatTime(now); - jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO); - jdbcRegistryClientHeartbeatDTO.setLastHeartbeatTime(clone.getLastHeartbeatTime()); - } - if (jdbcRegistryServerState == JdbcRegistryServerState.SUSPENDED) { - jdbcRegistryServerState = JdbcRegistryServerState.STARTED; - doTriggerReconnectedListener(); - } - lastSuccessHeartbeat = now; - log.debug("Success refresh clients: {} heartbeat.", - CollectionUtils.collect(jdbcRegistryClients, IJdbcRegistryClient::getJdbcRegistryClientIdentify)); - } catch (Exception ex) { - log.error("Failed to refresh the client's term", ex); - switch (jdbcRegistryServerState) { - case STARTED: - jdbcRegistryServerState = JdbcRegistryServerState.SUSPENDED; - break; - case SUSPENDED: - if (System.currentTimeMillis() - lastSuccessHeartbeat > jdbcRegistryProperties.getSessionTimeout() - .toMillis()) { - jdbcRegistryServerState = JdbcRegistryServerState.DISCONNECTED; - doTriggerOnDisConnectedListener(); - } - break; - default: - break; - } - } - } - - private void doTriggerReconnectedListener() { - log.info("Trigger:onReconnected listener."); - connectionStateListeners.forEach(listener -> { - try { - listener.onReconnected(); - } catch (Exception ex) { - log.error("Trigger:onReconnected failed", ex); - } - }); - } - - private void doTriggerOnConnectedListener() { - log.info("Trigger:onConnected listener."); - connectionStateListeners.forEach(listener -> { - try { - listener.onConnected(); - } catch (Exception ex) { - log.error("Trigger:onConnected failed", ex); - } - }); - } - - private void doTriggerOnDisConnectedListener() { - log.info("Trigger:onDisConnected listener."); - connectionStateListeners.forEach(listener -> { - try { - listener.onDisConnected(); - } catch (Exception ex) { - log.error("Trigger:onDisConnected failed", ex); - } - }); - } - } diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServerState.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServerState.java index e568e7d8a9..a5ee77f9b4 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServerState.java +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/java/org/apache/streampark/registry/core/server/JdbcRegistryServerState.java @@ -17,8 +17,6 @@ package org.apache.streampark.registry.core.server; -import org.apache.streampark.registry.core.JdbcRegistryProperties; - public enum JdbcRegistryServerState { /** * Once the {@link JdbcRegistryServer} created, it will be in the INIT state. @@ -28,15 +26,6 @@ public enum JdbcRegistryServerState { * After the {@link JdbcRegistryServer} started, it will be in the STARTED state. */ STARTED, - /** - * Once the {@link JdbcRegistryServer} cannot connect to DB, it will be in the SUSPENDED state, and if it can reconnect to DB in {@link JdbcRegistryProperties#getSessionTimeout()} ()}, - * it will be changed to the STARTED state again. - */ - SUSPENDED, - /** - * If the {@link JdbcRegistryServer} cannot connected to DB in {@link JdbcRegistryProperties#getSessionTimeout()}, it will be in the DISCONNECTED state. - */ - DISCONNECTED, /** * If the {@link JdbcRegistryServer} closed, it will be in the STOPPED state. */ diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/mysql_registry_init.sql b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/mysql_registry_init.sql index 4ee6c47a52..7f8f1be4f8 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/mysql_registry_init.sql +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/mysql_registry_init.sql @@ -22,8 +22,6 @@ CREATE TABLE `t_jdbc_registry_data` `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `data_key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path', `data_value` text NOT NULL COMMENT 'data, like zookeeper node value', - `data_type` varchar(64) NOT NULL COMMENT 'EPHEMERAL, PERSISTENT', - `client_id` bigint(11) NOT NULL COMMENT 'client id', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'last update time', PRIMARY KEY (`id`), @@ -31,32 +29,6 @@ CREATE TABLE `t_jdbc_registry_data` ) ENGINE = InnoDB DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_lock`; -CREATE TABLE `t_jdbc_registry_lock` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', - `lock_key` varchar(256) NOT NULL COMMENT 'lock path', - `lock_owner` varchar(256) NOT NULL COMMENT 'the lock owner, ip_processId', - `client_id` bigint(11) NOT NULL COMMENT 'client id', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`), - unique Key `uk_t_jdbc_registry_lockKey` (`lock_key`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_client_heartbeat`; -CREATE TABLE `t_jdbc_registry_client_heartbeat` -( - `id` bigint(11) NOT NULL COMMENT 'primary key', - `client_name` varchar(256) NOT NULL COMMENT 'client name, ip_processId', - `last_heartbeat_time` bigint(11) NOT NULL COMMENT 'last heartbeat timestamp', - `connection_config` text NOT NULL COMMENT 'connection config', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - DROP TABLE IF EXISTS `t_jdbc_registry_data_change_event`; CREATE TABLE `t_jdbc_registry_data_change_event` ( diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/postgresql_registry_init.sql b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/postgresql_registry_init.sql index dcfd82074a..64db72cd23 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/postgresql_registry_init.sql +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/main/resources/postgresql_registry_init.sql @@ -21,39 +21,12 @@ create table t_jdbc_registry_data id bigserial not null, data_key varchar not null, data_value text not null, - data_type varchar not null, - client_id bigint not null, create_time timestamp not null default current_timestamp, last_update_time timestamp not null default current_timestamp, primary key (id) ); create unique index uk_t_jdbc_registry_dataKey on t_jdbc_registry_data (data_key); - -DROP TABLE IF EXISTS t_jdbc_registry_lock; -create table t_jdbc_registry_lock -( - id bigserial not null, - lock_key varchar not null, - lock_owner varchar not null, - client_id bigint not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); -create unique index uk_t_jdbc_registry_lockKey on t_jdbc_registry_lock (lock_key); - - -DROP TABLE IF EXISTS t_jdbc_registry_client_heartbeat; -create table t_jdbc_registry_client_heartbeat -( - id bigint not null, - client_name varchar not null, - last_heartbeat_time bigint not null, - connection_config text not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); - DROP TABLE IF EXISTS t_jdbc_registry_data_change_event; create table t_jdbc_registry_data_change_event ( diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/JdbcRegistryTestCase.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/JdbcRegistryTestCase.java deleted file mode 100644 index 75b876d384..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/JdbcRegistryTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.streampark.registry.core; - -import org.apache.streampark.common.CommonConfiguration; -import org.apache.streampark.registry.RegistryTestCase; -import org.apache.streampark.registry.api.ConnectionState; -import org.apache.streampark.registry.core.server.IJdbcRegistryServer; - -import lombok.SneakyThrows; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; - -import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -@SpringBootTest(classes = {CommonConfiguration.class, JdbcRegistryProperties.class}) -@SpringBootApplication(scanBasePackageClasses = {CommonConfiguration.class, JdbcRegistryProperties.class}) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -public abstract class JdbcRegistryTestCase extends RegistryTestCase { - - @Autowired - private JdbcRegistryProperties jdbcRegistryProperties; - - @Autowired - private IJdbcRegistryServer jdbcRegistryServer; - - @SneakyThrows - @Test - public void testAddConnectionStateListener() { - - AtomicReference connectionState = new AtomicReference<>(); - registry.addConnectionStateListener(connectionState::set); - - // todo: since the jdbc registry is started at the auto configuration, the stateListener is added after the - // registry is started. - assertThat(connectionState.get()).isEqualTo(null); - } - - @Override - public JdbcRegistry createRegistry() { - return new JdbcRegistry(jdbcRegistryProperties, jdbcRegistryServer); - } - -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/LockUtilsTest.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/LockUtilsTest.java deleted file mode 100644 index 7d2b98e46f..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/LockUtilsTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.streampark.registry.core; - -import org.apache.streampark.common.utils.NetworkUtils; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -@SpringBootTest -@ContextConfiguration(classes = {NetworkUtils.class}) -@TestPropertySource(locations = "classpath:application.yaml") -class LockUtilsTest { - - @Test - void getLockOwner() { - assertThat(LockUtils.getLockOwner()).isNotNull(); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/MysqlJdbcRegistryTestCase.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/MysqlJdbcRegistryTestCase.java deleted file mode 100644 index 262df31d4b..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/MysqlJdbcRegistryTestCase.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.streampark.registry.core; - -import org.apache.streampark.registry.api.sql.SqlScriptRunner; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import lombok.SneakyThrows; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.springframework.test.context.ActiveProfiles; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.lifecycle.Startables; -import org.testcontainers.utility.DockerImageName; - -import java.time.Duration; -import java.util.stream.Stream; - -@ActiveProfiles("mysql") -class MysqlJdbcRegistryTestCase extends JdbcRegistryTestCase { - - private static GenericContainer mysqlContainer; - - @SneakyThrows - @BeforeAll - public static void setUpTestingServer() { - mysqlContainer = new MySQLContainer(DockerImageName.parse("mysql:8.0")) - .withUsername("root") - .withPassword("root") - .withDatabaseName("streampark") - .withNetwork(Network.newNetwork()) - .withExposedPorts(3306) - .waitingFor(Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(300))); - - Startables.deepStart(Stream.of(mysqlContainer)).join(); - - String jdbcUrl = "jdbc:mysql://localhost:" + mysqlContainer.getMappedPort(3306) - + "/streampark?useSSL=false&serverTimezone=UTC"; - System.clearProperty("spring.datasource.url"); - System.setProperty("spring.datasource.url", jdbcUrl); - - HikariConfig config = new HikariConfig(); - config.setJdbcUrl(jdbcUrl); - config.setUsername("root"); - config.setPassword("root"); - - try (HikariDataSource dataSource = new HikariDataSource(config)) { - SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, "mysql_registry_init.sql"); - sqlScriptRunner.execute(); - } - } - - @SneakyThrows - @AfterAll - public static void tearDownTestingServer() { - mysqlContainer.close(); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/PostgresqlJdbcRegistryTestCase.java b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/PostgresqlJdbcRegistryTestCase.java deleted file mode 100644 index 1e87d284ca..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/java/org/apache/streampark/registry/core/PostgresqlJdbcRegistryTestCase.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.streampark.registry.core; - -import org.apache.streampark.registry.api.sql.SqlScriptRunner; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import lombok.SneakyThrows; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.springframework.test.context.ActiveProfiles; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.lifecycle.Startables; -import org.testcontainers.utility.DockerImageName; - -import java.util.stream.Stream; - -@ActiveProfiles("postgresql") -public class PostgresqlJdbcRegistryTestCase extends JdbcRegistryTestCase { - - private static GenericContainer postgresqlContainer; - - @SneakyThrows - @BeforeAll - public static void setUpTestingServer() { - postgresqlContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:16.0")) - .withUsername("root") - .withPassword("root") - .withDatabaseName("streampark") - .withNetwork(Network.newNetwork()) - .withExposedPorts(5432); - - Startables.deepStart(Stream.of(postgresqlContainer)).join(); - - String jdbcUrl = "jdbc:postgresql://localhost:" + postgresqlContainer.getMappedPort(5432) + "/streampark"; - System.clearProperty("spring.datasource.url"); - System.setProperty("spring.datasource.url", jdbcUrl); - - HikariConfig config = new HikariConfig(); - config.setJdbcUrl(jdbcUrl); - config.setUsername("root"); - config.setPassword("root"); - - try (HikariDataSource dataSource = new HikariDataSource(config)) { - SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, "postgresql_registry_init.sql"); - sqlScriptRunner.execute(); - } - } - - @SneakyThrows - @AfterAll - public static void tearDownTestingServer() { - postgresqlContainer.close(); - } -} diff --git a/streampark-console/streampark-console-registry/streampark-registry-it/pom.xml b/streampark-console/streampark-console-registry/streampark-registry-it/pom.xml deleted file mode 100644 index 6fce49e99a..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-it/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - 4.0.0 - - org.apache.streampark - streampark-console-registry - 2.2.0-SNAPSHOT - - - streampark-registry-it - StreamPark : Console Registry Testcase - - - - org.apache.streampark - streampark-registry-api - ${project.version} - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - false - - - - - test-jar - - - - - - - - diff --git a/streampark-console/streampark-console-registry/streampark-registry-it/src/test/java/org/apache/streampark/plugin/registry/RegistryTestCase.java b/streampark-console/streampark-console-registry/streampark-registry-it/src/test/java/org/apache/streampark/plugin/registry/RegistryTestCase.java deleted file mode 100644 index 63ec429368..0000000000 --- a/streampark-console/streampark-console-registry/streampark-registry-it/src/test/java/org/apache/streampark/plugin/registry/RegistryTestCase.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * 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.streampark.registry; - -import org.apache.streampark.common.utils.NetworkUtils; -import org.apache.streampark.registry.api.ConnectionState; -import org.apache.streampark.registry.api.Event; -import org.apache.streampark.registry.api.Registry; -import org.apache.streampark.registry.api.RegistryException; -import org.apache.streampark.registry.api.SubscribeListener; - -import lombok.SneakyThrows; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.test.util.ReflectionTestUtils; - -import java.time.Duration; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.testcontainers.shaded.org.awaitility.Awaitility.await; - -public abstract class RegistryTestCase { - - protected R registry; - - @BeforeAll - public static void init() { - ReflectionTestUtils.setField(NetworkUtils.class, "priorityStrategy", "default"); - } - - @BeforeEach - public void setupRegistry() { - registry = createRegistry(); - } - - @SneakyThrows - @AfterEach - public void tearDownRegistry() { - this.registry.close(); - } - - @Test - public void testIsConnected() { - registry.start(); - assertThat(registry.isConnected()).isTrue(); - } - - @Test - public void testConnectUntilTimeout() { - registry.start(); - await().atMost(Duration.ofSeconds(10)) - .untilAsserted(() -> registry.connectUntilTimeout(Duration.ofSeconds(3))); - - } - - @SneakyThrows - @Test - public void testSubscribe() { - registry.start(); - - final AtomicBoolean subscribeAdded = new AtomicBoolean(false); - final AtomicBoolean subscribeRemoved = new AtomicBoolean(false); - final AtomicBoolean subscribeUpdated = new AtomicBoolean(false); - - SubscribeListener subscribeListener = event -> { - System.out.println("Receive event: " + event); - if (event.type() == Event.Type.ADD) { - subscribeAdded.compareAndSet(false, true); - } - if (event.type() == Event.Type.REMOVE) { - subscribeRemoved.compareAndSet(false, true); - } - if (event.type() == Event.Type.UPDATE) { - subscribeUpdated.compareAndSet(false, true); - } - }; - String key = "/nodes/console-server" + System.nanoTime(); - registry.subscribe(key, subscribeListener); - registry.put(key, String.valueOf(System.nanoTime()), true); - // Sleep 3 seconds here since in mysql jdbc registry - // If multiple event occurs in a refresh time, only the last event will be triggered - Thread.sleep(3000); - registry.put(key, String.valueOf(System.nanoTime()), true); - Thread.sleep(3000); - registry.delete(key); - - await().atMost(Duration.ofSeconds(10)) - .untilAsserted(() -> { - Assertions.assertTrue(subscribeAdded.get()); - Assertions.assertTrue(subscribeUpdated.get()); - Assertions.assertTrue(subscribeRemoved.get()); - }); - } - - @SneakyThrows - @Test - public void testAddConnectionStateListener() { - - AtomicReference connectionState = new AtomicReference<>(); - registry.addConnectionStateListener(connectionState::set); - - assertThat(connectionState.get()).isNull(); - registry.start(); - - await().atMost(Duration.ofSeconds(2)) - .until(() -> ConnectionState.CONNECTED == connectionState.get()); - - } - - @Test - public void testGet() { - registry.start(); - String key = "/nodes/console-server" + System.nanoTime(); - String value = "127.0.0.1:8080"; - assertThrows(RegistryException.class, () -> registry.get(key)); - registry.put(key, value, true); - assertThat(registry.get(key)).isEqualTo(value); - } - - @Test - public void testPut() { - registry.start(); - String key = "/nodes/console-server" + System.nanoTime(); - String value = "127.0.0.1:8080"; - registry.put(key, value, true); - assertThat(registry.get(key)).isEqualTo(value); - - // Update the value - registry.put(key, "123", true); - assertThat(registry.get(key)).isEqualTo("123"); - } - - @Test - public void testDelete() { - registry.start(); - String key = "/nodes/console-server" + System.nanoTime(); - String value = "127.0.0.1:8080"; - // Delete a non-existent key - registry.delete(key); - - registry.put(key, value, true); - assertThat(registry.get(key)).isEqualTo(value); - registry.delete(key); - assertThat(registry.exists(key)).isFalse(); - - } - - @Test - public void testChildren() { - registry.start(); - String master1 = "/nodes/children/childGroup1/127.0.0.1:8080"; - String master2 = "/nodes/children/childGroup1/127.0.0.2:8080"; - String value = "123"; - registry.put(master1, value, true); - registry.put(master2, value, true); - assertThat(registry.children("/nodes/children")).contains("childGroup1"); - assertThat(registry.children("/nodes/children/childGroup1")).contains("127.0.0.1:8080", - "127.0.0.2:8080"); - } - - @Test - public void testExists() { - registry.start(); - String key = "/nodes/console-server" + System.nanoTime(); - String value = "123"; - assertThat(registry.exists(key)).isFalse(); - registry.put(key, value, true); - assertThat(registry.exists(key)).isTrue(); - - } - - @SneakyThrows - @Test - public void testAcquireLock() { - registry.start(); - String lockKey = "/lock" + System.nanoTime(); - - // 1. Acquire the lock at the main thread - assertThat(registry.acquireLock(lockKey)).isTrue(); - // Acquire the lock at the main thread again - // It should acquire success - assertThat(registry.acquireLock(lockKey)).isTrue(); - - // Acquire the lock at another thread - // It should acquire failed - CompletableFuture acquireResult = CompletableFuture.supplyAsync(() -> registry.acquireLock(lockKey)); - assertThrows(TimeoutException.class, () -> acquireResult.get(3000, TimeUnit.MILLISECONDS)); - - } - - @SneakyThrows - @Test - public void testAcquireLock_withTimeout() { - registry.start(); - String lockKey = "/lock" + System.nanoTime(); - // 1. Acquire the lock in the main thread - assertThat(registry.acquireLock(lockKey, 3000)).isTrue(); - - // Acquire the lock in the main thread - // It should acquire success - assertThat(registry.acquireLock(lockKey, 3000)).isTrue(); - - // Acquire the lock at another thread - // It should acquire failed - CompletableFuture acquireResult = - CompletableFuture.supplyAsync(() -> registry.acquireLock(lockKey, 3000)); - assertThat(acquireResult.get()).isFalse(); - - } - - @SneakyThrows - @Test - public void testReleaseLock() { - registry.start(); - String lockKey = "/lock" + System.nanoTime(); - // 1. Acquire the lock in the main thread - assertThat(registry.acquireLock(lockKey, 3000)).isTrue(); - - // Acquire the lock at another thread - // It should acquire failed - CompletableFuture acquireResult = - CompletableFuture.supplyAsync(() -> registry.acquireLock(lockKey, 3000)); - assertThat(acquireResult.get()).isFalse(); - - // 2. Release the lock in the main thread - assertThat(registry.releaseLock(lockKey)).isTrue(); - - // Acquire the lock at another thread - // It should acquire success - acquireResult = CompletableFuture.supplyAsync(() -> registry.acquireLock(lockKey, 3000)); - assertThat(acquireResult.get()).isTrue(); - } - - public abstract R createRegistry(); - -} diff --git a/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql b/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql index 19feaf77d0..89b611d81a 100644 --- a/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql +++ b/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql @@ -691,8 +691,6 @@ CREATE TABLE `t_jdbc_registry_data` `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `data_key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path', `data_value` text NOT NULL COMMENT 'data, like zookeeper node value', - `data_type` varchar(64) NOT NULL COMMENT 'EPHEMERAL, PERSISTENT', - `client_id` bigint(11) NOT NULL COMMENT 'client id', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'last update time', PRIMARY KEY (`id`), @@ -700,32 +698,6 @@ CREATE TABLE `t_jdbc_registry_data` ) ENGINE = InnoDB DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_lock`; -CREATE TABLE `t_jdbc_registry_lock` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', - `lock_key` varchar(256) NOT NULL COMMENT 'lock path', - `lock_owner` varchar(256) NOT NULL COMMENT 'the lock owner, ip_processId', - `client_id` bigint(11) NOT NULL COMMENT 'client id', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`), - unique Key `uk_t_jdbc_registry_lockKey` (`lock_key`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_client_heartbeat`; -CREATE TABLE `t_jdbc_registry_client_heartbeat` -( - `id` bigint(11) NOT NULL COMMENT 'primary key', - `client_name` varchar(256) NOT NULL COMMENT 'client name, ip_processId', - `last_heartbeat_time` bigint(11) NOT NULL COMMENT 'last heartbeat timestamp', - `connection_config` text NOT NULL COMMENT 'connection config', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - DROP TABLE IF EXISTS `t_jdbc_registry_data_change_event`; CREATE TABLE `t_jdbc_registry_data_change_event` ( diff --git a/streampark-console/streampark-console-service/src/main/assembly/script/schema/pgsql-schema.sql b/streampark-console/streampark-console-service/src/main/assembly/script/schema/pgsql-schema.sql index 91eb751881..76bb12c452 100644 --- a/streampark-console/streampark-console-service/src/main/assembly/script/schema/pgsql-schema.sql +++ b/streampark-console/streampark-console-service/src/main/assembly/script/schema/pgsql-schema.sql @@ -893,39 +893,12 @@ create table t_jdbc_registry_data id bigserial not null, data_key varchar not null, data_value text not null, - data_type varchar not null, - client_id bigint not null, create_time timestamp not null default current_timestamp, last_update_time timestamp not null default current_timestamp, primary key (id) ); create unique index uk_t_jdbc_registry_dataKey on t_jdbc_registry_data (data_key); - -DROP TABLE IF EXISTS t_jdbc_registry_lock; -create table t_jdbc_registry_lock -( - id bigserial not null, - lock_key varchar not null, - lock_owner varchar not null, - client_id bigint not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); -create unique index uk_t_jdbc_registry_lockKey on t_jdbc_registry_lock (lock_key); - - -DROP TABLE IF EXISTS t_jdbc_registry_client_heartbeat; -create table t_jdbc_registry_client_heartbeat -( - id bigint not null, - client_name varchar not null, - last_heartbeat_time bigint not null, - connection_config text not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); - DROP TABLE IF EXISTS t_jdbc_registry_data_change_event; create table t_jdbc_registry_data_change_event ( diff --git a/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/mysql/2.2.0.sql b/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/mysql/2.2.0.sql index 91b1167633..36035e20e2 100644 --- a/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/mysql/2.2.0.sql +++ b/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/mysql/2.2.0.sql @@ -112,8 +112,6 @@ CREATE TABLE `t_jdbc_registry_data` ( `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `data_key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path', `data_value` text NOT NULL COMMENT 'data, like zookeeper node value', - `data_type` varchar(64) NOT NULL COMMENT 'EPHEMERAL, PERSISTENT', - `client_id` bigint(11) NOT NULL COMMENT 'client id', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'last update time', PRIMARY KEY (`id`), @@ -121,30 +119,6 @@ CREATE TABLE `t_jdbc_registry_data` ( ) ENGINE = InnoDB DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_lock`; -CREATE TABLE `t_jdbc_registry_lock` ( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', - `lock_key` varchar(256) NOT NULL COMMENT 'lock path', - `lock_owner` varchar(256) NOT NULL COMMENT 'the lock owner, ip_processId', - `client_id` bigint(11) NOT NULL COMMENT 'client id', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`), - unique Key `uk_t_jdbc_registry_lockKey` (`lock_key`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_client_heartbeat`; -CREATE TABLE `t_jdbc_registry_client_heartbeat` ( - `id` bigint(11) NOT NULL COMMENT 'primary key', - `client_name` varchar(256) NOT NULL COMMENT 'client name, ip_processId', - `last_heartbeat_time` bigint(11) NOT NULL COMMENT 'last heartbeat timestamp', - `connection_config` text NOT NULL COMMENT 'connection config', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time', - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - DROP TABLE IF EXISTS `t_jdbc_registry_data_change_event`; CREATE TABLE `t_jdbc_registry_data_change_event` ( `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', diff --git a/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/pgsql/2.2.0.sql b/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/pgsql/2.2.0.sql index 0230c82732..c5b2366e62 100644 --- a/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/pgsql/2.2.0.sql +++ b/streampark-console/streampark-console-service/src/main/assembly/script/upgrade/pgsql/2.2.0.sql @@ -108,39 +108,12 @@ create table t_jdbc_registry_data id bigserial not null, data_key varchar not null, data_value text not null, - data_type varchar not null, - client_id bigint not null, create_time timestamp not null default current_timestamp, last_update_time timestamp not null default current_timestamp, primary key (id) ); create unique index uk_t_jdbc_registry_dataKey on t_jdbc_registry_data (data_key); - -DROP TABLE IF EXISTS t_jdbc_registry_lock; -create table t_jdbc_registry_lock -( - id bigserial not null, - lock_key varchar not null, - lock_owner varchar not null, - client_id bigint not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); -create unique index uk_t_jdbc_registry_lockKey on t_jdbc_registry_lock (lock_key); - - -DROP TABLE IF EXISTS t_jdbc_registry_client_heartbeat; -create table t_jdbc_registry_client_heartbeat -( - id bigint not null, - client_name varchar not null, - last_heartbeat_time bigint not null, - connection_config text not null, - create_time timestamp not null default current_timestamp, - primary key (id) -); - DROP TABLE IF EXISTS t_jdbc_registry_data_change_event; create table t_jdbc_registry_data_change_event ( diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java index 3dfea13449..665f983ab7 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java @@ -78,7 +78,6 @@ public static void main(String[] args) throws Exception { @PostConstruct public void run() { consoleRegistryClient.start(); - consoleRegistryClient.setRegistryStoppable(this); Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (!ServerLifeCycleManager.isStopped()) { diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/config/ConsoleConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/config/ConsoleConfig.java index 6f17c038c7..d0a55e2ecc 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/config/ConsoleConfig.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/config/ConsoleConfig.java @@ -18,7 +18,6 @@ package org.apache.streampark.console.core.config; import org.apache.streampark.common.utils.NetworkUtils; -import org.apache.streampark.registry.api.ConnectStrategyProperties; import org.apache.streampark.registry.api.enums.RegistryNodeType; import org.apache.commons.lang3.StringUtils; @@ -55,8 +54,6 @@ public class ConsoleConfig implements Validator { @Value("${streampark.max-heartbeat-interval:10}") private Duration maxHeartbeatInterval = Duration.ofSeconds(10); - private ConnectStrategyProperties registryDisconnectStrategy = new ConnectStrategyProperties(); - /** * The IP address and listening port of the console server in the format 'ip:listenPort'. */ @@ -95,7 +92,6 @@ private void printConfig() { String config = "\n****************************Console Configuration**************************************" + "\n listen-port -> " + listenPort + - "\n registry-disconnect-strategy -> " + registryDisconnectStrategy + "\n console-address -> " + consoleAddress + "\n console-registry-path: " + consoleRegistryPath + "\n****************************Master Configuration**************************************"; diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectStrategy.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectStrategy.java deleted file mode 100644 index 97bb3aa6b2..0000000000 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectStrategy.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.streampark.console.core.registry; - -import org.apache.streampark.registry.api.ConnectStrategy; - -public interface ConsoleConnectStrategy extends ConnectStrategy { - -} diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectionStateListener.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectionStateListener.java deleted file mode 100644 index 0e44e1c50d..0000000000 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleConnectionStateListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.streampark.console.core.registry; - -import org.apache.streampark.registry.api.ConnectionListener; -import org.apache.streampark.registry.api.ConnectionState; -import org.apache.streampark.registry.api.lifecycle.ServerLifeCycleManager; - -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class ConsoleConnectionStateListener implements ConnectionListener { - - private final ConsoleConnectStrategy consoleConnectStrategy; - - public ConsoleConnectionStateListener(@NonNull ConsoleConnectStrategy consoleConnectStrategy) { - this.consoleConnectStrategy = consoleConnectStrategy; - } - - @Override - public void onUpdate(ConnectionState state) { - log.info("Master received a {} event from registry, the current server state is {}", state, - ServerLifeCycleManager.getServerLifeCycle()); - switch (state) { - case CONNECTED: - break; - case SUSPENDED: - break; - case RECONNECTED: - consoleConnectStrategy.reconnect(); - break; - case DISCONNECTED: - consoleConnectStrategy.disconnect(); - break; - default: - } - } -} diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java index b9c70be514..7761e8da76 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java @@ -17,7 +17,6 @@ package org.apache.streampark.console.core.registry; -import org.apache.streampark.common.IStoppable; import org.apache.streampark.common.utils.JSONUtils; import org.apache.streampark.common.utils.NetworkUtils; import org.apache.streampark.console.core.config.ConsoleConfig; @@ -26,8 +25,6 @@ import org.apache.streampark.registry.api.RegistryClient; import org.apache.streampark.registry.api.RegistryException; import org.apache.streampark.registry.api.enums.RegistryNodeType; -import org.apache.streampark.registry.api.enums.ServerStatusEnum; -import org.apache.streampark.registry.api.model.ConsoleHeartBeat; import org.apache.streampark.registry.api.thread.ThreadUtils; import org.apache.commons.lang3.StringUtils; @@ -54,9 +51,6 @@ public class ConsoleRegistryClient implements AutoCloseable { @Autowired private ConsoleConfig consoleConfig; - @Autowired - private ConsoleConnectStrategy consoleConnectStrategy; - @Autowired private DistributedTaskService distributedTaskService; @@ -68,20 +62,16 @@ public void start() { this.consoleHeartBeatTask = new ConsoleHeartBeatTask(consoleConfig, registryClient); // console registry registry(); - registryClient.addConnectionStateListener(new ConsoleConnectionStateListener(consoleConnectStrategy)); registryClient.subscribe(RegistryNodeType.ALL_SERVERS.getRegistryPath(), new ConsoleRegistryDataListener()); } catch (Exception e) { throw new RegistryException("Console registry client start up error", e); } } - public void setRegistryStoppable(IStoppable stoppable) { - registryClient.setStoppable(stoppable); - } - @Override public void close() { // TODO unsubscribe ConsoleRegistryDataListener + log.info("ConsoleRegistryClient close"); deregister(); } @@ -153,18 +143,12 @@ void registry() { log.info("Console node : {} registering to registry center", consoleConfig.getConsoleAddress()); String consoleRegistryPath = consoleConfig.getConsoleRegistryPath(); - ConsoleHeartBeat heartBeat = consoleHeartBeatTask.getHeartBeat(); - while (ServerStatusEnum.BUSY.equals(heartBeat.getServerStatusEnum())) { - log.warn("Console node is BUSY: {}", heartBeat); - ThreadUtils.sleep(SLEEP_TIME_MILLIS); - heartBeat = consoleHeartBeatTask.getHeartBeat(); - } - - // remove before persist - registryClient.remove(consoleRegistryPath); - registryClient.persistEphemeral(consoleRegistryPath, + // delete before persist + registryClient.delete(consoleRegistryPath); + registryClient.put(consoleRegistryPath, JSONUtils.toJsonString(consoleHeartBeatTask.getHeartBeat())); + // waiting for the console server node to be registered while (!registryClient.checkNodeExists(NetworkUtils.getHost(), RegistryNodeType.CONSOLE_SERVER)) { log.warn("The current console server node:{} cannot find in registry", NetworkUtils.getHost()); ThreadUtils.sleep(SLEEP_TIME_MILLIS); @@ -173,16 +157,17 @@ void registry() { // sleep 1s, waiting console failover remove ThreadUtils.sleep(SLEEP_TIME_MILLIS); + // start console heart beat task consoleHeartBeatTask.start(); - Set allServers = getServerNodes(RegistryNodeType.CONSOLE_SERVER); + + Set allServers = registryClient.getServerNodeSet(RegistryNodeType.CONSOLE_SERVER); distributedTaskService.init(allServers, consoleConfig.getConsoleAddress()); log.info("Console node : {} registered to registry center successfully", consoleConfig.getConsoleAddress()); - } public void deregister() { try { - registryClient.remove(consoleConfig.getConsoleRegistryPath()); + registryClient.delete(consoleConfig.getConsoleRegistryPath()); log.info("Console node : {} unRegistry to register center.", consoleConfig.getConsoleAddress()); if (consoleHeartBeatTask != null) { consoleHeartBeatTask.shutdown(); @@ -192,12 +177,4 @@ public void deregister() { log.error("ConsoleServer remove registry path exception ", e); } } - - public boolean isAvailable() { - return registryClient.isConnected(); - } - - public Set getServerNodes(RegistryNodeType nodeType) { - return registryClient.getServerNodeSet(nodeType); - } } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryDataListener.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryDataListener.java index cb40aa072f..0e1e40ec02 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryDataListener.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryDataListener.java @@ -58,6 +58,10 @@ private void handleConsoleEvent(Event event) { log.info("console node deleted : {}", path); consoleRegistryClient.removeConsoleNodePath(path, RegistryNodeType.CONSOLE_SERVER, true); break; + case UPDATE: + // TODO: update console node + log.info("console node updated : {}", path); + break; default: break; } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleStopStrategy.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleStopStrategy.java deleted file mode 100644 index 60034dd436..0000000000 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleStopStrategy.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.streampark.console.core.registry; - -import org.apache.streampark.registry.api.RegistryClient; -import org.apache.streampark.registry.api.StrategyType; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * This strategy will stop the console server, when disconnected from {@link org.apache.streampark.registry.api.Registry}. - */ -@Service -@Slf4j -public class ConsoleStopStrategy implements ConsoleConnectStrategy { - - @Autowired - private RegistryClient registryClient; - - @Override - public void disconnect() { - registryClient.getStoppable() - .stop("Console disconnected from registry, will stop myself due to the stop strategy"); - } - - @Override - public void reconnect() { - log.warn("The current connect strategy is stop, so the console will not reconnect to registry"); - } - - @Override - public StrategyType getStrategyType() { - return StrategyType.STOP; - } -} diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/ConsoleHeartBeatTask.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/ConsoleHeartBeatTask.java index 1fc25a18a9..692629c05b 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/ConsoleHeartBeatTask.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/task/ConsoleHeartBeatTask.java @@ -19,10 +19,8 @@ import org.apache.streampark.common.utils.JSONUtils; import org.apache.streampark.common.utils.NetworkUtils; -import org.apache.streampark.common.utils.OSUtils; import org.apache.streampark.console.core.config.ConsoleConfig; import org.apache.streampark.registry.api.RegistryClient; -import org.apache.streampark.registry.api.enums.ServerStatusEnum; import org.apache.streampark.registry.api.lifecycle.ServerLifeCycleManager; import org.apache.streampark.registry.api.model.BaseHeartBeatTask; import org.apache.streampark.registry.api.model.ConsoleHeartBeat; @@ -39,15 +37,12 @@ public class ConsoleHeartBeatTask extends BaseHeartBeatTask { private final String heartBeatPath; - private final int processId; - public ConsoleHeartBeatTask(@NonNull ConsoleConfig consoleConfig, @NonNull RegistryClient registryClient) { super("ConsoleHeartBeatTask", consoleConfig.getMaxHeartbeatInterval().toMillis()); this.consoleConfig = consoleConfig; this.registryClient = registryClient; this.heartBeatPath = consoleConfig.getConsoleRegistryPath(); - this.processId = OSUtils.getProcessID(); } @Override @@ -55,8 +50,6 @@ public ConsoleHeartBeat getHeartBeat() { return ConsoleHeartBeat.builder() .startupTime(ServerLifeCycleManager.getServerStartupTime()) .reportTime(System.currentTimeMillis()) - .processId(processId) - .serverStatusEnum(ServerStatusEnum.NORMAL) .host(NetworkUtils.getHost()) .port(consoleConfig.getListenPort()) .build(); @@ -65,7 +58,7 @@ public ConsoleHeartBeat getHeartBeat() { @Override public void writeHeartBeat(ConsoleHeartBeat consoleHeartBeat) { String masterHeartBeatJson = JSONUtils.toJsonString(consoleHeartBeat); - registryClient.persistEphemeral(heartBeatPath, masterHeartBeatJson); + registryClient.put(heartBeatPath, masterHeartBeatJson); log.debug("Success write master heartBeatInfo into registry, masterRegistryPath: {}, heartBeatInfo: {}", heartBeatPath, masterHeartBeatJson); } diff --git a/streampark-console/streampark-console-service/src/main/resources/db/schema-h2.sql b/streampark-console/streampark-console-service/src/main/resources/db/schema-h2.sql index 623b9a1396..e93b3f1cbb 100644 --- a/streampark-console/streampark-console-service/src/main/resources/db/schema-h2.sql +++ b/streampark-console/streampark-console-service/src/main/resources/db/schema-h2.sql @@ -680,8 +680,6 @@ CREATE TABLE `t_jdbc_registry_data` `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `data_key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path', `data_value` text NOT NULL COMMENT 'data, like zookeeper node value', - `data_type` varchar(64) NOT NULL COMMENT 'EPHEMERAL, PERSISTENT', - `client_id` bigint NOT NULL COMMENT 'client id', `create_time` timestamp NOT NULL default current_timestamp COMMENT 'create time', `last_update_time` timestamp NOT NULL default current_timestamp COMMENT 'last update time', PRIMARY KEY (`id`), @@ -689,32 +687,6 @@ CREATE TABLE `t_jdbc_registry_data` ) ENGINE = InnoDB DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_lock`; -CREATE TABLE `t_jdbc_registry_lock` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', - `lock_key` varchar(256) NOT NULL COMMENT 'lock path', - `lock_owner` varchar(256) NOT NULL COMMENT 'the lock owner, ip_processId', - `client_id` bigint NOT NULL COMMENT 'client id', - `create_time` timestamp NOT NULL default current_timestamp COMMENT 'create time', - PRIMARY KEY (`id`), - unique KEY `uk_t_jdbc_registry_lockKey`(`lock_key`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -DROP TABLE IF EXISTS `t_jdbc_registry_client_heartbeat`; -CREATE TABLE `t_jdbc_registry_client_heartbeat` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', - `client_name` varchar(256) NOT NULL COMMENT 'client name, ip_processId', - `last_heartbeat_time` bigint NOT NULL COMMENT 'last heartbeat timestamp', - `connection_config` text NOT NULL COMMENT 'connection config', - `create_time` timestamp NOT NULL default current_timestamp COMMENT 'create time', - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - DROP TABLE IF EXISTS `t_jdbc_registry_data_change_event`; CREATE TABLE `t_jdbc_registry_data_change_event` ( diff --git a/streampark.ipr b/streampark.ipr new file mode 100644 index 0000000000..1fec45b4a7 --- /dev/null +++ b/streampark.ipr @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b395bd3e3226a12ef42c04e1800825927517bce5 Mon Sep 17 00:00:00 2001 From: BUAAserein <18376359@buaa.edu.cn> Date: Tue, 22 Oct 2024 01:14:09 +0800 Subject: [PATCH 2/2] change conf --- .../org/apache/streampark/registry/api/RegistryClient.java | 4 ---- .../src/test/resources/application-mysql.yaml | 4 ++-- .../src/test/resources/application-postgresql.yaml | 4 ++-- .../src/main/assembly/script/schema/mysql-schema.sql | 2 +- .../console/core/registry/ConsoleRegistryClient.java | 2 +- .../src/test/resources/application-test.yml | 4 ++-- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java index 63f26d2dde..db416c49d8 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java +++ b/streampark-console/streampark-console-registry/streampark-registry-api/src/main/java/org/apache/streampark/registry/api/RegistryClient.java @@ -41,10 +41,6 @@ public class RegistryClient { public RegistryClient(Registry registry) { this.registry = registry; - // TODO: remove this - if (!registry.exists(RegistryNodeType.CONSOLE_SERVER.getRegistryPath())) { - registry.put(RegistryNodeType.CONSOLE_SERVER.getRegistryPath(), EMPTY); - } } /** diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-mysql.yaml b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-mysql.yaml index 779b43a2cc..72daffc2a7 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-mysql.yaml +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-mysql.yaml @@ -26,8 +26,8 @@ spring: registry: type: jdbc - heartbeat-refresh-interval: 1s - session-timeout: 3s + heartbeat-refresh-interval: 3s + session-timeout: 60s network: # network interface preferred like eth0, default: empty diff --git a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-postgresql.yaml b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-postgresql.yaml index e5fbb5a56a..981166daa3 100644 --- a/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-postgresql.yaml +++ b/streampark-console/streampark-console-registry/streampark-registry-core/src/test/resources/application-postgresql.yaml @@ -23,8 +23,8 @@ spring: registry: type: jdbc - heartbeat-refresh-interval: 1s - session-timeout: 3s + heartbeat-refresh-interval: 3s + session-timeout: 60s network: # network interface preferred like eth0, default: empty diff --git a/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql b/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql index 89b611d81a..0740b2b0f3 100644 --- a/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql +++ b/streampark-console/streampark-console-service/src/main/assembly/script/schema/mysql-schema.sql @@ -605,7 +605,7 @@ create table `t_spark_app` ( `jar_check_sum` bigint default null, `app_properties` text collate utf8mb4_general_ci comment 'Arbitrary Spark configuration property in key=value format (e.g. spark.driver.cores=1)', `app_args` text collate utf8mb4_general_ci comment 'Arguments passed to the main method of your main class', - `app_id` varchar(64) collate utf8mb4_general_ci default null comment '(1)application_id on yarn(2)driver_pod_name on k8s', + `cluster_id` varchar(64) collate utf8mb4_general_ci default null comment '(1)application_id on yarn(2)driver_pod_name on k8s', `yarn_queue` varchar(128) collate utf8mb4_general_ci default null, `k8s_master_url` varchar(128) collate utf8mb4_general_ci default null, `k8s_container_image` varchar(128) collate utf8mb4_general_ci default null, diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java index 7761e8da76..d98cde602b 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/registry/ConsoleRegistryClient.java @@ -101,7 +101,7 @@ public void addConsoleNodePath(String path, RegistryNodeType nodeType) { } distributedTaskService.addServer(serverHost); } catch (Exception e) { - log.error("{} server failover failed, host:{}", nodeType, serverHost, e); + log.error("{} server add failed, host:{}", nodeType, serverHost, e); } } diff --git a/streampark-console/streampark-console-service/src/test/resources/application-test.yml b/streampark-console/streampark-console-service/src/test/resources/application-test.yml index 9b3d1e1ce3..f8abef9c22 100644 --- a/streampark-console/streampark-console-service/src/test/resources/application-test.yml +++ b/streampark-console/streampark-console-service/src/test/resources/application-test.yml @@ -59,8 +59,8 @@ streampark: registry: # default using jdbc as registry type: jdbc - heartbeat-refresh-interval: 1s - session-timeout: 3s + heartbeat-refresh-interval: 3s + session-timeout: 60s network: # network interface preferred like eth0, default: empty