|
|
|
@ -17,8 +17,11 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.remote.utils; |
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.common.Constants.COLON; |
|
|
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.StringJoiner; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* server address |
|
|
|
@ -61,13 +64,13 @@ public class Host implements Serializable {
|
|
|
|
|
public Host(String ip, int port) { |
|
|
|
|
this.ip = ip; |
|
|
|
|
this.port = port; |
|
|
|
|
this.address = ip + ":" + port; |
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Host(String ip, int port, int weight, long startTime) { |
|
|
|
|
this.ip = ip; |
|
|
|
|
this.port = port; |
|
|
|
|
this.address = ip + ":" + port; |
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
this.weight = getWarmUpWeight(weight, startTime); |
|
|
|
|
this.startTime = startTime; |
|
|
|
|
} |
|
|
|
@ -75,7 +78,7 @@ public class Host implements Serializable {
|
|
|
|
|
public Host(String ip, int port, int weight, long startTime, String workGroup) { |
|
|
|
|
this.ip = ip; |
|
|
|
|
this.port = port; |
|
|
|
|
this.address = ip + ":" + port; |
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
this.weight = getWarmUpWeight(weight, startTime); |
|
|
|
|
this.workGroup = workGroup; |
|
|
|
|
this.startTime = startTime; |
|
|
|
@ -95,7 +98,7 @@ public class Host implements Serializable {
|
|
|
|
|
|
|
|
|
|
public void setIp(String ip) { |
|
|
|
|
this.ip = ip; |
|
|
|
|
this.address = ip + ":" + port; |
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getWeight() { |
|
|
|
@ -120,7 +123,7 @@ public class Host implements Serializable {
|
|
|
|
|
|
|
|
|
|
public void setPort(int port) { |
|
|
|
|
this.port = port; |
|
|
|
|
this.address = ip + ":" + port; |
|
|
|
|
this.address = ip + COLON + port; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getWorkGroup() { |
|
|
|
@ -141,7 +144,7 @@ public class Host implements Serializable {
|
|
|
|
|
if (address == null) { |
|
|
|
|
throw new IllegalArgumentException("Host : address is null."); |
|
|
|
|
} |
|
|
|
|
String[] parts = address.split(":"); |
|
|
|
|
String[] parts = address.split(COLON); |
|
|
|
|
if (parts.length < 2) { |
|
|
|
|
throw new IllegalArgumentException(String.format("Host : %s illegal.", address)); |
|
|
|
|
} |
|
|
|
@ -155,6 +158,21 @@ public class Host implements Serializable {
|
|
|
|
|
return host; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* generate host string |
|
|
|
|
* @param address address |
|
|
|
|
* @param weight weight |
|
|
|
|
* @param startTime startTime |
|
|
|
|
* @return address:weight:startTime |
|
|
|
|
*/ |
|
|
|
|
public static String generate(String address, int weight, long startTime) { |
|
|
|
|
StringJoiner stringJoiner = new StringJoiner(COLON); |
|
|
|
|
stringJoiner.add(address) |
|
|
|
|
.add(String.valueOf(weight)) |
|
|
|
|
.add(String.valueOf(startTime)); |
|
|
|
|
return stringJoiner.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* whether old version |
|
|
|
|
* |
|
|
|
@ -162,7 +180,7 @@ public class Host implements Serializable {
|
|
|
|
|
* @return old version is true , otherwise is false |
|
|
|
|
*/ |
|
|
|
|
public static Boolean isOldVersion(String address) { |
|
|
|
|
String[] parts = address.split(":"); |
|
|
|
|
String[] parts = address.split(COLON); |
|
|
|
|
return parts.length != 2 && parts.length != 3; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -187,6 +205,9 @@ public class Host implements Serializable {
|
|
|
|
|
public String toString() { |
|
|
|
|
return "Host{" |
|
|
|
|
+ "address='" + address + '\'' |
|
|
|
|
+ ", weight=" + weight |
|
|
|
|
+ ", startTime=" + startTime |
|
|
|
|
+ ", workGroup='" + workGroup + '\'' |
|
|
|
|
+ '}'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -201,4 +222,13 @@ public class Host implements Serializable {
|
|
|
|
|
} |
|
|
|
|
return weight; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get address and weight |
|
|
|
|
* |
|
|
|
|
* @return address:weight |
|
|
|
|
*/ |
|
|
|
|
public String getAddressAndWeight() { |
|
|
|
|
return address + COLON + weight; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|