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