|
|
@ -17,33 +17,20 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.remote.utils; |
|
|
|
package org.apache.dolphinscheduler.remote.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.common.constants.Constants.COLON; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
import java.io.Serializable; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.Data; |
|
|
|
import lombok.NonNull; |
|
|
|
import lombok.NonNull; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Data |
|
|
|
* server address |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public class Host implements Serializable { |
|
|
|
public class Host implements Serializable { |
|
|
|
|
|
|
|
|
|
|
|
private static final String COLON = ":"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final Host EMPTY = new Host(); |
|
|
|
public static final Host EMPTY = new Host(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* address |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String address; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* ip |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String ip; |
|
|
|
private String ip; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* port |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private int port; |
|
|
|
private int port; |
|
|
|
|
|
|
|
|
|
|
|
public Host() { |
|
|
|
public Host() { |
|
|
@ -52,107 +39,23 @@ public class Host implements Serializable { |
|
|
|
public Host(String ip, int port) { |
|
|
|
public Host(String ip, int port) { |
|
|
|
this.ip = ip; |
|
|
|
this.ip = ip; |
|
|
|
this.port = port; |
|
|
|
this.port = port; |
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Host(String address) { |
|
|
|
public Host(String address) { |
|
|
|
String[] parts = splitAddress(address); |
|
|
|
int lastColonIndex = address.lastIndexOf(COLON); |
|
|
|
this.ip = parts[0]; |
|
|
|
if (lastColonIndex < 0) { |
|
|
|
this.port = Integer.parseInt(parts[1]); |
|
|
|
|
|
|
|
this.address = address; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getAddress() { |
|
|
|
|
|
|
|
return address; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAddress(String address) { |
|
|
|
|
|
|
|
String[] parts = splitAddress(address); |
|
|
|
|
|
|
|
this.ip = parts[0]; |
|
|
|
|
|
|
|
this.port = Integer.parseInt(parts[1]); |
|
|
|
|
|
|
|
this.address = address; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getIp() { |
|
|
|
|
|
|
|
return ip; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setIp(String ip) { |
|
|
|
|
|
|
|
this.ip = ip; |
|
|
|
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getPort() { |
|
|
|
|
|
|
|
return port; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPort(int port) { |
|
|
|
|
|
|
|
this.port = port; |
|
|
|
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* address convert host |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param address address |
|
|
|
|
|
|
|
* @return host |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Host of(@NonNull String address) { |
|
|
|
|
|
|
|
String[] parts = splitAddress(address); |
|
|
|
|
|
|
|
return new Host(parts[0], Integer.parseInt(parts[1])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* address convert host |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param address address |
|
|
|
|
|
|
|
* @return host |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static String[] splitAddress(String address) { |
|
|
|
|
|
|
|
if (address == null) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Host : address is null."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String[] parts = address.split(COLON); |
|
|
|
|
|
|
|
if (parts.length != 2) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format("Host : %s illegal.", address)); |
|
|
|
throw new IllegalArgumentException(String.format("Host : %s illegal.", address)); |
|
|
|
} |
|
|
|
} |
|
|
|
return parts; |
|
|
|
this.ip = address.substring(0, lastColonIndex); |
|
|
|
} |
|
|
|
this.port = Integer.parseInt(address.substring(lastColonIndex + 1)); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* whether old version |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param address address |
|
|
|
|
|
|
|
* @return old version is true , otherwise is false |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Boolean isOldVersion(String address) { |
|
|
|
|
|
|
|
String[] parts = address.split(COLON); |
|
|
|
|
|
|
|
return parts.length != 2; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAddress() { |
|
|
|
public String toString() { |
|
|
|
return ip + COLON + port; |
|
|
|
return "Host{" |
|
|
|
|
|
|
|
+ "address='" + address + '\'' |
|
|
|
|
|
|
|
+ ", ip='" + ip + '\'' |
|
|
|
|
|
|
|
+ ", port=" + port |
|
|
|
|
|
|
|
+ '}'; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public static Host of(@NonNull String address) { |
|
|
|
public boolean equals(Object o) { |
|
|
|
return new Host(address); |
|
|
|
if (this == o) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (o == null || getClass() != o.getClass()) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Host host = (Host) o; |
|
|
|
|
|
|
|
return port == host.port && Objects.equals(address, host.address) && Objects.equals(ip, host.ip); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int hashCode() { |
|
|
|
|
|
|
|
return Objects.hash(address, ip, port); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|