kezhenxu94
3 years ago
committed by
GitHub
68 changed files with 882 additions and 1901 deletions
@ -1,82 +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.dolphinscheduler.api.utils; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.enums.NodeType; |
|
||||||
import org.apache.dolphinscheduler.common.model.Server; |
|
||||||
import org.apache.dolphinscheduler.dao.entity.ZookeeperRecord; |
|
||||||
import org.apache.dolphinscheduler.service.registry.RegistryClient; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* monitor zookeeper info todo registry-spi |
|
||||||
* fixme Some of the information obtained in the api belongs to the unique information of zk. |
|
||||||
* I am not sure whether there is a good abstraction method. This is related to whether the specific plug-in is provided. |
|
||||||
*/ |
|
||||||
public class RegistryCenterUtils { |
|
||||||
|
|
||||||
private static RegistryClient registryClient = RegistryClient.getInstance(); |
|
||||||
|
|
||||||
/** |
|
||||||
* @return zookeeper info list |
|
||||||
*/ |
|
||||||
public static List<ZookeeperRecord> zookeeperInfoList() { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* get master servers |
|
||||||
* |
|
||||||
* @return master server information |
|
||||||
*/ |
|
||||||
public static List<Server> getMasterServers() { |
|
||||||
return registryClient.getServerList(NodeType.MASTER); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* master construct is the same with worker, use the master instead |
|
||||||
* |
|
||||||
* @return worker server informations |
|
||||||
*/ |
|
||||||
public static List<Server> getWorkerServers() { |
|
||||||
return registryClient.getServerList(NodeType.WORKER); |
|
||||||
} |
|
||||||
|
|
||||||
public static Map<String, String> getServerMaps(NodeType nodeType, boolean hostOnly) { |
|
||||||
return registryClient.getServerMaps(nodeType, hostOnly); |
|
||||||
} |
|
||||||
|
|
||||||
public static List<String> getServerNodeList(NodeType nodeType, boolean hostOnly) { |
|
||||||
return registryClient.getServerNodeList(nodeType, hostOnly); |
|
||||||
} |
|
||||||
|
|
||||||
public static boolean isNodeExisted(String key) { |
|
||||||
return registryClient.isExisted(key); |
|
||||||
} |
|
||||||
|
|
||||||
public static List<String> getChildrenNodes(final String key) { |
|
||||||
return registryClient.getChildrenKeys(key); |
|
||||||
} |
|
||||||
|
|
||||||
public static String getNodeData(String key) { |
|
||||||
return registryClient.get(key); |
|
||||||
} |
|
||||||
} |
|
@ -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.dolphinscheduler.api.utils; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.model.Server; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import org.junit.Assert; |
|
||||||
import org.junit.Ignore; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
/** |
|
||||||
* zookeeper monitor utils test |
|
||||||
*/ |
|
||||||
@Ignore |
|
||||||
public class RegistryCenterUtilsTest { |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetMasterList(){ |
|
||||||
List<Server> masterServerList = RegistryCenterUtils.getMasterServers(); |
|
||||||
List<Server> workerServerList = RegistryCenterUtils.getWorkerServers(); |
|
||||||
|
|
||||||
Assert.assertTrue(masterServerList.size() >= 0); |
|
||||||
Assert.assertTrue(workerServerList.size() >= 0); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,56 +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.dolphinscheduler.plugin.registry.zookeeper; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryConnectListener; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryConnectState; |
|
||||||
|
|
||||||
import org.apache.curator.framework.CuratorFramework; |
|
||||||
import org.apache.curator.framework.state.ConnectionState; |
|
||||||
import org.apache.curator.framework.state.ConnectionStateListener; |
|
||||||
|
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
|
|
||||||
public class ZookeeperConnectionStateListener implements ConnectionStateListener { |
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ZookeeperConnectionStateListener.class); |
|
||||||
|
|
||||||
private RegistryConnectListener registryConnectListener; |
|
||||||
|
|
||||||
public ZookeeperConnectionStateListener(RegistryConnectListener registryConnectListener) { |
|
||||||
this.registryConnectListener = registryConnectListener; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void stateChanged(CuratorFramework client, ConnectionState newState) { |
|
||||||
|
|
||||||
if (newState == ConnectionState.LOST) { |
|
||||||
logger.error("connection lost from zookeeper"); |
|
||||||
registryConnectListener.notify(RegistryConnectState.LOST); |
|
||||||
} else if (newState == ConnectionState.RECONNECTED) { |
|
||||||
logger.info("reconnected to zookeeper"); |
|
||||||
registryConnectListener.notify(RegistryConnectState.RECONNECTED); |
|
||||||
} else if (newState == ConnectionState.SUSPENDED) { |
|
||||||
logger.warn("zookeeper connection SUSPENDED"); |
|
||||||
registryConnectListener.notify(RegistryConnectState.SUSPENDED); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -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.dolphinscheduler.plugin.registry.zookeeper; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryFactory; |
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList; |
|
||||||
|
|
||||||
/** |
|
||||||
* zookeeper registry plugin |
|
||||||
*/ |
|
||||||
public class ZookeeperRegistryPlugin implements DolphinSchedulerPlugin { |
|
||||||
|
|
||||||
@Override |
|
||||||
public Iterable<RegistryFactory> getRegisterFactorys() { |
|
||||||
return ImmutableList.of(new ZookeeperRegistryFactory()); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,32 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!-- |
||||||
|
~ Licensed to 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. Apache Software Foundation (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. |
||||||
|
--> |
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<artifactId>dolphinscheduler-registry</artifactId> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<version>2.0.0-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<artifactId>dolphinscheduler-registry-api</artifactId> |
||||||
|
</project> |
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
@FunctionalInterface |
||||||
|
public interface ConnectionListener { |
||||||
|
void onUpdate(ConnectionState newState); |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
public enum ConnectionState { |
||||||
|
CONNECTED, |
||||||
|
RECONNECTED, |
||||||
|
SUSPENDED, |
||||||
|
DISCONNECTED |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import lombok.Setter; |
||||||
|
import lombok.ToString; |
||||||
|
import lombok.experimental.Accessors; |
||||||
|
|
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@Builder |
||||||
|
@ToString |
||||||
|
@NoArgsConstructor |
||||||
|
@AllArgsConstructor |
||||||
|
@Accessors(fluent = true) |
||||||
|
public class Event { |
||||||
|
private String key; |
||||||
|
private String path; |
||||||
|
private String data; |
||||||
|
private Type type; |
||||||
|
|
||||||
|
public enum Type { |
||||||
|
ADD, |
||||||
|
REMOVE, |
||||||
|
UPDATE |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
import java.io.Closeable; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public interface Registry extends Closeable { |
||||||
|
void start(Map<String, String> config); |
||||||
|
|
||||||
|
boolean subscribe(String path, SubscribeListener listener); |
||||||
|
|
||||||
|
void unsubscribe(String path); |
||||||
|
|
||||||
|
void addConnectionStateListener(ConnectionListener listener); |
||||||
|
|
||||||
|
String get(String key); |
||||||
|
|
||||||
|
void put(String key, String value, boolean deleteOnDisconnect); |
||||||
|
|
||||||
|
void delete(String key); |
||||||
|
|
||||||
|
Collection<String> children(String key); |
||||||
|
|
||||||
|
boolean exists(String key); |
||||||
|
|
||||||
|
boolean acquireLock(String key); |
||||||
|
|
||||||
|
boolean releaseLock(String key); |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
public final class RegistryException extends RuntimeException { |
||||||
|
|
||||||
|
public RegistryException(String message, Throwable cause) { |
||||||
|
super(message, cause); |
||||||
|
} |
||||||
|
|
||||||
|
public RegistryException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
public interface RegistryFactory { |
||||||
|
String name(); |
||||||
|
|
||||||
|
Registry create(); |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toMap; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.ServiceLoader; |
||||||
|
import java.util.function.Function; |
||||||
|
import java.util.stream.StreamSupport; |
||||||
|
|
||||||
|
public final class RegistryFactoryLoader { |
||||||
|
public static Map<String, RegistryFactory> load() { |
||||||
|
final ServiceLoader<RegistryFactory> factories = ServiceLoader.load(RegistryFactory.class); |
||||||
|
return StreamSupport.stream(factories.spliterator(), false) |
||||||
|
.collect(toMap(RegistryFactory::name, Function.identity())); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
/* |
||||||
|
* Licensed to 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. Apache Software Foundation (ASF) licenses this file to you under |
||||||
|
* the Apache License, Version 2.0 (the "License"); you may |
||||||
|
* not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, |
||||||
|
* software distributed under the License is distributed on an |
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||||||
|
* KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations |
||||||
|
* under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.apache.dolphinscheduler.registry.api; |
||||||
|
|
||||||
|
public interface SubscribeListener { |
||||||
|
void notify(Event event); |
||||||
|
} |
0
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConfiguration.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConfiguration.java
0
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConfiguration.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperConfiguration.java
@ -0,0 +1,54 @@ |
|||||||
|
/* |
||||||
|
* 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.zookeeper; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.registry.api.ConnectionListener; |
||||||
|
import org.apache.dolphinscheduler.registry.api.ConnectionState; |
||||||
|
|
||||||
|
import org.apache.curator.framework.CuratorFramework; |
||||||
|
import org.apache.curator.framework.state.ConnectionStateListener; |
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@RequiredArgsConstructor |
||||||
|
public final class ZookeeperConnectionStateListener implements ConnectionStateListener { |
||||||
|
private final ConnectionListener listener; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void stateChanged(CuratorFramework client, |
||||||
|
org.apache.curator.framework.state.ConnectionState newState) { |
||||||
|
switch (newState) { |
||||||
|
case LOST: |
||||||
|
log.warn("Registry disconnected"); |
||||||
|
listener.onUpdate(ConnectionState.DISCONNECTED); |
||||||
|
break; |
||||||
|
case RECONNECTED: |
||||||
|
log.info("Registry reconnected"); |
||||||
|
listener.onUpdate(ConnectionState.RECONNECTED); |
||||||
|
break; |
||||||
|
case SUSPENDED: |
||||||
|
log.warn("Registry suspended"); |
||||||
|
listener.onUpdate(ConnectionState.SUSPENDED); |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
229
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java
229
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java
14
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryFactory.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryFactory.java
14
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryFactory.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryFactory.java
23
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/test/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryTest.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/test/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryTest.java
23
dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/src/test/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryTest.java → dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/test/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryTest.java
@ -0,0 +1,36 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!-- |
||||||
|
~ Licensed to 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. Apache Software Foundation (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. |
||||||
|
--> |
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<parent> |
||||||
|
<artifactId>dolphinscheduler-registry</artifactId> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<version>2.0.0-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
<artifactId>dolphinscheduler-registry-plugins</artifactId> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<packaging>pom</packaging> |
||||||
|
|
||||||
|
<modules> |
||||||
|
<module>dolphinscheduler-registry-zookeeper</module> |
||||||
|
</modules> |
||||||
|
</project> |
@ -1,243 +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.dolphinscheduler.service.registry; |
|
||||||
|
|
||||||
import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS; |
|
||||||
import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_MASTERS; |
|
||||||
import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.IStoppable; |
|
||||||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
|
||||||
import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; |
|
||||||
import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; |
|
||||||
import org.apache.dolphinscheduler.spi.register.Registry; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryConnectListener; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryException; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryPluginManager; |
|
||||||
import org.apache.dolphinscheduler.spi.register.SubscribeListener; |
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.atomic.AtomicBoolean; |
|
||||||
|
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList; |
|
||||||
|
|
||||||
/** |
|
||||||
* All business parties use this class to access the registry |
|
||||||
*/ |
|
||||||
public class RegistryCenter { |
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RegistryCenter.class); |
|
||||||
|
|
||||||
private final AtomicBoolean isStarted = new AtomicBoolean(false); |
|
||||||
|
|
||||||
private Registry registry; |
|
||||||
|
|
||||||
private IStoppable stoppable; |
|
||||||
|
|
||||||
/** |
|
||||||
* nodes namespace |
|
||||||
*/ |
|
||||||
protected static String NODES; |
|
||||||
|
|
||||||
private RegistryPluginManager registryPluginManager; |
|
||||||
|
|
||||||
protected static final String EMPTY = ""; |
|
||||||
|
|
||||||
private static final String REGISTRY_PREFIX = "registry"; |
|
||||||
|
|
||||||
private static final String REGISTRY_PLUGIN_BINDING = "registry.plugin.binding"; |
|
||||||
|
|
||||||
private static final String REGISTRY_PLUGIN_DIR = "registry.plugin.dir"; |
|
||||||
|
|
||||||
private static final String MAVEN_LOCAL_REPOSITORY = "maven.local.repository"; |
|
||||||
|
|
||||||
private static final String REGISTRY_PLUGIN_NAME = "plugin.name"; |
|
||||||
|
|
||||||
/** |
|
||||||
* default registry plugin dir |
|
||||||
*/ |
|
||||||
private static final String REGISTRY_PLUGIN_PATH = "lib/plugin/registry"; |
|
||||||
|
|
||||||
private static final String REGISTRY_CONFIG_FILE_PATH = "/registry.properties"; |
|
||||||
|
|
||||||
/** |
|
||||||
* init node persist |
|
||||||
*/ |
|
||||||
public void init() { |
|
||||||
if (isStarted.compareAndSet(false, true)) { |
|
||||||
PropertyUtils.loadPropertyFile(REGISTRY_CONFIG_FILE_PATH); |
|
||||||
Map<String, String> registryConfig = PropertyUtils.getPropertiesByPrefix(REGISTRY_PREFIX); |
|
||||||
|
|
||||||
if (null == registryConfig || registryConfig.isEmpty()) { |
|
||||||
throw new RegistryException("registry config param is null"); |
|
||||||
} |
|
||||||
if (null == registryPluginManager) { |
|
||||||
installRegistryPlugin(registryConfig.get(REGISTRY_PLUGIN_NAME)); |
|
||||||
registry = registryPluginManager.getRegistry(); |
|
||||||
} |
|
||||||
|
|
||||||
registry.init(registryConfig); |
|
||||||
initNodes(); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* init nodes |
|
||||||
*/ |
|
||||||
private void initNodes() { |
|
||||||
persist(REGISTRY_DOLPHINSCHEDULER_MASTERS, EMPTY); |
|
||||||
persist(REGISTRY_DOLPHINSCHEDULER_WORKERS, EMPTY); |
|
||||||
persist(REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS, EMPTY); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* install registry plugin |
|
||||||
*/ |
|
||||||
private void installRegistryPlugin(String registryPluginName) { |
|
||||||
DolphinPluginManagerConfig registryPluginManagerConfig = new DolphinPluginManagerConfig(); |
|
||||||
registryPluginManagerConfig.setPlugins(PropertyUtils.getString(REGISTRY_PLUGIN_BINDING)); |
|
||||||
if (StringUtils.isNotBlank(PropertyUtils.getString(REGISTRY_PLUGIN_DIR))) { |
|
||||||
registryPluginManagerConfig.setInstalledPluginsDir(PropertyUtils.getString(REGISTRY_PLUGIN_DIR, REGISTRY_PLUGIN_PATH).trim()); |
|
||||||
} |
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(PropertyUtils.getString(MAVEN_LOCAL_REPOSITORY))) { |
|
||||||
registryPluginManagerConfig.setMavenLocalRepository(PropertyUtils.getString(MAVEN_LOCAL_REPOSITORY).trim()); |
|
||||||
} |
|
||||||
|
|
||||||
registryPluginManager = new RegistryPluginManager(registryPluginName); |
|
||||||
|
|
||||||
DolphinPluginLoader registryPluginLoader = new DolphinPluginLoader(registryPluginManagerConfig, ImmutableList.of(registryPluginManager)); |
|
||||||
try { |
|
||||||
registryPluginLoader.loadPlugins(); |
|
||||||
} catch (Exception e) { |
|
||||||
throw new RuntimeException("Load registry Plugin Failed !", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* close |
|
||||||
*/ |
|
||||||
public void close() { |
|
||||||
if (isStarted.compareAndSet(true, false) && registry != null) { |
|
||||||
registry.close(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void persist(String key, String value) { |
|
||||||
registry.persist(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
public void persistEphemeral(String key, String value) { |
|
||||||
registry.persistEphemeral(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
public void remove(String key) { |
|
||||||
registry.remove(key); |
|
||||||
} |
|
||||||
|
|
||||||
public void update(String key, String value) { |
|
||||||
registry.update(key, value); |
|
||||||
} |
|
||||||
|
|
||||||
public String get(String key) { |
|
||||||
return registry.get(key); |
|
||||||
} |
|
||||||
|
|
||||||
public void subscribe(String path, SubscribeListener subscribeListener) { |
|
||||||
registry.subscribe(path, subscribeListener); |
|
||||||
} |
|
||||||
|
|
||||||
public void addConnectionStateListener(RegistryConnectListener registryConnectListener) { |
|
||||||
registry.addConnectionStateListener(registryConnectListener); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isExisted(String key) { |
|
||||||
return registry.isExisted(key); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean getLock(String key) { |
|
||||||
return registry.acquireLock(key); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean releaseLock(String key) { |
|
||||||
return registry.releaseLock(key); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return get dead server node parent path |
|
||||||
*/ |
|
||||||
public String getDeadZNodeParentPath() { |
|
||||||
return REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS; |
|
||||||
} |
|
||||||
|
|
||||||
public void setStoppable(IStoppable stoppable) { |
|
||||||
this.stoppable = stoppable; |
|
||||||
} |
|
||||||
|
|
||||||
public IStoppable getStoppable() { |
|
||||||
return stoppable; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* whether master path |
|
||||||
* |
|
||||||
* @param path path |
|
||||||
* @return result |
|
||||||
*/ |
|
||||||
public boolean isMasterPath(String path) { |
|
||||||
return path != null && path.contains(REGISTRY_DOLPHINSCHEDULER_MASTERS); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* get worker group path |
|
||||||
* |
|
||||||
* @param workerGroup workerGroup |
|
||||||
* @return worker group path |
|
||||||
*/ |
|
||||||
public String getWorkerGroupPath(String workerGroup) { |
|
||||||
return REGISTRY_DOLPHINSCHEDULER_WORKERS + "/" + workerGroup; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* whether worker path |
|
||||||
* |
|
||||||
* @param path path |
|
||||||
* @return result |
|
||||||
*/ |
|
||||||
public boolean isWorkerPath(String path) { |
|
||||||
return path != null && path.contains(REGISTRY_DOLPHINSCHEDULER_WORKERS); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* get children nodes |
|
||||||
* |
|
||||||
* @param key key |
|
||||||
* @return children nodes |
|
||||||
*/ |
|
||||||
public List<String> getChildrenKeys(final String key) { |
|
||||||
return registry.getChildren(key); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,74 +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.dolphinscheduler.service.registry; |
|
||||||
|
|
||||||
import static org.apache.dolphinscheduler.common.Constants.ADD_OP; |
|
||||||
import static org.apache.dolphinscheduler.common.Constants.DELETE_OP; |
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.enums.NodeType; |
|
||||||
import org.apache.dolphinscheduler.spi.register.Registry; |
|
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
import org.junit.runner.RunWith; |
|
||||||
import org.mockito.Mockito; |
|
||||||
import org.powermock.api.mockito.PowerMockito; |
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
||||||
import org.powermock.modules.junit4.PowerMockRunner; |
|
||||||
|
|
||||||
import com.google.common.collect.Sets; |
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class) |
|
||||||
@PrepareForTest({ RegistryClient.class }) |
|
||||||
public class RegistryClientTest { |
|
||||||
|
|
||||||
private RegistryClient registryClient; |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test() throws Exception { |
|
||||||
Registry registry = PowerMockito.mock(Registry.class); |
|
||||||
PowerMockito.doNothing().when(registry).persist(Mockito.anyString(), Mockito.anyString()); |
|
||||||
PowerMockito.doNothing().when(registry).update(Mockito.anyString(), Mockito.anyString()); |
|
||||||
PowerMockito.when(registry.releaseLock(Mockito.anyString())).thenReturn(true); |
|
||||||
PowerMockito.when(registry.getChildren("/dead-servers")).thenReturn(Arrays.asList("worker_127.0.0.1:8089")); |
|
||||||
|
|
||||||
PowerMockito.suppress(PowerMockito.constructor(RegistryClient.class)); |
|
||||||
registryClient = PowerMockito.mock(RegistryClient.class); |
|
||||||
registryClient.persist("/key", ""); |
|
||||||
registryClient.update("/key", ""); |
|
||||||
registryClient.releaseLock("/key"); |
|
||||||
registryClient.getChildrenKeys("/key"); |
|
||||||
registryClient.handleDeadServer(Sets.newHashSet("ma/127.0.0.1:8089"), NodeType.WORKER, DELETE_OP); |
|
||||||
registryClient.handleDeadServer(Sets.newHashSet("ma/127.0.0.1:8089"), NodeType.WORKER, ADD_OP); |
|
||||||
//registryClient.removeDeadServerByHost("127.0.0.1:8089","master");
|
|
||||||
registryClient.handleDeadServer("ma/127.0.0.1:8089", NodeType.WORKER, DELETE_OP); |
|
||||||
registryClient.handleDeadServer("ma/127.0.0.1:8089", NodeType.WORKER, ADD_OP); |
|
||||||
registryClient.checkIsDeadServer("master/127.0.0.1","master"); |
|
||||||
given(registry.getChildren("/nodes/worker")).willReturn(Arrays.asList("worker_127.0.0.1:8089")); |
|
||||||
given(registry.getChildren("/nodes/worker/worker_127.0.0.1:8089")).willReturn(Arrays.asList("default")); |
|
||||||
|
|
||||||
registryClient.checkNodeExists("127.0.0.1",NodeType.WORKER); |
|
||||||
|
|
||||||
registryClient.getServerList(NodeType.MASTER); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -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.dolphinscheduler.service.registry; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.spi.plugin.DolphinPluginLoader; |
|
||||||
import org.apache.dolphinscheduler.spi.plugin.DolphinPluginManagerConfig; |
|
||||||
import org.apache.dolphinscheduler.spi.register.RegistryPluginManager; |
|
||||||
|
|
||||||
import org.junit.Assert; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList; |
|
||||||
|
|
||||||
public class RegistryPluginTest { |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testLoadPlugin() throws Exception { |
|
||||||
DolphinPluginManagerConfig registryPluginManagerConfig = new DolphinPluginManagerConfig(); |
|
||||||
String path = DolphinPluginLoader.class.getClassLoader().getResource("").getPath(); |
|
||||||
|
|
||||||
String registryPluginZkPath = path + "../../../dolphinscheduler-registry-plugin/dolphinscheduler-registry-zookeeper/pom.xml"; |
|
||||||
registryPluginManagerConfig.setPlugins(registryPluginZkPath); |
|
||||||
RegistryPluginManager registryPluginManager = new RegistryPluginManager("zookeeper"); |
|
||||||
|
|
||||||
DolphinPluginLoader registryPluginLoader = new DolphinPluginLoader(registryPluginManagerConfig, ImmutableList.of(registryPluginManager)); |
|
||||||
registryPluginLoader.loadPlugins(); |
|
||||||
Assert.assertNotNull(registryPluginManager.getRegistry()); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -1,23 +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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
public interface ConnectStateListener { |
|
||||||
|
|
||||||
void notify(RegistryConnectState state); |
|
||||||
} |
|
@ -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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
/** |
|
||||||
* Monitor the type of data changes |
|
||||||
*/ |
|
||||||
public enum DataChangeEvent { |
|
||||||
|
|
||||||
ADD("ADD", 1), |
|
||||||
REMOVE("REMOVE", 2), |
|
||||||
UPDATE("UPDATE",3); |
|
||||||
|
|
||||||
private String type; |
|
||||||
|
|
||||||
private int value; |
|
||||||
|
|
||||||
DataChangeEvent(String type, int value) { |
|
||||||
this.type = type; |
|
||||||
this.value = value; |
|
||||||
} |
|
||||||
} |
|
@ -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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
|
|
||||||
/** |
|
||||||
* The registry node monitors subscriptions |
|
||||||
*/ |
|
||||||
public class ListenerManager { |
|
||||||
|
|
||||||
/** |
|
||||||
* All message subscriptions must be subscribed uniformly at startup. |
|
||||||
* A node path only supports one listener |
|
||||||
*/ |
|
||||||
private static HashMap<String, SubscribeListener> listeners = new HashMap<>(); |
|
||||||
|
|
||||||
/** |
|
||||||
* Check whether the key has been monitored |
|
||||||
*/ |
|
||||||
public static boolean checkHasListeners(String path) { |
|
||||||
return null != listeners.get(path); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* add listener(A node can only be monitored by one listener) |
|
||||||
*/ |
|
||||||
public static void addListener(String path, SubscribeListener listener) { |
|
||||||
listeners.put(path, listener); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* remove listener |
|
||||||
*/ |
|
||||||
public static void removeListener(String path) { |
|
||||||
listeners.remove(path); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
*After the data changes, it is distributed to the corresponding listener for processing |
|
||||||
*/ |
|
||||||
public static void dataChange(String key,String path, String data, DataChangeEvent dataChangeEvent) { |
|
||||||
SubscribeListener notifyListener = listeners.get(key); |
|
||||||
if (null == notifyListener) { |
|
||||||
return; |
|
||||||
} |
|
||||||
notifyListener.notify(path, data, dataChangeEvent); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,102 +0,0 @@ |
|||||||
package org.apache.dolphinscheduler.spi.register;/* |
|
||||||
* 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. |
|
||||||
*/ |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* The final display of all registry component data must follow a tree structure. |
|
||||||
* Therefore, some registry may need to do a layer of internal conversion, such as Etcd |
|
||||||
*/ |
|
||||||
public interface Registry { |
|
||||||
|
|
||||||
/** |
|
||||||
* initialize registry center. |
|
||||||
*/ |
|
||||||
void init(Map<String, String> registerData); |
|
||||||
|
|
||||||
/** |
|
||||||
* close registry |
|
||||||
*/ |
|
||||||
void close(); |
|
||||||
|
|
||||||
/** |
|
||||||
* subscribe registry data change, a path can only be monitored by one listener |
|
||||||
*/ |
|
||||||
boolean subscribe(String path, SubscribeListener subscribeListener); |
|
||||||
|
|
||||||
/** |
|
||||||
* unsubscribe |
|
||||||
*/ |
|
||||||
void unsubscribe(String path); |
|
||||||
|
|
||||||
/** |
|
||||||
* Registry status monitoring, globally unique. Only one is allowed to subscribe. |
|
||||||
*/ |
|
||||||
void addConnectionStateListener(RegistryConnectListener registryConnectListener); |
|
||||||
|
|
||||||
/** |
|
||||||
* get key |
|
||||||
*/ |
|
||||||
String get(String key); |
|
||||||
|
|
||||||
/** |
|
||||||
* delete |
|
||||||
*/ |
|
||||||
void remove(String key); |
|
||||||
|
|
||||||
/** |
|
||||||
* persist data |
|
||||||
*/ |
|
||||||
void persist(String key, String value); |
|
||||||
|
|
||||||
/** |
|
||||||
*persist ephemeral data |
|
||||||
*/ |
|
||||||
void persistEphemeral(String key, String value); |
|
||||||
|
|
||||||
/** |
|
||||||
* update data |
|
||||||
*/ |
|
||||||
void update(String key, String value); |
|
||||||
|
|
||||||
/** |
|
||||||
* get children keys |
|
||||||
*/ |
|
||||||
List<String> getChildren(String path); |
|
||||||
|
|
||||||
/** |
|
||||||
* Judge node is exist or not. |
|
||||||
*/ |
|
||||||
boolean isExisted(String key); |
|
||||||
|
|
||||||
/** |
|
||||||
* delete kay |
|
||||||
*/ |
|
||||||
boolean delete(String key); |
|
||||||
|
|
||||||
/** |
|
||||||
* Obtain a distributed lock |
|
||||||
* todo It is best to add expiration time, and automatically release the lock after expiration |
|
||||||
*/ |
|
||||||
boolean acquireLock(String key); |
|
||||||
|
|
||||||
/** |
|
||||||
* release key |
|
||||||
*/ |
|
||||||
boolean releaseLock(String key); |
|
||||||
} |
|
@ -1,23 +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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
public interface RegistryConnectListener { |
|
||||||
|
|
||||||
void notify(RegistryConnectState newState); |
|
||||||
} |
|
@ -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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
/** |
|
||||||
* All registry connection status must be converted to this |
|
||||||
*/ |
|
||||||
public enum RegistryConnectState { |
|
||||||
CONNECTED("connected", 1), |
|
||||||
RECONNECTED("reconnected", 2), |
|
||||||
SUSPENDED("suspended", 3), |
|
||||||
LOST("lost", 4); |
|
||||||
|
|
||||||
private String description; |
|
||||||
|
|
||||||
private int state; |
|
||||||
|
|
||||||
RegistryConnectState(String description, int state) { |
|
||||||
this.description = description; |
|
||||||
this.state = state; |
|
||||||
} |
|
||||||
} |
|
@ -1,32 +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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
/** |
|
||||||
* registry exception |
|
||||||
*/ |
|
||||||
public class RegistryException extends RuntimeException { |
|
||||||
|
|
||||||
public RegistryException(String message, Throwable cause) { |
|
||||||
super(message, cause); |
|
||||||
} |
|
||||||
|
|
||||||
public RegistryException(String message) { |
|
||||||
super(message); |
|
||||||
} |
|
||||||
} |
|
@ -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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
/** |
|
||||||
* Registry the component factory, all registry must implement this interface
|
|
||||||
*/ |
|
||||||
public interface RegistryFactory { |
|
||||||
|
|
||||||
/** |
|
||||||
* get registry component name |
|
||||||
*/ |
|
||||||
String getName(); |
|
||||||
|
|
||||||
/** |
|
||||||
* get registry |
|
||||||
*/ |
|
||||||
Registry create(); |
|
||||||
} |
|
@ -1,82 +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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin; |
|
||||||
import org.apache.dolphinscheduler.spi.classloader.ThreadContextClassLoader; |
|
||||||
import org.apache.dolphinscheduler.spi.plugin.AbstractDolphinPluginManager; |
|
||||||
|
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
|
|
||||||
/** |
|
||||||
* The plug-in address of the registry needs to be configured. |
|
||||||
* Multi-registries are not supported. |
|
||||||
* When the plug-in directory contains multiple plug-ins, only the configured plug-in will be used. |
|
||||||
* todo It’s not good to put it here, consider creating a separate API module for each plugin |
|
||||||
*/ |
|
||||||
public class RegistryPluginManager extends AbstractDolphinPluginManager { |
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RegistryPluginManager.class); |
|
||||||
|
|
||||||
private RegistryFactory registryFactory; |
|
||||||
|
|
||||||
public static Registry registry; |
|
||||||
|
|
||||||
private String registerPluginName; |
|
||||||
|
|
||||||
public RegistryPluginManager(String registerPluginName) { |
|
||||||
this.registerPluginName = registerPluginName; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void installPlugin(DolphinSchedulerPlugin dolphinSchedulerPlugin) { |
|
||||||
for (RegistryFactory registryFactory : dolphinSchedulerPlugin.getRegisterFactorys()) { |
|
||||||
logger.info("Registering Registry Plugin '{}'", registryFactory.getName()); |
|
||||||
if (registerPluginName.equals(registryFactory.getName())) { |
|
||||||
this.registryFactory = registryFactory; |
|
||||||
loadRegistry(); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
if (null == registry) { |
|
||||||
throw new RegistryException(String.format("not found %s registry plugin ", registerPluginName)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* load registry |
|
||||||
*/ |
|
||||||
private void loadRegistry() { |
|
||||||
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(registryFactory.getClass().getClassLoader())) { |
|
||||||
registry = registryFactory.create(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* get registry |
|
||||||
* @return registry |
|
||||||
*/ |
|
||||||
public Registry getRegistry() { |
|
||||||
if (null == registry) { |
|
||||||
throw new RegistryException("not install registry"); |
|
||||||
} |
|
||||||
return registry; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,30 +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.dolphinscheduler.spi.register; |
|
||||||
|
|
||||||
/** |
|
||||||
* Registration center subscription. All listeners must implement this interface
|
|
||||||
*/ |
|
||||||
public interface SubscribeListener { |
|
||||||
|
|
||||||
/** |
|
||||||
* Processing logic when the subscription node changes |
|
||||||
*/ |
|
||||||
void notify(String path, String data, DataChangeEvent dataChangeEvent); |
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue