Browse Source

add java doc for common module (#1213)

pull/2/head
dailidong 5 years ago committed by qiaozhanwei
parent
commit
f92516892e
  1. 13
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/ExecutionStatus.java
  2. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java
  3. 26
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/graph/DAG.java
  4. 10
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/shell/AbstractShell.java
  5. 10
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/shell/ShellExecutor.java
  6. 16
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Bytes.java
  7. 17
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java
  8. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java
  9. 94
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
  10. 6
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DependentUtils.java
  11. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/EncryptionUtils.java
  12. 43
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
  13. 44
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java
  14. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
  15. 1
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java
  16. 37
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
  17. 33
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  18. 28
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
  19. 42
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
  20. 29
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java
  21. 14
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/SchemaUtils.java
  22. 11
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java
  23. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/TaskParametersUtils.java
  24. 1
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/BusinessTimeUtils.java
  25. 1
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java
  26. 1
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PropertyPlaceholderHelper.java
  27. 41
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
  28. 92
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/zk/AbstractZKClient.java

13
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/ExecutionStatus.java

@ -67,7 +67,7 @@ public enum ExecutionStatus {
/** /**
* status is success * status is success
* @return * @return status
*/ */
public boolean typeIsSuccess(){ public boolean typeIsSuccess(){
return this == SUCCESS; return this == SUCCESS;
@ -75,7 +75,7 @@ public enum ExecutionStatus {
/** /**
* status is failure * status is failure
* @return * @return status
*/ */
public boolean typeIsFailure(){ public boolean typeIsFailure(){
return this == FAILURE || this == NEED_FAULT_TOLERANCE; return this == FAILURE || this == NEED_FAULT_TOLERANCE;
@ -83,7 +83,7 @@ public enum ExecutionStatus {
/** /**
* status is finished * status is finished
* @return * @return status
*/ */
public boolean typeIsFinished(){ public boolean typeIsFinished(){
@ -93,7 +93,7 @@ public enum ExecutionStatus {
/** /**
* status is waiting thread * status is waiting thread
* @return * @return status
*/ */
public boolean typeIsWaittingThread(){ public boolean typeIsWaittingThread(){
return this == WAITTING_THREAD; return this == WAITTING_THREAD;
@ -101,7 +101,7 @@ public enum ExecutionStatus {
/** /**
* status is pause * status is pause
* @return * @return status
*/ */
public boolean typeIsPause(){ public boolean typeIsPause(){
return this == PAUSE; return this == PAUSE;
@ -109,7 +109,7 @@ public enum ExecutionStatus {
/** /**
* status is running * status is running
* @return * @return status
*/ */
public boolean typeIsRunning(){ public boolean typeIsRunning(){
return this == RUNNING_EXEUTION || this == WAITTING_DEPEND; return this == RUNNING_EXEUTION || this == WAITTING_DEPEND;
@ -117,6 +117,7 @@ public enum ExecutionStatus {
/** /**
* status is cancel * status is cancel
* @return status
*/ */
public boolean typeIsCancel(){ return this == KILL || this == STOP ;} public boolean typeIsCancel(){ return this == KILL || this == STOP ;}

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java

@ -31,8 +31,8 @@ public enum TaskStateType {
/** /**
* convert task state to execute status integer array ; * convert task state to execute status integer array ;
* @param taskStateType * @param taskStateType task state type
* @return * @return result of execution status
*/ */
public static int[] convert2ExecutStatusIntArray(TaskStateType taskStateType){ public static int[] convert2ExecutStatusIntArray(TaskStateType taskStateType){

26
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/graph/DAG.java

@ -139,7 +139,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* whether this node is contained * whether this node is contained
* *
* @param node node * @param node node
* @return * @return true if contains
*/ */
public boolean containsNode(Node node) { public boolean containsNode(Node node) {
lock.readLock().lock(); lock.readLock().lock();
@ -157,7 +157,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* *
* @param fromNode node of origin * @param fromNode node of origin
* @param toNode node of destination * @param toNode node of destination
* @return * @return true if contains
*/ */
public boolean containsEdge(Node fromNode, Node toNode) { public boolean containsEdge(Node fromNode, Node toNode) {
lock.readLock().lock(); lock.readLock().lock();
@ -178,7 +178,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* get node description * get node description
* *
* @param node node * @param node node
* @return * @return node description
*/ */
public NodeInfo getNode(Node node) { public NodeInfo getNode(Node node) {
lock.readLock().lock(); lock.readLock().lock();
@ -194,7 +194,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/** /**
* Get the number of nodes * Get the number of nodes
* *
* @return * @return the number of nodes
*/ */
public int getNodesCount() { public int getNodesCount() {
lock.readLock().lock(); lock.readLock().lock();
@ -209,7 +209,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/** /**
* Get the number of edges * Get the number of edges
* *
* @return * @return the number of edges
*/ */
public int getEdgesCount() { public int getEdgesCount() {
lock.readLock().lock(); lock.readLock().lock();
@ -230,7 +230,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/** /**
* get the start node of DAG * get the start node of DAG
* *
* @return * @return the start node of DAG
*/ */
public Collection<Node> getBeginNode() { public Collection<Node> getBeginNode() {
lock.readLock().lock(); lock.readLock().lock();
@ -247,7 +247,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/** /**
* get the end node of DAG * get the end node of DAG
* *
* @return * @return the end node of DAG
*/ */
public Collection<Node> getEndNode() { public Collection<Node> getEndNode() {
@ -266,7 +266,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Gets all previous nodes of the node * Gets all previous nodes of the node
* *
* @param node node id to be calculated * @param node node id to be calculated
* @return * @return all previous nodes of the node
*/ */
public Set<Node> getPreviousNodes(Node node) { public Set<Node> getPreviousNodes(Node node) {
lock.readLock().lock(); lock.readLock().lock();
@ -283,7 +283,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Get all subsequent nodes of the node * Get all subsequent nodes of the node
* *
* @param node node id to be calculated * @param node node id to be calculated
* @return * @return all subsequent nodes of the node
*/ */
public Set<Node> getSubsequentNodes(Node node) { public Set<Node> getSubsequentNodes(Node node) {
lock.readLock().lock(); lock.readLock().lock();
@ -300,7 +300,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* Gets the degree of entry of the node * Gets the degree of entry of the node
* *
* @param node node id * @param node node id
* @return * @return the degree of entry of the node
*/ */
public int getIndegree(Node node) { public int getIndegree(Node node) {
lock.readLock().lock(); lock.readLock().lock();
@ -331,7 +331,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
/** /**
* Only DAG has a topological sort * Only DAG has a topological sort
* @return topologically sorted results, returns false if the DAG result is a ring result * @return topologically sorted results, returns false if the DAG result is a ring result
* @throws Exception * @throws Exception errors
*/ */
public List<Node> topologicalSort() throws Exception { public List<Node> topologicalSort() throws Exception {
lock.readLock().lock(); lock.readLock().lock();
@ -385,7 +385,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* @param fromNode node of origin * @param fromNode node of origin
* @param toNode node of destination * @param toNode node of destination
* @param createNode whether to create a node * @param createNode whether to create a node
* @return * @return true if added
*/ */
private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) { private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) {
if (fromNode.equals(toNode)) { if (fromNode.equals(toNode)) {
@ -429,7 +429,7 @@ public class DAG<Node, NodeInfo, EdgeInfo> {
* *
* @param node Node id to be calculated * @param node Node id to be calculated
* @param edges neighbor edge information * @param edges neighbor edge information
* @return * @return all neighbor nodes of the node
*/ */
private Set<Node> getNeighborNodes(Node node, final Map<Node, Map<Node, EdgeInfo>> edges) { private Set<Node> getNeighborNodes(Node node, final Map<Node, Map<Node, EdgeInfo>> edges) {
final Map<Node, EdgeInfo> neighborEdges = edges.get(node); final Map<Node, EdgeInfo> neighborEdges = edges.get(node);

10
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/shell/AbstractShell.java

@ -113,6 +113,7 @@ public abstract class AbstractShell {
/** /**
* check to see if a command needs to be executed and execute if needed * check to see if a command needs to be executed and execute if needed
* @throws IOException errors
*/ */
protected void run() throws IOException { protected void run() throws IOException {
if (lastTime + interval > System.currentTimeMillis()) { if (lastTime + interval > System.currentTimeMillis()) {
@ -222,13 +223,16 @@ public abstract class AbstractShell {
} }
/** /**
* return an array containing the command name & its parameters *
* */ * @return an array containing the command name and its parameters
*/
protected abstract String[] getExecString(); protected abstract String[] getExecString();
/** /**
* Parse the execution result * Parse the execution result
* */ * @param lines lines
* @throws IOException errors
*/
protected abstract void parseExecResult(BufferedReader lines) protected abstract void parseExecResult(BufferedReader lines)
throws IOException; throws IOException;

10
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/shell/ShellExecutor.java

@ -81,6 +81,7 @@ public class ShellExecutor extends AbstractShell {
* the <code>AbstractShell</code> interface. * the <code>AbstractShell</code> interface.
* @param cmd shell command to execute. * @param cmd shell command to execute.
* @return the output of the executed command. * @return the output of the executed command.
* @throws IOException errors
*/ */
public static String execCommand(String... cmd) throws IOException { public static String execCommand(String... cmd) throws IOException {
return execCommand(null, cmd, 0L); return execCommand(null, cmd, 0L);
@ -93,9 +94,9 @@ public class ShellExecutor extends AbstractShell {
* @param env the map of environment key=value * @param env the map of environment key=value
* @param cmd shell command to execute. * @param cmd shell command to execute.
* @param timeout time in milliseconds after which script should be marked timeout * @param timeout time in milliseconds after which script should be marked timeout
* @return the output of the executed command.o * @return the output of the executed command.
* @throws IOException errors
*/ */
public static String execCommand(Map<String, String> env, String[] cmd, public static String execCommand(Map<String, String> env, String[] cmd,
long timeout) throws IOException { long timeout) throws IOException {
ShellExecutor exec = new ShellExecutor(cmd, null, env, ShellExecutor exec = new ShellExecutor(cmd, null, env,
@ -111,6 +112,7 @@ public class ShellExecutor extends AbstractShell {
* @param env the map of environment key=value * @param env the map of environment key=value
* @param cmd shell command to execute. * @param cmd shell command to execute.
* @return the output of the executed command. * @return the output of the executed command.
* @throws IOException errors
*/ */
public static String execCommand(Map<String,String> env, String ... cmd) public static String execCommand(Map<String,String> env, String ... cmd)
throws IOException { throws IOException {
@ -119,7 +121,7 @@ public class ShellExecutor extends AbstractShell {
/** /**
* Execute the shell command * Execute the shell command
* * @throws IOException errors
*/ */
public void execute() throws IOException { public void execute() throws IOException {
this.run(); this.run();
@ -144,7 +146,7 @@ public class ShellExecutor extends AbstractShell {
/** /**
* *
* Get the output of the shell command * @return the output of the shell command
*/ */
public String getOutput() { public String getOutput() {
return (output == null) ? "" : output.toString(); return (output == null) ? "" : output.toString();

16
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/Bytes.java

@ -106,6 +106,7 @@ public class Bytes {
* @param b1 The first byte array. * @param b1 The first byte array.
* @param sep The separator to use. * @param sep The separator to use.
* @param b2 The second byte array. * @param b2 The second byte array.
* @return two byte arrays together using a separator.
*/ */
public static String toString(final byte [] b1, public static String toString(final byte [] b1,
String sep, String sep,
@ -470,9 +471,9 @@ public class Bytes {
} }
/** /**
* This method will get a sequence of bytes from pos -> limit, * This method will get a sequence of bytes from pos to limit,
* but will restore pos after. * but will restore pos after.
* @param buf * @param buf buffer
* @return byte array * @return byte array
*/ */
public static byte[] getBytes(ByteBuffer buf) { public static byte[] getBytes(ByteBuffer buf) {
@ -506,7 +507,7 @@ public class Bytes {
/** /**
* Convert a BigDecimal value to a byte array * Convert a BigDecimal value to a byte array
* *
* @param val * @param val value
* @return the byte array * @return the byte array
*/ */
public static byte[] toBytes(BigDecimal val) { public static byte[] toBytes(BigDecimal val) {
@ -521,7 +522,7 @@ public class Bytes {
/** /**
* Converts a byte array to a BigDecimal * Converts a byte array to a BigDecimal
* *
* @param bytes * @param bytes bytes array
* @return the char value * @return the char value
*/ */
public static BigDecimal toBigDecimal(byte[] bytes) { public static BigDecimal toBigDecimal(byte[] bytes) {
@ -531,9 +532,9 @@ public class Bytes {
/** /**
* Converts a byte array to a BigDecimal value * Converts a byte array to a BigDecimal value
* *
* @param bytes * @param bytes bytes array
* @param offset * @param offset offset
* @param length * @param length length
* @return the char value * @return the char value
*/ */
public static BigDecimal toBigDecimal(byte[] bytes, int offset, final int length) { public static BigDecimal toBigDecimal(byte[] bytes, int offset, final int length) {
@ -652,6 +653,7 @@ public class Bytes {
* @param bytes array to hash * @param bytes array to hash
* @param offset offset to start from * @param offset offset to start from
* @param length length to hash * @param length length to hash
* @return hash code
* */ * */
public static int hashCode(byte[] bytes, int offset, int length) { public static int hashCode(byte[] bytes, int offset, int length) {
int hash = 1; int hash = 1;

17
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CollectionUtils.java

@ -41,7 +41,7 @@ public class CollectionUtils {
* Returns a new {@link Collection} containing <i>a</i> minus a subset of * Returns a new {@link Collection} containing <i>a</i> minus a subset of
* <i>b</i>. Only the elements of <i>b</i> that satisfy the predicate * <i>b</i>. Only the elements of <i>b</i> that satisfy the predicate
* condition, <i>p</i> are subtracted from <i>a</i>. * condition, <i>p</i> are subtracted from <i>a</i>.
* <p> *
* <p>The cardinality of each element <i>e</i> in the returned {@link Collection} * <p>The cardinality of each element <i>e</i> in the returned {@link Collection}
* that satisfies the predicate condition will be the cardinality of <i>e</i> in <i>a</i> * that satisfies the predicate condition will be the cardinality of <i>e</i> in <i>a</i>
* minus the cardinality of <i>e</i> in <i>b</i>, or zero, whichever is greater.</p> * minus the cardinality of <i>e</i> in <i>b</i>, or zero, whichever is greater.</p>
@ -50,6 +50,7 @@ public class CollectionUtils {
* *
* @param a the collection to subtract from, must not be null * @param a the collection to subtract from, must not be null
* @param b the collection to subtract, must not be null * @param b the collection to subtract, must not be null
* @param <T> T
* @return a new collection with the results * @return a new collection with the results
* @see Collection#removeAll * @see Collection#removeAll
*/ */
@ -70,7 +71,7 @@ public class CollectionUtils {
* *
* @param str string * @param str string
* @param separator separator * @param separator separator
* @return * @return string to map
*/ */
public static Map<String, String> stringToMap(String str, String separator) { public static Map<String, String> stringToMap(String str, String separator) {
return stringToMap(str, separator, ""); return stringToMap(str, separator, "");
@ -82,7 +83,7 @@ public class CollectionUtils {
* @param str string * @param str string
* @param separator separator * @param separator separator
* @param keyPrefix prefix * @param keyPrefix prefix
* @return * @return string to map
*/ */
public static Map<String, String> stringToMap(String str, String separator, String keyPrefix) { public static Map<String, String> stringToMap(String str, String separator, String keyPrefix) {
if (null == str || "".equals(str)) { if (null == str || "".equals(str)) {
@ -245,7 +246,7 @@ public class CollectionUtils {
* Only those elements present in the collection will appear as * Only those elements present in the collection will appear as
* keys in the map. * keys in the map.
* *
* @param <O> the type of object in the returned {@link Map}. This is a super type of <I>. * @param <O> the type of object in the returned {@link Map}. This is a super type of O
* @param coll the collection to get the cardinality map for, must not be null * @param coll the collection to get the cardinality map for, must not be null
* @return the populated cardinality map * @return the populated cardinality map
*/ */
@ -265,10 +266,10 @@ public class CollectionUtils {
/** /**
* Removes certain attributes of each object in the list * Removes certain attributes of each object in the list
* @param originList * @param originList origin list
* @param exclusionSet * @param exclusionSet exclusion set
* @param <T> * @param <T> T
* @return * @return removes certain attributes of each object in the list
*/ */
public static <T extends Object> List<Map<String, Object>> getListByExclusion(List<T> originList, Set<String> exclusionSet) { public static <T extends Object> List<Map<String, Object>> getListByExclusion(List<T> originList, Set<String> exclusionSet) {
List<Map<String, Object>> instanceList = new ArrayList<>(); List<Map<String, Object>> instanceList = new ArrayList<>();

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/CommonUtils.java

@ -64,7 +64,7 @@ public class CommonUtils {
/** /**
* if upload resource is HDFS and kerberos startup is true , else false * if upload resource is HDFS and kerberos startup is true , else false
* @return * @return true if upload resource is HDFS and kerberos startup
*/ */
public static boolean getKerberosStartupState(){ public static boolean getKerberosStartupState(){
String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE); String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE);
@ -75,7 +75,7 @@ public class CommonUtils {
/** /**
* load kerberos configuration * load kerberos configuration
* @throws Exception * @throws Exception errors
*/ */
public static void loadKerberosConf()throws Exception{ public static void loadKerberosConf()throws Exception{
if (CommonUtils.getKerberosStartupState()) { if (CommonUtils.getKerberosStartupState()) {

94
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java

@ -63,7 +63,7 @@ public class DateUtils {
} }
/** /**
* @param format * @param format format
* @return get the date string in the specified format of the current time * @return get the date string in the specified format of the current time
*/ */
public static String getCurrentTime(String format) { public static String getCurrentTime(String format) {
@ -72,7 +72,7 @@ public class DateUtils {
} }
/** /**
* @param date * @param date date
* @param format e.g. yyyy-MM-dd HH:mm:ss * @param format e.g. yyyy-MM-dd HH:mm:ss
* @return get the formatted date string * @return get the formatted date string
*/ */
@ -82,7 +82,7 @@ public class DateUtils {
} }
/** /**
* @param localDateTime * @param localDateTime local data time
* @param format e.g. yyyy-MM-dd HH:mm:ss * @param format e.g. yyyy-MM-dd HH:mm:ss
* @return get the formatted date string * @return get the formatted date string
*/ */
@ -91,7 +91,7 @@ public class DateUtils {
} }
/** /**
* @param date * @param date date
* @return convert time to yyyy-MM-dd HH:mm:ss format * @return convert time to yyyy-MM-dd HH:mm:ss format
*/ */
public static String dateToString(Date date) { public static String dateToString(Date date) {
@ -100,7 +100,8 @@ public class DateUtils {
/** /**
* @param date * @param date date
* @param format format
* @return convert string to date and time * @return convert string to date and time
*/ */
public static Date parse(String date, String format) { public static Date parse(String date, String format) {
@ -117,8 +118,8 @@ public class DateUtils {
/** /**
* convert date str to yyyy-MM-dd HH:mm:ss format * convert date str to yyyy-MM-dd HH:mm:ss format
* *
* @param str * @param str date string
* @return * @return yyyy-MM-dd HH:mm:ss format
*/ */
public static Date stringToDate(String str) { public static Date stringToDate(String str) {
return parse(str, Constants.YYYY_MM_DD_HH_MM_SS); return parse(str, Constants.YYYY_MM_DD_HH_MM_SS);
@ -127,9 +128,9 @@ public class DateUtils {
/** /**
* get seconds between two dates * get seconds between two dates
* *
* @param d1 * @param d1 date1
* @param d2 * @param d2 date2
* @return * @return differ seconds
*/ */
public static long differSec(Date d1, Date d2) { public static long differSec(Date d1, Date d2) {
if(d1 == null || d2 == null){ if(d1 == null || d2 == null){
@ -141,9 +142,9 @@ public class DateUtils {
/** /**
* get ms between two dates * get ms between two dates
* *
* @param d1 * @param d1 date1
* @param d2 * @param d2 date2
* @return * @return differ ms
*/ */
public static long differMs(Date d1, Date d2) { public static long differMs(Date d1, Date d2) {
return Math.abs(d1.getTime() - d2.getTime()); return Math.abs(d1.getTime() - d2.getTime());
@ -153,9 +154,9 @@ public class DateUtils {
/** /**
* get hours between two dates * get hours between two dates
* *
* @param d1 * @param d1 date1
* @param d2 * @param d2 date2
* @return * @return differ hours
*/ */
public static long diffHours(Date d1, Date d2) { public static long diffHours(Date d1, Date d2) {
return (long) Math.ceil(diffMin(d1, d2) / 60.0); return (long) Math.ceil(diffMin(d1, d2) / 60.0);
@ -164,9 +165,9 @@ public class DateUtils {
/** /**
* get minutes between two dates * get minutes between two dates
* *
* @param d1 * @param d1 date1
* @param d2 * @param d2 date2
* @return * @return differ minutes
*/ */
public static long diffMin(Date d1, Date d2) { public static long diffMin(Date d1, Date d2) {
return (long) Math.ceil(differSec(d1, d2) / 60.0); return (long) Math.ceil(differSec(d1, d2) / 60.0);
@ -176,9 +177,9 @@ public class DateUtils {
/** /**
* get the date of the specified date in the days before and after * get the date of the specified date in the days before and after
* *
* @param date * @param date date
* @param day * @param day day
* @return * @return the date of the specified date in the days before and after
*/ */
public static Date getSomeDay(Date date, int day) { public static Date getSomeDay(Date date, int day) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -190,9 +191,9 @@ public class DateUtils {
/** /**
* compare two dates * compare two dates
* *
* @param future * @param future future date
* @param old * @param old old date
* @return * @return true if future time greater than old time
*/ */
public static boolean compare(Date future, Date old) { public static boolean compare(Date future, Date old) {
return future.getTime() > old.getTime(); return future.getTime() > old.getTime();
@ -201,8 +202,8 @@ public class DateUtils {
/** /**
* convert schedule string to date * convert schedule string to date
* *
* @param schedule * @param schedule schedule
* @return * @return convert schedule string to date
*/ */
public static Date getScheduleDate(String schedule) { public static Date getScheduleDate(String schedule) {
return stringToDate(schedule); return stringToDate(schedule);
@ -211,8 +212,8 @@ public class DateUtils {
/** /**
* format time to readable * format time to readable
* *
* @param ms * @param ms ms
* @return * @return format time
*/ */
public static String format2Readable(long ms) { public static String format2Readable(long ms) {
@ -228,7 +229,9 @@ public class DateUtils {
/** /**
* get monday * get monday
* <p> * <p>
* note: Set the first day of the week to Monday, the default is Sunday * note: Set the first day of the week to Monday, the default is Sunday</p>
* @param date date
* @return get monday
*/ */
public static Date getMonday(Date date) { public static Date getMonday(Date date) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -245,6 +248,8 @@ public class DateUtils {
* get sunday * get sunday
* <p> * <p>
* note: Set the first day of the week to Monday, the default is Sunday * note: Set the first day of the week to Monday, the default is Sunday
* @param date date
* @return get sunday
*/ */
public static Date getSunday(Date date) { public static Date getSunday(Date date) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -258,7 +263,9 @@ public class DateUtils {
/** /**
* get first day of month * get first day of month
*/ * @param date date
* @return first day of month
* */
public static Date getFirstDayOfMonth(Date date) { public static Date getFirstDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -269,8 +276,11 @@ public class DateUtils {
} }
/** /**
* get first day of month * get some hour of day
*/ * @param date date
* @param hours hours
* @return some hour of day
* */
public static Date getSomeHourOfDay(Date date, int hours) { public static Date getSomeHourOfDay(Date date, int hours) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -284,6 +294,8 @@ public class DateUtils {
/** /**
* get last day of month * get last day of month
* @param date date
* @return get last day of month
*/ */
public static Date getLastDayOfMonth(Date date) { public static Date getLastDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -300,8 +312,8 @@ public class DateUtils {
/** /**
* return YYYY-MM-DD 00:00:00 * return YYYY-MM-DD 00:00:00
* *
* @param inputDay * @param inputDay date
* @return * @return start day
*/ */
public static Date getStartOfDay(Date inputDay) { public static Date getStartOfDay(Date inputDay) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -315,8 +327,8 @@ public class DateUtils {
/** /**
* return YYYY-MM-DD 23:59:59 * return YYYY-MM-DD 23:59:59
* *
* @param inputDay * @param inputDay day
* @return * @return end of day
*/ */
public static Date getEndOfDay(Date inputDay) { public static Date getEndOfDay(Date inputDay) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -330,8 +342,8 @@ public class DateUtils {
/** /**
* return YYYY-MM-DD 00:00:00 * return YYYY-MM-DD 00:00:00
* *
* @param inputDay * @param inputDay day
* @return * @return start of hour
*/ */
public static Date getStartOfHour(Date inputDay) { public static Date getStartOfHour(Date inputDay) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -344,8 +356,8 @@ public class DateUtils {
/** /**
* return YYYY-MM-DD 23:59:59 * return YYYY-MM-DD 23:59:59
* *
* @param inputDay * @param inputDay day
* @return * @return end of hour
*/ */
public static Date getEndOfHour(Date inputDay) { public static Date getEndOfHour(Date inputDay) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();

6
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DependentUtils.java

@ -64,9 +64,9 @@ public class DependentUtils {
/** /**
* get date interval list by business date and date value. * get date interval list by business date and date value.
* @param businessDate * @param businessDate business date
* @param dateValue * @param dateValue date value
* @return * @return date interval list by business date and date value.
*/ */
public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue){ public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue){
List<DateInterval> result = new ArrayList<>(); List<DateInterval> result = new ArrayList<>();

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/EncryptionUtils.java

@ -27,7 +27,7 @@ public class EncryptionUtils {
/** /**
* *
* @param rawStr * @param rawStr raw string
* @return md5(rawStr) * @return md5(rawStr)
*/ */
public static String getMd5(String rawStr) { public static String getMd5(String rawStr) {

43
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java

@ -37,7 +37,7 @@ public class FileUtils {
/** /**
* get file suffix * get file suffix
* *
* @param filename * @param filename file name
* @return file suffix * @return file suffix
*/ */
public static String suffix(String filename) { public static String suffix(String filename) {
@ -55,7 +55,7 @@ public class FileUtils {
/** /**
* get download file absolute path and name * get download file absolute path and name
* *
* @param filename * @param filename file name
* @return download file name * @return download file name
*/ */
public static String getDownloadFilename(String filename) { public static String getDownloadFilename(String filename) {
@ -75,10 +75,10 @@ public class FileUtils {
/** /**
* directory of process execution * directory of process execution
* @param projectId * @param projectId project id
* @param processDefineId * @param processDefineId process definition id
* @param processInstanceId * @param processInstanceId process instance id
* @param taskInstanceId * @param taskInstanceId task instance id
* @return directory of process execution * @return directory of process execution
*/ */
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId, int taskInstanceId) { public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId, int taskInstanceId) {
@ -89,9 +89,9 @@ public class FileUtils {
/** /**
* directory of process instances * directory of process instances
* @param projectId * @param projectId project id
* @param processDefineId * @param processDefineId process definition id
* @param processInstanceId * @param processInstanceId process instance id
* @return directory of process instances * @return directory of process instances
*/ */
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId) { public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId) {
@ -108,10 +108,10 @@ public class FileUtils {
/** /**
* create directory and user * create directory and user
* @param execLocalPath * @param execLocalPath execute local path
* @param userName * @param userName user name
* @param logger * @param logger logger
* @throws IOException * @throws IOException errors
*/ */
public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{ public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{
//if work dir exists, first delete //if work dir exists, first delete
@ -145,7 +145,7 @@ public class FileUtils {
* *
* @param content content * @param content content
* @param filePath target file path * @param filePath target file path
* @return * @return true if write success
*/ */
public static boolean writeContent2File(String content, String filePath) { public static boolean writeContent2File(String content, String filePath) {
boolean flag = true; boolean flag = true;
@ -344,7 +344,8 @@ public class FileUtils {
/** /**
* deletes a directory recursively * deletes a directory recursively
* @param dir * @param dir directory
* @throws IOException in case deletion is unsuccessful
*/ */
public static void deleteDir(String dir) throws IOException { public static void deleteDir(String dir) throws IOException {
@ -361,7 +362,7 @@ public class FileUtils {
* (java.io.File methods returns a boolean)</li> * (java.io.File methods returns a boolean)</li>
* </ul> * </ul>
* *
* @param filename * @param filename file name
* @throws IOException in case deletion is unsuccessful * @throws IOException in case deletion is unsuccessful
*/ */
public static void deleteFile(String filename) throws IOException { public static void deleteFile(String filename) throws IOException {
@ -370,8 +371,8 @@ public class FileUtils {
/** /**
* Gets all the parent subdirectories of the parentDir directory * Gets all the parent subdirectories of the parentDir directory
* @param parentDir * @param parentDir parent dir
* @return * @return all dirs
*/ */
public static File[] getAllDir(String parentDir){ public static File[] getAllDir(String parentDir){
if(parentDir == null || "".equals(parentDir)) { if(parentDir == null || "".equals(parentDir)) {
@ -401,9 +402,9 @@ public class FileUtils {
/** /**
* Get Content * Get Content
* @param inputStream * @param inputStream input stream
* @return * @return string of input stream
* @throws IOException * @throws IOException errors
*/ */
public static String readFile2Str(InputStream inputStream) throws IOException{ public static String readFile2Str(InputStream inputStream) throws IOException{
String all_content=null; String all_content=null;

44
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HadoopUtils.java

@ -177,8 +177,8 @@ public class HadoopUtils implements Closeable {
/** /**
* get application url * get application url
* *
* @param applicationId * @param applicationId application id
* @return * @return url of application
*/ */
public String getApplicationUrl(String applicationId) { public String getApplicationUrl(String applicationId) {
return String.format(configuration.get(Constants.YARN_APPLICATION_STATUS_ADDRESS), applicationId); return String.format(configuration.get(Constants.YARN_APPLICATION_STATUS_ADDRESS), applicationId);
@ -188,7 +188,8 @@ public class HadoopUtils implements Closeable {
* cat file on hdfs * cat file on hdfs
* *
* @param hdfsFilePath hdfs file path * @param hdfsFilePath hdfs file path
* @return byte[] * @return byte[] byte array
* @throws IOException errors
*/ */
public byte[] catFile(String hdfsFilePath) throws IOException { public byte[] catFile(String hdfsFilePath) throws IOException {
@ -209,7 +210,8 @@ public class HadoopUtils implements Closeable {
* @param hdfsFilePath hdfs file path * @param hdfsFilePath hdfs file path
* @param skipLineNums skip line numbers * @param skipLineNums skip line numbers
* @param limit read how many lines * @param limit read how many lines
* @return * @return content of file
* @throws IOException errors
*/ */
public List<String> catFile(String hdfsFilePath, int skipLineNums, int limit) throws IOException { public List<String> catFile(String hdfsFilePath, int skipLineNums, int limit) throws IOException {
@ -230,6 +232,8 @@ public class HadoopUtils implements Closeable {
* Existence of the directory hierarchy is not an error. * Existence of the directory hierarchy is not an error.
* *
* @param hdfsPath path to create * @param hdfsPath path to create
* @return mkdir result
* @throws IOException errors
*/ */
public boolean mkdir(String hdfsPath) throws IOException { public boolean mkdir(String hdfsPath) throws IOException {
return fs.mkdirs(new Path(hdfsPath)); return fs.mkdirs(new Path(hdfsPath));
@ -242,7 +246,8 @@ public class HadoopUtils implements Closeable {
* @param dstPath destination hdfs path * @param dstPath destination hdfs path
* @param deleteSource whether to delete the src * @param deleteSource whether to delete the src
* @param overwrite whether to overwrite an existing file * @param overwrite whether to overwrite an existing file
* @return 是否成功 * @return if success or not
* @throws IOException errors
*/ */
public boolean copy(String srcPath, String dstPath, boolean deleteSource, boolean overwrite) throws IOException { public boolean copy(String srcPath, String dstPath, boolean deleteSource, boolean overwrite) throws IOException {
return FileUtil.copy(fs, new Path(srcPath), fs, new Path(dstPath), deleteSource, overwrite, fs.getConf()); return FileUtil.copy(fs, new Path(srcPath), fs, new Path(dstPath), deleteSource, overwrite, fs.getConf());
@ -256,6 +261,8 @@ public class HadoopUtils implements Closeable {
* @param dstHdfsPath destination hdfs path * @param dstHdfsPath destination hdfs path
* @param deleteSource whether to delete the src * @param deleteSource whether to delete the src
* @param overwrite whether to overwrite an existing file * @param overwrite whether to overwrite an existing file
* @return if success or not
* @throws IOException errors
*/ */
public boolean copyLocalToHdfs(String srcFile, String dstHdfsPath, boolean deleteSource, boolean overwrite) throws IOException { public boolean copyLocalToHdfs(String srcFile, String dstHdfsPath, boolean deleteSource, boolean overwrite) throws IOException {
Path srcPath = new Path(srcFile); Path srcPath = new Path(srcFile);
@ -273,8 +280,8 @@ public class HadoopUtils implements Closeable {
* @param dstFile destination file * @param dstFile destination file
* @param deleteSource delete source * @param deleteSource delete source
* @param overwrite overwrite * @param overwrite overwrite
* @return * @return result of copy hdfs file to local
* @throws IOException * @throws IOException errors
*/ */
public boolean copyHdfsToLocal(String srcHdfsFilePath, String dstFile, boolean deleteSource, boolean overwrite) throws IOException { public boolean copyHdfsToLocal(String srcHdfsFilePath, String dstFile, boolean deleteSource, boolean overwrite) throws IOException {
Path srcPath = new Path(srcHdfsFilePath); Path srcPath = new Path(srcHdfsFilePath);
@ -306,7 +313,7 @@ public class HadoopUtils implements Closeable {
* true, the directory is deleted else throws an exception. In * true, the directory is deleted else throws an exception. In
* case of a file the recursive can be set to either true or false. * case of a file the recursive can be set to either true or false.
* @return true if delete is successful else false. * @return true if delete is successful else false.
* @throws IOException * @throws IOException errors
*/ */
public boolean delete(String hdfsFilePath, boolean recursive) throws IOException { public boolean delete(String hdfsFilePath, boolean recursive) throws IOException {
return fs.delete(new Path(hdfsFilePath), recursive); return fs.delete(new Path(hdfsFilePath), recursive);
@ -316,7 +323,8 @@ public class HadoopUtils implements Closeable {
* check if exists * check if exists
* *
* @param hdfsFilePath source file path * @param hdfsFilePath source file path
* @return * @return result of exists or not
* @throws IOException errors
*/ */
public boolean exists(String hdfsFilePath) throws IOException { public boolean exists(String hdfsFilePath) throws IOException {
return fs.exists(new Path(hdfsFilePath)); return fs.exists(new Path(hdfsFilePath));
@ -325,8 +333,9 @@ public class HadoopUtils implements Closeable {
/** /**
* Gets a list of files in the directory * Gets a list of files in the directory
* *
* @param filePath * @param filePath file path
* @return {@link FileStatus} * @return {@link FileStatus} file status
* @throws Exception errors
*/ */
public FileStatus[] listFileStatus(String filePath)throws Exception{ public FileStatus[] listFileStatus(String filePath)throws Exception{
Path path = new Path(filePath); Path path = new Path(filePath);
@ -354,10 +363,9 @@ public class HadoopUtils implements Closeable {
/** /**
* get the state of an application * get the state of an application
* *
* @param applicationId * @param applicationId application id
* @return the return may be null or there may be other parse exceptions * @return the return may be null or there may be other parse exceptions
* @throws JSONException * @throws JSONException json exception
* @throws IOException
*/ */
public ExecutionStatus getApplicationStatus(String applicationId) throws JSONException { public ExecutionStatus getApplicationStatus(String applicationId) throws JSONException {
if (StringUtils.isEmpty(applicationId)) { if (StringUtils.isEmpty(applicationId)) {
@ -418,6 +426,7 @@ public class HadoopUtils implements Closeable {
* hdfs user dir * hdfs user dir
* *
* @param tenantCode tenant code * @param tenantCode tenant code
* @param userId user id
* @return hdfs resource dir * @return hdfs resource dir
*/ */
public static String getHdfsUserDir(String tenantCode,int userId) { public static String getHdfsUserDir(String tenantCode,int userId) {
@ -457,6 +466,7 @@ public class HadoopUtils implements Closeable {
} }
/** /**
* @param tenantCode tenant code
* @return file directory of tenants on hdfs * @return file directory of tenants on hdfs
*/ */
public static String getHdfsTenantDir(String tenantCode) { public static String getHdfsTenantDir(String tenantCode) {
@ -467,9 +477,9 @@ public class HadoopUtils implements Closeable {
/** /**
* getAppAddress * getAppAddress
* *
* @param appAddress * @param appAddress app address
* @param rmHa * @param rmHa resource manager ha
* @return * @return app address
*/ */
public static String getAppAddress(String appAddress, String rmHa) { public static String getAppAddress(String appAddress, String rmHa) {

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java

@ -39,7 +39,7 @@ public class HttpUtils {
/** /**
* get http request content * get http request content
* @param url * @param url url
* @return http response * @return http response
*/ */
public static String get(String url){ public static String get(String url){

1
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java

@ -33,6 +33,7 @@ public class IpUtils {
* ip str to long <p> * ip str to long <p>
* *
* @param ipStr ip string * @param ipStr ip string
* @return ip to long
*/ */
public static Long ipToLong(String ipStr) { public static Long ipToLong(String ipStr) {
String[] ipSet = ipStr.split("\\" + DOT); String[] ipSet = ipStr.split("\\" + DOT);

37
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java

@ -54,7 +54,7 @@ public class JSONUtils {
/** /**
* json representation of object * json representation of object
* @param object * @param object object
* @return object to json string * @return object to json string
*/ */
public static String toJson(Object object) { public static String toJson(Object object) {
@ -79,6 +79,7 @@ public class JSONUtils {
* *
* @param json the string from which the object is to be deserialized * @param json the string from which the object is to be deserialized
* @param clazz the class of T * @param clazz the class of T
* @param <T> T
* @return an object of type T from the string * @return an object of type T from the string
* classOfT * classOfT
*/ */
@ -99,10 +100,10 @@ public class JSONUtils {
/** /**
* json to list * json to list
* *
* @param json * @param json json string
* @param clazz c * @param clazz class
* @param <T> * @param <T> T
* @return * @return list
*/ */
public static <T> List<T> toList(String json, Class<T> clazz) { public static <T> List<T> toList(String json, Class<T> clazz) {
if (StringUtils.isEmpty(json)) { if (StringUtils.isEmpty(json)) {
@ -122,8 +123,8 @@ public class JSONUtils {
/** /**
* check json object valid * check json object valid
* *
* @param json * @param json json
* @return * @return true if valid
*/ */
public static boolean checkJsonVaild(String json) { public static boolean checkJsonVaild(String json) {
@ -147,6 +148,7 @@ public class JSONUtils {
* node or its child nodes, and returning value it has. * node or its child nodes, and returning value it has.
* If no matching field is found in this node or its descendants, returns null. * If no matching field is found in this node or its descendants, returns null.
* *
* @param jsonNode json node
* @param fieldName Name of field to look for * @param fieldName Name of field to look for
* *
* @return Value of first matching node found, if any; null if none * @return Value of first matching node found, if any; null if none
@ -167,8 +169,8 @@ public class JSONUtils {
* *
* {@link #toMap(String, Class, Class)} * {@link #toMap(String, Class, Class)}
* *
* @param json * @param json json
* @return * @return json to map
*/ */
public static Map<String, String> toMap(String json) { public static Map<String, String> toMap(String json) {
if (StringUtils.isEmpty(json)) { if (StringUtils.isEmpty(json)) {
@ -188,16 +190,12 @@ public class JSONUtils {
* *
* json to map * json to map
* *
* <pre> * @param json json
* String jsonStr = "{\"id\":\"1001\",\"name\":\"Jobs\"}"; * @param classK classK
* Map<String,String> models = JSONUtils.toMap(jsonStr, String.class,String.class); * @param classV classV
* </pre> * @param <K> K
* @param json * @param <V> V
* @param classK * @return to map
* @param classV
* @param <K>
* @param <V>
* @return
*/ */
public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) { public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {
if (StringUtils.isEmpty(json)) { if (StringUtils.isEmpty(json)) {
@ -215,6 +213,7 @@ public class JSONUtils {
/** /**
* object to json string * object to json string
* @param object object
* @return json string * @return json string
*/ */
public static String toJsonString(Object object) { public static String toJsonString(Object object) {

33
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java

@ -106,7 +106,7 @@ public class OSUtils {
/** /**
* load average * load average
* *
* @return * @return load average
*/ */
public static double loadAverage() { public static double loadAverage() {
double loadAverage = hal.getProcessor().getSystemLoadAverage(); double loadAverage = hal.getProcessor().getSystemLoadAverage();
@ -120,7 +120,7 @@ public class OSUtils {
/** /**
* get cpu usage * get cpu usage
* *
* @return * @return cpu usage
*/ */
public static double cpuUsage() { public static double cpuUsage() {
CentralProcessor processor = hal.getProcessor(); CentralProcessor processor = hal.getProcessor();
@ -136,7 +136,7 @@ public class OSUtils {
/** /**
* get user list * get user list
* *
* @return * @return user list
*/ */
public static List<String> getUserList() { public static List<String> getUserList() {
List<String> userList = new ArrayList<>(); List<String> userList = new ArrayList<>();
@ -169,8 +169,8 @@ public class OSUtils {
/** /**
* get system group information * get system group information
* @return * @return system group info
* @throws IOException * @throws IOException errors
*/ */
public static String getGroup() throws IOException { public static String getGroup() throws IOException {
String result = exeCmd("groups"); String result = exeCmd("groups");
@ -186,9 +186,9 @@ public class OSUtils {
/** /**
* Execute the corresponding command of Linux or Windows * Execute the corresponding command of Linux or Windows
* *
* @param command * @param command command
* @return * @return result of execute command
* @throws IOException * @throws IOException errors
*/ */
public static String exeCmd(String command) throws IOException { public static String exeCmd(String command) throws IOException {
BufferedReader br = null; BufferedReader br = null;
@ -217,9 +217,9 @@ public class OSUtils {
/** /**
* Execute the shell * Execute the shell
* @param command * @param command command
* @return * @return result of execute the shell
* @throws IOException * @throws IOException errors
*/ */
public static String exeShell(String command) throws IOException { public static String exeShell(String command) throws IOException {
return ShellExecutor.execCommand(command); return ShellExecutor.execCommand(command);
@ -227,7 +227,7 @@ public class OSUtils {
/** /**
* get process id * get process id
* @return * @return process id
*/ */
public static int getProcessID() { public static int getProcessID() {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
@ -236,7 +236,7 @@ public class OSUtils {
/** /**
* get local host * get local host
* @return * @return host
*/ */
public static String getHost(){ public static String getHost(){
try { try {
@ -250,6 +250,7 @@ public class OSUtils {
/** /**
* whether is macOS * whether is macOS
* @return true if mac
*/ */
public static boolean isMacOS() { public static boolean isMacOS() {
String os = System.getProperty("os.name"); String os = System.getProperty("os.name");
@ -259,6 +260,7 @@ public class OSUtils {
/** /**
* whether is windows * whether is windows
* @return true if windows
*/ */
public static boolean isWindows() { public static boolean isWindows() {
String os = System.getProperty("os.name"); String os = System.getProperty("os.name");
@ -268,8 +270,9 @@ public class OSUtils {
/** /**
* check memory and cpu usage * check memory and cpu usage
* @param conf * @param conf conf
* @return * @param isMaster is master
* @return check memory and cpu usage
*/ */
public static Boolean checkResource(Configuration conf, Boolean isMaster){ public static Boolean checkResource(Configuration conf, Boolean isMaster){
double systemCpuLoad; double systemCpuLoad;

28
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java

@ -43,9 +43,9 @@ public class ParameterUtils {
/** /**
* convert parameters place holders * convert parameters place holders
* *
* @param parameterString * @param parameterString parameter
* @param parameterMap * @param parameterMap parameter map
* @return * @return convert parameters place holders
*/ */
public static String convertParameterPlaceholders(String parameterString, Map<String, String> parameterMap) { public static String convertParameterPlaceholders(String parameterString, Map<String, String> parameterMap) {
if (StringUtils.isEmpty(parameterString)) { if (StringUtils.isEmpty(parameterString)) {
@ -80,11 +80,11 @@ public class ParameterUtils {
/** /**
* set in parameter * set in parameter
* @param index * @param index index
* @param stmt * @param stmt preparedstatement
* @param dataType * @param dataType data type
* @param value * @param value value
* @throws Exception * @throws Exception errors
*/ */
public static void setInParameter(int index, PreparedStatement stmt, DataType dataType, String value)throws Exception{ public static void setInParameter(int index, PreparedStatement stmt, DataType dataType, String value)throws Exception{
if (dataType.equals(DataType.VARCHAR)){ if (dataType.equals(DataType.VARCHAR)){
@ -111,7 +111,11 @@ public class ParameterUtils {
/** /**
* curing user define parameters * curing user define parameters
* *
* @return * @param globalParamMap global param map
* @param globalParamList global param list
* @param commandType command type
* @param scheduleTime schedule time
* @return curing user define parameters
*/ */
public static String curingGlobalParams(Map<String,String> globalParamMap, List<Property> globalParamList, public static String curingGlobalParams(Map<String,String> globalParamMap, List<Property> globalParamList,
CommandType commandType, Date scheduleTime){ CommandType commandType, Date scheduleTime){
@ -120,7 +124,7 @@ public class ParameterUtils {
globalMap.putAll(globalParamMap); globalMap.putAll(globalParamMap);
} }
Map<String,String> allParamMap = new HashMap<>(); Map<String,String> allParamMap = new HashMap<>();
//如果是补数,需要传入一个补数时间,根据任务类型 //If it is a complement, a complement time needs to be passed in, according to the task type
Map<String,String> timeParams = BusinessTimeUtils Map<String,String> timeParams = BusinessTimeUtils
.getBusinessTime(commandType, scheduleTime); .getBusinessTime(commandType, scheduleTime);
@ -163,8 +167,8 @@ public class ParameterUtils {
/** /**
* handle escapes * handle escapes
* @param inputString * @param inputString input string
* @return * @return string filter escapes
*/ */
public static String handleEscapes(String inputString){ public static String handleEscapes(String inputString){

42
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java

@ -71,8 +71,8 @@ public class PropertyUtils {
} }
/** /**
* judge whether resource upload startup *
* @return * @return judge whether resource upload startup
*/ */
public static Boolean getResUploadStartupState(){ public static Boolean getResUploadStartupState(){
String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE); String resUploadStartupType = PropertyUtils.getString(Constants.RES_UPLOAD_STARTUP_TYPE);
@ -84,7 +84,7 @@ public class PropertyUtils {
* get property value * get property value
* *
* @param key property name * @param key property name
* @return * @return property value
*/ */
public static String getString(String key) { public static String getString(String key) {
return properties.getProperty(key.trim()); return properties.getProperty(key.trim());
@ -102,9 +102,9 @@ public class PropertyUtils {
/** /**
* *
* @param key * @param key key
* @param defaultValue * @param defaultValue default value
* @return * @return property value
*/ */
public static int getInt(String key, int defaultValue) { public static int getInt(String key, int defaultValue) {
String value = getString(key); String value = getString(key);
@ -124,7 +124,7 @@ public class PropertyUtils {
* get property value * get property value
* *
* @param key property name * @param key property name
* @return * @return property value
*/ */
public static Boolean getBoolean(String key) { public static Boolean getBoolean(String key) {
String value = properties.getProperty(key.trim()); String value = properties.getProperty(key.trim());
@ -137,9 +137,9 @@ public class PropertyUtils {
/** /**
* get property long value * get property long value
* @param key * @param key key
* @param defaultVal * @param defaultVal default value
* @return * @return property value
*/ */
public static long getLong(String key, long defaultVal) { public static long getLong(String key, long defaultVal) {
String val = getString(key); String val = getString(key);
@ -148,8 +148,8 @@ public class PropertyUtils {
/** /**
* *
* @param key * @param key key
* @return * @return property value
*/ */
public static long getLong(String key) { public static long getLong(String key) {
return getLong(key,-1); return getLong(key,-1);
@ -157,9 +157,9 @@ public class PropertyUtils {
/** /**
* *
* @param key * @param key key
* @param defaultVal * @param defaultVal default value
* @return * @return property value
*/ */
public double getDouble(String key, double defaultVal) { public double getDouble(String key, double defaultVal) {
String val = getString(key); String val = getString(key);
@ -171,7 +171,7 @@ public class PropertyUtils {
* get array * get array
* @param key property name * @param key property name
* @param splitStr separator * @param splitStr separator
* @return * @return property value through array
*/ */
public static String[] getArray(String key, String splitStr) { public static String[] getArray(String key, String splitStr) {
String value = getString(key); String value = getString(key);
@ -189,10 +189,10 @@ public class PropertyUtils {
/** /**
* *
* @param key * @param key key
* @param type * @param type type
* @param defaultValue * @param defaultValue default value
* @param <T> * @param <T> T
* @return get enum value * @return get enum value
*/ */
public <T extends Enum<T>> T getEnum(String key, Class<T> type, public <T extends Enum<T>> T getEnum(String key, Class<T> type,
@ -204,7 +204,7 @@ public class PropertyUtils {
/** /**
* get all properties with specified prefix, like: fs. * get all properties with specified prefix, like: fs.
* @param prefix prefix to search * @param prefix prefix to search
* @return * @return all properties with specified prefix
*/ */
public static Map<String, String> getPrefixedProperties(String prefix) { public static Map<String, String> getPrefixedProperties(String prefix) {
Map<String, String> matchedProperties = new HashMap<>(); Map<String, String> matchedProperties = new HashMap<>();

29
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java

@ -79,7 +79,10 @@ public class ResInfo {
/** /**
* get CPU and memory usage * get CPU and memory usage
* @return * @param cpuUsage cpu usage
* @param memoryUsage memory usage
* @param loadAverage load average
* @return cpu and memory usage
*/ */
public static String getResInfoJson(double cpuUsage , double memoryUsage,double loadAverage){ public static String getResInfoJson(double cpuUsage , double memoryUsage,double loadAverage){
ResInfo resInfo = new ResInfo(cpuUsage,memoryUsage,loadAverage); ResInfo resInfo = new ResInfo(cpuUsage,memoryUsage,loadAverage);
@ -89,8 +92,8 @@ public class ResInfo {
/** /**
* get heart beat info * get heart beat info
* @param now * @param now now
* @return * @return heart beat info
*/ */
public static String getHeartBeatInfo(Date now){ public static String getHeartBeatInfo(Date now){
return buildHeartbeatForZKInfo(OSUtils.getHost(), return buildHeartbeatForZKInfo(OSUtils.getHost(),
@ -105,14 +108,14 @@ public class ResInfo {
/** /**
* build heartbeat info for zk * build heartbeat info for zk
* @param host * @param host host
* @param port * @param port port
* @param cpuUsage * @param cpuUsage cpu usage
* @param memoryUsage * @param memoryUsage memory usage
* @param loadAverage * @param loadAverage load average
* @param createTime * @param createTime create time
* @param lastHeartbeatTime * @param lastHeartbeatTime last heartbeat time
* @return * @return heartbeat info
*/ */
public static String buildHeartbeatForZKInfo(String host , int port , public static String buildHeartbeatForZKInfo(String host , int port ,
double cpuUsage , double memoryUsage,double loadAverage, double cpuUsage , double memoryUsage,double loadAverage,
@ -128,8 +131,8 @@ public class ResInfo {
/** /**
* parse heartbeat info for zk * parse heartbeat info for zk
* @param heartBeatInfo * @param heartBeatInfo heartbeat info
* @return * @return heartbeat info to Server
*/ */
public static Server parseHeartbeatForZKInfo(String heartBeatInfo){ public static Server parseHeartbeatForZKInfo(String heartBeatInfo){
Server masterServer = null; Server masterServer = null;

14
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/SchemaUtils.java

@ -42,7 +42,7 @@ public class SchemaUtils {
/** /**
* Gets upgradable schemas for all upgrade directories * Gets upgradable schemas for all upgrade directories
* @return * @return all schema list
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<String> getAllSchemaList() { public static List<String> getAllSchemaList() {
@ -86,9 +86,9 @@ public class SchemaUtils {
/** /**
* Determine whether schemaVersion is higher than version * Determine whether schemaVersion is higher than version
* @param schemaVersion * @param schemaVersion schema version
* @param version * @param version version
* @return * @return Determine whether schemaVersion is higher than version
*/ */
public static boolean isAGreatVersion(String schemaVersion, String version) { public static boolean isAGreatVersion(String schemaVersion, String version) {
if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) { if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) {
@ -112,7 +112,7 @@ public class SchemaUtils {
/** /**
* Gets the current software version number of the system * Gets the current software version number of the system
* @return * @return current software version
*/ */
public static String getSoftVersion() { public static String getSoftVersion() {
String soft_version; String soft_version;
@ -131,8 +131,8 @@ public class SchemaUtils {
/** /**
* Strips the string of space carriage returns and tabs * Strips the string of space carriage returns and tabs
* @param str * @param str string
* @return * @return string removed blank
*/ */
public static String replaceBlank(String str) { public static String replaceBlank(String str) {
String dest = ""; String dest = "";

11
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java

@ -62,20 +62,13 @@ public class ScriptRunner {
private String delimiter = DEFAULT_DELIMITER; private String delimiter = DEFAULT_DELIMITER;
private boolean fullLineDelimiter = false; private boolean fullLineDelimiter = false;
/**
* Default constructor
*/
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) { public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) {
this.connection = connection; this.connection = connection;
this.autoCommit = autoCommit; this.autoCommit = autoCommit;
this.stopOnError = stopOnError; this.stopOnError = stopOnError;
} }
public static void main(String[] args) {
String dbName = "db_mmu";
String appKey = dbName.substring(dbName.lastIndexOf("_")+1, dbName.length());
System.out.println(appKey);
}
public void setDelimiter(String delimiter, boolean fullLineDelimiter) { public void setDelimiter(String delimiter, boolean fullLineDelimiter) {
this.delimiter = delimiter; this.delimiter = delimiter;
@ -87,6 +80,8 @@ public class ScriptRunner {
* *
* @param reader * @param reader
* - the source of the script * - the source of the script
* @throws IOException errors
* @throws SQLException errors
*/ */
public void runScript(Reader reader) throws IOException, SQLException { public void runScript(Reader reader) throws IOException, SQLException {
try { try {

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/TaskParametersUtils.java

@ -42,8 +42,8 @@ public class TaskParametersUtils {
/** /**
* get task parameters * get task parameters
* @param taskType * @param taskType task type
* @param parameter * @param parameter parameter
* @return task parameters * @return task parameters
*/ */
public static AbstractParameters getParameters(String taskType, String parameter) { public static AbstractParameters getParameters(String taskType, String parameter) {

1
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/BusinessTimeUtils.java

@ -39,6 +39,7 @@ public class BusinessTimeUtils {
* *
* @param commandType command type * @param commandType command type
* @param runTime run time or schedule time * @param runTime run time or schedule time
* @return business time
*/ */
public static Map<String, String> getBusinessTime(CommandType commandType, Date runTime) { public static Map<String, String> getBusinessTime(CommandType commandType, Date runTime) {
Date businessDate = runTime; Date businessDate = runTime;

1
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java

@ -64,6 +64,7 @@ public class PlaceholderUtils {
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix. * Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should * @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
* be ignored ({@code true}) or cause an exception ({@code false}) * be ignored ({@code true}) or cause an exception ({@code false})
* @return PropertyPlaceholderHelper
*/ */
public static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { public static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {

1
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PropertyPlaceholderHelper.java

@ -225,6 +225,7 @@ public class PropertyPlaceholderHelper {
* @param str the original string (or StringBuilder) * @param str the original string (or StringBuilder)
* @param index the index in the original string to start matching against * @param index the index in the original string to start matching against
* @param substring the substring to match at the given index * @param substring the substring to match at the given index
* @return whether the given string matches the given substring
*/ */
public static boolean substringMatch(CharSequence str, int index, CharSequence substring) { public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
for (int j = 0; j < substring.length(); j++) { for (int j = 0; j < substring.length(); j++) {

41
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java

@ -48,7 +48,7 @@ public class TimePlaceholderUtils {
* *
* @param value the value containing the placeholders to be replaced * @param value the value containing the placeholders to be replaced
* @param date custom date * @param date custom date
* @param ignoreUnresolvablePlaceholders * @param ignoreUnresolvablePlaceholders ignore unresolvable placeholders
* @return the supplied value with placeholders replaced inline * @return the supplied value with placeholders replaced inline
*/ */
public static String replacePlaceholders(String value, Date date, boolean ignoreUnresolvablePlaceholders) { public static String replacePlaceholders(String value, Date date, boolean ignoreUnresolvablePlaceholders) {
@ -72,8 +72,8 @@ public class TimePlaceholderUtils {
/** /**
* calculate expression's value * calculate expression's value
* *
* @param expression * @param expression expression
* @return * @return expression's value
*/ */
public static Integer calculate(String expression) { public static Integer calculate(String expression) {
expression = StringUtils.trim(expression); expression = StringUtils.trim(expression);
@ -320,8 +320,9 @@ public class TimePlaceholderUtils {
/** /**
* calculate time expresstion * calculate time expresstion
* * @param expression expresstion
* @return <date, date format> * @param date date
* @return map with date, date format
*/ */
public static Map.Entry<Date, String> calcTimeExpression(String expression, Date date) { public static Map.Entry<Date, String> calcTimeExpression(String expression, Date date) {
Map.Entry<Date, String> resultEntry; Map.Entry<Date, String> resultEntry;
@ -345,8 +346,9 @@ public class TimePlaceholderUtils {
/** /**
* get first day of month * get first day of month
* * @param expression expresstion
* @return * @param date date
* @return first day of month
*/ */
public static Map.Entry<Date, String> calcMonthBegin(String expression, Date date) { public static Map.Entry<Date, String> calcMonthBegin(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.MONTH_BEGIN.length() + 1, expression.length() - 1); String addMonthExpr = expression.substring(Constants.MONTH_BEGIN.length() + 1, expression.length() - 1);
@ -367,7 +369,9 @@ public class TimePlaceholderUtils {
/** /**
* get last day of month * get last day of month
* * @param expression expresstion
* @param date date
* @return last day of month
*/ */
public static Map.Entry<Date, String> calcMonthEnd(String expression, Date date) { public static Map.Entry<Date, String> calcMonthEnd(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.MONTH_END.length() + 1, expression.length() - 1); String addMonthExpr = expression.substring(Constants.MONTH_END.length() + 1, expression.length() - 1);
@ -388,7 +392,8 @@ public class TimePlaceholderUtils {
/** /**
* get first day of week * get first day of week
* * @param expression expresstion
* @param date date
* @return monday * @return monday
*/ */
public static Map.Entry<Date, String> calcWeekStart(String expression, Date date) { public static Map.Entry<Date, String> calcWeekStart(String expression, Date date) {
@ -409,7 +414,9 @@ public class TimePlaceholderUtils {
/** /**
* get last day of week * get last day of week
* * @param expression expresstion
* @param date date
* @return last day of week
*/ */
public static Map.Entry<Date, String> calcWeekEnd(String expression, Date date) { public static Map.Entry<Date, String> calcWeekEnd(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.WEEK_END.length() + 1, expression.length() - 1); String addMonthExpr = expression.substring(Constants.WEEK_END.length() + 1, expression.length() - 1);
@ -430,8 +437,9 @@ public class TimePlaceholderUtils {
/** /**
* calc months expression * calc months expression
* * @param expression expresstion
* @return <date, format> * @param date date
* @return calc months
*/ */
public static Map.Entry<Date, String> calcMonths(String expression, Date date) { public static Map.Entry<Date, String> calcMonths(String expression, Date date) {
String addMonthExpr = expression.substring(Constants.ADD_MONTHS.length() + 1, expression.length() - 1); String addMonthExpr = expression.substring(Constants.ADD_MONTHS.length() + 1, expression.length() - 1);
@ -452,8 +460,9 @@ public class TimePlaceholderUtils {
/** /**
* calculate time expression * calculate time expression
* *
* * @param expression expresstion
* @return <date, format> * @param date date
* @return calculate time expression with date,format
*/ */
public static Map.Entry<Date, String> calcMinutes(String expression, Date date) { public static Map.Entry<Date, String> calcMinutes(String expression, Date date) {
if (expression.contains("+")) { if (expression.contains("+")) {
@ -490,8 +499,8 @@ public class TimePlaceholderUtils {
/** /**
* calculate need minutes * calculate need minutes
* *
* @param minuteExpression * @param minuteExpression minute expression
* @return * @return calculate need minutes
*/ */
public static Integer calcMinutes(String minuteExpression) { public static Integer calcMinutes(String minuteExpression) {
int index = minuteExpression.indexOf("/"); int index = minuteExpression.indexOf("/");

92
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/zk/AbstractZKClient.java

@ -140,7 +140,8 @@ public abstract class AbstractZKClient {
/** /**
* heartbeat for zookeeper * heartbeat for zookeeper
* @param znode * @param znode zookeeper node
* @param serverType server type
*/ */
public void heartBeatForZk(String znode, String serverType){ public void heartBeatForZk(String znode, String serverType){
try { try {
@ -177,7 +178,8 @@ public abstract class AbstractZKClient {
* *
* @param zNode node path * @param zNode node path
* @param serverType master or worker prefix * @param serverType master or worker prefix
* @throws Exception * @return true if not exists
* @throws Exception errors
*/ */
protected boolean checkIsDeadServer(String zNode, String serverType) throws Exception{ protected boolean checkIsDeadServer(String zNode, String serverType) throws Exception{
//ip_sequenceno //ip_sequenceno
@ -213,8 +215,8 @@ public abstract class AbstractZKClient {
/** /**
* create zookeeper path according the zk node type. * create zookeeper path according the zk node type.
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return * @return register zookeeper path
* @throws Exception * @throws Exception
*/ */
private String createZNodePath(ZKNodeType zkNodeType) throws Exception { private String createZNodePath(ZKNodeType zkNodeType) throws Exception {
@ -231,8 +233,9 @@ public abstract class AbstractZKClient {
/** /**
* register server, if server already exists, return null. * register server, if server already exists, return null.
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return register server path in zookeeper * @return register server path in zookeeper
* @throws Exception errors
*/ */
public String registerServer(ZKNodeType zkNodeType) throws Exception { public String registerServer(ZKNodeType zkNodeType) throws Exception {
String registerPath = null; String registerPath = null;
@ -257,7 +260,7 @@ public abstract class AbstractZKClient {
* @param zNode node path * @param zNode node path
* @param zkNodeType master or worker * @param zkNodeType master or worker
* @param opType delete or add * @param opType delete or add
* @throws Exception * @throws Exception errors
*/ */
public void handleDeadServer(String zNode, ZKNodeType zkNodeType, String opType) throws Exception { public void handleDeadServer(String zNode, ZKNodeType zkNodeType, String opType) throws Exception {
//ip_sequenceno //ip_sequenceno
@ -291,7 +294,7 @@ public abstract class AbstractZKClient {
/** /**
* for stop server * for stop server
* @param serverStoppable * @param serverStoppable server stoppable interface
*/ */
public void setStoppable(IStoppable serverStoppable){ public void setStoppable(IStoppable serverStoppable){
this.stoppable = serverStoppable; this.stoppable = serverStoppable;
@ -299,7 +302,7 @@ public abstract class AbstractZKClient {
/** /**
* get active master num * get active master num
* @return * @return active master number
*/ */
public int getActiveMasterNum(){ public int getActiveMasterNum(){
List<String> childrenList = new ArrayList<>(); List<String> childrenList = new ArrayList<>();
@ -340,8 +343,8 @@ public abstract class AbstractZKClient {
/** /**
* get server list. * get server list.
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return * @return server list
*/ */
public List<Server> getServersList(ZKNodeType zkNodeType){ public List<Server> getServersList(ZKNodeType zkNodeType){
Map<String, String> masterMap = getServerMaps(zkNodeType); Map<String, String> masterMap = getServerMaps(zkNodeType);
@ -361,8 +364,8 @@ public abstract class AbstractZKClient {
/** /**
* get master server list map. * get master server list map.
* result : {host : resource info} * @param zkNodeType zookeeper node type
* @return * @return result : {host : resource info}
*/ */
public Map<String, String> getServerMaps(ZKNodeType zkNodeType){ public Map<String, String> getServerMaps(ZKNodeType zkNodeType){
@ -383,10 +386,9 @@ public abstract class AbstractZKClient {
/** /**
* check the zookeeper node already exists * check the zookeeper node already exists
* @param host * @param host host
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return * @return true if exists
* @throws Exception
*/ */
public boolean checkZKNodeExists(String host, ZKNodeType zkNodeType) { public boolean checkZKNodeExists(String host, ZKNodeType zkNodeType) {
String path = getZNodeParentPath(zkNodeType); String path = getZNodeParentPath(zkNodeType);
@ -406,36 +408,36 @@ public abstract class AbstractZKClient {
/** /**
* get zkclient * get zkclient
* @return * @return zookeeper client
*/ */
public CuratorFramework getZkClient() { public CuratorFramework getZkClient() {
return zkClient; return zkClient;
} }
/** /**
* get worker node parent path *
* @return * @return get worker node parent path
*/ */
protected String getWorkerZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS);}; protected String getWorkerZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS);};
/** /**
* get master node parent path *
* @return * @return get master node parent path
*/ */
protected String getMasterZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_MASTERS);} protected String getMasterZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_MASTERS);}
/** /**
* get master lock path *
* @return * @return get master lock path
*/ */
public String getMasterLockPath(){ public String getMasterLockPath(){
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_MASTERS); return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_MASTERS);
} }
/** /**
* get zookeeper node parent path *
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return * @return get zookeeper node parent path
*/ */
public String getZNodeParentPath(ZKNodeType zkNodeType) { public String getZNodeParentPath(ZKNodeType zkNodeType) {
String path = ""; String path = "";
@ -453,32 +455,32 @@ public abstract class AbstractZKClient {
} }
/** /**
* get dead server node parent path *
* @return * @return get dead server node parent path
*/ */
protected String getDeadZNodeParentPath(){ protected String getDeadZNodeParentPath(){
return conf.getString(ZOOKEEPER_DOLPHINSCHEDULER_DEAD_SERVERS); return conf.getString(ZOOKEEPER_DOLPHINSCHEDULER_DEAD_SERVERS);
} }
/** /**
* get master start up lock path *
* @return * @return get master start up lock path
*/ */
public String getMasterStartUpLockPath(){ public String getMasterStartUpLockPath(){
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS); return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS);
} }
/** /**
* get master failover lock path *
* @return * @return get master failover lock path
*/ */
public String getMasterFailoverLockPath(){ public String getMasterFailoverLockPath(){
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS); return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS);
} }
/** /**
* get worker failover lock path *
* @return * @return get worker failover lock path
*/ */
public String getWorkerFailoverLockPath(){ public String getWorkerFailoverLockPath(){
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS); return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS);
@ -486,7 +488,7 @@ public abstract class AbstractZKClient {
/** /**
* release mutex * release mutex
* @param mutex * @param mutex mutex
*/ */
public static void releaseMutex(InterProcessMutex mutex) { public static void releaseMutex(InterProcessMutex mutex) {
if (mutex != null){ if (mutex != null){
@ -519,8 +521,8 @@ public abstract class AbstractZKClient {
/** /**
* create zookeeper node path if not exists * create zookeeper node path if not exists
* @param zNodeParentPath * @param zNodeParentPath zookeeper parent path
* @throws Exception * @throws Exception errors
*/ */
private void createNodePath(String zNodeParentPath) throws Exception { private void createNodePath(String zNodeParentPath) throws Exception {
if(null == zkClient.checkExists().forPath(zNodeParentPath)){ if(null == zkClient.checkExists().forPath(zNodeParentPath)){
@ -531,8 +533,9 @@ public abstract class AbstractZKClient {
/** /**
* server self dead, stop all threads * server self dead, stop all threads
* @param serverHost * @param serverHost server host
* @param zkNodeType * @param zkNodeType zookeeper node type
* @return true if server dead and stop all threads
*/ */
protected boolean checkServerSelfDead(String serverHost, ZKNodeType zkNodeType) { protected boolean checkServerSelfDead(String serverHost, ZKNodeType zkNodeType) {
if (serverHost.equals(OSUtils.getHost())) { if (serverHost.equals(OSUtils.getHost())) {
@ -547,8 +550,8 @@ public abstract class AbstractZKClient {
/** /**
* get host ip, string format: masterParentPath/ip_000001/value * get host ip, string format: masterParentPath/ip_000001/value
* @param path * @param path path
* @return * @return host ip, string format: masterParentPath/ip_000001/value
*/ */
protected String getHostByEventDataPath(String path) { protected String getHostByEventDataPath(String path) {
int startIndex = path.lastIndexOf("/")+1; int startIndex = path.lastIndexOf("/")+1;
@ -562,9 +565,10 @@ public abstract class AbstractZKClient {
} }
/** /**
* acquire zk lock * acquire zk lock
* @param zkClient * @param zkClient zk client
* @param zNodeLockPath * @param zNodeLockPath zk lock path
* @throws Exception * @return zk lock
* @throws Exception errors
*/ */
public InterProcessMutex acquireZkLock(CuratorFramework zkClient,String zNodeLockPath)throws Exception{ public InterProcessMutex acquireZkLock(CuratorFramework zkClient,String zNodeLockPath)throws Exception{
InterProcessMutex mutex = new InterProcessMutex(zkClient, zNodeLockPath); InterProcessMutex mutex = new InterProcessMutex(zkClient, zNodeLockPath);

Loading…
Cancel
Save