github-advanced-security[bot] commented on code in PR #16352: URL: https://github.com/apache/dolphinscheduler/pull/16352#discussion_r1685445080
########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftSubscribeDataManager.java: ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft; + +import static com.alipay.sofa.jraft.util.BytesUtil.readUtf8; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.registry.api.Event; +import org.apache.dolphinscheduler.registry.api.SubscribeListener; +import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; + +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.rhea.client.RheaKVStore; +import com.alipay.sofa.jraft.rhea.storage.KVEntry; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +@Slf4j +public class RaftSubscribeDataManager implements IRaftSubscribeDataManager { + + private final Map<String, List<SubscribeListener>> dataSubScribeMap = new ConcurrentHashMap<>(); + + private final RaftRegistryProperties properties; + + private final RheaKVStore kvStore; + + public RaftSubscribeDataManager(RaftRegistryProperties properties, RheaKVStore kvStore) { + this.properties = properties; + this.kvStore = kvStore; + } + + private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool( + 1, + new ThreadFactoryBuilder().setNameFormat("SubscribeListenerCheckThread").setDaemon(true).build()); + + public void start() { Review Comment: ## Missing Override annotation This method overrides [IRaftSubscribeDataManager.start](1); it is advisable to add an Override annotation. [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/4250) ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/client/IRaftRegisterClient.java: ########## @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft.client; + +import org.apache.dolphinscheduler.registry.api.ConnectionListener; +import org.apache.dolphinscheduler.registry.api.SubscribeListener; + +import java.util.Collection; + +public interface IRaftRegisterClient extends AutoCloseable { + + /** + * Start the raft registry client. Once started, the client will connect to the raft registry server and then it can be used. + */ + void start(); + + /** + * Check the connectivity of the client. + * + * @return true if the client is connected, false otherwise + */ + boolean isConnectivity(); + + /** + * Subscribe to the raft registry connection state change event. + * + * @param connectionStateListener the listener to handle connection state changes + */ + void subscribeConnectionStateChange(ConnectionListener connectionStateListener); + + /** + * Subscribe to the register data change event. + * + * @param path the path to subscribe to + * @param listener the listener to handle data changes + */ + void subscribeRaftRegistryDataChange(String path, SubscribeListener listener); + + /** + * Get the raft register data by key. + * + * @param key the key of the register data + * @return the value associated with the key + */ + String getRegistryDataByKey(String key); + + /** + * Put the register data to the raft registry server. + * <p> + * If the key already exists, then update the value. If the key does not exist, then insert a new key-value pair. + * + * @param key the key of the register data + * @param value the value to be associated with the key + * @param deleteOnDisconnect if true, the data will be deleted when the client disconnects + */ + void putRegistryData(String key, String value, boolean deleteOnDisconnect); Review Comment: ## Useless parameter The parameter 'deleteOnDisconnect' is never used. [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/4247) ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftConnectionStateManager.java: ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft; + +import org.apache.dolphinscheduler.registry.api.ConnectionListener; +import org.apache.dolphinscheduler.registry.api.ConnectionState; + +import java.time.Duration; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.RouteTable; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.rpc.CliClientService; +import com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +@Slf4j +public class RaftConnectionStateManager implements IRaftConnectionStateManager { + + private static final String DEFAULT_REGION_ID = "--1"; + private ConnectionState currentConnectionState; + private static final Duration CONNECT_STATE_CHECK_INTERVENE = Duration.ofSeconds(2); + private final RaftRegistryProperties properties; + private final List<ConnectionListener> connectionListeners = new CopyOnWriteArrayList<>(); + private final ScheduledExecutorService scheduledExecutorService; + private final CliOptions cliOptions; + private final CliClientService cliClientService; + + public RaftConnectionStateManager(RaftRegistryProperties properties) { + this.properties = properties; + this.cliOptions = new CliOptions(); + this.cliOptions.setMaxRetry(3); + this.cliOptions.setTimeoutMs(5000); + this.cliClientService = new CliClientServiceImpl(); + this.scheduledExecutorService = Executors.newScheduledThreadPool( + 1, + new ThreadFactoryBuilder().setNameFormat("ConnectionStateRefreshThread").setDaemon(true).build()); + } + + public void start() { + cliClientService.init(cliOptions); + scheduledExecutorService.scheduleWithFixedDelay( + new ConnectionStateRefreshTask(connectionListeners), + CONNECT_STATE_CHECK_INTERVENE.toMillis(), + CONNECT_STATE_CHECK_INTERVENE.toMillis(), + TimeUnit.MILLISECONDS); + } + + public void addConnectionListener(ConnectionListener listener) { Review Comment: ## Missing Override annotation This method overrides [IRaftConnectionStateManager.addConnectionListener](1); it is advisable to add an Override annotation. [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/4248) ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftConnectionStateManager.java: ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.registry.raft; + +import org.apache.dolphinscheduler.registry.api.ConnectionListener; +import org.apache.dolphinscheduler.registry.api.ConnectionState; + +import java.time.Duration; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.RouteTable; +import com.alipay.sofa.jraft.option.CliOptions; +import com.alipay.sofa.jraft.rpc.CliClientService; +import com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +@Slf4j +public class RaftConnectionStateManager implements IRaftConnectionStateManager { + + private static final String DEFAULT_REGION_ID = "--1"; + private ConnectionState currentConnectionState; + private static final Duration CONNECT_STATE_CHECK_INTERVENE = Duration.ofSeconds(2); + private final RaftRegistryProperties properties; + private final List<ConnectionListener> connectionListeners = new CopyOnWriteArrayList<>(); + private final ScheduledExecutorService scheduledExecutorService; + private final CliOptions cliOptions; + private final CliClientService cliClientService; + + public RaftConnectionStateManager(RaftRegistryProperties properties) { + this.properties = properties; + this.cliOptions = new CliOptions(); + this.cliOptions.setMaxRetry(3); + this.cliOptions.setTimeoutMs(5000); + this.cliClientService = new CliClientServiceImpl(); + this.scheduledExecutorService = Executors.newScheduledThreadPool( + 1, + new ThreadFactoryBuilder().setNameFormat("ConnectionStateRefreshThread").setDaemon(true).build()); + } + + public void start() { Review Comment: ## Missing Override annotation This method overrides [IRaftConnectionStateManager.start](1); it is advisable to add an Override annotation. [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/4249) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
